Compute Library
 21.02
OpenCL.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
25 #pragma GCC diagnostic push
26 #pragma GCC diagnostic ignored "-Wunused-parameter"
28 #pragma GCC diagnostic pop
29 
30 #include "arm_compute/core/Error.h"
31 
32 #include <dlfcn.h>
33 #include <iostream>
34 
35 namespace arm_compute
36 {
37 CLSymbols::CLSymbols() noexcept(false)
38  : _loaded(
39 {
40  false, false
41 })
42 {
43 }
44 
46 {
47  static CLSymbols symbols;
48  return symbols;
49 }
50 
52 {
53  static const std::vector<std::string> libraries{ "libOpenCL.so", "libGLES_mali.so", "libmali.so" };
54 
55  if(_loaded.first)
56  {
57  return _loaded.second;
58  }
59 
60  // Indicate that default loading has been tried
61  _loaded.first = true;
62 
63  for(const auto &lib : libraries)
64  {
65  if(load(lib))
66  {
67  ARM_COMPUTE_ERROR_ON_MSG(this->clBuildProgram_ptr == nullptr, "Failed to load OpenCL symbols from shared library");
68  return true;
69  }
70  }
71 
72  std::cerr << "Couldn't find any OpenCL library.\n";
73  return false;
74 }
75 
76 bool CLSymbols::load(const std::string &library)
77 {
78  void *handle = dlopen(library.c_str(), RTLD_LAZY | RTLD_LOCAL);
79 
80  if(handle == nullptr)
81  {
82  std::cerr << "Can't load " << library << ": " << dlerror() << "\n";
83  // Set status of loading to failed
84  _loaded.second = false;
85  return false;
86  }
87 
88 #define LOAD_FUNCTION_PTR(func_name, handle) \
89  func_name##_ptr = reinterpret_cast<decltype(func_name) *>(dlsym(handle, #func_name));
90 
104  LOAD_FUNCTION_PTR(clFlush, handle);
105  LOAD_FUNCTION_PTR(clFinish, handle);
130  LOAD_FUNCTION_PTR(clSVMAlloc, handle);
131  LOAD_FUNCTION_PTR(clSVMFree, handle);
138 
139  // Third-party extensions
141 
142 #undef LOAD_FUNCTION_PTR
143 
144  //Don't call dlclose(handle) or all the symbols will be unloaded !
145 
146  // Disable default loading and set status to successful
147  _loaded = std::make_pair(true, true);
148 
149  return true;
150 }
151 
153 {
155  return CLSymbols::get().clBuildProgram_ptr != nullptr;
156 }
157 } // namespace arm_compute
158 
159 cl_int clEnqueueMarker(cl_command_queue command_queue,
160  cl_event *event)
161 {
164  if(func != nullptr)
165  {
166  return func(command_queue, event);
167  }
168  else
169  {
170  return CL_OUT_OF_RESOURCES;
171  }
172 }
173 
174 cl_int clWaitForEvents(cl_uint num_events,
175  const cl_event *event_list)
176 {
179  if(func != nullptr)
180  {
181  return func(num_events, event_list);
182  }
183  else
184  {
185  return CL_OUT_OF_RESOURCES;
186  }
187 }
188 
189 cl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags flags, void *svm_ptr,
190  size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
191 {
194  if(func != nullptr)
195  {
196  return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
197  }
198  else
199  {
200  return CL_OUT_OF_RESOURCES;
201  }
202 }
203 
204 cl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *svm_ptr, cl_uint num_events_in_wait_list,
205  const cl_event *event_wait_list, cl_event *event)
206 {
209  if(func != nullptr)
210  {
211  return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
212  }
213  else
214  {
215  return CL_OUT_OF_RESOURCES;
216  }
217 }
218 
219 void *clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
220 {
223  if(func != nullptr)
224  {
225  return func(context, flags, size, alignment);
226  }
227  else
228  {
229  return nullptr;
230  }
231 }
232 
233 void clSVMFree(cl_context context, void *svm_pointer)
234 {
237  if(func != nullptr)
238  {
239  func(context, svm_pointer);
240  }
241 }
242 
243 cl_int clGetContextInfo(cl_context context,
244  cl_context_info param_name,
245  size_t param_value_size,
246  void *param_value,
247  size_t *param_value_size_ret)
248 {
251  if(func != nullptr)
252  {
253  return func(context, param_name, param_value_size, param_value, param_value_size_ret);
254  }
255  else
256  {
257  return CL_OUT_OF_RESOURCES;
258  }
259 }
260 
261 cl_command_queue clCreateCommandQueue(cl_context context,
262  cl_device_id device,
263  cl_command_queue_properties properties,
264  cl_int *errcode_ret)
265 {
268  if(func != nullptr)
269  {
270  return func(context, device, properties, errcode_ret);
271  }
272  else
273  {
274  return nullptr;
275  }
276 }
277 
278 cl_context clCreateContext(
279  const cl_context_properties *properties,
280  cl_uint num_devices,
281  const cl_device_id *devices,
282  void (*pfn_notify)(const char *, const void *, size_t, void *),
283  void *user_data,
284  cl_int *errcode_ret)
285 {
288  if(func != nullptr)
289  {
290  return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
291  }
292  else
293  {
294  return nullptr;
295  }
296 }
297 
298 cl_context clCreateContextFromType(const cl_context_properties *properties,
299  cl_device_type device_type,
300  void (*pfn_notify)(const char *, const void *, size_t, void *),
301  void *user_data,
302  cl_int *errcode_ret)
303 {
306  if(func != nullptr)
307  {
308  return func(properties, device_type, pfn_notify, user_data, errcode_ret);
309  }
310  else
311  {
312  return nullptr;
313  }
314 }
315 
317  cl_program program,
318  cl_uint num_devices,
319  const cl_device_id *device_list,
320  const char *options,
321  void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
322  void *user_data)
323 {
326  if(func != nullptr)
327  {
328  return func(program, num_devices, device_list, options, pfn_notify, user_data);
329  }
330  else
331  {
332  return CL_OUT_OF_RESOURCES;
333  }
334 }
335 
337  cl_command_queue command_queue,
338  cl_kernel kernel,
339  cl_uint work_dim,
340  const size_t *global_work_offset,
341  const size_t *global_work_size,
342  const size_t *local_work_size,
343  cl_uint num_events_in_wait_list,
344  const cl_event *event_wait_list,
345  cl_event *event)
346 {
349  if(func != nullptr)
350  {
351  return func(command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size, num_events_in_wait_list, event_wait_list, event);
352  }
353  else
354  {
355  return CL_OUT_OF_RESOURCES;
356  }
357 }
358 
360  cl_kernel kernel,
361  cl_uint arg_index,
362  size_t arg_size,
363  const void *arg_value)
364 {
367  if(func != nullptr)
368  {
369  return func(kernel, arg_index, arg_size, arg_value);
370  }
371  else
372  {
373  return CL_OUT_OF_RESOURCES;
374  }
375 }
376 
377 cl_int clRetainMemObject(cl_mem memobj)
378 {
381  if(func != nullptr)
382  {
383  return func(memobj);
384  }
385  else
386  {
387  return CL_OUT_OF_RESOURCES;
388  }
389 }
390 
391 cl_int clReleaseMemObject(cl_mem memobj)
392 {
395  if(func != nullptr)
396  {
397  return func(memobj);
398  }
399  else
400  {
401  return CL_OUT_OF_RESOURCES;
402  }
403 }
404 
406  cl_command_queue command_queue,
407  cl_mem memobj,
408  void *mapped_ptr,
409  cl_uint num_events_in_wait_list,
410  const cl_event *event_wait_list,
411  cl_event *event)
412 {
415  if(func != nullptr)
416  {
417  return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
418  }
419  else
420  {
421  return CL_OUT_OF_RESOURCES;
422  }
423 }
424 
425 cl_int clRetainCommandQueue(cl_command_queue command_queue)
426 {
429  if(func != nullptr)
430  {
431  return func(command_queue);
432  }
433  else
434  {
435  return CL_OUT_OF_RESOURCES;
436  }
437 }
438 
439 cl_int clReleaseContext(cl_context context)
440 {
443  if(func != nullptr)
444  {
445  return func(context);
446  }
447  else
448  {
449  return CL_OUT_OF_RESOURCES;
450  }
451 }
452 cl_int clReleaseEvent(cl_event event)
453 {
456  if(func != nullptr)
457  {
458  return func(event);
459  }
460  else
461  {
462  return CL_OUT_OF_RESOURCES;
463  }
464 }
465 
467  cl_command_queue command_queue,
468  cl_mem buffer,
469  cl_bool blocking_write,
470  size_t offset,
471  size_t size,
472  const void *ptr,
473  cl_uint num_events_in_wait_list,
474  const cl_event *event_wait_list,
475  cl_event *event)
476 {
479  if(func != nullptr)
480  {
481  return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
482  }
483  else
484  {
485  return CL_OUT_OF_RESOURCES;
486  }
487 }
488 
490  cl_command_queue command_queue,
491  cl_mem buffer,
492  cl_bool blocking_read,
493  size_t offset,
494  size_t size,
495  void *ptr,
496  cl_uint num_events_in_wait_list,
497  const cl_event *event_wait_list,
498  cl_event *event)
499 {
502  if(func != nullptr)
503  {
504  return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
505  }
506  else
507  {
508  return CL_OUT_OF_RESOURCES;
509  }
510 }
511 
513  cl_program program,
514  cl_device_id device,
515  cl_program_build_info param_name,
516  size_t param_value_size,
517  void *param_value,
518  size_t *param_value_size_ret)
519 {
522  if(func != nullptr)
523  {
524  return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
525  }
526  else
527  {
528  return CL_OUT_OF_RESOURCES;
529  }
530 }
531 
532 cl_int clRetainProgram(cl_program program)
533 {
536  if(func != nullptr)
537  {
538  return func(program);
539  }
540  else
541  {
542  return CL_OUT_OF_RESOURCES;
543  }
544 }
545 
547  cl_command_queue command_queue,
548  cl_mem buffer,
549  cl_bool blocking_map,
550  cl_map_flags map_flags,
551  size_t offset,
552  size_t size,
553  cl_uint num_events_in_wait_list,
554  const cl_event *event_wait_list,
555  cl_event *event,
556  cl_int *errcode_ret)
557 {
560  if(func != nullptr)
561  {
562  return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
563  }
564  else
565  {
566  if(errcode_ret != nullptr)
567  {
568  *errcode_ret = CL_OUT_OF_RESOURCES;
569  }
570  return nullptr;
571  }
572 }
573 
574 cl_int clReleaseCommandQueue(cl_command_queue command_queue)
575 {
578  if(func != nullptr)
579  {
580  return func(command_queue);
581  }
582  else
583  {
584  return CL_OUT_OF_RESOURCES;
585  }
586 }
587 
589  cl_context context,
590  cl_uint num_devices,
591  const cl_device_id *device_list,
592  const size_t *lengths,
593  const unsigned char **binaries,
594  cl_int *binary_status,
595  cl_int *errcode_ret)
596 {
599  if(func != nullptr)
600  {
601  return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
602  }
603  else
604  {
605  if(errcode_ret != nullptr)
606  {
607  *errcode_ret = CL_OUT_OF_RESOURCES;
608  }
609  return nullptr;
610  }
611 }
612 
613 cl_int clRetainContext(cl_context context)
614 {
617  if(func != nullptr)
618  {
619  return func(context);
620  }
621  else
622  {
623  return CL_OUT_OF_RESOURCES;
624  }
625 }
626 
627 cl_int clReleaseProgram(cl_program program)
628 {
631  if(func != nullptr)
632  {
633  return func(program);
634  }
635  else
636  {
637  return CL_OUT_OF_RESOURCES;
638  }
639 }
640 
641 cl_int clFlush(cl_command_queue command_queue)
642 {
645  if(func != nullptr)
646  {
647  return func(command_queue);
648  }
649  else
650  {
651  return CL_OUT_OF_RESOURCES;
652  }
653 }
654 
655 cl_int clFinish(cl_command_queue command_queue)
656 {
659  if(func != nullptr)
660  {
661  return func(command_queue);
662  }
663  else
664  {
665  return CL_OUT_OF_RESOURCES;
666  }
667 }
668 
670  cl_program program,
671  cl_program_info param_name,
672  size_t param_value_size,
673  void *param_value,
674  size_t *param_value_size_ret)
675 {
678  if(func != nullptr)
679  {
680  return func(program, param_name, param_value_size, param_value, param_value_size_ret);
681  }
682  else
683  {
684  return CL_OUT_OF_RESOURCES;
685  }
686 }
687 
688 cl_kernel clCreateKernel(
689  cl_program program,
690  const char *kernel_name,
691  cl_int *errcode_ret)
692 {
695  if(func != nullptr)
696  {
697  return func(program, kernel_name, errcode_ret);
698  }
699  else
700  {
701  if(errcode_ret != nullptr)
702  {
703  *errcode_ret = CL_OUT_OF_RESOURCES;
704  }
705  return nullptr;
706  }
707 }
708 
709 cl_int clRetainKernel(cl_kernel kernel)
710 {
713  if(func != nullptr)
714  {
715  return func(kernel);
716  }
717  else
718  {
719  return CL_OUT_OF_RESOURCES;
720  }
721 }
722 
724  cl_context context,
725  cl_mem_flags flags,
726  size_t size,
727  void *host_ptr,
728  cl_int *errcode_ret)
729 {
732  if(func != nullptr)
733  {
734  return func(context, flags, size, host_ptr, errcode_ret);
735  }
736  else
737  {
738  if(errcode_ret != nullptr)
739  {
740  *errcode_ret = CL_OUT_OF_RESOURCES;
741  }
742  return nullptr;
743  }
744 }
745 
747  cl_context context,
748  cl_uint count,
749  const char **strings,
750  const size_t *lengths,
751  cl_int *errcode_ret)
752 {
755  if(func != nullptr)
756  {
757  return func(context, count, strings, lengths, errcode_ret);
758  }
759  else
760  {
761  if(errcode_ret != nullptr)
762  {
763  *errcode_ret = CL_OUT_OF_RESOURCES;
764  }
765  return nullptr;
766  }
767 }
768 
769 cl_int clReleaseKernel(cl_kernel kernel)
770 {
773  if(func != nullptr)
774  {
775  return func(kernel);
776  }
777  else
778  {
779  return CL_OUT_OF_RESOURCES;
780  }
781 }
782 
783 cl_int clGetDeviceIDs(cl_platform_id platform,
784  cl_device_type device_type,
785  cl_uint num_entries,
786  cl_device_id *devices,
787  cl_uint *num_devices)
788 {
791  if(func != nullptr)
792  {
793  return func(platform, device_type, num_entries, devices, num_devices);
794  }
795  else
796  {
797  return CL_OUT_OF_RESOURCES;
798  }
799 }
800 
801 cl_int clGetDeviceInfo(cl_device_id device,
802  cl_device_info param_name,
803  size_t param_value_size,
804  void *param_value,
805  size_t *param_value_size_ret)
806 {
809  if(func != nullptr)
810  {
811  return func(device, param_name, param_value_size, param_value, param_value_size_ret);
812  }
813  else
814  {
815  return CL_OUT_OF_RESOURCES;
816  }
817 }
818 
819 cl_int clGetMemObjectInfo(cl_mem memobj,
820  cl_mem_info param_name,
821  size_t param_value_size,
822  void *param_value,
823  size_t *param_value_size_ret)
824 {
827  if(func != nullptr)
828  {
829  return func(memobj, param_name, param_value_size, param_value, param_value_size_ret);
830  }
831  else
832  {
833  return CL_OUT_OF_RESOURCES;
834  }
835 }
836 
837 cl_int clRetainEvent(cl_event event)
838 {
841  if(func != nullptr)
842  {
843  return func(event);
844  }
845  else
846  {
847  return CL_OUT_OF_RESOURCES;
848  }
849 }
850 
851 cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
852 {
855  if(func != nullptr)
856  {
857  return func(num_entries, platforms, num_platforms);
858  }
859  else
860  {
861  return CL_OUT_OF_RESOURCES;
862  }
863 }
864 
865 cl_int
866 clGetKernelWorkGroupInfo(cl_kernel kernel,
867  cl_device_id device,
868  cl_kernel_work_group_info param_name,
869  size_t param_value_size,
870  void *param_value,
871  size_t *param_value_size_ret)
872 {
875  if(func != nullptr)
876  {
877  return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
878  }
879  else
880  {
881  return CL_OUT_OF_RESOURCES;
882  }
883 }
884 
885 cl_int
886 clGetCommandQueueInfo(cl_command_queue command_queue,
887  cl_command_queue_info param_name,
888  size_t param_value_size,
889  void *param_value,
890  size_t *param_value_size_ret)
891 {
894  if(func != nullptr)
895  {
896  return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
897  }
898  else
899  {
900  return CL_OUT_OF_RESOURCES;
901  }
902 }
903 
904 cl_int
905 clGetKernelInfo(cl_kernel kernel,
906  cl_kernel_info param_name,
907  size_t param_value_size,
908  void *param_value,
909  size_t *param_value_size_ret)
910 {
913  if(func != nullptr)
914  {
915  return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
916  }
917  else
918  {
919  return CL_OUT_OF_RESOURCES;
920  }
921 }
922 
923 cl_int
924 clGetEventProfilingInfo(cl_event event,
925  cl_profiling_info param_name,
926  size_t param_value_size,
927  void *param_value,
928  size_t *param_value_size_ret)
929 {
932  if(func != nullptr)
933  {
934  return func(event, param_name, param_value_size, param_value, param_value_size_ret);
935  }
936  else
937  {
938  return CL_OUT_OF_RESOURCES;
939  }
940 }
941 
942 cl_mem
943 clCreateImage(cl_context context,
944  cl_mem_flags flags,
945  const cl_image_format *image_format,
946  const cl_image_desc *image_desc,
947  void *host_ptr,
948  cl_int *errcode_ret)
949 {
952  if(func != nullptr)
953  {
954  return func(context, flags, image_format, image_desc, host_ptr, errcode_ret);
955  }
956  else
957  {
958  if(errcode_ret != nullptr)
959  {
960  *errcode_ret = CL_OUT_OF_RESOURCES;
961  }
962  return nullptr;
963  }
964 }
965 
966 cl_int clSetKernelExecInfo(cl_kernel kernel,
967  cl_kernel_exec_info param_name,
968  size_t param_value_size,
969  const void *param_value)
970 {
973  if(func != nullptr)
974  {
975  return func(kernel, param_name, param_value_size, param_value);
976  }
977  else
978  {
979  return CL_OUT_OF_RESOURCES;
980  }
981 }
982 
983 cl_mem
984 clImportMemoryARM(cl_context context,
985  cl_mem_flags flags,
986  const cl_import_properties_arm *properties,
987  void *memory,
988  size_t size,
989  cl_int *errcode_ret)
990 {
993  if(func != nullptr)
994  {
995  return func(context, flags, properties, memory, size, errcode_ret);
996  }
997  else
998  {
999  if(errcode_ret != nullptr)
1000  {
1001  *errcode_ret = CL_OUT_OF_RESOURCES;
1002  }
1003  return nullptr;
1004  }
1005 }
Class for loading OpenCL symbols.
Definition: OpenCL.h:61
std::function< decltype(clCreateKernel)> clCreateKernel_ptr
Definition: OpenCL.h:103
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:846
std::function< decltype(clSVMFree)> clSVMFree_ptr
Definition: OpenCL.h:132
std::function< decltype(clEnqueueSVMUnmap)> clEnqueueSVMUnmap_ptr
Definition: OpenCL.h:134
cl_int clRetainMemObject(cl_mem memobj)
Definition: OpenCL.cpp:377
std::function< decltype(clEnqueueReadBuffer)> clEnqueueReadBuffer_ptr
Definition: OpenCL.h:114
cl_int clEnqueueWriteBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, size_t offset, size_t size, const void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
Definition: OpenCL.cpp:466
std::function< decltype(clRetainContext)> clRetainContext_ptr
Definition: OpenCL.h:108
cl_int clGetEventProfilingInfo(cl_event event, cl_profiling_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
Definition: OpenCL.cpp:924
std::function< decltype(clGetEventProfilingInfo)> clGetEventProfilingInfo_ptr
Definition: OpenCL.h:130
cl_int clSetKernelExecInfo(cl_kernel kernel, cl_kernel_exec_info param_name, size_t param_value_size, const void *param_value)
Definition: OpenCL.cpp:966
std::function< decltype(clGetDeviceInfo)> clGetDeviceInfo_ptr
Definition: OpenCL.h:122
std::function< decltype(clCreateBuffer)> clCreateBuffer_ptr
Definition: OpenCL.h:101
std::function< decltype(clReleaseProgram)> clReleaseProgram_ptr
Definition: OpenCL.h:107
std::function< decltype(clReleaseCommandQueue)> clReleaseCommandQueue_ptr
Definition: OpenCL.h:110
std::function< decltype(clReleaseMemObject)> clReleaseMemObject_ptr
Definition: OpenCL.h:121
cl_int clEnqueueUnmapMemObject(cl_command_queue command_queue, cl_mem memobj, void *mapped_ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
Definition: OpenCL.cpp:405
std::function< decltype(clEnqueueSVMMap)> clEnqueueSVMMap_ptr
Definition: OpenCL.h:133
std::function< decltype(clGetContextInfo)> clGetContextInfo_ptr
Definition: OpenCL.h:95
std::function< decltype(clCreateProgramWithSource)> clCreateProgramWithSource_ptr
Definition: OpenCL.h:100
std::function< decltype(clRetainCommandQueue)> clRetainCommandQueue_ptr
Definition: OpenCL.h:118
cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
Definition: OpenCL.cpp:851
std::function< decltype(clRetainProgram)> clRetainProgram_ptr
Definition: OpenCL.h:112
std::function< decltype(clGetProgramInfo)> clGetProgramInfo_ptr
Definition: OpenCL.h:104
cl_int clRetainCommandQueue(cl_command_queue command_queue)
Definition: OpenCL.cpp:425
std::function< decltype(clWaitForEvents)> clWaitForEvents_ptr
Definition: OpenCL.h:136
cl_int clEnqueueReadBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, size_t offset, size_t size, void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
Definition: OpenCL.cpp:489
cl_int clSetKernelArg(cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value)
Definition: OpenCL.cpp:359
std::function< decltype(clEnqueueUnmapMemObject)> clEnqueueUnmapMemObject_ptr
Definition: OpenCL.h:119
cl_mem clCreateImage(cl_context context, cl_mem_flags flags, const cl_image_format *image_format, const cl_image_desc *image_desc, void *host_ptr, cl_int *errcode_ret)
Definition: OpenCL.cpp:943
cl_int clRetainEvent(cl_event event)
Definition: OpenCL.cpp:837
std::function< decltype(clSVMAlloc)> clSVMAlloc_ptr
Definition: OpenCL.h:131
Copyright (c) 2017-2021 Arm Limited.
cl_int clRetainProgram(cl_program program)
Definition: OpenCL.cpp:532
cl_int clRetainKernel(cl_kernel kernel)
Definition: OpenCL.cpp:709
void clSVMFree(cl_context context, void *svm_pointer)
Definition: OpenCL.cpp:233
std::function< decltype(clGetPlatformIDs)> clGetPlatformIDs_ptr
Definition: OpenCL.h:126
cl_program clCreateProgramWithBinary(cl_context context, cl_uint num_devices, const cl_device_id *device_list, const size_t *lengths, const unsigned char **binaries, cl_int *binary_status, cl_int *errcode_ret)
Definition: OpenCL.cpp:588
bool load(const std::string &library)
Load symbols from the given OpenCL library path.
Definition: OpenCL.cpp:76
cl_int clGetDeviceInfo(cl_device_id device, cl_device_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
Definition: OpenCL.cpp:801
std::function< decltype(clEnqueueNDRangeKernel)> clEnqueueNDRangeKernel_ptr
Definition: OpenCL.h:97
CLSymbols() noexcept(false)
Default Constructor.
Definition: OpenCL.cpp:37
cl_int clGetProgramInfo(cl_program program, cl_program_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
Definition: OpenCL.cpp:669
std::unique_ptr< AssetsLibrary > library
Definition: main.cpp:78
std::function< decltype(clFinish)> clFinish_ptr
Definition: OpenCL.h:106
cl_command_queue clCreateCommandQueue(cl_context context, cl_device_id device, cl_command_queue_properties properties, cl_int *errcode_ret)
Definition: OpenCL.cpp:261
cl_int clFlush(cl_command_queue command_queue)
Definition: OpenCL.cpp:641
cl_int clReleaseCommandQueue(cl_command_queue command_queue)
Definition: OpenCL.cpp:574
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
std::function< decltype(clCreateContext)> clCreateContext_ptr
Definition: OpenCL.h:92
bool load_default()
Load symbols from any of the default OpenCL library names.
Definition: OpenCL.cpp:51
std::string kernel_name
std::function< decltype(clGetKernelWorkGroupInfo)> clGetKernelWorkGroupInfo_ptr
Definition: OpenCL.h:127
void * clEnqueueMapBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_map, cl_map_flags map_flags, size_t offset, size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event, cl_int *errcode_ret)
Definition: OpenCL.cpp:546
cl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *svm_ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
Definition: OpenCL.cpp:204
std::function< decltype(clCreateImage)> clCreateImage_ptr
Definition: OpenCL.h:137
std::function< decltype(clGetDeviceIDs)> clGetDeviceIDs_ptr
Definition: OpenCL.h:123
cl_int clEnqueueNDRangeKernel(cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim, const size_t *global_work_offset, const size_t *global_work_size, const size_t *local_work_size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
Definition: OpenCL.cpp:336
cl_mem clCreateBuffer(cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret)
Definition: OpenCL.cpp:723
cl_int clEnqueueMarker(cl_command_queue command_queue, cl_event *event)
Definition: OpenCL.cpp:159
std::function< decltype(clEnqueueWriteBuffer)> clEnqueueWriteBuffer_ptr
Definition: OpenCL.h:115
std::function< decltype(clCreateProgramWithBinary)> clCreateProgramWithBinary_ptr
Definition: OpenCL.h:109
std::function< decltype(clGetCommandQueueInfo)> clGetCommandQueueInfo_ptr
Definition: OpenCL.h:128
cl_context clCreateContextFromType(const cl_context_properties *properties, cl_device_type device_type, void(*pfn_notify)(const char *, const void *, size_t, void *), void *user_data, cl_int *errcode_ret)
Definition: OpenCL.cpp:298
cl_int clReleaseEvent(cl_event event)
Definition: OpenCL.cpp:452
cl_int clReleaseProgram(cl_program program)
Definition: OpenCL.cpp:627
FloorUKernelPtr func
cl_int clGetCommandQueueInfo(cl_command_queue command_queue, cl_command_queue_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
Definition: OpenCL.cpp:886
std::function< decltype(clBuildProgram)> clBuildProgram_ptr
Definition: OpenCL.h:96
std::function< decltype(clRetainEvent)> clRetainEvent_ptr
Definition: OpenCL.h:125
cl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags flags, void *svm_ptr, size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
Definition: OpenCL.cpp:189
std::function< decltype(clRetainKernel)> clRetainKernel_ptr
Definition: OpenCL.h:102
std::function< decltype(clEnqueueMarker)> clEnqueueMarker_ptr
Definition: OpenCL.h:135
cl_int clReleaseKernel(cl_kernel kernel)
Definition: OpenCL.cpp:769
cl_int clGetContextInfo(cl_context context, cl_context_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
Definition: OpenCL.cpp:243
std::function< decltype(clImportMemoryARM)> clImportMemoryARM_ptr
Definition: OpenCL.h:141
void * clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
Definition: OpenCL.cpp:219
Wrapper to configure the Khronos OpenCL C++ header.
cl_program clCreateProgramWithSource(cl_context context, cl_uint count, const char **strings, const size_t *lengths, cl_int *errcode_ret)
Definition: OpenCL.cpp:746
std::function< decltype(clGetProgramBuildInfo)> clGetProgramBuildInfo_ptr
Definition: OpenCL.h:113
std::function< decltype(clEnqueueMapBuffer)> clEnqueueMapBuffer_ptr
Definition: OpenCL.h:111
cl_int clGetMemObjectInfo(cl_mem memobj, cl_mem_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
Definition: OpenCL.cpp:819
cl_int clGetKernelWorkGroupInfo(cl_kernel kernel, cl_device_id device, cl_kernel_work_group_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
Definition: OpenCL.cpp:866
cl_context clCreateContext(const cl_context_properties *properties, cl_uint num_devices, const cl_device_id *devices, void(*pfn_notify)(const char *, const void *, size_t, void *), void *user_data, cl_int *errcode_ret)
Definition: OpenCL.cpp:278
#define LOAD_FUNCTION_PTR(func_name, handle)
cl_int clReleaseContext(cl_context context)
Definition: OpenCL.cpp:439
std::function< decltype(clGetMemObjectInfo)> clGetMemObjectInfo_ptr
Definition: OpenCL.h:124
std::function< decltype(clFlush)> clFlush_ptr
Definition: OpenCL.h:105
std::function< decltype(clGetKernelInfo)> clGetKernelInfo_ptr
Definition: OpenCL.h:129
std::function< decltype(clSetKernelExecInfo)> clSetKernelExecInfo_ptr
Definition: OpenCL.h:138
cl_mem clImportMemoryARM(cl_context context, cl_mem_flags flags, const cl_import_properties_arm *properties, void *memory, size_t size, cl_int *errcode_ret)
Definition: OpenCL.cpp:984
cl_int clGetKernelInfo(cl_kernel kernel, cl_kernel_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
Definition: OpenCL.cpp:905
std::function< decltype(clReleaseEvent)> clReleaseEvent_ptr
Definition: OpenCL.h:116
std::function< decltype(clSetKernelArg)> clSetKernelArg_ptr
Definition: OpenCL.h:98
std::function< decltype(clRetainMemObject)> clRetainMemObject_ptr
Definition: OpenCL.h:120
cl_kernel clCreateKernel(cl_program program, const char *kernel_name, cl_int *errcode_ret)
Definition: OpenCL.cpp:688
cl_int clWaitForEvents(cl_uint num_events, const cl_event *event_list)
Definition: OpenCL.cpp:174
std::function< decltype(clCreateCommandQueue)> clCreateCommandQueue_ptr
Definition: OpenCL.h:94
static CLSymbols & get()
Get the static instance of CLSymbols.
Definition: OpenCL.cpp:45
cl_int clBuildProgram(cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data), void *user_data)
Definition: OpenCL.cpp:316
std::function< decltype(clCreateContextFromType)> clCreateContextFromType_ptr
Definition: OpenCL.h:93
std::function< decltype(clReleaseContext)> clReleaseContext_ptr
Definition: OpenCL.h:117
cl_int clReleaseMemObject(cl_mem memobj)
Definition: OpenCL.cpp:391
cl_int clRetainContext(cl_context context)
Definition: OpenCL.cpp:613
cl_int clFinish(cl_command_queue command_queue)
Definition: OpenCL.cpp:655
bool opencl_is_available()
Check if OpenCL is available.
Definition: OpenCL.cpp:152
cl_int clGetProgramBuildInfo(cl_program program, cl_device_id device, cl_program_build_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
Definition: OpenCL.cpp:512
cl_int clGetDeviceIDs(cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id *devices, cl_uint *num_devices)
Definition: OpenCL.cpp:783
std::function< decltype(clReleaseKernel)> clReleaseKernel_ptr
Definition: OpenCL.h:99