Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

finished up basic info prog

  • Loading branch information...
commit 8e2fa2d98a5a6985e1c8798624301ff0784d9aeb 1 parent 856aa43
enjalot authored
38 info/c/CMakeLists.txt
... ... @@ -1,38 +0,0 @@
1   -CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
2   -project(part1)
3   -
4   -#need to include FindOPENCL.cmake to
5   -SET( CMAKE_MODULE_PATH ${part1_SOURCE_DIR}/../cmake)
6   -
7   -message("CMake module path: ${CMAKE_MODULE_PATH}\n")
8   -
9   -FIND_PACKAGE (OPENCL)
10   -
11   -INCLUDE_DIRECTORIES(
12   - ${part1_SOURCE_DIR}/../opencl10
13   -)
14   -
15   -message("include directories: \n")
16   -get_directory_property(includes INCLUDE_DIRECTORIES)
17   -message("${includes}\n")
18   -
19   -#provide the source path so we can open our .cl file at runtime
20   -ADD_DEFINITIONS(-DCL_SOURCE_DIR="${part1_SOURCE_DIR}")
21   -#build in debug mode
22   -ADD_DEFINITIONS(-g )
23   -
24   -#the source files we want to compile into the library
25   -set (LIBCXXFILES cll.cpp part1.cpp util.cpp)
26   -#set a CMake variable to name the library
27   -SET(cllib part1)
28   -ADD_LIBRARY(${cllib} ${LIBCXXFILES})
29   -
30   -
31   -#create the executable
32   -SET(EXEC part1.x)
33   -ADD_EXECUTABLE(${EXEC} main.cpp)
34   -
35   -TARGET_LINK_LIBRARIES (${EXEC}
36   - ${cllib}
37   - ${OPENCL_LIBRARIES}
38   -)
2  info/c/README
... ... @@ -1,2 +0,0 @@
1   -Example of querying Platforms and Devices using the OpenCL 1.0 C API
2   -
123 info/c/cll.cpp
... ... @@ -1,123 +0,0 @@
1   -#include <stdio.h>
2   -#include <string>
3   -#include <cstdlib>
4   -
5   -#include "cll.h"
6   -#include "util.h"
7   -
8   -CL::CL()
9   -{
10   - printf("Initialize OpenCL object and context\n");
11   - //setup devices and context
12   - cl_uint numPlatforms;
13   - cl_platform_id platform = NULL;
14   - status = clGetPlatformIDs(0, NULL, &numPlatforms);
15   -
16   - //this function is defined in util.cpp
17   - //it comes from the NVIDIA SDK example code
18   - err = oclGetPlatformID(&platform);
19   - //oclErrorString is also defined in util.cpp and comes from the NVIDIA SDK
20   - printf("oclGetPlatformID: %s\n", oclErrorString(err));
21   -
22   - // Get the number of GPU devices available to the platform
23   - // we should probably expose the device type to the user
24   - // the other common option is CL_DEVICE_TYPE_CPU
25   - err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
26   - printf("clGetDeviceIDs (get number of devices): %s\n", oclErrorString(err));
27   -
28   -
29   - // Create the device list
30   - devices = new cl_device_id [numDevices];
31   - err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numDevices, devices, NULL);
32   - printf("clGetDeviceIDs (create device list): %s\n", oclErrorString(err));
33   -
34   - //create the context
35   - context = clCreateContext(0, 1, devices, NULL, NULL, &err);
36   -
37   - //for right now we just use the first available device
38   - //later you may have criteria (such as support for different extensions)
39   - //that you want to use to select the device
40   - deviceUsed = 0;
41   -
42   - //create the command queue we will use to execute OpenCL commands
43   - command_queue = clCreateCommandQueue(context, devices[deviceUsed], 0, &err);
44   -
45   - cl_a = 0;
46   - cl_b = 0;
47   - cl_c = 0;
48   -}
49   -
50   -CL::~CL()
51   -{
52   - printf("Releasing OpenCL memory\n");
53   - if(kernel)clReleaseKernel(kernel);
54   - if(program)clReleaseProgram(program);
55   - if(command_queue)clReleaseCommandQueue(command_queue);
56   -
57   - //need to release any other OpenCL memory objects here
58   - if(cl_a)clReleaseMemObject(cl_a);
59   - if(cl_b)clReleaseMemObject(cl_b);
60   - if(cl_c)clReleaseMemObject(cl_c);
61   -
62   - if(context)clReleaseContext(context);
63   -
64   - if(devices)delete(devices);
65   - printf("OpenCL memory released\n");
66   -}
67   -
68   -
69   -void CL::loadProgram(const char* relative_path)
70   -{
71   - // Program Setup
72   - int pl;
73   - size_t program_length;
74   - printf("load the program\n");
75   -
76   - //CL_SOURCE_DIR is set in the CMakeLists.txt
77   - std::string path(CL_SOURCE_DIR);
78   - path += "/" + std::string(relative_path);
79   - printf("path: %s\n", path.c_str());
80   -
81   - //file_contents is defined in util.cpp
82   - //it loads the contents of the file at the given path
83   - char* cSourceCL = file_contents(path.c_str(), &pl);
84   - //printf("file: %s\n", cSourceCL);
85   - program_length = (size_t)pl;
86   -
87   - // create the program
88   - program = clCreateProgramWithSource(context, 1,
89   - (const char **) &cSourceCL, &program_length, &err);
90   - printf("clCreateProgramWithSource: %s\n", oclErrorString(err));
91   -
92   - buildExecutable();
93   -
94   - //Free buffer returned by file_contents
95   - free(cSourceCL);
96   -}
97   -
98   -//----------------------------------------------------------------------
99   -void CL::buildExecutable()
100   -{
101   - // Build the program executable
102   -
103   - printf("building the program\n");
104   - // build the program
105   - //err = clBuildProgram(program, 0, NULL, "-cl-nv-verbose", NULL, NULL);
106   - err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
107   - printf("clBuildProgram: %s\n", oclErrorString(err));
108   - //if(err != CL_SUCCESS){
109   - cl_build_status build_status;
110   - err = clGetProgramBuildInfo(program, devices[deviceUsed], CL_PROGRAM_BUILD_STATUS, sizeof(cl_build_status), &build_status, NULL);
111   -
112   - char *build_log;
113   - size_t ret_val_size;
114   - err = clGetProgramBuildInfo(program, devices[deviceUsed], CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);
115   -
116   - build_log = new char[ret_val_size+1];
117   - err = clGetProgramBuildInfo(program, devices[deviceUsed], CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
118   - build_log[ret_val_size] = '\0';
119   - printf("BUILD LOG: \n %s", build_log);
120   - //}
121   - printf("program built\n");
122   -}
123   -
63 info/c/cll.h
... ... @@ -1,63 +0,0 @@
1   -#ifndef ADVCL_CLL_H_INCLUDED
2   -#define ADVCL_CLL_H_INCLUDED
3   -
4   -#if defined __APPLE__ || defined(MACOSX)
5   - #include <OpenCL/opencl.h>
6   -#else
7   - #include <CL/opencl.h>
8   -#endif
9   -
10   -class CL {
11   - public:
12   -
13   - //These are arrays we will use in this tutorial
14   - cl_mem cl_a;
15   - cl_mem cl_b;
16   - cl_mem cl_c;
17   - int num; //the size of our arrays
18   -
19   -
20   - size_t workGroupSize[1]; //N dimensional array of workgroup size we must pass to the kernel
21   -
22   - //default constructor initializes OpenCL context and automatically chooses platform and device
23   - CL();
24   - //default destructor releases OpenCL objects and frees device memory
25   - ~CL();
26   -
27   - //load an OpenCL program from a file
28   - //the path is relative to the CL_SOURCE_DIR set in CMakeLists.txt
29   - void loadProgram(const char* relative_path);
30   -
31   - //setup the data for the kernel
32   - //these are implemented in part1.cpp (in the future we will make these more general)
33   - void popCorn();
34   - //execute the kernel
35   - void runKernel();
36   -
37   - private:
38   -
39   - //handles for creating an opencl context
40   - cl_platform_id platform;
41   -
42   - //device variables
43   - cl_device_id* devices;
44   - cl_uint numDevices;
45   - unsigned int deviceUsed;
46   -
47   - cl_context context;
48   -
49   - cl_command_queue command_queue;
50   - cl_program program;
51   - cl_kernel kernel;
52   -
53   -
54   - //debugging variables
55   - cl_int err;
56   - cl_event event;
57   -
58   - //buildExecutable is called by loadProgram
59   - //build runtime executable from a program
60   - void buildExecutable();
61   -};
62   -
63   -#endif
27 info/c/main.cpp
... ... @@ -1,27 +0,0 @@
1   -/*
2   - * Adventures in OpenCL tutorial series
3   - * Part 1
4   - *
5   - * author: Ian Johnson
6   - * code based on advisor Gordon Erlebacher's work
7   - * NVIDIA's examples
8   - * as well as various blogs and resources on the internet
9   - */
10   -#include <stdio.h>
11   -#include <util.h>
12   -
13   -#if defined __APPLE__ || defined(MACOSX)
14   - #include <OpenCL/opencl.h>
15   -#else
16   - #include <CL/opencl.h>
17   -#endif
18   -
19   -
20   -int main(int argc, char** argv)
21   -{
22   - printf("Hello, OpenCL\n");
23   -
24   - //printf("oclGetPlatformID: %s\n", oclErrorString(err));
25   -
26   -
27   -}
6 info/c/part1.cl
... ... @@ -1,6 +0,0 @@
1   -__kernel void part1(__global float* a, __global float* b, __global float* c)
2   -{
3   - unsigned int i = get_global_id(0);
4   -
5   - c[i] = a[i] + b[i];
6   -}
80 info/c/part1.cpp
... ... @@ -1,80 +0,0 @@
1   -#include <stdio.h>
2   -
3   -#include "cll.h"
4   -#include "util.h"
5   -
6   -void CL::popCorn()
7   -{
8   - printf("in popCorn\n");
9   -
10   - //initialize our kernel from the program
11   - kernel = clCreateKernel(program, "part1", &err);
12   - printf("clCreateKernel: %s\n", oclErrorString(err));
13   -
14   - //initialize our CPU memory arrays, send them to the device and set the kernel arguements
15   - num = 10;
16   - float *a = new float[num];
17   - float *b = new float[num];
18   - for(int i=0; i < num; i++)
19   - {
20   - a[i] = 1.0f * i;
21   - b[i] = 1.0f * i;
22   - }
23   -
24   - printf("Creating OpenCL arrays\n");
25   - //our input arrays
26   - //create our OpenCL buffer for a, copying the data from CPU to the GPU at the same time
27   - cl_a = clCreateBuffer(context, CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR, sizeof(float) * num, a, &err);
28   - //cl_b = clCreateBuffer(context, CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR, sizeof(float) * num, b, &err);
29   - //we could do b similar, but you may want to create your buffer and fill it at a different time
30   - cl_b = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(float) * num, NULL, &err);
31   - //our output array
32   - cl_c = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(float) * num, NULL, &err);
33   -
34   - printf("Pushing data to the GPU\n");
35   - //push our CPU arrays to the GPU
36   -// err = clEnqueueWriteBuffer(command_queue, cl_a, CL_TRUE, 0, sizeof(float) * num, a, 0, NULL, &event);
37   -// clReleaseEvent(event); //we need to release events in order to be completely clean (has to do with openclprof)
38   -//
39   - //push b's data to the GPU
40   - err = clEnqueueWriteBuffer(command_queue, cl_b, CL_TRUE, 0, sizeof(float) * num, b, 0, NULL, &event);
41   - clReleaseEvent(event);
42   -
43   -
44   - //set the arguements of our kernel
45   - err = clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *) &cl_a);
46   - err = clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *) &cl_b);
47   - err = clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *) &cl_c);
48   - //Wait for the command queue to finish these commands before proceeding
49   - clFinish(command_queue);
50   -
51   - //clean up allocated space.
52   - delete[] a;
53   - delete[] b;
54   -
55   - //for now we make the workgroup size the same as the number of elements in our arrays
56   - workGroupSize[0] = num;
57   -}
58   -
59   -void CL::runKernel()
60   -{
61   - printf("in runKernel\n");
62   - //execute the kernel
63   - err = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, workGroupSize, NULL, 0, NULL, &event);
64   - clReleaseEvent(event);
65   - printf("clEnqueueNDRangeKernel: %s\n", oclErrorString(err));
66   - clFinish(command_queue);
67   -
68   - //lets check our calculations by reading from the device memory and printing out the results
69   - float c_done[num];
70   - err = clEnqueueReadBuffer(command_queue, cl_c, CL_TRUE, 0, sizeof(float) * num, &c_done, 0, NULL, &event);
71   - printf("clEnqueueReadBuffer: %s\n", oclErrorString(err));
72   - clReleaseEvent(event);
73   -
74   - for(int i=0; i < num; i++)
75   - {
76   - printf("c_done[%d] = %g\n", i, c_done[i]);
77   - }
78   -}
79   -
80   -
192 info/c/util.cpp
... ... @@ -1,192 +0,0 @@
1   -#include <math.h>
2   -#include <stdio.h>
3   -#include <stdlib.h>
4   -#include <string>
5   -#include <string.h>
6   -
7   -
8   -#include "cll.h"
9   -#include "util.h"
10   -
11   -char *file_contents(const char *filename, int *length)
12   -{
13   - FILE *f = fopen(filename, "r");
14   - void *buffer;
15   -
16   - if (!f) {
17   - fprintf(stderr, "Unable to open %s for reading\n", filename);
18   - return NULL;
19   - }
20   -
21   - fseek(f, 0, SEEK_END);
22   - *length = ftell(f);
23   - fseek(f, 0, SEEK_SET);
24   -
25   - buffer = malloc(*length+1);
26   - *length = fread(buffer, 1, *length, f);
27   - fclose(f);
28   - ((char*)buffer)[*length] = '\0';
29   -
30   - return (char*)buffer;
31   -}
32   -
33   -
34   -
35   -//NVIDIA's code follows
36   -//license issues probably prevent you from using this, but shouldn't take long
37   -//to reimplement
38   -//////////////////////////////////////////////////////////////////////////////
39   -//! Gets the platform ID for NVIDIA if available, otherwise default to platform 0
40   -//!
41   -//! @return the id
42   -//! @param clSelectedPlatformID OpenCL platform ID
43   -//////////////////////////////////////////////////////////////////////////////
44   -cl_int oclGetPlatformID(cl_platform_id* clSelectedPlatformID)
45   -{
46   - char chBuffer[1024];
47   - cl_uint num_platforms;
48   - cl_platform_id* clPlatformIDs;
49   - cl_int ciErrNum;
50   - *clSelectedPlatformID = NULL;
51   - cl_uint i = 0;
52   -
53   - // Get OpenCL platform count
54   - ciErrNum = clGetPlatformIDs (0, NULL, &num_platforms);
55   - if (ciErrNum != CL_SUCCESS)
56   - {
57   - //shrLog(" Error %i in clGetPlatformIDs Call !!!\n\n", ciErrNum);
58   - printf(" Error %i in clGetPlatformIDs Call !!!\n\n", ciErrNum);
59   - return -1000;
60   - }
61   - else
62   - {
63   - if(num_platforms == 0)
64   - {
65   - //shrLog("No OpenCL platform found!\n\n");
66   - printf("No OpenCL platform found!\n\n");
67   - return -2000;
68   - }
69   - else
70   - {
71   - // if there's a platform or more, make space for ID's
72   - if ((clPlatformIDs = (cl_platform_id*)malloc(num_platforms * sizeof(cl_platform_id))) == NULL)
73   - {
74   - //shrLog("Failed to allocate memory for cl_platform ID's!\n\n");
75   - printf("Failed to allocate memory for cl_platform ID's!\n\n");
76   - return -3000;
77   - }
78   -
79   - // get platform info for each platform and trap the NVIDIA platform if found
80   - ciErrNum = clGetPlatformIDs (num_platforms, clPlatformIDs, NULL);
81   - printf("Available platforms:\n");
82   - for(i = 0; i < num_platforms; ++i)
83   - {
84   - ciErrNum = clGetPlatformInfo (clPlatformIDs[i], CL_PLATFORM_NAME, 1024, &chBuffer, NULL);
85   - if(ciErrNum == CL_SUCCESS)
86   - {
87   - printf("platform %d: %s\n", i, chBuffer);
88   - if(strstr(chBuffer, "NVIDIA") != NULL)
89   - {
90   - printf("selected platform %d\n", i);
91   - *clSelectedPlatformID = clPlatformIDs[i];
92   - break;
93   - }
94   - }
95   - }
96   -
97   - // default to zeroeth platform if NVIDIA not found
98   - if(*clSelectedPlatformID == NULL)
99   - {
100   - //shrLog("WARNING: NVIDIA OpenCL platform not found - defaulting to first platform!\n\n");
101   - //printf("WARNING: NVIDIA OpenCL platform not found - defaulting to first platform!\n\n");
102   - printf("selected platform: %d\n", 0);
103   - *clSelectedPlatformID = clPlatformIDs[0];
104   - }
105   -
106   - free(clPlatformIDs);
107   - }
108   - }
109   -
110   - return CL_SUCCESS;
111   -}
112   -
113   -
114   -// Helper function to get error string
115   -// *********************************************************************
116   -const char* oclErrorString(cl_int error)
117   -{
118   - static const char* errorString[] = {
119   - "CL_SUCCESS",
120   - "CL_DEVICE_NOT_FOUND",
121   - "CL_DEVICE_NOT_AVAILABLE",
122   - "CL_COMPILER_NOT_AVAILABLE",
123   - "CL_MEM_OBJECT_ALLOCATION_FAILURE",
124   - "CL_OUT_OF_RESOURCES",
125   - "CL_OUT_OF_HOST_MEMORY",
126   - "CL_PROFILING_INFO_NOT_AVAILABLE",
127   - "CL_MEM_COPY_OVERLAP",
128   - "CL_IMAGE_FORMAT_MISMATCH",
129   - "CL_IMAGE_FORMAT_NOT_SUPPORTED",
130   - "CL_BUILD_PROGRAM_FAILURE",
131   - "CL_MAP_FAILURE",
132   - "",
133   - "",
134   - "",
135   - "",
136   - "",
137   - "",
138   - "",
139   - "",
140   - "",
141   - "",
142   - "",
143   - "",
144   - "",
145   - "",
146   - "",
147   - "",
148   - "",
149   - "CL_INVALID_VALUE",
150   - "CL_INVALID_DEVICE_TYPE",
151   - "CL_INVALID_PLATFORM",
152   - "CL_INVALID_DEVICE",
153   - "CL_INVALID_CONTEXT",
154   - "CL_INVALID_QUEUE_PROPERTIES",
155   - "CL_INVALID_COMMAND_QUEUE",
156   - "CL_INVALID_HOST_PTR",
157   - "CL_INVALID_MEM_OBJECT",
158   - "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR",
159   - "CL_INVALID_IMAGE_SIZE",
160   - "CL_INVALID_SAMPLER",
161   - "CL_INVALID_BINARY",
162   - "CL_INVALID_BUILD_OPTIONS",
163   - "CL_INVALID_PROGRAM",
164   - "CL_INVALID_PROGRAM_EXECUTABLE",
165   - "CL_INVALID_KERNEL_NAME",
166   - "CL_INVALID_KERNEL_DEFINITION",
167   - "CL_INVALID_KERNEL",
168   - "CL_INVALID_ARG_INDEX",
169   - "CL_INVALID_ARG_VALUE",
170   - "CL_INVALID_ARG_SIZE",
171   - "CL_INVALID_KERNEL_ARGS",
172   - "CL_INVALID_WORK_DIMENSION",
173   - "CL_INVALID_WORK_GROUP_SIZE",
174   - "CL_INVALID_WORK_ITEM_SIZE",
175   - "CL_INVALID_GLOBAL_OFFSET",
176   - "CL_INVALID_EVENT_WAIT_LIST",
177   - "CL_INVALID_EVENT",
178   - "CL_INVALID_OPERATION",
179   - "CL_INVALID_GL_OBJECT",
180   - "CL_INVALID_BUFFER_SIZE",
181   - "CL_INVALID_MIP_LEVEL",
182   - "CL_INVALID_GLOBAL_WORK_SIZE",
183   - };
184   -
185   - const int errorCount = sizeof(errorString) / sizeof(errorString[0]);
186   -
187   - const int index = -error;
188   -
189   - return (index >= 0 && index < errorCount) ? errorString[index] : "";
190   -
191   -}
192   -
12 info/c/util.h
... ... @@ -1,12 +0,0 @@
1   -//from http://www.songho.ca/opengl/gl_vbo.html
2   -
3   -#ifndef ADVCL_UTIL_H_INCLUDED
4   -#define ADVCL_UTIL_H_INCLUDED
5   -
6   -char *file_contents(const char *filename, int *length);
7   -
8   -cl_int oclGetPlatformID(cl_platform_id* clSelectedPlatformID);
9   -const char* oclErrorString(cl_int error);
10   -
11   -
12   -#endif
66 info/cpp/main.cpp
@@ -55,16 +55,68 @@ int main(int argc, char** argv)
55 55 for(int j = 0; j < devices.size(); j++)
56 56 {
57 57 cl::Device d = devices[j];
58   - printf("====== Device %d ======\n", j);
59   - printf("Type: %s\n", GetCLPropertyString(d.getInfo<CL_DEVICE_TYPE>()) );
60   - printf("Name: %s\n", d.getInfo<CL_DEVICE_NAME>().c_str() );
  58 + //printf("Type: %s\n", GetCLPropertyString(d.getInfo<CL_DEVICE_TYPE>()) );
  59 + const char* type = oclPropDevice(d.getInfo<CL_DEVICE_TYPE>());
  60 + printf("====== Device %d (%s) ======\n", j, type);
  61 + string name = d.getInfo<CL_DEVICE_NAME>();
  62 + printf(" Name: %s\n", name.c_str());
61 63
62   - //Number of parallel compute cores on the device
63   - printf("Max Compute Units: %d\n", d.getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>() );
64 64 //Maximum dimensions that specify the global and local work-item
65 65 //IDs used by the data parallel execution model
66   - printf("Max Dimensions: %d\n", d.getInfo<CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS>() );
67   - printf("======================\n");
  66 + int dimensions = d.getInfo<CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS>();
  67 + printf(" Max Dimensions: %d\n", dimensions);
  68 +
  69 + //Maximum work item sizes in each dimension
  70 + vector<long unsigned int> max_wi_sizes = d.getInfo<CL_DEVICE_MAX_WORK_ITEM_SIZES>();
  71 + printf(" Max Work Item Sizes: ");
  72 + for(int k = 0; k < dimensions; k++)
  73 + printf("%zd ", max_wi_sizes[k]);
  74 + printf("\n");
  75 +
  76 + //Maximum work group size
  77 + printf(" Max Work Group Size: %zd\n", d.getInfo<CL_DEVICE_MAX_WORK_GROUP_SIZE>() );
  78 +
  79 +
  80 +
  81 + printf(" Memory:\n ------\n");
  82 + unsigned long global_size = (unsigned long)d.getInfo<CL_DEVICE_GLOBAL_MEM_SIZE>();
  83 + printf(" Global Memory Size: %ld (bytes) or %4.0f (MB)\n", global_size, global_size / 1048576.0);
  84 + unsigned long alloc_size = (unsigned long)d.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>();
  85 + printf(" Max Mem Alloc Size: %ld (bytes) or %4.0f (MB)\n", alloc_size, alloc_size / 1048576.0);
  86 + unsigned long cache_size = (unsigned long)d.getInfo<CL_DEVICE_GLOBAL_MEM_CACHE_SIZE>();
  87 + printf(" Global Memory Cache Size: %ld (bytes) or %4.0f (MB)\n", cache_size, cache_size / 1048576.0);
  88 + printf(" Global Memory Cache Type: %s\n", oclPropCache(d.getInfo<CL_DEVICE_GLOBAL_MEM_CACHE_TYPE>()) );
  89 + printf("\n");
  90 + unsigned long local_size = (unsigned long)d.getInfo<CL_DEVICE_LOCAL_MEM_SIZE>();
  91 + printf(" Local Memory Size: %ld (bytes) or %4.0f (KB)\n", local_size, local_size / 1024.0);
  92 + printf(" Local Memory Type: %s\n", oclPropMem(d.getInfo<CL_DEVICE_LOCAL_MEM_TYPE>()) );
  93 + printf("\n");
  94 + unsigned long constant_size = (unsigned long)d.getInfo<CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE>();
  95 + printf(" Constant Memory Size: %ld (bytes) or %4.0f (KB)\n", constant_size, constant_size / 1024.0 );
  96 + int constant_args = d.getInfo<CL_DEVICE_MAX_CONSTANT_ARGS>();
  97 + printf(" Max Constant Args: %d\n", constant_args);
  98 + //1.1 only
  99 + //printf("\n");
  100 + //printf(" Unified Memory: %s\n", d.getInfo<CL_DEVICE_HOST_UNIFIED_MEMORY>() ? "True" : "False");
  101 + printf(" ------\n");
  102 +
  103 +
  104 + printf(" Image support: %s\n", d.getInfo<CL_DEVICE_IMAGE_SUPPORT>() ? "True" : "False");
  105 + //Number of parallel compute cores on the device
  106 + printf(" Max Compute Units: %d\n", d.getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>() );
  107 + printf(" Default Address Size: %dbit\n", (int)d.getInfo<CL_DEVICE_ADDRESS_BITS>() );
  108 + printf("\n");
  109 + //OpenCL version supported by the device
  110 + const char* device_version = d.getInfo<CL_DEVICE_VERSION>().c_str();
  111 + printf(" Device Version: %s\n", device_version);
  112 + const char* device_extensions = d.getInfo<CL_DEVICE_EXTENSIONS>().c_str();
  113 + printf(" Device Extensions: %s\n", device_extensions);
  114 + //1.1 only
  115 + //const char* clc_version = d.getInfo<CL_DEVICE_OPENCL_C_VERSION>();
  116 + //printf(" Device Version: %s\n", clc_version);
  117 +
  118 +
  119 + printf("======================\n\n");
68 120 }
69 121
70 122
37 info/cpp/util.cpp
@@ -32,7 +32,7 @@ char *file_contents(const char *filename, int *length)
32 32
33 33 //Some hacked together stuff to print out nice names for OpenCL enums
34 34 //filling it in as I go so it wont have all of them
35   -const char* GetCLPropertyString(int prop)
  35 +const char* oclPropDevice(int prop)
36 36 {
37 37 switch(prop)
38 38 {
@@ -48,8 +48,39 @@ const char* GetCLPropertyString(int prop)
48 48 case(CL_DEVICE_TYPE_DEFAULT):
49 49 return "DEFAULT";
50 50 break;
51   -
52   -
  51 + default:
  52 + return "UNKOWN";
  53 + break;
  54 + }
  55 +}
  56 +const char* oclPropCache(int prop)
  57 +{
  58 + switch(prop)
  59 + {
  60 + case(CL_NONE):
  61 + return "None";
  62 + break;
  63 + case(CL_READ_ONLY_CACHE):
  64 + return "Read Only";
  65 + break;
  66 + case(CL_READ_WRITE_CACHE):
  67 + return "Read-Write";
  68 + break;
  69 + }
  70 +}
  71 +const char* oclPropMem(int prop)
  72 +{
  73 + switch(prop)
  74 + {
  75 + case(CL_LOCAL):
  76 + return "Local";
  77 + break;
  78 + case(CL_GLOBAL):
  79 + return "Global";
  80 + break;
  81 + default:
  82 + return "UNKOWN";
  83 + break;
53 84 }
54 85 }
55 86
4 info/cpp/util.h
@@ -8,6 +8,8 @@ char *file_contents(const char *filename, int *length);
8 8 cl_int oclGetPlatformID(cl_platform_id* clSelectedPlatformID);
9 9 const char* oclErrorString(cl_int error);
10 10
11   -const char* GetCLPropertyString(int prop);
  11 +const char* oclPropDevice(int prop);
  12 +const char* oclPropCache(int prop);
  13 +const char* oclPropMem(int prop);
12 14
13 15 #endif

0 comments on commit 8e2fa2d

Please sign in to comment.
Something went wrong with that request. Please try again.