Compute Library
 22.08
OpenCL.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2022 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, /* use_loader */false))
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 #ifdef __ANDROID__
73  // When running in NDK environment, the above libraries are not accessible.
74  static const std::vector<std::string> android_libraries{ "libOpenCL-pixel.so", "libOpenCL-car.so" };
75 
76  for(const auto &lib : android_libraries)
77  {
78  if(load(lib, /* use_loader */true))
79  {
80  ARM_COMPUTE_ERROR_ON_MSG(this->clBuildProgram_ptr == nullptr, "Failed to load OpenCL symbols from android shared library");
81  return true;
82  }
83  }
84 #endif /* __ANDROID__ */
85 
86  std::cerr << "Couldn't find any OpenCL library.\n";
87  return false;
88 }
89 
90 bool CLSymbols::load(const std::string &library, bool use_loader)
91 {
92  void *handle = dlopen(library.c_str(), RTLD_LAZY | RTLD_LOCAL);
93 
94  if(handle == nullptr)
95  {
96  std::cerr << "Can't load " << library << ": " << dlerror() << "\n";
97  // Set status of loading to failed
98  _loaded.second = false;
99  return false;
100  }
101 
102 #ifdef __ANDROID__
103  typedef void* (*loadOpenCLPointer_t)(const char* name);
104  loadOpenCLPointer_t loadOpenCLPointer;
105  if (use_loader) {
106  typedef void (*enableOpenCL_t)();
107  enableOpenCL_t enableOpenCL =
108  reinterpret_cast<enableOpenCL_t>(dlsym(handle, "enableOpenCL"));
109  enableOpenCL();
110 
111  loadOpenCLPointer = reinterpret_cast<loadOpenCLPointer_t>(
112  dlsym(handle, "loadOpenCLPointer"));
113  } else {
114  loadOpenCLPointer = nullptr;
115  }
116 #define LOAD_FUNCTION_PTR(func_name, _handle) \
117  func_name##_ptr = reinterpret_cast<decltype(func_name) *>( use_loader ? \
118  loadOpenCLPointer(#func_name) : dlsym(handle, #func_name));
119 #else /* __ANDROID__ */
120  (void)use_loader; // Avoid unused warning
121 #define LOAD_FUNCTION_PTR(func_name, handle) \
122  func_name##_ptr = reinterpret_cast<decltype(func_name) *>(dlsym(handle, #func_name));
123 #endif /* __ANDROID__ */
124 
139  LOAD_FUNCTION_PTR(clFlush, handle);
140  LOAD_FUNCTION_PTR(clFinish, handle);
166  LOAD_FUNCTION_PTR(clSVMAlloc, handle);
167  LOAD_FUNCTION_PTR(clSVMFree, handle);
174 
175  // Third-party extensions
177 
178 #undef LOAD_FUNCTION_PTR
179 
180  //Don't call dlclose(handle) or all the symbols will be unloaded !
181 
182  // Disable default loading and set status to successful
183  _loaded = std::make_pair(true, true);
184 
185  return true;
186 }
187 
189 {
191 
192  // Using static objects that rely on OpenCL in their constructor or
193  // destructor is implementation defined according to the OpenCL API
194  // Specification. These objects include CLScheduler.
195  //
196  // For compatibility with OpenCL runtimes that also use static objects to
197  // hold their state, we call a harmless OpenCL function (clGetPlatformIDs
198  // with invalid parameters must result in CL_INVALID_VALUE) to ensure the
199  // runtimes have a chance to initialize their static objects first. Thanks
200  // to C++11 rules about normal program completion (cf [basic.start]), this
201  // ensures their static objects are destroyed last, i.e. after the
202  // singleton CLScheduler is destroyed.
203  //
204  // When OpenCL is not available, this call results in CL_OUT_OF_RESOURCES,
205  // which is equally harmless.
206  (void)clGetPlatformIDs(0, nullptr, nullptr);
207 
208  return CLSymbols::get().clBuildProgram_ptr != nullptr;
209 }
210 } // namespace arm_compute
211 
212 cl_int clEnqueueMarker(cl_command_queue command_queue,
213  cl_event *event)
214 {
217  if(func != nullptr)
218  {
219  return func(command_queue, event);
220  }
221  else
222  {
223  return CL_OUT_OF_RESOURCES;
224  }
225 }
226 
227 cl_int clWaitForEvents(cl_uint num_events,
228  const cl_event *event_list)
229 {
232  if(func != nullptr)
233  {
234  return func(num_events, event_list);
235  }
236  else
237  {
238  return CL_OUT_OF_RESOURCES;
239  }
240 }
241 
242 cl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags flags, void *svm_ptr,
243  size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
244 {
247  if(func != nullptr)
248  {
249  return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
250  }
251  else
252  {
253  return CL_OUT_OF_RESOURCES;
254  }
255 }
256 
257 cl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *svm_ptr, cl_uint num_events_in_wait_list,
258  const cl_event *event_wait_list, cl_event *event)
259 {
262  if(func != nullptr)
263  {
264  return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
265  }
266  else
267  {
268  return CL_OUT_OF_RESOURCES;
269  }
270 }
271 
272 void *clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
273 {
276  if(func != nullptr)
277  {
278  return func(context, flags, size, alignment);
279  }
280  else
281  {
282  return nullptr;
283  }
284 }
285 
286 void clSVMFree(cl_context context, void *svm_pointer)
287 {
290  if(func != nullptr)
291  {
292  func(context, svm_pointer);
293  }
294 }
295 
296 cl_int clGetContextInfo(cl_context context,
297  cl_context_info param_name,
298  size_t param_value_size,
299  void *param_value,
300  size_t *param_value_size_ret)
301 {
304  if(func != nullptr)
305  {
306  return func(context, param_name, param_value_size, param_value, param_value_size_ret);
307  }
308  else
309  {
310  return CL_OUT_OF_RESOURCES;
311  }
312 }
313 
314 cl_command_queue clCreateCommandQueue(cl_context context,
315  cl_device_id device,
316  cl_command_queue_properties properties,
317  cl_int *errcode_ret)
318 {
321  if(func != nullptr)
322  {
323  return func(context, device, properties, errcode_ret);
324  }
325  else
326  {
327  return nullptr;
328  }
329 }
330 
331 cl_command_queue clCreateCommandQueueWithProperties(cl_context context,
332  cl_device_id device,
333  const cl_queue_properties *properties,
334  cl_int *errcode_ret)
335 {
338  if(func != nullptr)
339  {
340  return func(context, device, properties, errcode_ret);
341  }
342  else
343  {
344  return nullptr;
345  }
346 }
347 
348 cl_context clCreateContext(
349  const cl_context_properties *properties,
350  cl_uint num_devices,
351  const cl_device_id *devices,
352  void (*pfn_notify)(const char *, const void *, size_t, void *),
353  void *user_data,
354  cl_int *errcode_ret)
355 {
358  if(func != nullptr)
359  {
360  return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
361  }
362  else
363  {
364  return nullptr;
365  }
366 }
367 
368 cl_context clCreateContextFromType(const cl_context_properties *properties,
369  cl_device_type device_type,
370  void (*pfn_notify)(const char *, const void *, size_t, void *),
371  void *user_data,
372  cl_int *errcode_ret)
373 {
376  if(func != nullptr)
377  {
378  return func(properties, device_type, pfn_notify, user_data, errcode_ret);
379  }
380  else
381  {
382  return nullptr;
383  }
384 }
385 
387  cl_program program,
388  cl_uint num_devices,
389  const cl_device_id *device_list,
390  const char *options,
391  void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
392  void *user_data)
393 {
396  if(func != nullptr)
397  {
398  return func(program, num_devices, device_list, options, pfn_notify, user_data);
399  }
400  else
401  {
402  return CL_OUT_OF_RESOURCES;
403  }
404 }
405 
407  cl_command_queue command_queue,
408  cl_kernel kernel,
409  cl_uint work_dim,
410  const size_t *global_work_offset,
411  const size_t *global_work_size,
412  const size_t *local_work_size,
413  cl_uint num_events_in_wait_list,
414  const cl_event *event_wait_list,
415  cl_event *event)
416 {
419  if(func != nullptr)
420  {
421  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);
422  }
423  else
424  {
425  return CL_OUT_OF_RESOURCES;
426  }
427 }
428 
430  cl_kernel kernel,
431  cl_uint arg_index,
432  size_t arg_size,
433  const void *arg_value)
434 {
437  if(func != nullptr)
438  {
439  return func(kernel, arg_index, arg_size, arg_value);
440  }
441  else
442  {
443  return CL_OUT_OF_RESOURCES;
444  }
445 }
446 
447 cl_int clRetainMemObject(cl_mem memobj)
448 {
451  if(func != nullptr)
452  {
453  return func(memobj);
454  }
455  else
456  {
457  return CL_OUT_OF_RESOURCES;
458  }
459 }
460 
461 cl_int clReleaseMemObject(cl_mem memobj)
462 {
465  if(func != nullptr)
466  {
467  return func(memobj);
468  }
469  else
470  {
471  return CL_OUT_OF_RESOURCES;
472  }
473 }
474 
476  cl_command_queue command_queue,
477  cl_mem memobj,
478  void *mapped_ptr,
479  cl_uint num_events_in_wait_list,
480  const cl_event *event_wait_list,
481  cl_event *event)
482 {
485  if(func != nullptr)
486  {
487  return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
488  }
489  else
490  {
491  return CL_OUT_OF_RESOURCES;
492  }
493 }
494 
495 cl_int clRetainCommandQueue(cl_command_queue command_queue)
496 {
499  if(func != nullptr)
500  {
501  return func(command_queue);
502  }
503  else
504  {
505  return CL_OUT_OF_RESOURCES;
506  }
507 }
508 
509 cl_int clReleaseContext(cl_context context)
510 {
513  if(func != nullptr)
514  {
515  return func(context);
516  }
517  else
518  {
519  return CL_OUT_OF_RESOURCES;
520  }
521 }
522 cl_int clReleaseEvent(cl_event event)
523 {
526  if(func != nullptr)
527  {
528  return func(event);
529  }
530  else
531  {
532  return CL_OUT_OF_RESOURCES;
533  }
534 }
535 
537  cl_command_queue command_queue,
538  cl_mem buffer,
539  cl_bool blocking_write,
540  size_t offset,
541  size_t size,
542  const void *ptr,
543  cl_uint num_events_in_wait_list,
544  const cl_event *event_wait_list,
545  cl_event *event)
546 {
549  if(func != nullptr)
550  {
551  return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
552  }
553  else
554  {
555  return CL_OUT_OF_RESOURCES;
556  }
557 }
558 
560  cl_command_queue command_queue,
561  cl_mem buffer,
562  cl_bool blocking_read,
563  size_t offset,
564  size_t size,
565  void *ptr,
566  cl_uint num_events_in_wait_list,
567  const cl_event *event_wait_list,
568  cl_event *event)
569 {
572  if(func != nullptr)
573  {
574  return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
575  }
576  else
577  {
578  return CL_OUT_OF_RESOURCES;
579  }
580 }
581 
583  cl_program program,
584  cl_device_id device,
585  cl_program_build_info param_name,
586  size_t param_value_size,
587  void *param_value,
588  size_t *param_value_size_ret)
589 {
592  if(func != nullptr)
593  {
594  return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
595  }
596  else
597  {
598  return CL_OUT_OF_RESOURCES;
599  }
600 }
601 
602 cl_int clRetainProgram(cl_program program)
603 {
606  if(func != nullptr)
607  {
608  return func(program);
609  }
610  else
611  {
612  return CL_OUT_OF_RESOURCES;
613  }
614 }
615 
617  cl_command_queue command_queue,
618  cl_mem buffer,
619  cl_bool blocking_map,
620  cl_map_flags map_flags,
621  size_t offset,
622  size_t size,
623  cl_uint num_events_in_wait_list,
624  const cl_event *event_wait_list,
625  cl_event *event,
626  cl_int *errcode_ret)
627 {
630  if(func != nullptr)
631  {
632  return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
633  }
634  else
635  {
636  if(errcode_ret != nullptr)
637  {
638  *errcode_ret = CL_OUT_OF_RESOURCES;
639  }
640  return nullptr;
641  }
642 }
643 
644 cl_int clReleaseCommandQueue(cl_command_queue command_queue)
645 {
648  if(func != nullptr)
649  {
650  return func(command_queue);
651  }
652  else
653  {
654  return CL_OUT_OF_RESOURCES;
655  }
656 }
657 
659  cl_context context,
660  cl_uint num_devices,
661  const cl_device_id *device_list,
662  const size_t *lengths,
663  const unsigned char **binaries,
664  cl_int *binary_status,
665  cl_int *errcode_ret)
666 {
669  if(func != nullptr)
670  {
671  return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
672  }
673  else
674  {
675  if(errcode_ret != nullptr)
676  {
677  *errcode_ret = CL_OUT_OF_RESOURCES;
678  }
679  return nullptr;
680  }
681 }
682 
683 cl_int clRetainContext(cl_context context)
684 {
687  if(func != nullptr)
688  {
689  return func(context);
690  }
691  else
692  {
693  return CL_OUT_OF_RESOURCES;
694  }
695 }
696 
697 cl_int clReleaseProgram(cl_program program)
698 {
701  if(func != nullptr)
702  {
703  return func(program);
704  }
705  else
706  {
707  return CL_OUT_OF_RESOURCES;
708  }
709 }
710 
711 cl_int clFlush(cl_command_queue command_queue)
712 {
715  if(func != nullptr)
716  {
717  return func(command_queue);
718  }
719  else
720  {
721  return CL_OUT_OF_RESOURCES;
722  }
723 }
724 
725 cl_int clFinish(cl_command_queue command_queue)
726 {
729  if(func != nullptr)
730  {
731  return func(command_queue);
732  }
733  else
734  {
735  return CL_OUT_OF_RESOURCES;
736  }
737 }
738 
740  cl_program program,
741  cl_program_info param_name,
742  size_t param_value_size,
743  void *param_value,
744  size_t *param_value_size_ret)
745 {
748  if(func != nullptr)
749  {
750  return func(program, param_name, param_value_size, param_value, param_value_size_ret);
751  }
752  else
753  {
754  return CL_OUT_OF_RESOURCES;
755  }
756 }
757 
758 cl_kernel clCreateKernel(
759  cl_program program,
760  const char *kernel_name,
761  cl_int *errcode_ret)
762 {
765  if(func != nullptr)
766  {
767  return func(program, kernel_name, errcode_ret);
768  }
769  else
770  {
771  if(errcode_ret != nullptr)
772  {
773  *errcode_ret = CL_OUT_OF_RESOURCES;
774  }
775  return nullptr;
776  }
777 }
778 
779 cl_int clRetainKernel(cl_kernel kernel)
780 {
783  if(func != nullptr)
784  {
785  return func(kernel);
786  }
787  else
788  {
789  return CL_OUT_OF_RESOURCES;
790  }
791 }
792 
794  cl_context context,
795  cl_mem_flags flags,
796  size_t size,
797  void *host_ptr,
798  cl_int *errcode_ret)
799 {
802  if(func != nullptr)
803  {
804  return func(context, flags, size, host_ptr, errcode_ret);
805  }
806  else
807  {
808  if(errcode_ret != nullptr)
809  {
810  *errcode_ret = CL_OUT_OF_RESOURCES;
811  }
812  return nullptr;
813  }
814 }
815 
817  cl_context context,
818  cl_uint count,
819  const char **strings,
820  const size_t *lengths,
821  cl_int *errcode_ret)
822 {
825  if(func != nullptr)
826  {
827  return func(context, count, strings, lengths, errcode_ret);
828  }
829  else
830  {
831  if(errcode_ret != nullptr)
832  {
833  *errcode_ret = CL_OUT_OF_RESOURCES;
834  }
835  return nullptr;
836  }
837 }
838 
839 cl_int clReleaseKernel(cl_kernel kernel)
840 {
843  if(func != nullptr)
844  {
845  return func(kernel);
846  }
847  else
848  {
849  return CL_OUT_OF_RESOURCES;
850  }
851 }
852 
853 cl_int clGetDeviceIDs(cl_platform_id platform,
854  cl_device_type device_type,
855  cl_uint num_entries,
856  cl_device_id *devices,
857  cl_uint *num_devices)
858 {
861  if(func != nullptr)
862  {
863  return func(platform, device_type, num_entries, devices, num_devices);
864  }
865  else
866  {
867  return CL_OUT_OF_RESOURCES;
868  }
869 }
870 
871 cl_int clGetDeviceInfo(cl_device_id device,
872  cl_device_info param_name,
873  size_t param_value_size,
874  void *param_value,
875  size_t *param_value_size_ret)
876 {
879  if(func != nullptr)
880  {
881  return func(device, param_name, param_value_size, param_value, param_value_size_ret);
882  }
883  else
884  {
885  return CL_OUT_OF_RESOURCES;
886  }
887 }
888 
889 cl_int clGetMemObjectInfo(cl_mem memobj,
890  cl_mem_info param_name,
891  size_t param_value_size,
892  void *param_value,
893  size_t *param_value_size_ret)
894 {
897  if(func != nullptr)
898  {
899  return func(memobj, param_name, param_value_size, param_value, param_value_size_ret);
900  }
901  else
902  {
903  return CL_OUT_OF_RESOURCES;
904  }
905 }
906 
907 cl_int clRetainEvent(cl_event event)
908 {
911  if(func != nullptr)
912  {
913  return func(event);
914  }
915  else
916  {
917  return CL_OUT_OF_RESOURCES;
918  }
919 }
920 
921 cl_int clGetPlatformInfo(cl_platform_id platform,
922  cl_platform_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(platform, 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 clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
940 {
943  if(func != nullptr)
944  {
945  return func(num_entries, platforms, num_platforms);
946  }
947  else
948  {
949  return CL_OUT_OF_RESOURCES;
950  }
951 }
952 
953 cl_int
954 clGetKernelWorkGroupInfo(cl_kernel kernel,
955  cl_device_id device,
956  cl_kernel_work_group_info param_name,
957  size_t param_value_size,
958  void *param_value,
959  size_t *param_value_size_ret)
960 {
963  if(func != nullptr)
964  {
965  return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
966  }
967  else
968  {
969  return CL_OUT_OF_RESOURCES;
970  }
971 }
972 
973 cl_int
974 clGetCommandQueueInfo(cl_command_queue command_queue,
975  cl_command_queue_info param_name,
976  size_t param_value_size,
977  void *param_value,
978  size_t *param_value_size_ret)
979 {
982  if(func != nullptr)
983  {
984  return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
985  }
986  else
987  {
988  return CL_OUT_OF_RESOURCES;
989  }
990 }
991 
992 cl_int
993 clGetKernelInfo(cl_kernel kernel,
994  cl_kernel_info param_name,
995  size_t param_value_size,
996  void *param_value,
997  size_t *param_value_size_ret)
998 {
1001  if(func != nullptr)
1002  {
1003  return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
1004  }
1005  else
1006  {
1007  return CL_OUT_OF_RESOURCES;
1008  }
1009 }
1010 
1011 cl_int
1013  cl_profiling_info param_name,
1014  size_t param_value_size,
1015  void *param_value,
1016  size_t *param_value_size_ret)
1017 {
1020  if(func != nullptr)
1021  {
1022  return func(event, param_name, param_value_size, param_value, param_value_size_ret);
1023  }
1024  else
1025  {
1026  return CL_OUT_OF_RESOURCES;
1027  }
1028 }
1029 
1030 cl_mem
1031 clCreateImage(cl_context context,
1032  cl_mem_flags flags,
1033  const cl_image_format *image_format,
1034  const cl_image_desc *image_desc,
1035  void *host_ptr,
1036  cl_int *errcode_ret)
1037 {
1040  if(func != nullptr)
1041  {
1042  return func(context, flags, image_format, image_desc, host_ptr, errcode_ret);
1043  }
1044  else
1045  {
1046  if(errcode_ret != nullptr)
1047  {
1048  *errcode_ret = CL_OUT_OF_RESOURCES;
1049  }
1050  return nullptr;
1051  }
1052 }
1053 
1054 cl_int clSetKernelExecInfo(cl_kernel kernel,
1055  cl_kernel_exec_info param_name,
1056  size_t param_value_size,
1057  const void *param_value)
1058 {
1061  if(func != nullptr)
1062  {
1063  return func(kernel, param_name, param_value_size, param_value);
1064  }
1065  else
1066  {
1067  return CL_OUT_OF_RESOURCES;
1068  }
1069 }
1070 
1071 cl_mem
1072 clImportMemoryARM(cl_context context,
1073  cl_mem_flags flags,
1074  const cl_import_properties_arm *properties,
1075  void *memory,
1076  size_t size,
1077  cl_int *errcode_ret)
1078 {
1081  if(func != nullptr)
1082  {
1083  return func(context, flags, properties, memory, size, errcode_ret);
1084  }
1085  else
1086  {
1087  if(errcode_ret != nullptr)
1088  {
1089  *errcode_ret = CL_OUT_OF_RESOURCES;
1090  }
1091  return nullptr;
1092  }
1093 }
Class for loading OpenCL symbols.
Definition: OpenCL.h:61
std::function< decltype(clCreateKernel)> clCreateKernel_ptr
Definition: OpenCL.h:105
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:1084
std::function< decltype(clSVMFree)> clSVMFree_ptr
Definition: OpenCL.h:135
std::function< decltype(clEnqueueSVMUnmap)> clEnqueueSVMUnmap_ptr
Definition: OpenCL.h:137
cl_int clRetainMemObject(cl_mem memobj)
Definition: OpenCL.cpp:447
std::function< decltype(clEnqueueReadBuffer)> clEnqueueReadBuffer_ptr
Definition: OpenCL.h:116
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:536
std::function< decltype(clRetainContext)> clRetainContext_ptr
Definition: OpenCL.h:110
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:1012
std::function< decltype(clGetEventProfilingInfo)> clGetEventProfilingInfo_ptr
Definition: OpenCL.h:133
cl_int clSetKernelExecInfo(cl_kernel kernel, cl_kernel_exec_info param_name, size_t param_value_size, const void *param_value)
Definition: OpenCL.cpp:1054
cl_command_queue clCreateCommandQueueWithProperties(cl_context context, cl_device_id device, const cl_queue_properties *properties, cl_int *errcode_ret)
Definition: OpenCL.cpp:331
std::function< decltype(clGetDeviceInfo)> clGetDeviceInfo_ptr
Definition: OpenCL.h:124
std::function< decltype(clCreateBuffer)> clCreateBuffer_ptr
Definition: OpenCL.h:103
std::function< decltype(clReleaseProgram)> clReleaseProgram_ptr
Definition: OpenCL.h:109
std::function< decltype(clReleaseCommandQueue)> clReleaseCommandQueue_ptr
Definition: OpenCL.h:112
std::function< decltype(clReleaseMemObject)> clReleaseMemObject_ptr
Definition: OpenCL.h:123
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:475
std::function< decltype(clEnqueueSVMMap)> clEnqueueSVMMap_ptr
Definition: OpenCL.h:136
std::function< decltype(clGetContextInfo)> clGetContextInfo_ptr
Definition: OpenCL.h:97
std::function< decltype(clCreateProgramWithSource)> clCreateProgramWithSource_ptr
Definition: OpenCL.h:102
std::function< decltype(clRetainCommandQueue)> clRetainCommandQueue_ptr
Definition: OpenCL.h:120
cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
Definition: OpenCL.cpp:939
std::function< decltype(clRetainProgram)> clRetainProgram_ptr
Definition: OpenCL.h:114
std::function< decltype(clGetProgramInfo)> clGetProgramInfo_ptr
Definition: OpenCL.h:106
cl_int clRetainCommandQueue(cl_command_queue command_queue)
Definition: OpenCL.cpp:495
std::function< decltype(clWaitForEvents)> clWaitForEvents_ptr
Definition: OpenCL.h:139
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:559
cl_int clSetKernelArg(cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value)
Definition: OpenCL.cpp:429
std::function< decltype(clEnqueueUnmapMemObject)> clEnqueueUnmapMemObject_ptr
Definition: OpenCL.h:121
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:1031
cl_int clRetainEvent(cl_event event)
Definition: OpenCL.cpp:907
std::function< decltype(clSVMAlloc)> clSVMAlloc_ptr
Definition: OpenCL.h:134
Copyright (c) 2017-2022 Arm Limited.
cl_int clRetainProgram(cl_program program)
Definition: OpenCL.cpp:602
cl_int clRetainKernel(cl_kernel kernel)
Definition: OpenCL.cpp:779
void clSVMFree(cl_context context, void *svm_pointer)
Definition: OpenCL.cpp:286
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:921
std::function< decltype(clGetPlatformIDs)> clGetPlatformIDs_ptr
Definition: OpenCL.h:129
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:658
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:871
std::function< decltype(clEnqueueNDRangeKernel)> clEnqueueNDRangeKernel_ptr
Definition: OpenCL.h:99
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:739
std::unique_ptr< AssetsLibrary > library
Definition: main.cpp:76
std::function< decltype(clFinish)> clFinish_ptr
Definition: OpenCL.h:108
cl_command_queue clCreateCommandQueue(cl_context context, cl_device_id device, cl_command_queue_properties properties, cl_int *errcode_ret)
Definition: OpenCL.cpp:314
cl_int clFlush(cl_command_queue command_queue)
Definition: OpenCL.cpp:711
cl_int clReleaseCommandQueue(cl_command_queue command_queue)
Definition: OpenCL.cpp:644
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
std::function< decltype(clCreateContext)> clCreateContext_ptr
Definition: OpenCL.h:93
bool load_default()
Load symbols from any of the default OpenCL library names.
Definition: OpenCL.cpp:51
std::function< decltype(clGetKernelWorkGroupInfo)> clGetKernelWorkGroupInfo_ptr
Definition: OpenCL.h:130
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:616
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:257
std::function< decltype(clCreateImage)> clCreateImage_ptr
Definition: OpenCL.h:140
std::function< decltype(clGetDeviceIDs)> clGetDeviceIDs_ptr
Definition: OpenCL.h:125
const char * name
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:406
cl_mem clCreateBuffer(cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret)
Definition: OpenCL.cpp:793
cl_int clEnqueueMarker(cl_command_queue command_queue, cl_event *event)
Definition: OpenCL.cpp:212
std::function< decltype(clEnqueueWriteBuffer)> clEnqueueWriteBuffer_ptr
Definition: OpenCL.h:117
bool load(const std::string &library, bool use_loader=false)
Load symbols from the given OpenCL library path.
Definition: OpenCL.cpp:90
std::function< decltype(clCreateProgramWithBinary)> clCreateProgramWithBinary_ptr
Definition: OpenCL.h:111
std::function< decltype(clGetCommandQueueInfo)> clGetCommandQueueInfo_ptr
Definition: OpenCL.h:131
std::function< decltype(clCreateCommandQueueWithProperties)> clCreateCommandQueueWithProperties_ptr
Definition: OpenCL.h:96
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:368
cl_int clReleaseEvent(cl_event event)
Definition: OpenCL.cpp:522
cl_int clReleaseProgram(cl_program program)
Definition: OpenCL.cpp:697
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:974
std::function< decltype(clBuildProgram)> clBuildProgram_ptr
Definition: OpenCL.h:98
std::function< decltype(clRetainEvent)> clRetainEvent_ptr
Definition: OpenCL.h:127
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:242
std::function< decltype(clRetainKernel)> clRetainKernel_ptr
Definition: OpenCL.h:104
std::function< decltype(clEnqueueMarker)> clEnqueueMarker_ptr
Definition: OpenCL.h:138
cl_int clReleaseKernel(cl_kernel kernel)
Definition: OpenCL.cpp:839
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:296
std::function< decltype(clImportMemoryARM)> clImportMemoryARM_ptr
Definition: OpenCL.h:144
void * clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
Definition: OpenCL.cpp:272
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:816
std::function< decltype(clGetProgramBuildInfo)> clGetProgramBuildInfo_ptr
Definition: OpenCL.h:115
std::function< decltype(clEnqueueMapBuffer)> clEnqueueMapBuffer_ptr
Definition: OpenCL.h:113
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:889
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:954
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:348
#define LOAD_FUNCTION_PTR(func_name, handle)
cl_int clReleaseContext(cl_context context)
Definition: OpenCL.cpp:509
std::function< decltype(clGetMemObjectInfo)> clGetMemObjectInfo_ptr
Definition: OpenCL.h:126
std::function< decltype(clFlush)> clFlush_ptr
Definition: OpenCL.h:107
std::function< decltype(clGetKernelInfo)> clGetKernelInfo_ptr
Definition: OpenCL.h:132
std::function< decltype(clSetKernelExecInfo)> clSetKernelExecInfo_ptr
Definition: OpenCL.h:141
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:1072
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:993
std::function< decltype(clGetPlatformInfo)> clGetPlatformInfo_ptr
Definition: OpenCL.h:128
std::function< decltype(clReleaseEvent)> clReleaseEvent_ptr
Definition: OpenCL.h:118
std::function< decltype(clSetKernelArg)> clSetKernelArg_ptr
Definition: OpenCL.h:100
std::string kernel_name
std::function< decltype(clRetainMemObject)> clRetainMemObject_ptr
Definition: OpenCL.h:122
cl_kernel clCreateKernel(cl_program program, const char *kernel_name, cl_int *errcode_ret)
Definition: OpenCL.cpp:758
cl_int clWaitForEvents(cl_uint num_events, const cl_event *event_list)
Definition: OpenCL.cpp:227
std::function< decltype(clCreateCommandQueue)> clCreateCommandQueue_ptr
Definition: OpenCL.h:95
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:386
std::function< decltype(clCreateContextFromType)> clCreateContextFromType_ptr
Definition: OpenCL.h:94
std::function< decltype(clReleaseContext)> clReleaseContext_ptr
Definition: OpenCL.h:119
cl_int clReleaseMemObject(cl_mem memobj)
Definition: OpenCL.cpp:461
cl_int clRetainContext(cl_context context)
Definition: OpenCL.cpp:683
cl_int clFinish(cl_command_queue command_queue)
Definition: OpenCL.cpp:725
bool opencl_is_available()
Check if OpenCL is available.
Definition: OpenCL.cpp:188
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:582
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:853
std::function< decltype(clReleaseKernel)> clReleaseKernel_ptr
Definition: OpenCL.h:101