blob: 726279c6ea48102717af58e3d97fe785a798af0a [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
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);
111
112#undef LOAD_FUNCTION_PTR
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100113
Anthony Barbier7b43d312017-12-14 10:58:47 +0000114 //Don't call dlclose(handle) or all the symbols will be unloaded !
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100115
116 // Disable default loading and set status to successful
117 _loaded = std::make_pair(true, true);
118
119 return true;
120}
121
122bool opencl_is_available()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100123{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100124 CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000125 return CLSymbols::get().clBuildProgram_ptr != nullptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100126}
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100127} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100128
Anthony Barbiera9e15332017-12-22 16:37:30 +0000129cl_int clGetContextInfo(cl_context context,
130 cl_context_info param_name,
131 size_t param_value_size,
132 void *param_value,
133 size_t *param_value_size_ret)
134{
135 arm_compute::CLSymbols::get().load_default();
136 auto func = arm_compute::CLSymbols::get().clGetContextInfo_ptr;
137 if(func != nullptr)
138 {
139 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
140 }
141 else
142 {
143 return CL_OUT_OF_RESOURCES;
144 }
145}
146
147cl_command_queue clCreateCommandQueue(cl_context context,
148 cl_device_id device,
149 cl_command_queue_properties properties,
150 cl_int *errcode_ret)
151{
152 arm_compute::CLSymbols::get().load_default();
153 auto func = arm_compute::CLSymbols::get().clCreateCommandQueue_ptr;
154 if(func != nullptr)
155 {
156 return func(context, device, properties, errcode_ret);
157 }
158 else
159 {
160 return nullptr;
161 }
162}
163
164cl_context clCreateContextFromType(const cl_context_properties *properties,
165 cl_device_type device_type,
166 void (*pfn_notify)(const char *, const void *, size_t, void *),
167 void *user_data,
168 cl_int *errcode_ret)
169{
170 arm_compute::CLSymbols::get().load_default();
171 auto func = arm_compute::CLSymbols::get().clCreateContextFromType_ptr;
172 if(func != nullptr)
173 {
174 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
175 }
176 else
177 {
178 return nullptr;
179 }
180}
181
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100182cl_int clBuildProgram(
183 cl_program program,
184 cl_uint num_devices,
185 const cl_device_id *device_list,
186 const char *options,
187 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
188 void *user_data)
189{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100190 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000191 auto func = arm_compute::CLSymbols::get().clBuildProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100192 if(func != nullptr)
193 {
194 return func(program, num_devices, device_list, options, pfn_notify, user_data);
195 }
196 else
197 {
198 return CL_OUT_OF_RESOURCES;
199 }
200}
201
202cl_int clEnqueueNDRangeKernel(
203 cl_command_queue command_queue,
204 cl_kernel kernel,
205 cl_uint work_dim,
206 const size_t *global_work_offset,
207 const size_t *global_work_size,
208 const size_t *local_work_size,
209 cl_uint num_events_in_wait_list,
210 const cl_event *event_wait_list,
211 cl_event *event)
212{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100213 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000214 auto func = arm_compute::CLSymbols::get().clEnqueueNDRangeKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100215 if(func != nullptr)
216 {
217 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);
218 }
219 else
220 {
221 return CL_OUT_OF_RESOURCES;
222 }
223}
224
225cl_int clSetKernelArg(
226 cl_kernel kernel,
227 cl_uint arg_index,
228 size_t arg_size,
229 const void *arg_value)
230{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100231 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000232 auto func = arm_compute::CLSymbols::get().clSetKernelArg_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100233 if(func != nullptr)
234 {
235 return func(kernel, arg_index, arg_size, arg_value);
236 }
237 else
238 {
239 return CL_OUT_OF_RESOURCES;
240 }
241}
242
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100243cl_int clRetainMemObject(cl_mem memobj)
244{
245 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000246 auto func = arm_compute::CLSymbols::get().clRetainMemObject_ptr;
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100247 if(func != nullptr)
248 {
249 return func(memobj);
250 }
251 else
252 {
253 return CL_OUT_OF_RESOURCES;
254 }
255}
256
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100257cl_int clReleaseMemObject(cl_mem memobj)
258{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100259 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000260 auto func = arm_compute::CLSymbols::get().clReleaseMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100261 if(func != nullptr)
262 {
263 return func(memobj);
264 }
265 else
266 {
267 return CL_OUT_OF_RESOURCES;
268 }
269}
270
271cl_int clEnqueueUnmapMemObject(
272 cl_command_queue command_queue,
273 cl_mem memobj,
274 void *mapped_ptr,
275 cl_uint num_events_in_wait_list,
276 const cl_event *event_wait_list,
277 cl_event *event)
278{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100279 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000280 auto func = arm_compute::CLSymbols::get().clEnqueueUnmapMemObject_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100281 if(func != nullptr)
282 {
283 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
284 }
285 else
286 {
287 return CL_OUT_OF_RESOURCES;
288 }
289}
290
291cl_int clRetainCommandQueue(cl_command_queue command_queue)
292{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100293 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000294 auto func = arm_compute::CLSymbols::get().clRetainCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100295 if(func != nullptr)
296 {
297 return func(command_queue);
298 }
299 else
300 {
301 return CL_OUT_OF_RESOURCES;
302 }
303}
304
305cl_int clReleaseContext(cl_context context)
306{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100307 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000308 auto func = arm_compute::CLSymbols::get().clReleaseContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100309 if(func != nullptr)
310 {
311 return func(context);
312 }
313 else
314 {
315 return CL_OUT_OF_RESOURCES;
316 }
317}
318cl_int clReleaseEvent(cl_event event)
319{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100320 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000321 auto func = arm_compute::CLSymbols::get().clReleaseEvent_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100322 if(func != nullptr)
323 {
324 return func(event);
325 }
326 else
327 {
328 return CL_OUT_OF_RESOURCES;
329 }
330}
331
332cl_int clEnqueueWriteBuffer(
333 cl_command_queue command_queue,
334 cl_mem buffer,
335 cl_bool blocking_write,
336 size_t offset,
337 size_t size,
338 const void *ptr,
339 cl_uint num_events_in_wait_list,
340 const cl_event *event_wait_list,
341 cl_event *event)
342{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100343 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000344 auto func = arm_compute::CLSymbols::get().clEnqueueWriteBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100345 if(func != nullptr)
346 {
347 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
348 }
349 else
350 {
351 return CL_OUT_OF_RESOURCES;
352 }
353}
354
355cl_int clEnqueueReadBuffer(
356 cl_command_queue command_queue,
357 cl_mem buffer,
358 cl_bool blocking_read,
359 size_t offset,
360 size_t size,
361 void *ptr,
362 cl_uint num_events_in_wait_list,
363 const cl_event *event_wait_list,
364 cl_event *event)
365{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100366 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000367 auto func = arm_compute::CLSymbols::get().clEnqueueReadBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100368 if(func != nullptr)
369 {
370 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
371 }
372 else
373 {
374 return CL_OUT_OF_RESOURCES;
375 }
376}
377
378cl_int clGetProgramBuildInfo(
379 cl_program program,
380 cl_device_id device,
381 cl_program_build_info param_name,
382 size_t param_value_size,
383 void *param_value,
384 size_t *param_value_size_ret)
385{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100386 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000387 auto func = arm_compute::CLSymbols::get().clGetProgramBuildInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100388 if(func != nullptr)
389 {
390 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
391 }
392 else
393 {
394 return CL_OUT_OF_RESOURCES;
395 }
396}
397
398cl_int clRetainProgram(cl_program program)
399{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100400 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000401 auto func = arm_compute::CLSymbols::get().clRetainProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100402 if(func != nullptr)
403 {
404 return func(program);
405 }
406 else
407 {
408 return CL_OUT_OF_RESOURCES;
409 }
410}
411
412void *clEnqueueMapBuffer(
413 cl_command_queue command_queue,
414 cl_mem buffer,
415 cl_bool blocking_map,
416 cl_map_flags map_flags,
417 size_t offset,
418 size_t size,
419 cl_uint num_events_in_wait_list,
420 const cl_event *event_wait_list,
421 cl_event *event,
422 cl_int *errcode_ret)
423{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100424 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000425 auto func = arm_compute::CLSymbols::get().clEnqueueMapBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100426 if(func != nullptr)
427 {
428 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
429 }
430 else
431 {
432 if(errcode_ret != nullptr)
433 {
434 *errcode_ret = CL_OUT_OF_RESOURCES;
435 }
436 return nullptr;
437 }
438}
439
440cl_int clReleaseCommandQueue(cl_command_queue command_queue)
441{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100442 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000443 auto func = arm_compute::CLSymbols::get().clReleaseCommandQueue_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100444 if(func != nullptr)
445 {
446 return func(command_queue);
447 }
448 else
449 {
450 return CL_OUT_OF_RESOURCES;
451 }
452}
453
454cl_program clCreateProgramWithBinary(
455 cl_context context,
456 cl_uint num_devices,
457 const cl_device_id *device_list,
458 const size_t *lengths,
459 const unsigned char **binaries,
460 cl_int *binary_status,
461 cl_int *errcode_ret)
462{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100463 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000464 auto func = arm_compute::CLSymbols::get().clCreateProgramWithBinary_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100465 if(func != nullptr)
466 {
467 return func(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
468 }
469 else
470 {
471 if(errcode_ret != nullptr)
472 {
473 *errcode_ret = CL_OUT_OF_RESOURCES;
474 }
475 return nullptr;
476 }
477}
478
479cl_int clRetainContext(cl_context context)
480{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100481 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000482 auto func = arm_compute::CLSymbols::get().clRetainContext_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100483 if(func != nullptr)
484 {
485 return func(context);
486 }
487 else
488 {
489 return CL_OUT_OF_RESOURCES;
490 }
491}
492
493cl_int clReleaseProgram(cl_program program)
494{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100495 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000496 auto func = arm_compute::CLSymbols::get().clReleaseProgram_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100497 if(func != nullptr)
498 {
499 return func(program);
500 }
501 else
502 {
503 return CL_OUT_OF_RESOURCES;
504 }
505}
506
507cl_int clFlush(cl_command_queue command_queue)
508{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100509 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000510 auto func = arm_compute::CLSymbols::get().clFlush_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100511 if(func != nullptr)
512 {
513 return func(command_queue);
514 }
515 else
516 {
517 return CL_OUT_OF_RESOURCES;
518 }
519}
520
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100521cl_int clFinish(cl_command_queue command_queue)
522{
523 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000524 auto func = arm_compute::CLSymbols::get().clFinish_ptr;
Gian Marco Iodice63d76a72017-08-11 11:56:52 +0100525 if(func != nullptr)
526 {
527 return func(command_queue);
528 }
529 else
530 {
531 return CL_OUT_OF_RESOURCES;
532 }
533}
534
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100535cl_int clGetProgramInfo(
536 cl_program program,
537 cl_program_info param_name,
538 size_t param_value_size,
539 void *param_value,
540 size_t *param_value_size_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().clGetProgramInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100544 if(func != nullptr)
545 {
546 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
547 }
548 else
549 {
550 return CL_OUT_OF_RESOURCES;
551 }
552}
553
554cl_kernel clCreateKernel(
555 cl_program program,
556 const char *kernel_name,
557 cl_int *errcode_ret)
558{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100559 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000560 auto func = arm_compute::CLSymbols::get().clCreateKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100561 if(func != nullptr)
562 {
563 return func(program, kernel_name, errcode_ret);
564 }
565 else
566 {
567 if(errcode_ret != nullptr)
568 {
569 *errcode_ret = CL_OUT_OF_RESOURCES;
570 }
571 return nullptr;
572 }
573}
574
575cl_int clRetainKernel(cl_kernel kernel)
576{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100577 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000578 auto func = arm_compute::CLSymbols::get().clRetainKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100579 if(func != nullptr)
580 {
581 return func(kernel);
582 }
583 else
584 {
585 return CL_OUT_OF_RESOURCES;
586 }
587}
588
589cl_mem clCreateBuffer(
590 cl_context context,
591 cl_mem_flags flags,
592 size_t size,
593 void *host_ptr,
594 cl_int *errcode_ret)
595{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100596 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000597 auto func = arm_compute::CLSymbols::get().clCreateBuffer_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100598 if(func != nullptr)
599 {
600 return func(context, flags, size, host_ptr, errcode_ret);
601 }
602 else
603 {
604 if(errcode_ret != nullptr)
605 {
606 *errcode_ret = CL_OUT_OF_RESOURCES;
607 }
608 return nullptr;
609 }
610}
611
612cl_program clCreateProgramWithSource(
613 cl_context context,
614 cl_uint count,
615 const char **strings,
616 const size_t *lengths,
617 cl_int *errcode_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().clCreateProgramWithSource_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100621 if(func != nullptr)
622 {
623 return func(context, count, strings, lengths, errcode_ret);
624 }
625 else
626 {
627 if(errcode_ret != nullptr)
628 {
629 *errcode_ret = CL_OUT_OF_RESOURCES;
630 }
631 return nullptr;
632 }
633}
634
635cl_int clReleaseKernel(cl_kernel kernel)
636{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100637 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000638 auto func = arm_compute::CLSymbols::get().clReleaseKernel_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100639 if(func != nullptr)
640 {
641 return func(kernel);
642 }
643 else
644 {
645 return CL_OUT_OF_RESOURCES;
646 }
647}
648
649cl_int clGetDeviceIDs(cl_platform_id platform,
650 cl_device_type device_type,
651 cl_uint num_entries,
652 cl_device_id *devices,
653 cl_uint *num_devices)
654{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100655 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000656 auto func = arm_compute::CLSymbols::get().clGetDeviceIDs_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100657 if(func != nullptr)
658 {
659 return func(platform, device_type, num_entries, devices, num_devices);
660 }
661 else
662 {
663 return CL_OUT_OF_RESOURCES;
664 }
665}
666
667cl_int clGetDeviceInfo(cl_device_id device,
668 cl_device_info param_name,
669 size_t param_value_size,
670 void *param_value,
671 size_t *param_value_size_ret)
672{
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100673 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000674 auto func = arm_compute::CLSymbols::get().clGetDeviceInfo_ptr;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100675 if(func != nullptr)
676 {
677 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
678 }
679 else
680 {
681 return CL_OUT_OF_RESOURCES;
682 }
683}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100684
685cl_int clRetainEvent(cl_event event)
686{
Moritz Pflanzer159b6da2017-09-20 16:03:35 +0100687 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000688 auto func = arm_compute::CLSymbols::get().clRetainEvent_ptr;
Giorgio Arena9fe41442017-08-23 16:36:24 +0100689 if(func != nullptr)
690 {
691 return func(event);
692 }
693 else
694 {
695 return CL_OUT_OF_RESOURCES;
696 }
697}
steniu01f01f9de2017-09-27 17:00:11 +0100698
699cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
700{
701 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000702 auto func = arm_compute::CLSymbols::get().clGetPlatformIDs_ptr;
steniu01f01f9de2017-09-27 17:00:11 +0100703 if(func != nullptr)
704 {
705 return func(num_entries, platforms, num_platforms);
706 }
707 else
708 {
709 return CL_OUT_OF_RESOURCES;
710 }
711}
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100712
713cl_int
714clGetKernelWorkGroupInfo(cl_kernel kernel,
715 cl_device_id device,
716 cl_kernel_work_group_info param_name,
717 size_t param_value_size,
718 void *param_value,
719 size_t *param_value_size_ret)
720{
721 arm_compute::CLSymbols::get().load_default();
Anthony Barbier58c4ff12017-11-09 09:15:32 +0000722 auto func = arm_compute::CLSymbols::get().clGetKernelWorkGroupInfo_ptr;
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100723 if(func != nullptr)
724 {
725 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
726 }
727 else
728 {
729 return CL_OUT_OF_RESOURCES;
730 }
731}