blob: 07baa5e7fb13b3ad850ae26d07c64cf32ffa4330 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Ramy Elgammala7db3562023-04-19 18:49:44 +01002 * Copyright (c) 2017-2023 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);
199 clGetPlatformIDs(num_platforms, platform_ids.data(), nullptr);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000200
Viet-Hoa Do500e10b2023-09-12 17:49:38 +0100201 // Command buffer and mutable dispatch command buffer extensions
Gunes Bayireb475ec2023-12-07 11:47:50 +0000202 /// TODO: (COMPMID-6742) Load Command Buffer extensions in a Portable way
203 /// using clGetExtensionFunctionAddressForPlatform().
204 /// The details can be found here:
205 /// https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#getting-opencl-api-extension-function-pointers
206 ///
207 /// @note: There are some problems reported while loading these extensions in the recommended way.
208 /// For details, please see COMPUTE-16545
Viet-Hoa Do500e10b2023-09-12 17:49:38 +0100209 LOAD_FUNCTION_PTR(clCreateCommandBufferKHR, handle);
210 LOAD_FUNCTION_PTR(clRetainCommandBufferKHR, handle);
211 LOAD_FUNCTION_PTR(clReleaseCommandBufferKHR, handle);
212 LOAD_FUNCTION_PTR(clFinalizeCommandBufferKHR, handle);
213 LOAD_FUNCTION_PTR(clEnqueueCommandBufferKHR, handle);
214 LOAD_FUNCTION_PTR(clCommandNDRangeKernelKHR, handle);
215
216 LOAD_FUNCTION_PTR(clUpdateMutableCommandsKHR, handle);
217
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100218 // Third-party extensions
Gunes Bayireb475ec2023-12-07 11:47:50 +0000219 LOAD_EXTENSION_FUNCTION_PTR(clImportMemoryARM, platform_ids[0]);
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100220
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000221#undef LOAD_FUNCTION_PTR
Gunes Bayireb475ec2023-12-07 11:47:50 +0000222#undef LOAD_EXTENSION_FUNCTION_PTR
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100223
Georgios Pinitas42bd2652021-03-12 18:40:30 +0000224 //Don't call dlclose(handle) or all the symbols will be unloaded !
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100225
226 // Disable default loading and set status to successful
227 _loaded = std::make_pair(true, true);
228
229 return true;
230}
231
232bool opencl_is_available()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100233{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100234 CLSymbols::get().load_default();
Marco Antognini4a5f73d2021-03-23 16:59:08 +0000235
236 // Using static objects that rely on OpenCL in their constructor or
237 // destructor is implementation defined according to the OpenCL API
238 // Specification. These objects include CLScheduler.
239 //
240 // For compatibility with OpenCL runtimes that also use static objects to
241 // hold their state, we call a harmless OpenCL function (clGetPlatformIDs
242 // with invalid parameters must result in CL_INVALID_VALUE) to ensure the
243 // runtimes have a chance to initialize their static objects first. Thanks
ramelg01b2eba7f2021-12-23 08:32:08 +0000244 // to C++11 rules about normal program completion (cf [basic.start]), this
Marco Antognini4a5f73d2021-03-23 16:59:08 +0000245 // ensures their static objects are destroyed last, i.e. after the
246 // singleton CLScheduler is destroyed.
247 //
248 // When OpenCL is not available, this call results in CL_OUT_OF_RESOURCES,
249 // which is equally harmless.
250 (void)clGetPlatformIDs(0, nullptr, nullptr);
251
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000252 return CLSymbols::get().clBuildProgram_ptr != nullptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100253}
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100254} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100255
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100256cl_int clEnqueueMarker(cl_command_queue command_queue, cl_event *event)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100257{
258 arm_compute::CLSymbols::get().load_default();
259 auto func = arm_compute::CLSymbols::get().clEnqueueMarker_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100260 if (func != nullptr)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100261 {
262 return func(command_queue, event);
263 }
264 else
265 {
266 return CL_OUT_OF_RESOURCES;
267 }
268}
269
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100270cl_int clWaitForEvents(cl_uint num_events, const cl_event *event_list)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100271{
272 arm_compute::CLSymbols::get().load_default();
273 auto func = arm_compute::CLSymbols::get().clWaitForEvents_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100274 if (func != nullptr)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100275 {
276 return func(num_events, event_list);
277 }
278 else
279 {
280 return CL_OUT_OF_RESOURCES;
281 }
282}
283
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100284cl_int clEnqueueSVMMap(cl_command_queue command_queue,
285 cl_bool blocking_map,
286 cl_map_flags flags,
287 void *svm_ptr,
288 size_t size,
289 cl_uint num_events_in_wait_list,
290 const cl_event *event_wait_list,
291 cl_event *event)
Pablo Telloe86a09f2018-01-11 15:44:48 +0000292{
293 arm_compute::CLSymbols::get().load_default();
294 auto func = arm_compute::CLSymbols::get().clEnqueueSVMMap_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100295 if (func != nullptr)
Pablo Telloe86a09f2018-01-11 15:44:48 +0000296 {
297 return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
298 }
299 else
300 {
301 return CL_OUT_OF_RESOURCES;
302 }
303}
304
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100305cl_int clEnqueueSVMUnmap(cl_command_queue command_queue,
306 void *svm_ptr,
307 cl_uint num_events_in_wait_list,
308 const cl_event *event_wait_list,
309 cl_event *event)
Pablo Telloe86a09f2018-01-11 15:44:48 +0000310{
311 arm_compute::CLSymbols::get().load_default();
312 auto func = arm_compute::CLSymbols::get().clEnqueueSVMUnmap_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100313 if (func != nullptr)
Pablo Telloe86a09f2018-01-11 15:44:48 +0000314 {
315 return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
316 }
317 else
318 {
319 return CL_OUT_OF_RESOURCES;
320 }
321}
322
323void *clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
324{
325 arm_compute::CLSymbols::get().load_default();
326 auto func = arm_compute::CLSymbols::get().clSVMAlloc_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100327 if (func != nullptr)
Pablo Telloe86a09f2018-01-11 15:44:48 +0000328 {
329 return func(context, flags, size, alignment);
330 }
331 else
332 {
333 return nullptr;
334 }
335}
336
337void clSVMFree(cl_context context, void *svm_pointer)
338{
339 arm_compute::CLSymbols::get().load_default();
340 auto func = arm_compute::CLSymbols::get().clSVMFree_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100341 if (func != nullptr)
Pablo Telloe86a09f2018-01-11 15:44:48 +0000342 {
343 func(context, svm_pointer);
344 }
345}
346
Anthony Barbiera9e15332017-12-22 16:37:30 +0000347cl_int clGetContextInfo(cl_context context,
348 cl_context_info param_name,
349 size_t param_value_size,
350 void *param_value,
351 size_t *param_value_size_ret)
352{
353 arm_compute::CLSymbols::get().load_default();
354 auto func = arm_compute::CLSymbols::get().clGetContextInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100355 if (func != nullptr)
Anthony Barbiera9e15332017-12-22 16:37:30 +0000356 {
357 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
358 }
359 else
360 {
361 return CL_OUT_OF_RESOURCES;
362 }
363}
364
365cl_command_queue clCreateCommandQueue(cl_context context,
366 cl_device_id device,
367 cl_command_queue_properties properties,
368 cl_int *errcode_ret)
369{
370 arm_compute::CLSymbols::get().load_default();
371 auto func = arm_compute::CLSymbols::get().clCreateCommandQueue_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100372 if (func != nullptr)
Anthony Barbiera9e15332017-12-22 16:37:30 +0000373 {
374 return func(context, device, properties, errcode_ret);
375 }
376 else
377 {
378 return nullptr;
379 }
380}
381
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000382cl_command_queue clCreateCommandQueueWithProperties(cl_context context,
383 cl_device_id device,
384 const cl_queue_properties *properties,
385 cl_int *errcode_ret)
386{
387 arm_compute::CLSymbols::get().load_default();
388 auto func = arm_compute::CLSymbols::get().clCreateCommandQueueWithProperties_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100389 if (func != nullptr)
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000390 {
391 return func(context, device, properties, errcode_ret);
392 }
393 else
394 {
395 return nullptr;
396 }
397}
398
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100399cl_context clCreateContext(const cl_context_properties *properties,
400 cl_uint num_devices,
401 const cl_device_id *devices,
402 void (*pfn_notify)(const char *, const void *, size_t, void *),
403 void *user_data,
404 cl_int *errcode_ret)
Anthony Barbierb6eb3532018-08-08 13:20:04 +0100405{
406 arm_compute::CLSymbols::get().load_default();
407 auto func = arm_compute::CLSymbols::get().clCreateContext_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100408 if (func != nullptr)
Anthony Barbierb6eb3532018-08-08 13:20:04 +0100409 {
410 return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
411 }
412 else
413 {
414 return nullptr;
415 }
416}
417
Anthony Barbiera9e15332017-12-22 16:37:30 +0000418cl_context clCreateContextFromType(const cl_context_properties *properties,
419 cl_device_type device_type,
420 void (*pfn_notify)(const char *, const void *, size_t, void *),
421 void *user_data,
422 cl_int *errcode_ret)
423{
424 arm_compute::CLSymbols::get().load_default();
425 auto func = arm_compute::CLSymbols::get().clCreateContextFromType_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100426 if (func != nullptr)
Anthony Barbiera9e15332017-12-22 16:37:30 +0000427 {
428 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
429 }
430 else
431 {
432 return nullptr;
433 }
434}
435
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100436cl_int clBuildProgram(cl_program program,
437 cl_uint num_devices,
438 const cl_device_id *device_list,
439 const char *options,
440 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
441 void *user_data)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100442{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100443 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000444 auto func = arm_compute::CLSymbols::get().clBuildProgram_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100445 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100446 {
447 return func(program, num_devices, device_list, options, pfn_notify, user_data);
448 }
449 else
450 {
451 return CL_OUT_OF_RESOURCES;
452 }
453}
454
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100455cl_int clEnqueueNDRangeKernel(cl_command_queue command_queue,
456 cl_kernel kernel,
457 cl_uint work_dim,
458 const size_t *global_work_offset,
459 const size_t *global_work_size,
460 const size_t *local_work_size,
461 cl_uint num_events_in_wait_list,
462 const cl_event *event_wait_list,
463 cl_event *event)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100464{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100465 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000466 auto func = arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100467 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100468 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100469 return func(command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size,
470 num_events_in_wait_list, event_wait_list, event);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100471 }
472 else
473 {
474 return CL_OUT_OF_RESOURCES;
475 }
476}
477
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100478cl_int clSetKernelArg(cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100479{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100480 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000481 auto func = arm_compute::CLSymbols::get().clSetKernelArg_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100482 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100483 {
484 return func(kernel, arg_index, arg_size, arg_value);
485 }
486 else
487 {
488 return CL_OUT_OF_RESOURCES;
489 }
490}
491
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100492cl_int clRetainMemObject(cl_mem memobj)
493{
494 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000495 auto func = arm_compute::CLSymbols::get().clRetainMemObject_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100496 if (func != nullptr)
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100497 {
498 return func(memobj);
499 }
500 else
501 {
502 return CL_OUT_OF_RESOURCES;
503 }
504}
505
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100506cl_int clReleaseMemObject(cl_mem memobj)
507{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100508 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000509 auto func = arm_compute::CLSymbols::get().clReleaseMemObject_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100510 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100511 {
512 return func(memobj);
513 }
514 else
515 {
516 return CL_OUT_OF_RESOURCES;
517 }
518}
519
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100520cl_int clEnqueueUnmapMemObject(cl_command_queue command_queue,
521 cl_mem memobj,
522 void *mapped_ptr,
523 cl_uint num_events_in_wait_list,
524 const cl_event *event_wait_list,
525 cl_event *event)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100526{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100527 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000528 auto func = arm_compute::CLSymbols::get().clEnqueueUnmapMemObject_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100529 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100530 {
531 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
532 }
533 else
534 {
535 return CL_OUT_OF_RESOURCES;
536 }
537}
538
539cl_int clRetainCommandQueue(cl_command_queue command_queue)
540{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100541 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000542 auto func = arm_compute::CLSymbols::get().clRetainCommandQueue_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100543 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100544 {
545 return func(command_queue);
546 }
547 else
548 {
549 return CL_OUT_OF_RESOURCES;
550 }
551}
552
553cl_int clReleaseContext(cl_context context)
554{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100555 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000556 auto func = arm_compute::CLSymbols::get().clReleaseContext_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100557 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100558 {
559 return func(context);
560 }
561 else
562 {
563 return CL_OUT_OF_RESOURCES;
564 }
565}
566cl_int clReleaseEvent(cl_event event)
567{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100568 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000569 auto func = arm_compute::CLSymbols::get().clReleaseEvent_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100570 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100571 {
572 return func(event);
573 }
574 else
575 {
576 return CL_OUT_OF_RESOURCES;
577 }
578}
579
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100580cl_int clEnqueueWriteBuffer(cl_command_queue command_queue,
581 cl_mem buffer,
582 cl_bool blocking_write,
583 size_t offset,
584 size_t size,
585 const void *ptr,
586 cl_uint num_events_in_wait_list,
587 const cl_event *event_wait_list,
588 cl_event *event)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100589{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100590 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000591 auto func = arm_compute::CLSymbols::get().clEnqueueWriteBuffer_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100592 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100593 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100594 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list,
595 event);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100596 }
597 else
598 {
599 return CL_OUT_OF_RESOURCES;
600 }
601}
602
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100603cl_int clEnqueueReadBuffer(cl_command_queue command_queue,
604 cl_mem buffer,
605 cl_bool blocking_read,
606 size_t offset,
607 size_t size,
608 void *ptr,
609 cl_uint num_events_in_wait_list,
610 const cl_event *event_wait_list,
611 cl_event *event)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100612{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100613 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000614 auto func = arm_compute::CLSymbols::get().clEnqueueReadBuffer_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100615 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100616 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100617 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list,
618 event);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100619 }
620 else
621 {
622 return CL_OUT_OF_RESOURCES;
623 }
624}
625
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100626cl_int clGetProgramBuildInfo(cl_program program,
627 cl_device_id device,
628 cl_program_build_info param_name,
629 size_t param_value_size,
630 void *param_value,
631 size_t *param_value_size_ret)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100632{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100633 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000634 auto func = arm_compute::CLSymbols::get().clGetProgramBuildInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100635 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100636 {
637 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
638 }
639 else
640 {
641 return CL_OUT_OF_RESOURCES;
642 }
643}
644
645cl_int clRetainProgram(cl_program program)
646{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100647 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000648 auto func = arm_compute::CLSymbols::get().clRetainProgram_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100649 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100650 {
651 return func(program);
652 }
653 else
654 {
655 return CL_OUT_OF_RESOURCES;
656 }
657}
658
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100659void *clEnqueueMapBuffer(cl_command_queue command_queue,
660 cl_mem buffer,
661 cl_bool blocking_map,
662 cl_map_flags map_flags,
663 size_t offset,
664 size_t size,
665 cl_uint num_events_in_wait_list,
666 const cl_event *event_wait_list,
667 cl_event *event,
668 cl_int *errcode_ret)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100669{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100670 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000671 auto func = arm_compute::CLSymbols::get().clEnqueueMapBuffer_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100672 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100673 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100674 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list,
675 event_wait_list, event, errcode_ret);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100676 }
677 else
678 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100679 if (errcode_ret != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100680 {
681 *errcode_ret = CL_OUT_OF_RESOURCES;
682 }
683 return nullptr;
684 }
685}
686
687cl_int clReleaseCommandQueue(cl_command_queue command_queue)
688{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100689 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000690 auto func = arm_compute::CLSymbols::get().clReleaseCommandQueue_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100691 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100692 {
693 return func(command_queue);
694 }
695 else
696 {
697 return CL_OUT_OF_RESOURCES;
698 }
699}
700
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100701cl_program clCreateProgramWithBinary(cl_context context,
702 cl_uint num_devices,
703 const cl_device_id *device_list,
704 const size_t *lengths,
705 const unsigned char **binaries,
706 cl_int *binary_status,
707 cl_int *errcode_ret)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100708{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100709 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000710 auto func = arm_compute::CLSymbols::get().clCreateProgramWithBinary_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100711 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100712 {
713 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
714 }
715 else
716 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100717 if (errcode_ret != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100718 {
719 *errcode_ret = CL_OUT_OF_RESOURCES;
720 }
721 return nullptr;
722 }
723}
724
725cl_int clRetainContext(cl_context context)
726{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100727 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000728 auto func = arm_compute::CLSymbols::get().clRetainContext_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100729 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100730 {
731 return func(context);
732 }
733 else
734 {
735 return CL_OUT_OF_RESOURCES;
736 }
737}
738
739cl_int clReleaseProgram(cl_program program)
740{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100741 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000742 auto func = arm_compute::CLSymbols::get().clReleaseProgram_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100743 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100744 {
745 return func(program);
746 }
747 else
748 {
749 return CL_OUT_OF_RESOURCES;
750 }
751}
752
753cl_int clFlush(cl_command_queue command_queue)
754{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100755 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000756 auto func = arm_compute::CLSymbols::get().clFlush_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100757 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100758 {
759 return func(command_queue);
760 }
761 else
762 {
763 return CL_OUT_OF_RESOURCES;
764 }
765}
766
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100767cl_int clFinish(cl_command_queue command_queue)
768{
769 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000770 auto func = arm_compute::CLSymbols::get().clFinish_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100771 if (func != nullptr)
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100772 {
773 return func(command_queue);
774 }
775 else
776 {
777 return CL_OUT_OF_RESOURCES;
778 }
779}
780
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100781cl_int clGetProgramInfo(cl_program program,
782 cl_program_info param_name,
783 size_t param_value_size,
784 void *param_value,
785 size_t *param_value_size_ret)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100786{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100787 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000788 auto func = arm_compute::CLSymbols::get().clGetProgramInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100789 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100790 {
791 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
792 }
793 else
794 {
795 return CL_OUT_OF_RESOURCES;
796 }
797}
798
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100799cl_kernel clCreateKernel(cl_program program, const char *kernel_name, cl_int *errcode_ret)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100800{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100801 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000802 auto func = arm_compute::CLSymbols::get().clCreateKernel_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100803 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100804 {
805 return func(program, kernel_name, errcode_ret);
806 }
807 else
808 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100809 if (errcode_ret != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100810 {
811 *errcode_ret = CL_OUT_OF_RESOURCES;
812 }
813 return nullptr;
814 }
815}
816
817cl_int clRetainKernel(cl_kernel kernel)
818{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100819 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000820 auto func = arm_compute::CLSymbols::get().clRetainKernel_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100821 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100822 {
823 return func(kernel);
824 }
825 else
826 {
827 return CL_OUT_OF_RESOURCES;
828 }
829}
830
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100831cl_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 +0100832{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100833 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000834 auto func = arm_compute::CLSymbols::get().clCreateBuffer_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100835 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100836 {
837 return func(context, flags, size, host_ptr, errcode_ret);
838 }
839 else
840 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100841 if (errcode_ret != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100842 {
843 *errcode_ret = CL_OUT_OF_RESOURCES;
844 }
845 return nullptr;
846 }
847}
848
849cl_program clCreateProgramWithSource(
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100850 cl_context context, cl_uint count, const char **strings, const size_t *lengths, cl_int *errcode_ret)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100851{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100852 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000853 auto func = arm_compute::CLSymbols::get().clCreateProgramWithSource_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100854 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100855 {
856 return func(context, count, strings, lengths, errcode_ret);
857 }
858 else
859 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100860 if (errcode_ret != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100861 {
862 *errcode_ret = CL_OUT_OF_RESOURCES;
863 }
864 return nullptr;
865 }
866}
867
868cl_int clReleaseKernel(cl_kernel kernel)
869{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100870 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000871 auto func = arm_compute::CLSymbols::get().clReleaseKernel_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100872 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100873 {
874 return func(kernel);
875 }
876 else
877 {
878 return CL_OUT_OF_RESOURCES;
879 }
880}
881
882cl_int clGetDeviceIDs(cl_platform_id platform,
883 cl_device_type device_type,
884 cl_uint num_entries,
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100885 cl_device_id *devices,
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100886 cl_uint *num_devices)
887{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100888 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000889 auto func = arm_compute::CLSymbols::get().clGetDeviceIDs_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100890 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100891 {
892 return func(platform, device_type, num_entries, devices, num_devices);
893 }
894 else
895 {
896 return CL_OUT_OF_RESOURCES;
897 }
898}
899
900cl_int clGetDeviceInfo(cl_device_id device,
901 cl_device_info param_name,
902 size_t param_value_size,
903 void *param_value,
904 size_t *param_value_size_ret)
905{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100906 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000907 auto func = arm_compute::CLSymbols::get().clGetDeviceInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100908 if (func != nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100909 {
910 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
911 }
912 else
913 {
914 return CL_OUT_OF_RESOURCES;
915 }
916}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100917
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100918cl_int clGetMemObjectInfo(
919 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 +0000920{
921 arm_compute::CLSymbols::get().load_default();
922 auto func = arm_compute::CLSymbols::get().clGetMemObjectInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100923 if (func != nullptr)
Georgios Pinitasdf310362018-11-14 13:16:56 +0000924 {
925 return func(memobj, param_name, param_value_size, param_value, param_value_size_ret);
926 }
927 else
928 {
929 return CL_OUT_OF_RESOURCES;
930 }
931}
932
Giorgio Arena9fe41442017-08-23 16:36:24 +0100933cl_int clRetainEvent(cl_event event)
934{
Moritz Pflanzer159b6da2017-09-20 16:03:35 +0100935 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000936 auto func = arm_compute::CLSymbols::get().clRetainEvent_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100937 if (func != nullptr)
Giorgio Arena9fe41442017-08-23 16:36:24 +0100938 {
939 return func(event);
940 }
941 else
942 {
943 return CL_OUT_OF_RESOURCES;
944 }
945}
steniu01f01f9de2017-09-27 17:00:11 +0100946
Michalis Spyrou402740d2021-04-20 11:26:21 +0100947cl_int clGetPlatformInfo(cl_platform_id platform,
948 cl_platform_info param_name,
949 size_t param_value_size,
950 void *param_value,
951 size_t *param_value_size_ret)
952{
953 arm_compute::CLSymbols::get().load_default();
954 auto func = arm_compute::CLSymbols::get().clGetPlatformInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100955 if (func != nullptr)
Michalis Spyrou402740d2021-04-20 11:26:21 +0100956 {
957 return func(platform, param_name, param_value_size, param_value, param_value_size_ret);
958 }
959 else
960 {
961 return CL_OUT_OF_RESOURCES;
962 }
963}
964
steniu01f01f9de2017-09-27 17:00:11 +0100965cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
966{
967 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000968 auto func = arm_compute::CLSymbols::get().clGetPlatformIDs_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100969 if (func != nullptr)
steniu01f01f9de2017-09-27 17:00:11 +0100970 {
971 return func(num_entries, platforms, num_platforms);
972 }
973 else
974 {
975 return CL_OUT_OF_RESOURCES;
976 }
977}
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100978
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100979cl_int clGetKernelWorkGroupInfo(cl_kernel kernel,
980 cl_device_id device,
981 cl_kernel_work_group_info param_name,
982 size_t param_value_size,
983 void *param_value,
984 size_t *param_value_size_ret)
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100985{
986 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000987 auto func = arm_compute::CLSymbols::get().clGetKernelWorkGroupInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100988 if (func != nullptr)
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100989 {
990 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
991 }
992 else
993 {
994 return CL_OUT_OF_RESOURCES;
995 }
996}
Gian Marco85e6f512018-02-01 16:57:48 +0000997
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100998cl_int clGetCommandQueueInfo(cl_command_queue command_queue,
999 cl_command_queue_info param_name,
1000 size_t param_value_size,
1001 void *param_value,
1002 size_t *param_value_size_ret)
Gian Marco85e6f512018-02-01 16:57:48 +00001003{
1004 arm_compute::CLSymbols::get().load_default();
1005 auto func = arm_compute::CLSymbols::get().clGetCommandQueueInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001006 if (func != nullptr)
Gian Marco85e6f512018-02-01 16:57:48 +00001007 {
1008 return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
1009 }
1010 else
1011 {
1012 return CL_OUT_OF_RESOURCES;
1013 }
1014}
1015
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001016cl_int clGetKernelInfo(cl_kernel kernel,
1017 cl_kernel_info param_name,
1018 size_t param_value_size,
1019 void *param_value,
1020 size_t *param_value_size_ret)
Gian Marco85e6f512018-02-01 16:57:48 +00001021{
1022 arm_compute::CLSymbols::get().load_default();
1023 auto func = arm_compute::CLSymbols::get().clGetKernelInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001024 if (func != nullptr)
Gian Marco85e6f512018-02-01 16:57:48 +00001025 {
1026 return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
1027 }
1028 else
1029 {
1030 return CL_OUT_OF_RESOURCES;
1031 }
1032}
1033
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001034cl_int clGetEventProfilingInfo(cl_event event,
1035 cl_profiling_info param_name,
1036 size_t param_value_size,
1037 void *param_value,
1038 size_t *param_value_size_ret)
Gian Marco85e6f512018-02-01 16:57:48 +00001039{
1040 arm_compute::CLSymbols::get().load_default();
1041 auto func = arm_compute::CLSymbols::get().clGetEventProfilingInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001042 if (func != nullptr)
Gian Marco85e6f512018-02-01 16:57:48 +00001043 {
1044 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
1045 }
1046 else
1047 {
1048 return CL_OUT_OF_RESOURCES;
1049 }
Anthony Barbierf5dcf792018-02-28 18:04:45 +00001050}
Georgios Pinitas4d0351c2019-04-03 15:11:16 +01001051
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001052cl_mem clCreateImage(cl_context context,
1053 cl_mem_flags flags,
1054 const cl_image_format *image_format,
1055 const cl_image_desc *image_desc,
1056 void *host_ptr,
1057 cl_int *errcode_ret)
Gian Marco Iodicea98dee22020-06-02 12:12:35 +01001058{
1059 arm_compute::CLSymbols::get().load_default();
1060 auto func = arm_compute::CLSymbols::get().clCreateImage_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001061 if (func != nullptr)
Gian Marco Iodicea98dee22020-06-02 12:12:35 +01001062 {
1063 return func(context, flags, image_format, image_desc, host_ptr, errcode_ret);
1064 }
1065 else
1066 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001067 if (errcode_ret != nullptr)
Gian Marco Iodicea98dee22020-06-02 12:12:35 +01001068 {
1069 *errcode_ret = CL_OUT_OF_RESOURCES;
1070 }
1071 return nullptr;
1072 }
1073}
1074
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001075cl_int
1076clSetKernelExecInfo(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 +00001077{
1078 arm_compute::CLSymbols::get().load_default();
1079 auto func = arm_compute::CLSymbols::get().clSetKernelExecInfo_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001080 if (func != nullptr)
Manuel Bottinibe9f9f92021-01-25 15:07:17 +00001081 {
1082 return func(kernel, param_name, param_value_size, param_value);
1083 }
1084 else
1085 {
1086 return CL_OUT_OF_RESOURCES;
1087 }
1088}
1089
Gunes Bayireb475ec2023-12-07 11:47:50 +00001090void *clGetExtensionFunctionAddressForPlatform(cl_platform_id platform, const char *funcname)
1091{
1092 arm_compute::CLSymbols::get().load_default();
1093 const auto func = arm_compute::CLSymbols::get().clGetExtensionFunctionAddressForPlatform_ptr;
1094
1095 if (func != nullptr)
1096 {
1097 return func(platform, funcname);
1098 }
1099
1100 return nullptr;
1101}
1102
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001103cl_command_buffer_khr clCreateCommandBufferKHR(cl_uint num_queues,
1104 const cl_command_queue *queues,
1105 const cl_command_buffer_properties_khr *properties,
1106 cl_int *errcode_ret)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001107{
1108 arm_compute::CLSymbols::get().load_default();
1109 const auto func = arm_compute::CLSymbols::get().clCreateCommandBufferKHR_ptr;
1110
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001111 if (func != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001112 {
1113 return func(num_queues, queues, properties, errcode_ret);
1114 }
1115 else
1116 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001117 if (errcode_ret != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001118 {
1119 *errcode_ret = CL_INVALID_OPERATION;
1120 }
1121
1122 return {};
1123 }
1124}
1125
1126cl_int clFinalizeCommandBufferKHR(cl_command_buffer_khr command_buffer)
1127{
1128 arm_compute::CLSymbols::get().load_default();
1129 const auto func = arm_compute::CLSymbols::get().clFinalizeCommandBufferKHR_ptr;
1130
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001131 if (func != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001132 {
1133 return func(command_buffer);
1134 }
1135 else
1136 {
1137 return CL_INVALID_OPERATION;
1138 }
1139}
1140
1141cl_int clRetainCommandBufferKHR(cl_command_buffer_khr command_buffer)
1142{
1143 arm_compute::CLSymbols::get().load_default();
1144 const auto func = arm_compute::CLSymbols::get().clRetainCommandBufferKHR_ptr;
1145
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001146 if (func != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001147 {
1148 return func(command_buffer);
1149 }
1150 else
1151 {
1152 return CL_INVALID_OPERATION;
1153 }
1154}
1155
1156cl_int clReleaseCommandBufferKHR(cl_command_buffer_khr command_buffer)
1157{
1158 arm_compute::CLSymbols::get().load_default();
1159 const auto func = arm_compute::CLSymbols::get().clReleaseCommandBufferKHR_ptr;
1160
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001161 if (func != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001162 {
1163 return func(command_buffer);
1164 }
1165 else
1166 {
1167 return CL_INVALID_OPERATION;
1168 }
1169}
1170
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001171cl_int clEnqueueCommandBufferKHR(cl_uint num_queues,
1172 cl_command_queue *queues,
1173 cl_command_buffer_khr command_buffer,
1174 cl_uint num_events_in_wait_list,
1175 const cl_event *event_wait_list,
1176 cl_event *event)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001177{
1178 arm_compute::CLSymbols::get().load_default();
1179 const auto func = arm_compute::CLSymbols::get().clEnqueueCommandBufferKHR_ptr;
1180
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001181 if (func != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001182 {
1183 return func(num_queues, queues, command_buffer, num_events_in_wait_list, event_wait_list, event);
1184 }
1185 else
1186 {
1187 return CL_INVALID_OPERATION;
1188 }
1189}
1190
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001191cl_int clCommandNDRangeKernelKHR(cl_command_buffer_khr command_buffer,
1192 cl_command_queue command_queue,
1193 const cl_ndrange_kernel_command_properties_khr *properties,
1194 cl_kernel kernel,
1195 cl_uint work_dim,
1196 const size_t *global_work_offset,
1197 const size_t *global_work_size,
1198 const size_t *local_work_size,
1199 cl_uint num_sync_points_in_wait_list,
1200 const cl_sync_point_khr *sync_point_wait_list,
1201 cl_sync_point_khr *sync_point,
1202 cl_mutable_command_khr *mutable_handle)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001203{
1204 arm_compute::CLSymbols::get().load_default();
1205 const auto func = arm_compute::CLSymbols::get().clCommandNDRangeKernelKHR_ptr;
1206
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001207 if (func != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001208 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001209 return func(command_buffer, command_queue, properties, kernel, work_dim, global_work_offset, global_work_size,
1210 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 +01001211 }
1212 else
1213 {
1214 return CL_INVALID_OPERATION;
1215 }
1216}
1217
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001218cl_int clUpdateMutableCommandsKHR(cl_command_buffer_khr command_buffer,
1219 const cl_mutable_base_config_khr *mutable_config)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001220{
1221 arm_compute::CLSymbols::get().load_default();
1222 const auto func = arm_compute::CLSymbols::get().clUpdateMutableCommandsKHR_ptr;
1223
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001224 if (func != nullptr)
Viet-Hoa Do500e10b2023-09-12 17:49:38 +01001225 {
1226 return func(command_buffer, mutable_config);
1227 }
1228 else
1229 {
1230 return CL_INVALID_OPERATION;
1231 }
1232}
1233
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001234cl_mem clImportMemoryARM(cl_context context,
1235 cl_mem_flags flags,
1236 const cl_import_properties_arm *properties,
1237 void *memory,
1238 size_t size,
1239 cl_int *errcode_ret)
Georgios Pinitas4d0351c2019-04-03 15:11:16 +01001240{
1241 arm_compute::CLSymbols::get().load_default();
1242 auto func = arm_compute::CLSymbols::get().clImportMemoryARM_ptr;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001243 if (func != nullptr)
Georgios Pinitas4d0351c2019-04-03 15:11:16 +01001244 {
1245 return func(context, flags, properties, memory, size, errcode_ret);
1246 }
1247 else
1248 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001249 if (errcode_ret != nullptr)
Georgios Pinitas4d0351c2019-04-03 15:11:16 +01001250 {
1251 *errcode_ret = CL_OUT_OF_RESOURCES;
1252 }
1253 return nullptr;
1254 }
Pablo Tellodb8485a2019-09-24 11:03:47 +01001255}