blob: 74c5b041d7cf1e418e54c3d26455fb779b0a4bde [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
Pablo Tellodb8485a2019-09-24 11:03:47 +010030#include "arm_compute/core/Error.h"
31
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032#include <dlfcn.h>
33#include <iostream>
34
Moritz Pflanzer725788e2017-07-07 15:35:56 +010035namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036{
Moritz Pflanzer725788e2017-07-07 15:35:56 +010037CLSymbols &CLSymbols::get()
38{
39 static CLSymbols symbols;
40 return symbols;
41}
42
43bool CLSymbols::load_default()
44{
45 static const std::vector<std::string> libraries{ "libOpenCL.so", "libGLES_mali.so", "libmali.so" };
46
47 if(_loaded.first)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010049 return _loaded.second;
50 }
51
52 // Indicate that default loading has been tried
53 _loaded.first = true;
54
55 for(const auto &lib : libraries)
56 {
57 if(load(lib))
Anthony Barbier6ff3b192017-09-04 18:44:23 +010058 {
Pablo Tellodb8485a2019-09-24 11:03:47 +010059 ARM_COMPUTE_ERROR_ON_MSG(this->clBuildProgram_ptr == nullptr, "Failed to load OpenCL symbols from shared library");
Moritz Pflanzer725788e2017-07-07 15:35:56 +010060 return true;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010061 }
62 }
63
Moritz Pflanzer725788e2017-07-07 15:35:56 +010064 std::cerr << "Couldn't find any OpenCL library.\n";
65 return false;
66}
67
68bool CLSymbols::load(const std::string &library)
69{
Georgios Pinitas0ec65b82019-07-11 13:12:46 +000070 void *handle = dlopen(library.c_str(), RTLD_LAZY | RTLD_LOCAL);
Moritz Pflanzer725788e2017-07-07 15:35:56 +010071
72 if(handle == nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010073 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010074 std::cerr << "Can't load " << library << ": " << dlerror() << "\n";
75 // Set status of loading to failed
76 _loaded.second = false;
77 return false;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010078 }
79
Anthony Barbier58c4ff12017-11-09 09:15:32 +000080#define LOAD_FUNCTION_PTR(func_name, handle) \
81 func_name##_ptr = reinterpret_cast<decltype(func_name) *>(dlsym(handle, #func_name));
82
Anthony Barbierb6eb3532018-08-08 13:20:04 +010083 LOAD_FUNCTION_PTR(clCreateContext, handle);
Anthony Barbiera9e15332017-12-22 16:37:30 +000084 LOAD_FUNCTION_PTR(clCreateContextFromType, handle);
85 LOAD_FUNCTION_PTR(clCreateCommandQueue, handle);
86 LOAD_FUNCTION_PTR(clGetContextInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +000087 LOAD_FUNCTION_PTR(clBuildProgram, handle);
88 LOAD_FUNCTION_PTR(clEnqueueNDRangeKernel, handle);
89 LOAD_FUNCTION_PTR(clSetKernelArg, handle);
90 LOAD_FUNCTION_PTR(clReleaseKernel, handle);
91 LOAD_FUNCTION_PTR(clCreateProgramWithSource, handle);
92 LOAD_FUNCTION_PTR(clCreateBuffer, handle);
93 LOAD_FUNCTION_PTR(clRetainKernel, handle);
94 LOAD_FUNCTION_PTR(clCreateKernel, handle);
95 LOAD_FUNCTION_PTR(clGetProgramInfo, handle);
96 LOAD_FUNCTION_PTR(clFlush, handle);
97 LOAD_FUNCTION_PTR(clFinish, handle);
98 LOAD_FUNCTION_PTR(clReleaseProgram, handle);
99 LOAD_FUNCTION_PTR(clRetainContext, handle);
100 LOAD_FUNCTION_PTR(clCreateProgramWithBinary, handle);
101 LOAD_FUNCTION_PTR(clReleaseCommandQueue, handle);
102 LOAD_FUNCTION_PTR(clEnqueueMapBuffer, handle);
103 LOAD_FUNCTION_PTR(clRetainProgram, handle);
104 LOAD_FUNCTION_PTR(clGetProgramBuildInfo, handle);
105 LOAD_FUNCTION_PTR(clEnqueueReadBuffer, handle);
106 LOAD_FUNCTION_PTR(clEnqueueWriteBuffer, handle);
107 LOAD_FUNCTION_PTR(clReleaseEvent, handle);
108 LOAD_FUNCTION_PTR(clReleaseContext, handle);
109 LOAD_FUNCTION_PTR(clRetainCommandQueue, handle);
110 LOAD_FUNCTION_PTR(clEnqueueUnmapMemObject, handle);
111 LOAD_FUNCTION_PTR(clRetainMemObject, handle);
112 LOAD_FUNCTION_PTR(clReleaseMemObject, handle);
113 LOAD_FUNCTION_PTR(clGetDeviceInfo, handle);
114 LOAD_FUNCTION_PTR(clGetDeviceIDs, handle);
Georgios Pinitasdf310362018-11-14 13:16:56 +0000115 LOAD_FUNCTION_PTR(clGetMemObjectInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000116 LOAD_FUNCTION_PTR(clRetainEvent, handle);
117 LOAD_FUNCTION_PTR(clGetPlatformIDs, handle);
118 LOAD_FUNCTION_PTR(clGetKernelWorkGroupInfo, handle);
Gian Marco85e6f512018-02-01 16:57:48 +0000119 LOAD_FUNCTION_PTR(clGetCommandQueueInfo, handle);
120 LOAD_FUNCTION_PTR(clGetKernelInfo, handle);
121 LOAD_FUNCTION_PTR(clGetEventProfilingInfo, handle);
Pablo Telloe86a09f2018-01-11 15:44:48 +0000122 LOAD_FUNCTION_PTR(clSVMAlloc, handle);
123 LOAD_FUNCTION_PTR(clSVMFree, handle);
124 LOAD_FUNCTION_PTR(clEnqueueSVMMap, handle);
125 LOAD_FUNCTION_PTR(clEnqueueSVMUnmap, handle);
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100126 LOAD_FUNCTION_PTR(clEnqueueMarker, handle);
127 LOAD_FUNCTION_PTR(clWaitForEvents, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000128
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100129 // Third-party extensions
130 LOAD_FUNCTION_PTR(clImportMemoryARM, handle);
131
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000132#undef LOAD_FUNCTION_PTR
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100133
Anthony Barbier7b43d312017-12-14 10:58:47 +0000134 //Don't call dlclose(handle) or all the symbols will be unloaded !
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100135
136 // Disable default loading and set status to successful
137 _loaded = std::make_pair(true, true);
138
139 return true;
140}
141
142bool opencl_is_available()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100143{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100144 CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000145 return CLSymbols::get().clBuildProgram_ptr != nullptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100146}
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100147} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100148
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100149cl_int clEnqueueMarker(cl_command_queue command_queue,
150 cl_event *event)
151{
152 arm_compute::CLSymbols::get().load_default();
153 auto func = arm_compute::CLSymbols::get().clEnqueueMarker_ptr;
154 if(func != nullptr)
155 {
156 return func(command_queue, event);
157 }
158 else
159 {
160 return CL_OUT_OF_RESOURCES;
161 }
162}
163
164cl_int clWaitForEvents(cl_uint num_events,
165 const cl_event *event_list)
166{
167 arm_compute::CLSymbols::get().load_default();
168 auto func = arm_compute::CLSymbols::get().clWaitForEvents_ptr;
169 if(func != nullptr)
170 {
171 return func(num_events, event_list);
172 }
173 else
174 {
175 return CL_OUT_OF_RESOURCES;
176 }
177}
178
Pablo Telloe86a09f2018-01-11 15:44:48 +0000179cl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags flags, void *svm_ptr,
180 size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
181{
182 arm_compute::CLSymbols::get().load_default();
183 auto func = arm_compute::CLSymbols::get().clEnqueueSVMMap_ptr;
184 if(func != nullptr)
185 {
186 return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
187 }
188 else
189 {
190 return CL_OUT_OF_RESOURCES;
191 }
192}
193
194cl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *svm_ptr, cl_uint num_events_in_wait_list,
195 const cl_event *event_wait_list, cl_event *event)
196{
197 arm_compute::CLSymbols::get().load_default();
198 auto func = arm_compute::CLSymbols::get().clEnqueueSVMUnmap_ptr;
199 if(func != nullptr)
200 {
201 return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
202 }
203 else
204 {
205 return CL_OUT_OF_RESOURCES;
206 }
207}
208
209void *clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
210{
211 arm_compute::CLSymbols::get().load_default();
212 auto func = arm_compute::CLSymbols::get().clSVMAlloc_ptr;
213 if(func != nullptr)
214 {
215 return func(context, flags, size, alignment);
216 }
217 else
218 {
219 return nullptr;
220 }
221}
222
223void clSVMFree(cl_context context, void *svm_pointer)
224{
225 arm_compute::CLSymbols::get().load_default();
226 auto func = arm_compute::CLSymbols::get().clSVMFree_ptr;
227 if(func != nullptr)
228 {
229 func(context, svm_pointer);
230 }
231}
232
Anthony Barbiera9e15332017-12-22 16:37:30 +0000233cl_int clGetContextInfo(cl_context context,
234 cl_context_info param_name,
235 size_t param_value_size,
236 void *param_value,
237 size_t *param_value_size_ret)
238{
239 arm_compute::CLSymbols::get().load_default();
240 auto func = arm_compute::CLSymbols::get().clGetContextInfo_ptr;
241 if(func != nullptr)
242 {
243 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
244 }
245 else
246 {
247 return CL_OUT_OF_RESOURCES;
248 }
249}
250
251cl_command_queue clCreateCommandQueue(cl_context context,
252 cl_device_id device,
253 cl_command_queue_properties properties,
254 cl_int *errcode_ret)
255{
256 arm_compute::CLSymbols::get().load_default();
257 auto func = arm_compute::CLSymbols::get().clCreateCommandQueue_ptr;
258 if(func != nullptr)
259 {
260 return func(context, device, properties, errcode_ret);
261 }
262 else
263 {
264 return nullptr;
265 }
266}
267
Anthony Barbierb6eb3532018-08-08 13:20:04 +0100268cl_context clCreateContext(
269 const cl_context_properties *properties,
270 cl_uint num_devices,
271 const cl_device_id *devices,
272 void (*pfn_notify)(const char *, const void *, size_t, void *),
273 void *user_data,
274 cl_int *errcode_ret)
275{
276 arm_compute::CLSymbols::get().load_default();
277 auto func = arm_compute::CLSymbols::get().clCreateContext_ptr;
278 if(func != nullptr)
279 {
280 return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
281 }
282 else
283 {
284 return nullptr;
285 }
286}
287
Anthony Barbiera9e15332017-12-22 16:37:30 +0000288cl_context clCreateContextFromType(const cl_context_properties *properties,
289 cl_device_type device_type,
290 void (*pfn_notify)(const char *, const void *, size_t, void *),
291 void *user_data,
292 cl_int *errcode_ret)
293{
294 arm_compute::CLSymbols::get().load_default();
295 auto func = arm_compute::CLSymbols::get().clCreateContextFromType_ptr;
296 if(func != nullptr)
297 {
298 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
299 }
300 else
301 {
302 return nullptr;
303 }
304}
305
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100306cl_int clBuildProgram(
307 cl_program program,
308 cl_uint num_devices,
309 const cl_device_id *device_list,
310 const char *options,
311 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
312 void *user_data)
313{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100314 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000315 auto func = arm_compute::CLSymbols::get().clBuildProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100316 if(func != nullptr)
317 {
318 return func(program, num_devices, device_list, options, pfn_notify, user_data);
319 }
320 else
321 {
322 return CL_OUT_OF_RESOURCES;
323 }
324}
325
326cl_int clEnqueueNDRangeKernel(
327 cl_command_queue command_queue,
328 cl_kernel kernel,
329 cl_uint work_dim,
330 const size_t *global_work_offset,
331 const size_t *global_work_size,
332 const size_t *local_work_size,
333 cl_uint num_events_in_wait_list,
334 const cl_event *event_wait_list,
335 cl_event *event)
336{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100337 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000338 auto func = arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100339 if(func != nullptr)
340 {
341 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);
342 }
343 else
344 {
345 return CL_OUT_OF_RESOURCES;
346 }
347}
348
349cl_int clSetKernelArg(
350 cl_kernel kernel,
351 cl_uint arg_index,
352 size_t arg_size,
353 const void *arg_value)
354{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100355 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000356 auto func = arm_compute::CLSymbols::get().clSetKernelArg_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100357 if(func != nullptr)
358 {
359 return func(kernel, arg_index, arg_size, arg_value);
360 }
361 else
362 {
363 return CL_OUT_OF_RESOURCES;
364 }
365}
366
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100367cl_int clRetainMemObject(cl_mem memobj)
368{
369 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000370 auto func = arm_compute::CLSymbols::get().clRetainMemObject_ptr;
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100371 if(func != nullptr)
372 {
373 return func(memobj);
374 }
375 else
376 {
377 return CL_OUT_OF_RESOURCES;
378 }
379}
380
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100381cl_int clReleaseMemObject(cl_mem memobj)
382{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100383 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000384 auto func = arm_compute::CLSymbols::get().clReleaseMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100385 if(func != nullptr)
386 {
387 return func(memobj);
388 }
389 else
390 {
391 return CL_OUT_OF_RESOURCES;
392 }
393}
394
395cl_int clEnqueueUnmapMemObject(
396 cl_command_queue command_queue,
397 cl_mem memobj,
398 void *mapped_ptr,
399 cl_uint num_events_in_wait_list,
400 const cl_event *event_wait_list,
401 cl_event *event)
402{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100403 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000404 auto func = arm_compute::CLSymbols::get().clEnqueueUnmapMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100405 if(func != nullptr)
406 {
407 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
408 }
409 else
410 {
411 return CL_OUT_OF_RESOURCES;
412 }
413}
414
415cl_int clRetainCommandQueue(cl_command_queue command_queue)
416{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100417 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000418 auto func = arm_compute::CLSymbols::get().clRetainCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100419 if(func != nullptr)
420 {
421 return func(command_queue);
422 }
423 else
424 {
425 return CL_OUT_OF_RESOURCES;
426 }
427}
428
429cl_int clReleaseContext(cl_context context)
430{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100431 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000432 auto func = arm_compute::CLSymbols::get().clReleaseContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100433 if(func != nullptr)
434 {
435 return func(context);
436 }
437 else
438 {
439 return CL_OUT_OF_RESOURCES;
440 }
441}
442cl_int clReleaseEvent(cl_event event)
443{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100444 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000445 auto func = arm_compute::CLSymbols::get().clReleaseEvent_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100446 if(func != nullptr)
447 {
448 return func(event);
449 }
450 else
451 {
452 return CL_OUT_OF_RESOURCES;
453 }
454}
455
456cl_int clEnqueueWriteBuffer(
457 cl_command_queue command_queue,
458 cl_mem buffer,
459 cl_bool blocking_write,
460 size_t offset,
461 size_t size,
462 const void *ptr,
463 cl_uint num_events_in_wait_list,
464 const cl_event *event_wait_list,
465 cl_event *event)
466{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100467 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000468 auto func = arm_compute::CLSymbols::get().clEnqueueWriteBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100469 if(func != nullptr)
470 {
471 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
472 }
473 else
474 {
475 return CL_OUT_OF_RESOURCES;
476 }
477}
478
479cl_int clEnqueueReadBuffer(
480 cl_command_queue command_queue,
481 cl_mem buffer,
482 cl_bool blocking_read,
483 size_t offset,
484 size_t size,
485 void *ptr,
486 cl_uint num_events_in_wait_list,
487 const cl_event *event_wait_list,
488 cl_event *event)
489{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100490 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000491 auto func = arm_compute::CLSymbols::get().clEnqueueReadBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100492 if(func != nullptr)
493 {
494 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
495 }
496 else
497 {
498 return CL_OUT_OF_RESOURCES;
499 }
500}
501
502cl_int clGetProgramBuildInfo(
503 cl_program program,
504 cl_device_id device,
505 cl_program_build_info param_name,
506 size_t param_value_size,
507 void *param_value,
508 size_t *param_value_size_ret)
509{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100510 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000511 auto func = arm_compute::CLSymbols::get().clGetProgramBuildInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100512 if(func != nullptr)
513 {
514 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
515 }
516 else
517 {
518 return CL_OUT_OF_RESOURCES;
519 }
520}
521
522cl_int clRetainProgram(cl_program program)
523{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100524 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000525 auto func = arm_compute::CLSymbols::get().clRetainProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100526 if(func != nullptr)
527 {
528 return func(program);
529 }
530 else
531 {
532 return CL_OUT_OF_RESOURCES;
533 }
534}
535
536void *clEnqueueMapBuffer(
537 cl_command_queue command_queue,
538 cl_mem buffer,
539 cl_bool blocking_map,
540 cl_map_flags map_flags,
541 size_t offset,
542 size_t size,
543 cl_uint num_events_in_wait_list,
544 const cl_event *event_wait_list,
545 cl_event *event,
546 cl_int *errcode_ret)
547{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100548 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000549 auto func = arm_compute::CLSymbols::get().clEnqueueMapBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100550 if(func != nullptr)
551 {
552 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
553 }
554 else
555 {
556 if(errcode_ret != nullptr)
557 {
558 *errcode_ret = CL_OUT_OF_RESOURCES;
559 }
560 return nullptr;
561 }
562}
563
564cl_int clReleaseCommandQueue(cl_command_queue command_queue)
565{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100566 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000567 auto func = arm_compute::CLSymbols::get().clReleaseCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100568 if(func != nullptr)
569 {
570 return func(command_queue);
571 }
572 else
573 {
574 return CL_OUT_OF_RESOURCES;
575 }
576}
577
578cl_program clCreateProgramWithBinary(
579 cl_context context,
580 cl_uint num_devices,
581 const cl_device_id *device_list,
582 const size_t *lengths,
583 const unsigned char **binaries,
584 cl_int *binary_status,
585 cl_int *errcode_ret)
586{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100587 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000588 auto func = arm_compute::CLSymbols::get().clCreateProgramWithBinary_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100589 if(func != nullptr)
590 {
591 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
592 }
593 else
594 {
595 if(errcode_ret != nullptr)
596 {
597 *errcode_ret = CL_OUT_OF_RESOURCES;
598 }
599 return nullptr;
600 }
601}
602
603cl_int clRetainContext(cl_context context)
604{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100605 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000606 auto func = arm_compute::CLSymbols::get().clRetainContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100607 if(func != nullptr)
608 {
609 return func(context);
610 }
611 else
612 {
613 return CL_OUT_OF_RESOURCES;
614 }
615}
616
617cl_int clReleaseProgram(cl_program program)
618{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100619 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000620 auto func = arm_compute::CLSymbols::get().clReleaseProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100621 if(func != nullptr)
622 {
623 return func(program);
624 }
625 else
626 {
627 return CL_OUT_OF_RESOURCES;
628 }
629}
630
631cl_int clFlush(cl_command_queue command_queue)
632{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100633 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000634 auto func = arm_compute::CLSymbols::get().clFlush_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100635 if(func != nullptr)
636 {
637 return func(command_queue);
638 }
639 else
640 {
641 return CL_OUT_OF_RESOURCES;
642 }
643}
644
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100645cl_int clFinish(cl_command_queue command_queue)
646{
647 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000648 auto func = arm_compute::CLSymbols::get().clFinish_ptr;
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100649 if(func != nullptr)
650 {
651 return func(command_queue);
652 }
653 else
654 {
655 return CL_OUT_OF_RESOURCES;
656 }
657}
658
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100659cl_int clGetProgramInfo(
660 cl_program program,
661 cl_program_info param_name,
662 size_t param_value_size,
663 void *param_value,
664 size_t *param_value_size_ret)
665{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100666 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000667 auto func = arm_compute::CLSymbols::get().clGetProgramInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100668 if(func != nullptr)
669 {
670 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
671 }
672 else
673 {
674 return CL_OUT_OF_RESOURCES;
675 }
676}
677
678cl_kernel clCreateKernel(
679 cl_program program,
680 const char *kernel_name,
681 cl_int *errcode_ret)
682{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100683 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000684 auto func = arm_compute::CLSymbols::get().clCreateKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100685 if(func != nullptr)
686 {
687 return func(program, kernel_name, errcode_ret);
688 }
689 else
690 {
691 if(errcode_ret != nullptr)
692 {
693 *errcode_ret = CL_OUT_OF_RESOURCES;
694 }
695 return nullptr;
696 }
697}
698
699cl_int clRetainKernel(cl_kernel kernel)
700{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100701 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000702 auto func = arm_compute::CLSymbols::get().clRetainKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100703 if(func != nullptr)
704 {
705 return func(kernel);
706 }
707 else
708 {
709 return CL_OUT_OF_RESOURCES;
710 }
711}
712
713cl_mem clCreateBuffer(
714 cl_context context,
715 cl_mem_flags flags,
716 size_t size,
717 void *host_ptr,
718 cl_int *errcode_ret)
719{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100720 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000721 auto func = arm_compute::CLSymbols::get().clCreateBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100722 if(func != nullptr)
723 {
724 return func(context, flags, size, host_ptr, errcode_ret);
725 }
726 else
727 {
728 if(errcode_ret != nullptr)
729 {
730 *errcode_ret = CL_OUT_OF_RESOURCES;
731 }
732 return nullptr;
733 }
734}
735
736cl_program clCreateProgramWithSource(
737 cl_context context,
738 cl_uint count,
739 const char **strings,
740 const size_t *lengths,
741 cl_int *errcode_ret)
742{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100743 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000744 auto func = arm_compute::CLSymbols::get().clCreateProgramWithSource_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100745 if(func != nullptr)
746 {
747 return func(context, count, strings, lengths, errcode_ret);
748 }
749 else
750 {
751 if(errcode_ret != nullptr)
752 {
753 *errcode_ret = CL_OUT_OF_RESOURCES;
754 }
755 return nullptr;
756 }
757}
758
759cl_int clReleaseKernel(cl_kernel kernel)
760{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100761 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000762 auto func = arm_compute::CLSymbols::get().clReleaseKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100763 if(func != nullptr)
764 {
765 return func(kernel);
766 }
767 else
768 {
769 return CL_OUT_OF_RESOURCES;
770 }
771}
772
773cl_int clGetDeviceIDs(cl_platform_id platform,
774 cl_device_type device_type,
775 cl_uint num_entries,
776 cl_device_id *devices,
777 cl_uint *num_devices)
778{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100779 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000780 auto func = arm_compute::CLSymbols::get().clGetDeviceIDs_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100781 if(func != nullptr)
782 {
783 return func(platform, device_type, num_entries, devices, num_devices);
784 }
785 else
786 {
787 return CL_OUT_OF_RESOURCES;
788 }
789}
790
791cl_int clGetDeviceInfo(cl_device_id device,
792 cl_device_info param_name,
793 size_t param_value_size,
794 void *param_value,
795 size_t *param_value_size_ret)
796{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100797 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000798 auto func = arm_compute::CLSymbols::get().clGetDeviceInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100799 if(func != nullptr)
800 {
801 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
802 }
803 else
804 {
805 return CL_OUT_OF_RESOURCES;
806 }
807}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100808
Georgios Pinitasdf310362018-11-14 13:16:56 +0000809cl_int clGetMemObjectInfo(cl_mem memobj,
810 cl_mem_info param_name,
811 size_t param_value_size,
812 void *param_value,
813 size_t *param_value_size_ret)
814{
815 arm_compute::CLSymbols::get().load_default();
816 auto func = arm_compute::CLSymbols::get().clGetMemObjectInfo_ptr;
817 if(func != nullptr)
818 {
819 return func(memobj, param_name, param_value_size, param_value, param_value_size_ret);
820 }
821 else
822 {
823 return CL_OUT_OF_RESOURCES;
824 }
825}
826
Giorgio Arena9fe41442017-08-23 16:36:24 +0100827cl_int clRetainEvent(cl_event event)
828{
Moritz Pflanzer159b6da2017-09-20 16:03:35 +0100829 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000830 auto func = arm_compute::CLSymbols::get().clRetainEvent_ptr;
Giorgio Arena9fe41442017-08-23 16:36:24 +0100831 if(func != nullptr)
832 {
833 return func(event);
834 }
835 else
836 {
837 return CL_OUT_OF_RESOURCES;
838 }
839}
steniu01f01f9de2017-09-27 17:00:11 +0100840
841cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
842{
843 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000844 auto func = arm_compute::CLSymbols::get().clGetPlatformIDs_ptr;
steniu01f01f9de2017-09-27 17:00:11 +0100845 if(func != nullptr)
846 {
847 return func(num_entries, platforms, num_platforms);
848 }
849 else
850 {
851 return CL_OUT_OF_RESOURCES;
852 }
853}
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100854
855cl_int
856clGetKernelWorkGroupInfo(cl_kernel kernel,
857 cl_device_id device,
858 cl_kernel_work_group_info param_name,
859 size_t param_value_size,
860 void *param_value,
861 size_t *param_value_size_ret)
862{
863 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000864 auto func = arm_compute::CLSymbols::get().clGetKernelWorkGroupInfo_ptr;
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100865 if(func != nullptr)
866 {
867 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
868 }
869 else
870 {
871 return CL_OUT_OF_RESOURCES;
872 }
873}
Gian Marco85e6f512018-02-01 16:57:48 +0000874
875cl_int
876clGetCommandQueueInfo(cl_command_queue command_queue,
877 cl_command_queue_info param_name,
878 size_t param_value_size,
879 void *param_value,
880 size_t *param_value_size_ret)
881{
882 arm_compute::CLSymbols::get().load_default();
883 auto func = arm_compute::CLSymbols::get().clGetCommandQueueInfo_ptr;
884 if(func != nullptr)
885 {
886 return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
887 }
888 else
889 {
890 return CL_OUT_OF_RESOURCES;
891 }
892}
893
894cl_int
895clGetKernelInfo(cl_kernel kernel,
896 cl_kernel_info param_name,
897 size_t param_value_size,
898 void *param_value,
899 size_t *param_value_size_ret)
900{
901 arm_compute::CLSymbols::get().load_default();
902 auto func = arm_compute::CLSymbols::get().clGetKernelInfo_ptr;
903 if(func != nullptr)
904 {
905 return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
906 }
907 else
908 {
909 return CL_OUT_OF_RESOURCES;
910 }
911}
912
913cl_int
914clGetEventProfilingInfo(cl_event event,
915 cl_profiling_info param_name,
916 size_t param_value_size,
917 void *param_value,
918 size_t *param_value_size_ret)
919{
920 arm_compute::CLSymbols::get().load_default();
921 auto func = arm_compute::CLSymbols::get().clGetEventProfilingInfo_ptr;
922 if(func != nullptr)
923 {
924 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
925 }
926 else
927 {
928 return CL_OUT_OF_RESOURCES;
929 }
Anthony Barbierf5dcf792018-02-28 18:04:45 +0000930}
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100931
932cl_mem
933clImportMemoryARM(cl_context context,
934 cl_mem_flags flags,
935 const cl_import_properties_arm *properties,
936 void *memory,
937 size_t size,
938 cl_int *errcode_ret)
939{
940 arm_compute::CLSymbols::get().load_default();
941 auto func = arm_compute::CLSymbols::get().clImportMemoryARM_ptr;
942 if(func != nullptr)
943 {
944 return func(context, flags, properties, memory, size, errcode_ret);
945 }
946 else
947 {
948 if(errcode_ret != nullptr)
949 {
950 *errcode_ret = CL_OUT_OF_RESOURCES;
951 }
952 return nullptr;
953 }
Pablo Tellodb8485a2019-09-24 11:03:47 +0100954}