blob: aff6285697d6c8073192c202a275667eb999d89c [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
41})
42{
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 Pinitas0ec65b82019-07-11 13:12:46 +000078 void *handle = dlopen(library.c_str(), RTLD_LAZY | RTLD_LOCAL);
Moritz Pflanzer725788e2017-07-07 15:35:56 +010079
80 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
Anthony Barbierb6eb3532018-08-08 13:20:04 +010091 LOAD_FUNCTION_PTR(clCreateContext, handle);
Anthony Barbiera9e15332017-12-22 16:37:30 +000092 LOAD_FUNCTION_PTR(clCreateContextFromType, handle);
93 LOAD_FUNCTION_PTR(clCreateCommandQueue, handle);
94 LOAD_FUNCTION_PTR(clGetContextInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +000095 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);
Georgios Pinitasdf310362018-11-14 13:16:56 +0000123 LOAD_FUNCTION_PTR(clGetMemObjectInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000124 LOAD_FUNCTION_PTR(clRetainEvent, handle);
125 LOAD_FUNCTION_PTR(clGetPlatformIDs, handle);
126 LOAD_FUNCTION_PTR(clGetKernelWorkGroupInfo, handle);
Gian Marco85e6f512018-02-01 16:57:48 +0000127 LOAD_FUNCTION_PTR(clGetCommandQueueInfo, handle);
128 LOAD_FUNCTION_PTR(clGetKernelInfo, handle);
129 LOAD_FUNCTION_PTR(clGetEventProfilingInfo, handle);
Pablo Telloe86a09f2018-01-11 15:44:48 +0000130 LOAD_FUNCTION_PTR(clSVMAlloc, handle);
131 LOAD_FUNCTION_PTR(clSVMFree, handle);
132 LOAD_FUNCTION_PTR(clEnqueueSVMMap, handle);
133 LOAD_FUNCTION_PTR(clEnqueueSVMUnmap, handle);
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100134 LOAD_FUNCTION_PTR(clEnqueueMarker, handle);
135 LOAD_FUNCTION_PTR(clWaitForEvents, handle);
Gian Marco Iodicea98dee22020-06-02 12:12:35 +0100136 LOAD_FUNCTION_PTR(clCreateImage, handle);
Manuel Bottinibe9f9f92021-01-25 15:07:17 +0000137 LOAD_FUNCTION_PTR(clSetKernelExecInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000138
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100139 // Third-party extensions
140 LOAD_FUNCTION_PTR(clImportMemoryARM, handle);
141
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000142#undef LOAD_FUNCTION_PTR
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100143
Anthony Barbier7b43d312017-12-14 10:58:47 +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();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000155 return CLSymbols::get().clBuildProgram_ptr != nullptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100156}
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100157} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100158
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100159cl_int clEnqueueMarker(cl_command_queue command_queue,
160 cl_event *event)
161{
162 arm_compute::CLSymbols::get().load_default();
163 auto func = arm_compute::CLSymbols::get().clEnqueueMarker_ptr;
164 if(func != nullptr)
165 {
166 return func(command_queue, event);
167 }
168 else
169 {
170 return CL_OUT_OF_RESOURCES;
171 }
172}
173
174cl_int clWaitForEvents(cl_uint num_events,
175 const cl_event *event_list)
176{
177 arm_compute::CLSymbols::get().load_default();
178 auto func = arm_compute::CLSymbols::get().clWaitForEvents_ptr;
179 if(func != nullptr)
180 {
181 return func(num_events, event_list);
182 }
183 else
184 {
185 return CL_OUT_OF_RESOURCES;
186 }
187}
188
Pablo Telloe86a09f2018-01-11 15:44:48 +0000189cl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags flags, void *svm_ptr,
190 size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
191{
192 arm_compute::CLSymbols::get().load_default();
193 auto func = arm_compute::CLSymbols::get().clEnqueueSVMMap_ptr;
194 if(func != nullptr)
195 {
196 return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
197 }
198 else
199 {
200 return CL_OUT_OF_RESOURCES;
201 }
202}
203
204cl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *svm_ptr, cl_uint num_events_in_wait_list,
205 const cl_event *event_wait_list, cl_event *event)
206{
207 arm_compute::CLSymbols::get().load_default();
208 auto func = arm_compute::CLSymbols::get().clEnqueueSVMUnmap_ptr;
209 if(func != nullptr)
210 {
211 return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
212 }
213 else
214 {
215 return CL_OUT_OF_RESOURCES;
216 }
217}
218
219void *clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
220{
221 arm_compute::CLSymbols::get().load_default();
222 auto func = arm_compute::CLSymbols::get().clSVMAlloc_ptr;
223 if(func != nullptr)
224 {
225 return func(context, flags, size, alignment);
226 }
227 else
228 {
229 return nullptr;
230 }
231}
232
233void clSVMFree(cl_context context, void *svm_pointer)
234{
235 arm_compute::CLSymbols::get().load_default();
236 auto func = arm_compute::CLSymbols::get().clSVMFree_ptr;
237 if(func != nullptr)
238 {
239 func(context, svm_pointer);
240 }
241}
242
Anthony Barbiera9e15332017-12-22 16:37:30 +0000243cl_int clGetContextInfo(cl_context context,
244 cl_context_info param_name,
245 size_t param_value_size,
246 void *param_value,
247 size_t *param_value_size_ret)
248{
249 arm_compute::CLSymbols::get().load_default();
250 auto func = arm_compute::CLSymbols::get().clGetContextInfo_ptr;
251 if(func != nullptr)
252 {
253 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
254 }
255 else
256 {
257 return CL_OUT_OF_RESOURCES;
258 }
259}
260
261cl_command_queue clCreateCommandQueue(cl_context context,
262 cl_device_id device,
263 cl_command_queue_properties properties,
264 cl_int *errcode_ret)
265{
266 arm_compute::CLSymbols::get().load_default();
267 auto func = arm_compute::CLSymbols::get().clCreateCommandQueue_ptr;
268 if(func != nullptr)
269 {
270 return func(context, device, properties, errcode_ret);
271 }
272 else
273 {
274 return nullptr;
275 }
276}
277
Anthony Barbierb6eb3532018-08-08 13:20:04 +0100278cl_context clCreateContext(
279 const cl_context_properties *properties,
280 cl_uint num_devices,
281 const cl_device_id *devices,
282 void (*pfn_notify)(const char *, const void *, size_t, void *),
283 void *user_data,
284 cl_int *errcode_ret)
285{
286 arm_compute::CLSymbols::get().load_default();
287 auto func = arm_compute::CLSymbols::get().clCreateContext_ptr;
288 if(func != nullptr)
289 {
290 return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
291 }
292 else
293 {
294 return nullptr;
295 }
296}
297
Anthony Barbiera9e15332017-12-22 16:37:30 +0000298cl_context clCreateContextFromType(const cl_context_properties *properties,
299 cl_device_type device_type,
300 void (*pfn_notify)(const char *, const void *, size_t, void *),
301 void *user_data,
302 cl_int *errcode_ret)
303{
304 arm_compute::CLSymbols::get().load_default();
305 auto func = arm_compute::CLSymbols::get().clCreateContextFromType_ptr;
306 if(func != nullptr)
307 {
308 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
309 }
310 else
311 {
312 return nullptr;
313 }
314}
315
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100316cl_int clBuildProgram(
317 cl_program program,
318 cl_uint num_devices,
319 const cl_device_id *device_list,
320 const char *options,
321 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
322 void *user_data)
323{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100324 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000325 auto func = arm_compute::CLSymbols::get().clBuildProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100326 if(func != nullptr)
327 {
328 return func(program, num_devices, device_list, options, pfn_notify, user_data);
329 }
330 else
331 {
332 return CL_OUT_OF_RESOURCES;
333 }
334}
335
336cl_int clEnqueueNDRangeKernel(
337 cl_command_queue command_queue,
338 cl_kernel kernel,
339 cl_uint work_dim,
340 const size_t *global_work_offset,
341 const size_t *global_work_size,
342 const size_t *local_work_size,
343 cl_uint num_events_in_wait_list,
344 const cl_event *event_wait_list,
345 cl_event *event)
346{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100347 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000348 auto func = arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100349 if(func != nullptr)
350 {
351 return func(command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size, num_events_in_wait_list, event_wait_list, event);
352 }
353 else
354 {
355 return CL_OUT_OF_RESOURCES;
356 }
357}
358
359cl_int clSetKernelArg(
360 cl_kernel kernel,
361 cl_uint arg_index,
362 size_t arg_size,
363 const void *arg_value)
364{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100365 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000366 auto func = arm_compute::CLSymbols::get().clSetKernelArg_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100367 if(func != nullptr)
368 {
369 return func(kernel, arg_index, arg_size, arg_value);
370 }
371 else
372 {
373 return CL_OUT_OF_RESOURCES;
374 }
375}
376
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100377cl_int clRetainMemObject(cl_mem memobj)
378{
379 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000380 auto func = arm_compute::CLSymbols::get().clRetainMemObject_ptr;
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100381 if(func != nullptr)
382 {
383 return func(memobj);
384 }
385 else
386 {
387 return CL_OUT_OF_RESOURCES;
388 }
389}
390
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100391cl_int clReleaseMemObject(cl_mem memobj)
392{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100393 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000394 auto func = arm_compute::CLSymbols::get().clReleaseMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100395 if(func != nullptr)
396 {
397 return func(memobj);
398 }
399 else
400 {
401 return CL_OUT_OF_RESOURCES;
402 }
403}
404
405cl_int clEnqueueUnmapMemObject(
406 cl_command_queue command_queue,
407 cl_mem memobj,
408 void *mapped_ptr,
409 cl_uint num_events_in_wait_list,
410 const cl_event *event_wait_list,
411 cl_event *event)
412{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100413 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000414 auto func = arm_compute::CLSymbols::get().clEnqueueUnmapMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100415 if(func != nullptr)
416 {
417 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
418 }
419 else
420 {
421 return CL_OUT_OF_RESOURCES;
422 }
423}
424
425cl_int clRetainCommandQueue(cl_command_queue command_queue)
426{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100427 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000428 auto func = arm_compute::CLSymbols::get().clRetainCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100429 if(func != nullptr)
430 {
431 return func(command_queue);
432 }
433 else
434 {
435 return CL_OUT_OF_RESOURCES;
436 }
437}
438
439cl_int clReleaseContext(cl_context context)
440{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100441 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000442 auto func = arm_compute::CLSymbols::get().clReleaseContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100443 if(func != nullptr)
444 {
445 return func(context);
446 }
447 else
448 {
449 return CL_OUT_OF_RESOURCES;
450 }
451}
452cl_int clReleaseEvent(cl_event event)
453{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100454 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000455 auto func = arm_compute::CLSymbols::get().clReleaseEvent_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100456 if(func != nullptr)
457 {
458 return func(event);
459 }
460 else
461 {
462 return CL_OUT_OF_RESOURCES;
463 }
464}
465
466cl_int clEnqueueWriteBuffer(
467 cl_command_queue command_queue,
468 cl_mem buffer,
469 cl_bool blocking_write,
470 size_t offset,
471 size_t size,
472 const void *ptr,
473 cl_uint num_events_in_wait_list,
474 const cl_event *event_wait_list,
475 cl_event *event)
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().clEnqueueWriteBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100479 if(func != nullptr)
480 {
481 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
482 }
483 else
484 {
485 return CL_OUT_OF_RESOURCES;
486 }
487}
488
489cl_int clEnqueueReadBuffer(
490 cl_command_queue command_queue,
491 cl_mem buffer,
492 cl_bool blocking_read,
493 size_t offset,
494 size_t size,
495 void *ptr,
496 cl_uint num_events_in_wait_list,
497 const cl_event *event_wait_list,
498 cl_event *event)
499{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100500 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000501 auto func = arm_compute::CLSymbols::get().clEnqueueReadBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100502 if(func != nullptr)
503 {
504 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
505 }
506 else
507 {
508 return CL_OUT_OF_RESOURCES;
509 }
510}
511
512cl_int clGetProgramBuildInfo(
513 cl_program program,
514 cl_device_id device,
515 cl_program_build_info param_name,
516 size_t param_value_size,
517 void *param_value,
518 size_t *param_value_size_ret)
519{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100520 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000521 auto func = arm_compute::CLSymbols::get().clGetProgramBuildInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100522 if(func != nullptr)
523 {
524 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
525 }
526 else
527 {
528 return CL_OUT_OF_RESOURCES;
529 }
530}
531
532cl_int clRetainProgram(cl_program program)
533{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100534 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000535 auto func = arm_compute::CLSymbols::get().clRetainProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100536 if(func != nullptr)
537 {
538 return func(program);
539 }
540 else
541 {
542 return CL_OUT_OF_RESOURCES;
543 }
544}
545
546void *clEnqueueMapBuffer(
547 cl_command_queue command_queue,
548 cl_mem buffer,
549 cl_bool blocking_map,
550 cl_map_flags map_flags,
551 size_t offset,
552 size_t size,
553 cl_uint num_events_in_wait_list,
554 const cl_event *event_wait_list,
555 cl_event *event,
556 cl_int *errcode_ret)
557{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100558 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000559 auto func = arm_compute::CLSymbols::get().clEnqueueMapBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100560 if(func != nullptr)
561 {
562 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
563 }
564 else
565 {
566 if(errcode_ret != nullptr)
567 {
568 *errcode_ret = CL_OUT_OF_RESOURCES;
569 }
570 return nullptr;
571 }
572}
573
574cl_int clReleaseCommandQueue(cl_command_queue command_queue)
575{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100576 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000577 auto func = arm_compute::CLSymbols::get().clReleaseCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100578 if(func != nullptr)
579 {
580 return func(command_queue);
581 }
582 else
583 {
584 return CL_OUT_OF_RESOURCES;
585 }
586}
587
588cl_program clCreateProgramWithBinary(
589 cl_context context,
590 cl_uint num_devices,
591 const cl_device_id *device_list,
592 const size_t *lengths,
593 const unsigned char **binaries,
594 cl_int *binary_status,
595 cl_int *errcode_ret)
596{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100597 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000598 auto func = arm_compute::CLSymbols::get().clCreateProgramWithBinary_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100599 if(func != nullptr)
600 {
601 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
602 }
603 else
604 {
605 if(errcode_ret != nullptr)
606 {
607 *errcode_ret = CL_OUT_OF_RESOURCES;
608 }
609 return nullptr;
610 }
611}
612
613cl_int clRetainContext(cl_context context)
614{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100615 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000616 auto func = arm_compute::CLSymbols::get().clRetainContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100617 if(func != nullptr)
618 {
619 return func(context);
620 }
621 else
622 {
623 return CL_OUT_OF_RESOURCES;
624 }
625}
626
627cl_int clReleaseProgram(cl_program program)
628{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100629 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000630 auto func = arm_compute::CLSymbols::get().clReleaseProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100631 if(func != nullptr)
632 {
633 return func(program);
634 }
635 else
636 {
637 return CL_OUT_OF_RESOURCES;
638 }
639}
640
641cl_int clFlush(cl_command_queue command_queue)
642{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100643 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000644 auto func = arm_compute::CLSymbols::get().clFlush_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100645 if(func != nullptr)
646 {
647 return func(command_queue);
648 }
649 else
650 {
651 return CL_OUT_OF_RESOURCES;
652 }
653}
654
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100655cl_int clFinish(cl_command_queue command_queue)
656{
657 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000658 auto func = arm_compute::CLSymbols::get().clFinish_ptr;
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100659 if(func != nullptr)
660 {
661 return func(command_queue);
662 }
663 else
664 {
665 return CL_OUT_OF_RESOURCES;
666 }
667}
668
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100669cl_int clGetProgramInfo(
670 cl_program program,
671 cl_program_info param_name,
672 size_t param_value_size,
673 void *param_value,
674 size_t *param_value_size_ret)
675{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100676 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000677 auto func = arm_compute::CLSymbols::get().clGetProgramInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100678 if(func != nullptr)
679 {
680 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
681 }
682 else
683 {
684 return CL_OUT_OF_RESOURCES;
685 }
686}
687
688cl_kernel clCreateKernel(
689 cl_program program,
690 const char *kernel_name,
691 cl_int *errcode_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().clCreateKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100695 if(func != nullptr)
696 {
697 return func(program, kernel_name, errcode_ret);
698 }
699 else
700 {
701 if(errcode_ret != nullptr)
702 {
703 *errcode_ret = CL_OUT_OF_RESOURCES;
704 }
705 return nullptr;
706 }
707}
708
709cl_int clRetainKernel(cl_kernel kernel)
710{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100711 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000712 auto func = arm_compute::CLSymbols::get().clRetainKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100713 if(func != nullptr)
714 {
715 return func(kernel);
716 }
717 else
718 {
719 return CL_OUT_OF_RESOURCES;
720 }
721}
722
723cl_mem clCreateBuffer(
724 cl_context context,
725 cl_mem_flags flags,
726 size_t size,
727 void *host_ptr,
728 cl_int *errcode_ret)
729{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100730 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000731 auto func = arm_compute::CLSymbols::get().clCreateBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100732 if(func != nullptr)
733 {
734 return func(context, flags, size, host_ptr, errcode_ret);
735 }
736 else
737 {
738 if(errcode_ret != nullptr)
739 {
740 *errcode_ret = CL_OUT_OF_RESOURCES;
741 }
742 return nullptr;
743 }
744}
745
746cl_program clCreateProgramWithSource(
747 cl_context context,
748 cl_uint count,
749 const char **strings,
750 const size_t *lengths,
751 cl_int *errcode_ret)
752{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100753 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000754 auto func = arm_compute::CLSymbols::get().clCreateProgramWithSource_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100755 if(func != nullptr)
756 {
757 return func(context, count, strings, lengths, errcode_ret);
758 }
759 else
760 {
761 if(errcode_ret != nullptr)
762 {
763 *errcode_ret = CL_OUT_OF_RESOURCES;
764 }
765 return nullptr;
766 }
767}
768
769cl_int clReleaseKernel(cl_kernel kernel)
770{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100771 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000772 auto func = arm_compute::CLSymbols::get().clReleaseKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100773 if(func != nullptr)
774 {
775 return func(kernel);
776 }
777 else
778 {
779 return CL_OUT_OF_RESOURCES;
780 }
781}
782
783cl_int clGetDeviceIDs(cl_platform_id platform,
784 cl_device_type device_type,
785 cl_uint num_entries,
786 cl_device_id *devices,
787 cl_uint *num_devices)
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().clGetDeviceIDs_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100791 if(func != nullptr)
792 {
793 return func(platform, device_type, num_entries, devices, num_devices);
794 }
795 else
796 {
797 return CL_OUT_OF_RESOURCES;
798 }
799}
800
801cl_int clGetDeviceInfo(cl_device_id device,
802 cl_device_info param_name,
803 size_t param_value_size,
804 void *param_value,
805 size_t *param_value_size_ret)
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().clGetDeviceInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100809 if(func != nullptr)
810 {
811 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
812 }
813 else
814 {
815 return CL_OUT_OF_RESOURCES;
816 }
817}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100818
Georgios Pinitasdf310362018-11-14 13:16:56 +0000819cl_int clGetMemObjectInfo(cl_mem memobj,
820 cl_mem_info param_name,
821 size_t param_value_size,
822 void *param_value,
823 size_t *param_value_size_ret)
824{
825 arm_compute::CLSymbols::get().load_default();
826 auto func = arm_compute::CLSymbols::get().clGetMemObjectInfo_ptr;
827 if(func != nullptr)
828 {
829 return func(memobj, param_name, param_value_size, param_value, param_value_size_ret);
830 }
831 else
832 {
833 return CL_OUT_OF_RESOURCES;
834 }
835}
836
Giorgio Arena9fe41442017-08-23 16:36:24 +0100837cl_int clRetainEvent(cl_event event)
838{
Moritz Pflanzer159b6da2017-09-20 16:03:35 +0100839 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000840 auto func = arm_compute::CLSymbols::get().clRetainEvent_ptr;
Giorgio Arena9fe41442017-08-23 16:36:24 +0100841 if(func != nullptr)
842 {
843 return func(event);
844 }
845 else
846 {
847 return CL_OUT_OF_RESOURCES;
848 }
849}
steniu01f01f9de2017-09-27 17:00:11 +0100850
851cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
852{
853 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000854 auto func = arm_compute::CLSymbols::get().clGetPlatformIDs_ptr;
steniu01f01f9de2017-09-27 17:00:11 +0100855 if(func != nullptr)
856 {
857 return func(num_entries, platforms, num_platforms);
858 }
859 else
860 {
861 return CL_OUT_OF_RESOURCES;
862 }
863}
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100864
865cl_int
866clGetKernelWorkGroupInfo(cl_kernel kernel,
867 cl_device_id device,
868 cl_kernel_work_group_info param_name,
869 size_t param_value_size,
870 void *param_value,
871 size_t *param_value_size_ret)
872{
873 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000874 auto func = arm_compute::CLSymbols::get().clGetKernelWorkGroupInfo_ptr;
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100875 if(func != nullptr)
876 {
877 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
878 }
879 else
880 {
881 return CL_OUT_OF_RESOURCES;
882 }
883}
Gian Marco85e6f512018-02-01 16:57:48 +0000884
885cl_int
886clGetCommandQueueInfo(cl_command_queue command_queue,
887 cl_command_queue_info param_name,
888 size_t param_value_size,
889 void *param_value,
890 size_t *param_value_size_ret)
891{
892 arm_compute::CLSymbols::get().load_default();
893 auto func = arm_compute::CLSymbols::get().clGetCommandQueueInfo_ptr;
894 if(func != nullptr)
895 {
896 return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
897 }
898 else
899 {
900 return CL_OUT_OF_RESOURCES;
901 }
902}
903
904cl_int
905clGetKernelInfo(cl_kernel kernel,
906 cl_kernel_info param_name,
907 size_t param_value_size,
908 void *param_value,
909 size_t *param_value_size_ret)
910{
911 arm_compute::CLSymbols::get().load_default();
912 auto func = arm_compute::CLSymbols::get().clGetKernelInfo_ptr;
913 if(func != nullptr)
914 {
915 return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
916 }
917 else
918 {
919 return CL_OUT_OF_RESOURCES;
920 }
921}
922
923cl_int
924clGetEventProfilingInfo(cl_event event,
925 cl_profiling_info param_name,
926 size_t param_value_size,
927 void *param_value,
928 size_t *param_value_size_ret)
929{
930 arm_compute::CLSymbols::get().load_default();
931 auto func = arm_compute::CLSymbols::get().clGetEventProfilingInfo_ptr;
932 if(func != nullptr)
933 {
934 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
935 }
936 else
937 {
938 return CL_OUT_OF_RESOURCES;
939 }
Anthony Barbierf5dcf792018-02-28 18:04:45 +0000940}
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100941
942cl_mem
Gian Marco Iodicea98dee22020-06-02 12:12:35 +0100943clCreateImage(cl_context context,
944 cl_mem_flags flags,
945 const cl_image_format *image_format,
946 const cl_image_desc *image_desc,
947 void *host_ptr,
948 cl_int *errcode_ret)
949{
950 arm_compute::CLSymbols::get().load_default();
951 auto func = arm_compute::CLSymbols::get().clCreateImage_ptr;
952 if(func != nullptr)
953 {
954 return func(context, flags, image_format, image_desc, host_ptr, errcode_ret);
955 }
956 else
957 {
958 if(errcode_ret != nullptr)
959 {
960 *errcode_ret = CL_OUT_OF_RESOURCES;
961 }
962 return nullptr;
963 }
964}
965
Manuel Bottinibe9f9f92021-01-25 15:07:17 +0000966cl_int clSetKernelExecInfo(cl_kernel kernel,
967 cl_kernel_exec_info param_name,
968 size_t param_value_size,
969 const void *param_value)
970{
971 arm_compute::CLSymbols::get().load_default();
972 auto func = arm_compute::CLSymbols::get().clSetKernelExecInfo_ptr;
973 if(func != nullptr)
974 {
975 return func(kernel, param_name, param_value_size, param_value);
976 }
977 else
978 {
979 return CL_OUT_OF_RESOURCES;
980 }
981}
982
Gian Marco Iodicea98dee22020-06-02 12:12:35 +0100983cl_mem
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100984clImportMemoryARM(cl_context context,
985 cl_mem_flags flags,
986 const cl_import_properties_arm *properties,
987 void *memory,
988 size_t size,
989 cl_int *errcode_ret)
990{
991 arm_compute::CLSymbols::get().load_default();
992 auto func = arm_compute::CLSymbols::get().clImportMemoryARM_ptr;
993 if(func != nullptr)
994 {
995 return func(context, flags, properties, memory, size, errcode_ret);
996 }
997 else
998 {
999 if(errcode_ret != nullptr)
1000 {
1001 *errcode_ret = CL_OUT_OF_RESOURCES;
1002 }
1003 return nullptr;
1004 }
Pablo Tellodb8485a2019-09-24 11:03:47 +01001005}