blob: ef03a5a302a621710dbfe7a3cd9b8d75fc9cb825 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Georgios Pinitas4d0351c2019-04-03 15:11:16 +01002 * Copyright (c) 2017-2019 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
25#include "arm_compute/core/CL/OpenCL.h"
26
27#include <dlfcn.h>
28#include <iostream>
29
Moritz Pflanzer725788e2017-07-07 15:35:56 +010030namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031{
Moritz Pflanzer725788e2017-07-07 15:35:56 +010032CLSymbols &CLSymbols::get()
33{
34 static CLSymbols symbols;
35 return symbols;
36}
37
38bool CLSymbols::load_default()
39{
40 static const std::vector<std::string> libraries{ "libOpenCL.so", "libGLES_mali.so", "libmali.so" };
41
42 if(_loaded.first)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010043 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010044 return _loaded.second;
45 }
46
47 // Indicate that default loading has been tried
48 _loaded.first = true;
49
50 for(const auto &lib : libraries)
51 {
52 if(load(lib))
Anthony Barbier6ff3b192017-09-04 18:44:23 +010053 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010054 return true;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010055 }
56 }
57
Moritz Pflanzer725788e2017-07-07 15:35:56 +010058 std::cerr << "Couldn't find any OpenCL library.\n";
59 return false;
60}
61
62bool CLSymbols::load(const std::string &library)
63{
64 void *handle = dlopen(library.c_str(), RTLD_LAZY | RTLD_LOCAL);
65
66 if(handle == nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010067 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010068 std::cerr << "Can't load " << library << ": " << dlerror() << "\n";
69 // Set status of loading to failed
70 _loaded.second = false;
71 return false;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010072 }
73
Anthony Barbier58c4ff12017-11-09 09:15:32 +000074#define LOAD_FUNCTION_PTR(func_name, handle) \
75 func_name##_ptr = reinterpret_cast<decltype(func_name) *>(dlsym(handle, #func_name));
76
Anthony Barbierb6eb3532018-08-08 13:20:04 +010077 LOAD_FUNCTION_PTR(clCreateContext, handle);
Anthony Barbiera9e15332017-12-22 16:37:30 +000078 LOAD_FUNCTION_PTR(clCreateContextFromType, handle);
79 LOAD_FUNCTION_PTR(clCreateCommandQueue, handle);
80 LOAD_FUNCTION_PTR(clGetContextInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +000081 LOAD_FUNCTION_PTR(clBuildProgram, handle);
82 LOAD_FUNCTION_PTR(clEnqueueNDRangeKernel, handle);
83 LOAD_FUNCTION_PTR(clSetKernelArg, handle);
84 LOAD_FUNCTION_PTR(clReleaseKernel, handle);
85 LOAD_FUNCTION_PTR(clCreateProgramWithSource, handle);
86 LOAD_FUNCTION_PTR(clCreateBuffer, handle);
87 LOAD_FUNCTION_PTR(clRetainKernel, handle);
88 LOAD_FUNCTION_PTR(clCreateKernel, handle);
89 LOAD_FUNCTION_PTR(clGetProgramInfo, handle);
90 LOAD_FUNCTION_PTR(clFlush, handle);
91 LOAD_FUNCTION_PTR(clFinish, handle);
92 LOAD_FUNCTION_PTR(clReleaseProgram, handle);
93 LOAD_FUNCTION_PTR(clRetainContext, handle);
94 LOAD_FUNCTION_PTR(clCreateProgramWithBinary, handle);
95 LOAD_FUNCTION_PTR(clReleaseCommandQueue, handle);
96 LOAD_FUNCTION_PTR(clEnqueueMapBuffer, handle);
97 LOAD_FUNCTION_PTR(clRetainProgram, handle);
98 LOAD_FUNCTION_PTR(clGetProgramBuildInfo, handle);
99 LOAD_FUNCTION_PTR(clEnqueueReadBuffer, handle);
100 LOAD_FUNCTION_PTR(clEnqueueWriteBuffer, handle);
101 LOAD_FUNCTION_PTR(clReleaseEvent, handle);
102 LOAD_FUNCTION_PTR(clReleaseContext, handle);
103 LOAD_FUNCTION_PTR(clRetainCommandQueue, handle);
104 LOAD_FUNCTION_PTR(clEnqueueUnmapMemObject, handle);
105 LOAD_FUNCTION_PTR(clRetainMemObject, handle);
106 LOAD_FUNCTION_PTR(clReleaseMemObject, handle);
107 LOAD_FUNCTION_PTR(clGetDeviceInfo, handle);
108 LOAD_FUNCTION_PTR(clGetDeviceIDs, handle);
Georgios Pinitasdf310362018-11-14 13:16:56 +0000109 LOAD_FUNCTION_PTR(clGetMemObjectInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000110 LOAD_FUNCTION_PTR(clRetainEvent, handle);
111 LOAD_FUNCTION_PTR(clGetPlatformIDs, handle);
112 LOAD_FUNCTION_PTR(clGetKernelWorkGroupInfo, handle);
Gian Marco85e6f512018-02-01 16:57:48 +0000113 LOAD_FUNCTION_PTR(clGetCommandQueueInfo, handle);
114 LOAD_FUNCTION_PTR(clGetKernelInfo, handle);
115 LOAD_FUNCTION_PTR(clGetEventProfilingInfo, handle);
Pablo Telloe86a09f2018-01-11 15:44:48 +0000116 LOAD_FUNCTION_PTR(clSVMAlloc, handle);
117 LOAD_FUNCTION_PTR(clSVMFree, handle);
118 LOAD_FUNCTION_PTR(clEnqueueSVMMap, handle);
119 LOAD_FUNCTION_PTR(clEnqueueSVMUnmap, handle);
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100120 LOAD_FUNCTION_PTR(clEnqueueMarker, handle);
121 LOAD_FUNCTION_PTR(clWaitForEvents, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000122
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100123 // Third-party extensions
124 LOAD_FUNCTION_PTR(clImportMemoryARM, handle);
125
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000126#undef LOAD_FUNCTION_PTR
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100127
Anthony Barbier7b43d312017-12-14 10:58:47 +0000128 //Don't call dlclose(handle) or all the symbols will be unloaded !
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100129
130 // Disable default loading and set status to successful
131 _loaded = std::make_pair(true, true);
132
133 return true;
134}
135
136bool opencl_is_available()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100137{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100138 CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000139 return CLSymbols::get().clBuildProgram_ptr != nullptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100140}
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100141} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100142
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100143cl_int clEnqueueMarker(cl_command_queue command_queue,
144 cl_event *event)
145{
146 arm_compute::CLSymbols::get().load_default();
147 auto func = arm_compute::CLSymbols::get().clEnqueueMarker_ptr;
148 if(func != nullptr)
149 {
150 return func(command_queue, event);
151 }
152 else
153 {
154 return CL_OUT_OF_RESOURCES;
155 }
156}
157
158cl_int clWaitForEvents(cl_uint num_events,
159 const cl_event *event_list)
160{
161 arm_compute::CLSymbols::get().load_default();
162 auto func = arm_compute::CLSymbols::get().clWaitForEvents_ptr;
163 if(func != nullptr)
164 {
165 return func(num_events, event_list);
166 }
167 else
168 {
169 return CL_OUT_OF_RESOURCES;
170 }
171}
172
Pablo Telloe86a09f2018-01-11 15:44:48 +0000173cl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags flags, void *svm_ptr,
174 size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
175{
176 arm_compute::CLSymbols::get().load_default();
177 auto func = arm_compute::CLSymbols::get().clEnqueueSVMMap_ptr;
178 if(func != nullptr)
179 {
180 return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
181 }
182 else
183 {
184 return CL_OUT_OF_RESOURCES;
185 }
186}
187
188cl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *svm_ptr, cl_uint num_events_in_wait_list,
189 const cl_event *event_wait_list, cl_event *event)
190{
191 arm_compute::CLSymbols::get().load_default();
192 auto func = arm_compute::CLSymbols::get().clEnqueueSVMUnmap_ptr;
193 if(func != nullptr)
194 {
195 return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
196 }
197 else
198 {
199 return CL_OUT_OF_RESOURCES;
200 }
201}
202
203void *clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
204{
205 arm_compute::CLSymbols::get().load_default();
206 auto func = arm_compute::CLSymbols::get().clSVMAlloc_ptr;
207 if(func != nullptr)
208 {
209 return func(context, flags, size, alignment);
210 }
211 else
212 {
213 return nullptr;
214 }
215}
216
217void clSVMFree(cl_context context, void *svm_pointer)
218{
219 arm_compute::CLSymbols::get().load_default();
220 auto func = arm_compute::CLSymbols::get().clSVMFree_ptr;
221 if(func != nullptr)
222 {
223 func(context, svm_pointer);
224 }
225}
226
Anthony Barbiera9e15332017-12-22 16:37:30 +0000227cl_int clGetContextInfo(cl_context context,
228 cl_context_info param_name,
229 size_t param_value_size,
230 void *param_value,
231 size_t *param_value_size_ret)
232{
233 arm_compute::CLSymbols::get().load_default();
234 auto func = arm_compute::CLSymbols::get().clGetContextInfo_ptr;
235 if(func != nullptr)
236 {
237 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
238 }
239 else
240 {
241 return CL_OUT_OF_RESOURCES;
242 }
243}
244
245cl_command_queue clCreateCommandQueue(cl_context context,
246 cl_device_id device,
247 cl_command_queue_properties properties,
248 cl_int *errcode_ret)
249{
250 arm_compute::CLSymbols::get().load_default();
251 auto func = arm_compute::CLSymbols::get().clCreateCommandQueue_ptr;
252 if(func != nullptr)
253 {
254 return func(context, device, properties, errcode_ret);
255 }
256 else
257 {
258 return nullptr;
259 }
260}
261
Anthony Barbierb6eb3532018-08-08 13:20:04 +0100262cl_context clCreateContext(
263 const cl_context_properties *properties,
264 cl_uint num_devices,
265 const cl_device_id *devices,
266 void (*pfn_notify)(const char *, const void *, size_t, void *),
267 void *user_data,
268 cl_int *errcode_ret)
269{
270 arm_compute::CLSymbols::get().load_default();
271 auto func = arm_compute::CLSymbols::get().clCreateContext_ptr;
272 if(func != nullptr)
273 {
274 return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
275 }
276 else
277 {
278 return nullptr;
279 }
280}
281
Anthony Barbiera9e15332017-12-22 16:37:30 +0000282cl_context clCreateContextFromType(const cl_context_properties *properties,
283 cl_device_type device_type,
284 void (*pfn_notify)(const char *, const void *, size_t, void *),
285 void *user_data,
286 cl_int *errcode_ret)
287{
288 arm_compute::CLSymbols::get().load_default();
289 auto func = arm_compute::CLSymbols::get().clCreateContextFromType_ptr;
290 if(func != nullptr)
291 {
292 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
293 }
294 else
295 {
296 return nullptr;
297 }
298}
299
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100300cl_int clBuildProgram(
301 cl_program program,
302 cl_uint num_devices,
303 const cl_device_id *device_list,
304 const char *options,
305 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
306 void *user_data)
307{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100308 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000309 auto func = arm_compute::CLSymbols::get().clBuildProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100310 if(func != nullptr)
311 {
312 return func(program, num_devices, device_list, options, pfn_notify, user_data);
313 }
314 else
315 {
316 return CL_OUT_OF_RESOURCES;
317 }
318}
319
320cl_int clEnqueueNDRangeKernel(
321 cl_command_queue command_queue,
322 cl_kernel kernel,
323 cl_uint work_dim,
324 const size_t *global_work_offset,
325 const size_t *global_work_size,
326 const size_t *local_work_size,
327 cl_uint num_events_in_wait_list,
328 const cl_event *event_wait_list,
329 cl_event *event)
330{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100331 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000332 auto func = arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100333 if(func != nullptr)
334 {
335 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);
336 }
337 else
338 {
339 return CL_OUT_OF_RESOURCES;
340 }
341}
342
343cl_int clSetKernelArg(
344 cl_kernel kernel,
345 cl_uint arg_index,
346 size_t arg_size,
347 const void *arg_value)
348{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100349 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000350 auto func = arm_compute::CLSymbols::get().clSetKernelArg_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100351 if(func != nullptr)
352 {
353 return func(kernel, arg_index, arg_size, arg_value);
354 }
355 else
356 {
357 return CL_OUT_OF_RESOURCES;
358 }
359}
360
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100361cl_int clRetainMemObject(cl_mem memobj)
362{
363 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000364 auto func = arm_compute::CLSymbols::get().clRetainMemObject_ptr;
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100365 if(func != nullptr)
366 {
367 return func(memobj);
368 }
369 else
370 {
371 return CL_OUT_OF_RESOURCES;
372 }
373}
374
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100375cl_int clReleaseMemObject(cl_mem memobj)
376{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100377 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000378 auto func = arm_compute::CLSymbols::get().clReleaseMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100379 if(func != nullptr)
380 {
381 return func(memobj);
382 }
383 else
384 {
385 return CL_OUT_OF_RESOURCES;
386 }
387}
388
389cl_int clEnqueueUnmapMemObject(
390 cl_command_queue command_queue,
391 cl_mem memobj,
392 void *mapped_ptr,
393 cl_uint num_events_in_wait_list,
394 const cl_event *event_wait_list,
395 cl_event *event)
396{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100397 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000398 auto func = arm_compute::CLSymbols::get().clEnqueueUnmapMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100399 if(func != nullptr)
400 {
401 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
402 }
403 else
404 {
405 return CL_OUT_OF_RESOURCES;
406 }
407}
408
409cl_int clRetainCommandQueue(cl_command_queue command_queue)
410{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100411 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000412 auto func = arm_compute::CLSymbols::get().clRetainCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100413 if(func != nullptr)
414 {
415 return func(command_queue);
416 }
417 else
418 {
419 return CL_OUT_OF_RESOURCES;
420 }
421}
422
423cl_int clReleaseContext(cl_context context)
424{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100425 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000426 auto func = arm_compute::CLSymbols::get().clReleaseContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100427 if(func != nullptr)
428 {
429 return func(context);
430 }
431 else
432 {
433 return CL_OUT_OF_RESOURCES;
434 }
435}
436cl_int clReleaseEvent(cl_event event)
437{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100438 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000439 auto func = arm_compute::CLSymbols::get().clReleaseEvent_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100440 if(func != nullptr)
441 {
442 return func(event);
443 }
444 else
445 {
446 return CL_OUT_OF_RESOURCES;
447 }
448}
449
450cl_int clEnqueueWriteBuffer(
451 cl_command_queue command_queue,
452 cl_mem buffer,
453 cl_bool blocking_write,
454 size_t offset,
455 size_t size,
456 const void *ptr,
457 cl_uint num_events_in_wait_list,
458 const cl_event *event_wait_list,
459 cl_event *event)
460{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100461 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000462 auto func = arm_compute::CLSymbols::get().clEnqueueWriteBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100463 if(func != nullptr)
464 {
465 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
466 }
467 else
468 {
469 return CL_OUT_OF_RESOURCES;
470 }
471}
472
473cl_int clEnqueueReadBuffer(
474 cl_command_queue command_queue,
475 cl_mem buffer,
476 cl_bool blocking_read,
477 size_t offset,
478 size_t size,
479 void *ptr,
480 cl_uint num_events_in_wait_list,
481 const cl_event *event_wait_list,
482 cl_event *event)
483{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100484 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000485 auto func = arm_compute::CLSymbols::get().clEnqueueReadBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100486 if(func != nullptr)
487 {
488 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
489 }
490 else
491 {
492 return CL_OUT_OF_RESOURCES;
493 }
494}
495
496cl_int clGetProgramBuildInfo(
497 cl_program program,
498 cl_device_id device,
499 cl_program_build_info param_name,
500 size_t param_value_size,
501 void *param_value,
502 size_t *param_value_size_ret)
503{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100504 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000505 auto func = arm_compute::CLSymbols::get().clGetProgramBuildInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100506 if(func != nullptr)
507 {
508 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
509 }
510 else
511 {
512 return CL_OUT_OF_RESOURCES;
513 }
514}
515
516cl_int clRetainProgram(cl_program program)
517{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100518 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000519 auto func = arm_compute::CLSymbols::get().clRetainProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100520 if(func != nullptr)
521 {
522 return func(program);
523 }
524 else
525 {
526 return CL_OUT_OF_RESOURCES;
527 }
528}
529
530void *clEnqueueMapBuffer(
531 cl_command_queue command_queue,
532 cl_mem buffer,
533 cl_bool blocking_map,
534 cl_map_flags map_flags,
535 size_t offset,
536 size_t size,
537 cl_uint num_events_in_wait_list,
538 const cl_event *event_wait_list,
539 cl_event *event,
540 cl_int *errcode_ret)
541{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100542 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000543 auto func = arm_compute::CLSymbols::get().clEnqueueMapBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100544 if(func != nullptr)
545 {
546 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
547 }
548 else
549 {
550 if(errcode_ret != nullptr)
551 {
552 *errcode_ret = CL_OUT_OF_RESOURCES;
553 }
554 return nullptr;
555 }
556}
557
558cl_int clReleaseCommandQueue(cl_command_queue command_queue)
559{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100560 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000561 auto func = arm_compute::CLSymbols::get().clReleaseCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100562 if(func != nullptr)
563 {
564 return func(command_queue);
565 }
566 else
567 {
568 return CL_OUT_OF_RESOURCES;
569 }
570}
571
572cl_program clCreateProgramWithBinary(
573 cl_context context,
574 cl_uint num_devices,
575 const cl_device_id *device_list,
576 const size_t *lengths,
577 const unsigned char **binaries,
578 cl_int *binary_status,
579 cl_int *errcode_ret)
580{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100581 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000582 auto func = arm_compute::CLSymbols::get().clCreateProgramWithBinary_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100583 if(func != nullptr)
584 {
585 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
586 }
587 else
588 {
589 if(errcode_ret != nullptr)
590 {
591 *errcode_ret = CL_OUT_OF_RESOURCES;
592 }
593 return nullptr;
594 }
595}
596
597cl_int clRetainContext(cl_context context)
598{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100599 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000600 auto func = arm_compute::CLSymbols::get().clRetainContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100601 if(func != nullptr)
602 {
603 return func(context);
604 }
605 else
606 {
607 return CL_OUT_OF_RESOURCES;
608 }
609}
610
611cl_int clReleaseProgram(cl_program program)
612{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100613 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000614 auto func = arm_compute::CLSymbols::get().clReleaseProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100615 if(func != nullptr)
616 {
617 return func(program);
618 }
619 else
620 {
621 return CL_OUT_OF_RESOURCES;
622 }
623}
624
625cl_int clFlush(cl_command_queue command_queue)
626{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100627 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000628 auto func = arm_compute::CLSymbols::get().clFlush_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100629 if(func != nullptr)
630 {
631 return func(command_queue);
632 }
633 else
634 {
635 return CL_OUT_OF_RESOURCES;
636 }
637}
638
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100639cl_int clFinish(cl_command_queue command_queue)
640{
641 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000642 auto func = arm_compute::CLSymbols::get().clFinish_ptr;
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100643 if(func != nullptr)
644 {
645 return func(command_queue);
646 }
647 else
648 {
649 return CL_OUT_OF_RESOURCES;
650 }
651}
652
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100653cl_int clGetProgramInfo(
654 cl_program program,
655 cl_program_info param_name,
656 size_t param_value_size,
657 void *param_value,
658 size_t *param_value_size_ret)
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().clGetProgramInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100662 if(func != nullptr)
663 {
664 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
665 }
666 else
667 {
668 return CL_OUT_OF_RESOURCES;
669 }
670}
671
672cl_kernel clCreateKernel(
673 cl_program program,
674 const char *kernel_name,
675 cl_int *errcode_ret)
676{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100677 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000678 auto func = arm_compute::CLSymbols::get().clCreateKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100679 if(func != nullptr)
680 {
681 return func(program, kernel_name, errcode_ret);
682 }
683 else
684 {
685 if(errcode_ret != nullptr)
686 {
687 *errcode_ret = CL_OUT_OF_RESOURCES;
688 }
689 return nullptr;
690 }
691}
692
693cl_int clRetainKernel(cl_kernel kernel)
694{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100695 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000696 auto func = arm_compute::CLSymbols::get().clRetainKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100697 if(func != nullptr)
698 {
699 return func(kernel);
700 }
701 else
702 {
703 return CL_OUT_OF_RESOURCES;
704 }
705}
706
707cl_mem clCreateBuffer(
708 cl_context context,
709 cl_mem_flags flags,
710 size_t size,
711 void *host_ptr,
712 cl_int *errcode_ret)
713{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100714 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000715 auto func = arm_compute::CLSymbols::get().clCreateBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100716 if(func != nullptr)
717 {
718 return func(context, flags, size, host_ptr, errcode_ret);
719 }
720 else
721 {
722 if(errcode_ret != nullptr)
723 {
724 *errcode_ret = CL_OUT_OF_RESOURCES;
725 }
726 return nullptr;
727 }
728}
729
730cl_program clCreateProgramWithSource(
731 cl_context context,
732 cl_uint count,
733 const char **strings,
734 const size_t *lengths,
735 cl_int *errcode_ret)
736{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100737 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000738 auto func = arm_compute::CLSymbols::get().clCreateProgramWithSource_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100739 if(func != nullptr)
740 {
741 return func(context, count, strings, lengths, errcode_ret);
742 }
743 else
744 {
745 if(errcode_ret != nullptr)
746 {
747 *errcode_ret = CL_OUT_OF_RESOURCES;
748 }
749 return nullptr;
750 }
751}
752
753cl_int clReleaseKernel(cl_kernel kernel)
754{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100755 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000756 auto func = arm_compute::CLSymbols::get().clReleaseKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100757 if(func != nullptr)
758 {
759 return func(kernel);
760 }
761 else
762 {
763 return CL_OUT_OF_RESOURCES;
764 }
765}
766
767cl_int clGetDeviceIDs(cl_platform_id platform,
768 cl_device_type device_type,
769 cl_uint num_entries,
770 cl_device_id *devices,
771 cl_uint *num_devices)
772{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100773 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000774 auto func = arm_compute::CLSymbols::get().clGetDeviceIDs_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100775 if(func != nullptr)
776 {
777 return func(platform, device_type, num_entries, devices, num_devices);
778 }
779 else
780 {
781 return CL_OUT_OF_RESOURCES;
782 }
783}
784
785cl_int clGetDeviceInfo(cl_device_id device,
786 cl_device_info param_name,
787 size_t param_value_size,
788 void *param_value,
789 size_t *param_value_size_ret)
790{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100791 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000792 auto func = arm_compute::CLSymbols::get().clGetDeviceInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100793 if(func != nullptr)
794 {
795 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
796 }
797 else
798 {
799 return CL_OUT_OF_RESOURCES;
800 }
801}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100802
Georgios Pinitasdf310362018-11-14 13:16:56 +0000803cl_int clGetMemObjectInfo(cl_mem memobj,
804 cl_mem_info param_name,
805 size_t param_value_size,
806 void *param_value,
807 size_t *param_value_size_ret)
808{
809 arm_compute::CLSymbols::get().load_default();
810 auto func = arm_compute::CLSymbols::get().clGetMemObjectInfo_ptr;
811 if(func != nullptr)
812 {
813 return func(memobj, param_name, param_value_size, param_value, param_value_size_ret);
814 }
815 else
816 {
817 return CL_OUT_OF_RESOURCES;
818 }
819}
820
Giorgio Arena9fe41442017-08-23 16:36:24 +0100821cl_int clRetainEvent(cl_event event)
822{
Moritz Pflanzer159b6da2017-09-20 16:03:35 +0100823 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000824 auto func = arm_compute::CLSymbols::get().clRetainEvent_ptr;
Giorgio Arena9fe41442017-08-23 16:36:24 +0100825 if(func != nullptr)
826 {
827 return func(event);
828 }
829 else
830 {
831 return CL_OUT_OF_RESOURCES;
832 }
833}
steniu01f01f9de2017-09-27 17:00:11 +0100834
835cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
836{
837 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000838 auto func = arm_compute::CLSymbols::get().clGetPlatformIDs_ptr;
steniu01f01f9de2017-09-27 17:00:11 +0100839 if(func != nullptr)
840 {
841 return func(num_entries, platforms, num_platforms);
842 }
843 else
844 {
845 return CL_OUT_OF_RESOURCES;
846 }
847}
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100848
849cl_int
850clGetKernelWorkGroupInfo(cl_kernel kernel,
851 cl_device_id device,
852 cl_kernel_work_group_info param_name,
853 size_t param_value_size,
854 void *param_value,
855 size_t *param_value_size_ret)
856{
857 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000858 auto func = arm_compute::CLSymbols::get().clGetKernelWorkGroupInfo_ptr;
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100859 if(func != nullptr)
860 {
861 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
862 }
863 else
864 {
865 return CL_OUT_OF_RESOURCES;
866 }
867}
Gian Marco85e6f512018-02-01 16:57:48 +0000868
869cl_int
870clGetCommandQueueInfo(cl_command_queue command_queue,
871 cl_command_queue_info param_name,
872 size_t param_value_size,
873 void *param_value,
874 size_t *param_value_size_ret)
875{
876 arm_compute::CLSymbols::get().load_default();
877 auto func = arm_compute::CLSymbols::get().clGetCommandQueueInfo_ptr;
878 if(func != nullptr)
879 {
880 return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
881 }
882 else
883 {
884 return CL_OUT_OF_RESOURCES;
885 }
886}
887
888cl_int
889clGetKernelInfo(cl_kernel kernel,
890 cl_kernel_info param_name,
891 size_t param_value_size,
892 void *param_value,
893 size_t *param_value_size_ret)
894{
895 arm_compute::CLSymbols::get().load_default();
896 auto func = arm_compute::CLSymbols::get().clGetKernelInfo_ptr;
897 if(func != nullptr)
898 {
899 return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
900 }
901 else
902 {
903 return CL_OUT_OF_RESOURCES;
904 }
905}
906
907cl_int
908clGetEventProfilingInfo(cl_event event,
909 cl_profiling_info param_name,
910 size_t param_value_size,
911 void *param_value,
912 size_t *param_value_size_ret)
913{
914 arm_compute::CLSymbols::get().load_default();
915 auto func = arm_compute::CLSymbols::get().clGetEventProfilingInfo_ptr;
916 if(func != nullptr)
917 {
918 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
919 }
920 else
921 {
922 return CL_OUT_OF_RESOURCES;
923 }
Anthony Barbierf5dcf792018-02-28 18:04:45 +0000924}
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100925
926cl_mem
927clImportMemoryARM(cl_context context,
928 cl_mem_flags flags,
929 const cl_import_properties_arm *properties,
930 void *memory,
931 size_t size,
932 cl_int *errcode_ret)
933{
934 arm_compute::CLSymbols::get().load_default();
935 auto func = arm_compute::CLSymbols::get().clImportMemoryARM_ptr;
936 if(func != nullptr)
937 {
938 return func(context, flags, properties, memory, size, errcode_ret);
939 }
940 else
941 {
942 if(errcode_ret != nullptr)
943 {
944 *errcode_ret = CL_OUT_OF_RESOURCES;
945 }
946 return nullptr;
947 }
948}