blob: d5034ba8fad53908a9a3b52a54acbc93af955856 [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);
Georgios Pinitasc3c352e2021-03-18 10:59:40 +000094 LOAD_FUNCTION_PTR(clCreateCommandQueueWithProperties, handle);
Georgios Pinitas42bd2652021-03-12 18:40:30 +000095 LOAD_FUNCTION_PTR(clGetContextInfo, handle);
96 LOAD_FUNCTION_PTR(clBuildProgram, handle);
97 LOAD_FUNCTION_PTR(clEnqueueNDRangeKernel, handle);
98 LOAD_FUNCTION_PTR(clSetKernelArg, handle);
99 LOAD_FUNCTION_PTR(clReleaseKernel, handle);
100 LOAD_FUNCTION_PTR(clCreateProgramWithSource, handle);
101 LOAD_FUNCTION_PTR(clCreateBuffer, handle);
102 LOAD_FUNCTION_PTR(clRetainKernel, handle);
103 LOAD_FUNCTION_PTR(clCreateKernel, handle);
104 LOAD_FUNCTION_PTR(clGetProgramInfo, handle);
105 LOAD_FUNCTION_PTR(clFlush, handle);
106 LOAD_FUNCTION_PTR(clFinish, handle);
107 LOAD_FUNCTION_PTR(clReleaseProgram, handle);
108 LOAD_FUNCTION_PTR(clRetainContext, handle);
109 LOAD_FUNCTION_PTR(clCreateProgramWithBinary, handle);
110 LOAD_FUNCTION_PTR(clReleaseCommandQueue, handle);
111 LOAD_FUNCTION_PTR(clEnqueueMapBuffer, handle);
112 LOAD_FUNCTION_PTR(clRetainProgram, handle);
113 LOAD_FUNCTION_PTR(clGetProgramBuildInfo, handle);
114 LOAD_FUNCTION_PTR(clEnqueueReadBuffer, handle);
115 LOAD_FUNCTION_PTR(clEnqueueWriteBuffer, handle);
116 LOAD_FUNCTION_PTR(clReleaseEvent, handle);
117 LOAD_FUNCTION_PTR(clReleaseContext, handle);
118 LOAD_FUNCTION_PTR(clRetainCommandQueue, handle);
119 LOAD_FUNCTION_PTR(clEnqueueUnmapMemObject, handle);
120 LOAD_FUNCTION_PTR(clRetainMemObject, handle);
121 LOAD_FUNCTION_PTR(clReleaseMemObject, handle);
122 LOAD_FUNCTION_PTR(clGetDeviceInfo, handle);
123 LOAD_FUNCTION_PTR(clGetDeviceIDs, handle);
124 LOAD_FUNCTION_PTR(clGetMemObjectInfo, handle);
125 LOAD_FUNCTION_PTR(clRetainEvent, handle);
Michalis Spyrou402740d2021-04-20 11:26:21 +0100126 LOAD_FUNCTION_PTR(clGetPlatformInfo, handle);
Georgios Pinitas42bd2652021-03-12 18:40:30 +0000127 LOAD_FUNCTION_PTR(clGetPlatformIDs, handle);
128 LOAD_FUNCTION_PTR(clGetKernelWorkGroupInfo, handle);
129 LOAD_FUNCTION_PTR(clGetCommandQueueInfo, handle);
130 LOAD_FUNCTION_PTR(clGetKernelInfo, handle);
131 LOAD_FUNCTION_PTR(clGetEventProfilingInfo, handle);
132 LOAD_FUNCTION_PTR(clSVMAlloc, handle);
133 LOAD_FUNCTION_PTR(clSVMFree, handle);
134 LOAD_FUNCTION_PTR(clEnqueueSVMMap, handle);
135 LOAD_FUNCTION_PTR(clEnqueueSVMUnmap, handle);
136 LOAD_FUNCTION_PTR(clEnqueueMarker, handle);
137 LOAD_FUNCTION_PTR(clWaitForEvents, handle);
138 LOAD_FUNCTION_PTR(clCreateImage, handle);
139 LOAD_FUNCTION_PTR(clSetKernelExecInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000140
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100141 // Third-party extensions
Georgios Pinitas42bd2652021-03-12 18:40:30 +0000142 LOAD_FUNCTION_PTR(clImportMemoryARM, handle);
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100143
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000144#undef LOAD_FUNCTION_PTR
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100145
Georgios Pinitas42bd2652021-03-12 18:40:30 +0000146 //Don't call dlclose(handle) or all the symbols will be unloaded !
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100147
148 // Disable default loading and set status to successful
149 _loaded = std::make_pair(true, true);
150
151 return true;
152}
153
154bool opencl_is_available()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100155{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100156 CLSymbols::get().load_default();
Marco Antognini4a5f73d2021-03-23 16:59:08 +0000157
158 // Using static objects that rely on OpenCL in their constructor or
159 // destructor is implementation defined according to the OpenCL API
160 // Specification. These objects include CLScheduler.
161 //
162 // For compatibility with OpenCL runtimes that also use static objects to
163 // hold their state, we call a harmless OpenCL function (clGetPlatformIDs
164 // with invalid parameters must result in CL_INVALID_VALUE) to ensure the
165 // runtimes have a chance to initialize their static objects first. Thanks
ramelg01b2eba7f2021-12-23 08:32:08 +0000166 // to C++11 rules about normal program completion (cf [basic.start]), this
Marco Antognini4a5f73d2021-03-23 16:59:08 +0000167 // ensures their static objects are destroyed last, i.e. after the
168 // singleton CLScheduler is destroyed.
169 //
170 // When OpenCL is not available, this call results in CL_OUT_OF_RESOURCES,
171 // which is equally harmless.
172 (void)clGetPlatformIDs(0, nullptr, nullptr);
173
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000174 return CLSymbols::get().clBuildProgram_ptr != nullptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100175}
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100176} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100177
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100178cl_int clEnqueueMarker(cl_command_queue command_queue,
179 cl_event *event)
180{
181 arm_compute::CLSymbols::get().load_default();
182 auto func = arm_compute::CLSymbols::get().clEnqueueMarker_ptr;
183 if(func != nullptr)
184 {
185 return func(command_queue, event);
186 }
187 else
188 {
189 return CL_OUT_OF_RESOURCES;
190 }
191}
192
193cl_int clWaitForEvents(cl_uint num_events,
194 const cl_event *event_list)
195{
196 arm_compute::CLSymbols::get().load_default();
197 auto func = arm_compute::CLSymbols::get().clWaitForEvents_ptr;
198 if(func != nullptr)
199 {
200 return func(num_events, event_list);
201 }
202 else
203 {
204 return CL_OUT_OF_RESOURCES;
205 }
206}
207
Pablo Telloe86a09f2018-01-11 15:44:48 +0000208cl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags flags, void *svm_ptr,
209 size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
210{
211 arm_compute::CLSymbols::get().load_default();
212 auto func = arm_compute::CLSymbols::get().clEnqueueSVMMap_ptr;
213 if(func != nullptr)
214 {
215 return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
216 }
217 else
218 {
219 return CL_OUT_OF_RESOURCES;
220 }
221}
222
223cl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *svm_ptr, cl_uint num_events_in_wait_list,
224 const cl_event *event_wait_list, cl_event *event)
225{
226 arm_compute::CLSymbols::get().load_default();
227 auto func = arm_compute::CLSymbols::get().clEnqueueSVMUnmap_ptr;
228 if(func != nullptr)
229 {
230 return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
231 }
232 else
233 {
234 return CL_OUT_OF_RESOURCES;
235 }
236}
237
238void *clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
239{
240 arm_compute::CLSymbols::get().load_default();
241 auto func = arm_compute::CLSymbols::get().clSVMAlloc_ptr;
242 if(func != nullptr)
243 {
244 return func(context, flags, size, alignment);
245 }
246 else
247 {
248 return nullptr;
249 }
250}
251
252void clSVMFree(cl_context context, void *svm_pointer)
253{
254 arm_compute::CLSymbols::get().load_default();
255 auto func = arm_compute::CLSymbols::get().clSVMFree_ptr;
256 if(func != nullptr)
257 {
258 func(context, svm_pointer);
259 }
260}
261
Anthony Barbiera9e15332017-12-22 16:37:30 +0000262cl_int clGetContextInfo(cl_context context,
263 cl_context_info param_name,
264 size_t param_value_size,
265 void *param_value,
266 size_t *param_value_size_ret)
267{
268 arm_compute::CLSymbols::get().load_default();
269 auto func = arm_compute::CLSymbols::get().clGetContextInfo_ptr;
270 if(func != nullptr)
271 {
272 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
273 }
274 else
275 {
276 return CL_OUT_OF_RESOURCES;
277 }
278}
279
280cl_command_queue clCreateCommandQueue(cl_context context,
281 cl_device_id device,
282 cl_command_queue_properties properties,
283 cl_int *errcode_ret)
284{
285 arm_compute::CLSymbols::get().load_default();
286 auto func = arm_compute::CLSymbols::get().clCreateCommandQueue_ptr;
287 if(func != nullptr)
288 {
289 return func(context, device, properties, errcode_ret);
290 }
291 else
292 {
293 return nullptr;
294 }
295}
296
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000297cl_command_queue clCreateCommandQueueWithProperties(cl_context context,
298 cl_device_id device,
299 const cl_queue_properties *properties,
300 cl_int *errcode_ret)
301{
302 arm_compute::CLSymbols::get().load_default();
303 auto func = arm_compute::CLSymbols::get().clCreateCommandQueueWithProperties_ptr;
304 if(func != nullptr)
305 {
306 return func(context, device, properties, errcode_ret);
307 }
308 else
309 {
310 return nullptr;
311 }
312}
313
Anthony Barbierb6eb3532018-08-08 13:20:04 +0100314cl_context clCreateContext(
315 const cl_context_properties *properties,
316 cl_uint num_devices,
317 const cl_device_id *devices,
318 void (*pfn_notify)(const char *, const void *, size_t, void *),
319 void *user_data,
320 cl_int *errcode_ret)
321{
322 arm_compute::CLSymbols::get().load_default();
323 auto func = arm_compute::CLSymbols::get().clCreateContext_ptr;
324 if(func != nullptr)
325 {
326 return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
327 }
328 else
329 {
330 return nullptr;
331 }
332}
333
Anthony Barbiera9e15332017-12-22 16:37:30 +0000334cl_context clCreateContextFromType(const cl_context_properties *properties,
335 cl_device_type device_type,
336 void (*pfn_notify)(const char *, const void *, size_t, void *),
337 void *user_data,
338 cl_int *errcode_ret)
339{
340 arm_compute::CLSymbols::get().load_default();
341 auto func = arm_compute::CLSymbols::get().clCreateContextFromType_ptr;
342 if(func != nullptr)
343 {
344 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
345 }
346 else
347 {
348 return nullptr;
349 }
350}
351
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100352cl_int clBuildProgram(
353 cl_program program,
354 cl_uint num_devices,
355 const cl_device_id *device_list,
356 const char *options,
357 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
358 void *user_data)
359{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100360 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000361 auto func = arm_compute::CLSymbols::get().clBuildProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100362 if(func != nullptr)
363 {
364 return func(program, num_devices, device_list, options, pfn_notify, user_data);
365 }
366 else
367 {
368 return CL_OUT_OF_RESOURCES;
369 }
370}
371
372cl_int clEnqueueNDRangeKernel(
373 cl_command_queue command_queue,
374 cl_kernel kernel,
375 cl_uint work_dim,
376 const size_t *global_work_offset,
377 const size_t *global_work_size,
378 const size_t *local_work_size,
379 cl_uint num_events_in_wait_list,
380 const cl_event *event_wait_list,
381 cl_event *event)
382{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100383 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000384 auto func = arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100385 if(func != nullptr)
386 {
387 return func(command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size, num_events_in_wait_list, event_wait_list, event);
388 }
389 else
390 {
391 return CL_OUT_OF_RESOURCES;
392 }
393}
394
395cl_int clSetKernelArg(
396 cl_kernel kernel,
397 cl_uint arg_index,
398 size_t arg_size,
399 const void *arg_value)
400{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100401 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000402 auto func = arm_compute::CLSymbols::get().clSetKernelArg_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100403 if(func != nullptr)
404 {
405 return func(kernel, arg_index, arg_size, arg_value);
406 }
407 else
408 {
409 return CL_OUT_OF_RESOURCES;
410 }
411}
412
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100413cl_int clRetainMemObject(cl_mem memobj)
414{
415 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000416 auto func = arm_compute::CLSymbols::get().clRetainMemObject_ptr;
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100417 if(func != nullptr)
418 {
419 return func(memobj);
420 }
421 else
422 {
423 return CL_OUT_OF_RESOURCES;
424 }
425}
426
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100427cl_int clReleaseMemObject(cl_mem memobj)
428{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100429 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000430 auto func = arm_compute::CLSymbols::get().clReleaseMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100431 if(func != nullptr)
432 {
433 return func(memobj);
434 }
435 else
436 {
437 return CL_OUT_OF_RESOURCES;
438 }
439}
440
441cl_int clEnqueueUnmapMemObject(
442 cl_command_queue command_queue,
443 cl_mem memobj,
444 void *mapped_ptr,
445 cl_uint num_events_in_wait_list,
446 const cl_event *event_wait_list,
447 cl_event *event)
448{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100449 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000450 auto func = arm_compute::CLSymbols::get().clEnqueueUnmapMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100451 if(func != nullptr)
452 {
453 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
454 }
455 else
456 {
457 return CL_OUT_OF_RESOURCES;
458 }
459}
460
461cl_int clRetainCommandQueue(cl_command_queue command_queue)
462{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100463 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000464 auto func = arm_compute::CLSymbols::get().clRetainCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100465 if(func != nullptr)
466 {
467 return func(command_queue);
468 }
469 else
470 {
471 return CL_OUT_OF_RESOURCES;
472 }
473}
474
475cl_int clReleaseContext(cl_context context)
476{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100477 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000478 auto func = arm_compute::CLSymbols::get().clReleaseContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100479 if(func != nullptr)
480 {
481 return func(context);
482 }
483 else
484 {
485 return CL_OUT_OF_RESOURCES;
486 }
487}
488cl_int clReleaseEvent(cl_event event)
489{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100490 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000491 auto func = arm_compute::CLSymbols::get().clReleaseEvent_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100492 if(func != nullptr)
493 {
494 return func(event);
495 }
496 else
497 {
498 return CL_OUT_OF_RESOURCES;
499 }
500}
501
502cl_int clEnqueueWriteBuffer(
503 cl_command_queue command_queue,
504 cl_mem buffer,
505 cl_bool blocking_write,
506 size_t offset,
507 size_t size,
508 const void *ptr,
509 cl_uint num_events_in_wait_list,
510 const cl_event *event_wait_list,
511 cl_event *event)
512{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100513 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000514 auto func = arm_compute::CLSymbols::get().clEnqueueWriteBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100515 if(func != nullptr)
516 {
517 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
518 }
519 else
520 {
521 return CL_OUT_OF_RESOURCES;
522 }
523}
524
525cl_int clEnqueueReadBuffer(
526 cl_command_queue command_queue,
527 cl_mem buffer,
528 cl_bool blocking_read,
529 size_t offset,
530 size_t size,
531 void *ptr,
532 cl_uint num_events_in_wait_list,
533 const cl_event *event_wait_list,
534 cl_event *event)
535{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100536 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000537 auto func = arm_compute::CLSymbols::get().clEnqueueReadBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100538 if(func != nullptr)
539 {
540 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
541 }
542 else
543 {
544 return CL_OUT_OF_RESOURCES;
545 }
546}
547
548cl_int clGetProgramBuildInfo(
549 cl_program program,
550 cl_device_id device,
551 cl_program_build_info param_name,
552 size_t param_value_size,
553 void *param_value,
554 size_t *param_value_size_ret)
555{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100556 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000557 auto func = arm_compute::CLSymbols::get().clGetProgramBuildInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100558 if(func != nullptr)
559 {
560 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
561 }
562 else
563 {
564 return CL_OUT_OF_RESOURCES;
565 }
566}
567
568cl_int clRetainProgram(cl_program program)
569{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100570 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000571 auto func = arm_compute::CLSymbols::get().clRetainProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100572 if(func != nullptr)
573 {
574 return func(program);
575 }
576 else
577 {
578 return CL_OUT_OF_RESOURCES;
579 }
580}
581
582void *clEnqueueMapBuffer(
583 cl_command_queue command_queue,
584 cl_mem buffer,
585 cl_bool blocking_map,
586 cl_map_flags map_flags,
587 size_t offset,
588 size_t size,
589 cl_uint num_events_in_wait_list,
590 const cl_event *event_wait_list,
591 cl_event *event,
592 cl_int *errcode_ret)
593{
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().clEnqueueMapBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100596 if(func != nullptr)
597 {
598 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
599 }
600 else
601 {
602 if(errcode_ret != nullptr)
603 {
604 *errcode_ret = CL_OUT_OF_RESOURCES;
605 }
606 return nullptr;
607 }
608}
609
610cl_int clReleaseCommandQueue(cl_command_queue command_queue)
611{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100612 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000613 auto func = arm_compute::CLSymbols::get().clReleaseCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100614 if(func != nullptr)
615 {
616 return func(command_queue);
617 }
618 else
619 {
620 return CL_OUT_OF_RESOURCES;
621 }
622}
623
624cl_program clCreateProgramWithBinary(
625 cl_context context,
626 cl_uint num_devices,
627 const cl_device_id *device_list,
628 const size_t *lengths,
629 const unsigned char **binaries,
630 cl_int *binary_status,
631 cl_int *errcode_ret)
632{
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().clCreateProgramWithBinary_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100635 if(func != nullptr)
636 {
637 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
638 }
639 else
640 {
641 if(errcode_ret != nullptr)
642 {
643 *errcode_ret = CL_OUT_OF_RESOURCES;
644 }
645 return nullptr;
646 }
647}
648
649cl_int clRetainContext(cl_context context)
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().clRetainContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100653 if(func != nullptr)
654 {
655 return func(context);
656 }
657 else
658 {
659 return CL_OUT_OF_RESOURCES;
660 }
661}
662
663cl_int clReleaseProgram(cl_program program)
664{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100665 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000666 auto func = arm_compute::CLSymbols::get().clReleaseProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100667 if(func != nullptr)
668 {
669 return func(program);
670 }
671 else
672 {
673 return CL_OUT_OF_RESOURCES;
674 }
675}
676
677cl_int clFlush(cl_command_queue command_queue)
678{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100679 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000680 auto func = arm_compute::CLSymbols::get().clFlush_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100681 if(func != nullptr)
682 {
683 return func(command_queue);
684 }
685 else
686 {
687 return CL_OUT_OF_RESOURCES;
688 }
689}
690
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100691cl_int clFinish(cl_command_queue command_queue)
692{
693 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000694 auto func = arm_compute::CLSymbols::get().clFinish_ptr;
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100695 if(func != nullptr)
696 {
697 return func(command_queue);
698 }
699 else
700 {
701 return CL_OUT_OF_RESOURCES;
702 }
703}
704
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100705cl_int clGetProgramInfo(
706 cl_program program,
707 cl_program_info param_name,
708 size_t param_value_size,
709 void *param_value,
710 size_t *param_value_size_ret)
711{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100712 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000713 auto func = arm_compute::CLSymbols::get().clGetProgramInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100714 if(func != nullptr)
715 {
716 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
717 }
718 else
719 {
720 return CL_OUT_OF_RESOURCES;
721 }
722}
723
724cl_kernel clCreateKernel(
725 cl_program program,
726 const char *kernel_name,
727 cl_int *errcode_ret)
728{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100729 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000730 auto func = arm_compute::CLSymbols::get().clCreateKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100731 if(func != nullptr)
732 {
733 return func(program, kernel_name, errcode_ret);
734 }
735 else
736 {
737 if(errcode_ret != nullptr)
738 {
739 *errcode_ret = CL_OUT_OF_RESOURCES;
740 }
741 return nullptr;
742 }
743}
744
745cl_int clRetainKernel(cl_kernel kernel)
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().clRetainKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100749 if(func != nullptr)
750 {
751 return func(kernel);
752 }
753 else
754 {
755 return CL_OUT_OF_RESOURCES;
756 }
757}
758
759cl_mem clCreateBuffer(
760 cl_context context,
761 cl_mem_flags flags,
762 size_t size,
763 void *host_ptr,
764 cl_int *errcode_ret)
765{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100766 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000767 auto func = arm_compute::CLSymbols::get().clCreateBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100768 if(func != nullptr)
769 {
770 return func(context, flags, size, host_ptr, errcode_ret);
771 }
772 else
773 {
774 if(errcode_ret != nullptr)
775 {
776 *errcode_ret = CL_OUT_OF_RESOURCES;
777 }
778 return nullptr;
779 }
780}
781
782cl_program clCreateProgramWithSource(
783 cl_context context,
784 cl_uint count,
785 const char **strings,
786 const size_t *lengths,
787 cl_int *errcode_ret)
788{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100789 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000790 auto func = arm_compute::CLSymbols::get().clCreateProgramWithSource_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100791 if(func != nullptr)
792 {
793 return func(context, count, strings, lengths, errcode_ret);
794 }
795 else
796 {
797 if(errcode_ret != nullptr)
798 {
799 *errcode_ret = CL_OUT_OF_RESOURCES;
800 }
801 return nullptr;
802 }
803}
804
805cl_int clReleaseKernel(cl_kernel kernel)
806{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100807 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000808 auto func = arm_compute::CLSymbols::get().clReleaseKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100809 if(func != nullptr)
810 {
811 return func(kernel);
812 }
813 else
814 {
815 return CL_OUT_OF_RESOURCES;
816 }
817}
818
819cl_int clGetDeviceIDs(cl_platform_id platform,
820 cl_device_type device_type,
821 cl_uint num_entries,
822 cl_device_id *devices,
823 cl_uint *num_devices)
824{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100825 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000826 auto func = arm_compute::CLSymbols::get().clGetDeviceIDs_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100827 if(func != nullptr)
828 {
829 return func(platform, device_type, num_entries, devices, num_devices);
830 }
831 else
832 {
833 return CL_OUT_OF_RESOURCES;
834 }
835}
836
837cl_int clGetDeviceInfo(cl_device_id device,
838 cl_device_info param_name,
839 size_t param_value_size,
840 void *param_value,
841 size_t *param_value_size_ret)
842{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100843 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000844 auto func = arm_compute::CLSymbols::get().clGetDeviceInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100845 if(func != nullptr)
846 {
847 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
848 }
849 else
850 {
851 return CL_OUT_OF_RESOURCES;
852 }
853}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100854
Georgios Pinitasdf310362018-11-14 13:16:56 +0000855cl_int clGetMemObjectInfo(cl_mem memobj,
856 cl_mem_info param_name,
857 size_t param_value_size,
858 void *param_value,
859 size_t *param_value_size_ret)
860{
861 arm_compute::CLSymbols::get().load_default();
862 auto func = arm_compute::CLSymbols::get().clGetMemObjectInfo_ptr;
863 if(func != nullptr)
864 {
865 return func(memobj, param_name, param_value_size, param_value, param_value_size_ret);
866 }
867 else
868 {
869 return CL_OUT_OF_RESOURCES;
870 }
871}
872
Giorgio Arena9fe41442017-08-23 16:36:24 +0100873cl_int clRetainEvent(cl_event event)
874{
Moritz Pflanzer159b6da2017-09-20 16:03:35 +0100875 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000876 auto func = arm_compute::CLSymbols::get().clRetainEvent_ptr;
Giorgio Arena9fe41442017-08-23 16:36:24 +0100877 if(func != nullptr)
878 {
879 return func(event);
880 }
881 else
882 {
883 return CL_OUT_OF_RESOURCES;
884 }
885}
steniu01f01f9de2017-09-27 17:00:11 +0100886
Michalis Spyrou402740d2021-04-20 11:26:21 +0100887cl_int clGetPlatformInfo(cl_platform_id platform,
888 cl_platform_info param_name,
889 size_t param_value_size,
890 void *param_value,
891 size_t *param_value_size_ret)
892{
893 arm_compute::CLSymbols::get().load_default();
894 auto func = arm_compute::CLSymbols::get().clGetPlatformInfo_ptr;
895 if(func != nullptr)
896 {
897 return func(platform, param_name, param_value_size, param_value, param_value_size_ret);
898 }
899 else
900 {
901 return CL_OUT_OF_RESOURCES;
902 }
903}
904
steniu01f01f9de2017-09-27 17:00:11 +0100905cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
906{
907 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000908 auto func = arm_compute::CLSymbols::get().clGetPlatformIDs_ptr;
steniu01f01f9de2017-09-27 17:00:11 +0100909 if(func != nullptr)
910 {
911 return func(num_entries, platforms, num_platforms);
912 }
913 else
914 {
915 return CL_OUT_OF_RESOURCES;
916 }
917}
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100918
919cl_int
920clGetKernelWorkGroupInfo(cl_kernel kernel,
921 cl_device_id device,
922 cl_kernel_work_group_info param_name,
923 size_t param_value_size,
924 void *param_value,
925 size_t *param_value_size_ret)
926{
927 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000928 auto func = arm_compute::CLSymbols::get().clGetKernelWorkGroupInfo_ptr;
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100929 if(func != nullptr)
930 {
931 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
932 }
933 else
934 {
935 return CL_OUT_OF_RESOURCES;
936 }
937}
Gian Marco85e6f512018-02-01 16:57:48 +0000938
939cl_int
940clGetCommandQueueInfo(cl_command_queue command_queue,
941 cl_command_queue_info param_name,
942 size_t param_value_size,
943 void *param_value,
944 size_t *param_value_size_ret)
945{
946 arm_compute::CLSymbols::get().load_default();
947 auto func = arm_compute::CLSymbols::get().clGetCommandQueueInfo_ptr;
948 if(func != nullptr)
949 {
950 return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
951 }
952 else
953 {
954 return CL_OUT_OF_RESOURCES;
955 }
956}
957
958cl_int
959clGetKernelInfo(cl_kernel kernel,
960 cl_kernel_info param_name,
961 size_t param_value_size,
962 void *param_value,
963 size_t *param_value_size_ret)
964{
965 arm_compute::CLSymbols::get().load_default();
966 auto func = arm_compute::CLSymbols::get().clGetKernelInfo_ptr;
967 if(func != nullptr)
968 {
969 return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
970 }
971 else
972 {
973 return CL_OUT_OF_RESOURCES;
974 }
975}
976
977cl_int
978clGetEventProfilingInfo(cl_event event,
979 cl_profiling_info param_name,
980 size_t param_value_size,
981 void *param_value,
982 size_t *param_value_size_ret)
983{
984 arm_compute::CLSymbols::get().load_default();
985 auto func = arm_compute::CLSymbols::get().clGetEventProfilingInfo_ptr;
986 if(func != nullptr)
987 {
988 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
989 }
990 else
991 {
992 return CL_OUT_OF_RESOURCES;
993 }
Anthony Barbierf5dcf792018-02-28 18:04:45 +0000994}
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100995
996cl_mem
Gian Marco Iodicea98dee22020-06-02 12:12:35 +0100997clCreateImage(cl_context context,
998 cl_mem_flags flags,
999 const cl_image_format *image_format,
1000 const cl_image_desc *image_desc,
1001 void *host_ptr,
1002 cl_int *errcode_ret)
1003{
1004 arm_compute::CLSymbols::get().load_default();
1005 auto func = arm_compute::CLSymbols::get().clCreateImage_ptr;
1006 if(func != nullptr)
1007 {
1008 return func(context, flags, image_format, image_desc, host_ptr, errcode_ret);
1009 }
1010 else
1011 {
1012 if(errcode_ret != nullptr)
1013 {
1014 *errcode_ret = CL_OUT_OF_RESOURCES;
1015 }
1016 return nullptr;
1017 }
1018}
1019
Manuel Bottinibe9f9f92021-01-25 15:07:17 +00001020cl_int clSetKernelExecInfo(cl_kernel kernel,
1021 cl_kernel_exec_info param_name,
1022 size_t param_value_size,
1023 const void *param_value)
1024{
1025 arm_compute::CLSymbols::get().load_default();
1026 auto func = arm_compute::CLSymbols::get().clSetKernelExecInfo_ptr;
1027 if(func != nullptr)
1028 {
1029 return func(kernel, param_name, param_value_size, param_value);
1030 }
1031 else
1032 {
1033 return CL_OUT_OF_RESOURCES;
1034 }
1035}
1036
Gian Marco Iodicea98dee22020-06-02 12:12:35 +01001037cl_mem
Georgios Pinitas4d0351c2019-04-03 15:11:16 +01001038clImportMemoryARM(cl_context context,
1039 cl_mem_flags flags,
1040 const cl_import_properties_arm *properties,
1041 void *memory,
1042 size_t size,
1043 cl_int *errcode_ret)
1044{
1045 arm_compute::CLSymbols::get().load_default();
1046 auto func = arm_compute::CLSymbols::get().clImportMemoryARM_ptr;
1047 if(func != nullptr)
1048 {
1049 return func(context, flags, properties, memory, size, errcode_ret);
1050 }
1051 else
1052 {
1053 if(errcode_ret != nullptr)
1054 {
1055 *errcode_ret = CL_OUT_OF_RESOURCES;
1056 }
1057 return nullptr;
1058 }
Pablo Tellodb8485a2019-09-24 11:03:47 +01001059}