blob: 1ce1b526d72a6b7f412daf3769decca711b01f65 [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
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
30#include <dlfcn.h>
31#include <iostream>
32
Moritz Pflanzer725788e2017-07-07 15:35:56 +010033namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034{
Moritz Pflanzer725788e2017-07-07 15:35:56 +010035CLSymbols &CLSymbols::get()
36{
37 static CLSymbols symbols;
38 return symbols;
39}
40
41bool CLSymbols::load_default()
42{
43 static const std::vector<std::string> libraries{ "libOpenCL.so", "libGLES_mali.so", "libmali.so" };
44
45 if(_loaded.first)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010046 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010047 return _loaded.second;
48 }
49
50 // Indicate that default loading has been tried
51 _loaded.first = true;
52
53 for(const auto &lib : libraries)
54 {
55 if(load(lib))
Anthony Barbier6ff3b192017-09-04 18:44:23 +010056 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010057 return true;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010058 }
59 }
60
Moritz Pflanzer725788e2017-07-07 15:35:56 +010061 std::cerr << "Couldn't find any OpenCL library.\n";
62 return false;
63}
64
65bool CLSymbols::load(const std::string &library)
66{
Georgios Pinitas0ec65b82019-07-11 13:12:46 +000067 void *handle = dlopen(library.c_str(), RTLD_LAZY | RTLD_LOCAL);
Moritz Pflanzer725788e2017-07-07 15:35:56 +010068
69 if(handle == nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010070 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010071 std::cerr << "Can't load " << library << ": " << dlerror() << "\n";
72 // Set status of loading to failed
73 _loaded.second = false;
74 return false;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010075 }
76
Anthony Barbier58c4ff12017-11-09 09:15:32 +000077#define LOAD_FUNCTION_PTR(func_name, handle) \
78 func_name##_ptr = reinterpret_cast<decltype(func_name) *>(dlsym(handle, #func_name));
79
Anthony Barbierb6eb3532018-08-08 13:20:04 +010080 LOAD_FUNCTION_PTR(clCreateContext, handle);
Anthony Barbiera9e15332017-12-22 16:37:30 +000081 LOAD_FUNCTION_PTR(clCreateContextFromType, handle);
82 LOAD_FUNCTION_PTR(clCreateCommandQueue, handle);
83 LOAD_FUNCTION_PTR(clGetContextInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +000084 LOAD_FUNCTION_PTR(clBuildProgram, handle);
85 LOAD_FUNCTION_PTR(clEnqueueNDRangeKernel, handle);
86 LOAD_FUNCTION_PTR(clSetKernelArg, handle);
87 LOAD_FUNCTION_PTR(clReleaseKernel, handle);
88 LOAD_FUNCTION_PTR(clCreateProgramWithSource, handle);
89 LOAD_FUNCTION_PTR(clCreateBuffer, handle);
90 LOAD_FUNCTION_PTR(clRetainKernel, handle);
91 LOAD_FUNCTION_PTR(clCreateKernel, handle);
92 LOAD_FUNCTION_PTR(clGetProgramInfo, handle);
93 LOAD_FUNCTION_PTR(clFlush, handle);
94 LOAD_FUNCTION_PTR(clFinish, handle);
95 LOAD_FUNCTION_PTR(clReleaseProgram, handle);
96 LOAD_FUNCTION_PTR(clRetainContext, handle);
97 LOAD_FUNCTION_PTR(clCreateProgramWithBinary, handle);
98 LOAD_FUNCTION_PTR(clReleaseCommandQueue, handle);
99 LOAD_FUNCTION_PTR(clEnqueueMapBuffer, handle);
100 LOAD_FUNCTION_PTR(clRetainProgram, handle);
101 LOAD_FUNCTION_PTR(clGetProgramBuildInfo, handle);
102 LOAD_FUNCTION_PTR(clEnqueueReadBuffer, handle);
103 LOAD_FUNCTION_PTR(clEnqueueWriteBuffer, handle);
104 LOAD_FUNCTION_PTR(clReleaseEvent, handle);
105 LOAD_FUNCTION_PTR(clReleaseContext, handle);
106 LOAD_FUNCTION_PTR(clRetainCommandQueue, handle);
107 LOAD_FUNCTION_PTR(clEnqueueUnmapMemObject, handle);
108 LOAD_FUNCTION_PTR(clRetainMemObject, handle);
109 LOAD_FUNCTION_PTR(clReleaseMemObject, handle);
110 LOAD_FUNCTION_PTR(clGetDeviceInfo, handle);
111 LOAD_FUNCTION_PTR(clGetDeviceIDs, handle);
Georgios Pinitasdf310362018-11-14 13:16:56 +0000112 LOAD_FUNCTION_PTR(clGetMemObjectInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000113 LOAD_FUNCTION_PTR(clRetainEvent, handle);
114 LOAD_FUNCTION_PTR(clGetPlatformIDs, handle);
115 LOAD_FUNCTION_PTR(clGetKernelWorkGroupInfo, handle);
Gian Marco85e6f512018-02-01 16:57:48 +0000116 LOAD_FUNCTION_PTR(clGetCommandQueueInfo, handle);
117 LOAD_FUNCTION_PTR(clGetKernelInfo, handle);
118 LOAD_FUNCTION_PTR(clGetEventProfilingInfo, handle);
Pablo Telloe86a09f2018-01-11 15:44:48 +0000119 LOAD_FUNCTION_PTR(clSVMAlloc, handle);
120 LOAD_FUNCTION_PTR(clSVMFree, handle);
121 LOAD_FUNCTION_PTR(clEnqueueSVMMap, handle);
122 LOAD_FUNCTION_PTR(clEnqueueSVMUnmap, handle);
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100123 LOAD_FUNCTION_PTR(clEnqueueMarker, handle);
124 LOAD_FUNCTION_PTR(clWaitForEvents, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000125
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100126 // Third-party extensions
127 LOAD_FUNCTION_PTR(clImportMemoryARM, handle);
128
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000129#undef LOAD_FUNCTION_PTR
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100130
Anthony Barbier7b43d312017-12-14 10:58:47 +0000131 //Don't call dlclose(handle) or all the symbols will be unloaded !
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100132
133 // Disable default loading and set status to successful
134 _loaded = std::make_pair(true, true);
135
136 return true;
137}
138
139bool opencl_is_available()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100140{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100141 CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000142 return CLSymbols::get().clBuildProgram_ptr != nullptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100143}
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100144} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100145
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100146cl_int clEnqueueMarker(cl_command_queue command_queue,
147 cl_event *event)
148{
149 arm_compute::CLSymbols::get().load_default();
150 auto func = arm_compute::CLSymbols::get().clEnqueueMarker_ptr;
151 if(func != nullptr)
152 {
153 return func(command_queue, event);
154 }
155 else
156 {
157 return CL_OUT_OF_RESOURCES;
158 }
159}
160
161cl_int clWaitForEvents(cl_uint num_events,
162 const cl_event *event_list)
163{
164 arm_compute::CLSymbols::get().load_default();
165 auto func = arm_compute::CLSymbols::get().clWaitForEvents_ptr;
166 if(func != nullptr)
167 {
168 return func(num_events, event_list);
169 }
170 else
171 {
172 return CL_OUT_OF_RESOURCES;
173 }
174}
175
Pablo Telloe86a09f2018-01-11 15:44:48 +0000176cl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags flags, void *svm_ptr,
177 size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
178{
179 arm_compute::CLSymbols::get().load_default();
180 auto func = arm_compute::CLSymbols::get().clEnqueueSVMMap_ptr;
181 if(func != nullptr)
182 {
183 return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
184 }
185 else
186 {
187 return CL_OUT_OF_RESOURCES;
188 }
189}
190
191cl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *svm_ptr, cl_uint num_events_in_wait_list,
192 const cl_event *event_wait_list, cl_event *event)
193{
194 arm_compute::CLSymbols::get().load_default();
195 auto func = arm_compute::CLSymbols::get().clEnqueueSVMUnmap_ptr;
196 if(func != nullptr)
197 {
198 return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
199 }
200 else
201 {
202 return CL_OUT_OF_RESOURCES;
203 }
204}
205
206void *clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
207{
208 arm_compute::CLSymbols::get().load_default();
209 auto func = arm_compute::CLSymbols::get().clSVMAlloc_ptr;
210 if(func != nullptr)
211 {
212 return func(context, flags, size, alignment);
213 }
214 else
215 {
216 return nullptr;
217 }
218}
219
220void clSVMFree(cl_context context, void *svm_pointer)
221{
222 arm_compute::CLSymbols::get().load_default();
223 auto func = arm_compute::CLSymbols::get().clSVMFree_ptr;
224 if(func != nullptr)
225 {
226 func(context, svm_pointer);
227 }
228}
229
Anthony Barbiera9e15332017-12-22 16:37:30 +0000230cl_int clGetContextInfo(cl_context context,
231 cl_context_info param_name,
232 size_t param_value_size,
233 void *param_value,
234 size_t *param_value_size_ret)
235{
236 arm_compute::CLSymbols::get().load_default();
237 auto func = arm_compute::CLSymbols::get().clGetContextInfo_ptr;
238 if(func != nullptr)
239 {
240 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
241 }
242 else
243 {
244 return CL_OUT_OF_RESOURCES;
245 }
246}
247
248cl_command_queue clCreateCommandQueue(cl_context context,
249 cl_device_id device,
250 cl_command_queue_properties properties,
251 cl_int *errcode_ret)
252{
253 arm_compute::CLSymbols::get().load_default();
254 auto func = arm_compute::CLSymbols::get().clCreateCommandQueue_ptr;
255 if(func != nullptr)
256 {
257 return func(context, device, properties, errcode_ret);
258 }
259 else
260 {
261 return nullptr;
262 }
263}
264
Anthony Barbierb6eb3532018-08-08 13:20:04 +0100265cl_context clCreateContext(
266 const cl_context_properties *properties,
267 cl_uint num_devices,
268 const cl_device_id *devices,
269 void (*pfn_notify)(const char *, const void *, size_t, void *),
270 void *user_data,
271 cl_int *errcode_ret)
272{
273 arm_compute::CLSymbols::get().load_default();
274 auto func = arm_compute::CLSymbols::get().clCreateContext_ptr;
275 if(func != nullptr)
276 {
277 return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
278 }
279 else
280 {
281 return nullptr;
282 }
283}
284
Anthony Barbiera9e15332017-12-22 16:37:30 +0000285cl_context clCreateContextFromType(const cl_context_properties *properties,
286 cl_device_type device_type,
287 void (*pfn_notify)(const char *, const void *, size_t, void *),
288 void *user_data,
289 cl_int *errcode_ret)
290{
291 arm_compute::CLSymbols::get().load_default();
292 auto func = arm_compute::CLSymbols::get().clCreateContextFromType_ptr;
293 if(func != nullptr)
294 {
295 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
296 }
297 else
298 {
299 return nullptr;
300 }
301}
302
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100303cl_int clBuildProgram(
304 cl_program program,
305 cl_uint num_devices,
306 const cl_device_id *device_list,
307 const char *options,
308 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
309 void *user_data)
310{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100311 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000312 auto func = arm_compute::CLSymbols::get().clBuildProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100313 if(func != nullptr)
314 {
315 return func(program, num_devices, device_list, options, pfn_notify, user_data);
316 }
317 else
318 {
319 return CL_OUT_OF_RESOURCES;
320 }
321}
322
323cl_int clEnqueueNDRangeKernel(
324 cl_command_queue command_queue,
325 cl_kernel kernel,
326 cl_uint work_dim,
327 const size_t *global_work_offset,
328 const size_t *global_work_size,
329 const size_t *local_work_size,
330 cl_uint num_events_in_wait_list,
331 const cl_event *event_wait_list,
332 cl_event *event)
333{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100334 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000335 auto func = arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100336 if(func != nullptr)
337 {
338 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);
339 }
340 else
341 {
342 return CL_OUT_OF_RESOURCES;
343 }
344}
345
346cl_int clSetKernelArg(
347 cl_kernel kernel,
348 cl_uint arg_index,
349 size_t arg_size,
350 const void *arg_value)
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().clSetKernelArg_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100354 if(func != nullptr)
355 {
356 return func(kernel, arg_index, arg_size, arg_value);
357 }
358 else
359 {
360 return CL_OUT_OF_RESOURCES;
361 }
362}
363
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100364cl_int clRetainMemObject(cl_mem memobj)
365{
366 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000367 auto func = arm_compute::CLSymbols::get().clRetainMemObject_ptr;
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100368 if(func != nullptr)
369 {
370 return func(memobj);
371 }
372 else
373 {
374 return CL_OUT_OF_RESOURCES;
375 }
376}
377
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100378cl_int clReleaseMemObject(cl_mem memobj)
379{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100380 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000381 auto func = arm_compute::CLSymbols::get().clReleaseMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100382 if(func != nullptr)
383 {
384 return func(memobj);
385 }
386 else
387 {
388 return CL_OUT_OF_RESOURCES;
389 }
390}
391
392cl_int clEnqueueUnmapMemObject(
393 cl_command_queue command_queue,
394 cl_mem memobj,
395 void *mapped_ptr,
396 cl_uint num_events_in_wait_list,
397 const cl_event *event_wait_list,
398 cl_event *event)
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().clEnqueueUnmapMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100402 if(func != nullptr)
403 {
404 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
405 }
406 else
407 {
408 return CL_OUT_OF_RESOURCES;
409 }
410}
411
412cl_int clRetainCommandQueue(cl_command_queue command_queue)
413{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100414 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000415 auto func = arm_compute::CLSymbols::get().clRetainCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100416 if(func != nullptr)
417 {
418 return func(command_queue);
419 }
420 else
421 {
422 return CL_OUT_OF_RESOURCES;
423 }
424}
425
426cl_int clReleaseContext(cl_context context)
427{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100428 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000429 auto func = arm_compute::CLSymbols::get().clReleaseContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100430 if(func != nullptr)
431 {
432 return func(context);
433 }
434 else
435 {
436 return CL_OUT_OF_RESOURCES;
437 }
438}
439cl_int clReleaseEvent(cl_event event)
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().clReleaseEvent_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100443 if(func != nullptr)
444 {
445 return func(event);
446 }
447 else
448 {
449 return CL_OUT_OF_RESOURCES;
450 }
451}
452
453cl_int clEnqueueWriteBuffer(
454 cl_command_queue command_queue,
455 cl_mem buffer,
456 cl_bool blocking_write,
457 size_t offset,
458 size_t size,
459 const void *ptr,
460 cl_uint num_events_in_wait_list,
461 const cl_event *event_wait_list,
462 cl_event *event)
463{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100464 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000465 auto func = arm_compute::CLSymbols::get().clEnqueueWriteBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100466 if(func != nullptr)
467 {
468 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
469 }
470 else
471 {
472 return CL_OUT_OF_RESOURCES;
473 }
474}
475
476cl_int clEnqueueReadBuffer(
477 cl_command_queue command_queue,
478 cl_mem buffer,
479 cl_bool blocking_read,
480 size_t offset,
481 size_t size,
482 void *ptr,
483 cl_uint num_events_in_wait_list,
484 const cl_event *event_wait_list,
485 cl_event *event)
486{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100487 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000488 auto func = arm_compute::CLSymbols::get().clEnqueueReadBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100489 if(func != nullptr)
490 {
491 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
492 }
493 else
494 {
495 return CL_OUT_OF_RESOURCES;
496 }
497}
498
499cl_int clGetProgramBuildInfo(
500 cl_program program,
501 cl_device_id device,
502 cl_program_build_info param_name,
503 size_t param_value_size,
504 void *param_value,
505 size_t *param_value_size_ret)
506{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100507 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000508 auto func = arm_compute::CLSymbols::get().clGetProgramBuildInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100509 if(func != nullptr)
510 {
511 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
512 }
513 else
514 {
515 return CL_OUT_OF_RESOURCES;
516 }
517}
518
519cl_int clRetainProgram(cl_program program)
520{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100521 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000522 auto func = arm_compute::CLSymbols::get().clRetainProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100523 if(func != nullptr)
524 {
525 return func(program);
526 }
527 else
528 {
529 return CL_OUT_OF_RESOURCES;
530 }
531}
532
533void *clEnqueueMapBuffer(
534 cl_command_queue command_queue,
535 cl_mem buffer,
536 cl_bool blocking_map,
537 cl_map_flags map_flags,
538 size_t offset,
539 size_t size,
540 cl_uint num_events_in_wait_list,
541 const cl_event *event_wait_list,
542 cl_event *event,
543 cl_int *errcode_ret)
544{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100545 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000546 auto func = arm_compute::CLSymbols::get().clEnqueueMapBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100547 if(func != nullptr)
548 {
549 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
550 }
551 else
552 {
553 if(errcode_ret != nullptr)
554 {
555 *errcode_ret = CL_OUT_OF_RESOURCES;
556 }
557 return nullptr;
558 }
559}
560
561cl_int clReleaseCommandQueue(cl_command_queue command_queue)
562{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100563 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000564 auto func = arm_compute::CLSymbols::get().clReleaseCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100565 if(func != nullptr)
566 {
567 return func(command_queue);
568 }
569 else
570 {
571 return CL_OUT_OF_RESOURCES;
572 }
573}
574
575cl_program clCreateProgramWithBinary(
576 cl_context context,
577 cl_uint num_devices,
578 const cl_device_id *device_list,
579 const size_t *lengths,
580 const unsigned char **binaries,
581 cl_int *binary_status,
582 cl_int *errcode_ret)
583{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100584 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000585 auto func = arm_compute::CLSymbols::get().clCreateProgramWithBinary_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100586 if(func != nullptr)
587 {
588 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
589 }
590 else
591 {
592 if(errcode_ret != nullptr)
593 {
594 *errcode_ret = CL_OUT_OF_RESOURCES;
595 }
596 return nullptr;
597 }
598}
599
600cl_int clRetainContext(cl_context context)
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().clRetainContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100604 if(func != nullptr)
605 {
606 return func(context);
607 }
608 else
609 {
610 return CL_OUT_OF_RESOURCES;
611 }
612}
613
614cl_int clReleaseProgram(cl_program program)
615{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100616 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000617 auto func = arm_compute::CLSymbols::get().clReleaseProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100618 if(func != nullptr)
619 {
620 return func(program);
621 }
622 else
623 {
624 return CL_OUT_OF_RESOURCES;
625 }
626}
627
628cl_int clFlush(cl_command_queue command_queue)
629{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100630 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000631 auto func = arm_compute::CLSymbols::get().clFlush_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100632 if(func != nullptr)
633 {
634 return func(command_queue);
635 }
636 else
637 {
638 return CL_OUT_OF_RESOURCES;
639 }
640}
641
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100642cl_int clFinish(cl_command_queue command_queue)
643{
644 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000645 auto func = arm_compute::CLSymbols::get().clFinish_ptr;
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100646 if(func != nullptr)
647 {
648 return func(command_queue);
649 }
650 else
651 {
652 return CL_OUT_OF_RESOURCES;
653 }
654}
655
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100656cl_int clGetProgramInfo(
657 cl_program program,
658 cl_program_info param_name,
659 size_t param_value_size,
660 void *param_value,
661 size_t *param_value_size_ret)
662{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100663 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000664 auto func = arm_compute::CLSymbols::get().clGetProgramInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100665 if(func != nullptr)
666 {
667 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
668 }
669 else
670 {
671 return CL_OUT_OF_RESOURCES;
672 }
673}
674
675cl_kernel clCreateKernel(
676 cl_program program,
677 const char *kernel_name,
678 cl_int *errcode_ret)
679{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100680 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000681 auto func = arm_compute::CLSymbols::get().clCreateKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100682 if(func != nullptr)
683 {
684 return func(program, kernel_name, errcode_ret);
685 }
686 else
687 {
688 if(errcode_ret != nullptr)
689 {
690 *errcode_ret = CL_OUT_OF_RESOURCES;
691 }
692 return nullptr;
693 }
694}
695
696cl_int clRetainKernel(cl_kernel kernel)
697{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100698 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000699 auto func = arm_compute::CLSymbols::get().clRetainKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100700 if(func != nullptr)
701 {
702 return func(kernel);
703 }
704 else
705 {
706 return CL_OUT_OF_RESOURCES;
707 }
708}
709
710cl_mem clCreateBuffer(
711 cl_context context,
712 cl_mem_flags flags,
713 size_t size,
714 void *host_ptr,
715 cl_int *errcode_ret)
716{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100717 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000718 auto func = arm_compute::CLSymbols::get().clCreateBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100719 if(func != nullptr)
720 {
721 return func(context, flags, size, host_ptr, errcode_ret);
722 }
723 else
724 {
725 if(errcode_ret != nullptr)
726 {
727 *errcode_ret = CL_OUT_OF_RESOURCES;
728 }
729 return nullptr;
730 }
731}
732
733cl_program clCreateProgramWithSource(
734 cl_context context,
735 cl_uint count,
736 const char **strings,
737 const size_t *lengths,
738 cl_int *errcode_ret)
739{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100740 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000741 auto func = arm_compute::CLSymbols::get().clCreateProgramWithSource_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100742 if(func != nullptr)
743 {
744 return func(context, count, strings, lengths, errcode_ret);
745 }
746 else
747 {
748 if(errcode_ret != nullptr)
749 {
750 *errcode_ret = CL_OUT_OF_RESOURCES;
751 }
752 return nullptr;
753 }
754}
755
756cl_int clReleaseKernel(cl_kernel kernel)
757{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100758 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000759 auto func = arm_compute::CLSymbols::get().clReleaseKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100760 if(func != nullptr)
761 {
762 return func(kernel);
763 }
764 else
765 {
766 return CL_OUT_OF_RESOURCES;
767 }
768}
769
770cl_int clGetDeviceIDs(cl_platform_id platform,
771 cl_device_type device_type,
772 cl_uint num_entries,
773 cl_device_id *devices,
774 cl_uint *num_devices)
775{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100776 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000777 auto func = arm_compute::CLSymbols::get().clGetDeviceIDs_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100778 if(func != nullptr)
779 {
780 return func(platform, device_type, num_entries, devices, num_devices);
781 }
782 else
783 {
784 return CL_OUT_OF_RESOURCES;
785 }
786}
787
788cl_int clGetDeviceInfo(cl_device_id device,
789 cl_device_info param_name,
790 size_t param_value_size,
791 void *param_value,
792 size_t *param_value_size_ret)
793{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100794 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000795 auto func = arm_compute::CLSymbols::get().clGetDeviceInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100796 if(func != nullptr)
797 {
798 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
799 }
800 else
801 {
802 return CL_OUT_OF_RESOURCES;
803 }
804}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100805
Georgios Pinitasdf310362018-11-14 13:16:56 +0000806cl_int clGetMemObjectInfo(cl_mem memobj,
807 cl_mem_info param_name,
808 size_t param_value_size,
809 void *param_value,
810 size_t *param_value_size_ret)
811{
812 arm_compute::CLSymbols::get().load_default();
813 auto func = arm_compute::CLSymbols::get().clGetMemObjectInfo_ptr;
814 if(func != nullptr)
815 {
816 return func(memobj, param_name, param_value_size, param_value, param_value_size_ret);
817 }
818 else
819 {
820 return CL_OUT_OF_RESOURCES;
821 }
822}
823
Giorgio Arena9fe41442017-08-23 16:36:24 +0100824cl_int clRetainEvent(cl_event event)
825{
Moritz Pflanzer159b6da2017-09-20 16:03:35 +0100826 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000827 auto func = arm_compute::CLSymbols::get().clRetainEvent_ptr;
Giorgio Arena9fe41442017-08-23 16:36:24 +0100828 if(func != nullptr)
829 {
830 return func(event);
831 }
832 else
833 {
834 return CL_OUT_OF_RESOURCES;
835 }
836}
steniu01f01f9de2017-09-27 17:00:11 +0100837
838cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
839{
840 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000841 auto func = arm_compute::CLSymbols::get().clGetPlatformIDs_ptr;
steniu01f01f9de2017-09-27 17:00:11 +0100842 if(func != nullptr)
843 {
844 return func(num_entries, platforms, num_platforms);
845 }
846 else
847 {
848 return CL_OUT_OF_RESOURCES;
849 }
850}
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100851
852cl_int
853clGetKernelWorkGroupInfo(cl_kernel kernel,
854 cl_device_id device,
855 cl_kernel_work_group_info param_name,
856 size_t param_value_size,
857 void *param_value,
858 size_t *param_value_size_ret)
859{
860 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000861 auto func = arm_compute::CLSymbols::get().clGetKernelWorkGroupInfo_ptr;
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100862 if(func != nullptr)
863 {
864 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
865 }
866 else
867 {
868 return CL_OUT_OF_RESOURCES;
869 }
870}
Gian Marco85e6f512018-02-01 16:57:48 +0000871
872cl_int
873clGetCommandQueueInfo(cl_command_queue command_queue,
874 cl_command_queue_info param_name,
875 size_t param_value_size,
876 void *param_value,
877 size_t *param_value_size_ret)
878{
879 arm_compute::CLSymbols::get().load_default();
880 auto func = arm_compute::CLSymbols::get().clGetCommandQueueInfo_ptr;
881 if(func != nullptr)
882 {
883 return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
884 }
885 else
886 {
887 return CL_OUT_OF_RESOURCES;
888 }
889}
890
891cl_int
892clGetKernelInfo(cl_kernel kernel,
893 cl_kernel_info param_name,
894 size_t param_value_size,
895 void *param_value,
896 size_t *param_value_size_ret)
897{
898 arm_compute::CLSymbols::get().load_default();
899 auto func = arm_compute::CLSymbols::get().clGetKernelInfo_ptr;
900 if(func != nullptr)
901 {
902 return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
903 }
904 else
905 {
906 return CL_OUT_OF_RESOURCES;
907 }
908}
909
910cl_int
911clGetEventProfilingInfo(cl_event event,
912 cl_profiling_info param_name,
913 size_t param_value_size,
914 void *param_value,
915 size_t *param_value_size_ret)
916{
917 arm_compute::CLSymbols::get().load_default();
918 auto func = arm_compute::CLSymbols::get().clGetEventProfilingInfo_ptr;
919 if(func != nullptr)
920 {
921 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
922 }
923 else
924 {
925 return CL_OUT_OF_RESOURCES;
926 }
Anthony Barbierf5dcf792018-02-28 18:04:45 +0000927}
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100928
929cl_mem
930clImportMemoryARM(cl_context context,
931 cl_mem_flags flags,
932 const cl_import_properties_arm *properties,
933 void *memory,
934 size_t size,
935 cl_int *errcode_ret)
936{
937 arm_compute::CLSymbols::get().load_default();
938 auto func = arm_compute::CLSymbols::get().clImportMemoryARM_ptr;
939 if(func != nullptr)
940 {
941 return func(context, flags, properties, memory, size, errcode_ret);
942 }
943 else
944 {
945 if(errcode_ret != nullptr)
946 {
947 *errcode_ret = CL_OUT_OF_RESOURCES;
948 }
949 return nullptr;
950 }
951}