25 #pragma GCC diagnostic push 26 #pragma GCC diagnostic ignored "-Wunused-parameter" 28 #pragma GCC diagnostic pop 53 static const std::vector<std::string> libraries{
"libOpenCL.so",
"libGLES_mali.so",
"libmali.so" };
57 return _loaded.second;
63 for(
const auto &lib : libraries)
72 std::cerr <<
"Couldn't find any OpenCL library.\n";
78 void *handle = dlopen(
library.c_str(), RTLD_LAZY | RTLD_LOCAL);
82 std::cerr <<
"Can't load " <<
library <<
": " << dlerror() <<
"\n";
84 _loaded.second =
false;
88 #define LOAD_FUNCTION_PTR(func_name, handle) \ 89 func_name##_ptr = reinterpret_cast<decltype(func_name) *>(dlsym(handle, #func_name)); 144 #undef LOAD_FUNCTION_PTR 149 _loaded = std::make_pair(
true,
true);
185 return func(command_queue, event);
189 return CL_OUT_OF_RESOURCES;
194 const cl_event *event_list)
200 return func(num_events, event_list);
204 return CL_OUT_OF_RESOURCES;
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)
215 return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
219 return CL_OUT_OF_RESOURCES;
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)
230 return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
234 return CL_OUT_OF_RESOURCES;
238 void *
clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags,
size_t size, cl_uint alignment)
244 return func(context, flags, size, alignment);
258 func(context, svm_pointer);
263 cl_context_info param_name,
264 size_t param_value_size,
266 size_t *param_value_size_ret)
272 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
276 return CL_OUT_OF_RESOURCES;
282 cl_command_queue_properties properties,
289 return func(context, device, properties, errcode_ret);
299 const cl_queue_properties *properties,
306 return func(context, device, properties, errcode_ret);
315 const cl_context_properties *properties,
317 const cl_device_id *devices,
318 void (*pfn_notify)(
const char *,
const void *,
size_t,
void *),
326 return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
335 cl_device_type device_type,
336 void (*pfn_notify)(
const char *,
const void *,
size_t,
void *),
344 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
355 const cl_device_id *device_list,
357 void(CL_CALLBACK *pfn_notify)(cl_program program,
void *user_data),
364 return func(program, num_devices, device_list, options, pfn_notify, user_data);
368 return CL_OUT_OF_RESOURCES;
373 cl_command_queue command_queue,
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,
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);
391 return CL_OUT_OF_RESOURCES;
399 const void *arg_value)
405 return func(kernel, arg_index, arg_size, arg_value);
409 return CL_OUT_OF_RESOURCES;
423 return CL_OUT_OF_RESOURCES;
437 return CL_OUT_OF_RESOURCES;
442 cl_command_queue command_queue,
445 cl_uint num_events_in_wait_list,
446 const cl_event *event_wait_list,
453 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
457 return CL_OUT_OF_RESOURCES;
467 return func(command_queue);
471 return CL_OUT_OF_RESOURCES;
481 return func(context);
485 return CL_OUT_OF_RESOURCES;
498 return CL_OUT_OF_RESOURCES;
503 cl_command_queue command_queue,
505 cl_bool blocking_write,
509 cl_uint num_events_in_wait_list,
510 const cl_event *event_wait_list,
517 return func(command_queue, buffer, blocking_write,
offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
521 return CL_OUT_OF_RESOURCES;
526 cl_command_queue command_queue,
528 cl_bool blocking_read,
532 cl_uint num_events_in_wait_list,
533 const cl_event *event_wait_list,
540 return func(command_queue, buffer, blocking_read,
offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
544 return CL_OUT_OF_RESOURCES;
551 cl_program_build_info param_name,
552 size_t param_value_size,
554 size_t *param_value_size_ret)
560 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
564 return CL_OUT_OF_RESOURCES;
574 return func(program);
578 return CL_OUT_OF_RESOURCES;
583 cl_command_queue command_queue,
585 cl_bool blocking_map,
586 cl_map_flags map_flags,
589 cl_uint num_events_in_wait_list,
590 const cl_event *event_wait_list,
598 return func(command_queue, buffer, blocking_map, map_flags,
offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
602 if(errcode_ret !=
nullptr)
604 *errcode_ret = CL_OUT_OF_RESOURCES;
616 return func(command_queue);
620 return CL_OUT_OF_RESOURCES;
627 const cl_device_id *device_list,
628 const size_t *lengths,
629 const unsigned char **binaries,
630 cl_int *binary_status,
637 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
641 if(errcode_ret !=
nullptr)
643 *errcode_ret = CL_OUT_OF_RESOURCES;
655 return func(context);
659 return CL_OUT_OF_RESOURCES;
669 return func(program);
673 return CL_OUT_OF_RESOURCES;
677 cl_int
clFlush(cl_command_queue command_queue)
683 return func(command_queue);
687 return CL_OUT_OF_RESOURCES;
697 return func(command_queue);
701 return CL_OUT_OF_RESOURCES;
707 cl_program_info param_name,
708 size_t param_value_size,
710 size_t *param_value_size_ret)
716 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
720 return CL_OUT_OF_RESOURCES;
737 if(errcode_ret !=
nullptr)
739 *errcode_ret = CL_OUT_OF_RESOURCES;
755 return CL_OUT_OF_RESOURCES;
770 return func(context, flags, size, host_ptr, errcode_ret);
774 if(errcode_ret !=
nullptr)
776 *errcode_ret = CL_OUT_OF_RESOURCES;
785 const char **strings,
786 const size_t *lengths,
793 return func(context, count, strings, lengths, errcode_ret);
797 if(errcode_ret !=
nullptr)
799 *errcode_ret = CL_OUT_OF_RESOURCES;
815 return CL_OUT_OF_RESOURCES;
820 cl_device_type device_type,
822 cl_device_id *devices,
823 cl_uint *num_devices)
829 return func(platform, device_type, num_entries, devices, num_devices);
833 return CL_OUT_OF_RESOURCES;
838 cl_device_info param_name,
839 size_t param_value_size,
841 size_t *param_value_size_ret)
847 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
851 return CL_OUT_OF_RESOURCES;
856 cl_mem_info param_name,
857 size_t param_value_size,
859 size_t *param_value_size_ret)
865 return func(memobj, param_name, param_value_size, param_value, param_value_size_ret);
869 return CL_OUT_OF_RESOURCES;
883 return CL_OUT_OF_RESOURCES;
888 cl_platform_info param_name,
889 size_t param_value_size,
891 size_t *param_value_size_ret)
897 return func(platform, param_name, param_value_size, param_value, param_value_size_ret);
901 return CL_OUT_OF_RESOURCES;
905 cl_int
clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
911 return func(num_entries, platforms, num_platforms);
915 return CL_OUT_OF_RESOURCES;
922 cl_kernel_work_group_info param_name,
923 size_t param_value_size,
925 size_t *param_value_size_ret)
931 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
935 return CL_OUT_OF_RESOURCES;
941 cl_command_queue_info param_name,
942 size_t param_value_size,
944 size_t *param_value_size_ret)
950 return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
954 return CL_OUT_OF_RESOURCES;
960 cl_kernel_info param_name,
961 size_t param_value_size,
963 size_t *param_value_size_ret)
969 return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
973 return CL_OUT_OF_RESOURCES;
979 cl_profiling_info param_name,
980 size_t param_value_size,
982 size_t *param_value_size_ret)
988 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
992 return CL_OUT_OF_RESOURCES;
999 const cl_image_format *image_format,
1000 const cl_image_desc *image_desc,
1002 cl_int *errcode_ret)
1008 return func(context, flags, image_format, image_desc, host_ptr, errcode_ret);
1012 if(errcode_ret !=
nullptr)
1014 *errcode_ret = CL_OUT_OF_RESOURCES;
1021 cl_kernel_exec_info param_name,
1022 size_t param_value_size,
1023 const void *param_value)
1029 return func(kernel, param_name, param_value_size, param_value);
1033 return CL_OUT_OF_RESOURCES;
1040 const cl_import_properties_arm *properties,
1043 cl_int *errcode_ret)
1049 return func(context, flags, properties, memory, size, errcode_ret);
1053 if(errcode_ret !=
nullptr)
1055 *errcode_ret = CL_OUT_OF_RESOURCES;
Class for loading OpenCL symbols.
std::function< decltype(clCreateKernel)> clCreateKernel_ptr
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
std::function< decltype(clSVMFree)> clSVMFree_ptr
std::function< decltype(clEnqueueSVMUnmap)> clEnqueueSVMUnmap_ptr
cl_int clRetainMemObject(cl_mem memobj)
std::function< decltype(clEnqueueReadBuffer)> clEnqueueReadBuffer_ptr
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)
std::function< decltype(clRetainContext)> clRetainContext_ptr
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)
std::function< decltype(clGetEventProfilingInfo)> clGetEventProfilingInfo_ptr
cl_int clSetKernelExecInfo(cl_kernel kernel, cl_kernel_exec_info param_name, size_t param_value_size, const void *param_value)
cl_command_queue clCreateCommandQueueWithProperties(cl_context context, cl_device_id device, const cl_queue_properties *properties, cl_int *errcode_ret)
std::function< decltype(clGetDeviceInfo)> clGetDeviceInfo_ptr
std::function< decltype(clCreateBuffer)> clCreateBuffer_ptr
std::function< decltype(clReleaseProgram)> clReleaseProgram_ptr
std::function< decltype(clReleaseCommandQueue)> clReleaseCommandQueue_ptr
std::function< decltype(clReleaseMemObject)> clReleaseMemObject_ptr
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)
std::function< decltype(clEnqueueSVMMap)> clEnqueueSVMMap_ptr
std::function< decltype(clGetContextInfo)> clGetContextInfo_ptr
std::function< decltype(clCreateProgramWithSource)> clCreateProgramWithSource_ptr
std::function< decltype(clRetainCommandQueue)> clRetainCommandQueue_ptr
cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
std::function< decltype(clRetainProgram)> clRetainProgram_ptr
std::function< decltype(clGetProgramInfo)> clGetProgramInfo_ptr
cl_int clRetainCommandQueue(cl_command_queue command_queue)
std::function< decltype(clWaitForEvents)> clWaitForEvents_ptr
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)
cl_int clSetKernelArg(cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value)
std::function< decltype(clEnqueueUnmapMemObject)> clEnqueueUnmapMemObject_ptr
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)
cl_int clRetainEvent(cl_event event)
std::function< decltype(clSVMAlloc)> clSVMAlloc_ptr
Copyright (c) 2017-2021 Arm Limited.
cl_int clRetainProgram(cl_program program)
cl_int clRetainKernel(cl_kernel kernel)
void clSVMFree(cl_context context, void *svm_pointer)
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)
std::function< decltype(clGetPlatformIDs)> clGetPlatformIDs_ptr
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)
bool load(const std::string &library)
Load symbols from the given OpenCL library path.
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)
std::function< decltype(clEnqueueNDRangeKernel)> clEnqueueNDRangeKernel_ptr
CLSymbols() noexcept(false)
Default Constructor.
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)
std::unique_ptr< AssetsLibrary > library
std::function< decltype(clFinish)> clFinish_ptr
cl_command_queue clCreateCommandQueue(cl_context context, cl_device_id device, cl_command_queue_properties properties, cl_int *errcode_ret)
cl_int clFlush(cl_command_queue command_queue)
cl_int clReleaseCommandQueue(cl_command_queue command_queue)
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
std::function< decltype(clCreateContext)> clCreateContext_ptr
bool load_default()
Load symbols from any of the default OpenCL library names.
std::function< decltype(clGetKernelWorkGroupInfo)> clGetKernelWorkGroupInfo_ptr
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)
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)
std::function< decltype(clCreateImage)> clCreateImage_ptr
std::function< decltype(clGetDeviceIDs)> clGetDeviceIDs_ptr
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)
cl_mem clCreateBuffer(cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret)
cl_int clEnqueueMarker(cl_command_queue command_queue, cl_event *event)
std::function< decltype(clEnqueueWriteBuffer)> clEnqueueWriteBuffer_ptr
std::function< decltype(clCreateProgramWithBinary)> clCreateProgramWithBinary_ptr
std::function< decltype(clGetCommandQueueInfo)> clGetCommandQueueInfo_ptr
std::function< decltype(clCreateCommandQueueWithProperties)> clCreateCommandQueueWithProperties_ptr
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)
cl_int clReleaseEvent(cl_event event)
cl_int clReleaseProgram(cl_program program)
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)
std::function< decltype(clBuildProgram)> clBuildProgram_ptr
std::function< decltype(clRetainEvent)> clRetainEvent_ptr
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)
std::function< decltype(clRetainKernel)> clRetainKernel_ptr
std::function< decltype(clEnqueueMarker)> clEnqueueMarker_ptr
cl_int clReleaseKernel(cl_kernel kernel)
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)
std::function< decltype(clImportMemoryARM)> clImportMemoryARM_ptr
void * clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
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)
std::function< decltype(clGetProgramBuildInfo)> clGetProgramBuildInfo_ptr
std::function< decltype(clEnqueueMapBuffer)> clEnqueueMapBuffer_ptr
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)
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)
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)
#define LOAD_FUNCTION_PTR(func_name, handle)
cl_int clReleaseContext(cl_context context)
std::function< decltype(clGetMemObjectInfo)> clGetMemObjectInfo_ptr
std::function< decltype(clFlush)> clFlush_ptr
std::function< decltype(clGetKernelInfo)> clGetKernelInfo_ptr
std::function< decltype(clSetKernelExecInfo)> clSetKernelExecInfo_ptr
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)
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)
std::function< decltype(clGetPlatformInfo)> clGetPlatformInfo_ptr
std::function< decltype(clReleaseEvent)> clReleaseEvent_ptr
std::function< decltype(clSetKernelArg)> clSetKernelArg_ptr
std::function< decltype(clRetainMemObject)> clRetainMemObject_ptr
cl_kernel clCreateKernel(cl_program program, const char *kernel_name, cl_int *errcode_ret)
cl_int clWaitForEvents(cl_uint num_events, const cl_event *event_list)
std::function< decltype(clCreateCommandQueue)> clCreateCommandQueue_ptr
static CLSymbols & get()
Get the static instance of CLSymbols.
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)
std::function< decltype(clCreateContextFromType)> clCreateContextFromType_ptr
std::function< decltype(clReleaseContext)> clReleaseContext_ptr
cl_int clReleaseMemObject(cl_mem memobj)
cl_int clRetainContext(cl_context context)
cl_int clFinish(cl_command_queue command_queue)
bool opencl_is_available()
Check if OpenCL is available.
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)
cl_int clGetDeviceIDs(cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id *devices, cl_uint *num_devices)
std::function< decltype(clReleaseKernel)> clReleaseKernel_ptr