blob: 2ebc3274aaf046f01cc12efcbba482cda9d0e843 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Anitha Raje8e016e2024-01-23 13:14:37 +00002 * Copyright (c) 2017-2024 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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
Michalis Spyrou6bff1952019-10-02 17:22:11 +010025#pragma GCC diagnostic push
26#pragma GCC diagnostic ignored "-Wunused-parameter"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/CL/OpenCL.h"
Michalis Spyrou6bff1952019-10-02 17:22:11 +010028#pragma GCC diagnostic pop
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029
Pablo Tellodb8485a2019-09-24 11:03:47 +010030#include "arm_compute/core/Error.h"
31
Ramy Elgammala7db3562023-04-19 18:49:44 +010032#include <algorithm>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033#include <dlfcn.h>
34#include <iostream>
Ramy Elgammala7db3562023-04-19 18:49:44 +010035#include <sstream>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036
Moritz Pflanzer725788e2017-07-07 15:35:56 +010037namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +010038{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010039CLSymbols::CLSymbols() noexcept(false) : _loaded({false, false})
Georgios Pinitas0b192e82020-02-20 17:09:28 +000040{
41}
42
Moritz Pflanzer725788e2017-07-07 15:35:56 +010043CLSymbols &CLSymbols::get()
44{
45 static CLSymbols symbols;
46 return symbols;
47}
48
49bool CLSymbols::load_default()
50{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010051 static const std::vector<std::string> libraries_filenames{"libOpenCL.so", "libGLES_mali.so", "libmali.so"};
Moritz Pflanzer725788e2017-07-07 15:35:56 +010052
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010053 if (_loaded.first)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010054 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010055 return _loaded.second;
56 }
57
58 // Indicate that default loading has been tried
59 _loaded.first = true;
60
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010061 if (load(libraries_filenames, /* use_loader */ false))
Moritz Pflanzer725788e2017-07-07 15:35:56 +010062 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010063 ARM_COMPUTE_ERROR_ON_MSG(this->clBuildProgram_ptr == nullptr,
64 "Failed to load OpenCL symbols from shared library");
Ramy Elgammala7db3562023-04-19 18:49:44 +010065 return true;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010066 }
67
ohadagoogle3efdfb32022-06-20 16:16:13 +000068#ifdef __ANDROID__
69 // When running in NDK environment, the above libraries are not accessible.
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010070 static const std::vector<std::string> android_libraries_filenames{"libOpenCL-pixel.so", "libOpenCL-car.so"};
ohadagoogle3efdfb32022-06-20 16:16:13 +000071
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010072 if (load(android_libraries_filenames, /* use_loader */ true))
ohadagoogle3efdfb32022-06-20 16:16:13 +000073 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010074 ARM_COMPUTE_ERROR_ON_MSG(this->clBuildProgram_ptr == nullptr,
75 "Failed to load OpenCL symbols from android shared library");
Ramy Elgammala7db3562023-04-19 18:49:44 +010076 return true;
ohadagoogle3efdfb32022-06-20 16:16:13 +000077 }
Ramy Elgammala7db3562023-04-19 18:49:44 +010078#endif // __ANDROID__
ohadagoogle3efdfb32022-06-20 16:16:13 +000079
Ramy Elgammala7db3562023-04-19 18:49:44 +010080 // If not returned till here then libraries not found
81 std::stringstream ss;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010082 std::for_each(libraries_filenames.begin(), libraries_filenames.end(),
83 [&ss](const std::string &s) { ss << s << " "; });
Ramy Elgammala7db3562023-04-19 18:49:44 +010084#ifdef __ANDROID__
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010085 std::for_each(android_libraries_filenames.begin(), android_libraries_filenames.end(),
86 [&ss](const std::string &s) { ss << s << " "; });
Ramy Elgammala7db3562023-04-19 18:49:44 +010087#endif // __ANDROID__
88 std::cerr << "Couldn't find any of the following OpenCL library: " << ss.str() << std::endl;
Moritz Pflanzer725788e2017-07-07 15:35:56 +010089 return false;
90}
91
Ramy Elgammala7db3562023-04-19 18:49:44 +010092bool CLSymbols::load(const std::vector<std::string> &libraries_filenames, bool use_loader)
Moritz Pflanzer725788e2017-07-07 15:35:56 +010093{
Ramy Elgammala7db3562023-04-19 18:49:44 +010094 void *handle = nullptr;
95 unsigned int index = 0;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010096 for (index = 0; index < libraries_filenames.size(); ++index)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010097 {
Ramy Elgammala7db3562023-04-19 18:49:44 +010098 handle = dlopen(libraries_filenames[index].c_str(), RTLD_LAZY | RTLD_LOCAL);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010099 if (handle != nullptr)
Ramy Elgammala7db3562023-04-19 18:49:44 +0100100 {
101 break;
102 }
103 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100104 if (index == libraries_filenames.size())
Ramy Elgammala7db3562023-04-19 18:49:44 +0100105 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100106 // Set status of loading to failed
107 _loaded.second = false;
108 return false;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100109 }
110
ohadagoogle3efdfb32022-06-20 16:16:13 +0000111#ifdef __ANDROID__
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100112 typedef void *(*loadOpenCLPointer_t)(const char *name);
ohadagoogle3efdfb32022-06-20 16:16:13 +0000113 loadOpenCLPointer_t loadOpenCLPointer;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100114 if (use_loader)
115 {
ohadagoogle3efdfb32022-06-20 16:16:13 +0000116 typedef void (*enableOpenCL_t)();
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100117 enableOpenCL_t enableOpenCL = reinterpret_cast<enableOpenCL_t>(dlsym(handle, "enableOpenCL"));
ohadagoogle3efdfb32022-06-20 16:16:13 +0000118 enableOpenCL();
119
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100120 loadOpenCLPointer = reinterpret_cast<loadOpenCLPointer_t>(dlsym(handle, "loadOpenCLPointer"));
121 }
122 else
123 {
ohadagoogle3efdfb32022-06-20 16:16:13 +0000124 loadOpenCLPointer = nullptr;
125 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100126#define LOAD_FUNCTION_PTR(func_name, _handle) \
127 func_name##_ptr = reinterpret_cast<decltype(func_name) *>(use_loader ? loadOpenCLPointer(#func_name) \
128 : dlsym(handle, #func_name));
ohadagoogle3efdfb32022-06-20 16:16:13 +0000129#else /* __ANDROID__ */
130 (void)use_loader; // Avoid unused warning
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000131#define LOAD_FUNCTION_PTR(func_name, handle) \
132 func_name##_ptr = reinterpret_cast<decltype(func_name) *>(dlsym(handle, #func_name));
ohadagoogle3efdfb32022-06-20 16:16:13 +0000133#endif /* __ANDROID__ */
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000134
Gunes Bayireb475ec2023-12-07 11:47:50 +0000135#define LOAD_EXTENSION_FUNCTION_PTR(func_name, platform_id) \
136 func_name##_ptr = \
137 reinterpret_cast<decltype(func_name) *>(clGetExtensionFunctionAddressForPlatform(platform_id, #func_name));
138
Georgios Pinitas42bd2652021-03-12 18:40:30 +0000139 LOAD_FUNCTION_PTR(clCreateContext, handle);
140 LOAD_FUNCTION_PTR(clCreateContextFromType, handle);
141 LOAD_FUNCTION_PTR(clCreateCommandQueue, handle);
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000142 LOAD_FUNCTION_PTR(clCreateCommandQueueWithProperties, handle);
Georgios Pinitas42bd2652021-03-12 18:40:30 +0000143 LOAD_FUNCTION_PTR(clGetContextInfo, handle);
144 LOAD_FUNCTION_PTR(clBuildProgram, handle);
145 LOAD_FUNCTION_PTR(clEnqueueNDRangeKernel, handle);
146 LOAD_FUNCTION_PTR(clSetKernelArg, handle);
147 LOAD_FUNCTION_PTR(clReleaseKernel, handle);
148 LOAD_FUNCTION_PTR(clCreateProgramWithSource, handle);
149 LOAD_FUNCTION_PTR(clCreateBuffer, handle);
150 LOAD_FUNCTION_PTR(clRetainKernel, handle);
151 LOAD_FUNCTION_PTR(clCreateKernel, handle);
152 LOAD_FUNCTION_PTR(clGetProgramInfo, handle);
153 LOAD_FUNCTION_PTR(clFlush, handle);
154 LOAD_FUNCTION_PTR(clFinish, handle);
155 LOAD_FUNCTION_PTR(clReleaseProgram, handle);
156 LOAD_FUNCTION_PTR(clRetainContext, handle);
157 LOAD_FUNCTION_PTR(clCreateProgramWithBinary, handle);
158 LOAD_FUNCTION_PTR(clReleaseCommandQueue, handle);
159 LOAD_FUNCTION_PTR(clEnqueueMapBuffer, handle);
160 LOAD_FUNCTION_PTR(clRetainProgram, handle);
161 LOAD_FUNCTION_PTR(clGetProgramBuildInfo, handle);
162 LOAD_FUNCTION_PTR(clEnqueueReadBuffer, handle);
163 LOAD_FUNCTION_PTR(clEnqueueWriteBuffer, handle);
164 LOAD_FUNCTION_PTR(clReleaseEvent, handle);
165 LOAD_FUNCTION_PTR(clReleaseContext, handle);
166 LOAD_FUNCTION_PTR(clRetainCommandQueue, handle);
167 LOAD_FUNCTION_PTR(clEnqueueUnmapMemObject, handle);
168 LOAD_FUNCTION_PTR(clRetainMemObject, handle);
169 LOAD_FUNCTION_PTR(clReleaseMemObject, handle);
170 LOAD_FUNCTION_PTR(clGetDeviceInfo, handle);
171 LOAD_FUNCTION_PTR(clGetDeviceIDs, handle);
172 LOAD_FUNCTION_PTR(clGetMemObjectInfo, handle);
173 LOAD_FUNCTION_PTR(clRetainEvent, handle);
Michalis Spyrou402740d2021-04-20 11:26:21 +0100174 LOAD_FUNCTION_PTR(clGetPlatformInfo, handle);
Georgios Pinitas42bd2652021-03-12 18:40:30 +0000175 LOAD_FUNCTION_PTR(clGetPlatformIDs, handle);
176 LOAD_FUNCTION_PTR(clGetKernelWorkGroupInfo, handle);
177 LOAD_FUNCTION_PTR(clGetCommandQueueInfo, handle);
178 LOAD_FUNCTION_PTR(clGetKernelInfo, handle);
179 LOAD_FUNCTION_PTR(clGetEventProfilingInfo, handle);
180 LOAD_FUNCTION_PTR(clSVMAlloc, handle);
181 LOAD_FUNCTION_PTR(clSVMFree, handle);
182 LOAD_FUNCTION_PTR(clEnqueueSVMMap, handle);
183 LOAD_FUNCTION_PTR(clEnqueueSVMUnmap, handle);
184 LOAD_FUNCTION_PTR(clEnqueueMarker, handle);
185 LOAD_FUNCTION_PTR(clWaitForEvents, handle);
186 LOAD_FUNCTION_PTR(clCreateImage, handle);
187 LOAD_FUNCTION_PTR(clSetKernelExecInfo, handle);
Gunes Bayireb475ec2023-12-07 11:47:50 +0000188 LOAD_FUNCTION_PTR(clGetExtensionFunctionAddressForPlatform, handle);
189
190 // Load Extensions
191
192 // Number of platforms is assumed to be 1. For this to be greater than 1,
193 // the system must have more than one OpenCL implementation provided by
194 // different vendors. This is not our use case. Besides, the library
195 // already assumes one implementation as it uses one handle to load core
196 // functions.
197 constexpr unsigned int num_platforms = 1U;
198 std::vector<cl_platform_id> platform_ids(num_platforms);
Anitha Raje8e016e2024-01-23 13:14:37 +0000199 cl_int err = clGetPlatformIDs(num_platforms, platform_ids.data(), nullptr);
200 if (err != CL_SUCCESS)
201 {
202 return false;
203 }
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000204
Viet-Hoa Do500e10b2023-09-12 17:49:38 +0100205 // Command buffer and mutable dispatch command buffer extensions
Gunes Bayireb475ec2023-12-07 11:47:50 +0000206 /// TODO: (COMPMID-6742) Load Command Buffer extensions in a Portable way
207 /// using clGetExtensionFunctionAddressForPlatform().
208 /// The details can be found here:
209 /// https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#getting-opencl-api-extension-function-pointers
210 ///
211 /// @note: There are some problems reported while loading these extensions in the recommended way.
212 /// For details, please see COMPUTE-16545
Viet-Hoa Do500e10b2023-09-12 17:49:38 +0100213 LOAD_FUNCTION_PTR(clCreateCommandBufferKHR, handle);
214 LOAD_FUNCTION_PTR(clRetainCommandBufferKHR, handle);
215 LOAD_FUNCTION_PTR(clReleaseCommandBufferKHR, handle);
216 LOAD_FUNCTION_PTR(clFinalizeCommandBufferKHR, handle);
217 LOAD_FUNCTION_PTR(clEnqueueCommandBufferKHR, handle);
218 LOAD_FUNCTION_PTR(clCommandNDRangeKernelKHR, handle);
219
220 LOAD_FUNCTION_PTR(clUpdateMutableCommandsKHR, handle);
221
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100222 // Third-party extensions
Gunes Bayireb475ec2023-12-07 11:47:50 +0000223 LOAD_EXTENSION_FUNCTION_PTR(clImportMemoryARM, platform_ids[0]);
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100224
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000225#undef LOAD_FUNCTION_PTR
Gunes Bayireb475ec2023-12-07 11:47:50 +0000226#undef LOAD_EXTENSION_FUNCTION_PTR
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100227
Georgios Pinitas42bd2652021-03-12 18:40:30 +0000228 //Don't call dlclose(handle) or all the symbols will be unloaded !
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100229
230 // Disable default loading and set status to successful
231 _loaded = std::make_pair(true, true);
232
233 return true;
234}
235
236bool opencl_is_available()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100237{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100238 CLSymbols::get().load_default();
Marco Antognini4a5f73d2021-03-23 16:59:08 +0000239
240 // Using static objects that rely on OpenCL in their constructor or
241 // destructor is implementation defined according to the OpenCL API
242 // Specification. These objects include CLScheduler.
243 //
244 // For compatibility with OpenCL runtimes that also use static objects to
245 // hold their state, we call a harmless OpenCL function (clGetPlatformIDs
246 // with invalid parameters must result in CL_INVALID_VALUE) to ensure the
247 // runtimes have a chance to initialize their static objects first. Thanks
ramelg01b2eba7f2021-12-23 08:32:08 +0000248 // to C++11 rules about normal program completion (cf [basic.start]), this
Marco Antognini4a5f73d2021-03-23 16:59:08 +0000249 // ensures their static objects are destroyed last, i.e. after the
250 // singleton CLScheduler is destroyed.
251 //
252 // When OpenCL is not available, this call results in CL_OUT_OF_RESOURCES,
253 // which is equally harmless.
254 (void)clGetPlatformIDs(0, nullptr, nullptr);
255
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000256 return CLSymbols::get().clBuildProgram_ptr != nullptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100257}
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100258} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100259
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100260cl_int clEnqueueMarker(cl_command_queue command_queue, cl_event *event)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100261{
262 arm_compute::CLSymbols::get().load_default();
263 auto func = arm_compute::CLSymbols::get().clEnqueueMarker_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100264 if (func != nullptr)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100265 {
266 return func(command_queue, event);
267 }
268 else
269 {
270 return CL_OUT_OF_RESOURCES;
271 }
272}
273
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100274cl_int clWaitForEvents(cl_uint num_events, const cl_event *event_list)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100275{
276 arm_compute::CLSymbols::get().load_default();
277 auto func = arm_compute::CLSymbols::get().clWaitForEvents_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100278 if (func != nullptr)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100279 {
280 return func(num_events, event_list);
281 }
282 else
283 {
284 return CL_OUT_OF_RESOURCES;
285 }
286}
287
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100288cl_int clEnqueueSVMMap(cl_command_queue command_queue,
289 cl_bool blocking_map,
290 cl_map_flags flags,
291 void *svm_ptr,
292 size_t size,
293 cl_uint num_events_in_wait_list,
294 const cl_event *event_wait_list,
295 cl_event *event)
Pablo Telloe86a09f2018-01-11 15:44:48 +0000296{
297 arm_compute::CLSymbols::get().load_default();
298 auto func = arm_compute::CLSymbols::get().clEnqueueSVMMap_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100299 if (func != nullptr)
Pablo Telloe86a09f2018-01-11 15:44:48 +0000300 {
301 return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
302 }
303 else
304 {
305 return CL_OUT_OF_RESOURCES;
306 }
307}
308
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100309cl_int clEnqueueSVMUnmap(cl_command_queue command_queue,
310 void *svm_ptr,
311 cl_uint num_events_in_wait_list,
312 const cl_event *event_wait_list,
313 cl_event *event)
Pablo Telloe86a09f2018-01-11 15:44:48 +0000314{
315 arm_compute::CLSymbols::get().load_default();
316 auto func = arm_compute::CLSymbols::get().clEnqueueSVMUnmap_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100317 if (func != nullptr)
Pablo Telloe86a09f2018-01-11 15:44:48 +0000318 {
319 return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
320 }
321 else
322 {
323 return CL_OUT_OF_RESOURCES;
324 }
325}
326
327void *clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
328{
329 arm_compute::CLSymbols::get().load_default();
330 auto func = arm_compute::CLSymbols::get().clSVMAlloc_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100331 if (func != nullptr)
Pablo Telloe86a09f2018-01-11 15:44:48 +0000332 {
333 return func(context, flags, size, alignment);
334 }
335 else
336 {
337 return nullptr;
338 }
339}
340
341void clSVMFree(cl_context context, void *svm_pointer)
342{
343 arm_compute::CLSymbols::get().load_default();
344 auto func = arm_compute::CLSymbols::get().clSVMFree_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100345 if (func != nullptr)
Pablo Telloe86a09f2018-01-11 15:44:48 +0000346 {
347 func(context, svm_pointer);
348 }
349}
350
Anthony Barbiera9e15332017-12-22 16:37:30 +0000351cl_int clGetContextInfo(cl_context context,
352 cl_context_info param_name,
353 size_t param_value_size,
354 void *param_value,
355 size_t *param_value_size_ret)
356{
357 arm_compute::CLSymbols::get().load_default();
358 auto func = arm_compute::CLSymbols::get().clGetContextInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100359 if (func != nullptr)
Anthony Barbiera9e15332017-12-22 16:37:30 +0000360 {
361 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
362 }
363 else
364 {
365 return CL_OUT_OF_RESOURCES;
366 }
367}
368
369cl_command_queue clCreateCommandQueue(cl_context context,
370 cl_device_id device,
371 cl_command_queue_properties properties,
372 cl_int *errcode_ret)
373{
374 arm_compute::CLSymbols::get().load_default();
375 auto func = arm_compute::CLSymbols::get().clCreateCommandQueue_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100376 if (func != nullptr)
Anthony Barbiera9e15332017-12-22 16:37:30 +0000377 {
378 return func(context, device, properties, errcode_ret);
379 }
380 else
381 {
382 return nullptr;
383 }
384}
385
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000386cl_command_queue clCreateCommandQueueWithProperties(cl_context context,
387 cl_device_id device,
388 const cl_queue_properties *properties,
389 cl_int *errcode_ret)
390{
391 arm_compute::CLSymbols::get().load_default();
392 auto func = arm_compute::CLSymbols::get().clCreateCommandQueueWithProperties_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100393 if (func != nullptr)
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000394 {
395 return func(context, device, properties, errcode_ret);
396 }
397 else
398 {
399 return nullptr;
400 }
401}
402
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100403cl_context clCreateContext(const cl_context_properties *properties,
404 cl_uint num_devices,
405 const cl_device_id *devices,
406 void (*pfn_notify)(const char *, const void *, size_t, void *),
407 void *user_data,
408 cl_int *errcode_ret)
Anthony Barbierb6eb3532018-08-08 13:20:04 +0100409{
410 arm_compute::CLSymbols::get().load_default();
411 auto func = arm_compute::CLSymbols::get().clCreateContext_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100412 if (func != nullptr)
Anthony Barbierb6eb3532018-08-08 13:20:04 +0100413 {
414 return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
415 }
416 else
417 {
418 return nullptr;
419 }
420}
421
Anthony Barbiera9e15332017-12-22 16:37:30 +0000422cl_context clCreateContextFromType(const cl_context_properties *properties,
423 cl_device_type device_type,
424 void (*pfn_notify)(const char *, const void *, size_t, void *),
425 void *user_data,
426 cl_int *errcode_ret)
427{
428 arm_compute::CLSymbols::get().load_default();
429 auto func = arm_compute::CLSymbols::get().clCreateContextFromType_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100430 if (func != nullptr)
Anthony Barbiera9e15332017-12-22 16:37:30 +0000431 {
432 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
433 }
434 else
435 {
436 return nullptr;
437 }
438}
439
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100440cl_int clBuildProgram(cl_program program,
441 cl_uint num_devices,
442 const cl_device_id *device_list,
443 const char *options,
444 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
445 void *user_data)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100446{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100447 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000448 auto func = arm_compute::CLSymbols::get().clBuildProgram_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100449 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100450 {
451 return func(program, num_devices, device_list, options, pfn_notify, user_data);
452 }
453 else
454 {
455 return CL_OUT_OF_RESOURCES;
456 }
457}
458
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100459cl_int clEnqueueNDRangeKernel(cl_command_queue command_queue,
460 cl_kernel kernel,
461 cl_uint work_dim,
462 const size_t *global_work_offset,
463 const size_t *global_work_size,
464 const size_t *local_work_size,
465 cl_uint num_events_in_wait_list,
466 const cl_event *event_wait_list,
467 cl_event *event)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100468{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100469 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000470 auto func = arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100471 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100472 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100473 return func(command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size,
474 num_events_in_wait_list, event_wait_list, event);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100475 }
476 else
477 {
478 return CL_OUT_OF_RESOURCES;
479 }
480}
481
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100482cl_int clSetKernelArg(cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100483{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100484 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000485 auto func = arm_compute::CLSymbols::get().clSetKernelArg_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100486 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100487 {
488 return func(kernel, arg_index, arg_size, arg_value);
489 }
490 else
491 {
492 return CL_OUT_OF_RESOURCES;
493 }
494}
495
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100496cl_int clRetainMemObject(cl_mem memobj)
497{
498 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000499 auto func = arm_compute::CLSymbols::get().clRetainMemObject_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100500 if (func != nullptr)
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100501 {
502 return func(memobj);
503 }
504 else
505 {
506 return CL_OUT_OF_RESOURCES;
507 }
508}
509
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100510cl_int clReleaseMemObject(cl_mem memobj)
511{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100512 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000513 auto func = arm_compute::CLSymbols::get().clReleaseMemObject_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100514 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100515 {
516 return func(memobj);
517 }
518 else
519 {
520 return CL_OUT_OF_RESOURCES;
521 }
522}
523
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100524cl_int clEnqueueUnmapMemObject(cl_command_queue command_queue,
525 cl_mem memobj,
526 void *mapped_ptr,
527 cl_uint num_events_in_wait_list,
528 const cl_event *event_wait_list,
529 cl_event *event)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100530{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100531 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000532 auto func = arm_compute::CLSymbols::get().clEnqueueUnmapMemObject_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100533 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100534 {
535 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
536 }
537 else
538 {
539 return CL_OUT_OF_RESOURCES;
540 }
541}
542
543cl_int clRetainCommandQueue(cl_command_queue command_queue)
544{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100545 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000546 auto func = arm_compute::CLSymbols::get().clRetainCommandQueue_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100547 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100548 {
549 return func(command_queue);
550 }
551 else
552 {
553 return CL_OUT_OF_RESOURCES;
554 }
555}
556
557cl_int clReleaseContext(cl_context context)
558{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100559 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000560 auto func = arm_compute::CLSymbols::get().clReleaseContext_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100561 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100562 {
563 return func(context);
564 }
565 else
566 {
567 return CL_OUT_OF_RESOURCES;
568 }
569}
570cl_int clReleaseEvent(cl_event event)
571{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100572 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000573 auto func = arm_compute::CLSymbols::get().clReleaseEvent_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100574 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100575 {
576 return func(event);
577 }
578 else
579 {
580 return CL_OUT_OF_RESOURCES;
581 }
582}
583
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100584cl_int clEnqueueWriteBuffer(cl_command_queue command_queue,
585 cl_mem buffer,
586 cl_bool blocking_write,
587 size_t offset,
588 size_t size,
589 const void *ptr,
590 cl_uint num_events_in_wait_list,
591 const cl_event *event_wait_list,
592 cl_event *event)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100593{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100594 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000595 auto func = arm_compute::CLSymbols::get().clEnqueueWriteBuffer_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100596 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100597 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100598 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list,
599 event);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100600 }
601 else
602 {
603 return CL_OUT_OF_RESOURCES;
604 }
605}
606
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100607cl_int clEnqueueReadBuffer(cl_command_queue command_queue,
608 cl_mem buffer,
609 cl_bool blocking_read,
610 size_t offset,
611 size_t size,
612 void *ptr,
613 cl_uint num_events_in_wait_list,
614 const cl_event *event_wait_list,
615 cl_event *event)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100616{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100617 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000618 auto func = arm_compute::CLSymbols::get().clEnqueueReadBuffer_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100619 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100620 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100621 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list,
622 event);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100623 }
624 else
625 {
626 return CL_OUT_OF_RESOURCES;
627 }
628}
629
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100630cl_int clGetProgramBuildInfo(cl_program program,
631 cl_device_id device,
632 cl_program_build_info param_name,
633 size_t param_value_size,
634 void *param_value,
635 size_t *param_value_size_ret)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100636{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100637 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000638 auto func = arm_compute::CLSymbols::get().clGetProgramBuildInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100639 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100640 {
641 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
642 }
643 else
644 {
645 return CL_OUT_OF_RESOURCES;
646 }
647}
648
649cl_int clRetainProgram(cl_program program)
650{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100651 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000652 auto func = arm_compute::CLSymbols::get().clRetainProgram_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100653 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100654 {
655 return func(program);
656 }
657 else
658 {
659 return CL_OUT_OF_RESOURCES;
660 }
661}
662
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100663void *clEnqueueMapBuffer(cl_command_queue command_queue,
664 cl_mem buffer,
665 cl_bool blocking_map,
666 cl_map_flags map_flags,
667 size_t offset,
668 size_t size,
669 cl_uint num_events_in_wait_list,
670 const cl_event *event_wait_list,
671 cl_event *event,
672 cl_int *errcode_ret)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100673{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100674 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000675 auto func = arm_compute::CLSymbols::get().clEnqueueMapBuffer_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100676 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100677 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100678 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list,
679 event_wait_list, event, errcode_ret);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100680 }
681 else
682 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100683 if (errcode_ret != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100684 {
685 *errcode_ret = CL_OUT_OF_RESOURCES;
686 }
687 return nullptr;
688 }
689}
690
691cl_int clReleaseCommandQueue(cl_command_queue command_queue)
692{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100693 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000694 auto func = arm_compute::CLSymbols::get().clReleaseCommandQueue_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100695 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100696 {
697 return func(command_queue);
698 }
699 else
700 {
701 return CL_OUT_OF_RESOURCES;
702 }
703}
704
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100705cl_program clCreateProgramWithBinary(cl_context context,
706 cl_uint num_devices,
707 const cl_device_id *device_list,
708 const size_t *lengths,
709 const unsigned char **binaries,
710 cl_int *binary_status,
711 cl_int *errcode_ret)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100712{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100713 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000714 auto func = arm_compute::CLSymbols::get().clCreateProgramWithBinary_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100715 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100716 {
717 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
718 }
719 else
720 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100721 if (errcode_ret != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100722 {
723 *errcode_ret = CL_OUT_OF_RESOURCES;
724 }
725 return nullptr;
726 }
727}
728
729cl_int clRetainContext(cl_context context)
730{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100731 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000732 auto func = arm_compute::CLSymbols::get().clRetainContext_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100733 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100734 {
735 return func(context);
736 }
737 else
738 {
739 return CL_OUT_OF_RESOURCES;
740 }
741}
742
743cl_int clReleaseProgram(cl_program program)
744{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100745 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000746 auto func = arm_compute::CLSymbols::get().clReleaseProgram_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100747 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100748 {
749 return func(program);
750 }
751 else
752 {
753 return CL_OUT_OF_RESOURCES;
754 }
755}
756
757cl_int clFlush(cl_command_queue command_queue)
758{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100759 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000760 auto func = arm_compute::CLSymbols::get().clFlush_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100761 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100762 {
763 return func(command_queue);
764 }
765 else
766 {
767 return CL_OUT_OF_RESOURCES;
768 }
769}
770
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100771cl_int clFinish(cl_command_queue command_queue)
772{
773 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000774 auto func = arm_compute::CLSymbols::get().clFinish_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100775 if (func != nullptr)
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100776 {
777 return func(command_queue);
778 }
779 else
780 {
781 return CL_OUT_OF_RESOURCES;
782 }
783}
784
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100785cl_int clGetProgramInfo(cl_program program,
786 cl_program_info param_name,
787 size_t param_value_size,
788 void *param_value,
789 size_t *param_value_size_ret)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100790{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100791 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000792 auto func = arm_compute::CLSymbols::get().clGetProgramInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100793 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100794 {
795 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
796 }
797 else
798 {
799 return CL_OUT_OF_RESOURCES;
800 }
801}
802
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100803cl_kernel clCreateKernel(cl_program program, const char *kernel_name, cl_int *errcode_ret)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100804{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100805 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000806 auto func = arm_compute::CLSymbols::get().clCreateKernel_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100807 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100808 {
809 return func(program, kernel_name, errcode_ret);
810 }
811 else
812 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100813 if (errcode_ret != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100814 {
815 *errcode_ret = CL_OUT_OF_RESOURCES;
816 }
817 return nullptr;
818 }
819}
820
821cl_int clRetainKernel(cl_kernel kernel)
822{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100823 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000824 auto func = arm_compute::CLSymbols::get().clRetainKernel_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100825 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100826 {
827 return func(kernel);
828 }
829 else
830 {
831 return CL_OUT_OF_RESOURCES;
832 }
833}
834
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100835cl_mem clCreateBuffer(cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100836{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100837 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000838 auto func = arm_compute::CLSymbols::get().clCreateBuffer_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100839 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100840 {
841 return func(context, flags, size, host_ptr, errcode_ret);
842 }
843 else
844 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100845 if (errcode_ret != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100846 {
847 *errcode_ret = CL_OUT_OF_RESOURCES;
848 }
849 return nullptr;
850 }
851}
852
853cl_program clCreateProgramWithSource(
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100854 cl_context context, cl_uint count, const char **strings, const size_t *lengths, cl_int *errcode_ret)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100855{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100856 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000857 auto func = arm_compute::CLSymbols::get().clCreateProgramWithSource_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100858 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100859 {
860 return func(context, count, strings, lengths, errcode_ret);
861 }
862 else
863 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100864 if (errcode_ret != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100865 {
866 *errcode_ret = CL_OUT_OF_RESOURCES;
867 }
868 return nullptr;
869 }
870}
871
872cl_int clReleaseKernel(cl_kernel kernel)
873{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100874 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000875 auto func = arm_compute::CLSymbols::get().clReleaseKernel_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100876 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100877 {
878 return func(kernel);
879 }
880 else
881 {
882 return CL_OUT_OF_RESOURCES;
883 }
884}
885
886cl_int clGetDeviceIDs(cl_platform_id platform,
887 cl_device_type device_type,
888 cl_uint num_entries,
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100889 cl_device_id *devices,
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100890 cl_uint *num_devices)
891{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100892 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000893 auto func = arm_compute::CLSymbols::get().clGetDeviceIDs_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100894 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100895 {
896 return func(platform, device_type, num_entries, devices, num_devices);
897 }
898 else
899 {
900 return CL_OUT_OF_RESOURCES;
901 }
902}
903
904cl_int clGetDeviceInfo(cl_device_id device,
905 cl_device_info param_name,
906 size_t param_value_size,
907 void *param_value,
908 size_t *param_value_size_ret)
909{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100910 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000911 auto func = arm_compute::CLSymbols::get().clGetDeviceInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100912 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100913 {
914 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
915 }
916 else
917 {
918 return CL_OUT_OF_RESOURCES;
919 }
920}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100921
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100922cl_int clGetMemObjectInfo(
923 cl_mem memobj, cl_mem_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
Georgios Pinitasdf310362018-11-14 13:16:56 +0000924{
925 arm_compute::CLSymbols::get().load_default();
926 auto func = arm_compute::CLSymbols::get().clGetMemObjectInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100927 if (func != nullptr)
Georgios Pinitasdf310362018-11-14 13:16:56 +0000928 {
929 return func(memobj, param_name, param_value_size, param_value, param_value_size_ret);
930 }
931 else
932 {
933 return CL_OUT_OF_RESOURCES;
934 }
935}
936
Giorgio Arena9fe41442017-08-23 16:36:24 +0100937cl_int clRetainEvent(cl_event event)
938{
Moritz Pflanzer159b6da2017-09-20 16:03:35 +0100939 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000940 auto func = arm_compute::CLSymbols::get().clRetainEvent_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100941 if (func != nullptr)
Giorgio Arena9fe41442017-08-23 16:36:24 +0100942 {
943 return func(event);
944 }
945 else
946 {
947 return CL_OUT_OF_RESOURCES;
948 }
949}
steniu01f01f9de2017-09-27 17:00:11 +0100950
Michalis Spyrou402740d2021-04-20 11:26:21 +0100951cl_int clGetPlatformInfo(cl_platform_id platform,
952 cl_platform_info param_name,
953 size_t param_value_size,
954 void *param_value,
955 size_t *param_value_size_ret)
956{
957 arm_compute::CLSymbols::get().load_default();
958 auto func = arm_compute::CLSymbols::get().clGetPlatformInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100959 if (func != nullptr)
Michalis Spyrou402740d2021-04-20 11:26:21 +0100960 {
961 return func(platform, param_name, param_value_size, param_value, param_value_size_ret);
962 }
963 else
964 {
965 return CL_OUT_OF_RESOURCES;
966 }
967}
968
steniu01f01f9de2017-09-27 17:00:11 +0100969cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
970{
971 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000972 auto func = arm_compute::CLSymbols::get().clGetPlatformIDs_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100973 if (func != nullptr)
steniu01f01f9de2017-09-27 17:00:11 +0100974 {
975 return func(num_entries, platforms, num_platforms);
976 }
977 else
978 {
979 return CL_OUT_OF_RESOURCES;
980 }
981}
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100982
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100983cl_int clGetKernelWorkGroupInfo(cl_kernel kernel,
984 cl_device_id device,
985 cl_kernel_work_group_info param_name,
986 size_t param_value_size,
987 void *param_value,
988 size_t *param_value_size_ret)
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100989{
990 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000991 auto func = arm_compute::CLSymbols::get().clGetKernelWorkGroupInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100992 if (func != nullptr)
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100993 {
994 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
995 }
996 else
997 {
998 return CL_OUT_OF_RESOURCES;
999 }
1000}
Gian Marco85e6f512018-02-01 16:57:48 +00001001
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001002cl_int clGetCommandQueueInfo(cl_command_queue command_queue,
1003 cl_command_queue_info param_name,
1004 size_t param_value_size,
1005 void *param_value,
1006 size_t *param_value_size_ret)
Gian Marco85e6f512018-02-01 16:57:48 +00001007{
1008 arm_compute::CLSymbols::get().load_default();
1009 auto func = arm_compute::CLSymbols::get().clGetCommandQueueInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001010 if (func != nullptr)
Gian Marco85e6f512018-02-01 16:57:48 +00001011 {
1012 return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
1013 }
1014 else
1015 {
1016 return CL_OUT_OF_RESOURCES;
1017 }
1018}
1019
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001020cl_int clGetKernelInfo(cl_kernel kernel,
1021 cl_kernel_info param_name,
1022 size_t param_value_size,
1023 void *param_value,
1024 size_t *param_value_size_ret)
Gian Marco85e6f512018-02-01 16:57:48 +00001025{
1026 arm_compute::CLSymbols::get().load_default();
1027 auto func = arm_compute::CLSymbols::get().clGetKernelInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001028 if (func != nullptr)
Gian Marco85e6f512018-02-01 16:57:48 +00001029 {
1030 return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
1031 }
1032 else
1033 {
1034 return CL_OUT_OF_RESOURCES;
1035 }
1036}
1037
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001038cl_int clGetEventProfilingInfo(cl_event event,
1039 cl_profiling_info param_name,
1040 size_t param_value_size,
1041 void *param_value,
1042 size_t *param_value_size_ret)
Gian Marco85e6f512018-02-01 16:57:48 +00001043{
1044 arm_compute::CLSymbols::get().load_default();
1045 auto func = arm_compute::CLSymbols::get().clGetEventProfilingInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001046 if (func != nullptr)
Gian Marco85e6f512018-02-01 16:57:48 +00001047 {
1048 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
1049 }
1050 else
1051 {
1052 return CL_OUT_OF_RESOURCES;
1053 }
Anthony Barbierf5dcf792018-02-28 18:04:45 +00001054}
Georgios Pinitas4d0351c2019-04-03 15:11:16 +01001055
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001056cl_mem clCreateImage(cl_context context,
1057 cl_mem_flags flags,
1058 const cl_image_format *image_format,
1059 const cl_image_desc *image_desc,
1060 void *host_ptr,
1061 cl_int *errcode_ret)
Gian Marco Iodicea98dee22020-06-02 12:12:35 +01001062{
1063 arm_compute::CLSymbols::get().load_default();
1064 auto func = arm_compute::CLSymbols::get().clCreateImage_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001065 if (func != nullptr)
Gian Marco Iodicea98dee22020-06-02 12:12:35 +01001066 {
1067 return func(context, flags, image_format, image_desc, host_ptr, errcode_ret);
1068 }
1069 else
1070 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001071 if (errcode_ret != nullptr)
Gian Marco Iodicea98dee22020-06-02 12:12:35 +01001072 {
1073 *errcode_ret = CL_OUT_OF_RESOURCES;
1074 }
1075 return nullptr;
1076 }
1077}
1078
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001079cl_int
1080clSetKernelExecInfo(cl_kernel kernel, cl_kernel_exec_info param_name, size_t param_value_size, const void *param_value)
Manuel Bottinibe9f9f92021-01-25 15:07:17 +00001081{
1082 arm_compute::CLSymbols::get().load_default();
1083 auto func = arm_compute::CLSymbols::get().clSetKernelExecInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001084 if (func != nullptr)
Manuel Bottinibe9f9f92021-01-25 15:07:17 +00001085 {
1086 return func(kernel, param_name, param_value_size, param_value);
1087 }
1088 else
1089 {
1090 return CL_OUT_OF_RESOURCES;
1091 }
1092}
1093
Gunes Bayireb475ec2023-12-07 11:47:50 +00001094void *clGetExtensionFunctionAddressForPlatform(cl_platform_id platform, const char *funcname)
1095{
1096 arm_compute::CLSymbols::get().load_default();
1097 const auto func = arm_compute::CLSymbols::get().clGetExtensionFunctionAddressForPlatform_ptr;
1098
1099 if (func != nullptr)
1100 {
1101 return func(platform, funcname);
1102 }
1103
1104 return nullptr;
1105}
1106
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001107cl_command_buffer_khr clCreateCommandBufferKHR(cl_uint num_queues,
1108 const cl_command_queue *queues,
1109 const cl_command_buffer_properties_khr *properties,
1110 cl_int *errcode_ret)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001111{
1112 arm_compute::CLSymbols::get().load_default();
1113 const auto func = arm_compute::CLSymbols::get().clCreateCommandBufferKHR_ptr;
1114
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001115 if (func != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001116 {
1117 return func(num_queues, queues, properties, errcode_ret);
1118 }
1119 else
1120 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001121 if (errcode_ret != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001122 {
1123 *errcode_ret = CL_INVALID_OPERATION;
1124 }
1125
1126 return {};
1127 }
1128}
1129
1130cl_int clFinalizeCommandBufferKHR(cl_command_buffer_khr command_buffer)
1131{
1132 arm_compute::CLSymbols::get().load_default();
1133 const auto func = arm_compute::CLSymbols::get().clFinalizeCommandBufferKHR_ptr;
1134
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001135 if (func != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001136 {
1137 return func(command_buffer);
1138 }
1139 else
1140 {
1141 return CL_INVALID_OPERATION;
1142 }
1143}
1144
1145cl_int clRetainCommandBufferKHR(cl_command_buffer_khr command_buffer)
1146{
1147 arm_compute::CLSymbols::get().load_default();
1148 const auto func = arm_compute::CLSymbols::get().clRetainCommandBufferKHR_ptr;
1149
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001150 if (func != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001151 {
1152 return func(command_buffer);
1153 }
1154 else
1155 {
1156 return CL_INVALID_OPERATION;
1157 }
1158}
1159
1160cl_int clReleaseCommandBufferKHR(cl_command_buffer_khr command_buffer)
1161{
1162 arm_compute::CLSymbols::get().load_default();
1163 const auto func = arm_compute::CLSymbols::get().clReleaseCommandBufferKHR_ptr;
1164
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001165 if (func != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001166 {
1167 return func(command_buffer);
1168 }
1169 else
1170 {
1171 return CL_INVALID_OPERATION;
1172 }
1173}
1174
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001175cl_int clEnqueueCommandBufferKHR(cl_uint num_queues,
1176 cl_command_queue *queues,
1177 cl_command_buffer_khr command_buffer,
1178 cl_uint num_events_in_wait_list,
1179 const cl_event *event_wait_list,
1180 cl_event *event)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001181{
1182 arm_compute::CLSymbols::get().load_default();
1183 const auto func = arm_compute::CLSymbols::get().clEnqueueCommandBufferKHR_ptr;
1184
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001185 if (func != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001186 {
1187 return func(num_queues, queues, command_buffer, num_events_in_wait_list, event_wait_list, event);
1188 }
1189 else
1190 {
1191 return CL_INVALID_OPERATION;
1192 }
1193}
1194
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001195cl_int clCommandNDRangeKernelKHR(cl_command_buffer_khr command_buffer,
1196 cl_command_queue command_queue,
1197 const cl_ndrange_kernel_command_properties_khr *properties,
1198 cl_kernel kernel,
1199 cl_uint work_dim,
1200 const size_t *global_work_offset,
1201 const size_t *global_work_size,
1202 const size_t *local_work_size,
1203 cl_uint num_sync_points_in_wait_list,
1204 const cl_sync_point_khr *sync_point_wait_list,
1205 cl_sync_point_khr *sync_point,
1206 cl_mutable_command_khr *mutable_handle)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001207{
1208 arm_compute::CLSymbols::get().load_default();
1209 const auto func = arm_compute::CLSymbols::get().clCommandNDRangeKernelKHR_ptr;
1210
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001211 if (func != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001212 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001213 return func(command_buffer, command_queue, properties, kernel, work_dim, global_work_offset, global_work_size,
1214 local_work_size, num_sync_points_in_wait_list, sync_point_wait_list, sync_point, mutable_handle);
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001215 }
1216 else
1217 {
1218 return CL_INVALID_OPERATION;
1219 }
1220}
1221
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001222cl_int clUpdateMutableCommandsKHR(cl_command_buffer_khr command_buffer,
1223 const cl_mutable_base_config_khr *mutable_config)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001224{
1225 arm_compute::CLSymbols::get().load_default();
1226 const auto func = arm_compute::CLSymbols::get().clUpdateMutableCommandsKHR_ptr;
1227
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001228 if (func != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001229 {
1230 return func(command_buffer, mutable_config);
1231 }
1232 else
1233 {
1234 return CL_INVALID_OPERATION;
1235 }
1236}
1237
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001238cl_mem clImportMemoryARM(cl_context context,
1239 cl_mem_flags flags,
1240 const cl_import_properties_arm *properties,
1241 void *memory,
1242 size_t size,
1243 cl_int *errcode_ret)
Georgios Pinitas4d0351c2019-04-03 15:11:16 +01001244{
1245 arm_compute::CLSymbols::get().load_default();
1246 auto func = arm_compute::CLSymbols::get().clImportMemoryARM_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001247 if (func != nullptr)
Georgios Pinitas4d0351c2019-04-03 15:11:16 +01001248 {
1249 return func(context, flags, properties, memory, size, errcode_ret);
1250 }
1251 else
1252 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001253 if (errcode_ret != nullptr)
Georgios Pinitas4d0351c2019-04-03 15:11:16 +01001254 {
1255 *errcode_ret = CL_OUT_OF_RESOURCES;
1256 }
1257 return nullptr;
1258 }
Pablo Tellodb8485a2019-09-24 11:03:47 +01001259}