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)); 142 #undef LOAD_FUNCTION_PTR 147 _loaded = std::make_pair(
true,
true);
166 return func(command_queue, event);
170 return CL_OUT_OF_RESOURCES;
175 const cl_event *event_list)
181 return func(num_events, event_list);
185 return CL_OUT_OF_RESOURCES;
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)
196 return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
200 return CL_OUT_OF_RESOURCES;
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)
211 return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
215 return CL_OUT_OF_RESOURCES;
219 void *
clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags,
size_t size, cl_uint alignment)
225 return func(context, flags, size, alignment);
239 func(context, svm_pointer);
244 cl_context_info param_name,
245 size_t param_value_size,
247 size_t *param_value_size_ret)
253 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
257 return CL_OUT_OF_RESOURCES;
263 cl_command_queue_properties properties,
270 return func(context, device, properties, errcode_ret);
279 const cl_context_properties *properties,
281 const cl_device_id *devices,
282 void (*pfn_notify)(
const char *,
const void *,
size_t,
void *),
290 return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
299 cl_device_type device_type,
300 void (*pfn_notify)(
const char *,
const void *,
size_t,
void *),
308 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
319 const cl_device_id *device_list,
321 void(CL_CALLBACK *pfn_notify)(cl_program program,
void *user_data),
328 return func(program, num_devices, device_list, options, pfn_notify, user_data);
332 return CL_OUT_OF_RESOURCES;
337 cl_command_queue command_queue,
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,
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);
355 return CL_OUT_OF_RESOURCES;
363 const void *arg_value)
369 return func(kernel, arg_index, arg_size, arg_value);
373 return CL_OUT_OF_RESOURCES;
387 return CL_OUT_OF_RESOURCES;
401 return CL_OUT_OF_RESOURCES;
406 cl_command_queue command_queue,
409 cl_uint num_events_in_wait_list,
410 const cl_event *event_wait_list,
417 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
421 return CL_OUT_OF_RESOURCES;
431 return func(command_queue);
435 return CL_OUT_OF_RESOURCES;
445 return func(context);
449 return CL_OUT_OF_RESOURCES;
462 return CL_OUT_OF_RESOURCES;
467 cl_command_queue command_queue,
469 cl_bool blocking_write,
473 cl_uint num_events_in_wait_list,
474 const cl_event *event_wait_list,
481 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
485 return CL_OUT_OF_RESOURCES;
490 cl_command_queue command_queue,
492 cl_bool blocking_read,
496 cl_uint num_events_in_wait_list,
497 const cl_event *event_wait_list,
504 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
508 return CL_OUT_OF_RESOURCES;
515 cl_program_build_info param_name,
516 size_t param_value_size,
518 size_t *param_value_size_ret)
524 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
528 return CL_OUT_OF_RESOURCES;
538 return func(program);
542 return CL_OUT_OF_RESOURCES;
547 cl_command_queue command_queue,
549 cl_bool blocking_map,
550 cl_map_flags map_flags,
553 cl_uint num_events_in_wait_list,
554 const cl_event *event_wait_list,
562 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
566 if(errcode_ret !=
nullptr)
568 *errcode_ret = CL_OUT_OF_RESOURCES;
580 return func(command_queue);
584 return CL_OUT_OF_RESOURCES;
591 const cl_device_id *device_list,
592 const size_t *lengths,
593 const unsigned char **binaries,
594 cl_int *binary_status,
601 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
605 if(errcode_ret !=
nullptr)
607 *errcode_ret = CL_OUT_OF_RESOURCES;
619 return func(context);
623 return CL_OUT_OF_RESOURCES;
633 return func(program);
637 return CL_OUT_OF_RESOURCES;
641 cl_int
clFlush(cl_command_queue command_queue)
647 return func(command_queue);
651 return CL_OUT_OF_RESOURCES;
661 return func(command_queue);
665 return CL_OUT_OF_RESOURCES;
671 cl_program_info param_name,
672 size_t param_value_size,
674 size_t *param_value_size_ret)
680 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
684 return CL_OUT_OF_RESOURCES;
697 return func(program, kernel_name, errcode_ret);
701 if(errcode_ret !=
nullptr)
703 *errcode_ret = CL_OUT_OF_RESOURCES;
719 return CL_OUT_OF_RESOURCES;
734 return func(context, flags, size, host_ptr, errcode_ret);
738 if(errcode_ret !=
nullptr)
740 *errcode_ret = CL_OUT_OF_RESOURCES;
749 const char **strings,
750 const size_t *lengths,
757 return func(context, count, strings, lengths, errcode_ret);
761 if(errcode_ret !=
nullptr)
763 *errcode_ret = CL_OUT_OF_RESOURCES;
779 return CL_OUT_OF_RESOURCES;
784 cl_device_type device_type,
786 cl_device_id *devices,
787 cl_uint *num_devices)
793 return func(platform, device_type, num_entries, devices, num_devices);
797 return CL_OUT_OF_RESOURCES;
802 cl_device_info param_name,
803 size_t param_value_size,
805 size_t *param_value_size_ret)
811 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
815 return CL_OUT_OF_RESOURCES;
820 cl_mem_info param_name,
821 size_t param_value_size,
823 size_t *param_value_size_ret)
829 return func(memobj, param_name, param_value_size, param_value, param_value_size_ret);
833 return CL_OUT_OF_RESOURCES;
847 return CL_OUT_OF_RESOURCES;
851 cl_int
clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
857 return func(num_entries, platforms, num_platforms);
861 return CL_OUT_OF_RESOURCES;
868 cl_kernel_work_group_info param_name,
869 size_t param_value_size,
871 size_t *param_value_size_ret)
877 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
881 return CL_OUT_OF_RESOURCES;
887 cl_command_queue_info param_name,
888 size_t param_value_size,
890 size_t *param_value_size_ret)
896 return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
900 return CL_OUT_OF_RESOURCES;
906 cl_kernel_info param_name,
907 size_t param_value_size,
909 size_t *param_value_size_ret)
915 return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
919 return CL_OUT_OF_RESOURCES;
925 cl_profiling_info param_name,
926 size_t param_value_size,
928 size_t *param_value_size_ret)
934 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
938 return CL_OUT_OF_RESOURCES;
945 const cl_image_format *image_format,
946 const cl_image_desc *image_desc,
954 return func(context, flags, image_format, image_desc, host_ptr, errcode_ret);
958 if(errcode_ret !=
nullptr)
960 *errcode_ret = CL_OUT_OF_RESOURCES;
967 cl_kernel_exec_info param_name,
968 size_t param_value_size,
969 const void *param_value)
975 return func(kernel, param_name, param_value_size, param_value);
979 return CL_OUT_OF_RESOURCES;
986 const cl_import_properties_arm *properties,
995 return func(context, flags, properties, memory, size, errcode_ret);
999 if(errcode_ret !=
nullptr)
1001 *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)
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)
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
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(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