Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/vis12-cl/src/lib/cl-target/ocl-support.c
ViewVC logotype

Annotation of /branches/vis12-cl/src/lib/cl-target/ocl-support.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3133 - (view) (download) (as text)

1 : jhr 2738 /*! \file ocl-support.c
2 : jhr 1671 *
3 :     * \author John Reppy
4 :     *
5 : jhr 2736 * \brief This file contains support code for the OpenCL target. It includes functions
6 :     * that can be used to determine properties of the host machine's OpenCL support.
7 : jhr 1671 */
8 :    
9 :     /*
10 : jhr 2761 * COPYRIGHT (c) 2014 The Diderot Project (http://diderot-language.cs.uchicago.edu)
11 : jhr 1671 * All rights reserved.
12 :     */
13 :    
14 : jhr 2738 #ifndef DIDEROT_TARGET_CL
15 :     # define DIDEROT_TARGET_CL
16 :     #endif
17 :    
18 : jhr 3121 #include "Diderot/diderot.h"
19 : jhr 1671 #include <stdio.h>
20 :     #include <string.h>
21 :     #include <stdlib.h>
22 : jhr 2738 #include <sys/stat.h>
23 : jhr 1671
24 : jhr 2761 #define MAX_PLATFORMS 16
25 : jhr 1671
26 : jhr 2738 static bool GetDevices (WorldPrefix_t *wrld, unsigned int platIdx, Diderot_PlatformInfo_t *plat);
27 : jhr 1671
28 : jhr 2761 #define CHECK(call) do { \
29 :     cl_int __sts = call; \
30 :     if (__sts != CL_SUCCESS) { \
31 :     biffMsgAddf(wrld->errors, "error at %s:%d: %s\n", \
32 :     __FILE__, __LINE__, Diderot_OCLErrorString(__sts)); \
33 :     return 0; \
34 :     } \
35 : jhr 1671 } while (0)
36 :    
37 : jhr 2738 Diderot_OCLInfo_t *Diderot_GetCLInfo (WorldPrefix_t *wrld)
38 : jhr 2075 {
39 : jhr 2761 cl_platform_id platformIDs[MAX_PLATFORMS];
40 : jhr 1671 char buf[512];
41 :    
42 :     // get platform info
43 :     // get number of OpenCL platforms
44 :     cl_uint numPlatforms;
45 :     CHECK(clGetPlatformIDs (MAX_PLATFORMS, platformIDs, &numPlatforms));
46 :    
47 : jhr 2738 Diderot_PlatformInfo_t *plats = NEWVEC(Diderot_PlatformInfo_t, numPlatforms);
48 : jhr 2075 for (unsigned int i = 0; i < numPlatforms; i++) {
49 : jhr 1671 clGetPlatformInfo (platformIDs[i], CL_PLATFORM_NAME, sizeof(buf), buf, 0);
50 :     plats[i].name = NEWSTR(buf);
51 :     plats[i].id = platformIDs[i];
52 :     // get OpenCL version info
53 :     clGetPlatformInfo (platformIDs[i], CL_PLATFORM_VERSION, sizeof(buf), buf, 0);
54 :     // get extension info
55 :     // FIXME: TODO
56 :     // get device info
57 : jhr 2738 if (GetDevices (wrld, i, &(plats[i]))) {
58 : jhr 1671 // free storage
59 : jhr 2075 for (unsigned int j = 0; j <= i; j++) {
60 : jhr 1671 free (plats[i].name);
61 :     }
62 :     free (plats);
63 : jhr 2761 return 0;
64 : jhr 1671 }
65 :     }
66 :    
67 : jhr 2736 Diderot_OCLInfo_t *info = NEW(Diderot_OCLInfo_t);
68 : jhr 1671 info->numPlatforms = numPlatforms;
69 :     info->platforms = plats;
70 :    
71 :     return info;
72 :    
73 :     }
74 :    
75 :     static char *GetStringInfo (cl_device_id dev, cl_device_info param)
76 :     {
77 :     char buf[1024];
78 : jhr 2738 cl_int sts = clGetDeviceInfo (dev, param, sizeof(buf), buf, 0);
79 :     if (sts != CL_SUCCESS)
80 : jhr 2761 return 0;
81 : jhr 2738 else
82 : jhr 2761 return NEWSTR(buf);
83 : jhr 1671 }
84 :    
85 : jhr 2738 static bool GetDevices (WorldPrefix_t *wrld, unsigned int platIdx, Diderot_PlatformInfo_t *plat)
86 : jhr 1671 {
87 :     cl_uint numDevs;
88 :     char buf[512];
89 :    
90 :     // get number of devices for the platform
91 :     clGetDeviceIDs (plat->id, CL_DEVICE_TYPE_ALL, 0, 0, &numDevs);
92 :    
93 :     if (numDevs == 0) {
94 :     plat->numDevices = 0;
95 :     plat->devices = 0;
96 :     return false;
97 :     }
98 :    
99 :     plat->numDevices = numDevs;
100 : jhr 2738 plat->devices = NEWVEC(Diderot_DeviceInfo_t, numDevs);
101 : jhr 1671
102 :     cl_device_id *devices = NEWVEC(cl_device_id, numDevs);
103 :     CHECK(clGetDeviceIDs (plat->id, CL_DEVICE_TYPE_ALL, numDevs, devices, 0));
104 :    
105 : jhr 2075 for (unsigned int i = 0; i < numDevs; i++) {
106 : jhr 2738 Diderot_DeviceInfo_t *dev = &(plat->devices[i]);
107 : jhr 2761 dev->index[0] = platIdx;
108 :     dev->index[1] = i;
109 : jhr 2738 if ((dev->name = GetStringInfo(devices[i], CL_DEVICE_NAME)) == 0) {
110 : jhr 2761 biffMsgAdd (wrld->errors, "error getting device name\n");
111 : jhr 2738 return true;
112 : jhr 2761 }
113 : jhr 2738 if ((dev->vendor = GetStringInfo(devices[i], CL_DEVICE_VENDOR)) == 0) {
114 : jhr 2761 biffMsgAdd (wrld->errors, "error getting device vendor\n");
115 : jhr 2738 return true;
116 : jhr 2761 }
117 : jhr 1671 dev->id = devices[i];
118 :     CHECK(clGetDeviceInfo (
119 :     devices[i], CL_DEVICE_VERSION, sizeof(buf), buf, 0));
120 :     if (sscanf (buf, "OpenCL %d.%d", &(dev->majorVersion), &(dev->minorVersion)) != 2) {
121 : jhr 2761 biffMsgAddf (wrld->errors, "error scanning version string: \"%s\"\n", buf);
122 : jhr 2738 return true;
123 : jhr 1671 }
124 :     CHECK(clGetDeviceInfo (
125 :     devices[i], CL_DEVICE_TYPE, sizeof(cl_device_type), &(dev->ty), 0));
126 :     CHECK(clGetDeviceInfo (
127 :     devices[i], CL_DEVICE_AVAILABLE, sizeof(cl_bool), &(dev->isAvail), 0));
128 :     CHECK(clGetDeviceInfo (
129 :     devices[i], CL_DEVICE_ADDRESS_BITS, sizeof(cl_uint), &(dev->addrBits), 0));
130 :     CHECK(clGetDeviceInfo (
131 :     devices[i], CL_DEVICE_ENDIAN_LITTLE, sizeof(cl_bool), &(dev->littleEndian), 0));
132 :     CHECK(clGetDeviceInfo (
133 :     devices[i], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), &(dev->numCUs), 0));
134 :     CHECK(clGetDeviceInfo (
135 :     devices[i], CL_DEVICE_MAX_CONSTANT_ARGS, sizeof(cl_uint), &(dev->maxConstArgs), 0));
136 :     CHECK(clGetDeviceInfo (
137 :     devices[i], CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(cl_uint), &(dev->maxWIDims), 0));
138 :     CHECK(clGetDeviceInfo (
139 :     devices[i], CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), &(dev->maxWGSize), 0));
140 :     size_t szb = sizeof(size_t) * dev->maxWIDims;
141 :     dev->maxWISize = (size_t *) CheckedAlloc (szb);
142 :     CHECK(clGetDeviceInfo (devices[i], CL_DEVICE_MAX_WORK_ITEM_SIZES, szb, dev->maxWISize, 0));
143 :     CHECK(clGetDeviceInfo (
144 :     devices[i], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(cl_ulong), &(dev->globalMemSzb), 0));
145 :     CHECK(clGetDeviceInfo (
146 :     devices[i], CL_DEVICE_LOCAL_MEM_SIZE, sizeof(cl_ulong), &(dev->localMemSzb), 0));
147 :     CHECK(clGetDeviceInfo (
148 :     devices[i], CL_DEVICE_MAX_PARAMETER_SIZE, sizeof(size_t), &(dev->maxParamSzb), 0));
149 :     CHECK(clGetDeviceInfo (
150 :     devices[i], CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, sizeof(cl_ulong), &(dev->maxConstBufSzb), 0));
151 :     CHECK(clGetDeviceInfo (
152 :     devices[i], CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(cl_ulong), &(dev->maxAllocSzb), 0));
153 :     cl_bool imagesSupported;
154 :     CHECK(clGetDeviceInfo (
155 :     devices[i], CL_DEVICE_IMAGE_SUPPORT, sizeof(cl_bool), &imagesSupported, 0));
156 :     if (imagesSupported) {
157 :     CHECK(clGetDeviceInfo (
158 :     devices[i], CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof(size_t), &(dev->maxImg2D[0]), 0));
159 :     CHECK(clGetDeviceInfo (
160 :     devices[i], CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof(size_t), &(dev->maxImg2D[1]), 0));
161 :     CHECK(clGetDeviceInfo (
162 :     devices[i], CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof(size_t), &(dev->maxImg3D[0]), 0));
163 :     CHECK(clGetDeviceInfo (
164 :     devices[i], CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof(size_t), &(dev->maxImg3D[1]), 0));
165 :     CHECK(clGetDeviceInfo (
166 :     devices[i], CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof(size_t), &(dev->maxImg3D[2]), 0));
167 :     }
168 :     else {
169 :     dev->maxImg2D[0] = dev->maxImg2D[1] = 0;
170 :     dev->maxImg3D[0] = dev->maxImg3D[1] = dev->maxImg3D[2] = 0;
171 :     }
172 :     CHECK(clGetDeviceInfo (
173 :     devices[i], CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, sizeof(cl_uint), &(dev->charWid), 0));
174 :     CHECK(clGetDeviceInfo (
175 :     devices[i], CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, sizeof(cl_uint), &(dev->shortWid), 0));
176 :     CHECK(clGetDeviceInfo (
177 :     devices[i], CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, sizeof(cl_uint), &(dev->intWid), 0));
178 :     CHECK(clGetDeviceInfo (
179 :     devices[i], CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, sizeof(cl_uint), &(dev->longWid), 0));
180 :     CHECK(clGetDeviceInfo (
181 :     devices[i], CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, sizeof(cl_uint), &(dev->floatWid), 0));
182 :     CHECK(clGetDeviceInfo (
183 :     devices[i], CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, sizeof(cl_uint), &(dev->doubleWid), 0));
184 :     // determine the compute-unit width
185 : jhr 2738 if (Diderot_isCPUDevice(dev))
186 : jhr 1671 dev->cuWidth = 1;
187 : jhr 2738 else if (Diderot_isGPUDevice(dev))
188 : jhr 1671 if (strcasecmp("AMD", dev->vendor) == 0)
189 :     dev->cuWidth = 64; // an AMD wavefront is 64-wide
190 :     else if (strcasecmp("NVIDIA", dev->vendor) == 0)
191 :     dev->cuWidth = 32; // an NVIDIA warp is 32-wide
192 :     else
193 :     dev->cuWidth = 32; // FIXME: not sure what this should be?
194 :     else
195 :     dev->cuWidth = 1; // FIXME: not sure what this should be?
196 :    
197 :     }
198 :    
199 :     free(devices);
200 :    
201 : jhr 2738 return false;
202 : jhr 1671 }
203 :    
204 : jhr 2075 /*! \brief return the device with the given index.
205 :     */
206 : jhr 2738 Diderot_DeviceInfo_t *Diderot_GetDeviceByIndex (Diderot_OCLInfo_t *clinfo, unsigned int platIdx, unsigned int devIdx)
207 : jhr 1671 {
208 : jhr 2075 if ((clinfo == 0)
209 :     || (clinfo->numPlatforms <= platIdx)
210 :     || (clinfo->platforms[platIdx].numDevices <= devIdx))
211 : jhr 2761 return 0;
212 : jhr 2075 else
213 : jhr 2761 return &(clinfo->platforms[platIdx].devices[devIdx]);
214 : jhr 2075 }
215 :    
216 : jhr 2736 void Diderot_PrintCLInfo (FILE *outS, Diderot_OCLInfo_t *clinfo)
217 : jhr 2075 {
218 : jhr 1671 if (clinfo->numPlatforms == 0) {
219 :     fprintf(outS, "No OpenCL platforms\n");
220 :     return;
221 :     }
222 :    
223 :     fprintf(outS, "OpenCL profile:\n");
224 : jhr 2075 for (unsigned int i = 0; i < clinfo->numPlatforms; i++) {
225 : jhr 2738 Diderot_PlatformInfo_t *plat = &(clinfo->platforms[i]);
226 : jhr 1671 fprintf (outS, " Platform %d (%s)\n", i, plat->name);
227 : jhr 2075 for (unsigned int j = 0; j < plat->numDevices; j++) {
228 : jhr 2738 Diderot_DeviceInfo_t *dev = &(plat->devices[j]);
229 : jhr 1671 if (dev->isAvail)
230 :     fprintf (outS, " Device %d.%d (%s):\n", i, j, dev->name);
231 :     else
232 :     fprintf (outS, " Device %d.%d (%s): **UNAVAILABLE**\n", i, j, dev->name);
233 :     fprintf (outS, " Vendor: %s\n", dev->vendor);
234 :     fprintf (outS, " OpenCL version: %d.%d\n",
235 :     dev->majorVersion, dev->minorVersion);
236 :     fprintf (outS, " Type: ");
237 : jhr 2738 if (Diderot_isCPUDevice(dev)) fprintf (outS, " CPU");
238 :     if (Diderot_isGPUDevice(dev)) fprintf (outS, " GPU");
239 : jhr 1671 if (dev->ty & CL_DEVICE_TYPE_ACCELERATOR) fprintf (outS, " ACCELERATOR");
240 :     if (dev->ty & CL_DEVICE_TYPE_DEFAULT) fprintf (outS, " DEFAULT");
241 :     fprintf (outS, "\n");
242 :     fprintf (outS, " Address size: %d\n", dev->addrBits);
243 :     fprintf (outS, " Endianess: %s\n", dev->littleEndian ? "LITTLE" : "BIG");
244 :     fprintf (outS, " Num. compute units: %d", dev->numCUs);
245 :     if (dev->cuWidth > 1)
246 :     fprintf (outS, " * %d\n", dev->cuWidth);
247 :     else
248 :     fprintf (outS, "\n");
249 :     fprintf (outS, " Max. dimensions: %d\n", dev->maxWIDims);
250 :     fprintf (outS, " Max. work group size: %ld\n", (long)(dev->maxWGSize));
251 :     fprintf (outS, " Max. work items: ");
252 :     for (int k = 0; k < dev->maxWIDims; k++)
253 :     fprintf (outS, "%s%ld", (k > 0) ? " x " : "", (long)(dev->maxWISize[k]));
254 :     fprintf (outS, "\n");
255 :     fprintf (outS, " Global memory size: %ld\n", (long)(dev->globalMemSzb));
256 :     fprintf (outS, " Local memory size: %ld\n", (long)(dev->localMemSzb));
257 :     fprintf (outS, " Max. parameter size: %ld\n", (long)(dev->maxParamSzb));
258 :     fprintf (outS, " Max. allocation size: %ld\n", (long)(dev->maxAllocSzb));
259 :     fprintf (outS, " Max. const. buffer size: %ld\n", (long)(dev->maxConstBufSzb));
260 :     fprintf (outS, " Max. const. arguments: %d\n", dev->maxConstArgs);
261 :     fprintf (outS, " Max. 2D image size: %ld x %ld\n",
262 :     (long)(dev->maxImg2D[0]), (long)(dev->maxImg2D[1]));
263 :     fprintf (outS, " Max. 3D image size: %ld x %ld x %ld\n",
264 :     (long)(dev->maxImg3D[0]), (long)(dev->maxImg3D[1]), (long)(dev->maxImg3D[2]));
265 :     fprintf (outS, " Prefered vector width: char%d, short%d, int%d, long%d\n",
266 :     dev->charWid, dev->shortWid, dev->intWid, dev->longWid);
267 :     fprintf (outS, " float%d", dev->floatWid);
268 :     if (dev->doubleWid > 0)
269 :     fprintf (outS, ", double%d\n", dev->doubleWid);
270 :     else
271 :     fprintf (outS, "\n");
272 :     }
273 :     }
274 :    
275 :     }
276 : jhr 2075
277 : jhr 2736 Diderot_DeviceInfo_t *Diderot_DefaultCLDevice (Diderot_OCLInfo_t *clinfo)
278 : jhr 2075 {
279 :     if ((clinfo == 0) || (clinfo->numPlatforms == 0))
280 : jhr 2761 return 0;
281 : jhr 2075
282 :     // we pick the first GPU device that we find
283 :     for (unsigned int i = 0; i < clinfo->numPlatforms; i++) {
284 : jhr 2738 Diderot_PlatformInfo_t *plat = &(clinfo->platforms[i]);
285 : jhr 2075 for (unsigned int j = 0; j < plat->numDevices; j++) {
286 : jhr 2761 if (Diderot_isGPUDevice(&(plat->devices[j])))
287 :     return &(plat->devices[j]);
288 :     }
289 : jhr 2075 }
290 :    
291 :     // otherwise we pick a CPU device
292 :     for (unsigned int i = 0; i < clinfo->numPlatforms; i++) {
293 : jhr 2738 Diderot_PlatformInfo_t *plat = &(clinfo->platforms[i]);
294 : jhr 2075 for (unsigned int j = 0; j < plat->numDevices; j++) {
295 : jhr 2761 if (Diderot_isCPUDevice(&(plat->devices[j])))
296 :     return &(plat->devices[j]);
297 :     }
298 : jhr 2075 }
299 :    
300 :     // otherwise return 0
301 :     return 0;
302 :    
303 :     }
304 : jhr 2736
305 :     /*! \brief load OpenCL code from a file
306 :     */
307 : jhr 2738 cl_program Diderot_LoadProgramFromSource (WorldPrefix_t *wrld, cl_context cxt, const char *filename, cl_int *sts)
308 : jhr 2736 {
309 :     struct stat statbuf;
310 :     if (stat(filename, &statbuf) < 0) {
311 :     biffMsgAddf (wrld->errors, "unable to stat OpenCL source file %s\n", filename);
312 : jhr 2761 *sts = CL_INVALID_PROGRAM;
313 : jhr 2736 return 0;
314 :     }
315 :    
316 :     char *source = (char *)CheckedAlloc(statbuf.st_size + 1);
317 :     if (source == 0) {
318 :     biffMsgAddf (wrld->errors, "unable to allocate memory for OpenCL source\n");
319 : jhr 2761 *sts = CL_OUT_OF_HOST_MEMORY;
320 : jhr 2736 return 0;
321 :     }
322 :    
323 :     FILE *fh = fopen(filename, "r");
324 :     if ((fh == 0)
325 :     || (fread(source, statbuf.st_size, 1, fh) != 1)) {
326 :     biffMsgAddf (wrld->errors, "unable to read OpenCL source from %s\n", filename);
327 : jhr 2761 *sts = CL_INVALID_PROGRAM;
328 : jhr 2736 return 0;
329 :     }
330 :     source[statbuf.st_size] = '\0';
331 :     fclose (fh);
332 :    
333 : jhr 2738 cl_program prog = clCreateProgramWithSource(cxt, 1, (const char **)&source, NULL, sts);
334 : jhr 2736 free (source);
335 : jhr 2738 if (*sts != CL_SUCCESS) {
336 : jhr 2761 biffMsgAddf (wrld->errors, "error creating program: %s\n", Diderot_OCLErrorString(*sts));
337 : jhr 2736 return 0;
338 :     }
339 :    
340 :     return prog;
341 :     }
342 :    
343 :     // convert an OpenCL error code to a string
344 :     //
345 :     const char *Diderot_OCLErrorString (cl_int sts)
346 :     {
347 :     switch (sts) {
348 :     case CL_SUCCESS: return "Success!";
349 :     case CL_DEVICE_NOT_FOUND: return "Device not found.";
350 :     case CL_DEVICE_NOT_AVAILABLE: return "Device not available";
351 :     case CL_COMPILER_NOT_AVAILABLE: return "Compiler not available";
352 :     case CL_MEM_OBJECT_ALLOCATION_FAILURE: return "Memory object allocation failure";
353 :     case CL_OUT_OF_RESOURCES: return "Out of resources";
354 :     case CL_OUT_OF_HOST_MEMORY: return "Out of host memory";
355 :     case CL_PROFILING_INFO_NOT_AVAILABLE: return "Profiling information not available";
356 :     case CL_MEM_COPY_OVERLAP: return "Memory copy overlap";
357 :     case CL_IMAGE_FORMAT_MISMATCH: return "Image format mismatch";
358 :     case CL_IMAGE_FORMAT_NOT_SUPPORTED: return "Image format not supported";
359 :     case CL_BUILD_PROGRAM_FAILURE: return "Program build failure";
360 :     case CL_MAP_FAILURE: return "Map failure";
361 :     case CL_INVALID_VALUE: return "Invalid value";
362 :     case CL_INVALID_DEVICE_TYPE: return "Invalid device type";
363 :     case CL_INVALID_PLATFORM: return "Invalid platform";
364 :     case CL_INVALID_DEVICE: return "Invalid device";
365 :     case CL_INVALID_CONTEXT: return "Invalid context";
366 :     case CL_INVALID_QUEUE_PROPERTIES: return "Invalid queue properties";
367 :     case CL_INVALID_COMMAND_QUEUE: return "Invalid command queue";
368 :     case CL_INVALID_HOST_PTR: return "Invalid host pointer";
369 :     case CL_INVALID_MEM_OBJECT: return "Invalid memory object";
370 :     case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: return "Invalid image format descriptor";
371 :     case CL_INVALID_IMAGE_SIZE: return "Invalid image size";
372 :     case CL_INVALID_SAMPLER: return "Invalid sampler";
373 :     case CL_INVALID_BINARY: return "Invalid binary";
374 :     case CL_INVALID_BUILD_OPTIONS: return "Invalid build options";
375 :     case CL_INVALID_PROGRAM: return "Invalid program";
376 :     case CL_INVALID_PROGRAM_EXECUTABLE: return "Invalid program executable";
377 :     case CL_INVALID_KERNEL_NAME: return "Invalid kernel name";
378 :     case CL_INVALID_KERNEL_DEFINITION: return "Invalid kernel definition";
379 :     case CL_INVALID_KERNEL: return "Invalid kernel";
380 :     case CL_INVALID_ARG_INDEX: return "Invalid argument index";
381 :     case CL_INVALID_ARG_VALUE: return "Invalid argument value";
382 :     case CL_INVALID_ARG_SIZE: return "Invalid argument size";
383 :     case CL_INVALID_KERNEL_ARGS: return "Invalid kernel arguments";
384 :     case CL_INVALID_WORK_DIMENSION: return "Invalid work dimension";
385 :     case CL_INVALID_WORK_GROUP_SIZE: return "Invalid work group size";
386 :     case CL_INVALID_WORK_ITEM_SIZE: return "Invalid work item size";
387 :     case CL_INVALID_GLOBAL_OFFSET: return "Invalid global offset";
388 :     case CL_INVALID_EVENT_WAIT_LIST: return "Invalid event wait list";
389 :     case CL_INVALID_EVENT: return "Invalid event";
390 :     case CL_INVALID_OPERATION: return "Invalid operation";
391 :     case CL_INVALID_GL_OBJECT: return "Invalid OpenGL object";
392 :     case CL_INVALID_BUFFER_SIZE: return "Invalid buffer size";
393 :     case CL_INVALID_MIP_LEVEL: return "Invalid mip-map level";
394 : jhr 3130 case CL_INVALID_GLOBAL_WORK_SIZE: return "Invalid global work size";
395 :     case CL_INVALID_PROPERTY: return "Invalid property";
396 : jhr 3131 #ifdef CL_INVALID_IMAGE_DESCRIPTOR
397 : jhr 3130 case CL_INVALID_IMAGE_DESCRIPTOR: return "Invalid image descriptor";
398 : jhr 3131 #endif
399 :     #ifdef CL_INVALID_COMPILER_OPTIONS
400 : jhr 3130 case CL_INVALID_COMPILER_OPTIONS: return "Invalid compiler options";
401 : jhr 3131 #endif
402 : jhr 3133 #ifdef CL_INVALID_LINKER_OPTIONS
403 : jhr 3130 case CL_INVALID_LINKER_OPTIONS: return "Invalid linker options";
404 : jhr 3133 #endif
405 : jhr 3131 #ifdef CL_INVALID_LINKER_OPTIONS
406 : jhr 3130 case CL_INVALID_DEVICE_PARTITION_COUNT: return "Invalid device partition count";
407 : jhr 3131 #endif
408 : jhr 2736 default: return "Unknown error";
409 :     }
410 :    
411 :     }
412 : jhr 3127
413 :     /* get the OpenCL program binary */
414 :     unsigned char *Diderot_OCLGetBinary (WorldPrefix_t *wrld, cl_program prog, size_t *sizeOut)
415 :     {
416 :     cl_int sts;
417 :    
418 :     size_t sizes[1];
419 :     CHECK (clGetProgramInfo (prog, CL_PROGRAM_BINARY_SIZES, sizeof(size_t), sizes, 0));
420 :    
421 :     unsigned char *bufs[1];
422 :     bufs[0] = NEWVEC(unsigned char, sizes[0]);
423 :     CHECK (clGetProgramInfo (prog, CL_PROGRAM_BINARIES, sizes[0], bufs, sizeOut));
424 :    
425 :     return bufs[0];
426 :    
427 :     }
428 :    
429 :     bool Diderot_OCLSaveBinary (WorldPrefix_t *wrld, cl_program prog, const char *file)
430 :     {
431 :     size_t sizeb;
432 :     unsigned char *binary = Diderot_OCLGetBinary (wrld, prog, &sizeb);
433 :     if (binary == 0) {
434 :     return true;
435 :     }
436 :    
437 :     FILE *outS = fopen (file, "wb");
438 :     if (outS == NULL) {
439 :     return true;
440 :     }
441 :    
442 :     if (fwrite (binary, sizeb, 1, outS) < sizeb) {
443 :     fclose (outS);
444 :     return true;
445 :     }
446 :    
447 :     fclose (outS);
448 :    
449 :     return false;
450 :    
451 :     }

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0