Caffe2 - C++ API
A deep learning, cross platform ML framework
libopencl.c
1 /*
2  * Stub libopencl that dlsyms into actual library based on environment variable
3  *
4  * LIBOPENCL_SO_PATH -- Path to opencl so that will be searched first
5  * LIBOPENCL_SO_PATH_2 -- Searched second
6  * LIBOPENCL_SO_PATH_3 -- Searched third
7  * LIBOPENCL_SO_PATH_4 -- Searched fourth
8  *
9  * If none of these are set, default system paths will be considered
10 **/
11 
12 #include "libopencl.h"
13 
14 
15 #if defined(__APPLE__) || defined(__MACOSX)
16 static const char *default_so_paths[] = {
17  "libOpenCL.so"
18 };
19 #elif defined(__ANDROID__)
20 static const char *default_so_paths[] = {
21  "/system/lib/libOpenCL.so",
22  "/system/vendor/lib/libOpenCL.so",
23  "/system/vendor/lib/egl/libGLES_mali.so",
24  "/system/vendor/lib/libPVROCL.so",
25  "/data/data/org.pocl.libs/files/lib/libpocl.so",
26  "libOpenCL.so"
27 };
28 #elif defined(_WIN32)
29 static const char *default_so_paths[] = {
30  "OpenCL.dll"
31 };
32 #elif defined(__linux__)
33 static const char *default_so_paths[] = {
34  "/usr/lib/libOpenCL.so",
35  "/usr/local/lib/libOpenCL.so",
36  "/usr/local/lib/libpocl.so",
37  "/usr/lib64/libOpenCL.so",
38  "/usr/lib32/libOpenCL.so",
39  "libOpenCL.so"
40 };
41 #endif
42 
43 static void *so_handle = NULL;
44 
45 
46 static int access_file(const char *filename)
47 {
48  struct stat buffer;
49  return (stat(filename, &buffer) == 0);
50 }
51 
52 int open_libopencl_so()
53 {
54  char *path = NULL, *str = NULL;
55  int i;
56 
57  if((str=getenv("LIBOPENCL_SO_PATH")) && access_file(str)) {
58  path = str;
59  }
60  else if((str=getenv("LIBOPENCL_SO_PATH_2")) && access_file(str)) {
61  path = str;
62  }
63  else if((str=getenv("LIBOPENCL_SO_PATH_3")) && access_file(str)) {
64  path = str;
65  }
66  else if((str=getenv("LIBOPENCL_SO_PATH_4")) && access_file(str)) {
67  path = str;
68  }
69 
70  if(!path)
71  {
72  for(i=0; i<(sizeof(default_so_paths) / sizeof(char*)); i++)
73  {
74  if(access_file(default_so_paths[i]))
75  {
76  path = (char *) default_so_paths[i];
77  break;
78  }
79  }
80  }
81 
82  if(path)
83  {
84  so_handle = dlopen(path, RTLD_LAZY);
85  if(so_handle) {
86  return 0;
87  }
88  }
89 
90  return -1;
91 }
92 
93 cl_int get_libopencl_path(char** cl_path)
94 {
95  char *path = NULL, *str = NULL;
96  int i;
97 
98  if((str=getenv("LIBOPENCL_SO_PATH")) && access_file(str)) {
99  path = str;
100  }
101  else if((str=getenv("LIBOPENCL_SO_PATH_2")) && access_file(str)) {
102  path = str;
103  }
104  else if((str=getenv("LIBOPENCL_SO_PATH_3")) && access_file(str)) {
105  path = str;
106  }
107  else if((str=getenv("LIBOPENCL_SO_PATH_4")) && access_file(str)) {
108  path = str;
109  }
110 
111  if(!path)
112  {
113  for(i=0; i<(sizeof(default_so_paths) / sizeof(char*)); i++)
114  {
115  if(access_file(default_so_paths[i]))
116  {
117  path = (char *) default_so_paths[i];
118  break;
119  }
120  }
121  }
122 
123  if (path)
124  {
125  *cl_path = strndup(path, strlen(path));
126  return CL_SUCCESS;
127  }
128  return CL_INVALID_PLATFORM;
129 }
130 
131 void stubOpenclReset()
132 {
133  if(so_handle)
134  dlclose(so_handle);
135 
136  so_handle = NULL;
137 }
138 
139 cl_int
140 clGetPlatformIDs(cl_uint num_entries,
141  cl_platform_id * platforms,
142  cl_uint * num_platforms)
143 {
144  f_clGetPlatformIDs func;
145 
146  if(!so_handle)
147  open_libopencl_so();
148 
149  func = (f_clGetPlatformIDs) dlsym(so_handle, "clGetPlatformIDs");
150  if(func) {
151  return func(num_entries, platforms, num_platforms);
152  } else {
153  return CL_INVALID_PLATFORM;
154  }
155 }
156 
157 
158 cl_int
159 clGetPlatformInfo(cl_platform_id platform,
160  cl_platform_info param_name,
161  size_t param_value_size,
162  void * param_value,
163  size_t * param_value_size_ret)
164 {
165  f_clGetPlatformInfo func;
166 
167  if(!so_handle)
168  open_libopencl_so();
169 
170  func = (f_clGetPlatformInfo) dlsym(so_handle, "clGetPlatformInfo");
171  if(func) {
172  return func(platform, param_name, param_value_size, param_value, param_value_size_ret);
173  } else {
174  return CL_INVALID_PLATFORM;
175  }
176 }
177 
178 
179 cl_int
180 clGetDeviceIDs(cl_platform_id platform,
181  cl_device_type device_type,
182  cl_uint num_entries,
183  cl_device_id * devices,
184  cl_uint * num_devices)
185 {
186  f_clGetDeviceIDs func;
187 
188  if(!so_handle)
189  open_libopencl_so();
190 
191  func = (f_clGetDeviceIDs) dlsym(so_handle, "clGetDeviceIDs");
192  if(func) {
193  return func(platform, device_type, num_entries, devices, num_devices);
194  } else {
195  return CL_INVALID_PLATFORM;
196  }
197 }
198 
199 cl_int
200 clGetDeviceInfo(cl_device_id device,
201  cl_device_info param_name,
202  size_t param_value_size,
203  void * param_value,
204  size_t * param_value_size_ret)
205 {
206  f_clGetDeviceInfo func;
207 
208  if(!so_handle)
209  open_libopencl_so();
210 
211  func = (f_clGetDeviceInfo) dlsym(so_handle, "clGetDeviceInfo");
212  if(func) {
213  return func(device, param_name, param_value_size, param_value, param_value_size_ret);
214  } else {
215  return CL_INVALID_PLATFORM;
216  }
217 }
218 
219 cl_int
220 clCreateSubDevices(cl_device_id in_device,
221  const cl_device_partition_property * properties,
222  cl_uint num_devices,
223  cl_device_id * out_devices,
224  cl_uint * num_devices_ret)
225 {
226  f_clCreateSubDevices func;
227 
228  if(!so_handle)
229  open_libopencl_so();
230 
231  func = (f_clCreateSubDevices) dlsym(so_handle, "clCreateSubDevices");
232  if(func) {
233  return func(in_device, properties, num_devices, out_devices, num_devices_ret);
234  } else {
235  return CL_INVALID_PLATFORM;
236  }
237 }
238 
239 cl_int
240 clRetainDevice(cl_device_id device)
241 {
242  f_clRetainDevice func;
243 
244  if(!so_handle)
245  open_libopencl_so();
246 
247  func = (f_clRetainDevice) dlsym(so_handle, "clRetainDevice");
248  if(func) {
249  return func(device);
250  } else {
251  return CL_INVALID_PLATFORM;
252  }
253 }
254 
255 cl_int
256 clReleaseDevice(cl_device_id device)
257 {
258  f_clReleaseDevice func;
259 
260  if(!so_handle)
261  open_libopencl_so();
262 
263  func = (f_clReleaseDevice) dlsym(so_handle, "clReleaseDevice");
264  if(func) {
265  return func(device);
266  } else {
267  return CL_INVALID_PLATFORM;
268  }
269 }
270 
271 
272 cl_context
273 clCreateContext(const cl_context_properties * properties,
274  cl_uint num_devices,
275  const cl_device_id * devices,
276  void (*pfn_notify)(const char *, const void *, size_t, void *),
277  void * user_data,
278  cl_int * errcode_ret)
279 {
280  f_clCreateContext func;
281 
282  if(!so_handle)
283  open_libopencl_so();
284 
285  func = (f_clCreateContext) dlsym(so_handle, "clCreateContext");
286  if(func) {
287  return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
288  } else {
289  return NULL;
290  }
291 }
292 
293 cl_context
294 clCreateContextFromType(const cl_context_properties * properties,
295  cl_device_type device_type,
296  void (*pfn_notify )(const char *, const void *, size_t, void *),
297  void * user_data,
298  cl_int * errcode_ret)
299 {
300  f_clCreateContextFromType func;
301 
302  if(!so_handle)
303  open_libopencl_so();
304 
305  func = (f_clCreateContextFromType) dlsym(so_handle, "clCreateContextFromType");
306  if(func) {
307  return func(properties, device_type, pfn_notify, user_data, errcode_ret);
308  } else {
309  return NULL;
310  }
311 }
312 
313 cl_int
314 clRetainContext(cl_context context)
315 {
316  f_clRetainContext func;
317 
318  if(!so_handle)
319  open_libopencl_so();
320 
321  func = (f_clRetainContext) dlsym(so_handle, "clRetainContext");
322  if(func) {
323  return func(context);
324  } else {
325  return CL_INVALID_PLATFORM;
326  }
327 }
328 
329 cl_int
330 clReleaseContext(cl_context context)
331 {
332  f_clReleaseContext func;
333 
334  if(!so_handle)
335  open_libopencl_so();
336 
337  func = (f_clReleaseContext) dlsym(so_handle, "clReleaseContext");
338  if(func) {
339  return func(context);
340  } else {
341  return CL_INVALID_PLATFORM;
342  }
343 }
344 
345 cl_int
346 clGetContextInfo(cl_context context,
347  cl_context_info param_name,
348  size_t param_value_size,
349  void * param_value,
350  size_t * param_value_size_ret)
351 {
352  f_clGetContextInfo func;
353 
354  if(!so_handle)
355  open_libopencl_so();
356 
357  func = (f_clGetContextInfo) dlsym(so_handle, "clGetContextInfo");
358  if(func) {
359  return func(context, param_name, param_value_size,
360  param_value, param_value_size_ret);
361  } else {
362  return CL_INVALID_PLATFORM;
363  }
364 }
365 
366 
367 cl_command_queue
368 clCreateCommandQueue(cl_context context,
369  cl_device_id device,
370  cl_command_queue_properties properties,
371  cl_int * errcode_ret)
372 {
373  f_clCreateCommandQueue func;
374 
375  if(!so_handle)
376  open_libopencl_so();
377 
378  func = (f_clCreateCommandQueue) dlsym(so_handle, "clCreateCommandQueue");
379  if(func) {
380  return func(context, device, properties, errcode_ret);
381  } else {
382  return NULL;
383  }
384 }
385 
386 cl_int
387 clRetainCommandQueue(cl_command_queue command_queue)
388 {
389  f_clRetainCommandQueue func;
390 
391  if(!so_handle)
392  open_libopencl_so();
393 
394  func = (f_clRetainCommandQueue) dlsym(so_handle, "clRetainCommandQueue");
395  if(func) {
396  return func(command_queue);
397  } else {
398  return CL_INVALID_PLATFORM;
399  }
400 }
401 
402 cl_int
403 clReleaseCommandQueue(cl_command_queue command_queue)
404 {
405  f_clReleaseCommandQueue func;
406 
407  if(!so_handle)
408  open_libopencl_so();
409 
410  func = (f_clReleaseCommandQueue) dlsym(so_handle, "clReleaseCommandQueue");
411  if(func) {
412  return func(command_queue);
413  } else {
414  return CL_INVALID_PLATFORM;
415  }
416 }
417 
418 cl_int
419 clGetCommandQueueInfo(cl_command_queue command_queue,
420  cl_command_queue_info param_name,
421  size_t param_value_size,
422  void * param_value,
423  size_t * param_value_size_ret)
424 {
425  f_clGetCommandQueueInfo func;
426 
427  if(!so_handle)
428  open_libopencl_so();
429 
430  func = (f_clGetCommandQueueInfo) dlsym(so_handle, "clGetCommandQueueInfo");
431  if(func) {
432  return func(command_queue, param_name, param_value_size,
433  param_value, param_value_size_ret);
434  } else {
435  return CL_INVALID_PLATFORM;
436  }
437 }
438 
439 
440 cl_mem
441 clCreateBuffer(cl_context context,
442  cl_mem_flags flags,
443  size_t size,
444  void * host_ptr,
445  cl_int * errcode_ret)
446 {
447  f_clCreateBuffer func;
448 
449  if(!so_handle)
450  open_libopencl_so();
451 
452  func = (f_clCreateBuffer) dlsym(so_handle, "clCreateBuffer");
453  if(func) {
454  return func(context, flags, size, host_ptr, errcode_ret);
455  } else {
456  return NULL;
457  }
458 }
459 
460 cl_mem
461 clCreateSubBuffer(cl_mem buffer,
462  cl_mem_flags flags,
463  cl_buffer_create_type buffer_create_type,
464  const void * buffer_create_info,
465  cl_int * errcode_ret)
466 {
467  f_clCreateSubBuffer func;
468 
469  if(!so_handle)
470  open_libopencl_so();
471 
472  func = (f_clCreateSubBuffer) dlsym(so_handle, "clCreateSubBuffer");
473  if(func) {
474  return func(buffer, flags, buffer_create_type,
475  buffer_create_info, errcode_ret);
476  } else {
477  return NULL;
478  }
479 }
480 
481 cl_mem
482 clCreateImage(cl_context context,
483  cl_mem_flags flags,
484  const cl_image_format * image_format,
485  const cl_image_desc * image_desc,
486  void * host_ptr,
487  cl_int * errcode_ret)
488 {
489  f_clCreateImage func;
490 
491  if(!so_handle)
492  open_libopencl_so();
493 
494  func = (f_clCreateImage) dlsym(so_handle, "clCreateImage");
495  if(func) {
496  return func(context, flags, image_format, image_desc,
497  host_ptr, errcode_ret);
498  } else {
499  return NULL;
500  }
501 }
502 
503 cl_int
504 clRetainMemObject(cl_mem memobj)
505 {
506  f_clRetainMemObject func;
507 
508  if(!so_handle)
509  open_libopencl_so();
510 
511  func = (f_clRetainMemObject) dlsym(so_handle, "clRetainMemObject");
512  if(func) {
513  return func(memobj);
514  } else {
515  return CL_INVALID_PLATFORM;
516  }
517 }
518 
519 cl_int
520 clReleaseMemObject(cl_mem memobj)
521 {
522  f_clReleaseMemObject func;
523 
524  if(!so_handle)
525  open_libopencl_so();
526 
527  func = (f_clReleaseMemObject) dlsym(so_handle, "clReleaseMemObject");
528  if(func) {
529  return func(memobj);
530  } else {
531  return CL_INVALID_PLATFORM;
532  }
533 }
534 
535 cl_int
536 clGetSupportedImageFormats(cl_context context,
537  cl_mem_flags flags,
538  cl_mem_object_type image_type,
539  cl_uint num_entries,
540  cl_image_format * image_formats,
541  cl_uint * num_image_formats)
542 {
543  f_clGetSupportedImageFormats func;
544 
545  if(!so_handle)
546  open_libopencl_so();
547 
548  func = (f_clGetSupportedImageFormats) dlsym(so_handle, "clGetSupportedImageFormats");
549  if(func) {
550  return func(context, flags, image_type, num_entries,
551  image_formats, num_image_formats);
552  } else {
553  return CL_INVALID_PLATFORM;
554  }
555 }
556 
557 cl_int
558 clGetMemObjectInfo(cl_mem memobj,
559  cl_mem_info param_name,
560  size_t param_value_size,
561  void * param_value,
562  size_t * param_value_size_ret)
563 {
564  f_clGetMemObjectInfo func;
565 
566  if(!so_handle)
567  open_libopencl_so();
568 
569  func = (f_clGetMemObjectInfo) dlsym(so_handle, "clGetMemObjectInfo");
570  if(func) {
571  return func(memobj, param_name, param_value_size,
572  param_value, param_value_size_ret);
573  } else {
574  return CL_INVALID_PLATFORM;
575  }
576 }
577 
578 cl_int
579 clGetImageInfo(cl_mem image,
580  cl_image_info param_name,
581  size_t param_value_size,
582  void * param_value,
583  size_t * param_value_size_ret)
584 {
585  f_clGetImageInfo func;
586 
587  if(!so_handle)
588  open_libopencl_so();
589 
590  func = (f_clGetImageInfo) dlsym(so_handle, "clGetImageInfo");
591  if(func) {
592  return func(image, param_name, param_value_size,
593  param_value, param_value_size_ret);
594  } else {
595  return CL_INVALID_PLATFORM;
596  }
597 }
598 
599 cl_int
600 clSetMemObjectDestructorCallback( cl_mem memobj,
601  void (*pfn_notify)( cl_mem memobj, void* user_data),
602  void * user_data )
603 {
604  f_clSetMemObjectDestructorCallback func;
605 
606  if(!so_handle)
607  open_libopencl_so();
608 
609  func = (f_clSetMemObjectDestructorCallback) dlsym(so_handle, "clSetMemObjectDestructorCallback");
610  if(func) {
611  return func(memobj, pfn_notify, user_data);
612  } else {
613  return CL_INVALID_PLATFORM;
614  }
615 }
616 
617 cl_sampler
618 clCreateSampler(cl_context context,
619  cl_bool normalized_coords,
620  cl_addressing_mode addressing_mode,
621  cl_filter_mode filter_mode,
622  cl_int * errcode_ret)
623 {
624  f_clCreateSampler func;
625 
626  if(!so_handle)
627  open_libopencl_so();
628 
629  func = (f_clCreateSampler) dlsym(so_handle, "clCreateSampler");
630  if(func) {
631  return func(context, normalized_coords, addressing_mode, filter_mode, errcode_ret);
632  } else {
633  return NULL;
634  }
635 }
636 
637 cl_int
638 clRetainSampler(cl_sampler sampler)
639 {
640  f_clRetainSampler func;
641 
642  if(!so_handle)
643  open_libopencl_so();
644 
645  func = (f_clRetainSampler) dlsym(so_handle, "clRetainSampler");
646  if(func) {
647  return func(sampler);
648  } else {
649  return CL_INVALID_PLATFORM;
650  }
651 }
652 
653 cl_int
654 clReleaseSampler(cl_sampler sampler)
655 {
656  f_clReleaseSampler func;
657 
658  if(!so_handle)
659  open_libopencl_so();
660 
661  func = (f_clReleaseSampler) dlsym(so_handle, "clReleaseSampler");
662  if(func) {
663  return func(sampler);
664  } else {
665  return CL_INVALID_PLATFORM;
666  }
667 }
668 
669 cl_int
670 clGetSamplerInfo(cl_sampler sampler,
671  cl_sampler_info param_name,
672  size_t param_value_size,
673  void * param_value,
674  size_t * param_value_size_ret)
675 {
676  f_clGetSamplerInfo func;
677 
678  if(!so_handle)
679  open_libopencl_so();
680 
681  func = (f_clGetSamplerInfo) dlsym(so_handle, "clGetSamplerInfo");
682  if(func) {
683  return func(sampler, param_name, param_value_size, param_value, param_value_size_ret);
684  } else {
685  return CL_INVALID_PLATFORM;
686  }
687 }
688 
689 
690 cl_program
691 clCreateProgramWithSource(cl_context context,
692  cl_uint count,
693  const char ** strings,
694  const size_t * lengths,
695  cl_int * errcode_ret)
696 {
697  f_clCreateProgramWithSource func;
698 
699  if(!so_handle)
700  open_libopencl_so();
701 
702  func = (f_clCreateProgramWithSource) dlsym(so_handle, "clCreateProgramWithSource");
703  if(func) {
704  return func(context, count, strings, lengths, errcode_ret);
705  } else {
706  return NULL;
707  }
708 }
709 
710 
711 
712 cl_program
713 clCreateProgramWithBinary(cl_context context,
714  cl_uint num_devices,
715  const cl_device_id * device_list,
716  const size_t * lengths,
717  const unsigned char ** binaries,
718  cl_int * binary_status,
719  cl_int * errcode_ret)
720 {
721  f_clCreateProgramWithBinary func;
722 
723  if(!so_handle)
724  open_libopencl_so();
725 
726  func = (f_clCreateProgramWithBinary) dlsym(so_handle, "clCreateProgramWithBinary");
727  if(func) {
728  return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
729  } else {
730  return NULL;
731  }
732 }
733 
734 cl_program
735 clCreateProgramWithBuiltInKernels(cl_context context,
736  cl_uint num_devices,
737  const cl_device_id * device_list,
738  const char * kernel_names,
739  cl_int * errcode_ret)
740 {
741  f_clCreateProgramWithBuiltInKernels func;
742 
743  if(!so_handle)
744  open_libopencl_so();
745 
746  func = (f_clCreateProgramWithBuiltInKernels) dlsym(so_handle, "clCreateProgramWithBuiltInKernels");
747  if(func) {
748  return func(context, num_devices, device_list, kernel_names, errcode_ret);
749  } else {
750  return NULL;
751  }
752 }
753 
754 cl_int
755 clRetainProgram(cl_program program)
756 {
757  f_clRetainProgram func;
758 
759  if(!so_handle)
760  open_libopencl_so();
761 
762  func = (f_clRetainProgram) dlsym(so_handle, "clRetainProgram");
763  if(func) {
764  return func(program);
765  } else {
766  return CL_INVALID_PLATFORM;
767  }
768 }
769 
770 cl_int
771 clReleaseProgram(cl_program program)
772 {
773  f_clReleaseProgram func;
774 
775  if(!so_handle)
776  open_libopencl_so();
777 
778  func = (f_clReleaseProgram) dlsym(so_handle, "clReleaseProgram");
779  if(func) {
780  return func(program);
781  } else {
782  return CL_INVALID_PLATFORM;
783  }
784 }
785 
786 cl_int
787 clBuildProgram(cl_program program,
788  cl_uint num_devices,
789  const cl_device_id * device_list,
790  const char * options,
791  void (*pfn_notify)(cl_program program, void * user_data),
792  void * user_data)
793 {
794  f_clBuildProgram func;
795 
796  if(!so_handle)
797  open_libopencl_so();
798 
799  func = (f_clBuildProgram) dlsym(so_handle, "clBuildProgram");
800  if(func) {
801  return func(program, num_devices, device_list, options, pfn_notify, user_data);
802  } else {
803  return CL_INVALID_PLATFORM;
804  }
805 }
806 
807 cl_int
808 clCompileProgram(cl_program program,
809  cl_uint num_devices,
810  const cl_device_id * device_list,
811  const char * options,
812  cl_uint num_input_headers,
813  const cl_program * input_headers,
814  const char ** header_include_names,
815  void (*pfn_notify)(cl_program program, void * user_data),
816  void * user_data)
817 {
818  f_clCompileProgram func;
819 
820  if(!so_handle)
821  open_libopencl_so();
822 
823  func = (f_clCompileProgram) dlsym(so_handle, "clCompileProgram");
824  if(func) {
825  return func(program, num_devices, device_list, options, num_input_headers, input_headers,
826  header_include_names, pfn_notify, user_data);
827  } else {
828  return CL_INVALID_PLATFORM;
829  }
830 }
831 
832 cl_program
833 clLinkProgram(cl_context context,
834  cl_uint num_devices,
835  const cl_device_id * device_list,
836  const char * options,
837  cl_uint num_input_programs,
838  const cl_program * input_programs,
839  void (*pfn_notify)(cl_program program, void * user_data),
840  void * user_data,
841  cl_int * errcode_ret)
842 {
843  f_clLinkProgram func;
844 
845  if(!so_handle)
846  open_libopencl_so();
847 
848  func = (f_clLinkProgram) dlsym(so_handle, "clLinkProgram");
849  if(func) {
850  return func(context, num_devices, device_list, options, num_input_programs,
851  input_programs, pfn_notify, user_data, errcode_ret);
852  } else {
853  return NULL;
854  }
855 }
856 
857 
858 cl_int
859 clUnloadPlatformCompiler(cl_platform_id platform)
860 {
861  f_clUnloadPlatformCompiler func;
862 
863  if(!so_handle)
864  open_libopencl_so();
865 
866  func = (f_clUnloadPlatformCompiler) dlsym(so_handle, "clUnloadPlatformCompiler");
867  if(func) {
868  return func(platform);
869  } else {
870  return CL_INVALID_PLATFORM;
871  }
872 }
873 
874 cl_int
875 clGetProgramInfo(cl_program program,
876  cl_program_info param_name,
877  size_t param_value_size,
878  void * param_value,
879  size_t * param_value_size_ret)
880 {
881  f_clGetProgramInfo func;
882 
883  if(!so_handle)
884  open_libopencl_so();
885 
886  func = (f_clGetProgramInfo) dlsym(so_handle, "clGetProgramInfo");
887  if(func) {
888  return func(program, param_name, param_value_size,
889  param_value, param_value_size_ret);
890  } else {
891  return CL_INVALID_PLATFORM;
892  }
893 }
894 
895 cl_int
896 clGetProgramBuildInfo(cl_program program,
897  cl_device_id device,
898  cl_program_build_info param_name,
899  size_t param_value_size,
900  void * param_value,
901  size_t * param_value_size_ret)
902 {
903  f_clGetProgramBuildInfo func;
904 
905  if(!so_handle)
906  open_libopencl_so();
907 
908  func = (f_clGetProgramBuildInfo) dlsym(so_handle, "clGetProgramBuildInfo");
909  if(func) {
910  return func(program, device, param_name, param_value_size,
911  param_value, param_value_size_ret);
912  } else {
913  return CL_INVALID_PLATFORM;
914  }
915 }
916 
917 
918 cl_kernel
919 clCreateKernel(cl_program program,
920  const char * kernel_name,
921  cl_int * errcode_ret)
922 {
923  f_clCreateKernel func;
924 
925  if(!so_handle)
926  open_libopencl_so();
927 
928  func = (f_clCreateKernel) dlsym(so_handle, "clCreateKernel");
929  if(func) {
930  return func(program, kernel_name, errcode_ret);
931  } else {
932  return NULL;
933  }
934 }
935 
936 cl_int
937 clCreateKernelsInProgram(cl_program program,
938  cl_uint num_kernels,
939  cl_kernel * kernels,
940  cl_uint * num_kernels_ret)
941 {
942  f_clCreateKernelsInProgram func;
943 
944  if(!so_handle)
945  open_libopencl_so();
946 
947  func = (f_clCreateKernelsInProgram) dlsym(so_handle, "clCreateKernelsInProgram");
948  if(func) {
949  return func(program, num_kernels, kernels, num_kernels_ret);
950  } else {
951  return CL_INVALID_PLATFORM;
952  }
953 }
954 
955 cl_int
956 clRetainKernel(cl_kernel kernel)
957 {
958  f_clRetainKernel func;
959 
960  if(!so_handle)
961  open_libopencl_so();
962 
963  func = (f_clRetainKernel) dlsym(so_handle, "clRetainKernel");
964  if(func) {
965  return func(kernel);
966  } else {
967  return CL_INVALID_PLATFORM;
968  }
969 }
970 
971 cl_int
972 clReleaseKernel(cl_kernel kernel)
973 {
974  f_clReleaseKernel func;
975 
976  if(!so_handle)
977  open_libopencl_so();
978 
979  func = (f_clReleaseKernel) dlsym(so_handle, "clReleaseKernel");
980  if(func) {
981  return func(kernel);
982  } else {
983  return CL_INVALID_PLATFORM;
984  }
985 }
986 
987 cl_int
988 clSetKernelArg(cl_kernel kernel,
989  cl_uint arg_index,
990  size_t arg_size,
991  const void * arg_value)
992 {
993  f_clSetKernelArg func;
994 
995  if(!so_handle)
996  open_libopencl_so();
997 
998  func = (f_clSetKernelArg) dlsym(so_handle, "clSetKernelArg");
999  if(func) {
1000  return func(kernel, arg_index, arg_size, arg_value);
1001  } else {
1002  return CL_INVALID_PLATFORM;
1003  }
1004 }
1005 
1006 cl_int
1007 clGetKernelInfo(cl_kernel kernel,
1008  cl_kernel_info param_name,
1009  size_t param_value_size,
1010  void * param_value,
1011  size_t * param_value_size_ret)
1012 {
1013  f_clGetKernelInfo func;
1014 
1015  if(!so_handle)
1016  open_libopencl_so();
1017 
1018  func = (f_clGetKernelInfo) dlsym(so_handle, "clGetKernelInfo");
1019  if(func) {
1020  return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
1021  } else {
1022  return CL_INVALID_PLATFORM;
1023  }
1024 }
1025 
1026 cl_int
1027 clGetKernelArgInfo(cl_kernel kernel,
1028  cl_uint arg_indx,
1029  cl_kernel_arg_info param_name,
1030  size_t param_value_size,
1031  void * param_value,
1032  size_t * param_value_size_ret)
1033 {
1034  f_clGetKernelArgInfo func;
1035 
1036  if(!so_handle)
1037  open_libopencl_so();
1038 
1039  func = (f_clGetKernelArgInfo) dlsym(so_handle, "clGetKernelArgInfo");
1040  if(func) {
1041  return func(kernel, arg_indx, param_name, param_value_size,
1042  param_value, param_value_size_ret);
1043  } else {
1044  return CL_INVALID_PLATFORM;
1045  }
1046 }
1047 
1048 cl_int
1049 clGetKernelWorkGroupInfo(cl_kernel kernel,
1050  cl_device_id device,
1051  cl_kernel_work_group_info param_name,
1052  size_t param_value_size,
1053  void * param_value,
1054  size_t * param_value_size_ret)
1055 {
1056  f_clGetKernelWorkGroupInfo func;
1057 
1058  if(!so_handle)
1059  open_libopencl_so();
1060 
1061  func = (f_clGetKernelWorkGroupInfo) dlsym(so_handle, "clGetKernelWorkGroupInfo");
1062  if(func) {
1063  return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
1064  } else {
1065  return CL_INVALID_PLATFORM;
1066  }
1067 }
1068 
1069 
1070 cl_int
1071 clWaitForEvents(cl_uint num_events,
1072  const cl_event * event_list)
1073 {
1074  f_clWaitForEvents func;
1075 
1076  if(!so_handle)
1077  open_libopencl_so();
1078 
1079  func = (f_clWaitForEvents) dlsym(so_handle, "clWaitForEvents");
1080  if(func) {
1081  return func(num_events, event_list);
1082  } else {
1083  return CL_INVALID_PLATFORM;
1084  }
1085 }
1086 
1087 
1088 cl_int
1089 clGetEventInfo(cl_event event,
1090  cl_event_info param_name,
1091  size_t param_value_size,
1092  void * param_value,
1093  size_t * param_value_size_ret)
1094 {
1095  f_clGetEventInfo func;
1096 
1097  if(!so_handle)
1098  open_libopencl_so();
1099 
1100  func = (f_clGetEventInfo) dlsym(so_handle, "clGetEventInfo");
1101  if(func) {
1102  return func(event, param_name, param_value_size, param_value, param_value_size_ret);
1103  } else {
1104  return CL_INVALID_PLATFORM;
1105  }
1106 }
1107 
1108 cl_event
1109 clCreateUserEvent(cl_context context,
1110  cl_int * errcode_ret)
1111 {
1112  f_clCreateUserEvent func;
1113 
1114  if(!so_handle)
1115  open_libopencl_so();
1116 
1117  func = (f_clCreateUserEvent) dlsym(so_handle, "clCreateUserEvent");
1118  if(func) {
1119  return func(context, errcode_ret);
1120  } else {
1121  return NULL;
1122  }
1123 }
1124 
1125 cl_int
1126 clRetainEvent(cl_event event)
1127 {
1128  f_clRetainEvent func;
1129 
1130  if(!so_handle)
1131  open_libopencl_so();
1132 
1133  func = (f_clRetainEvent) dlsym(so_handle, "clRetainEvent");
1134  if(func) {
1135  return func(event);
1136  } else {
1137  return CL_INVALID_PLATFORM;
1138  }
1139 }
1140 
1141 cl_int
1142 clReleaseEvent(cl_event event)
1143 {
1144  f_clReleaseEvent func;
1145 
1146  if(!so_handle)
1147  open_libopencl_so();
1148 
1149  func = (f_clReleaseEvent) dlsym(so_handle, "clReleaseEvent");
1150  if(func) {
1151  return func(event);
1152  } else {
1153  return CL_INVALID_PLATFORM;
1154  }
1155 }
1156 
1157 cl_int
1158 clSetUserEventStatus(cl_event event,
1159  cl_int execution_status)
1160 {
1161  f_clSetUserEventStatus func;
1162 
1163  if(!so_handle)
1164  open_libopencl_so();
1165 
1166  func = (f_clSetUserEventStatus) dlsym(so_handle, "clSetUserEventStatus");
1167  if(func) {
1168  return func(event, execution_status);
1169  } else {
1170  return CL_INVALID_PLATFORM;
1171  }
1172 }
1173 
1174 cl_int
1175 clSetEventCallback( cl_event event,
1176  cl_int command_exec_callback_type,
1177  void (*pfn_notify)(cl_event, cl_int, void *),
1178  void * user_data)
1179 {
1180  f_clSetEventCallback func;
1181 
1182  if(!so_handle)
1183  open_libopencl_so();
1184 
1185  func = (f_clSetEventCallback) dlsym(so_handle, "clSetEventCallback");
1186  if(func) {
1187  return func(event, command_exec_callback_type, pfn_notify, user_data);
1188  } else {
1189  return CL_INVALID_PLATFORM;
1190  }
1191 }
1192 
1193 cl_int
1194 clGetEventProfilingInfo(cl_event event,
1195  cl_profiling_info param_name,
1196  size_t param_value_size,
1197  void * param_value,
1198  size_t * param_value_size_ret)
1199 {
1200  f_clGetEventProfilingInfo func;
1201 
1202  if(!so_handle)
1203  open_libopencl_so();
1204 
1205  func = (f_clGetEventProfilingInfo) dlsym(so_handle, "clGetEventProfilingInfo");
1206  if(func) {
1207  return func(event, param_name, param_value_size, param_value, param_value_size_ret);
1208  } else {
1209  return CL_INVALID_PLATFORM;
1210  }
1211 }
1212 
1213 cl_int
1214 clFlush(cl_command_queue command_queue)
1215 {
1216  f_clFlush func;
1217 
1218  if(!so_handle)
1219  open_libopencl_so();
1220 
1221  func = (f_clFlush) dlsym(so_handle, "clFlush");
1222  if(func) {
1223  return func(command_queue);
1224  } else {
1225  return CL_INVALID_PLATFORM;
1226  }
1227 }
1228 
1229 cl_int
1230 clFinish(cl_command_queue command_queue)
1231 {
1232  f_clFinish func;
1233 
1234  if(!so_handle)
1235  open_libopencl_so();
1236 
1237  func = (f_clFinish) dlsym(so_handle, "clFinish");
1238  if(func) {
1239  return func(command_queue);
1240  } else {
1241  return CL_INVALID_PLATFORM;
1242  }
1243 }
1244 
1245 
1246 cl_int
1247 clEnqueueReadBuffer(cl_command_queue command_queue,
1248  cl_mem buffer,
1249  cl_bool blocking_read,
1250  size_t offset,
1251  size_t size,
1252  void * ptr,
1253  cl_uint num_events_in_wait_list,
1254  const cl_event * event_wait_list,
1255  cl_event * event)
1256 {
1257  f_clEnqueueReadBuffer func;
1258 
1259  if(!so_handle)
1260  open_libopencl_so();
1261 
1262  func = (f_clEnqueueReadBuffer) dlsym(so_handle, "clEnqueueReadBuffer");
1263  if(func) {
1264  return func(command_queue, buffer, blocking_read, offset, size, ptr,
1265  num_events_in_wait_list, event_wait_list, event);
1266  } else {
1267  return CL_INVALID_PLATFORM;
1268  }
1269 }
1270 
1271 cl_int
1272 clEnqueueReadBufferRect(cl_command_queue command_queue,
1273  cl_mem buffer,
1274  cl_bool blocking_read,
1275  const size_t * buffer_offset,
1276  const size_t * host_offset,
1277  const size_t * region,
1278  size_t buffer_row_pitch,
1279  size_t buffer_slice_pitch,
1280  size_t host_row_pitch,
1281  size_t host_slice_pitch,
1282  void * ptr,
1283  cl_uint num_events_in_wait_list,
1284  const cl_event * event_wait_list,
1285  cl_event * event)
1286 {
1287  f_clEnqueueReadBufferRect func;
1288 
1289  if(!so_handle)
1290  open_libopencl_so();
1291 
1292  func = (f_clEnqueueReadBufferRect) dlsym(so_handle, "clEnqueueReadBufferRect");
1293  if(func) {
1294  return func(command_queue, buffer, blocking_read, buffer_offset, host_offset, region,
1295  buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, ptr,
1296  num_events_in_wait_list, event_wait_list, event);
1297  } else {
1298  return CL_INVALID_PLATFORM;
1299  }
1300 }
1301 
1302 cl_int
1303 clEnqueueWriteBuffer(cl_command_queue command_queue,
1304  cl_mem buffer,
1305  cl_bool blocking_write,
1306  size_t offset,
1307  size_t size,
1308  const void * ptr,
1309  cl_uint num_events_in_wait_list,
1310  const cl_event * event_wait_list,
1311  cl_event * event)
1312 {
1313  f_clEnqueueWriteBuffer func;
1314 
1315  if(!so_handle)
1316  open_libopencl_so();
1317 
1318  func = (f_clEnqueueWriteBuffer) dlsym(so_handle, "clEnqueueWriteBuffer");
1319  if(func) {
1320  return func(command_queue, buffer, blocking_write, offset, size, ptr,
1321  num_events_in_wait_list, event_wait_list, event);
1322  } else {
1323  return CL_INVALID_PLATFORM;
1324  }
1325 }
1326 
1327 
1328 cl_int
1329 clEnqueueWriteBufferRect(cl_command_queue command_queue,
1330  cl_mem buffer,
1331  cl_bool blocking_write,
1332  const size_t * buffer_offset,
1333  const size_t * host_offset,
1334  const size_t * region,
1335  size_t buffer_row_pitch,
1336  size_t buffer_slice_pitch,
1337  size_t host_row_pitch,
1338  size_t host_slice_pitch,
1339  const void * ptr,
1340  cl_uint num_events_in_wait_list,
1341  const cl_event * event_wait_list,
1342  cl_event * event)
1343 {
1344  f_clEnqueueWriteBufferRect func;
1345 
1346  if(!so_handle)
1347  open_libopencl_so();
1348 
1349  func = (f_clEnqueueWriteBufferRect) dlsym(so_handle, "clEnqueueWriteBufferRect");
1350  if(func) {
1351  return func(command_queue, buffer, blocking_write, buffer_offset, host_offset, region,
1352  buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch,
1353  ptr, num_events_in_wait_list, event_wait_list, event);
1354  } else {
1355  return CL_INVALID_PLATFORM;
1356  }
1357 }
1358 
1359 
1360 cl_int
1361 clEnqueueFillBuffer(cl_command_queue command_queue,
1362  cl_mem buffer,
1363  const void * pattern,
1364  size_t pattern_size,
1365  size_t offset,
1366  size_t size,
1367  cl_uint num_events_in_wait_list,
1368  const cl_event * event_wait_list,
1369  cl_event * event)
1370 {
1371  f_clEnqueueFillBuffer func;
1372 
1373  if(!so_handle)
1374  open_libopencl_so();
1375 
1376  func = (f_clEnqueueFillBuffer) dlsym(so_handle, "clEnqueueFillBuffer");
1377  if(func) {
1378  return func(command_queue, buffer, pattern, pattern_size, offset, size,
1379  num_events_in_wait_list, event_wait_list, event);
1380  } else {
1381  return CL_INVALID_PLATFORM;
1382  }
1383 }
1384 
1385 cl_int
1386 clEnqueueCopyBuffer(cl_command_queue command_queue,
1387  cl_mem src_buffer,
1388  cl_mem dst_buffer,
1389  size_t src_offset,
1390  size_t dst_offset,
1391  size_t size,
1392  cl_uint num_events_in_wait_list,
1393  const cl_event * event_wait_list,
1394  cl_event * event)
1395 {
1396  f_clEnqueueCopyBuffer func;
1397 
1398  if(!so_handle)
1399  open_libopencl_so();
1400 
1401  func = (f_clEnqueueCopyBuffer) dlsym(so_handle, "clEnqueueCopyBuffer");
1402  if(func) {
1403  return func(command_queue, src_buffer, dst_buffer, src_offset, dst_offset, size,
1404  num_events_in_wait_list, event_wait_list, event);
1405  } else {
1406  return CL_INVALID_PLATFORM;
1407  }
1408 }
1409 
1410 
1411 
1412 cl_int
1413 clEnqueueCopyBufferRect(cl_command_queue command_queue,
1414  cl_mem src_buffer,
1415  cl_mem dst_buffer,
1416  const size_t * src_origin,
1417  const size_t * dst_origin,
1418  const size_t * region,
1419  size_t src_row_pitch,
1420  size_t src_slice_pitch,
1421  size_t dst_row_pitch,
1422  size_t dst_slice_pitch,
1423  cl_uint num_events_in_wait_list,
1424  const cl_event * event_wait_list,
1425  cl_event * event)
1426 {
1427  f_clEnqueueCopyBufferRect func;
1428 
1429  if(!so_handle)
1430  open_libopencl_so();
1431 
1432  func = (f_clEnqueueCopyBufferRect) dlsym(so_handle, "clEnqueueCopyBufferRect");
1433  if(func) {
1434  return func(command_queue, src_buffer, dst_buffer, src_origin, dst_origin, region, src_row_pitch,
1435  src_slice_pitch, dst_row_pitch, dst_slice_pitch, num_events_in_wait_list, event_wait_list, event);
1436  } else {
1437  return CL_INVALID_PLATFORM;
1438  }
1439 }
1440 
1441 cl_int
1442 clEnqueueReadImage(cl_command_queue command_queue,
1443  cl_mem image,
1444  cl_bool blocking_read,
1445  const size_t * origin,
1446  const size_t * region,
1447  size_t row_pitch,
1448  size_t slice_pitch,
1449  void * ptr,
1450  cl_uint num_events_in_wait_list,
1451  const cl_event * event_wait_list,
1452  cl_event * event)
1453 {
1454  f_clEnqueueReadImage func;
1455 
1456  if(!so_handle)
1457  open_libopencl_so();
1458 
1459  func = (f_clEnqueueReadImage) dlsym(so_handle, "clEnqueueReadImage");
1460  if(func) {
1461  return func(command_queue, image, blocking_read, origin, region, row_pitch, slice_pitch,
1462  ptr, num_events_in_wait_list, event_wait_list, event);
1463  } else {
1464  return CL_INVALID_PLATFORM;
1465  }
1466 }
1467 
1468 cl_int
1469 clEnqueueWriteImage(cl_command_queue command_queue,
1470  cl_mem image,
1471  cl_bool blocking_write,
1472  const size_t * origin,
1473  const size_t * region,
1474  size_t input_row_pitch,
1475  size_t input_slice_pitch,
1476  const void * ptr,
1477  cl_uint num_events_in_wait_list,
1478  const cl_event * event_wait_list,
1479  cl_event * event)
1480 {
1481  f_clEnqueueWriteImage func;
1482 
1483  if(!so_handle)
1484  open_libopencl_so();
1485 
1486  func = (f_clEnqueueWriteImage) dlsym(so_handle, "clEnqueueWriteImage");
1487  if(func) {
1488  return func(command_queue, image, blocking_write, origin, region, input_row_pitch, input_slice_pitch, ptr,
1489  num_events_in_wait_list, event_wait_list, event);
1490  } else {
1491  return CL_INVALID_PLATFORM;
1492  }
1493 }
1494 
1495 
1496 cl_int
1497 clEnqueueFillImage(cl_command_queue command_queue,
1498  cl_mem image,
1499  const void * fill_color,
1500  const size_t * origin,
1501  const size_t * region,
1502  cl_uint num_events_in_wait_list,
1503  const cl_event * event_wait_list,
1504  cl_event * event)
1505 {
1506  f_clEnqueueFillImage func;
1507 
1508  if(!so_handle)
1509  open_libopencl_so();
1510 
1511  func = (f_clEnqueueFillImage) dlsym(so_handle, "clEnqueueFillImage");
1512  if(func) {
1513  return func(command_queue, image, fill_color, origin, region, num_events_in_wait_list, event_wait_list, event);
1514  } else {
1515  return CL_INVALID_PLATFORM;
1516  }
1517 }
1518 
1519 cl_int
1520 clEnqueueCopyImage(cl_command_queue command_queue,
1521  cl_mem src_image,
1522  cl_mem dst_image,
1523  const size_t * src_origin,
1524  const size_t * dst_origin,
1525  const size_t * region,
1526  cl_uint num_events_in_wait_list,
1527  const cl_event * event_wait_list,
1528  cl_event * event)
1529 {
1530  f_clEnqueueCopyImage func;
1531 
1532  if(!so_handle)
1533  open_libopencl_so();
1534 
1535  func = (f_clEnqueueCopyImage) dlsym(so_handle, "clEnqueueCopyImage");
1536  if(func) {
1537  return func(command_queue, src_image, dst_image, src_origin, dst_origin, region,
1538  num_events_in_wait_list, event_wait_list, event);
1539  } else {
1540  return CL_INVALID_PLATFORM;
1541  }
1542 }
1543 
1544 cl_int
1545 clEnqueueCopyImageToBuffer(cl_command_queue command_queue,
1546  cl_mem src_image,
1547  cl_mem dst_buffer,
1548  const size_t * src_origin,
1549  const size_t * region,
1550  size_t dst_offset,
1551  cl_uint num_events_in_wait_list,
1552  const cl_event * event_wait_list,
1553  cl_event * event)
1554 {
1555  f_clEnqueueCopyImageToBuffer func;
1556 
1557  if(!so_handle)
1558  open_libopencl_so();
1559 
1560  func = (f_clEnqueueCopyImageToBuffer) dlsym(so_handle, "clEnqueueCopyImageToBuffer");
1561  if(func) {
1562  return func(command_queue, src_image, dst_buffer, src_origin, region, dst_offset,
1563  num_events_in_wait_list, event_wait_list, event);
1564  } else {
1565  return CL_INVALID_PLATFORM;
1566  }
1567 }
1568 
1569 
1570 cl_int
1571 clEnqueueCopyBufferToImage(cl_command_queue command_queue,
1572  cl_mem src_buffer,
1573  cl_mem dst_image,
1574  size_t src_offset,
1575  const size_t * dst_origin,
1576  const size_t * region,
1577  cl_uint num_events_in_wait_list,
1578  const cl_event * event_wait_list,
1579  cl_event * event)
1580 {
1581  f_clEnqueueCopyBufferToImage func;
1582 
1583  if(!so_handle)
1584  open_libopencl_so();
1585 
1586  func = (f_clEnqueueCopyBufferToImage) dlsym(so_handle, "clEnqueueCopyBufferToImage");
1587  if(func) {
1588  return func(command_queue, src_buffer, dst_image, src_offset, dst_origin, region,
1589  num_events_in_wait_list, event_wait_list, event);
1590  } else {
1591  return CL_INVALID_PLATFORM;
1592  }
1593 }
1594 
1595 void *
1596 clEnqueueMapBuffer(cl_command_queue command_queue,
1597  cl_mem buffer,
1598  cl_bool blocking_map,
1599  cl_map_flags map_flags,
1600  size_t offset,
1601  size_t size,
1602  cl_uint num_events_in_wait_list,
1603  const cl_event * event_wait_list,
1604  cl_event * event,
1605  cl_int * errcode_ret)
1606 {
1607  f_clEnqueueMapBuffer func;
1608 
1609  if(!so_handle)
1610  open_libopencl_so();
1611 
1612  func = (f_clEnqueueMapBuffer) dlsym(so_handle, "clEnqueueMapBuffer");
1613  if(func) {
1614  return func(command_queue, buffer, blocking_map, map_flags, offset, size,
1615  num_events_in_wait_list, event_wait_list, event, errcode_ret);
1616  } else {
1617  return NULL;
1618  }
1619 }
1620 
1621 void *
1622 clEnqueueMapImage(cl_command_queue command_queue,
1623  cl_mem image,
1624  cl_bool blocking_map,
1625  cl_map_flags map_flags,
1626  const size_t * origin,
1627  const size_t * region,
1628  size_t * image_row_pitch,
1629  size_t * image_slice_pitch,
1630  cl_uint num_events_in_wait_list,
1631  const cl_event * event_wait_list,
1632  cl_event * event,
1633  cl_int * errcode_ret)
1634 {
1635  f_clEnqueueMapImage func;
1636 
1637  if(!so_handle)
1638  open_libopencl_so();
1639 
1640  func = (f_clEnqueueMapImage) dlsym(so_handle, "clEnqueueMapImage");
1641  if(func) {
1642  return func(command_queue, image, blocking_map, map_flags, origin, region, image_row_pitch,
1643  image_slice_pitch, num_events_in_wait_list, event_wait_list, event, errcode_ret);
1644  } else {
1645  return NULL;
1646  }
1647 }
1648 
1649 cl_int
1650 clEnqueueUnmapMemObject(cl_command_queue command_queue,
1651  cl_mem memobj,
1652  void * mapped_ptr,
1653  cl_uint num_events_in_wait_list,
1654  const cl_event * event_wait_list,
1655  cl_event * event)
1656 {
1657  f_clEnqueueUnmapMemObject func;
1658 
1659  if(!so_handle)
1660  open_libopencl_so();
1661 
1662  func = (f_clEnqueueUnmapMemObject) dlsym(so_handle, "clEnqueueUnmapMemObject");
1663  if(func) {
1664  return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
1665  } else {
1666  return CL_INVALID_PLATFORM;
1667  }
1668 }
1669 
1670 cl_int
1671 clEnqueueMigrateMemObjects(cl_command_queue command_queue,
1672  cl_uint num_mem_objects,
1673  const cl_mem * mem_objects,
1674  cl_mem_migration_flags flags,
1675  cl_uint num_events_in_wait_list,
1676  const cl_event * event_wait_list,
1677  cl_event * event)
1678 {
1679  f_clEnqueueMigrateMemObjects func;
1680 
1681  if(!so_handle)
1682  open_libopencl_so();
1683 
1684  func = (f_clEnqueueMigrateMemObjects) dlsym(so_handle, "clEnqueueMigrateMemObjects");
1685  if(func) {
1686  return func(command_queue, num_mem_objects, mem_objects, flags, num_events_in_wait_list, event_wait_list, event);
1687  } else {
1688  return CL_INVALID_PLATFORM;
1689  }
1690 }
1691 
1692 cl_int
1693 clEnqueueNDRangeKernel(cl_command_queue command_queue,
1694  cl_kernel kernel,
1695  cl_uint work_dim,
1696  const size_t * global_work_offset,
1697  const size_t * global_work_size,
1698  const size_t * local_work_size,
1699  cl_uint num_events_in_wait_list,
1700  const cl_event * event_wait_list,
1701  cl_event * event)
1702 {
1703  f_clEnqueueNDRangeKernel func;
1704 
1705  if(!so_handle)
1706  open_libopencl_so();
1707 
1708  func = (f_clEnqueueNDRangeKernel) dlsym(so_handle, "clEnqueueNDRangeKernel");
1709  if(func) {
1710  return func(command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size,
1711  num_events_in_wait_list, event_wait_list, event);
1712  } else {
1713  return CL_INVALID_PLATFORM;
1714  }
1715 }
1716 
1717 cl_int
1718 clEnqueueTask(cl_command_queue command_queue,
1719  cl_kernel kernel,
1720  cl_uint num_events_in_wait_list,
1721  const cl_event * event_wait_list,
1722  cl_event * event)
1723 {
1724  f_clEnqueueTask func;
1725 
1726  if(!so_handle)
1727  open_libopencl_so();
1728 
1729  func = (f_clEnqueueTask) dlsym(so_handle, "clEnqueueTask");
1730  if(func) {
1731  return func(command_queue, kernel, num_events_in_wait_list, event_wait_list, event);
1732  } else {
1733  return CL_INVALID_PLATFORM;
1734  }
1735 }
1736 
1737 cl_int
1738 clEnqueueNativeKernel(cl_command_queue command_queue,
1739  void (*user_func)(void *),
1740  void * args,
1741  size_t cb_args,
1742  cl_uint num_mem_objects,
1743  const cl_mem * mem_list,
1744  const void ** args_mem_loc,
1745  cl_uint num_events_in_wait_list,
1746  const cl_event * event_wait_list,
1747  cl_event * event)
1748 {
1749  f_clEnqueueNativeKernel func;
1750 
1751  if(!so_handle)
1752  open_libopencl_so();
1753 
1754  func = (f_clEnqueueNativeKernel) dlsym(so_handle, "clEnqueueNativeKernel");
1755  if(func) {
1756  return func(command_queue, user_func, args, cb_args, num_mem_objects, mem_list,
1757  args_mem_loc, num_events_in_wait_list, event_wait_list, event);
1758  } else {
1759  return CL_INVALID_PLATFORM;
1760  }
1761 }
1762 
1763 cl_int
1764 clEnqueueMarkerWithWaitList(cl_command_queue command_queue,
1765  cl_uint num_events_in_wait_list,
1766  const cl_event * event_wait_list,
1767  cl_event * event)
1768 {
1769  f_clEnqueueMarkerWithWaitList func;
1770 
1771  if(!so_handle)
1772  open_libopencl_so();
1773 
1774  func = (f_clEnqueueMarkerWithWaitList) dlsym(so_handle, "clEnqueueMarkerWithWaitList");
1775  if(func) {
1776  return func(command_queue, num_events_in_wait_list, event_wait_list, event);
1777  } else {
1778  return CL_INVALID_PLATFORM;
1779  }
1780 }
1781 
1782 cl_int
1783 clEnqueueBarrierWithWaitList(cl_command_queue command_queue,
1784  cl_uint num_events_in_wait_list,
1785  const cl_event * event_wait_list,
1786  cl_event * event)
1787 {
1788  f_clEnqueueBarrierWithWaitList func;
1789 
1790  if(!so_handle)
1791  open_libopencl_so();
1792 
1793  func = (f_clEnqueueBarrierWithWaitList) dlsym(so_handle, "clEnqueueBarrierWithWaitList");
1794  if(func) {
1795  return func(command_queue, num_events_in_wait_list, event_wait_list, event);
1796  } else {
1797  return CL_INVALID_PLATFORM;
1798  }
1799 }
1800 
1801 void *
1802 clGetExtensionFunctionAddressForPlatform(cl_platform_id platform,
1803  const char * func_name)
1804 {
1805  f_clGetExtensionFunctionAddressForPlatform func;
1806 
1807  if(!so_handle)
1808  open_libopencl_so();
1809 
1810  func = (f_clGetExtensionFunctionAddressForPlatform) dlsym(so_handle, "clGetExtensionFunctionAddressForPlatform");
1811  if(func) {
1812  return func(platform, func_name);
1813  } else {
1814  return NULL;
1815  }
1816 }
1817 
1818 
1819 cl_mem
1820 clCreateImage2D(cl_context context,
1821  cl_mem_flags flags,
1822  const cl_image_format * image_format,
1823  size_t image_width,
1824  size_t image_height,
1825  size_t image_row_pitch,
1826  void * host_ptr,
1827  cl_int * errcode_ret)
1828 {
1829  f_clCreateImage2D func;
1830 
1831  if(!so_handle)
1832  open_libopencl_so();
1833 
1834  func = (f_clCreateImage2D) dlsym(so_handle, "clCreateImage2D");
1835  if(func) {
1836  return func(context, flags, image_format, image_width, image_height,
1837  image_row_pitch, host_ptr, errcode_ret);
1838  } else {
1839  return NULL;
1840  }
1841 }
1842 
1843 cl_mem
1844 clCreateImage3D(cl_context context,
1845  cl_mem_flags flags,
1846  const cl_image_format * image_format,
1847  size_t image_width,
1848  size_t image_height,
1849  size_t image_depth,
1850  size_t image_row_pitch,
1851  size_t image_slice_pitch,
1852  void * host_ptr,
1853  cl_int * errcode_ret)
1854 {
1855  f_clCreateImage3D func;
1856 
1857  if(!so_handle)
1858  open_libopencl_so();
1859 
1860  func = (f_clCreateImage3D) dlsym(so_handle, "clCreateImage3D");
1861  if(func) {
1862  return func(context, flags, image_format, image_width, image_height, image_depth,
1863  image_row_pitch, image_slice_pitch, host_ptr, errcode_ret);
1864  } else {
1865  return NULL;
1866  }
1867 }
1868 
1869 cl_int
1870 clEnqueueMarker(cl_command_queue command_queue,
1871  cl_event * event)
1872 {
1873  f_clEnqueueMarker func;
1874 
1875  if(!so_handle)
1876  open_libopencl_so();
1877 
1878  func = (f_clEnqueueMarker) dlsym(so_handle, "clEnqueueMarker");
1879  if(func) {
1880  return func(command_queue, event);
1881  } else {
1882  return CL_INVALID_PLATFORM;
1883  }
1884 }
1885 
1886 cl_int
1887 clEnqueueWaitForEvents(cl_command_queue command_queue,
1888  cl_uint num_events,
1889  const cl_event * event_list)
1890 {
1891  f_clEnqueueWaitForEvents func;
1892 
1893  if(!so_handle)
1894  open_libopencl_so();
1895 
1896  func = (f_clEnqueueWaitForEvents) dlsym(so_handle, "clEnqueueWaitForEvents");
1897  if(func) {
1898  return func(command_queue, num_events, event_list);
1899  } else {
1900  return CL_INVALID_PLATFORM;
1901  }
1902 }
1903 
1904 cl_int
1905 clEnqueueBarrier(cl_command_queue command_queue)
1906 {
1907  f_clEnqueueBarrier func;
1908 
1909  if(!so_handle)
1910  open_libopencl_so();
1911 
1912  func = (f_clEnqueueBarrier) dlsym(so_handle, "clEnqueueBarrier");
1913  if(func) {
1914  return func(command_queue);
1915  } else {
1916  return CL_INVALID_PLATFORM;
1917  }
1918 }
1919 
1920 cl_int
1921 clUnloadCompiler(void)
1922 {
1923  f_clUnloadCompiler func;
1924 
1925  if(!so_handle)
1926  open_libopencl_so();
1927 
1928  func = (f_clUnloadCompiler) dlsym(so_handle, "clUnloadCompiler");
1929  if(func) {
1930  return func();
1931  } else {
1932  return CL_INVALID_PLATFORM;
1933  }
1934 }
1935 
1936 void *
1937 clGetExtensionFunctionAddress(const char * func_name)
1938 {
1939  f_clGetExtensionFunctionAddress func;
1940 
1941  if(!so_handle)
1942  open_libopencl_so();
1943 
1944  func = (f_clGetExtensionFunctionAddress) dlsym(so_handle, "clGetExtensionFunctionAddress");
1945  if(func) {
1946  return func(func_name);
1947  } else {
1948  return NULL;
1949  }
1950 }
1951 
1952 
1953 cl_mem
1954 clCreateFromGLBuffer(cl_context context,
1955  cl_mem_flags flags,
1956  cl_GLuint bufobj,
1957  int * errcode_ret)
1958 {
1959  f_clCreateFromGLBuffer func;
1960 
1961  if(!so_handle)
1962  open_libopencl_so();
1963 
1964  func = (f_clCreateFromGLBuffer) dlsym(so_handle, "clCreateFromGLBuffer");
1965  if(func) {
1966  return func(context, flags, bufobj, errcode_ret);
1967  } else {
1968  return NULL;
1969  }
1970 }
1971 
1972 cl_mem
1973 clCreateFromGLTexture(cl_context context,
1974  cl_mem_flags flags,
1975  cl_GLenum target,
1976  cl_GLint miplevel,
1977  cl_GLuint texture,
1978  cl_int * errcode_ret)
1979 {
1980  f_clCreateFromGLTexture func;
1981 
1982  if(!so_handle)
1983  open_libopencl_so();
1984 
1985  func = (f_clCreateFromGLTexture) dlsym(so_handle, "clCreateFromGLTexture");
1986  if(func) {
1987  return func(context, flags, target, miplevel, texture, errcode_ret);
1988  } else {
1989  return NULL;
1990  }
1991 }
1992 
1993 cl_mem
1994 clCreateFromGLRenderbuffer(cl_context context,
1995  cl_mem_flags flags,
1996  cl_GLuint renderbuffer,
1997  cl_int * errcode_ret)
1998 {
1999  f_clCreateFromGLRenderbuffer func;
2000 
2001  if(!so_handle)
2002  open_libopencl_so();
2003 
2004  func = (f_clCreateFromGLRenderbuffer) dlsym(so_handle, "clCreateFromGLRenderbuffer");
2005  if(func) {
2006  return func(context, flags, renderbuffer, errcode_ret);
2007  } else {
2008  return NULL;
2009  }
2010 }
2011 
2012 cl_int
2013 clGetGLObjectInfo(cl_mem memobj,
2014  cl_gl_object_type * gl_object_type,
2015  cl_GLuint * gl_object_name)
2016 {
2017  f_clGetGLObjectInfo func;
2018 
2019  if(!so_handle)
2020  open_libopencl_so();
2021 
2022  func = (f_clGetGLObjectInfo) dlsym(so_handle, "clGetGLObjectInfo");
2023  if(func) {
2024  return func(memobj, gl_object_type, gl_object_name);
2025  } else {
2026  return CL_INVALID_PLATFORM;
2027  }
2028 }
2029 
2030 cl_int
2031 clGetGLTextureInfo(cl_mem memobj,
2032  cl_gl_texture_info param_name,
2033  size_t param_value_size,
2034  void * param_value,
2035  size_t * param_value_size_ret)
2036 {
2037  f_clGetGLTextureInfo func;
2038 
2039  if(!so_handle)
2040  open_libopencl_so();
2041 
2042  func = (f_clGetGLTextureInfo) dlsym(so_handle, "clGetGLTextureInfo");
2043  if(func) {
2044  return func(memobj, param_name, param_value_size, param_value, param_value_size_ret);
2045  } else {
2046  return CL_INVALID_PLATFORM;
2047  }
2048 }
2049 
2050 cl_int
2051 clEnqueueAcquireGLObjects(cl_command_queue command_queue,
2052  cl_uint num_objects,
2053  const cl_mem * mem_objects,
2054  cl_uint num_events_in_wait_list,
2055  const cl_event * event_wait_list,
2056  cl_event * event)
2057 {
2058  f_clEnqueueAcquireGLObjects func;
2059 
2060  if(!so_handle)
2061  open_libopencl_so();
2062 
2063  func = (f_clEnqueueAcquireGLObjects) dlsym(so_handle, "clEnqueueAcquireGLObjects");
2064  if(func) {
2065  return func(command_queue, num_objects, mem_objects, num_events_in_wait_list, event_wait_list, event);
2066  } else {
2067  return CL_INVALID_PLATFORM;
2068  }
2069 }
2070 
2071 cl_int
2072 clEnqueueReleaseGLObjects(cl_command_queue command_queue,
2073  cl_uint num_objects,
2074  const cl_mem * mem_objects,
2075  cl_uint num_events_in_wait_list,
2076  const cl_event * event_wait_list,
2077  cl_event * event)
2078 {
2079  f_clEnqueueReleaseGLObjects func;
2080 
2081  if(!so_handle)
2082  open_libopencl_so();
2083 
2084  func = (f_clEnqueueReleaseGLObjects) dlsym(so_handle, "clEnqueueReleaseGLObjects");
2085  if(func) {
2086  return func(command_queue, num_objects, mem_objects, num_events_in_wait_list, event_wait_list, event);
2087  } else {
2088  return CL_INVALID_PLATFORM;
2089  }
2090 }
2091 
2092 
2093 cl_mem
2094 clCreateFromGLTexture2D(cl_context context,
2095  cl_mem_flags flags,
2096  cl_GLenum target,
2097  cl_GLint miplevel,
2098  cl_GLuint texture,
2099  cl_int * errcode_ret)
2100 {
2101  f_clCreateFromGLTexture2D func;
2102 
2103  if(!so_handle)
2104  open_libopencl_so();
2105 
2106  func = (f_clCreateFromGLTexture2D) dlsym(so_handle, "clCreateFromGLTexture2D");
2107  if(func) {
2108  return func(context, flags, target, miplevel, texture, errcode_ret);
2109  } else {
2110  return NULL;
2111  }
2112 }
2113 
2114 cl_mem
2115 clCreateFromGLTexture3D(cl_context context,
2116  cl_mem_flags flags,
2117  cl_GLenum target,
2118  cl_GLint miplevel,
2119  cl_GLuint texture,
2120  cl_int * errcode_ret)
2121 {
2122  f_clCreateFromGLTexture3D func;
2123 
2124  if(!so_handle)
2125  open_libopencl_so();
2126 
2127  func = (f_clCreateFromGLTexture3D) dlsym(so_handle, "clCreateFromGLTexture3D");
2128  if(func) {
2129  return func(context, flags, target, miplevel, texture, errcode_ret);
2130  } else {
2131  return NULL;
2132  }
2133 }
2134 
2135 cl_int
2136 clGetGLContextInfoKHR(const cl_context_properties * properties,
2137  cl_gl_context_info param_name,
2138  size_t param_value_size,
2139  void * param_value,
2140  size_t * param_value_size_ret)
2141 {
2142  f_clGetGLContextInfoKHR func;
2143 
2144  if(!so_handle)
2145  open_libopencl_so();
2146 
2147  func = (f_clGetGLContextInfoKHR) dlsym(so_handle, "clGetGLContextInfoKHR");
2148  if(func) {
2149  return func(properties, param_name, param_value_size, param_value, param_value_size_ret);
2150  } else {
2151  return CL_INVALID_PLATFORM;
2152  }
2153 }