blob: a8ed9733efcdbfe70cbfc9988d4e7617ec6fc655 [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 Barbiera9e15332017-12-22 16:37:30 +000077 LOAD_FUNCTION_PTR(clCreateContextFromType, handle);
78 LOAD_FUNCTION_PTR(clCreateCommandQueue, handle);
79 LOAD_FUNCTION_PTR(clGetContextInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +000080 LOAD_FUNCTION_PTR(clBuildProgram, handle);
81 LOAD_FUNCTION_PTR(clEnqueueNDRangeKernel, handle);
82 LOAD_FUNCTION_PTR(clSetKernelArg, handle);
83 LOAD_FUNCTION_PTR(clReleaseKernel, handle);
84 LOAD_FUNCTION_PTR(clCreateProgramWithSource, handle);
85 LOAD_FUNCTION_PTR(clCreateBuffer, handle);
86 LOAD_FUNCTION_PTR(clRetainKernel, handle);
87 LOAD_FUNCTION_PTR(clCreateKernel, handle);
88 LOAD_FUNCTION_PTR(clGetProgramInfo, handle);
89 LOAD_FUNCTION_PTR(clFlush, handle);
90 LOAD_FUNCTION_PTR(clFinish, handle);
91 LOAD_FUNCTION_PTR(clReleaseProgram, handle);
92 LOAD_FUNCTION_PTR(clRetainContext, handle);
93 LOAD_FUNCTION_PTR(clCreateProgramWithBinary, handle);
94 LOAD_FUNCTION_PTR(clReleaseCommandQueue, handle);
95 LOAD_FUNCTION_PTR(clEnqueueMapBuffer, handle);
96 LOAD_FUNCTION_PTR(clRetainProgram, handle);
97 LOAD_FUNCTION_PTR(clGetProgramBuildInfo, handle);
98 LOAD_FUNCTION_PTR(clEnqueueReadBuffer, handle);
99 LOAD_FUNCTION_PTR(clEnqueueWriteBuffer, handle);
100 LOAD_FUNCTION_PTR(clReleaseEvent, handle);
101 LOAD_FUNCTION_PTR(clReleaseContext, handle);
102 LOAD_FUNCTION_PTR(clRetainCommandQueue, handle);
103 LOAD_FUNCTION_PTR(clEnqueueUnmapMemObject, handle);
104 LOAD_FUNCTION_PTR(clRetainMemObject, handle);
105 LOAD_FUNCTION_PTR(clReleaseMemObject, handle);
106 LOAD_FUNCTION_PTR(clGetDeviceInfo, handle);
107 LOAD_FUNCTION_PTR(clGetDeviceIDs, handle);
108 LOAD_FUNCTION_PTR(clRetainEvent, handle);
109 LOAD_FUNCTION_PTR(clGetPlatformIDs, handle);
110 LOAD_FUNCTION_PTR(clGetKernelWorkGroupInfo, handle);
Gian Marco85e6f512018-02-01 16:57:48 +0000111 LOAD_FUNCTION_PTR(clGetCommandQueueInfo, handle);
112 LOAD_FUNCTION_PTR(clGetKernelInfo, handle);
113 LOAD_FUNCTION_PTR(clGetEventProfilingInfo, handle);
Pablo Telloe86a09f2018-01-11 15:44:48 +0000114 LOAD_FUNCTION_PTR(clSVMAlloc, handle);
115 LOAD_FUNCTION_PTR(clSVMFree, handle);
116 LOAD_FUNCTION_PTR(clEnqueueSVMMap, handle);
117 LOAD_FUNCTION_PTR(clEnqueueSVMUnmap, handle);
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100118 LOAD_FUNCTION_PTR(clEnqueueMarker, handle);
119 LOAD_FUNCTION_PTR(clWaitForEvents, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000120
121#undef LOAD_FUNCTION_PTR
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100122
Anthony Barbier7b43d312017-12-14 10:58:47 +0000123 //Don't call dlclose(handle) or all the symbols will be unloaded !
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100124
125 // Disable default loading and set status to successful
126 _loaded = std::make_pair(true, true);
127
128 return true;
129}
130
131bool opencl_is_available()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100132{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100133 CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000134 return CLSymbols::get().clBuildProgram_ptr != nullptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100135}
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100136} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100137
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100138cl_int clEnqueueMarker(cl_command_queue command_queue,
139 cl_event *event)
140{
141 arm_compute::CLSymbols::get().load_default();
142 auto func = arm_compute::CLSymbols::get().clEnqueueMarker_ptr;
143 if(func != nullptr)
144 {
145 return func(command_queue, event);
146 }
147 else
148 {
149 return CL_OUT_OF_RESOURCES;
150 }
151}
152
153cl_int clWaitForEvents(cl_uint num_events,
154 const cl_event *event_list)
155{
156 arm_compute::CLSymbols::get().load_default();
157 auto func = arm_compute::CLSymbols::get().clWaitForEvents_ptr;
158 if(func != nullptr)
159 {
160 return func(num_events, event_list);
161 }
162 else
163 {
164 return CL_OUT_OF_RESOURCES;
165 }
166}
167
Pablo Telloe86a09f2018-01-11 15:44:48 +0000168cl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags flags, void *svm_ptr,
169 size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
170{
171 arm_compute::CLSymbols::get().load_default();
172 auto func = arm_compute::CLSymbols::get().clEnqueueSVMMap_ptr;
173 if(func != nullptr)
174 {
175 return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
176 }
177 else
178 {
179 return CL_OUT_OF_RESOURCES;
180 }
181}
182
183cl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *svm_ptr, cl_uint num_events_in_wait_list,
184 const cl_event *event_wait_list, cl_event *event)
185{
186 arm_compute::CLSymbols::get().load_default();
187 auto func = arm_compute::CLSymbols::get().clEnqueueSVMUnmap_ptr;
188 if(func != nullptr)
189 {
190 return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
191 }
192 else
193 {
194 return CL_OUT_OF_RESOURCES;
195 }
196}
197
198void *clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
199{
200 arm_compute::CLSymbols::get().load_default();
201 auto func = arm_compute::CLSymbols::get().clSVMAlloc_ptr;
202 if(func != nullptr)
203 {
204 return func(context, flags, size, alignment);
205 }
206 else
207 {
208 return nullptr;
209 }
210}
211
212void clSVMFree(cl_context context, void *svm_pointer)
213{
214 arm_compute::CLSymbols::get().load_default();
215 auto func = arm_compute::CLSymbols::get().clSVMFree_ptr;
216 if(func != nullptr)
217 {
218 func(context, svm_pointer);
219 }
220}
221
Anthony Barbiera9e15332017-12-22 16:37:30 +0000222cl_int clGetContextInfo(cl_context context,
223 cl_context_info param_name,
224 size_t param_value_size,
225 void *param_value,
226 size_t *param_value_size_ret)
227{
228 arm_compute::CLSymbols::get().load_default();
229 auto func = arm_compute::CLSymbols::get().clGetContextInfo_ptr;
230 if(func != nullptr)
231 {
232 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
233 }
234 else
235 {
236 return CL_OUT_OF_RESOURCES;
237 }
238}
239
240cl_command_queue clCreateCommandQueue(cl_context context,
241 cl_device_id device,
242 cl_command_queue_properties properties,
243 cl_int *errcode_ret)
244{
245 arm_compute::CLSymbols::get().load_default();
246 auto func = arm_compute::CLSymbols::get().clCreateCommandQueue_ptr;
247 if(func != nullptr)
248 {
249 return func(context, device, properties, errcode_ret);
250 }
251 else
252 {
253 return nullptr;
254 }
255}
256
257cl_context clCreateContextFromType(const cl_context_properties *properties,
258 cl_device_type device_type,
259 void (*pfn_notify)(const char *, const void *, size_t, void *),
260 void *user_data,
261 cl_int *errcode_ret)
262{
263 arm_compute::CLSymbols::get().load_default();
264 auto func = arm_compute::CLSymbols::get().clCreateContextFromType_ptr;
265 if(func != nullptr)
266 {
267 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
268 }
269 else
270 {
271 return nullptr;
272 }
273}
274
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100275cl_int clBuildProgram(
276 cl_program program,
277 cl_uint num_devices,
278 const cl_device_id *device_list,
279 const char *options,
280 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
281 void *user_data)
282{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100283 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000284 auto func = arm_compute::CLSymbols::get().clBuildProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100285 if(func != nullptr)
286 {
287 return func(program, num_devices, device_list, options, pfn_notify, user_data);
288 }
289 else
290 {
291 return CL_OUT_OF_RESOURCES;
292 }
293}
294
295cl_int clEnqueueNDRangeKernel(
296 cl_command_queue command_queue,
297 cl_kernel kernel,
298 cl_uint work_dim,
299 const size_t *global_work_offset,
300 const size_t *global_work_size,
301 const size_t *local_work_size,
302 cl_uint num_events_in_wait_list,
303 const cl_event *event_wait_list,
304 cl_event *event)
305{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100306 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000307 auto func = arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100308 if(func != nullptr)
309 {
310 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);
311 }
312 else
313 {
314 return CL_OUT_OF_RESOURCES;
315 }
316}
317
318cl_int clSetKernelArg(
319 cl_kernel kernel,
320 cl_uint arg_index,
321 size_t arg_size,
322 const void *arg_value)
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().clSetKernelArg_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100326 if(func != nullptr)
327 {
328 return func(kernel, arg_index, arg_size, arg_value);
329 }
330 else
331 {
332 return CL_OUT_OF_RESOURCES;
333 }
334}
335
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100336cl_int clRetainMemObject(cl_mem memobj)
337{
338 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000339 auto func = arm_compute::CLSymbols::get().clRetainMemObject_ptr;
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100340 if(func != nullptr)
341 {
342 return func(memobj);
343 }
344 else
345 {
346 return CL_OUT_OF_RESOURCES;
347 }
348}
349
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100350cl_int clReleaseMemObject(cl_mem memobj)
351{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100352 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000353 auto func = arm_compute::CLSymbols::get().clReleaseMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100354 if(func != nullptr)
355 {
356 return func(memobj);
357 }
358 else
359 {
360 return CL_OUT_OF_RESOURCES;
361 }
362}
363
364cl_int clEnqueueUnmapMemObject(
365 cl_command_queue command_queue,
366 cl_mem memobj,
367 void *mapped_ptr,
368 cl_uint num_events_in_wait_list,
369 const cl_event *event_wait_list,
370 cl_event *event)
371{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100372 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000373 auto func = arm_compute::CLSymbols::get().clEnqueueUnmapMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100374 if(func != nullptr)
375 {
376 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
377 }
378 else
379 {
380 return CL_OUT_OF_RESOURCES;
381 }
382}
383
384cl_int clRetainCommandQueue(cl_command_queue command_queue)
385{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100386 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000387 auto func = arm_compute::CLSymbols::get().clRetainCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100388 if(func != nullptr)
389 {
390 return func(command_queue);
391 }
392 else
393 {
394 return CL_OUT_OF_RESOURCES;
395 }
396}
397
398cl_int clReleaseContext(cl_context context)
399{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100400 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000401 auto func = arm_compute::CLSymbols::get().clReleaseContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100402 if(func != nullptr)
403 {
404 return func(context);
405 }
406 else
407 {
408 return CL_OUT_OF_RESOURCES;
409 }
410}
411cl_int clReleaseEvent(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().clReleaseEvent_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100415 if(func != nullptr)
416 {
417 return func(event);
418 }
419 else
420 {
421 return CL_OUT_OF_RESOURCES;
422 }
423}
424
425cl_int clEnqueueWriteBuffer(
426 cl_command_queue command_queue,
427 cl_mem buffer,
428 cl_bool blocking_write,
429 size_t offset,
430 size_t size,
431 const void *ptr,
432 cl_uint num_events_in_wait_list,
433 const cl_event *event_wait_list,
434 cl_event *event)
435{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100436 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000437 auto func = arm_compute::CLSymbols::get().clEnqueueWriteBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100438 if(func != nullptr)
439 {
440 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
441 }
442 else
443 {
444 return CL_OUT_OF_RESOURCES;
445 }
446}
447
448cl_int clEnqueueReadBuffer(
449 cl_command_queue command_queue,
450 cl_mem buffer,
451 cl_bool blocking_read,
452 size_t offset,
453 size_t size,
454 void *ptr,
455 cl_uint num_events_in_wait_list,
456 const cl_event *event_wait_list,
457 cl_event *event)
458{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100459 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000460 auto func = arm_compute::CLSymbols::get().clEnqueueReadBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100461 if(func != nullptr)
462 {
463 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
464 }
465 else
466 {
467 return CL_OUT_OF_RESOURCES;
468 }
469}
470
471cl_int clGetProgramBuildInfo(
472 cl_program program,
473 cl_device_id device,
474 cl_program_build_info param_name,
475 size_t param_value_size,
476 void *param_value,
477 size_t *param_value_size_ret)
478{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100479 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000480 auto func = arm_compute::CLSymbols::get().clGetProgramBuildInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100481 if(func != nullptr)
482 {
483 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
484 }
485 else
486 {
487 return CL_OUT_OF_RESOURCES;
488 }
489}
490
491cl_int clRetainProgram(cl_program program)
492{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100493 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000494 auto func = arm_compute::CLSymbols::get().clRetainProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100495 if(func != nullptr)
496 {
497 return func(program);
498 }
499 else
500 {
501 return CL_OUT_OF_RESOURCES;
502 }
503}
504
505void *clEnqueueMapBuffer(
506 cl_command_queue command_queue,
507 cl_mem buffer,
508 cl_bool blocking_map,
509 cl_map_flags map_flags,
510 size_t offset,
511 size_t size,
512 cl_uint num_events_in_wait_list,
513 const cl_event *event_wait_list,
514 cl_event *event,
515 cl_int *errcode_ret)
516{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100517 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000518 auto func = arm_compute::CLSymbols::get().clEnqueueMapBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100519 if(func != nullptr)
520 {
521 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
522 }
523 else
524 {
525 if(errcode_ret != nullptr)
526 {
527 *errcode_ret = CL_OUT_OF_RESOURCES;
528 }
529 return nullptr;
530 }
531}
532
533cl_int clReleaseCommandQueue(cl_command_queue command_queue)
534{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100535 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000536 auto func = arm_compute::CLSymbols::get().clReleaseCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100537 if(func != nullptr)
538 {
539 return func(command_queue);
540 }
541 else
542 {
543 return CL_OUT_OF_RESOURCES;
544 }
545}
546
547cl_program clCreateProgramWithBinary(
548 cl_context context,
549 cl_uint num_devices,
550 const cl_device_id *device_list,
551 const size_t *lengths,
552 const unsigned char **binaries,
553 cl_int *binary_status,
554 cl_int *errcode_ret)
555{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100556 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000557 auto func = arm_compute::CLSymbols::get().clCreateProgramWithBinary_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100558 if(func != nullptr)
559 {
560 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
561 }
562 else
563 {
564 if(errcode_ret != nullptr)
565 {
566 *errcode_ret = CL_OUT_OF_RESOURCES;
567 }
568 return nullptr;
569 }
570}
571
572cl_int clRetainContext(cl_context context)
573{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100574 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000575 auto func = arm_compute::CLSymbols::get().clRetainContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100576 if(func != nullptr)
577 {
578 return func(context);
579 }
580 else
581 {
582 return CL_OUT_OF_RESOURCES;
583 }
584}
585
586cl_int clReleaseProgram(cl_program program)
587{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100588 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000589 auto func = arm_compute::CLSymbols::get().clReleaseProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100590 if(func != nullptr)
591 {
592 return func(program);
593 }
594 else
595 {
596 return CL_OUT_OF_RESOURCES;
597 }
598}
599
600cl_int clFlush(cl_command_queue command_queue)
601{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100602 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000603 auto func = arm_compute::CLSymbols::get().clFlush_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100604 if(func != nullptr)
605 {
606 return func(command_queue);
607 }
608 else
609 {
610 return CL_OUT_OF_RESOURCES;
611 }
612}
613
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100614cl_int clFinish(cl_command_queue command_queue)
615{
616 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000617 auto func = arm_compute::CLSymbols::get().clFinish_ptr;
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100618 if(func != nullptr)
619 {
620 return func(command_queue);
621 }
622 else
623 {
624 return CL_OUT_OF_RESOURCES;
625 }
626}
627
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100628cl_int clGetProgramInfo(
629 cl_program program,
630 cl_program_info param_name,
631 size_t param_value_size,
632 void *param_value,
633 size_t *param_value_size_ret)
634{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100635 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000636 auto func = arm_compute::CLSymbols::get().clGetProgramInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100637 if(func != nullptr)
638 {
639 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
640 }
641 else
642 {
643 return CL_OUT_OF_RESOURCES;
644 }
645}
646
647cl_kernel clCreateKernel(
648 cl_program program,
649 const char *kernel_name,
650 cl_int *errcode_ret)
651{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100652 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000653 auto func = arm_compute::CLSymbols::get().clCreateKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100654 if(func != nullptr)
655 {
656 return func(program, kernel_name, errcode_ret);
657 }
658 else
659 {
660 if(errcode_ret != nullptr)
661 {
662 *errcode_ret = CL_OUT_OF_RESOURCES;
663 }
664 return nullptr;
665 }
666}
667
668cl_int clRetainKernel(cl_kernel kernel)
669{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100670 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000671 auto func = arm_compute::CLSymbols::get().clRetainKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100672 if(func != nullptr)
673 {
674 return func(kernel);
675 }
676 else
677 {
678 return CL_OUT_OF_RESOURCES;
679 }
680}
681
682cl_mem clCreateBuffer(
683 cl_context context,
684 cl_mem_flags flags,
685 size_t size,
686 void *host_ptr,
687 cl_int *errcode_ret)
688{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100689 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000690 auto func = arm_compute::CLSymbols::get().clCreateBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100691 if(func != nullptr)
692 {
693 return func(context, flags, size, host_ptr, errcode_ret);
694 }
695 else
696 {
697 if(errcode_ret != nullptr)
698 {
699 *errcode_ret = CL_OUT_OF_RESOURCES;
700 }
701 return nullptr;
702 }
703}
704
705cl_program clCreateProgramWithSource(
706 cl_context context,
707 cl_uint count,
708 const char **strings,
709 const size_t *lengths,
710 cl_int *errcode_ret)
711{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100712 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000713 auto func = arm_compute::CLSymbols::get().clCreateProgramWithSource_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100714 if(func != nullptr)
715 {
716 return func(context, count, strings, lengths, errcode_ret);
717 }
718 else
719 {
720 if(errcode_ret != nullptr)
721 {
722 *errcode_ret = CL_OUT_OF_RESOURCES;
723 }
724 return nullptr;
725 }
726}
727
728cl_int clReleaseKernel(cl_kernel kernel)
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().clReleaseKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100732 if(func != nullptr)
733 {
734 return func(kernel);
735 }
736 else
737 {
738 return CL_OUT_OF_RESOURCES;
739 }
740}
741
742cl_int clGetDeviceIDs(cl_platform_id platform,
743 cl_device_type device_type,
744 cl_uint num_entries,
745 cl_device_id *devices,
746 cl_uint *num_devices)
747{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100748 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000749 auto func = arm_compute::CLSymbols::get().clGetDeviceIDs_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100750 if(func != nullptr)
751 {
752 return func(platform, device_type, num_entries, devices, num_devices);
753 }
754 else
755 {
756 return CL_OUT_OF_RESOURCES;
757 }
758}
759
760cl_int clGetDeviceInfo(cl_device_id device,
761 cl_device_info param_name,
762 size_t param_value_size,
763 void *param_value,
764 size_t *param_value_size_ret)
765{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100766 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000767 auto func = arm_compute::CLSymbols::get().clGetDeviceInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100768 if(func != nullptr)
769 {
770 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
771 }
772 else
773 {
774 return CL_OUT_OF_RESOURCES;
775 }
776}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100777
778cl_int clRetainEvent(cl_event event)
779{
Moritz Pflanzer159b6da2017-09-20 16:03:35 +0100780 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000781 auto func = arm_compute::CLSymbols::get().clRetainEvent_ptr;
Giorgio Arena9fe41442017-08-23 16:36:24 +0100782 if(func != nullptr)
783 {
784 return func(event);
785 }
786 else
787 {
788 return CL_OUT_OF_RESOURCES;
789 }
790}
steniu01f01f9de2017-09-27 17:00:11 +0100791
792cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
793{
794 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000795 auto func = arm_compute::CLSymbols::get().clGetPlatformIDs_ptr;
steniu01f01f9de2017-09-27 17:00:11 +0100796 if(func != nullptr)
797 {
798 return func(num_entries, platforms, num_platforms);
799 }
800 else
801 {
802 return CL_OUT_OF_RESOURCES;
803 }
804}
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100805
806cl_int
807clGetKernelWorkGroupInfo(cl_kernel kernel,
808 cl_device_id device,
809 cl_kernel_work_group_info param_name,
810 size_t param_value_size,
811 void *param_value,
812 size_t *param_value_size_ret)
813{
814 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000815 auto func = arm_compute::CLSymbols::get().clGetKernelWorkGroupInfo_ptr;
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100816 if(func != nullptr)
817 {
818 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
819 }
820 else
821 {
822 return CL_OUT_OF_RESOURCES;
823 }
824}
Gian Marco85e6f512018-02-01 16:57:48 +0000825
826cl_int
827clGetCommandQueueInfo(cl_command_queue command_queue,
828 cl_command_queue_info param_name,
829 size_t param_value_size,
830 void *param_value,
831 size_t *param_value_size_ret)
832{
833 arm_compute::CLSymbols::get().load_default();
834 auto func = arm_compute::CLSymbols::get().clGetCommandQueueInfo_ptr;
835 if(func != nullptr)
836 {
837 return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
838 }
839 else
840 {
841 return CL_OUT_OF_RESOURCES;
842 }
843}
844
845cl_int
846clGetKernelInfo(cl_kernel kernel,
847 cl_kernel_info param_name,
848 size_t param_value_size,
849 void *param_value,
850 size_t *param_value_size_ret)
851{
852 arm_compute::CLSymbols::get().load_default();
853 auto func = arm_compute::CLSymbols::get().clGetKernelInfo_ptr;
854 if(func != nullptr)
855 {
856 return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
857 }
858 else
859 {
860 return CL_OUT_OF_RESOURCES;
861 }
862}
863
864cl_int
865clGetEventProfilingInfo(cl_event event,
866 cl_profiling_info param_name,
867 size_t param_value_size,
868 void *param_value,
869 size_t *param_value_size_ret)
870{
871 arm_compute::CLSymbols::get().load_default();
872 auto func = arm_compute::CLSymbols::get().clGetEventProfilingInfo_ptr;
873 if(func != nullptr)
874 {
875 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
876 }
877 else
878 {
879 return CL_OUT_OF_RESOURCES;
880 }
Anthony Barbierf5dcf792018-02-28 18:04:45 +0000881}