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

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