blob: f75a90a324c99e56b0d0b37e477e0cd83a3fcf46 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Gian Marco85e6f512018-02-01 16:57:48 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#include "arm_compute/core/CL/OpenCL.h"
26
27#include <dlfcn.h>
28#include <iostream>
29
Moritz Pflanzer725788e2017-07-07 15:35:56 +010030namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031{
Moritz Pflanzer725788e2017-07-07 15:35:56 +010032CLSymbols &CLSymbols::get()
33{
34 static CLSymbols symbols;
35 return symbols;
36}
37
38bool CLSymbols::load_default()
39{
40 static const std::vector<std::string> libraries{ "libOpenCL.so", "libGLES_mali.so", "libmali.so" };
41
42 if(_loaded.first)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010043 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010044 return _loaded.second;
45 }
46
47 // Indicate that default loading has been tried
48 _loaded.first = true;
49
50 for(const auto &lib : libraries)
51 {
52 if(load(lib))
Anthony Barbier6ff3b192017-09-04 18:44:23 +010053 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010054 return true;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010055 }
56 }
57
Moritz Pflanzer725788e2017-07-07 15:35:56 +010058 std::cerr << "Couldn't find any OpenCL library.\n";
59 return false;
60}
61
62bool CLSymbols::load(const std::string &library)
63{
64 void *handle = dlopen(library.c_str(), RTLD_LAZY | RTLD_LOCAL);
65
66 if(handle == nullptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010067 {
Moritz Pflanzer725788e2017-07-07 15:35:56 +010068 std::cerr << "Can't load " << library << ": " << dlerror() << "\n";
69 // Set status of loading to failed
70 _loaded.second = false;
71 return false;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010072 }
73
Anthony Barbier58c4ff12017-11-09 09:15:32 +000074#define LOAD_FUNCTION_PTR(func_name, handle) \
75 func_name##_ptr = reinterpret_cast<decltype(func_name) *>(dlsym(handle, #func_name));
76
Anthony Barbiera9e15332017-12-22 16:37:30 +000077 LOAD_FUNCTION_PTR(clCreateContextFromType, handle);
78 LOAD_FUNCTION_PTR(clCreateCommandQueue, handle);
79 LOAD_FUNCTION_PTR(clGetContextInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +000080 LOAD_FUNCTION_PTR(clBuildProgram, handle);
81 LOAD_FUNCTION_PTR(clEnqueueNDRangeKernel, handle);
82 LOAD_FUNCTION_PTR(clSetKernelArg, handle);
83 LOAD_FUNCTION_PTR(clReleaseKernel, handle);
84 LOAD_FUNCTION_PTR(clCreateProgramWithSource, handle);
85 LOAD_FUNCTION_PTR(clCreateBuffer, handle);
86 LOAD_FUNCTION_PTR(clRetainKernel, handle);
87 LOAD_FUNCTION_PTR(clCreateKernel, handle);
88 LOAD_FUNCTION_PTR(clGetProgramInfo, handle);
89 LOAD_FUNCTION_PTR(clFlush, handle);
90 LOAD_FUNCTION_PTR(clFinish, handle);
91 LOAD_FUNCTION_PTR(clReleaseProgram, handle);
92 LOAD_FUNCTION_PTR(clRetainContext, handle);
93 LOAD_FUNCTION_PTR(clCreateProgramWithBinary, handle);
94 LOAD_FUNCTION_PTR(clReleaseCommandQueue, handle);
95 LOAD_FUNCTION_PTR(clEnqueueMapBuffer, handle);
96 LOAD_FUNCTION_PTR(clRetainProgram, handle);
97 LOAD_FUNCTION_PTR(clGetProgramBuildInfo, handle);
98 LOAD_FUNCTION_PTR(clEnqueueReadBuffer, handle);
99 LOAD_FUNCTION_PTR(clEnqueueWriteBuffer, handle);
100 LOAD_FUNCTION_PTR(clReleaseEvent, handle);
101 LOAD_FUNCTION_PTR(clReleaseContext, handle);
102 LOAD_FUNCTION_PTR(clRetainCommandQueue, handle);
103 LOAD_FUNCTION_PTR(clEnqueueUnmapMemObject, handle);
104 LOAD_FUNCTION_PTR(clRetainMemObject, handle);
105 LOAD_FUNCTION_PTR(clReleaseMemObject, handle);
106 LOAD_FUNCTION_PTR(clGetDeviceInfo, handle);
107 LOAD_FUNCTION_PTR(clGetDeviceIDs, handle);
108 LOAD_FUNCTION_PTR(clRetainEvent, handle);
109 LOAD_FUNCTION_PTR(clGetPlatformIDs, handle);
110 LOAD_FUNCTION_PTR(clGetKernelWorkGroupInfo, handle);
Gian Marco85e6f512018-02-01 16:57:48 +0000111 LOAD_FUNCTION_PTR(clGetCommandQueueInfo, handle);
112 LOAD_FUNCTION_PTR(clGetKernelInfo, handle);
113 LOAD_FUNCTION_PTR(clGetEventProfilingInfo, handle);
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000114
115#undef LOAD_FUNCTION_PTR
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100116
Anthony Barbier7b43d312017-12-14 10:58:47 +0000117 //Don't call dlclose(handle) or all the symbols will be unloaded !
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100118
119 // Disable default loading and set status to successful
120 _loaded = std::make_pair(true, true);
121
122 return true;
123}
124
125bool opencl_is_available()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100126{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100127 CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000128 return CLSymbols::get().clBuildProgram_ptr != nullptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100129}
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100130} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100131
Anthony Barbiera9e15332017-12-22 16:37:30 +0000132cl_int clGetContextInfo(cl_context context,
133 cl_context_info param_name,
134 size_t param_value_size,
135 void *param_value,
136 size_t *param_value_size_ret)
137{
138 arm_compute::CLSymbols::get().load_default();
139 auto func = arm_compute::CLSymbols::get().clGetContextInfo_ptr;
140 if(func != nullptr)
141 {
142 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
143 }
144 else
145 {
146 return CL_OUT_OF_RESOURCES;
147 }
148}
149
150cl_command_queue clCreateCommandQueue(cl_context context,
151 cl_device_id device,
152 cl_command_queue_properties properties,
153 cl_int *errcode_ret)
154{
155 arm_compute::CLSymbols::get().load_default();
156 auto func = arm_compute::CLSymbols::get().clCreateCommandQueue_ptr;
157 if(func != nullptr)
158 {
159 return func(context, device, properties, errcode_ret);
160 }
161 else
162 {
163 return nullptr;
164 }
165}
166
167cl_context clCreateContextFromType(const cl_context_properties *properties,
168 cl_device_type device_type,
169 void (*pfn_notify)(const char *, const void *, size_t, void *),
170 void *user_data,
171 cl_int *errcode_ret)
172{
173 arm_compute::CLSymbols::get().load_default();
174 auto func = arm_compute::CLSymbols::get().clCreateContextFromType_ptr;
175 if(func != nullptr)
176 {
177 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
178 }
179 else
180 {
181 return nullptr;
182 }
183}
184
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100185cl_int clBuildProgram(
186 cl_program program,
187 cl_uint num_devices,
188 const cl_device_id *device_list,
189 const char *options,
190 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
191 void *user_data)
192{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100193 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000194 auto func = arm_compute::CLSymbols::get().clBuildProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100195 if(func != nullptr)
196 {
197 return func(program, num_devices, device_list, options, pfn_notify, user_data);
198 }
199 else
200 {
201 return CL_OUT_OF_RESOURCES;
202 }
203}
204
205cl_int clEnqueueNDRangeKernel(
206 cl_command_queue command_queue,
207 cl_kernel kernel,
208 cl_uint work_dim,
209 const size_t *global_work_offset,
210 const size_t *global_work_size,
211 const size_t *local_work_size,
212 cl_uint num_events_in_wait_list,
213 const cl_event *event_wait_list,
214 cl_event *event)
215{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100216 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000217 auto func = arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100218 if(func != nullptr)
219 {
220 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);
221 }
222 else
223 {
224 return CL_OUT_OF_RESOURCES;
225 }
226}
227
228cl_int clSetKernelArg(
229 cl_kernel kernel,
230 cl_uint arg_index,
231 size_t arg_size,
232 const void *arg_value)
233{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100234 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000235 auto func = arm_compute::CLSymbols::get().clSetKernelArg_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100236 if(func != nullptr)
237 {
238 return func(kernel, arg_index, arg_size, arg_value);
239 }
240 else
241 {
242 return CL_OUT_OF_RESOURCES;
243 }
244}
245
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100246cl_int clRetainMemObject(cl_mem memobj)
247{
248 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000249 auto func = arm_compute::CLSymbols::get().clRetainMemObject_ptr;
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100250 if(func != nullptr)
251 {
252 return func(memobj);
253 }
254 else
255 {
256 return CL_OUT_OF_RESOURCES;
257 }
258}
259
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100260cl_int clReleaseMemObject(cl_mem memobj)
261{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100262 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000263 auto func = arm_compute::CLSymbols::get().clReleaseMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100264 if(func != nullptr)
265 {
266 return func(memobj);
267 }
268 else
269 {
270 return CL_OUT_OF_RESOURCES;
271 }
272}
273
274cl_int clEnqueueUnmapMemObject(
275 cl_command_queue command_queue,
276 cl_mem memobj,
277 void *mapped_ptr,
278 cl_uint num_events_in_wait_list,
279 const cl_event *event_wait_list,
280 cl_event *event)
281{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100282 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000283 auto func = arm_compute::CLSymbols::get().clEnqueueUnmapMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100284 if(func != nullptr)
285 {
286 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
287 }
288 else
289 {
290 return CL_OUT_OF_RESOURCES;
291 }
292}
293
294cl_int clRetainCommandQueue(cl_command_queue command_queue)
295{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100296 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000297 auto func = arm_compute::CLSymbols::get().clRetainCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100298 if(func != nullptr)
299 {
300 return func(command_queue);
301 }
302 else
303 {
304 return CL_OUT_OF_RESOURCES;
305 }
306}
307
308cl_int clReleaseContext(cl_context context)
309{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100310 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000311 auto func = arm_compute::CLSymbols::get().clReleaseContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100312 if(func != nullptr)
313 {
314 return func(context);
315 }
316 else
317 {
318 return CL_OUT_OF_RESOURCES;
319 }
320}
321cl_int clReleaseEvent(cl_event event)
322{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100323 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000324 auto func = arm_compute::CLSymbols::get().clReleaseEvent_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100325 if(func != nullptr)
326 {
327 return func(event);
328 }
329 else
330 {
331 return CL_OUT_OF_RESOURCES;
332 }
333}
334
335cl_int clEnqueueWriteBuffer(
336 cl_command_queue command_queue,
337 cl_mem buffer,
338 cl_bool blocking_write,
339 size_t offset,
340 size_t size,
341 const void *ptr,
342 cl_uint num_events_in_wait_list,
343 const cl_event *event_wait_list,
344 cl_event *event)
345{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100346 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000347 auto func = arm_compute::CLSymbols::get().clEnqueueWriteBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100348 if(func != nullptr)
349 {
350 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
351 }
352 else
353 {
354 return CL_OUT_OF_RESOURCES;
355 }
356}
357
358cl_int clEnqueueReadBuffer(
359 cl_command_queue command_queue,
360 cl_mem buffer,
361 cl_bool blocking_read,
362 size_t offset,
363 size_t size,
364 void *ptr,
365 cl_uint num_events_in_wait_list,
366 const cl_event *event_wait_list,
367 cl_event *event)
368{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100369 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000370 auto func = arm_compute::CLSymbols::get().clEnqueueReadBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100371 if(func != nullptr)
372 {
373 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
374 }
375 else
376 {
377 return CL_OUT_OF_RESOURCES;
378 }
379}
380
381cl_int clGetProgramBuildInfo(
382 cl_program program,
383 cl_device_id device,
384 cl_program_build_info param_name,
385 size_t param_value_size,
386 void *param_value,
387 size_t *param_value_size_ret)
388{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100389 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000390 auto func = arm_compute::CLSymbols::get().clGetProgramBuildInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100391 if(func != nullptr)
392 {
393 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
394 }
395 else
396 {
397 return CL_OUT_OF_RESOURCES;
398 }
399}
400
401cl_int clRetainProgram(cl_program program)
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().clRetainProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100405 if(func != nullptr)
406 {
407 return func(program);
408 }
409 else
410 {
411 return CL_OUT_OF_RESOURCES;
412 }
413}
414
415void *clEnqueueMapBuffer(
416 cl_command_queue command_queue,
417 cl_mem buffer,
418 cl_bool blocking_map,
419 cl_map_flags map_flags,
420 size_t offset,
421 size_t size,
422 cl_uint num_events_in_wait_list,
423 const cl_event *event_wait_list,
424 cl_event *event,
425 cl_int *errcode_ret)
426{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100427 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000428 auto func = arm_compute::CLSymbols::get().clEnqueueMapBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100429 if(func != nullptr)
430 {
431 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
432 }
433 else
434 {
435 if(errcode_ret != nullptr)
436 {
437 *errcode_ret = CL_OUT_OF_RESOURCES;
438 }
439 return nullptr;
440 }
441}
442
443cl_int clReleaseCommandQueue(cl_command_queue command_queue)
444{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100445 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000446 auto func = arm_compute::CLSymbols::get().clReleaseCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100447 if(func != nullptr)
448 {
449 return func(command_queue);
450 }
451 else
452 {
453 return CL_OUT_OF_RESOURCES;
454 }
455}
456
457cl_program clCreateProgramWithBinary(
458 cl_context context,
459 cl_uint num_devices,
460 const cl_device_id *device_list,
461 const size_t *lengths,
462 const unsigned char **binaries,
463 cl_int *binary_status,
464 cl_int *errcode_ret)
465{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100466 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000467 auto func = arm_compute::CLSymbols::get().clCreateProgramWithBinary_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100468 if(func != nullptr)
469 {
470 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
471 }
472 else
473 {
474 if(errcode_ret != nullptr)
475 {
476 *errcode_ret = CL_OUT_OF_RESOURCES;
477 }
478 return nullptr;
479 }
480}
481
482cl_int clRetainContext(cl_context context)
483{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100484 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000485 auto func = arm_compute::CLSymbols::get().clRetainContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100486 if(func != nullptr)
487 {
488 return func(context);
489 }
490 else
491 {
492 return CL_OUT_OF_RESOURCES;
493 }
494}
495
496cl_int clReleaseProgram(cl_program program)
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().clReleaseProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100500 if(func != nullptr)
501 {
502 return func(program);
503 }
504 else
505 {
506 return CL_OUT_OF_RESOURCES;
507 }
508}
509
510cl_int clFlush(cl_command_queue command_queue)
511{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100512 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000513 auto func = arm_compute::CLSymbols::get().clFlush_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100514 if(func != nullptr)
515 {
516 return func(command_queue);
517 }
518 else
519 {
520 return CL_OUT_OF_RESOURCES;
521 }
522}
523
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100524cl_int clFinish(cl_command_queue command_queue)
525{
526 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000527 auto func = arm_compute::CLSymbols::get().clFinish_ptr;
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100528 if(func != nullptr)
529 {
530 return func(command_queue);
531 }
532 else
533 {
534 return CL_OUT_OF_RESOURCES;
535 }
536}
537
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100538cl_int clGetProgramInfo(
539 cl_program program,
540 cl_program_info param_name,
541 size_t param_value_size,
542 void *param_value,
543 size_t *param_value_size_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().clGetProgramInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100547 if(func != nullptr)
548 {
549 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
550 }
551 else
552 {
553 return CL_OUT_OF_RESOURCES;
554 }
555}
556
557cl_kernel clCreateKernel(
558 cl_program program,
559 const char *kernel_name,
560 cl_int *errcode_ret)
561{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100562 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000563 auto func = arm_compute::CLSymbols::get().clCreateKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100564 if(func != nullptr)
565 {
566 return func(program, kernel_name, errcode_ret);
567 }
568 else
569 {
570 if(errcode_ret != nullptr)
571 {
572 *errcode_ret = CL_OUT_OF_RESOURCES;
573 }
574 return nullptr;
575 }
576}
577
578cl_int clRetainKernel(cl_kernel kernel)
579{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100580 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000581 auto func = arm_compute::CLSymbols::get().clRetainKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100582 if(func != nullptr)
583 {
584 return func(kernel);
585 }
586 else
587 {
588 return CL_OUT_OF_RESOURCES;
589 }
590}
591
592cl_mem clCreateBuffer(
593 cl_context context,
594 cl_mem_flags flags,
595 size_t size,
596 void *host_ptr,
597 cl_int *errcode_ret)
598{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100599 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000600 auto func = arm_compute::CLSymbols::get().clCreateBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100601 if(func != nullptr)
602 {
603 return func(context, flags, size, host_ptr, errcode_ret);
604 }
605 else
606 {
607 if(errcode_ret != nullptr)
608 {
609 *errcode_ret = CL_OUT_OF_RESOURCES;
610 }
611 return nullptr;
612 }
613}
614
615cl_program clCreateProgramWithSource(
616 cl_context context,
617 cl_uint count,
618 const char **strings,
619 const size_t *lengths,
620 cl_int *errcode_ret)
621{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100622 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000623 auto func = arm_compute::CLSymbols::get().clCreateProgramWithSource_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100624 if(func != nullptr)
625 {
626 return func(context, count, strings, lengths, errcode_ret);
627 }
628 else
629 {
630 if(errcode_ret != nullptr)
631 {
632 *errcode_ret = CL_OUT_OF_RESOURCES;
633 }
634 return nullptr;
635 }
636}
637
638cl_int clReleaseKernel(cl_kernel kernel)
639{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100640 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000641 auto func = arm_compute::CLSymbols::get().clReleaseKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100642 if(func != nullptr)
643 {
644 return func(kernel);
645 }
646 else
647 {
648 return CL_OUT_OF_RESOURCES;
649 }
650}
651
652cl_int clGetDeviceIDs(cl_platform_id platform,
653 cl_device_type device_type,
654 cl_uint num_entries,
655 cl_device_id *devices,
656 cl_uint *num_devices)
657{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100658 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000659 auto func = arm_compute::CLSymbols::get().clGetDeviceIDs_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100660 if(func != nullptr)
661 {
662 return func(platform, device_type, num_entries, devices, num_devices);
663 }
664 else
665 {
666 return CL_OUT_OF_RESOURCES;
667 }
668}
669
670cl_int clGetDeviceInfo(cl_device_id device,
671 cl_device_info param_name,
672 size_t param_value_size,
673 void *param_value,
674 size_t *param_value_size_ret)
675{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100676 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000677 auto func = arm_compute::CLSymbols::get().clGetDeviceInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100678 if(func != nullptr)
679 {
680 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
681 }
682 else
683 {
684 return CL_OUT_OF_RESOURCES;
685 }
686}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100687
688cl_int clRetainEvent(cl_event event)
689{
Moritz Pflanzer159b6da2017-09-20 16:03:35 +0100690 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000691 auto func = arm_compute::CLSymbols::get().clRetainEvent_ptr;
Giorgio Arena9fe41442017-08-23 16:36:24 +0100692 if(func != nullptr)
693 {
694 return func(event);
695 }
696 else
697 {
698 return CL_OUT_OF_RESOURCES;
699 }
700}
steniu01f01f9de2017-09-27 17:00:11 +0100701
702cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
703{
704 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000705 auto func = arm_compute::CLSymbols::get().clGetPlatformIDs_ptr;
steniu01f01f9de2017-09-27 17:00:11 +0100706 if(func != nullptr)
707 {
708 return func(num_entries, platforms, num_platforms);
709 }
710 else
711 {
712 return CL_OUT_OF_RESOURCES;
713 }
714}
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100715
716cl_int
717clGetKernelWorkGroupInfo(cl_kernel kernel,
718 cl_device_id device,
719 cl_kernel_work_group_info param_name,
720 size_t param_value_size,
721 void *param_value,
722 size_t *param_value_size_ret)
723{
724 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000725 auto func = arm_compute::CLSymbols::get().clGetKernelWorkGroupInfo_ptr;
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100726 if(func != nullptr)
727 {
728 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
729 }
730 else
731 {
732 return CL_OUT_OF_RESOURCES;
733 }
734}
Gian Marco85e6f512018-02-01 16:57:48 +0000735
736cl_int
737clGetCommandQueueInfo(cl_command_queue command_queue,
738 cl_command_queue_info param_name,
739 size_t param_value_size,
740 void *param_value,
741 size_t *param_value_size_ret)
742{
743 arm_compute::CLSymbols::get().load_default();
744 auto func = arm_compute::CLSymbols::get().clGetCommandQueueInfo_ptr;
745 if(func != nullptr)
746 {
747 return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
748 }
749 else
750 {
751 return CL_OUT_OF_RESOURCES;
752 }
753}
754
755cl_int
756clGetKernelInfo(cl_kernel kernel,
757 cl_kernel_info param_name,
758 size_t param_value_size,
759 void *param_value,
760 size_t *param_value_size_ret)
761{
762 arm_compute::CLSymbols::get().load_default();
763 auto func = arm_compute::CLSymbols::get().clGetKernelInfo_ptr;
764 if(func != nullptr)
765 {
766 return func(kernel, param_name, param_value_size, param_value, param_value_size_ret);
767 }
768 else
769 {
770 return CL_OUT_OF_RESOURCES;
771 }
772}
773
774cl_int
775clGetEventProfilingInfo(cl_event event,
776 cl_profiling_info param_name,
777 size_t param_value_size,
778 void *param_value,
779 size_t *param_value_size_ret)
780{
781 arm_compute::CLSymbols::get().load_default();
782 auto func = arm_compute::CLSymbols::get().clGetEventProfilingInfo_ptr;
783 if(func != nullptr)
784 {
785 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
786 }
787 else
788 {
789 return CL_OUT_OF_RESOURCES;
790 }
Anthony Barbierf5dcf792018-02-28 18:04:45 +0000791}