blob: 486bb6a1bd67ca139e8323827034ec7333f8a62c [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Gian Marco85e6f512018-02-01 16:57:48 +00002 * Copyright (c) 2017-2018 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);
109 LOAD_FUNCTION_PTR(clRetainEvent, handle);
110 LOAD_FUNCTION_PTR(clGetPlatformIDs, handle);
111 LOAD_FUNCTION_PTR(clGetKernelWorkGroupInfo, handle);
Gian Marco85e6f512018-02-01 16:57:48 +0000112 LOAD_FUNCTION_PTR(clGetCommandQueueInfo, handle);
113 LOAD_FUNCTION_PTR(clGetKernelInfo, handle);
114 LOAD_FUNCTION_PTR(clGetEventProfilingInfo, handle);
Pablo Telloe86a09f2018-01-11 15:44:48 +0000115 LOAD_FUNCTION_PTR(clSVMAlloc, handle);
116 LOAD_FUNCTION_PTR(clSVMFree, handle);
117 LOAD_FUNCTION_PTR(clEnqueueSVMMap, handle);
118 LOAD_FUNCTION_PTR(clEnqueueSVMUnmap, handle);
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100119 LOAD_FUNCTION_PTR(clEnqueueMarker, handle);
120 LOAD_FUNCTION_PTR(clWaitForEvents, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000121
122#undef LOAD_FUNCTION_PTR
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100123
Anthony Barbier7b43d312017-12-14 10:58:47 +0000124 //Don't call dlclose(handle) or all the symbols will be unloaded !
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100125
126 // Disable default loading and set status to successful
127 _loaded = std::make_pair(true, true);
128
129 return true;
130}
131
132bool opencl_is_available()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100133{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100134 CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000135 return CLSymbols::get().clBuildProgram_ptr != nullptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100136}
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100137} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100138
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100139cl_int clEnqueueMarker(cl_command_queue command_queue,
140 cl_event *event)
141{
142 arm_compute::CLSymbols::get().load_default();
143 auto func = arm_compute::CLSymbols::get().clEnqueueMarker_ptr;
144 if(func != nullptr)
145 {
146 return func(command_queue, event);
147 }
148 else
149 {
150 return CL_OUT_OF_RESOURCES;
151 }
152}
153
154cl_int clWaitForEvents(cl_uint num_events,
155 const cl_event *event_list)
156{
157 arm_compute::CLSymbols::get().load_default();
158 auto func = arm_compute::CLSymbols::get().clWaitForEvents_ptr;
159 if(func != nullptr)
160 {
161 return func(num_events, event_list);
162 }
163 else
164 {
165 return CL_OUT_OF_RESOURCES;
166 }
167}
168
Pablo Telloe86a09f2018-01-11 15:44:48 +0000169cl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags flags, void *svm_ptr,
170 size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
171{
172 arm_compute::CLSymbols::get().load_default();
173 auto func = arm_compute::CLSymbols::get().clEnqueueSVMMap_ptr;
174 if(func != nullptr)
175 {
176 return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
177 }
178 else
179 {
180 return CL_OUT_OF_RESOURCES;
181 }
182}
183
184cl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *svm_ptr, cl_uint num_events_in_wait_list,
185 const cl_event *event_wait_list, cl_event *event)
186{
187 arm_compute::CLSymbols::get().load_default();
188 auto func = arm_compute::CLSymbols::get().clEnqueueSVMUnmap_ptr;
189 if(func != nullptr)
190 {
191 return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
192 }
193 else
194 {
195 return CL_OUT_OF_RESOURCES;
196 }
197}
198
199void *clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
200{
201 arm_compute::CLSymbols::get().load_default();
202 auto func = arm_compute::CLSymbols::get().clSVMAlloc_ptr;
203 if(func != nullptr)
204 {
205 return func(context, flags, size, alignment);
206 }
207 else
208 {
209 return nullptr;
210 }
211}
212
213void clSVMFree(cl_context context, void *svm_pointer)
214{
215 arm_compute::CLSymbols::get().load_default();
216 auto func = arm_compute::CLSymbols::get().clSVMFree_ptr;
217 if(func != nullptr)
218 {
219 func(context, svm_pointer);
220 }
221}
222
Anthony Barbiera9e15332017-12-22 16:37:30 +0000223cl_int clGetContextInfo(cl_context context,
224 cl_context_info param_name,
225 size_t param_value_size,
226 void *param_value,
227 size_t *param_value_size_ret)
228{
229 arm_compute::CLSymbols::get().load_default();
230 auto func = arm_compute::CLSymbols::get().clGetContextInfo_ptr;
231 if(func != nullptr)
232 {
233 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
234 }
235 else
236 {
237 return CL_OUT_OF_RESOURCES;
238 }
239}
240
241cl_command_queue clCreateCommandQueue(cl_context context,
242 cl_device_id device,
243 cl_command_queue_properties properties,
244 cl_int *errcode_ret)
245{
246 arm_compute::CLSymbols::get().load_default();
247 auto func = arm_compute::CLSymbols::get().clCreateCommandQueue_ptr;
248 if(func != nullptr)
249 {
250 return func(context, device, properties, errcode_ret);
251 }
252 else
253 {
254 return nullptr;
255 }
256}
257
Anthony Barbierb6eb3532018-08-08 13:20:04 +0100258cl_context clCreateContext(
259 const cl_context_properties *properties,
260 cl_uint num_devices,
261 const cl_device_id *devices,
262 void (*pfn_notify)(const char *, const void *, size_t, void *),
263 void *user_data,
264 cl_int *errcode_ret)
265{
266 arm_compute::CLSymbols::get().load_default();
267 auto func = arm_compute::CLSymbols::get().clCreateContext_ptr;
268 if(func != nullptr)
269 {
270 return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
271 }
272 else
273 {
274 return nullptr;
275 }
276}
277
Anthony Barbiera9e15332017-12-22 16:37:30 +0000278cl_context clCreateContextFromType(const cl_context_properties *properties,
279 cl_device_type device_type,
280 void (*pfn_notify)(const char *, const void *, size_t, void *),
281 void *user_data,
282 cl_int *errcode_ret)
283{
284 arm_compute::CLSymbols::get().load_default();
285 auto func = arm_compute::CLSymbols::get().clCreateContextFromType_ptr;
286 if(func != nullptr)
287 {
288 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
289 }
290 else
291 {
292 return nullptr;
293 }
294}
295
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100296cl_int clBuildProgram(
297 cl_program program,
298 cl_uint num_devices,
299 const cl_device_id *device_list,
300 const char *options,
301 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
302 void *user_data)
303{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100304 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000305 auto func = arm_compute::CLSymbols::get().clBuildProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100306 if(func != nullptr)
307 {
308 return func(program, num_devices, device_list, options, pfn_notify, user_data);
309 }
310 else
311 {
312 return CL_OUT_OF_RESOURCES;
313 }
314}
315
316cl_int clEnqueueNDRangeKernel(
317 cl_command_queue command_queue,
318 cl_kernel kernel,
319 cl_uint work_dim,
320 const size_t *global_work_offset,
321 const size_t *global_work_size,
322 const size_t *local_work_size,
323 cl_uint num_events_in_wait_list,
324 const cl_event *event_wait_list,
325 cl_event *event)
326{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100327 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000328 auto func = arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100329 if(func != nullptr)
330 {
331 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);
332 }
333 else
334 {
335 return CL_OUT_OF_RESOURCES;
336 }
337}
338
339cl_int clSetKernelArg(
340 cl_kernel kernel,
341 cl_uint arg_index,
342 size_t arg_size,
343 const void *arg_value)
344{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100345 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000346 auto func = arm_compute::CLSymbols::get().clSetKernelArg_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100347 if(func != nullptr)
348 {
349 return func(kernel, arg_index, arg_size, arg_value);
350 }
351 else
352 {
353 return CL_OUT_OF_RESOURCES;
354 }
355}
356
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100357cl_int clRetainMemObject(cl_mem memobj)
358{
359 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000360 auto func = arm_compute::CLSymbols::get().clRetainMemObject_ptr;
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100361 if(func != nullptr)
362 {
363 return func(memobj);
364 }
365 else
366 {
367 return CL_OUT_OF_RESOURCES;
368 }
369}
370
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100371cl_int clReleaseMemObject(cl_mem memobj)
372{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100373 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000374 auto func = arm_compute::CLSymbols::get().clReleaseMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100375 if(func != nullptr)
376 {
377 return func(memobj);
378 }
379 else
380 {
381 return CL_OUT_OF_RESOURCES;
382 }
383}
384
385cl_int clEnqueueUnmapMemObject(
386 cl_command_queue command_queue,
387 cl_mem memobj,
388 void *mapped_ptr,
389 cl_uint num_events_in_wait_list,
390 const cl_event *event_wait_list,
391 cl_event *event)
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().clEnqueueUnmapMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100395 if(func != nullptr)
396 {
397 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
398 }
399 else
400 {
401 return CL_OUT_OF_RESOURCES;
402 }
403}
404
405cl_int clRetainCommandQueue(cl_command_queue command_queue)
406{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100407 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000408 auto func = arm_compute::CLSymbols::get().clRetainCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100409 if(func != nullptr)
410 {
411 return func(command_queue);
412 }
413 else
414 {
415 return CL_OUT_OF_RESOURCES;
416 }
417}
418
419cl_int clReleaseContext(cl_context context)
420{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100421 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000422 auto func = arm_compute::CLSymbols::get().clReleaseContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100423 if(func != nullptr)
424 {
425 return func(context);
426 }
427 else
428 {
429 return CL_OUT_OF_RESOURCES;
430 }
431}
432cl_int clReleaseEvent(cl_event event)
433{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100434 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000435 auto func = arm_compute::CLSymbols::get().clReleaseEvent_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100436 if(func != nullptr)
437 {
438 return func(event);
439 }
440 else
441 {
442 return CL_OUT_OF_RESOURCES;
443 }
444}
445
446cl_int clEnqueueWriteBuffer(
447 cl_command_queue command_queue,
448 cl_mem buffer,
449 cl_bool blocking_write,
450 size_t offset,
451 size_t size,
452 const void *ptr,
453 cl_uint num_events_in_wait_list,
454 const cl_event *event_wait_list,
455 cl_event *event)
456{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100457 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000458 auto func = arm_compute::CLSymbols::get().clEnqueueWriteBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100459 if(func != nullptr)
460 {
461 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
462 }
463 else
464 {
465 return CL_OUT_OF_RESOURCES;
466 }
467}
468
469cl_int clEnqueueReadBuffer(
470 cl_command_queue command_queue,
471 cl_mem buffer,
472 cl_bool blocking_read,
473 size_t offset,
474 size_t size,
475 void *ptr,
476 cl_uint num_events_in_wait_list,
477 const cl_event *event_wait_list,
478 cl_event *event)
479{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100480 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000481 auto func = arm_compute::CLSymbols::get().clEnqueueReadBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100482 if(func != nullptr)
483 {
484 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
485 }
486 else
487 {
488 return CL_OUT_OF_RESOURCES;
489 }
490}
491
492cl_int clGetProgramBuildInfo(
493 cl_program program,
494 cl_device_id device,
495 cl_program_build_info param_name,
496 size_t param_value_size,
497 void *param_value,
498 size_t *param_value_size_ret)
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().clGetProgramBuildInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100502 if(func != nullptr)
503 {
504 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
505 }
506 else
507 {
508 return CL_OUT_OF_RESOURCES;
509 }
510}
511
512cl_int clRetainProgram(cl_program program)
513{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100514 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000515 auto func = arm_compute::CLSymbols::get().clRetainProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100516 if(func != nullptr)
517 {
518 return func(program);
519 }
520 else
521 {
522 return CL_OUT_OF_RESOURCES;
523 }
524}
525
526void *clEnqueueMapBuffer(
527 cl_command_queue command_queue,
528 cl_mem buffer,
529 cl_bool blocking_map,
530 cl_map_flags map_flags,
531 size_t offset,
532 size_t size,
533 cl_uint num_events_in_wait_list,
534 const cl_event *event_wait_list,
535 cl_event *event,
536 cl_int *errcode_ret)
537{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100538 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000539 auto func = arm_compute::CLSymbols::get().clEnqueueMapBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100540 if(func != nullptr)
541 {
542 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
543 }
544 else
545 {
546 if(errcode_ret != nullptr)
547 {
548 *errcode_ret = CL_OUT_OF_RESOURCES;
549 }
550 return nullptr;
551 }
552}
553
554cl_int clReleaseCommandQueue(cl_command_queue command_queue)
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().clReleaseCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100558 if(func != nullptr)
559 {
560 return func(command_queue);
561 }
562 else
563 {
564 return CL_OUT_OF_RESOURCES;
565 }
566}
567
568cl_program clCreateProgramWithBinary(
569 cl_context context,
570 cl_uint num_devices,
571 const cl_device_id *device_list,
572 const size_t *lengths,
573 const unsigned char **binaries,
574 cl_int *binary_status,
575 cl_int *errcode_ret)
576{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100577 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000578 auto func = arm_compute::CLSymbols::get().clCreateProgramWithBinary_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100579 if(func != nullptr)
580 {
581 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
582 }
583 else
584 {
585 if(errcode_ret != nullptr)
586 {
587 *errcode_ret = CL_OUT_OF_RESOURCES;
588 }
589 return nullptr;
590 }
591}
592
593cl_int clRetainContext(cl_context context)
594{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100595 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000596 auto func = arm_compute::CLSymbols::get().clRetainContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100597 if(func != nullptr)
598 {
599 return func(context);
600 }
601 else
602 {
603 return CL_OUT_OF_RESOURCES;
604 }
605}
606
607cl_int clReleaseProgram(cl_program program)
608{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100609 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000610 auto func = arm_compute::CLSymbols::get().clReleaseProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100611 if(func != nullptr)
612 {
613 return func(program);
614 }
615 else
616 {
617 return CL_OUT_OF_RESOURCES;
618 }
619}
620
621cl_int clFlush(cl_command_queue command_queue)
622{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100623 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000624 auto func = arm_compute::CLSymbols::get().clFlush_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100625 if(func != nullptr)
626 {
627 return func(command_queue);
628 }
629 else
630 {
631 return CL_OUT_OF_RESOURCES;
632 }
633}
634
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100635cl_int clFinish(cl_command_queue command_queue)
636{
637 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000638 auto func = arm_compute::CLSymbols::get().clFinish_ptr;
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100639 if(func != nullptr)
640 {
641 return func(command_queue);
642 }
643 else
644 {
645 return CL_OUT_OF_RESOURCES;
646 }
647}
648
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100649cl_int clGetProgramInfo(
650 cl_program program,
651 cl_program_info param_name,
652 size_t param_value_size,
653 void *param_value,
654 size_t *param_value_size_ret)
655{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100656 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000657 auto func = arm_compute::CLSymbols::get().clGetProgramInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100658 if(func != nullptr)
659 {
660 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
661 }
662 else
663 {
664 return CL_OUT_OF_RESOURCES;
665 }
666}
667
668cl_kernel clCreateKernel(
669 cl_program program,
670 const char *kernel_name,
671 cl_int *errcode_ret)
672{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100673 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000674 auto func = arm_compute::CLSymbols::get().clCreateKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100675 if(func != nullptr)
676 {
677 return func(program, kernel_name, errcode_ret);
678 }
679 else
680 {
681 if(errcode_ret != nullptr)
682 {
683 *errcode_ret = CL_OUT_OF_RESOURCES;
684 }
685 return nullptr;
686 }
687}
688
689cl_int clRetainKernel(cl_kernel kernel)
690{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100691 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000692 auto func = arm_compute::CLSymbols::get().clRetainKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100693 if(func != nullptr)
694 {
695 return func(kernel);
696 }
697 else
698 {
699 return CL_OUT_OF_RESOURCES;
700 }
701}
702
703cl_mem clCreateBuffer(
704 cl_context context,
705 cl_mem_flags flags,
706 size_t size,
707 void *host_ptr,
708 cl_int *errcode_ret)
709{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100710 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000711 auto func = arm_compute::CLSymbols::get().clCreateBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100712 if(func != nullptr)
713 {
714 return func(context, flags, size, host_ptr, errcode_ret);
715 }
716 else
717 {
718 if(errcode_ret != nullptr)
719 {
720 *errcode_ret = CL_OUT_OF_RESOURCES;
721 }
722 return nullptr;
723 }
724}
725
726cl_program clCreateProgramWithSource(
727 cl_context context,
728 cl_uint count,
729 const char **strings,
730 const size_t *lengths,
731 cl_int *errcode_ret)
732{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100733 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000734 auto func = arm_compute::CLSymbols::get().clCreateProgramWithSource_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100735 if(func != nullptr)
736 {
737 return func(context, count, strings, lengths, errcode_ret);
738 }
739 else
740 {
741 if(errcode_ret != nullptr)
742 {
743 *errcode_ret = CL_OUT_OF_RESOURCES;
744 }
745 return nullptr;
746 }
747}
748
749cl_int clReleaseKernel(cl_kernel kernel)
750{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100751 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000752 auto func = arm_compute::CLSymbols::get().clReleaseKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100753 if(func != nullptr)
754 {
755 return func(kernel);
756 }
757 else
758 {
759 return CL_OUT_OF_RESOURCES;
760 }
761}
762
763cl_int clGetDeviceIDs(cl_platform_id platform,
764 cl_device_type device_type,
765 cl_uint num_entries,
766 cl_device_id *devices,
767 cl_uint *num_devices)
768{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100769 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000770 auto func = arm_compute::CLSymbols::get().clGetDeviceIDs_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100771 if(func != nullptr)
772 {
773 return func(platform, device_type, num_entries, devices, num_devices);
774 }
775 else
776 {
777 return CL_OUT_OF_RESOURCES;
778 }
779}
780
781cl_int clGetDeviceInfo(cl_device_id device,
782 cl_device_info param_name,
783 size_t param_value_size,
784 void *param_value,
785 size_t *param_value_size_ret)
786{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100787 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000788 auto func = arm_compute::CLSymbols::get().clGetDeviceInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100789 if(func != nullptr)
790 {
791 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
792 }
793 else
794 {
795 return CL_OUT_OF_RESOURCES;
796 }
797}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100798
799cl_int clRetainEvent(cl_event event)
800{
Moritz Pflanzer159b6da2017-09-20 16:03:35 +0100801 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000802 auto func = arm_compute::CLSymbols::get().clRetainEvent_ptr;
Giorgio Arena9fe41442017-08-23 16:36:24 +0100803 if(func != nullptr)
804 {
805 return func(event);
806 }
807 else
808 {
809 return CL_OUT_OF_RESOURCES;
810 }
811}
steniu01f01f9de2017-09-27 17:00:11 +0100812
813cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
814{
815 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000816 auto func = arm_compute::CLSymbols::get().clGetPlatformIDs_ptr;
steniu01f01f9de2017-09-27 17:00:11 +0100817 if(func != nullptr)
818 {
819 return func(num_entries, platforms, num_platforms);
820 }
821 else
822 {
823 return CL_OUT_OF_RESOURCES;
824 }
825}
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100826
827cl_int
828clGetKernelWorkGroupInfo(cl_kernel kernel,
829 cl_device_id device,
830 cl_kernel_work_group_info param_name,
831 size_t param_value_size,
832 void *param_value,
833 size_t *param_value_size_ret)
834{
835 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000836 auto func = arm_compute::CLSymbols::get().clGetKernelWorkGroupInfo_ptr;
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100837 if(func != nullptr)
838 {
839 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
840 }
841 else
842 {
843 return CL_OUT_OF_RESOURCES;
844 }
845}
Gian Marco85e6f512018-02-01 16:57:48 +0000846
847cl_int
848clGetCommandQueueInfo(cl_command_queue command_queue,
849 cl_command_queue_info param_name,
850 size_t param_value_size,
851 void *param_value,
852 size_t *param_value_size_ret)
853{
854 arm_compute::CLSymbols::get().load_default();
855 auto func = arm_compute::CLSymbols::get().clGetCommandQueueInfo_ptr;
856 if(func != nullptr)
857 {
858 return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
859 }
860 else
861 {
862 return CL_OUT_OF_RESOURCES;
863 }
864}
865
866cl_int
867clGetKernelInfo(cl_kernel kernel,
868 cl_kernel_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();
874 auto func = arm_compute::CLSymbols::get().clGetKernelInfo_ptr;
875 if(func != nullptr)
876 {
877 return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
878 }
879 else
880 {
881 return CL_OUT_OF_RESOURCES;
882 }
883}
884
885cl_int
886clGetEventProfilingInfo(cl_event event,
887 cl_profiling_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().clGetEventProfilingInfo_ptr;
894 if(func != nullptr)
895 {
896 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
897 }
898 else
899 {
900 return CL_OUT_OF_RESOURCES;
901 }
Anthony Barbierf5dcf792018-02-28 18:04:45 +0000902}