blob: 3a145e0ab3e08b03cb092f30b0f719ed57a65821 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
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
77 LOAD_FUNCTION_PTR(clBuildProgram, handle);
78 LOAD_FUNCTION_PTR(clEnqueueNDRangeKernel, handle);
79 LOAD_FUNCTION_PTR(clBuildProgram, handle);
80 LOAD_FUNCTION_PTR(clEnqueueNDRangeKernel, handle);
81 LOAD_FUNCTION_PTR(clSetKernelArg, handle);
82 LOAD_FUNCTION_PTR(clReleaseKernel, handle);
83 LOAD_FUNCTION_PTR(clCreateProgramWithSource, handle);
84 LOAD_FUNCTION_PTR(clCreateBuffer, handle);
85 LOAD_FUNCTION_PTR(clRetainKernel, handle);
86 LOAD_FUNCTION_PTR(clCreateKernel, handle);
87 LOAD_FUNCTION_PTR(clGetProgramInfo, handle);
88 LOAD_FUNCTION_PTR(clFlush, handle);
89 LOAD_FUNCTION_PTR(clFinish, handle);
90 LOAD_FUNCTION_PTR(clReleaseProgram, handle);
91 LOAD_FUNCTION_PTR(clRetainContext, handle);
92 LOAD_FUNCTION_PTR(clCreateProgramWithBinary, handle);
93 LOAD_FUNCTION_PTR(clReleaseCommandQueue, handle);
94 LOAD_FUNCTION_PTR(clEnqueueMapBuffer, handle);
95 LOAD_FUNCTION_PTR(clRetainProgram, handle);
96 LOAD_FUNCTION_PTR(clGetProgramBuildInfo, handle);
97 LOAD_FUNCTION_PTR(clEnqueueReadBuffer, handle);
98 LOAD_FUNCTION_PTR(clEnqueueWriteBuffer, handle);
99 LOAD_FUNCTION_PTR(clReleaseEvent, handle);
100 LOAD_FUNCTION_PTR(clReleaseContext, handle);
101 LOAD_FUNCTION_PTR(clRetainCommandQueue, handle);
102 LOAD_FUNCTION_PTR(clEnqueueUnmapMemObject, handle);
103 LOAD_FUNCTION_PTR(clRetainMemObject, handle);
104 LOAD_FUNCTION_PTR(clReleaseMemObject, handle);
105 LOAD_FUNCTION_PTR(clGetDeviceInfo, handle);
106 LOAD_FUNCTION_PTR(clGetDeviceIDs, handle);
107 LOAD_FUNCTION_PTR(clRetainEvent, handle);
108 LOAD_FUNCTION_PTR(clGetPlatformIDs, handle);
109 LOAD_FUNCTION_PTR(clGetKernelWorkGroupInfo, handle);
110
111#undef LOAD_FUNCTION_PTR
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100112
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100113 dlclose(handle);
114
115 // Disable default loading and set status to successful
116 _loaded = std::make_pair(true, true);
117
118 return true;
119}
120
121bool opencl_is_available()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100122{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100123 CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000124 return CLSymbols::get().clBuildProgram_ptr != nullptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100125}
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100126} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100127
128cl_int clBuildProgram(
129 cl_program program,
130 cl_uint num_devices,
131 const cl_device_id *device_list,
132 const char *options,
133 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
134 void *user_data)
135{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100136 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000137 auto func = arm_compute::CLSymbols::get().clBuildProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100138 if(func != nullptr)
139 {
140 return func(program, num_devices, device_list, options, pfn_notify, user_data);
141 }
142 else
143 {
144 return CL_OUT_OF_RESOURCES;
145 }
146}
147
148cl_int clEnqueueNDRangeKernel(
149 cl_command_queue command_queue,
150 cl_kernel kernel,
151 cl_uint work_dim,
152 const size_t *global_work_offset,
153 const size_t *global_work_size,
154 const size_t *local_work_size,
155 cl_uint num_events_in_wait_list,
156 const cl_event *event_wait_list,
157 cl_event *event)
158{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100159 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000160 auto func = arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100161 if(func != nullptr)
162 {
163 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);
164 }
165 else
166 {
167 return CL_OUT_OF_RESOURCES;
168 }
169}
170
171cl_int clSetKernelArg(
172 cl_kernel kernel,
173 cl_uint arg_index,
174 size_t arg_size,
175 const void *arg_value)
176{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100177 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000178 auto func = arm_compute::CLSymbols::get().clSetKernelArg_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100179 if(func != nullptr)
180 {
181 return func(kernel, arg_index, arg_size, arg_value);
182 }
183 else
184 {
185 return CL_OUT_OF_RESOURCES;
186 }
187}
188
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100189cl_int clRetainMemObject(cl_mem memobj)
190{
191 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000192 auto func = arm_compute::CLSymbols::get().clRetainMemObject_ptr;
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100193 if(func != nullptr)
194 {
195 return func(memobj);
196 }
197 else
198 {
199 return CL_OUT_OF_RESOURCES;
200 }
201}
202
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100203cl_int clReleaseMemObject(cl_mem memobj)
204{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100205 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000206 auto func = arm_compute::CLSymbols::get().clReleaseMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100207 if(func != nullptr)
208 {
209 return func(memobj);
210 }
211 else
212 {
213 return CL_OUT_OF_RESOURCES;
214 }
215}
216
217cl_int clEnqueueUnmapMemObject(
218 cl_command_queue command_queue,
219 cl_mem memobj,
220 void *mapped_ptr,
221 cl_uint num_events_in_wait_list,
222 const cl_event *event_wait_list,
223 cl_event *event)
224{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100225 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000226 auto func = arm_compute::CLSymbols::get().clEnqueueUnmapMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100227 if(func != nullptr)
228 {
229 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
230 }
231 else
232 {
233 return CL_OUT_OF_RESOURCES;
234 }
235}
236
237cl_int clRetainCommandQueue(cl_command_queue command_queue)
238{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100239 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000240 auto func = arm_compute::CLSymbols::get().clRetainCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100241 if(func != nullptr)
242 {
243 return func(command_queue);
244 }
245 else
246 {
247 return CL_OUT_OF_RESOURCES;
248 }
249}
250
251cl_int clReleaseContext(cl_context context)
252{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100253 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000254 auto func = arm_compute::CLSymbols::get().clReleaseContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100255 if(func != nullptr)
256 {
257 return func(context);
258 }
259 else
260 {
261 return CL_OUT_OF_RESOURCES;
262 }
263}
264cl_int clReleaseEvent(cl_event event)
265{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100266 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000267 auto func = arm_compute::CLSymbols::get().clReleaseEvent_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100268 if(func != nullptr)
269 {
270 return func(event);
271 }
272 else
273 {
274 return CL_OUT_OF_RESOURCES;
275 }
276}
277
278cl_int clEnqueueWriteBuffer(
279 cl_command_queue command_queue,
280 cl_mem buffer,
281 cl_bool blocking_write,
282 size_t offset,
283 size_t size,
284 const void *ptr,
285 cl_uint num_events_in_wait_list,
286 const cl_event *event_wait_list,
287 cl_event *event)
288{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100289 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000290 auto func = arm_compute::CLSymbols::get().clEnqueueWriteBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100291 if(func != nullptr)
292 {
293 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
294 }
295 else
296 {
297 return CL_OUT_OF_RESOURCES;
298 }
299}
300
301cl_int clEnqueueReadBuffer(
302 cl_command_queue command_queue,
303 cl_mem buffer,
304 cl_bool blocking_read,
305 size_t offset,
306 size_t size,
307 void *ptr,
308 cl_uint num_events_in_wait_list,
309 const cl_event *event_wait_list,
310 cl_event *event)
311{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100312 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000313 auto func = arm_compute::CLSymbols::get().clEnqueueReadBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100314 if(func != nullptr)
315 {
316 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
317 }
318 else
319 {
320 return CL_OUT_OF_RESOURCES;
321 }
322}
323
324cl_int clGetProgramBuildInfo(
325 cl_program program,
326 cl_device_id device,
327 cl_program_build_info param_name,
328 size_t param_value_size,
329 void *param_value,
330 size_t *param_value_size_ret)
331{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100332 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000333 auto func = arm_compute::CLSymbols::get().clGetProgramBuildInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100334 if(func != nullptr)
335 {
336 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
337 }
338 else
339 {
340 return CL_OUT_OF_RESOURCES;
341 }
342}
343
344cl_int clRetainProgram(cl_program program)
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().clRetainProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100348 if(func != nullptr)
349 {
350 return func(program);
351 }
352 else
353 {
354 return CL_OUT_OF_RESOURCES;
355 }
356}
357
358void *clEnqueueMapBuffer(
359 cl_command_queue command_queue,
360 cl_mem buffer,
361 cl_bool blocking_map,
362 cl_map_flags map_flags,
363 size_t offset,
364 size_t size,
365 cl_uint num_events_in_wait_list,
366 const cl_event *event_wait_list,
367 cl_event *event,
368 cl_int *errcode_ret)
369{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100370 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000371 auto func = arm_compute::CLSymbols::get().clEnqueueMapBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100372 if(func != nullptr)
373 {
374 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
375 }
376 else
377 {
378 if(errcode_ret != nullptr)
379 {
380 *errcode_ret = CL_OUT_OF_RESOURCES;
381 }
382 return nullptr;
383 }
384}
385
386cl_int clReleaseCommandQueue(cl_command_queue command_queue)
387{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100388 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000389 auto func = arm_compute::CLSymbols::get().clReleaseCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100390 if(func != nullptr)
391 {
392 return func(command_queue);
393 }
394 else
395 {
396 return CL_OUT_OF_RESOURCES;
397 }
398}
399
400cl_program clCreateProgramWithBinary(
401 cl_context context,
402 cl_uint num_devices,
403 const cl_device_id *device_list,
404 const size_t *lengths,
405 const unsigned char **binaries,
406 cl_int *binary_status,
407 cl_int *errcode_ret)
408{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100409 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000410 auto func = arm_compute::CLSymbols::get().clCreateProgramWithBinary_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100411 if(func != nullptr)
412 {
413 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
414 }
415 else
416 {
417 if(errcode_ret != nullptr)
418 {
419 *errcode_ret = CL_OUT_OF_RESOURCES;
420 }
421 return nullptr;
422 }
423}
424
425cl_int clRetainContext(cl_context context)
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().clRetainContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100429 if(func != nullptr)
430 {
431 return func(context);
432 }
433 else
434 {
435 return CL_OUT_OF_RESOURCES;
436 }
437}
438
439cl_int clReleaseProgram(cl_program program)
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().clReleaseProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100443 if(func != nullptr)
444 {
445 return func(program);
446 }
447 else
448 {
449 return CL_OUT_OF_RESOURCES;
450 }
451}
452
453cl_int clFlush(cl_command_queue command_queue)
454{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100455 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000456 auto func = arm_compute::CLSymbols::get().clFlush_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100457 if(func != nullptr)
458 {
459 return func(command_queue);
460 }
461 else
462 {
463 return CL_OUT_OF_RESOURCES;
464 }
465}
466
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100467cl_int clFinish(cl_command_queue command_queue)
468{
469 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000470 auto func = arm_compute::CLSymbols::get().clFinish_ptr;
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100471 if(func != nullptr)
472 {
473 return func(command_queue);
474 }
475 else
476 {
477 return CL_OUT_OF_RESOURCES;
478 }
479}
480
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100481cl_int clGetProgramInfo(
482 cl_program program,
483 cl_program_info param_name,
484 size_t param_value_size,
485 void *param_value,
486 size_t *param_value_size_ret)
487{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100488 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000489 auto func = arm_compute::CLSymbols::get().clGetProgramInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100490 if(func != nullptr)
491 {
492 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
493 }
494 else
495 {
496 return CL_OUT_OF_RESOURCES;
497 }
498}
499
500cl_kernel clCreateKernel(
501 cl_program program,
502 const char *kernel_name,
503 cl_int *errcode_ret)
504{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100505 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000506 auto func = arm_compute::CLSymbols::get().clCreateKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100507 if(func != nullptr)
508 {
509 return func(program, kernel_name, errcode_ret);
510 }
511 else
512 {
513 if(errcode_ret != nullptr)
514 {
515 *errcode_ret = CL_OUT_OF_RESOURCES;
516 }
517 return nullptr;
518 }
519}
520
521cl_int clRetainKernel(cl_kernel kernel)
522{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100523 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000524 auto func = arm_compute::CLSymbols::get().clRetainKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100525 if(func != nullptr)
526 {
527 return func(kernel);
528 }
529 else
530 {
531 return CL_OUT_OF_RESOURCES;
532 }
533}
534
535cl_mem clCreateBuffer(
536 cl_context context,
537 cl_mem_flags flags,
538 size_t size,
539 void *host_ptr,
540 cl_int *errcode_ret)
541{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100542 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000543 auto func = arm_compute::CLSymbols::get().clCreateBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100544 if(func != nullptr)
545 {
546 return func(context, flags, size, host_ptr, errcode_ret);
547 }
548 else
549 {
550 if(errcode_ret != nullptr)
551 {
552 *errcode_ret = CL_OUT_OF_RESOURCES;
553 }
554 return nullptr;
555 }
556}
557
558cl_program clCreateProgramWithSource(
559 cl_context context,
560 cl_uint count,
561 const char **strings,
562 const size_t *lengths,
563 cl_int *errcode_ret)
564{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100565 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000566 auto func = arm_compute::CLSymbols::get().clCreateProgramWithSource_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100567 if(func != nullptr)
568 {
569 return func(context, count, strings, lengths, errcode_ret);
570 }
571 else
572 {
573 if(errcode_ret != nullptr)
574 {
575 *errcode_ret = CL_OUT_OF_RESOURCES;
576 }
577 return nullptr;
578 }
579}
580
581cl_int clReleaseKernel(cl_kernel kernel)
582{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100583 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000584 auto func = arm_compute::CLSymbols::get().clReleaseKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100585 if(func != nullptr)
586 {
587 return func(kernel);
588 }
589 else
590 {
591 return CL_OUT_OF_RESOURCES;
592 }
593}
594
595cl_int clGetDeviceIDs(cl_platform_id platform,
596 cl_device_type device_type,
597 cl_uint num_entries,
598 cl_device_id *devices,
599 cl_uint *num_devices)
600{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100601 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000602 auto func = arm_compute::CLSymbols::get().clGetDeviceIDs_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100603 if(func != nullptr)
604 {
605 return func(platform, device_type, num_entries, devices, num_devices);
606 }
607 else
608 {
609 return CL_OUT_OF_RESOURCES;
610 }
611}
612
613cl_int clGetDeviceInfo(cl_device_id device,
614 cl_device_info param_name,
615 size_t param_value_size,
616 void *param_value,
617 size_t *param_value_size_ret)
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().clGetDeviceInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100621 if(func != nullptr)
622 {
623 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
624 }
625 else
626 {
627 return CL_OUT_OF_RESOURCES;
628 }
629}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100630
631cl_int clRetainEvent(cl_event event)
632{
Moritz Pflanzer159b6da2017-09-20 16:03:35 +0100633 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000634 auto func = arm_compute::CLSymbols::get().clRetainEvent_ptr;
Giorgio Arena9fe41442017-08-23 16:36:24 +0100635 if(func != nullptr)
636 {
637 return func(event);
638 }
639 else
640 {
641 return CL_OUT_OF_RESOURCES;
642 }
643}
steniu01f01f9de2017-09-27 17:00:11 +0100644
645cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
646{
647 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000648 auto func = arm_compute::CLSymbols::get().clGetPlatformIDs_ptr;
steniu01f01f9de2017-09-27 17:00:11 +0100649 if(func != nullptr)
650 {
651 return func(num_entries, platforms, num_platforms);
652 }
653 else
654 {
655 return CL_OUT_OF_RESOURCES;
656 }
657}
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100658
659cl_int
660clGetKernelWorkGroupInfo(cl_kernel kernel,
661 cl_device_id device,
662 cl_kernel_work_group_info param_name,
663 size_t param_value_size,
664 void *param_value,
665 size_t *param_value_size_ret)
666{
667 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000668 auto func = arm_compute::CLSymbols::get().clGetKernelWorkGroupInfo_ptr;
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100669 if(func != nullptr)
670 {
671 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
672 }
673 else
674 {
675 return CL_OUT_OF_RESOURCES;
676 }
677}