blob: 9a3e344f1fc844b378ae2e9a30839e1e91dc9313 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Georgios Pinitas0b192e82020-02-20 17:09:28 +00002 * Copyright (c) 2017-2020 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{
Georgios Pinitas0b192e82020-02-20 17:09:28 +000037CLSymbols::CLSymbols() noexcept(false)
38 : _loaded(
39{
40 false, false
41})
42{
43}
44
Moritz Pflanzer725788e2017-07-07 15:35:56 +010045CLSymbols &CLSymbols::get()
46{
47 static CLSymbols symbols;
48 return symbols;
49}
50
51bool CLSymbols::load_default()
52{
53 static const std::vector<std::string> libraries{ "libOpenCL.so", "libGLES_mali.so", "libmali.so" };
54
55 if(_loaded.first)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010056 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010057 return _loaded.second;
58 }
59
60 // Indicate that default loading has been tried
61 _loaded.first = true;
62
63 for(const auto &lib : libraries)
64 {
65 if(load(lib))
Anthony Barbier6ff3b192017-09-04 18:44:23 +010066 {
Pablo Tellodb8485a2019-09-24 11:03:47 +010067 ARM_COMPUTE_ERROR_ON_MSG(this->clBuildProgram_ptr == nullptr, "Failed to load OpenCL symbols from shared library");
Moritz Pflanzer725788e2017-07-07 15:35:56 +010068 return true;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010069 }
70 }
71
Moritz Pflanzer725788e2017-07-07 15:35:56 +010072 std::cerr << "Couldn't find any OpenCL library.\n";
73 return false;
74}
75
76bool CLSymbols::load(const std::string &library)
77{
Georgios Pinitas0ec65b82019-07-11 13:12:46 +000078 void *handle = dlopen(library.c_str(), RTLD_LAZY | RTLD_LOCAL);
Moritz Pflanzer725788e2017-07-07 15:35:56 +010079
80 if(handle == nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010081 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010082 std::cerr << "Can't load " << library << ": " << dlerror() << "\n";
83 // Set status of loading to failed
84 _loaded.second = false;
85 return false;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010086 }
87
Anthony Barbier58c4ff12017-11-09 09:15:32 +000088#define LOAD_FUNCTION_PTR(func_name, handle) \
89 func_name##_ptr = reinterpret_cast<decltype(func_name) *>(dlsym(handle, #func_name));
90
Anthony Barbierb6eb3532018-08-08 13:20:04 +010091 LOAD_FUNCTION_PTR(clCreateContext, handle);
Anthony Barbiera9e15332017-12-22 16:37:30 +000092 LOAD_FUNCTION_PTR(clCreateContextFromType, handle);
93 LOAD_FUNCTION_PTR(clCreateCommandQueue, handle);
94 LOAD_FUNCTION_PTR(clGetContextInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +000095 LOAD_FUNCTION_PTR(clBuildProgram, handle);
96 LOAD_FUNCTION_PTR(clEnqueueNDRangeKernel, handle);
97 LOAD_FUNCTION_PTR(clSetKernelArg, handle);
98 LOAD_FUNCTION_PTR(clReleaseKernel, handle);
99 LOAD_FUNCTION_PTR(clCreateProgramWithSource, handle);
100 LOAD_FUNCTION_PTR(clCreateBuffer, handle);
101 LOAD_FUNCTION_PTR(clRetainKernel, handle);
102 LOAD_FUNCTION_PTR(clCreateKernel, handle);
103 LOAD_FUNCTION_PTR(clGetProgramInfo, handle);
104 LOAD_FUNCTION_PTR(clFlush, handle);
105 LOAD_FUNCTION_PTR(clFinish, handle);
106 LOAD_FUNCTION_PTR(clReleaseProgram, handle);
107 LOAD_FUNCTION_PTR(clRetainContext, handle);
108 LOAD_FUNCTION_PTR(clCreateProgramWithBinary, handle);
109 LOAD_FUNCTION_PTR(clReleaseCommandQueue, handle);
110 LOAD_FUNCTION_PTR(clEnqueueMapBuffer, handle);
111 LOAD_FUNCTION_PTR(clRetainProgram, handle);
112 LOAD_FUNCTION_PTR(clGetProgramBuildInfo, handle);
113 LOAD_FUNCTION_PTR(clEnqueueReadBuffer, handle);
114 LOAD_FUNCTION_PTR(clEnqueueWriteBuffer, handle);
115 LOAD_FUNCTION_PTR(clReleaseEvent, handle);
116 LOAD_FUNCTION_PTR(clReleaseContext, handle);
117 LOAD_FUNCTION_PTR(clRetainCommandQueue, handle);
118 LOAD_FUNCTION_PTR(clEnqueueUnmapMemObject, handle);
119 LOAD_FUNCTION_PTR(clRetainMemObject, handle);
120 LOAD_FUNCTION_PTR(clReleaseMemObject, handle);
121 LOAD_FUNCTION_PTR(clGetDeviceInfo, handle);
122 LOAD_FUNCTION_PTR(clGetDeviceIDs, handle);
Georgios Pinitasdf310362018-11-14 13:16:56 +0000123 LOAD_FUNCTION_PTR(clGetMemObjectInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000124 LOAD_FUNCTION_PTR(clRetainEvent, handle);
125 LOAD_FUNCTION_PTR(clGetPlatformIDs, handle);
126 LOAD_FUNCTION_PTR(clGetKernelWorkGroupInfo, handle);
Gian Marco85e6f512018-02-01 16:57:48 +0000127 LOAD_FUNCTION_PTR(clGetCommandQueueInfo, handle);
128 LOAD_FUNCTION_PTR(clGetKernelInfo, handle);
129 LOAD_FUNCTION_PTR(clGetEventProfilingInfo, handle);
Pablo Telloe86a09f2018-01-11 15:44:48 +0000130 LOAD_FUNCTION_PTR(clSVMAlloc, handle);
131 LOAD_FUNCTION_PTR(clSVMFree, handle);
132 LOAD_FUNCTION_PTR(clEnqueueSVMMap, handle);
133 LOAD_FUNCTION_PTR(clEnqueueSVMUnmap, handle);
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100134 LOAD_FUNCTION_PTR(clEnqueueMarker, handle);
135 LOAD_FUNCTION_PTR(clWaitForEvents, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000136
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100137 // Third-party extensions
138 LOAD_FUNCTION_PTR(clImportMemoryARM, handle);
139
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000140#undef LOAD_FUNCTION_PTR
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100141
Anthony Barbier7b43d312017-12-14 10:58:47 +0000142 //Don't call dlclose(handle) or all the symbols will be unloaded !
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100143
144 // Disable default loading and set status to successful
145 _loaded = std::make_pair(true, true);
146
147 return true;
148}
149
150bool opencl_is_available()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100151{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100152 CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000153 return CLSymbols::get().clBuildProgram_ptr != nullptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100154}
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100155} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100156
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100157cl_int clEnqueueMarker(cl_command_queue command_queue,
158 cl_event *event)
159{
160 arm_compute::CLSymbols::get().load_default();
161 auto func = arm_compute::CLSymbols::get().clEnqueueMarker_ptr;
162 if(func != nullptr)
163 {
164 return func(command_queue, event);
165 }
166 else
167 {
168 return CL_OUT_OF_RESOURCES;
169 }
170}
171
172cl_int clWaitForEvents(cl_uint num_events,
173 const cl_event *event_list)
174{
175 arm_compute::CLSymbols::get().load_default();
176 auto func = arm_compute::CLSymbols::get().clWaitForEvents_ptr;
177 if(func != nullptr)
178 {
179 return func(num_events, event_list);
180 }
181 else
182 {
183 return CL_OUT_OF_RESOURCES;
184 }
185}
186
Pablo Telloe86a09f2018-01-11 15:44:48 +0000187cl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags flags, void *svm_ptr,
188 size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
189{
190 arm_compute::CLSymbols::get().load_default();
191 auto func = arm_compute::CLSymbols::get().clEnqueueSVMMap_ptr;
192 if(func != nullptr)
193 {
194 return func(command_queue, blocking_map, flags, svm_ptr, size, num_events_in_wait_list, event_wait_list, event);
195 }
196 else
197 {
198 return CL_OUT_OF_RESOURCES;
199 }
200}
201
202cl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *svm_ptr, cl_uint num_events_in_wait_list,
203 const cl_event *event_wait_list, cl_event *event)
204{
205 arm_compute::CLSymbols::get().load_default();
206 auto func = arm_compute::CLSymbols::get().clEnqueueSVMUnmap_ptr;
207 if(func != nullptr)
208 {
209 return func(command_queue, svm_ptr, num_events_in_wait_list, event_wait_list, event);
210 }
211 else
212 {
213 return CL_OUT_OF_RESOURCES;
214 }
215}
216
217void *clSVMAlloc(cl_context context, cl_svm_mem_flags_arm flags, size_t size, cl_uint alignment)
218{
219 arm_compute::CLSymbols::get().load_default();
220 auto func = arm_compute::CLSymbols::get().clSVMAlloc_ptr;
221 if(func != nullptr)
222 {
223 return func(context, flags, size, alignment);
224 }
225 else
226 {
227 return nullptr;
228 }
229}
230
231void clSVMFree(cl_context context, void *svm_pointer)
232{
233 arm_compute::CLSymbols::get().load_default();
234 auto func = arm_compute::CLSymbols::get().clSVMFree_ptr;
235 if(func != nullptr)
236 {
237 func(context, svm_pointer);
238 }
239}
240
Anthony Barbiera9e15332017-12-22 16:37:30 +0000241cl_int clGetContextInfo(cl_context context,
242 cl_context_info param_name,
243 size_t param_value_size,
244 void *param_value,
245 size_t *param_value_size_ret)
246{
247 arm_compute::CLSymbols::get().load_default();
248 auto func = arm_compute::CLSymbols::get().clGetContextInfo_ptr;
249 if(func != nullptr)
250 {
251 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
252 }
253 else
254 {
255 return CL_OUT_OF_RESOURCES;
256 }
257}
258
259cl_command_queue clCreateCommandQueue(cl_context context,
260 cl_device_id device,
261 cl_command_queue_properties properties,
262 cl_int *errcode_ret)
263{
264 arm_compute::CLSymbols::get().load_default();
265 auto func = arm_compute::CLSymbols::get().clCreateCommandQueue_ptr;
266 if(func != nullptr)
267 {
268 return func(context, device, properties, errcode_ret);
269 }
270 else
271 {
272 return nullptr;
273 }
274}
275
Anthony Barbierb6eb3532018-08-08 13:20:04 +0100276cl_context clCreateContext(
277 const cl_context_properties *properties,
278 cl_uint num_devices,
279 const cl_device_id *devices,
280 void (*pfn_notify)(const char *, const void *, size_t, void *),
281 void *user_data,
282 cl_int *errcode_ret)
283{
284 arm_compute::CLSymbols::get().load_default();
285 auto func = arm_compute::CLSymbols::get().clCreateContext_ptr;
286 if(func != nullptr)
287 {
288 return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
289 }
290 else
291 {
292 return nullptr;
293 }
294}
295
Anthony Barbiera9e15332017-12-22 16:37:30 +0000296cl_context clCreateContextFromType(const cl_context_properties *properties,
297 cl_device_type device_type,
298 void (*pfn_notify)(const char *, const void *, size_t, void *),
299 void *user_data,
300 cl_int *errcode_ret)
301{
302 arm_compute::CLSymbols::get().load_default();
303 auto func = arm_compute::CLSymbols::get().clCreateContextFromType_ptr;
304 if(func != nullptr)
305 {
306 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
307 }
308 else
309 {
310 return nullptr;
311 }
312}
313
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100314cl_int clBuildProgram(
315 cl_program program,
316 cl_uint num_devices,
317 const cl_device_id *device_list,
318 const char *options,
319 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
320 void *user_data)
321{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100322 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000323 auto func = arm_compute::CLSymbols::get().clBuildProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100324 if(func != nullptr)
325 {
326 return func(program, num_devices, device_list, options, pfn_notify, user_data);
327 }
328 else
329 {
330 return CL_OUT_OF_RESOURCES;
331 }
332}
333
334cl_int clEnqueueNDRangeKernel(
335 cl_command_queue command_queue,
336 cl_kernel kernel,
337 cl_uint work_dim,
338 const size_t *global_work_offset,
339 const size_t *global_work_size,
340 const size_t *local_work_size,
341 cl_uint num_events_in_wait_list,
342 const cl_event *event_wait_list,
343 cl_event *event)
344{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100345 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000346 auto func = arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100347 if(func != nullptr)
348 {
349 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);
350 }
351 else
352 {
353 return CL_OUT_OF_RESOURCES;
354 }
355}
356
357cl_int clSetKernelArg(
358 cl_kernel kernel,
359 cl_uint arg_index,
360 size_t arg_size,
361 const void *arg_value)
362{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100363 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000364 auto func = arm_compute::CLSymbols::get().clSetKernelArg_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100365 if(func != nullptr)
366 {
367 return func(kernel, arg_index, arg_size, arg_value);
368 }
369 else
370 {
371 return CL_OUT_OF_RESOURCES;
372 }
373}
374
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100375cl_int clRetainMemObject(cl_mem memobj)
376{
377 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000378 auto func = arm_compute::CLSymbols::get().clRetainMemObject_ptr;
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100379 if(func != nullptr)
380 {
381 return func(memobj);
382 }
383 else
384 {
385 return CL_OUT_OF_RESOURCES;
386 }
387}
388
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100389cl_int clReleaseMemObject(cl_mem memobj)
390{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100391 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000392 auto func = arm_compute::CLSymbols::get().clReleaseMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100393 if(func != nullptr)
394 {
395 return func(memobj);
396 }
397 else
398 {
399 return CL_OUT_OF_RESOURCES;
400 }
401}
402
403cl_int clEnqueueUnmapMemObject(
404 cl_command_queue command_queue,
405 cl_mem memobj,
406 void *mapped_ptr,
407 cl_uint num_events_in_wait_list,
408 const cl_event *event_wait_list,
409 cl_event *event)
410{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100411 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000412 auto func = arm_compute::CLSymbols::get().clEnqueueUnmapMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100413 if(func != nullptr)
414 {
415 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
416 }
417 else
418 {
419 return CL_OUT_OF_RESOURCES;
420 }
421}
422
423cl_int clRetainCommandQueue(cl_command_queue command_queue)
424{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100425 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000426 auto func = arm_compute::CLSymbols::get().clRetainCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100427 if(func != nullptr)
428 {
429 return func(command_queue);
430 }
431 else
432 {
433 return CL_OUT_OF_RESOURCES;
434 }
435}
436
437cl_int clReleaseContext(cl_context context)
438{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100439 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000440 auto func = arm_compute::CLSymbols::get().clReleaseContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100441 if(func != nullptr)
442 {
443 return func(context);
444 }
445 else
446 {
447 return CL_OUT_OF_RESOURCES;
448 }
449}
450cl_int clReleaseEvent(cl_event event)
451{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100452 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000453 auto func = arm_compute::CLSymbols::get().clReleaseEvent_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100454 if(func != nullptr)
455 {
456 return func(event);
457 }
458 else
459 {
460 return CL_OUT_OF_RESOURCES;
461 }
462}
463
464cl_int clEnqueueWriteBuffer(
465 cl_command_queue command_queue,
466 cl_mem buffer,
467 cl_bool blocking_write,
468 size_t offset,
469 size_t size,
470 const void *ptr,
471 cl_uint num_events_in_wait_list,
472 const cl_event *event_wait_list,
473 cl_event *event)
474{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100475 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000476 auto func = arm_compute::CLSymbols::get().clEnqueueWriteBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100477 if(func != nullptr)
478 {
479 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
480 }
481 else
482 {
483 return CL_OUT_OF_RESOURCES;
484 }
485}
486
487cl_int clEnqueueReadBuffer(
488 cl_command_queue command_queue,
489 cl_mem buffer,
490 cl_bool blocking_read,
491 size_t offset,
492 size_t size,
493 void *ptr,
494 cl_uint num_events_in_wait_list,
495 const cl_event *event_wait_list,
496 cl_event *event)
497{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100498 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000499 auto func = arm_compute::CLSymbols::get().clEnqueueReadBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100500 if(func != nullptr)
501 {
502 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
503 }
504 else
505 {
506 return CL_OUT_OF_RESOURCES;
507 }
508}
509
510cl_int clGetProgramBuildInfo(
511 cl_program program,
512 cl_device_id device,
513 cl_program_build_info param_name,
514 size_t param_value_size,
515 void *param_value,
516 size_t *param_value_size_ret)
517{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100518 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000519 auto func = arm_compute::CLSymbols::get().clGetProgramBuildInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100520 if(func != nullptr)
521 {
522 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
523 }
524 else
525 {
526 return CL_OUT_OF_RESOURCES;
527 }
528}
529
530cl_int clRetainProgram(cl_program program)
531{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100532 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000533 auto func = arm_compute::CLSymbols::get().clRetainProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100534 if(func != nullptr)
535 {
536 return func(program);
537 }
538 else
539 {
540 return CL_OUT_OF_RESOURCES;
541 }
542}
543
544void *clEnqueueMapBuffer(
545 cl_command_queue command_queue,
546 cl_mem buffer,
547 cl_bool blocking_map,
548 cl_map_flags map_flags,
549 size_t offset,
550 size_t size,
551 cl_uint num_events_in_wait_list,
552 const cl_event *event_wait_list,
553 cl_event *event,
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().clEnqueueMapBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100558 if(func != nullptr)
559 {
560 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, 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 clReleaseCommandQueue(cl_command_queue command_queue)
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().clReleaseCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100576 if(func != nullptr)
577 {
578 return func(command_queue);
579 }
580 else
581 {
582 return CL_OUT_OF_RESOURCES;
583 }
584}
585
586cl_program clCreateProgramWithBinary(
587 cl_context context,
588 cl_uint num_devices,
589 const cl_device_id *device_list,
590 const size_t *lengths,
591 const unsigned char **binaries,
592 cl_int *binary_status,
593 cl_int *errcode_ret)
594{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100595 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000596 auto func = arm_compute::CLSymbols::get().clCreateProgramWithBinary_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100597 if(func != nullptr)
598 {
599 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
600 }
601 else
602 {
603 if(errcode_ret != nullptr)
604 {
605 *errcode_ret = CL_OUT_OF_RESOURCES;
606 }
607 return nullptr;
608 }
609}
610
611cl_int clRetainContext(cl_context context)
612{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100613 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000614 auto func = arm_compute::CLSymbols::get().clRetainContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100615 if(func != nullptr)
616 {
617 return func(context);
618 }
619 else
620 {
621 return CL_OUT_OF_RESOURCES;
622 }
623}
624
625cl_int clReleaseProgram(cl_program program)
626{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100627 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000628 auto func = arm_compute::CLSymbols::get().clReleaseProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100629 if(func != nullptr)
630 {
631 return func(program);
632 }
633 else
634 {
635 return CL_OUT_OF_RESOURCES;
636 }
637}
638
639cl_int clFlush(cl_command_queue command_queue)
640{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100641 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000642 auto func = arm_compute::CLSymbols::get().clFlush_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100643 if(func != nullptr)
644 {
645 return func(command_queue);
646 }
647 else
648 {
649 return CL_OUT_OF_RESOURCES;
650 }
651}
652
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100653cl_int clFinish(cl_command_queue command_queue)
654{
655 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000656 auto func = arm_compute::CLSymbols::get().clFinish_ptr;
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100657 if(func != nullptr)
658 {
659 return func(command_queue);
660 }
661 else
662 {
663 return CL_OUT_OF_RESOURCES;
664 }
665}
666
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100667cl_int clGetProgramInfo(
668 cl_program program,
669 cl_program_info param_name,
670 size_t param_value_size,
671 void *param_value,
672 size_t *param_value_size_ret)
673{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100674 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000675 auto func = arm_compute::CLSymbols::get().clGetProgramInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100676 if(func != nullptr)
677 {
678 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
679 }
680 else
681 {
682 return CL_OUT_OF_RESOURCES;
683 }
684}
685
686cl_kernel clCreateKernel(
687 cl_program program,
688 const char *kernel_name,
689 cl_int *errcode_ret)
690{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100691 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000692 auto func = arm_compute::CLSymbols::get().clCreateKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100693 if(func != nullptr)
694 {
695 return func(program, kernel_name, errcode_ret);
696 }
697 else
698 {
699 if(errcode_ret != nullptr)
700 {
701 *errcode_ret = CL_OUT_OF_RESOURCES;
702 }
703 return nullptr;
704 }
705}
706
707cl_int clRetainKernel(cl_kernel kernel)
708{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100709 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000710 auto func = arm_compute::CLSymbols::get().clRetainKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100711 if(func != nullptr)
712 {
713 return func(kernel);
714 }
715 else
716 {
717 return CL_OUT_OF_RESOURCES;
718 }
719}
720
721cl_mem clCreateBuffer(
722 cl_context context,
723 cl_mem_flags flags,
724 size_t size,
725 void *host_ptr,
726 cl_int *errcode_ret)
727{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100728 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000729 auto func = arm_compute::CLSymbols::get().clCreateBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100730 if(func != nullptr)
731 {
732 return func(context, flags, size, host_ptr, errcode_ret);
733 }
734 else
735 {
736 if(errcode_ret != nullptr)
737 {
738 *errcode_ret = CL_OUT_OF_RESOURCES;
739 }
740 return nullptr;
741 }
742}
743
744cl_program clCreateProgramWithSource(
745 cl_context context,
746 cl_uint count,
747 const char **strings,
748 const size_t *lengths,
749 cl_int *errcode_ret)
750{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100751 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000752 auto func = arm_compute::CLSymbols::get().clCreateProgramWithSource_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100753 if(func != nullptr)
754 {
755 return func(context, count, strings, lengths, errcode_ret);
756 }
757 else
758 {
759 if(errcode_ret != nullptr)
760 {
761 *errcode_ret = CL_OUT_OF_RESOURCES;
762 }
763 return nullptr;
764 }
765}
766
767cl_int clReleaseKernel(cl_kernel kernel)
768{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100769 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000770 auto func = arm_compute::CLSymbols::get().clReleaseKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100771 if(func != nullptr)
772 {
773 return func(kernel);
774 }
775 else
776 {
777 return CL_OUT_OF_RESOURCES;
778 }
779}
780
781cl_int clGetDeviceIDs(cl_platform_id platform,
782 cl_device_type device_type,
783 cl_uint num_entries,
784 cl_device_id *devices,
785 cl_uint *num_devices)
786{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100787 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000788 auto func = arm_compute::CLSymbols::get().clGetDeviceIDs_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100789 if(func != nullptr)
790 {
791 return func(platform, device_type, num_entries, devices, num_devices);
792 }
793 else
794 {
795 return CL_OUT_OF_RESOURCES;
796 }
797}
798
799cl_int clGetDeviceInfo(cl_device_id device,
800 cl_device_info param_name,
801 size_t param_value_size,
802 void *param_value,
803 size_t *param_value_size_ret)
804{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100805 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000806 auto func = arm_compute::CLSymbols::get().clGetDeviceInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100807 if(func != nullptr)
808 {
809 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
810 }
811 else
812 {
813 return CL_OUT_OF_RESOURCES;
814 }
815}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100816
Georgios Pinitasdf310362018-11-14 13:16:56 +0000817cl_int clGetMemObjectInfo(cl_mem memobj,
818 cl_mem_info param_name,
819 size_t param_value_size,
820 void *param_value,
821 size_t *param_value_size_ret)
822{
823 arm_compute::CLSymbols::get().load_default();
824 auto func = arm_compute::CLSymbols::get().clGetMemObjectInfo_ptr;
825 if(func != nullptr)
826 {
827 return func(memobj, param_name, param_value_size, param_value, param_value_size_ret);
828 }
829 else
830 {
831 return CL_OUT_OF_RESOURCES;
832 }
833}
834
Giorgio Arena9fe41442017-08-23 16:36:24 +0100835cl_int clRetainEvent(cl_event event)
836{
Moritz Pflanzer159b6da2017-09-20 16:03:35 +0100837 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000838 auto func = arm_compute::CLSymbols::get().clRetainEvent_ptr;
Giorgio Arena9fe41442017-08-23 16:36:24 +0100839 if(func != nullptr)
840 {
841 return func(event);
842 }
843 else
844 {
845 return CL_OUT_OF_RESOURCES;
846 }
847}
steniu01f01f9de2017-09-27 17:00:11 +0100848
849cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
850{
851 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000852 auto func = arm_compute::CLSymbols::get().clGetPlatformIDs_ptr;
steniu01f01f9de2017-09-27 17:00:11 +0100853 if(func != nullptr)
854 {
855 return func(num_entries, platforms, num_platforms);
856 }
857 else
858 {
859 return CL_OUT_OF_RESOURCES;
860 }
861}
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100862
863cl_int
864clGetKernelWorkGroupInfo(cl_kernel kernel,
865 cl_device_id device,
866 cl_kernel_work_group_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();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000872 auto func = arm_compute::CLSymbols::get().clGetKernelWorkGroupInfo_ptr;
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100873 if(func != nullptr)
874 {
875 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
876 }
877 else
878 {
879 return CL_OUT_OF_RESOURCES;
880 }
881}
Gian Marco85e6f512018-02-01 16:57:48 +0000882
883cl_int
884clGetCommandQueueInfo(cl_command_queue command_queue,
885 cl_command_queue_info param_name,
886 size_t param_value_size,
887 void *param_value,
888 size_t *param_value_size_ret)
889{
890 arm_compute::CLSymbols::get().load_default();
891 auto func = arm_compute::CLSymbols::get().clGetCommandQueueInfo_ptr;
892 if(func != nullptr)
893 {
894 return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
895 }
896 else
897 {
898 return CL_OUT_OF_RESOURCES;
899 }
900}
901
902cl_int
903clGetKernelInfo(cl_kernel kernel,
904 cl_kernel_info param_name,
905 size_t param_value_size,
906 void *param_value,
907 size_t *param_value_size_ret)
908{
909 arm_compute::CLSymbols::get().load_default();
910 auto func = arm_compute::CLSymbols::get().clGetKernelInfo_ptr;
911 if(func != nullptr)
912 {
913 return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
914 }
915 else
916 {
917 return CL_OUT_OF_RESOURCES;
918 }
919}
920
921cl_int
922clGetEventProfilingInfo(cl_event event,
923 cl_profiling_info param_name,
924 size_t param_value_size,
925 void *param_value,
926 size_t *param_value_size_ret)
927{
928 arm_compute::CLSymbols::get().load_default();
929 auto func = arm_compute::CLSymbols::get().clGetEventProfilingInfo_ptr;
930 if(func != nullptr)
931 {
932 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
933 }
934 else
935 {
936 return CL_OUT_OF_RESOURCES;
937 }
Anthony Barbierf5dcf792018-02-28 18:04:45 +0000938}
Georgios Pinitas4d0351c2019-04-03 15:11:16 +0100939
940cl_mem
941clImportMemoryARM(cl_context context,
942 cl_mem_flags flags,
943 const cl_import_properties_arm *properties,
944 void *memory,
945 size_t size,
946 cl_int *errcode_ret)
947{
948 arm_compute::CLSymbols::get().load_default();
949 auto func = arm_compute::CLSymbols::get().clImportMemoryARM_ptr;
950 if(func != nullptr)
951 {
952 return func(context, flags, properties, memory, size, errcode_ret);
953 }
954 else
955 {
956 if(errcode_ret != nullptr)
957 {
958 *errcode_ret = CL_OUT_OF_RESOURCES;
959 }
960 return nullptr;
961 }
Pablo Tellodb8485a2019-09-24 11:03:47 +0100962}