blob: dd9960a7b3e79c60831ca3764631b2426b7ba48b [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Manuel Bottinibe9f9f92021-01-25 15:07:17 +00002 * Copyright (c) 2017-2021 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
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032#include <dlfcn.h>
33#include <iostream>
34
Moritz Pflanzer725788e2017-07-07 15:35:56 +010035namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036{
Georgios Pinitas0b192e82020-02-20 17:09:28 +000037CLSymbols::CLSymbols() noexcept(false)
38 : _loaded(
39{
40 false, false
Georgios Pinitas42bd2652021-03-12 18:40:30 +000041})
Georgios Pinitas0b192e82020-02-20 17:09:28 +000042{
43}
44
Moritz Pflanzer725788e2017-07-07 15:35:56 +010045CLSymbols &CLSymbols::get()
46{
47 static CLSymbols symbols;
48 return symbols;
49}
50
51bool CLSymbols::load_default()
52{
53 static const std::vector<std::string> libraries{ "libOpenCL.so", "libGLES_mali.so", "libmali.so" };
54
55 if(_loaded.first)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010056 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010057 return _loaded.second;
58 }
59
60 // Indicate that default loading has been tried
61 _loaded.first = true;
62
63 for(const auto &lib : libraries)
64 {
65 if(load(lib))
Anthony Barbier6ff3b192017-09-04 18:44:23 +010066 {
Pablo Tellodb8485a2019-09-24 11:03:47 +010067 ARM_COMPUTE_ERROR_ON_MSG(this->clBuildProgram_ptr == nullptr, "Failed to load OpenCL symbols from shared library");
Moritz Pflanzer725788e2017-07-07 15:35:56 +010068 return true;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010069 }
70 }
71
Moritz Pflanzer725788e2017-07-07 15:35:56 +010072 std::cerr << "Couldn't find any OpenCL library.\n";
73 return false;
74}
75
76bool CLSymbols::load(const std::string &library)
77{
Georgios Pinitas42bd2652021-03-12 18:40:30 +000078 void *handle = dlopen(library.c_str(), RTLD_LAZY | RTLD_LOCAL);
Moritz Pflanzer725788e2017-07-07 15:35:56 +010079
Georgios Pinitas42bd2652021-03-12 18:40:30 +000080 if(handle == nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010081 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010082 std::cerr << "Can't load " << library << ": " << dlerror() << "\n";
83 // Set status of loading to failed
84 _loaded.second = false;
85 return false;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010086 }
87
Anthony Barbier58c4ff12017-11-09 09:15:32 +000088#define LOAD_FUNCTION_PTR(func_name, handle) \
89 func_name##_ptr = reinterpret_cast<decltype(func_name) *>(dlsym(handle, #func_name));
90
Georgios Pinitas42bd2652021-03-12 18:40:30 +000091 LOAD_FUNCTION_PTR(clCreateContext, handle);
92 LOAD_FUNCTION_PTR(clCreateContextFromType, handle);
93 LOAD_FUNCTION_PTR(clCreateCommandQueue, handle);
94 LOAD_FUNCTION_PTR(clGetContextInfo, handle);
95 LOAD_FUNCTION_PTR(clBuildProgram, handle);
96 LOAD_FUNCTION_PTR(clEnqueueNDRangeKernel, handle);
97 LOAD_FUNCTION_PTR(clSetKernelArg, handle);
98 LOAD_FUNCTION_PTR(clReleaseKernel, handle);
99 LOAD_FUNCTION_PTR(clCreateProgramWithSource, handle);
100 LOAD_FUNCTION_PTR(clCreateBuffer, handle);
101 LOAD_FUNCTION_PTR(clRetainKernel, handle);
102 LOAD_FUNCTION_PTR(clCreateKernel, handle);
103 LOAD_FUNCTION_PTR(clGetProgramInfo, handle);
104 LOAD_FUNCTION_PTR(clFlush, handle);
105 LOAD_FUNCTION_PTR(clFinish, handle);
106 LOAD_FUNCTION_PTR(clReleaseProgram, handle);
107 LOAD_FUNCTION_PTR(clRetainContext, handle);
108 LOAD_FUNCTION_PTR(clCreateProgramWithBinary, handle);
109 LOAD_FUNCTION_PTR(clReleaseCommandQueue, handle);
110 LOAD_FUNCTION_PTR(clEnqueueMapBuffer, handle);
111 LOAD_FUNCTION_PTR(clRetainProgram, handle);
112 LOAD_FUNCTION_PTR(clGetProgramBuildInfo, handle);
113 LOAD_FUNCTION_PTR(clEnqueueReadBuffer, handle);
114 LOAD_FUNCTION_PTR(clEnqueueWriteBuffer, handle);
115 LOAD_FUNCTION_PTR(clReleaseEvent, handle);
116 LOAD_FUNCTION_PTR(clReleaseContext, handle);
117 LOAD_FUNCTION_PTR(clRetainCommandQueue, handle);
118 LOAD_FUNCTION_PTR(clEnqueueUnmapMemObject, handle);
119 LOAD_FUNCTION_PTR(clRetainMemObject, handle);
120 LOAD_FUNCTION_PTR(clReleaseMemObject, handle);
121 LOAD_FUNCTION_PTR(clGetDeviceInfo, handle);
122 LOAD_FUNCTION_PTR(clGetDeviceIDs, handle);
123 LOAD_FUNCTION_PTR(clGetMemObjectInfo, handle);
124 LOAD_FUNCTION_PTR(clRetainEvent, handle);
125 LOAD_FUNCTION_PTR(clGetPlatformIDs, handle);
126 LOAD_FUNCTION_PTR(clGetKernelWorkGroupInfo, handle);
127 LOAD_FUNCTION_PTR(clGetCommandQueueInfo, handle);
128 LOAD_FUNCTION_PTR(clGetKernelInfo, handle);
129 LOAD_FUNCTION_PTR(clGetEventProfilingInfo, handle);
130 LOAD_FUNCTION_PTR(clSVMAlloc, handle);
131 LOAD_FUNCTION_PTR(clSVMFree, handle);
132 LOAD_FUNCTION_PTR(clEnqueueSVMMap, handle);
133 LOAD_FUNCTION_PTR(clEnqueueSVMUnmap, handle);
134 LOAD_FUNCTION_PTR(clEnqueueMarker, handle);
135 LOAD_FUNCTION_PTR(clWaitForEvents, handle);
136 LOAD_FUNCTION_PTR(clCreateImage, handle);
137 LOAD_FUNCTION_PTR(clSetKernelExecInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000138
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100139 // Third-party extensions
Georgios Pinitas42bd2652021-03-12 18:40:30 +0000140 LOAD_FUNCTION_PTR(clImportMemoryARM, handle);
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100141
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000142#undef LOAD_FUNCTION_PTR
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100143
Georgios Pinitas42bd2652021-03-12 18:40:30 +0000144 //Don't call dlclose(handle) or all the symbols will be unloaded !
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100145
146 // Disable default loading and set status to successful
147 _loaded = std::make_pair(true, true);
148
149 return true;
150}
151
152bool opencl_is_available()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100153{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100154 CLSymbols::get().load_default();
Marco Antognini4a5f73d2021-03-23 16:59:08 +0000155
156 // Using static objects that rely on OpenCL in their constructor or
157 // destructor is implementation defined according to the OpenCL API
158 // Specification. These objects include CLScheduler.
159 //
160 // For compatibility with OpenCL runtimes that also use static objects to
161 // hold their state, we call a harmless OpenCL function (clGetPlatformIDs
162 // with invalid parameters must result in CL_INVALID_VALUE) to ensure the
163 // runtimes have a chance to initialize their static objects first. Thanks
164 // to C++11 rules about normal program termination (cf [basic.start]), this
165 // ensures their static objects are destroyed last, i.e. after the
166 // singleton CLScheduler is destroyed.
167 //
168 // When OpenCL is not available, this call results in CL_OUT_OF_RESOURCES,
169 // which is equally harmless.
170 (void)clGetPlatformIDs(0, nullptr, nullptr);
171
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000172 return CLSymbols::get().clBuildProgram_ptr != nullptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100173}
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100174} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100175
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100176cl_int clEnqueueMarker(cl_command_queue command_queue,
177 cl_event *event)
178{
179 arm_compute::CLSymbols::get().load_default();
180 auto func = arm_compute::CLSymbols::get().clEnqueueMarker_ptr;
181 if(func != nullptr)
182 {
183 return func(command_queue, event);
184 }
185 else
186 {
187 return CL_OUT_OF_RESOURCES;
188 }
189}
190
191cl_int clWaitForEvents(cl_uint num_events,
192 const cl_event *event_list)
193{
194 arm_compute::CLSymbols::get().load_default();
195 auto func = arm_compute::CLSymbols::get().clWaitForEvents_ptr;
196 if(func != nullptr)
197 {
198 return func(num_events, event_list);
199 }
200 else
201 {
202 return CL_OUT_OF_RESOURCES;
203 }
204}
205
Pablo Telloe86a09f2018-01-11 15:44:48 +0000206cl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags flags, void *svm_ptr,
207 size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
208{
209 arm_compute::CLSymbols::get().load_default();
210 auto func = arm_compute::CLSymbols::get().clEnqueueSVMMap_ptr;
211 if(func != nullptr)
212 {
213 return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
214 }
215 else
216 {
217 return CL_OUT_OF_RESOURCES;
218 }
219}
220
221cl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *svm_ptr, cl_uint num_events_in_wait_list,
222 const cl_event *event_wait_list, cl_event *event)
223{
224 arm_compute::CLSymbols::get().load_default();
225 auto func = arm_compute::CLSymbols::get().clEnqueueSVMUnmap_ptr;
226 if(func != nullptr)
227 {
228 return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
229 }
230 else
231 {
232 return CL_OUT_OF_RESOURCES;
233 }
234}
235
236void *clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
237{
238 arm_compute::CLSymbols::get().load_default();
239 auto func = arm_compute::CLSymbols::get().clSVMAlloc_ptr;
240 if(func != nullptr)
241 {
242 return func(context, flags, size, alignment);
243 }
244 else
245 {
246 return nullptr;
247 }
248}
249
250void clSVMFree(cl_context context, void *svm_pointer)
251{
252 arm_compute::CLSymbols::get().load_default();
253 auto func = arm_compute::CLSymbols::get().clSVMFree_ptr;
254 if(func != nullptr)
255 {
256 func(context, svm_pointer);
257 }
258}
259
Anthony Barbiera9e15332017-12-22 16:37:30 +0000260cl_int clGetContextInfo(cl_context context,
261 cl_context_info param_name,
262 size_t param_value_size,
263 void *param_value,
264 size_t *param_value_size_ret)
265{
266 arm_compute::CLSymbols::get().load_default();
267 auto func = arm_compute::CLSymbols::get().clGetContextInfo_ptr;
268 if(func != nullptr)
269 {
270 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
271 }
272 else
273 {
274 return CL_OUT_OF_RESOURCES;
275 }
276}
277
278cl_command_queue clCreateCommandQueue(cl_context context,
279 cl_device_id device,
280 cl_command_queue_properties properties,
281 cl_int *errcode_ret)
282{
283 arm_compute::CLSymbols::get().load_default();
284 auto func = arm_compute::CLSymbols::get().clCreateCommandQueue_ptr;
285 if(func != nullptr)
286 {
287 return func(context, device, properties, errcode_ret);
288 }
289 else
290 {
291 return nullptr;
292 }
293}
294
Anthony Barbierb6eb3532018-08-08 13:20:04 +0100295cl_context clCreateContext(
296 const cl_context_properties *properties,
297 cl_uint num_devices,
298 const cl_device_id *devices,
299 void (*pfn_notify)(const char *, const void *, size_t, void *),
300 void *user_data,
301 cl_int *errcode_ret)
302{
303 arm_compute::CLSymbols::get().load_default();
304 auto func = arm_compute::CLSymbols::get().clCreateContext_ptr;
305 if(func != nullptr)
306 {
307 return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
308 }
309 else
310 {
311 return nullptr;
312 }
313}
314
Anthony Barbiera9e15332017-12-22 16:37:30 +0000315cl_context clCreateContextFromType(const cl_context_properties *properties,
316 cl_device_type device_type,
317 void (*pfn_notify)(const char *, const void *, size_t, void *),
318 void *user_data,
319 cl_int *errcode_ret)
320{
321 arm_compute::CLSymbols::get().load_default();
322 auto func = arm_compute::CLSymbols::get().clCreateContextFromType_ptr;
323 if(func != nullptr)
324 {
325 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
326 }
327 else
328 {
329 return nullptr;
330 }
331}
332
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100333cl_int clBuildProgram(
334 cl_program program,
335 cl_uint num_devices,
336 const cl_device_id *device_list,
337 const char *options,
338 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
339 void *user_data)
340{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100341 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000342 auto func = arm_compute::CLSymbols::get().clBuildProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100343 if(func != nullptr)
344 {
345 return func(program, num_devices, device_list, options, pfn_notify, user_data);
346 }
347 else
348 {
349 return CL_OUT_OF_RESOURCES;
350 }
351}
352
353cl_int clEnqueueNDRangeKernel(
354 cl_command_queue command_queue,
355 cl_kernel kernel,
356 cl_uint work_dim,
357 const size_t *global_work_offset,
358 const size_t *global_work_size,
359 const size_t *local_work_size,
360 cl_uint num_events_in_wait_list,
361 const cl_event *event_wait_list,
362 cl_event *event)
363{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100364 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000365 auto func = arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100366 if(func != nullptr)
367 {
368 return func(command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size, num_events_in_wait_list, event_wait_list, event);
369 }
370 else
371 {
372 return CL_OUT_OF_RESOURCES;
373 }
374}
375
376cl_int clSetKernelArg(
377 cl_kernel kernel,
378 cl_uint arg_index,
379 size_t arg_size,
380 const void *arg_value)
381{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100382 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000383 auto func = arm_compute::CLSymbols::get().clSetKernelArg_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100384 if(func != nullptr)
385 {
386 return func(kernel, arg_index, arg_size, arg_value);
387 }
388 else
389 {
390 return CL_OUT_OF_RESOURCES;
391 }
392}
393
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100394cl_int clRetainMemObject(cl_mem memobj)
395{
396 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000397 auto func = arm_compute::CLSymbols::get().clRetainMemObject_ptr;
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100398 if(func != nullptr)
399 {
400 return func(memobj);
401 }
402 else
403 {
404 return CL_OUT_OF_RESOURCES;
405 }
406}
407
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100408cl_int clReleaseMemObject(cl_mem memobj)
409{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100410 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000411 auto func = arm_compute::CLSymbols::get().clReleaseMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100412 if(func != nullptr)
413 {
414 return func(memobj);
415 }
416 else
417 {
418 return CL_OUT_OF_RESOURCES;
419 }
420}
421
422cl_int clEnqueueUnmapMemObject(
423 cl_command_queue command_queue,
424 cl_mem memobj,
425 void *mapped_ptr,
426 cl_uint num_events_in_wait_list,
427 const cl_event *event_wait_list,
428 cl_event *event)
429{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100430 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000431 auto func = arm_compute::CLSymbols::get().clEnqueueUnmapMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100432 if(func != nullptr)
433 {
434 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
435 }
436 else
437 {
438 return CL_OUT_OF_RESOURCES;
439 }
440}
441
442cl_int clRetainCommandQueue(cl_command_queue command_queue)
443{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100444 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000445 auto func = arm_compute::CLSymbols::get().clRetainCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100446 if(func != nullptr)
447 {
448 return func(command_queue);
449 }
450 else
451 {
452 return CL_OUT_OF_RESOURCES;
453 }
454}
455
456cl_int clReleaseContext(cl_context context)
457{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100458 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000459 auto func = arm_compute::CLSymbols::get().clReleaseContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100460 if(func != nullptr)
461 {
462 return func(context);
463 }
464 else
465 {
466 return CL_OUT_OF_RESOURCES;
467 }
468}
469cl_int clReleaseEvent(cl_event event)
470{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100471 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000472 auto func = arm_compute::CLSymbols::get().clReleaseEvent_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100473 if(func != nullptr)
474 {
475 return func(event);
476 }
477 else
478 {
479 return CL_OUT_OF_RESOURCES;
480 }
481}
482
483cl_int clEnqueueWriteBuffer(
484 cl_command_queue command_queue,
485 cl_mem buffer,
486 cl_bool blocking_write,
487 size_t offset,
488 size_t size,
489 const void *ptr,
490 cl_uint num_events_in_wait_list,
491 const cl_event *event_wait_list,
492 cl_event *event)
493{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100494 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000495 auto func = arm_compute::CLSymbols::get().clEnqueueWriteBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100496 if(func != nullptr)
497 {
498 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
499 }
500 else
501 {
502 return CL_OUT_OF_RESOURCES;
503 }
504}
505
506cl_int clEnqueueReadBuffer(
507 cl_command_queue command_queue,
508 cl_mem buffer,
509 cl_bool blocking_read,
510 size_t offset,
511 size_t size,
512 void *ptr,
513 cl_uint num_events_in_wait_list,
514 const cl_event *event_wait_list,
515 cl_event *event)
516{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100517 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000518 auto func = arm_compute::CLSymbols::get().clEnqueueReadBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100519 if(func != nullptr)
520 {
521 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
522 }
523 else
524 {
525 return CL_OUT_OF_RESOURCES;
526 }
527}
528
529cl_int clGetProgramBuildInfo(
530 cl_program program,
531 cl_device_id device,
532 cl_program_build_info param_name,
533 size_t param_value_size,
534 void *param_value,
535 size_t *param_value_size_ret)
536{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100537 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000538 auto func = arm_compute::CLSymbols::get().clGetProgramBuildInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100539 if(func != nullptr)
540 {
541 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
542 }
543 else
544 {
545 return CL_OUT_OF_RESOURCES;
546 }
547}
548
549cl_int clRetainProgram(cl_program program)
550{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100551 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000552 auto func = arm_compute::CLSymbols::get().clRetainProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100553 if(func != nullptr)
554 {
555 return func(program);
556 }
557 else
558 {
559 return CL_OUT_OF_RESOURCES;
560 }
561}
562
563void *clEnqueueMapBuffer(
564 cl_command_queue command_queue,
565 cl_mem buffer,
566 cl_bool blocking_map,
567 cl_map_flags map_flags,
568 size_t offset,
569 size_t size,
570 cl_uint num_events_in_wait_list,
571 const cl_event *event_wait_list,
572 cl_event *event,
573 cl_int *errcode_ret)
574{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100575 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000576 auto func = arm_compute::CLSymbols::get().clEnqueueMapBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100577 if(func != nullptr)
578 {
579 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
580 }
581 else
582 {
583 if(errcode_ret != nullptr)
584 {
585 *errcode_ret = CL_OUT_OF_RESOURCES;
586 }
587 return nullptr;
588 }
589}
590
591cl_int clReleaseCommandQueue(cl_command_queue command_queue)
592{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100593 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000594 auto func = arm_compute::CLSymbols::get().clReleaseCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100595 if(func != nullptr)
596 {
597 return func(command_queue);
598 }
599 else
600 {
601 return CL_OUT_OF_RESOURCES;
602 }
603}
604
605cl_program clCreateProgramWithBinary(
606 cl_context context,
607 cl_uint num_devices,
608 const cl_device_id *device_list,
609 const size_t *lengths,
610 const unsigned char **binaries,
611 cl_int *binary_status,
612 cl_int *errcode_ret)
613{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100614 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000615 auto func = arm_compute::CLSymbols::get().clCreateProgramWithBinary_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100616 if(func != nullptr)
617 {
618 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
619 }
620 else
621 {
622 if(errcode_ret != nullptr)
623 {
624 *errcode_ret = CL_OUT_OF_RESOURCES;
625 }
626 return nullptr;
627 }
628}
629
630cl_int clRetainContext(cl_context context)
631{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100632 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000633 auto func = arm_compute::CLSymbols::get().clRetainContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100634 if(func != nullptr)
635 {
636 return func(context);
637 }
638 else
639 {
640 return CL_OUT_OF_RESOURCES;
641 }
642}
643
644cl_int clReleaseProgram(cl_program program)
645{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100646 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000647 auto func = arm_compute::CLSymbols::get().clReleaseProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100648 if(func != nullptr)
649 {
650 return func(program);
651 }
652 else
653 {
654 return CL_OUT_OF_RESOURCES;
655 }
656}
657
658cl_int clFlush(cl_command_queue command_queue)
659{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100660 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000661 auto func = arm_compute::CLSymbols::get().clFlush_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100662 if(func != nullptr)
663 {
664 return func(command_queue);
665 }
666 else
667 {
668 return CL_OUT_OF_RESOURCES;
669 }
670}
671
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100672cl_int clFinish(cl_command_queue command_queue)
673{
674 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000675 auto func = arm_compute::CLSymbols::get().clFinish_ptr;
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100676 if(func != nullptr)
677 {
678 return func(command_queue);
679 }
680 else
681 {
682 return CL_OUT_OF_RESOURCES;
683 }
684}
685
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100686cl_int clGetProgramInfo(
687 cl_program program,
688 cl_program_info param_name,
689 size_t param_value_size,
690 void *param_value,
691 size_t *param_value_size_ret)
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().clGetProgramInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100695 if(func != nullptr)
696 {
697 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
698 }
699 else
700 {
701 return CL_OUT_OF_RESOURCES;
702 }
703}
704
705cl_kernel clCreateKernel(
706 cl_program program,
707 const char *kernel_name,
708 cl_int *errcode_ret)
709{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100710 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000711 auto func = arm_compute::CLSymbols::get().clCreateKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100712 if(func != nullptr)
713 {
714 return func(program, kernel_name, errcode_ret);
715 }
716 else
717 {
718 if(errcode_ret != nullptr)
719 {
720 *errcode_ret = CL_OUT_OF_RESOURCES;
721 }
722 return nullptr;
723 }
724}
725
726cl_int clRetainKernel(cl_kernel kernel)
727{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100728 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000729 auto func = arm_compute::CLSymbols::get().clRetainKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100730 if(func != nullptr)
731 {
732 return func(kernel);
733 }
734 else
735 {
736 return CL_OUT_OF_RESOURCES;
737 }
738}
739
740cl_mem clCreateBuffer(
741 cl_context context,
742 cl_mem_flags flags,
743 size_t size,
744 void *host_ptr,
745 cl_int *errcode_ret)
746{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100747 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000748 auto func = arm_compute::CLSymbols::get().clCreateBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100749 if(func != nullptr)
750 {
751 return func(context, flags, size, host_ptr, errcode_ret);
752 }
753 else
754 {
755 if(errcode_ret != nullptr)
756 {
757 *errcode_ret = CL_OUT_OF_RESOURCES;
758 }
759 return nullptr;
760 }
761}
762
763cl_program clCreateProgramWithSource(
764 cl_context context,
765 cl_uint count,
766 const char **strings,
767 const size_t *lengths,
768 cl_int *errcode_ret)
769{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100770 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000771 auto func = arm_compute::CLSymbols::get().clCreateProgramWithSource_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100772 if(func != nullptr)
773 {
774 return func(context, count, strings, lengths, errcode_ret);
775 }
776 else
777 {
778 if(errcode_ret != nullptr)
779 {
780 *errcode_ret = CL_OUT_OF_RESOURCES;
781 }
782 return nullptr;
783 }
784}
785
786cl_int clReleaseKernel(cl_kernel kernel)
787{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100788 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000789 auto func = arm_compute::CLSymbols::get().clReleaseKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100790 if(func != nullptr)
791 {
792 return func(kernel);
793 }
794 else
795 {
796 return CL_OUT_OF_RESOURCES;
797 }
798}
799
800cl_int clGetDeviceIDs(cl_platform_id platform,
801 cl_device_type device_type,
802 cl_uint num_entries,
803 cl_device_id *devices,
804 cl_uint *num_devices)
805{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100806 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000807 auto func = arm_compute::CLSymbols::get().clGetDeviceIDs_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100808 if(func != nullptr)
809 {
810 return func(platform, device_type, num_entries, devices, num_devices);
811 }
812 else
813 {
814 return CL_OUT_OF_RESOURCES;
815 }
816}
817
818cl_int clGetDeviceInfo(cl_device_id device,
819 cl_device_info param_name,
820 size_t param_value_size,
821 void *param_value,
822 size_t *param_value_size_ret)
823{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100824 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000825 auto func = arm_compute::CLSymbols::get().clGetDeviceInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100826 if(func != nullptr)
827 {
828 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
829 }
830 else
831 {
832 return CL_OUT_OF_RESOURCES;
833 }
834}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100835
Georgios Pinitasdf310362018-11-14 13:16:56 +0000836cl_int clGetMemObjectInfo(cl_mem memobj,
837 cl_mem_info param_name,
838 size_t param_value_size,
839 void *param_value,
840 size_t *param_value_size_ret)
841{
842 arm_compute::CLSymbols::get().load_default();
843 auto func = arm_compute::CLSymbols::get().clGetMemObjectInfo_ptr;
844 if(func != nullptr)
845 {
846 return func(memobj, param_name, param_value_size, param_value, param_value_size_ret);
847 }
848 else
849 {
850 return CL_OUT_OF_RESOURCES;
851 }
852}
853
Giorgio Arena9fe41442017-08-23 16:36:24 +0100854cl_int clRetainEvent(cl_event event)
855{
Moritz Pflanzer159b6da2017-09-20 16:03:35 +0100856 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000857 auto func = arm_compute::CLSymbols::get().clRetainEvent_ptr;
Giorgio Arena9fe41442017-08-23 16:36:24 +0100858 if(func != nullptr)
859 {
860 return func(event);
861 }
862 else
863 {
864 return CL_OUT_OF_RESOURCES;
865 }
866}
steniu01f01f9de2017-09-27 17:00:11 +0100867
868cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
869{
870 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000871 auto func = arm_compute::CLSymbols::get().clGetPlatformIDs_ptr;
steniu01f01f9de2017-09-27 17:00:11 +0100872 if(func != nullptr)
873 {
874 return func(num_entries, platforms, num_platforms);
875 }
876 else
877 {
878 return CL_OUT_OF_RESOURCES;
879 }
880}
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100881
882cl_int
883clGetKernelWorkGroupInfo(cl_kernel kernel,
884 cl_device_id device,
885 cl_kernel_work_group_info param_name,
886 size_t param_value_size,
887 void *param_value,
888 size_t *param_value_size_ret)
889{
890 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000891 auto func = arm_compute::CLSymbols::get().clGetKernelWorkGroupInfo_ptr;
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100892 if(func != nullptr)
893 {
894 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
895 }
896 else
897 {
898 return CL_OUT_OF_RESOURCES;
899 }
900}
Gian Marco85e6f512018-02-01 16:57:48 +0000901
902cl_int
903clGetCommandQueueInfo(cl_command_queue command_queue,
904 cl_command_queue_info param_name,
905 size_t param_value_size,
906 void *param_value,
907 size_t *param_value_size_ret)
908{
909 arm_compute::CLSymbols::get().load_default();
910 auto func = arm_compute::CLSymbols::get().clGetCommandQueueInfo_ptr;
911 if(func != nullptr)
912 {
913 return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
914 }
915 else
916 {
917 return CL_OUT_OF_RESOURCES;
918 }
919}
920
921cl_int
922clGetKernelInfo(cl_kernel kernel,
923 cl_kernel_info param_name,
924 size_t param_value_size,
925 void *param_value,
926 size_t *param_value_size_ret)
927{
928 arm_compute::CLSymbols::get().load_default();
929 auto func = arm_compute::CLSymbols::get().clGetKernelInfo_ptr;
930 if(func != nullptr)
931 {
932 return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
933 }
934 else
935 {
936 return CL_OUT_OF_RESOURCES;
937 }
938}
939
940cl_int
941clGetEventProfilingInfo(cl_event event,
942 cl_profiling_info param_name,
943 size_t param_value_size,
944 void *param_value,
945 size_t *param_value_size_ret)
946{
947 arm_compute::CLSymbols::get().load_default();
948 auto func = arm_compute::CLSymbols::get().clGetEventProfilingInfo_ptr;
949 if(func != nullptr)
950 {
951 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
952 }
953 else
954 {
955 return CL_OUT_OF_RESOURCES;
956 }
Anthony Barbierf5dcf792018-02-28 18:04:45 +0000957}
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100958
959cl_mem
Gian Marco Iodicea98dee22020-06-02 12:12:35 +0100960clCreateImage(cl_context context,
961 cl_mem_flags flags,
962 const cl_image_format *image_format,
963 const cl_image_desc *image_desc,
964 void *host_ptr,
965 cl_int *errcode_ret)
966{
967 arm_compute::CLSymbols::get().load_default();
968 auto func = arm_compute::CLSymbols::get().clCreateImage_ptr;
969 if(func != nullptr)
970 {
971 return func(context, flags, image_format, image_desc, host_ptr, errcode_ret);
972 }
973 else
974 {
975 if(errcode_ret != nullptr)
976 {
977 *errcode_ret = CL_OUT_OF_RESOURCES;
978 }
979 return nullptr;
980 }
981}
982
Manuel Bottinibe9f9f92021-01-25 15:07:17 +0000983cl_int clSetKernelExecInfo(cl_kernel kernel,
984 cl_kernel_exec_info param_name,
985 size_t param_value_size,
986 const void *param_value)
987{
988 arm_compute::CLSymbols::get().load_default();
989 auto func = arm_compute::CLSymbols::get().clSetKernelExecInfo_ptr;
990 if(func != nullptr)
991 {
992 return func(kernel, param_name, param_value_size, param_value);
993 }
994 else
995 {
996 return CL_OUT_OF_RESOURCES;
997 }
998}
999
Gian Marco Iodicea98dee22020-06-02 12:12:35 +01001000cl_mem
Georgios Pinitas4d0351c2019-04-03 15:11:16 +01001001clImportMemoryARM(cl_context context,
1002 cl_mem_flags flags,
1003 const cl_import_properties_arm *properties,
1004 void *memory,
1005 size_t size,
1006 cl_int *errcode_ret)
1007{
1008 arm_compute::CLSymbols::get().load_default();
1009 auto func = arm_compute::CLSymbols::get().clImportMemoryARM_ptr;
1010 if(func != nullptr)
1011 {
1012 return func(context, flags, properties, memory, size, errcode_ret);
1013 }
1014 else
1015 {
1016 if(errcode_ret != nullptr)
1017 {
1018 *errcode_ret = CL_OUT_OF_RESOURCES;
1019 }
1020 return nullptr;
1021 }
Pablo Tellodb8485a2019-09-24 11:03:47 +01001022}