Compute Library
 21.05
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 
105  LOAD_FUNCTION_PTR(clFlush, handle);
106  LOAD_FUNCTION_PTR(clFinish, handle);
132  LOAD_FUNCTION_PTR(clSVMAlloc, handle);
133  LOAD_FUNCTION_PTR(clSVMFree, handle);
140 
141  // Third-party extensions
143 
144 #undef LOAD_FUNCTION_PTR
145 
146  //Don't call dlclose(handle) or all the symbols will be unloaded !
147 
148  // Disable default loading and set status to successful
149  _loaded = std::make_pair(true, true);
150 
151  return true;
152 }
153 
155 {
157 
158  // Using static objects that rely on OpenCL in their constructor or
159  // destructor is implementation defined according to the OpenCL API
160  // Specification. These objects include CLScheduler.
161  //
162  // For compatibility with OpenCL runtimes that also use static objects to
163  // hold their state, we call a harmless OpenCL function (clGetPlatformIDs
164  // with invalid parameters must result in CL_INVALID_VALUE) to ensure the
165  // runtimes have a chance to initialize their static objects first. Thanks
166  // to C++11 rules about normal program termination (cf [basic.start]), this
167  // ensures their static objects are destroyed last, i.e. after the
168  // singleton CLScheduler is destroyed.
169  //
170  // When OpenCL is not available, this call results in CL_OUT_OF_RESOURCES,
171  // which is equally harmless.
172  (void)clGetPlatformIDs(0, nullptr, nullptr);
173 
174  return CLSymbols::get().clBuildProgram_ptr != nullptr;
175 }
176 } // namespace arm_compute
177 
178 cl_int clEnqueueMarker(cl_command_queue command_queue,
179  cl_event *event)
180 {
183  if(func != nullptr)
184  {
185  return func(command_queue, event);
186  }
187  else
188  {
189  return CL_OUT_OF_RESOURCES;
190  }
191 }
192 
193 cl_int clWaitForEvents(cl_uint num_events,
194  const cl_event *event_list)
195 {
198  if(func != nullptr)
199  {
200  return func(num_events, event_list);
201  }
202  else
203  {
204  return CL_OUT_OF_RESOURCES;
205  }
206 }
207 
208 cl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags flags, void *svm_ptr,
209  size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
210 {
213  if(func != nullptr)
214  {
215  return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
216  }
217  else
218  {
219  return CL_OUT_OF_RESOURCES;
220  }
221 }
222 
223 cl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *svm_ptr, cl_uint num_events_in_wait_list,
224  const cl_event *event_wait_list, cl_event *event)
225 {
228  if(func != nullptr)
229  {
230  return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
231  }
232  else
233  {
234  return CL_OUT_OF_RESOURCES;
235  }
236 }
237 
238 void *clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
239 {
242  if(func != nullptr)
243  {
244  return func(context, flags, size, alignment);
245  }
246  else
247  {
248  return nullptr;
249  }
250 }
251 
252 void clSVMFree(cl_context context, void *svm_pointer)
253 {
256  if(func != nullptr)
257  {
258  func(context, svm_pointer);
259  }
260 }
261 
262 cl_int clGetContextInfo(cl_context context,
263  cl_context_info param_name,
264  size_t param_value_size,
265  void *param_value,
266  size_t *param_value_size_ret)
267 {
270  if(func != nullptr)
271  {
272  return func(context, param_name, param_value_size, param_value, param_value_size_ret);
273  }
274  else
275  {
276  return CL_OUT_OF_RESOURCES;
277  }
278 }
279 
280 cl_command_queue clCreateCommandQueue(cl_context context,
281  cl_device_id device,
282  cl_command_queue_properties properties,
283  cl_int *errcode_ret)
284 {
287  if(func != nullptr)
288  {
289  return func(context, device, properties, errcode_ret);
290  }
291  else
292  {
293  return nullptr;
294  }
295 }
296 
297 cl_command_queue clCreateCommandQueueWithProperties(cl_context context,
298  cl_device_id device,
299  const cl_queue_properties *properties,
300  cl_int *errcode_ret)
301 {
304  if(func != nullptr)
305  {
306  return func(context, device, properties, errcode_ret);
307  }
308  else
309  {
310  return nullptr;
311  }
312 }
313 
314 cl_context clCreateContext(
315  const cl_context_properties *properties,
316  cl_uint num_devices,
317  const cl_device_id *devices,
318  void (*pfn_notify)(const char *, const void *, size_t, void *),
319  void *user_data,
320  cl_int *errcode_ret)
321 {
324  if(func != nullptr)
325  {
326  return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
327  }
328  else
329  {
330  return nullptr;
331  }
332 }
333 
334 cl_context clCreateContextFromType(const cl_context_properties *properties,
335  cl_device_type device_type,
336  void (*pfn_notify)(const char *, const void *, size_t, void *),
337  void *user_data,
338  cl_int *errcode_ret)
339 {
342  if(func != nullptr)
343  {
344  return func(properties, device_type, pfn_notify, user_data, errcode_ret);
345  }
346  else
347  {
348  return nullptr;
349  }
350 }
351 
353  cl_program program,
354  cl_uint num_devices,
355  const cl_device_id *device_list,
356  const char *options,
357  void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
358  void *user_data)
359 {
362  if(func != nullptr)
363  {
364  return func(program, num_devices, device_list, options, pfn_notify, user_data);
365  }
366  else
367  {
368  return CL_OUT_OF_RESOURCES;
369  }
370 }
371 
373  cl_command_queue command_queue,
374  cl_kernel kernel,
375  cl_uint work_dim,
376  const size_t *global_work_offset,
377  const size_t *global_work_size,
378  const size_t *local_work_size,
379  cl_uint num_events_in_wait_list,
380  const cl_event *event_wait_list,
381  cl_event *event)
382 {
385  if(func != nullptr)
386  {
387  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);
388  }
389  else
390  {
391  return CL_OUT_OF_RESOURCES;
392  }
393 }
394 
396  cl_kernel kernel,
397  cl_uint arg_index,
398  size_t arg_size,
399  const void *arg_value)
400 {
403  if(func != nullptr)
404  {
405  return func(kernel, arg_index, arg_size, arg_value);
406  }
407  else
408  {
409  return CL_OUT_OF_RESOURCES;
410  }
411 }
412 
413 cl_int clRetainMemObject(cl_mem memobj)
414 {
417  if(func != nullptr)
418  {
419  return func(memobj);
420  }
421  else
422  {
423  return CL_OUT_OF_RESOURCES;
424  }
425 }
426 
427 cl_int clReleaseMemObject(cl_mem memobj)
428 {
431  if(func != nullptr)
432  {
433  return func(memobj);
434  }
435  else
436  {
437  return CL_OUT_OF_RESOURCES;
438  }
439 }
440 
442  cl_command_queue command_queue,
443  cl_mem memobj,
444  void *mapped_ptr,
445  cl_uint num_events_in_wait_list,
446  const cl_event *event_wait_list,
447  cl_event *event)
448 {
451  if(func != nullptr)
452  {
453  return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
454  }
455  else
456  {
457  return CL_OUT_OF_RESOURCES;
458  }
459 }
460 
461 cl_int clRetainCommandQueue(cl_command_queue command_queue)
462 {
465  if(func != nullptr)
466  {
467  return func(command_queue);
468  }
469  else
470  {
471  return CL_OUT_OF_RESOURCES;
472  }
473 }
474 
475 cl_int clReleaseContext(cl_context context)
476 {
479  if(func != nullptr)
480  {
481  return func(context);
482  }
483  else
484  {
485  return CL_OUT_OF_RESOURCES;
486  }
487 }
488 cl_int clReleaseEvent(cl_event event)
489 {
492  if(func != nullptr)
493  {
494  return func(event);
495  }
496  else
497  {
498  return CL_OUT_OF_RESOURCES;
499  }
500 }
501 
503  cl_command_queue command_queue,
504  cl_mem buffer,
505  cl_bool blocking_write,
506  size_t offset,
507  size_t size,
508  const void *ptr,
509  cl_uint num_events_in_wait_list,
510  const cl_event *event_wait_list,
511  cl_event *event)
512 {
515  if(func != nullptr)
516  {
517  return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
518  }
519  else
520  {
521  return CL_OUT_OF_RESOURCES;
522  }
523 }
524 
526  cl_command_queue command_queue,
527  cl_mem buffer,
528  cl_bool blocking_read,
529  size_t offset,
530  size_t size,
531  void *ptr,
532  cl_uint num_events_in_wait_list,
533  const cl_event *event_wait_list,
534  cl_event *event)
535 {
538  if(func != nullptr)
539  {
540  return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
541  }
542  else
543  {
544  return CL_OUT_OF_RESOURCES;
545  }
546 }
547 
549  cl_program program,
550  cl_device_id device,
551  cl_program_build_info param_name,
552  size_t param_value_size,
553  void *param_value,
554  size_t *param_value_size_ret)
555 {
558  if(func != nullptr)
559  {
560  return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
561  }
562  else
563  {
564  return CL_OUT_OF_RESOURCES;
565  }
566 }
567 
568 cl_int clRetainProgram(cl_program program)
569 {
572  if(func != nullptr)
573  {
574  return func(program);
575  }
576  else
577  {
578  return CL_OUT_OF_RESOURCES;
579  }
580 }
581 
583  cl_command_queue command_queue,
584  cl_mem buffer,
585  cl_bool blocking_map,
586  cl_map_flags map_flags,
587  size_t offset,
588  size_t size,
589  cl_uint num_events_in_wait_list,
590  const cl_event *event_wait_list,
591  cl_event *event,
592  cl_int *errcode_ret)
593 {
596  if(func != nullptr)
597  {
598  return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
599  }
600  else
601  {
602  if(errcode_ret != nullptr)
603  {
604  *errcode_ret = CL_OUT_OF_RESOURCES;
605  }
606  return nullptr;
607  }
608 }
609 
610 cl_int clReleaseCommandQueue(cl_command_queue command_queue)
611 {
614  if(func != nullptr)
615  {
616  return func(command_queue);
617  }
618  else
619  {
620  return CL_OUT_OF_RESOURCES;
621  }
622 }
623 
625  cl_context context,
626  cl_uint num_devices,
627  const cl_device_id *device_list,
628  const size_t *lengths,
629  const unsigned char **binaries,
630  cl_int *binary_status,
631  cl_int *errcode_ret)
632 {
635  if(func != nullptr)
636  {
637  return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
638  }
639  else
640  {
641  if(errcode_ret != nullptr)
642  {
643  *errcode_ret = CL_OUT_OF_RESOURCES;
644  }
645  return nullptr;
646  }
647 }
648 
649 cl_int clRetainContext(cl_context context)
650 {
653  if(func != nullptr)
654  {
655  return func(context);
656  }
657  else
658  {
659  return CL_OUT_OF_RESOURCES;
660  }
661 }
662 
663 cl_int clReleaseProgram(cl_program program)
664 {
667  if(func != nullptr)
668  {
669  return func(program);
670  }
671  else
672  {
673  return CL_OUT_OF_RESOURCES;
674  }
675 }
676 
677 cl_int clFlush(cl_command_queue command_queue)
678 {
681  if(func != nullptr)
682  {
683  return func(command_queue);
684  }
685  else
686  {
687  return CL_OUT_OF_RESOURCES;
688  }
689 }
690 
691 cl_int clFinish(cl_command_queue command_queue)
692 {
695  if(func != nullptr)
696  {
697  return func(command_queue);
698  }
699  else
700  {
701  return CL_OUT_OF_RESOURCES;
702  }
703 }
704 
706  cl_program program,
707  cl_program_info param_name,
708  size_t param_value_size,
709  void *param_value,
710  size_t *param_value_size_ret)
711 {
714  if(func != nullptr)
715  {
716  return func(program, param_name, param_value_size, param_value, param_value_size_ret);
717  }
718  else
719  {
720  return CL_OUT_OF_RESOURCES;
721  }
722 }
723 
724 cl_kernel clCreateKernel(
725  cl_program program,
726  const char *kernel_name,
727  cl_int *errcode_ret)
728 {
731  if(func != nullptr)
732  {
733  return func(program, kernel_name, errcode_ret);
734  }
735  else
736  {
737  if(errcode_ret != nullptr)
738  {
739  *errcode_ret = CL_OUT_OF_RESOURCES;
740  }
741  return nullptr;
742  }
743 }
744 
745 cl_int clRetainKernel(cl_kernel kernel)
746 {
749  if(func != nullptr)
750  {
751  return func(kernel);
752  }
753  else
754  {
755  return CL_OUT_OF_RESOURCES;
756  }
757 }
758 
760  cl_context context,
761  cl_mem_flags flags,
762  size_t size,
763  void *host_ptr,
764  cl_int *errcode_ret)
765 {
768  if(func != nullptr)
769  {
770  return func(context, flags, size, host_ptr, errcode_ret);
771  }
772  else
773  {
774  if(errcode_ret != nullptr)
775  {
776  *errcode_ret = CL_OUT_OF_RESOURCES;
777  }
778  return nullptr;
779  }
780 }
781 
783  cl_context context,
784  cl_uint count,
785  const char **strings,
786  const size_t *lengths,
787  cl_int *errcode_ret)
788 {
791  if(func != nullptr)
792  {
793  return func(context, count, strings, lengths, errcode_ret);
794  }
795  else
796  {
797  if(errcode_ret != nullptr)
798  {
799  *errcode_ret = CL_OUT_OF_RESOURCES;
800  }
801  return nullptr;
802  }
803 }
804 
805 cl_int clReleaseKernel(cl_kernel kernel)
806 {
809  if(func != nullptr)
810  {
811  return func(kernel);
812  }
813  else
814  {
815  return CL_OUT_OF_RESOURCES;
816  }
817 }
818 
819 cl_int clGetDeviceIDs(cl_platform_id platform,
820  cl_device_type device_type,
821  cl_uint num_entries,
822  cl_device_id *devices,
823  cl_uint *num_devices)
824 {
827  if(func != nullptr)
828  {
829  return func(platform, device_type, num_entries, devices, num_devices);
830  }
831  else
832  {
833  return CL_OUT_OF_RESOURCES;
834  }
835 }
836 
837 cl_int clGetDeviceInfo(cl_device_id device,
838  cl_device_info param_name,
839  size_t param_value_size,
840  void *param_value,
841  size_t *param_value_size_ret)
842 {
845  if(func != nullptr)
846  {
847  return func(device, param_name, param_value_size, param_value, param_value_size_ret);
848  }
849  else
850  {
851  return CL_OUT_OF_RESOURCES;
852  }
853 }
854 
855 cl_int clGetMemObjectInfo(cl_mem memobj,
856  cl_mem_info param_name,
857  size_t param_value_size,
858  void *param_value,
859  size_t *param_value_size_ret)
860 {
863  if(func != nullptr)
864  {
865  return func(memobj, param_name, param_value_size, param_value, param_value_size_ret);
866  }
867  else
868  {
869  return CL_OUT_OF_RESOURCES;
870  }
871 }
872 
873 cl_int clRetainEvent(cl_event event)
874 {
877  if(func != nullptr)
878  {
879  return func(event);
880  }
881  else
882  {
883  return CL_OUT_OF_RESOURCES;
884  }
885 }
886 
887 cl_int clGetPlatformInfo(cl_platform_id platform,
888  cl_platform_info param_name,
889  size_t param_value_size,
890  void *param_value,
891  size_t *param_value_size_ret)
892 {
895  if(func != nullptr)
896  {
897  return func(platform, param_name, param_value_size, param_value, param_value_size_ret);
898  }
899  else
900  {
901  return CL_OUT_OF_RESOURCES;
902  }
903 }
904 
905 cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
906 {
909  if(func != nullptr)
910  {
911  return func(num_entries, platforms, num_platforms);
912  }
913  else
914  {
915  return CL_OUT_OF_RESOURCES;
916  }
917 }
918 
919 cl_int
920 clGetKernelWorkGroupInfo(cl_kernel kernel,
921  cl_device_id device,
922  cl_kernel_work_group_info param_name,
923  size_t param_value_size,
924  void *param_value,
925  size_t *param_value_size_ret)
926 {
929  if(func != nullptr)
930  {
931  return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
932  }
933  else
934  {
935  return CL_OUT_OF_RESOURCES;
936  }
937 }
938 
939 cl_int
940 clGetCommandQueueInfo(cl_command_queue command_queue,
941  cl_command_queue_info param_name,
942  size_t param_value_size,
943  void *param_value,
944  size_t *param_value_size_ret)
945 {
948  if(func != nullptr)
949  {
950  return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
951  }
952  else
953  {
954  return CL_OUT_OF_RESOURCES;
955  }
956 }
957 
958 cl_int
959 clGetKernelInfo(cl_kernel kernel,
960  cl_kernel_info param_name,
961  size_t param_value_size,
962  void *param_value,
963  size_t *param_value_size_ret)
964 {
967  if(func != nullptr)
968  {
969  return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
970  }
971  else
972  {
973  return CL_OUT_OF_RESOURCES;
974  }
975 }
976 
977 cl_int
978 clGetEventProfilingInfo(cl_event event,
979  cl_profiling_info param_name,
980  size_t param_value_size,
981  void *param_value,
982  size_t *param_value_size_ret)
983 {
986  if(func != nullptr)
987  {
988  return func(event, param_name, param_value_size, param_value, param_value_size_ret);
989  }
990  else
991  {
992  return CL_OUT_OF_RESOURCES;
993  }
994 }
995 
996 cl_mem
997 clCreateImage(cl_context context,
998  cl_mem_flags flags,
999  const cl_image_format *image_format,
1000  const cl_image_desc *image_desc,
1001  void *host_ptr,
1002  cl_int *errcode_ret)
1003 {
1006  if(func != nullptr)
1007  {
1008  return func(context, flags, image_format, image_desc, host_ptr, errcode_ret);
1009  }
1010  else
1011  {
1012  if(errcode_ret != nullptr)
1013  {
1014  *errcode_ret = CL_OUT_OF_RESOURCES;
1015  }
1016  return nullptr;
1017  }
1018 }
1019 
1020 cl_int clSetKernelExecInfo(cl_kernel kernel,
1021  cl_kernel_exec_info param_name,
1022  size_t param_value_size,
1023  const void *param_value)
1024 {
1027  if(func != nullptr)
1028  {
1029  return func(kernel, param_name, param_value_size, param_value);
1030  }
1031  else
1032  {
1033  return CL_OUT_OF_RESOURCES;
1034  }
1035 }
1036 
1037 cl_mem
1038 clImportMemoryARM(cl_context context,
1039  cl_mem_flags flags,
1040  const cl_import_properties_arm *properties,
1041  void *memory,
1042  size_t size,
1043  cl_int *errcode_ret)
1044 {
1047  if(func != nullptr)
1048  {
1049  return func(context, flags, properties, memory, size, errcode_ret);
1050  }
1051  else
1052  {
1053  if(errcode_ret != nullptr)
1054  {
1055  *errcode_ret = CL_OUT_OF_RESOURCES;
1056  }
1057  return nullptr;
1058  }
1059 }
Class for loading OpenCL symbols.
Definition: OpenCL.h:61
std::function< decltype(clCreateKernel)> clCreateKernel_ptr
Definition: OpenCL.h:104
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:861
std::function< decltype(clSVMFree)> clSVMFree_ptr
Definition: OpenCL.h:134
std::function< decltype(clEnqueueSVMUnmap)> clEnqueueSVMUnmap_ptr
Definition: OpenCL.h:136
cl_int clRetainMemObject(cl_mem memobj)
Definition: OpenCL.cpp:413
std::function< decltype(clEnqueueReadBuffer)> clEnqueueReadBuffer_ptr
Definition: OpenCL.h:115
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:502
std::function< decltype(clRetainContext)> clRetainContext_ptr
Definition: OpenCL.h:109
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:978
std::function< decltype(clGetEventProfilingInfo)> clGetEventProfilingInfo_ptr
Definition: OpenCL.h:132
cl_int clSetKernelExecInfo(cl_kernel kernel, cl_kernel_exec_info param_name, size_t param_value_size, const void *param_value)
Definition: OpenCL.cpp:1020
cl_command_queue clCreateCommandQueueWithProperties(cl_context context, cl_device_id device, const cl_queue_properties *properties, cl_int *errcode_ret)
Definition: OpenCL.cpp:297
std::function< decltype(clGetDeviceInfo)> clGetDeviceInfo_ptr
Definition: OpenCL.h:123
std::function< decltype(clCreateBuffer)> clCreateBuffer_ptr
Definition: OpenCL.h:102
std::function< decltype(clReleaseProgram)> clReleaseProgram_ptr
Definition: OpenCL.h:108
std::function< decltype(clReleaseCommandQueue)> clReleaseCommandQueue_ptr
Definition: OpenCL.h:111
std::function< decltype(clReleaseMemObject)> clReleaseMemObject_ptr
Definition: OpenCL.h:122
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:441
std::function< decltype(clEnqueueSVMMap)> clEnqueueSVMMap_ptr
Definition: OpenCL.h:135
std::function< decltype(clGetContextInfo)> clGetContextInfo_ptr
Definition: OpenCL.h:96
std::function< decltype(clCreateProgramWithSource)> clCreateProgramWithSource_ptr
Definition: OpenCL.h:101
std::function< decltype(clRetainCommandQueue)> clRetainCommandQueue_ptr
Definition: OpenCL.h:119
cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
Definition: OpenCL.cpp:905
std::function< decltype(clRetainProgram)> clRetainProgram_ptr
Definition: OpenCL.h:113
std::function< decltype(clGetProgramInfo)> clGetProgramInfo_ptr
Definition: OpenCL.h:105
cl_int clRetainCommandQueue(cl_command_queue command_queue)
Definition: OpenCL.cpp:461
std::function< decltype(clWaitForEvents)> clWaitForEvents_ptr
Definition: OpenCL.h:138
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:525
cl_int clSetKernelArg(cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value)
Definition: OpenCL.cpp:395
std::function< decltype(clEnqueueUnmapMemObject)> clEnqueueUnmapMemObject_ptr
Definition: OpenCL.h:120
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:997
cl_int clRetainEvent(cl_event event)
Definition: OpenCL.cpp:873
std::function< decltype(clSVMAlloc)> clSVMAlloc_ptr
Definition: OpenCL.h:133
Copyright (c) 2017-2021 Arm Limited.
cl_int clRetainProgram(cl_program program)
Definition: OpenCL.cpp:568
cl_int clRetainKernel(cl_kernel kernel)
Definition: OpenCL.cpp:745
void clSVMFree(cl_context context, void *svm_pointer)
Definition: OpenCL.cpp:252
cl_int clGetPlatformInfo(cl_platform_id platform, cl_platform_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
Definition: OpenCL.cpp:887
std::function< decltype(clGetPlatformIDs)> clGetPlatformIDs_ptr
Definition: OpenCL.h:128
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:624
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:837
std::function< decltype(clEnqueueNDRangeKernel)> clEnqueueNDRangeKernel_ptr
Definition: OpenCL.h:98
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:705
std::unique_ptr< AssetsLibrary > library
Definition: main.cpp:75
std::function< decltype(clFinish)> clFinish_ptr
Definition: OpenCL.h:107
cl_command_queue clCreateCommandQueue(cl_context context, cl_device_id device, cl_command_queue_properties properties, cl_int *errcode_ret)
Definition: OpenCL.cpp:280
cl_int clFlush(cl_command_queue command_queue)
Definition: OpenCL.cpp:677
cl_int clReleaseCommandQueue(cl_command_queue command_queue)
Definition: OpenCL.cpp:610
#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:129
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:582
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:223
std::function< decltype(clCreateImage)> clCreateImage_ptr
Definition: OpenCL.h:139
std::function< decltype(clGetDeviceIDs)> clGetDeviceIDs_ptr
Definition: OpenCL.h:124
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:372
cl_mem clCreateBuffer(cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret)
Definition: OpenCL.cpp:759
cl_int clEnqueueMarker(cl_command_queue command_queue, cl_event *event)
Definition: OpenCL.cpp:178
std::function< decltype(clEnqueueWriteBuffer)> clEnqueueWriteBuffer_ptr
Definition: OpenCL.h:116
std::function< decltype(clCreateProgramWithBinary)> clCreateProgramWithBinary_ptr
Definition: OpenCL.h:110
std::function< decltype(clGetCommandQueueInfo)> clGetCommandQueueInfo_ptr
Definition: OpenCL.h:130
std::function< decltype(clCreateCommandQueueWithProperties)> clCreateCommandQueueWithProperties_ptr
Definition: OpenCL.h:95
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:334
cl_int clReleaseEvent(cl_event event)
Definition: OpenCL.cpp:488
cl_int clReleaseProgram(cl_program program)
Definition: OpenCL.cpp:663
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:940
std::function< decltype(clBuildProgram)> clBuildProgram_ptr
Definition: OpenCL.h:97
std::function< decltype(clRetainEvent)> clRetainEvent_ptr
Definition: OpenCL.h:126
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:208
std::function< decltype(clRetainKernel)> clRetainKernel_ptr
Definition: OpenCL.h:103
std::function< decltype(clEnqueueMarker)> clEnqueueMarker_ptr
Definition: OpenCL.h:137
cl_int clReleaseKernel(cl_kernel kernel)
Definition: OpenCL.cpp:805
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:262
std::function< decltype(clImportMemoryARM)> clImportMemoryARM_ptr
Definition: OpenCL.h:143
void * clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
Definition: OpenCL.cpp:238
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:782
std::function< decltype(clGetProgramBuildInfo)> clGetProgramBuildInfo_ptr
Definition: OpenCL.h:114
std::function< decltype(clEnqueueMapBuffer)> clEnqueueMapBuffer_ptr
Definition: OpenCL.h:112
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:855
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:920
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:314
#define LOAD_FUNCTION_PTR(func_name, handle)
cl_int clReleaseContext(cl_context context)
Definition: OpenCL.cpp:475
std::function< decltype(clGetMemObjectInfo)> clGetMemObjectInfo_ptr
Definition: OpenCL.h:125
std::function< decltype(clFlush)> clFlush_ptr
Definition: OpenCL.h:106
std::function< decltype(clGetKernelInfo)> clGetKernelInfo_ptr
Definition: OpenCL.h:131
std::function< decltype(clSetKernelExecInfo)> clSetKernelExecInfo_ptr
Definition: OpenCL.h:140
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:1038
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:959
std::function< decltype(clGetPlatformInfo)> clGetPlatformInfo_ptr
Definition: OpenCL.h:127
std::function< decltype(clReleaseEvent)> clReleaseEvent_ptr
Definition: OpenCL.h:117
std::function< decltype(clSetKernelArg)> clSetKernelArg_ptr
Definition: OpenCL.h:99
std::function< decltype(clRetainMemObject)> clRetainMemObject_ptr
Definition: OpenCL.h:121
cl_kernel clCreateKernel(cl_program program, const char *kernel_name, cl_int *errcode_ret)
Definition: OpenCL.cpp:724
cl_int clWaitForEvents(cl_uint num_events, const cl_event *event_list)
Definition: OpenCL.cpp:193
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:352
std::function< decltype(clCreateContextFromType)> clCreateContextFromType_ptr
Definition: OpenCL.h:93
std::function< decltype(clReleaseContext)> clReleaseContext_ptr
Definition: OpenCL.h:118
cl_int clReleaseMemObject(cl_mem memobj)
Definition: OpenCL.cpp:427
cl_int clRetainContext(cl_context context)
Definition: OpenCL.cpp:649
cl_int clFinish(cl_command_queue command_queue)
Definition: OpenCL.cpp:691
bool opencl_is_available()
Check if OpenCL is available.
Definition: OpenCL.cpp:154
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:548
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:819
std::function< decltype(clReleaseKernel)> clReleaseKernel_ptr
Definition: OpenCL.h:100