1 /*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #define USE_OPENCL_WRAPPER
16 #ifdef USE_OPENCL_WRAPPER
17
18 #include "opencl_wrapper.h"
19 #include <algorithm>
20 #include <dlfcn.h>
21 #include <memory>
22 #include <mutex>
23 #include <string>
24 #include <vector>
25 #include <iostream>
26
27 namespace OHOS {
28 // default opencl library path
29 static const std::vector<std::string> g_opencl_library_paths = {
30 #if defined(__APPLE__) || defined(__MACOSX)
31 "libOpenCL.so", "/System/Library/Frameworks/OpenCL.framework/OpenCL"
32 #else
33 "/vendor/lib64/chipsetsdk/libGLES_mali.so",
34 "/system/lib64/libGLES_mali.so",
35 "libGLES_mali.so",
36 "/vendor/lib64/chipsetsdk/libhvgr_v200.so",
37 "/vendor/lib64/chipsetsdk/libEGL_impl.so",
38 #endif
39 };
40
41 static std::mutex g_initMutex;
42 static bool g_isInit = false;
43 static bool g_loadSuccess = false;
44 static void *g_handle{nullptr};
45
InitOpenCL()46 bool InitOpenCL()
47 {
48 std::lock_guard<std::mutex> lock(g_initMutex);
49 if (g_isInit) {
50 return g_loadSuccess;
51 }
52 g_isInit = true;
53 g_loadSuccess = LoadOpenCLLibrary(&g_handle);
54 return g_loadSuccess;
55 }
56
UnLoadOpenCLLibrary(void * handle)57 bool UnLoadOpenCLLibrary(void *handle)
58 {
59 if (handle != nullptr) {
60 if (dlclose(handle) != 0) {
61 return false;
62 }
63 return true;
64 }
65 return true;
66 }
67
LoadLibraryFromPath(const std::string & library_path,void ** handle_ptr)68 static bool LoadLibraryFromPath(const std::string &library_path, void **handle_ptr)
69 {
70 if (handle_ptr == nullptr) {
71 return false;
72 }
73
74 *handle_ptr = dlopen(library_path.c_str(), RTLD_NOW | RTLD_LOCAL);
75 if (*handle_ptr == nullptr) {
76 return false;
77 }
78
79 // load function ptr use dlopen and dlsym.
80 #define LOAD_OPENCL_FUNCTION_PTR(func_name) \
81 func_name = reinterpret_cast<func_name##Func>(dlsym(*handle_ptr, #func_name)); \
82 if (func_name == nullptr) { \
83 return false; \
84 }
85
86 LOAD_OPENCL_FUNCTION_PTR(clGetPlatformIDs);
87 LOAD_OPENCL_FUNCTION_PTR(clGetPlatformInfo);
88 LOAD_OPENCL_FUNCTION_PTR(clBuildProgram);
89 LOAD_OPENCL_FUNCTION_PTR(clEnqueueNDRangeKernel);
90 LOAD_OPENCL_FUNCTION_PTR(clSetKernelArg);
91 LOAD_OPENCL_FUNCTION_PTR(clReleaseKernel);
92 LOAD_OPENCL_FUNCTION_PTR(clCreateProgramWithSource);
93 LOAD_OPENCL_FUNCTION_PTR(clCreateBuffer);
94 LOAD_OPENCL_FUNCTION_PTR(clCreateImage2D);
95 LOAD_OPENCL_FUNCTION_PTR(clCreateImage3D);
96 LOAD_OPENCL_FUNCTION_PTR(clRetainKernel);
97 LOAD_OPENCL_FUNCTION_PTR(clCreateKernel);
98 LOAD_OPENCL_FUNCTION_PTR(clGetProgramInfo);
99 LOAD_OPENCL_FUNCTION_PTR(clFlush);
100 LOAD_OPENCL_FUNCTION_PTR(clFinish);
101 LOAD_OPENCL_FUNCTION_PTR(clReleaseProgram);
102 LOAD_OPENCL_FUNCTION_PTR(clRetainContext);
103 LOAD_OPENCL_FUNCTION_PTR(clGetContextInfo);
104 LOAD_OPENCL_FUNCTION_PTR(clCreateProgramWithBinary);
105 LOAD_OPENCL_FUNCTION_PTR(clCreateCommandQueue);
106 LOAD_OPENCL_FUNCTION_PTR(clGetCommandQueueInfo);
107 LOAD_OPENCL_FUNCTION_PTR(clReleaseCommandQueue);
108 LOAD_OPENCL_FUNCTION_PTR(clEnqueueMapBuffer);
109 LOAD_OPENCL_FUNCTION_PTR(clEnqueueMapImage);
110 LOAD_OPENCL_FUNCTION_PTR(clRetainProgram);
111 LOAD_OPENCL_FUNCTION_PTR(clGetProgramBuildInfo);
112 LOAD_OPENCL_FUNCTION_PTR(clEnqueueReadBuffer);
113 LOAD_OPENCL_FUNCTION_PTR(clEnqueueReadBufferRect);
114 LOAD_OPENCL_FUNCTION_PTR(clEnqueueWriteBuffer);
115 LOAD_OPENCL_FUNCTION_PTR(clEnqueueReadImage);
116 LOAD_OPENCL_FUNCTION_PTR(clEnqueueWriteImage);
117 LOAD_OPENCL_FUNCTION_PTR(clWaitForEvents);
118 LOAD_OPENCL_FUNCTION_PTR(clReleaseEvent);
119 LOAD_OPENCL_FUNCTION_PTR(clCreateContext);
120 LOAD_OPENCL_FUNCTION_PTR(clCreateContextFromType);
121 LOAD_OPENCL_FUNCTION_PTR(clReleaseContext);
122 LOAD_OPENCL_FUNCTION_PTR(clRetainCommandQueue);
123 LOAD_OPENCL_FUNCTION_PTR(clEnqueueUnmapMemObject);
124 LOAD_OPENCL_FUNCTION_PTR(clRetainMemObject);
125 LOAD_OPENCL_FUNCTION_PTR(clReleaseMemObject);
126 LOAD_OPENCL_FUNCTION_PTR(clGetDeviceInfo);
127 LOAD_OPENCL_FUNCTION_PTR(clGetDeviceIDs);
128 LOAD_OPENCL_FUNCTION_PTR(clRetainEvent);
129 LOAD_OPENCL_FUNCTION_PTR(clGetKernelWorkGroupInfo);
130 LOAD_OPENCL_FUNCTION_PTR(clGetEventInfo);
131 LOAD_OPENCL_FUNCTION_PTR(clGetEventProfilingInfo);
132 LOAD_OPENCL_FUNCTION_PTR(clGetImageInfo);
133 LOAD_OPENCL_FUNCTION_PTR(clEnqueueCopyImage);
134 LOAD_OPENCL_FUNCTION_PTR(clEnqueueCopyBufferToImage);
135 LOAD_OPENCL_FUNCTION_PTR(clEnqueueCopyImageToBuffer);
136 #if defined(CL_TARGET_OPENCL_VERSION) && CL_TARGET_OPENCL_VERSION >= 120
137 LOAD_OPENCL_FUNCTION_PTR(clRetainDevice);
138 LOAD_OPENCL_FUNCTION_PTR(clReleaseDevice);
139 LOAD_OPENCL_FUNCTION_PTR(clCreateImage);
140 LOAD_OPENCL_FUNCTION_PTR(clEnqueueFillImage);
141 #endif
142 #if defined(CL_TARGET_OPENCL_VERSION) && CL_TARGET_OPENCL_VERSION >= 200
143 LOAD_OPENCL_FUNCTION_PTR(clCreateCommandQueueWithProperties);
144 LOAD_OPENCL_FUNCTION_PTR(clGetExtensionFunctionAddress);
145 LOAD_OPENCL_FUNCTION_PTR(clSVMAlloc);
146 LOAD_OPENCL_FUNCTION_PTR(clSVMFree);
147 LOAD_OPENCL_FUNCTION_PTR(clEnqueueSVMMap);
148 LOAD_OPENCL_FUNCTION_PTR(clEnqueueSVMUnmap);
149 LOAD_OPENCL_FUNCTION_PTR(clSetKernelArgSVMPointer);
150 #endif
151
152 return true;
153 }
154 // load default library path
LoadOpenCLLibrary(void ** handle_ptr)155 bool LoadOpenCLLibrary(void **handle_ptr)
156 {
157 if (handle_ptr == nullptr) {
158 return false;
159 }
160 auto it =
161 std::find_if(g_opencl_library_paths.begin(), g_opencl_library_paths.end(),
162 [&](const std::string &lib_path) { return OHOS::LoadLibraryFromPath(lib_path, handle_ptr); });
163 if (it != g_opencl_library_paths.end()) {
164 return true;
165 }
166 return false;
167 }
168
169 #define CL_DEFINE_FUNC_PTR(func) func##Func func = nullptr
170
171 CL_DEFINE_FUNC_PTR(clGetPlatformIDs);
172 CL_DEFINE_FUNC_PTR(clGetPlatformInfo);
173 CL_DEFINE_FUNC_PTR(clBuildProgram);
174 CL_DEFINE_FUNC_PTR(clEnqueueNDRangeKernel);
175 CL_DEFINE_FUNC_PTR(clSetKernelArg);
176 CL_DEFINE_FUNC_PTR(clReleaseKernel);
177 CL_DEFINE_FUNC_PTR(clCreateProgramWithSource);
178 CL_DEFINE_FUNC_PTR(clCreateBuffer);
179 CL_DEFINE_FUNC_PTR(clCreateImage2D);
180 CL_DEFINE_FUNC_PTR(clImportMemoryARM);
181 CL_DEFINE_FUNC_PTR(clCreateImage3D);
182 CL_DEFINE_FUNC_PTR(clRetainKernel);
183 CL_DEFINE_FUNC_PTR(clCreateKernel);
184 CL_DEFINE_FUNC_PTR(clGetProgramInfo);
185 CL_DEFINE_FUNC_PTR(clFlush);
186 CL_DEFINE_FUNC_PTR(clFinish);
187 CL_DEFINE_FUNC_PTR(clReleaseProgram);
188 CL_DEFINE_FUNC_PTR(clRetainContext);
189 CL_DEFINE_FUNC_PTR(clGetContextInfo);
190 CL_DEFINE_FUNC_PTR(clCreateProgramWithBinary);
191 CL_DEFINE_FUNC_PTR(clCreateCommandQueue);
192 CL_DEFINE_FUNC_PTR(clGetCommandQueueInfo);
193 CL_DEFINE_FUNC_PTR(clReleaseCommandQueue);
194 CL_DEFINE_FUNC_PTR(clEnqueueMapBuffer);
195 CL_DEFINE_FUNC_PTR(clEnqueueMapImage);
196 CL_DEFINE_FUNC_PTR(clEnqueueCopyImage);
197 CL_DEFINE_FUNC_PTR(clRetainProgram);
198 CL_DEFINE_FUNC_PTR(clGetProgramBuildInfo);
199 CL_DEFINE_FUNC_PTR(clEnqueueReadBuffer);
200 CL_DEFINE_FUNC_PTR(clEnqueueReadBufferRect);
201 CL_DEFINE_FUNC_PTR(clEnqueueWriteBuffer);
202 CL_DEFINE_FUNC_PTR(clEnqueueWriteImage);
203 CL_DEFINE_FUNC_PTR(clEnqueueReadImage);
204 CL_DEFINE_FUNC_PTR(clWaitForEvents);
205 CL_DEFINE_FUNC_PTR(clReleaseEvent);
206 CL_DEFINE_FUNC_PTR(clCreateContext);
207 CL_DEFINE_FUNC_PTR(clCreateContextFromType);
208 CL_DEFINE_FUNC_PTR(clReleaseContext);
209 CL_DEFINE_FUNC_PTR(clRetainCommandQueue);
210 CL_DEFINE_FUNC_PTR(clEnqueueUnmapMemObject);
211 CL_DEFINE_FUNC_PTR(clRetainMemObject);
212 CL_DEFINE_FUNC_PTR(clReleaseMemObject);
213 CL_DEFINE_FUNC_PTR(clGetDeviceInfo);
214 CL_DEFINE_FUNC_PTR(clGetDeviceIDs);
215 CL_DEFINE_FUNC_PTR(clRetainEvent);
216 CL_DEFINE_FUNC_PTR(clGetKernelWorkGroupInfo);
217 CL_DEFINE_FUNC_PTR(clGetEventInfo);
218 CL_DEFINE_FUNC_PTR(clGetEventProfilingInfo);
219 CL_DEFINE_FUNC_PTR(clGetImageInfo);
220 CL_DEFINE_FUNC_PTR(clEnqueueCopyBufferToImage);
221 CL_DEFINE_FUNC_PTR(clEnqueueCopyImageToBuffer);
222 #if defined(CL_TARGET_OPENCL_VERSION) && CL_TARGET_OPENCL_VERSION >= 120
223 CL_DEFINE_FUNC_PTR(clRetainDevice);
224 CL_DEFINE_FUNC_PTR(clReleaseDevice);
225 CL_DEFINE_FUNC_PTR(clCreateImage);
226 CL_DEFINE_FUNC_PTR(clEnqueueFillImage);
227 #endif
228 #if defined(CL_TARGET_OPENCL_VERSION) && CL_TARGET_OPENCL_VERSION >= 200
229 CL_DEFINE_FUNC_PTR(clGetKernelSubGroupInfoKHR);
230 CL_DEFINE_FUNC_PTR(clCreateCommandQueueWithProperties);
231 CL_DEFINE_FUNC_PTR(clGetExtensionFunctionAddress);
232 CL_DEFINE_FUNC_PTR(clCreateProgramWithIL);
233 CL_DEFINE_FUNC_PTR(clSVMAlloc);
234 CL_DEFINE_FUNC_PTR(clSVMFree);
235 CL_DEFINE_FUNC_PTR(clEnqueueSVMMap);
236 CL_DEFINE_FUNC_PTR(clEnqueueSVMUnmap);
237 CL_DEFINE_FUNC_PTR(clSetKernelArgSVMPointer);
238 #endif
239 #undef LOAD_OPENCL_FUNCTION_PTR
240 } // namespace OHOS
241
242 // clGetPlatformIDs wrapper, use OpenCLWrapper function. use OpenCLWrapper function.
clGetPlatformIDs(cl_uint num_entries,cl_platform_id * platforms,cl_uint * num_platforms)243 cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
244 {
245 OHOS::InitOpenCL();
246 auto func = OHOS::clGetPlatformIDs;
247 MS_ASSERT(func != nullptr);
248 return func(num_entries, platforms, num_platforms);
249 }
250
251 // clGetPlatformInfo wrapper, use OpenCLWrapper function. use OpenCLWrapper function.
clGetPlatformInfo(cl_platform_id platform,cl_platform_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)252 cl_int clGetPlatformInfo(cl_platform_id platform, cl_platform_info param_name, size_t param_value_size,
253 void *param_value, size_t *param_value_size_ret)
254 {
255 OHOS::InitOpenCL();
256 auto func = OHOS::clGetPlatformInfo;
257 MS_ASSERT(func != nullptr);
258 return func(platform, param_name, param_value_size, param_value, param_value_size_ret);
259 }
260
261 // clGetDeviceIDs wrapper, use OpenCLWrapper function.
clGetDeviceIDs(cl_platform_id platform,cl_device_type device_type,cl_uint num_entries,cl_device_id * devices,cl_uint * num_devices)262 cl_int clGetDeviceIDs(cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id *devices,
263 cl_uint *num_devices)
264 {
265 OHOS::InitOpenCL();
266 auto func = OHOS::clGetDeviceIDs;
267 MS_ASSERT(func != nullptr);
268 return func(platform, device_type, num_entries, devices, num_devices);
269 }
270
271 // clGetDeviceInfo wrapper, use OpenCLWrapper function.
clGetDeviceInfo(cl_device_id device,cl_device_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)272 cl_int clGetDeviceInfo(cl_device_id device, cl_device_info param_name, size_t param_value_size, void *param_value,
273 size_t *param_value_size_ret)
274 {
275 OHOS::InitOpenCL();
276 auto func = OHOS::clGetDeviceInfo;
277 MS_ASSERT(func != nullptr);
278 return func(device, param_name, param_value_size, param_value, param_value_size_ret);
279 }
280
281 // clCreateContext wrapper, use OpenCLWrapper function.
clCreateContext(const cl_context_properties * properties,cl_uint num_devices,const cl_device_id * devices,void (CL_CALLBACK * pfn_notify)(const char *,const void *,size_t,void *),void * user_data,cl_int * errcode_ret)282 cl_context clCreateContext(const cl_context_properties *properties, cl_uint num_devices, const cl_device_id *devices,
283 void(CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *), void *user_data,
284 cl_int *errcode_ret)
285 {
286 OHOS::InitOpenCL();
287 auto func = OHOS::clCreateContext;
288 MS_ASSERT(func != nullptr);
289 return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
290 }
291
292 // clCreateContextFromType wrapper, use OpenCLWrapper function.
clCreateContextFromType(const cl_context_properties * properties,cl_device_type device_type,void (CL_CALLBACK * pfn_notify)(const char *,const void *,size_t,void *),void * user_data,cl_int * errcode_ret)293 cl_context clCreateContextFromType(const cl_context_properties *properties, cl_device_type device_type,
294 void(CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *),
295 void *user_data, cl_int *errcode_ret)
296 {
297 OHOS::InitOpenCL();
298 auto func = OHOS::clCreateContextFromType;
299 MS_ASSERT(func != nullptr);
300 return func(properties, device_type, pfn_notify, user_data, errcode_ret);
301 }
302
303 // clRetainContext wrapper, use OpenCLWrapper function.
clRetainContext(cl_context context)304 cl_int clRetainContext(cl_context context)
305 {
306 OHOS::InitOpenCL();
307 auto func = OHOS::clRetainContext;
308 MS_ASSERT(func != nullptr);
309 return func(context);
310 }
311
312 // clReleaseContext wrapper, use OpenCLWrapper function.
clReleaseContext(cl_context context)313 cl_int clReleaseContext(cl_context context)
314 {
315 OHOS::InitOpenCL();
316 auto func = OHOS::clReleaseContext;
317 MS_ASSERT(func != nullptr);
318 return func(context);
319 }
320
321 // clGetContextInfo wrapper, use OpenCLWrapper function.
clGetContextInfo(cl_context context,cl_context_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)322 cl_int clGetContextInfo(cl_context context, cl_context_info param_name, size_t param_value_size, void *param_value,
323 size_t *param_value_size_ret)
324 {
325 OHOS::InitOpenCL();
326 auto func = OHOS::clGetContextInfo;
327 MS_ASSERT(func != nullptr);
328 return func(context, param_name, param_value_size, param_value, param_value_size_ret);
329 }
330
331 // clCreateProgramWithSource wrapper, use OpenCLWrapper function.
clCreateProgramWithSource(cl_context context,cl_uint count,const char ** strings,const size_t * lengths,cl_int * errcode_ret)332 cl_program clCreateProgramWithSource(cl_context context, cl_uint count, const char **strings, const size_t *lengths,
333 cl_int *errcode_ret)
334 {
335 OHOS::InitOpenCL();
336 auto func = OHOS::clCreateProgramWithSource;
337 MS_ASSERT(func != nullptr);
338 return func(context, count, strings, lengths, errcode_ret);
339 }
340
341 // clCreateProgramWithBinary wrapper, use OpenCLWrapper function.
clCreateProgramWithBinary(cl_context context,cl_uint num_devices,const cl_device_id * devices_list,const size_t * lengths,const unsigned char ** binaries,cl_int * binary_status,cl_int * errcode_ret)342 cl_program clCreateProgramWithBinary(cl_context context, cl_uint num_devices, const cl_device_id *devices_list,
343 const size_t *lengths, const unsigned char **binaries, cl_int *binary_status,
344 cl_int *errcode_ret)
345 {
346 OHOS::InitOpenCL();
347 auto func = OHOS::clCreateProgramWithBinary;
348 MS_ASSERT(func != nullptr);
349 return func(context, num_devices, devices_list, lengths, binaries, binary_status, errcode_ret);
350 }
351
352 // clGetProgramInfo wrapper, use OpenCLWrapper function.
clGetProgramInfo(cl_program program,cl_program_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)353 cl_int clGetProgramInfo(cl_program program, cl_program_info param_name, size_t param_value_size, void *param_value,
354 size_t *param_value_size_ret)
355 {
356 OHOS::InitOpenCL();
357 auto func = OHOS::clGetProgramInfo;
358 MS_ASSERT(func != nullptr);
359 return func(program, param_name, param_value_size, param_value, param_value_size_ret);
360 }
361
362 // clGetProgramBuildInfo wrapper, use OpenCLWrapper function.
clGetProgramBuildInfo(cl_program program,cl_device_id device,cl_program_build_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)363 cl_int clGetProgramBuildInfo(cl_program program, cl_device_id device, cl_program_build_info param_name,
364 size_t param_value_size, void *param_value, size_t *param_value_size_ret)
365 {
366 OHOS::InitOpenCL();
367 auto func = OHOS::clGetProgramBuildInfo;
368 MS_ASSERT(func != nullptr);
369 return func(program, device, param_name, param_value_size, param_value, param_value_size_ret);
370 }
371
372 // clRetainProgram wrapper, use OpenCLWrapper function.
clRetainProgram(cl_program program)373 cl_int clRetainProgram(cl_program program)
374 {
375 OHOS::InitOpenCL();
376 auto func = OHOS::clRetainProgram;
377 MS_ASSERT(func != nullptr);
378 return func(program);
379 }
380
381 // clReleaseProgram wrapper, use OpenCLWrapper function.
clReleaseProgram(cl_program program)382 cl_int clReleaseProgram(cl_program program)
383 {
384 OHOS::InitOpenCL();
385 auto func = OHOS::clReleaseProgram;
386 MS_ASSERT(func != nullptr);
387 return func(program);
388 }
389
390 // clBuildProgram wrapper, use OpenCLWrapper function.
clBuildProgram(cl_program program,cl_uint num_devices,const cl_device_id * device_list,const char * options,void (CL_CALLBACK * pfn_notify)(cl_program program,void * user_data),void * user_data)391 cl_int clBuildProgram(cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options,
392 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data), void *user_data)
393 {
394 OHOS::InitOpenCL();
395 auto func = OHOS::clBuildProgram;
396 MS_ASSERT(func != nullptr);
397 return func(program, num_devices, device_list, options, pfn_notify, user_data);
398 }
399
400 // clCreateKernel wrapper, use OpenCLWrapper function.
clCreateKernel(cl_program program,const char * kernelName,cl_int * errcode_ret)401 cl_kernel clCreateKernel(cl_program program, const char *kernelName, cl_int *errcode_ret)
402 {
403 OHOS::InitOpenCL();
404 auto func = OHOS::clCreateKernel;
405 MS_ASSERT(func != nullptr);
406 return func(program, kernelName, errcode_ret);
407 }
408
409 // clRetainKernel wrapper, use OpenCLWrapper function.
clRetainKernel(cl_kernel kernel)410 cl_int clRetainKernel(cl_kernel kernel)
411 {
412 OHOS::InitOpenCL();
413 auto func = OHOS::clRetainKernel;
414 MS_ASSERT(func != nullptr);
415 return func(kernel);
416 }
417
418 // clReleaseKernel wrapper, use OpenCLWrapper function.
clReleaseKernel(cl_kernel kernel)419 cl_int clReleaseKernel(cl_kernel kernel)
420 {
421 OHOS::InitOpenCL();
422 auto func = OHOS::clReleaseKernel;
423 MS_ASSERT(func != nullptr);
424 return func(kernel);
425 }
426
427 // clSetKernelArg wrapper, use OpenCLWrapper function.
clSetKernelArg(cl_kernel kernel,cl_uint arg_index,size_t arg_size,const void * arg_value)428 cl_int clSetKernelArg(cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value)
429 {
430 OHOS::InitOpenCL();
431 auto func = OHOS::clSetKernelArg;
432 MS_ASSERT(func != nullptr);
433 return func(kernel, arg_index, arg_size, arg_value);
434 }
435
436 // clCreateBuffer wrapper, use OpenCLWrapper function.
clCreateBuffer(cl_context context,cl_mem_flags flags,size_t size,void * host_ptr,cl_int * errcode_ret)437 cl_mem clCreateBuffer(cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret)
438 {
439 OHOS::InitOpenCL();
440 auto func = OHOS::clCreateBuffer;
441 MS_ASSERT(func != nullptr);
442 return func(context, flags, size, host_ptr, errcode_ret);
443 }
444
445 // clRetainMemObject wrapper, use OpenCLWrapper function.
clRetainMemObject(cl_mem memobj)446 cl_int clRetainMemObject(cl_mem memobj)
447 {
448 OHOS::InitOpenCL();
449 auto func = OHOS::clRetainMemObject;
450 MS_ASSERT(func != nullptr);
451 return func(memobj);
452 }
453
454 // clReleaseMemObject wrapper, use OpenCLWrapper function.
clReleaseMemObject(cl_mem memobj)455 cl_int clReleaseMemObject(cl_mem memobj)
456 {
457 OHOS::InitOpenCL();
458 auto func = OHOS::clReleaseMemObject;
459 MS_ASSERT(func != nullptr);
460 return func(memobj);
461 }
462
463 // clGetImageInfo wrapper, use OpenCLWrapper function.
clGetImageInfo(cl_mem image,cl_image_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)464 cl_int clGetImageInfo(cl_mem image, cl_image_info param_name, size_t param_value_size, void *param_value,
465 size_t *param_value_size_ret)
466 {
467 OHOS::InitOpenCL();
468 auto func = OHOS::clGetImageInfo;
469 MS_ASSERT(func != nullptr);
470 return func(image, param_name, param_value_size, param_value, param_value_size_ret);
471 }
472
473 // clRetainCommandQueue wrapper, use OpenCLWrapper function.
clRetainCommandQueue(cl_command_queue command_queue)474 cl_int clRetainCommandQueue(cl_command_queue command_queue)
475 {
476 OHOS::InitOpenCL();
477 auto func = OHOS::clRetainCommandQueue;
478 MS_ASSERT(func != nullptr);
479 return func(command_queue);
480 }
481
482 // clReleaseCommandQueue wrapper, use OpenCLWrapper function.
clReleaseCommandQueue(cl_command_queue command_queue)483 cl_int clReleaseCommandQueue(cl_command_queue command_queue)
484 {
485 OHOS::InitOpenCL();
486 auto func = OHOS::clReleaseCommandQueue;
487 MS_ASSERT(func != nullptr);
488 return func(command_queue);
489 }
490
491 // clEnqueueReadBuffer wrapper, use OpenCLWrapper function.
clEnqueueReadBuffer(cl_command_queue command_queue,cl_mem buffer,cl_bool blocking_read,size_t offset,size_t size,void * ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)492 cl_int clEnqueueReadBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, size_t offset,
493 size_t size, void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list,
494 cl_event *event)
495 {
496 OHOS::InitOpenCL();
497 auto func = OHOS::clEnqueueReadBuffer;
498 MS_ASSERT(func != nullptr);
499 return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list,
500 event_wait_list, event);
501 }
502
503 // clEnqueueReadBufferRect wrapper, use OpenCLWrapper function.
clEnqueueReadBufferRect(cl_command_queue command_queue,cl_mem buffer,cl_bool blocking_read,const size_t * buffer_origin,const size_t * host_origin,const size_t * region,size_t buffer_row_pitch,size_t buffer_slice_pitch,size_t host_row_pitch,size_t host_slice_pitch,void * ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)504 cl_int clEnqueueReadBufferRect(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read,
505 const size_t *buffer_origin, const size_t *host_origin, const size_t *region,
506 size_t buffer_row_pitch, size_t buffer_slice_pitch, size_t host_row_pitch,
507 size_t host_slice_pitch, void *ptr, cl_uint num_events_in_wait_list,
508 const cl_event *event_wait_list, cl_event *event)
509 {
510 OHOS::InitOpenCL();
511 auto func = OHOS::clEnqueueReadBufferRect;
512 MS_ASSERT(func != nullptr);
513 return func(command_queue, buffer, blocking_read, buffer_origin, host_origin, region, buffer_row_pitch,
514 buffer_slice_pitch, host_row_pitch, host_slice_pitch, ptr, num_events_in_wait_list,
515 event_wait_list, event);
516 }
517
518 // clEnqueueWriteBuffer wrapper, use OpenCLWrapper function.
clEnqueueWriteBuffer(cl_command_queue command_queue,cl_mem buffer,cl_bool blocking_write,size_t offset,size_t size,const void * ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)519 cl_int clEnqueueWriteBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, size_t offset,
520 size_t size, const void *ptr, cl_uint num_events_in_wait_list,
521 const cl_event *event_wait_list, cl_event *event)
522 {
523 OHOS::InitOpenCL();
524 auto func = OHOS::clEnqueueWriteBuffer;
525 MS_ASSERT(func != nullptr);
526 return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list,
527 event);
528 }
529
530 // clEnqueueWriteImage wrapper, use OpenCLWrapper function.
clEnqueueWriteImage(cl_command_queue command_queue,cl_mem image,cl_bool blocking_write,const size_t * origin,const size_t * region,size_t input_row_pitch,size_t input_slice_pitch,const void * ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)531 cl_int clEnqueueWriteImage(cl_command_queue command_queue, cl_mem image, cl_bool blocking_write, const size_t *origin,
532 const size_t *region, size_t input_row_pitch, size_t input_slice_pitch, const void *ptr,
533 cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
534 {
535 OHOS::InitOpenCL();
536 auto func = OHOS::clEnqueueWriteImage;
537 MS_ASSERT(func != nullptr);
538 return func(command_queue, image, blocking_write, origin, region, input_row_pitch, input_slice_pitch, ptr,
539 num_events_in_wait_list, event_wait_list, event);
540 }
541
542 // clEnqueueReadImage wrapper, use OpenCLWrapper function.
clEnqueueReadImage(cl_command_queue command_queue,cl_mem image,cl_bool blocking_read,const size_t * origin,const size_t * region,size_t row_pitch,size_t slice_pitch,void * ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)543 cl_int clEnqueueReadImage(cl_command_queue command_queue, cl_mem image, cl_bool blocking_read, const size_t *origin,
544 const size_t *region, size_t row_pitch, size_t slice_pitch, void *ptr,
545 cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
546 {
547 OHOS::InitOpenCL();
548 auto func = OHOS::clEnqueueReadImage;
549 MS_ASSERT(func != nullptr);
550 return func(command_queue, image, blocking_read, origin, region, row_pitch, slice_pitch, ptr,
551 num_events_in_wait_list, event_wait_list, event);
552 }
553
554 // clEnqueueMapBuffer wrapper, use OpenCLWrapper function.
clEnqueueMapBuffer(cl_command_queue command_queue,cl_mem buffer,cl_bool blocking_map,cl_map_flags map_flags,size_t offset,size_t size,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event,cl_int * errcode_ret)555 void *clEnqueueMapBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_map, cl_map_flags map_flags,
556 size_t offset, size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list,
557 cl_event *event, cl_int *errcode_ret)
558 {
559 OHOS::InitOpenCL();
560 auto func = OHOS::clEnqueueMapBuffer;
561 MS_ASSERT(func != nullptr);
562 return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list,
563 event, errcode_ret);
564 }
565
566 // clEnqueueMapImage wrapper, use OpenCLWrapper function.
clEnqueueMapImage(cl_command_queue command_queue,cl_mem image,cl_bool blocking_map,cl_map_flags map_flags,const size_t * origin,const size_t * region,size_t * image_row_pitch,size_t * image_slice_pitch,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event,cl_int * errcode_ret)567 void *clEnqueueMapImage(cl_command_queue command_queue, cl_mem image, cl_bool blocking_map, cl_map_flags map_flags,
568 const size_t *origin, const size_t *region, size_t *image_row_pitch, size_t *image_slice_pitch,
569 cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event,
570 cl_int *errcode_ret)
571 {
572 OHOS::InitOpenCL();
573 auto func = OHOS::clEnqueueMapImage;
574 MS_ASSERT(func != nullptr);
575 return func(command_queue, image, blocking_map, map_flags, origin, region, image_row_pitch, image_slice_pitch,
576 num_events_in_wait_list, event_wait_list, event, errcode_ret);
577 }
578
579 // clEnqueueUnmapMemObject wrapper, use OpenCLWrapper function.
clEnqueueUnmapMemObject(cl_command_queue command_queue,cl_mem memobj,void * mapped_ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)580 cl_int clEnqueueUnmapMemObject(cl_command_queue command_queue, cl_mem memobj, void *mapped_ptr,
581 cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
582 {
583 OHOS::InitOpenCL();
584 auto func = OHOS::clEnqueueUnmapMemObject;
585 MS_ASSERT(func != nullptr);
586 return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
587 }
588
589 // clGetKernelWorkGroupInfo wrapper, use OpenCLWrapper function.
clGetKernelWorkGroupInfo(cl_kernel kernel,cl_device_id device,cl_kernel_work_group_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)590 cl_int clGetKernelWorkGroupInfo(cl_kernel kernel, cl_device_id device, cl_kernel_work_group_info param_name,
591 size_t param_value_size, void *param_value, size_t *param_value_size_ret)
592 {
593 OHOS::InitOpenCL();
594 auto func = OHOS::clGetKernelWorkGroupInfo;
595 MS_ASSERT(func != nullptr);
596 return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
597 }
598
599 // clGetEventProfilingInfo wrapper, use OpenCLWrapper function.
clGetEventProfilingInfo(cl_event event,cl_profiling_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)600 cl_int clGetEventProfilingInfo(cl_event event, cl_profiling_info param_name, size_t param_value_size, void *param_value,
601 size_t *param_value_size_ret)
602 {
603 OHOS::InitOpenCL();
604 auto func = OHOS::clGetEventProfilingInfo;
605 MS_ASSERT(func != nullptr);
606 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
607 }
608
609 // clEnqueueNDRangeKernel wrapper, use OpenCLWrapper function.
clEnqueueNDRangeKernel(cl_command_queue command_queue,cl_kernel kernel,cl_uint work_dim,const size_t * global_work_offset,const size_t * global_work_size,const size_t * local_work_size,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)610 cl_int clEnqueueNDRangeKernel(cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim,
611 const size_t *global_work_offset, const size_t *global_work_size,
612 const size_t *local_work_size, cl_uint num_events_in_wait_list,
613 const cl_event *event_wait_list, cl_event *event)
614 {
615 OHOS::InitOpenCL();
616 auto func = OHOS::clEnqueueNDRangeKernel;
617 MS_ASSERT(func != nullptr);
618 return func(command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size,
619 num_events_in_wait_list, event_wait_list, event);
620 }
621
622 // clWaitForEvents wrapper, use OpenCLWrapper function.
clWaitForEvents(cl_uint num_events,const cl_event * event_list)623 cl_int clWaitForEvents(cl_uint num_events, const cl_event *event_list)
624 {
625 OHOS::InitOpenCL();
626 auto func = OHOS::clWaitForEvents;
627 MS_ASSERT(func != nullptr);
628 return func(num_events, event_list);
629 }
630
631 // clRetainEvent wrapper, use OpenCLWrapper function.
clRetainEvent(cl_event event)632 cl_int clRetainEvent(cl_event event)
633 {
634 OHOS::InitOpenCL();
635 auto func = OHOS::clRetainEvent;
636 MS_ASSERT(func != nullptr);
637 return func(event);
638 }
639
640 // clReleaseEvent wrapper, use OpenCLWrapper function.
clReleaseEvent(cl_event event)641 cl_int clReleaseEvent(cl_event event)
642 {
643 OHOS::InitOpenCL();
644 auto func = OHOS::clReleaseEvent;
645 MS_ASSERT(func != nullptr);
646 return func(event);
647 }
648
649 // clGetEventInfo wrapper, use OpenCLWrapper function.
clGetEventInfo(cl_event event,cl_event_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)650 cl_int clGetEventInfo(cl_event event, cl_event_info param_name, size_t param_value_size, void *param_value,
651 size_t *param_value_size_ret)
652 {
653 OHOS::InitOpenCL();
654 auto func = OHOS::clGetEventInfo;
655 MS_ASSERT(func != nullptr);
656 return func(event, param_name, param_value_size, param_value, param_value_size_ret);
657 }
658
659 // clFlush wrapper, use OpenCLWrapper function.
clFlush(cl_command_queue command_queue)660 cl_int clFlush(cl_command_queue command_queue)
661 {
662 OHOS::InitOpenCL();
663 auto func = OHOS::clFlush;
664 MS_ASSERT(func != nullptr);
665 return func(command_queue);
666 }
667
668 // clFinish wrapper, use OpenCLWrapper function.
clFinish(cl_command_queue command_queue)669 cl_int clFinish(cl_command_queue command_queue)
670 {
671 OHOS::InitOpenCL();
672 auto func = OHOS::clFinish;
673 MS_ASSERT(func != nullptr);
674 return func(command_queue);
675 }
676
677 // clCreateImage2D wrapper, use OpenCLWrapper function.
clCreateImage2D(cl_context context,cl_mem_flags flags,const cl_image_format * image_format,size_t imageWidth,size_t imageHeight,size_t image_row_pitch,void * host_ptr,cl_int * errcode_ret)678 cl_mem clCreateImage2D(cl_context context, cl_mem_flags flags, const cl_image_format *image_format, size_t imageWidth,
679 size_t imageHeight, size_t image_row_pitch, void *host_ptr, cl_int *errcode_ret)
680 {
681 OHOS::InitOpenCL();
682 auto func = OHOS::clCreateImage2D;
683 MS_ASSERT(func != nullptr);
684 return func(context, flags, image_format, imageWidth, imageHeight, image_row_pitch, host_ptr, errcode_ret);
685 }
686
687 // clCreateImage3D wrapper, use OpenCLWrapper function.
clCreateImage3D(cl_context context,cl_mem_flags flags,const cl_image_format * image_format,size_t imageWidth,size_t imageHeight,size_t imageDepth,size_t image_row_pitch,size_t image_slice_pitch,void * host_ptr,cl_int * errcode_ret)688 cl_mem clCreateImage3D(cl_context context, cl_mem_flags flags, const cl_image_format *image_format, size_t imageWidth,
689 size_t imageHeight, size_t imageDepth, size_t image_row_pitch, size_t image_slice_pitch,
690 void *host_ptr, cl_int *errcode_ret)
691 {
692 OHOS::InitOpenCL();
693 auto func = OHOS::clCreateImage3D;
694 MS_ASSERT(func != nullptr);
695 return func(context, flags, image_format, imageWidth, imageHeight, imageDepth, image_row_pitch, image_slice_pitch,
696 host_ptr, errcode_ret);
697 }
698
699 // clCreateCommandQueue wrapper, use OpenCLWrapper function.
clCreateCommandQueue(cl_context context,cl_device_id device,cl_command_queue_properties properties,cl_int * errcode_ret)700 cl_command_queue clCreateCommandQueue(cl_context context, cl_device_id device, cl_command_queue_properties properties,
701 cl_int *errcode_ret)
702 {
703 OHOS::InitOpenCL();
704 auto func = OHOS::clCreateCommandQueue;
705 MS_ASSERT(func != nullptr);
706 return func(context, device, properties, errcode_ret);
707 }
708
709 // clGetCommandQueueInfo wrapper, use OpenCLWrapper function.
clGetCommandQueueInfo(cl_command_queue command_queue,cl_command_queue_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)710 cl_int clGetCommandQueueInfo(cl_command_queue command_queue, cl_command_queue_info param_name, size_t param_value_size,
711 void *param_value, size_t *param_value_size_ret)
712 {
713 OHOS::InitOpenCL();
714 auto func = OHOS::clGetCommandQueueInfo;
715 MS_ASSERT(func != nullptr);
716 return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
717 }
718
719 // clEnqueueCopyImage wrapper, use OpenCLWrapper function.
clEnqueueCopyImage(cl_command_queue queue,cl_mem src_image,cl_mem dst_image,const size_t * src_origin,const size_t * dst_origin,const size_t * region,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)720 cl_int clEnqueueCopyImage(cl_command_queue queue, cl_mem src_image, cl_mem dst_image, const size_t *src_origin,
721 const size_t *dst_origin, const size_t *region, cl_uint num_events_in_wait_list,
722 const cl_event *event_wait_list, cl_event *event)
723 {
724 OHOS::InitOpenCL();
725 auto func = OHOS::clEnqueueCopyImage;
726 MS_ASSERT(func != nullptr);
727 return func(queue, src_image, dst_image, src_origin, dst_origin, region, num_events_in_wait_list, event_wait_list,
728 event);
729 }
730
731 // clEnqueueCopyBufferToImage wrapper, use OpenCLWrapper function.
clEnqueueCopyBufferToImage(cl_command_queue command_queue,cl_mem src_buffer,cl_mem dst_image,size_t src_offset,const size_t * dst_origin,const size_t * region,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)732 cl_int clEnqueueCopyBufferToImage(cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_image,
733 size_t src_offset, const size_t *dst_origin, const size_t *region,
734 cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
735 {
736 OHOS::InitOpenCL();
737 auto func = OHOS::clEnqueueCopyBufferToImage;
738 MS_ASSERT(func != nullptr);
739 return func(command_queue, src_buffer, dst_image, src_offset, dst_origin, region, num_events_in_wait_list,
740 event_wait_list, event);
741 }
742
743 // clEnqueueCopyImageToBuffer wrapper, use OpenCLWrapper function.
clEnqueueCopyImageToBuffer(cl_command_queue command_queue,cl_mem src_image,cl_mem dst_buffer,const size_t * src_origin,const size_t * region,size_t dst_offset,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)744 cl_int clEnqueueCopyImageToBuffer(cl_command_queue command_queue, cl_mem src_image, cl_mem dst_buffer,
745 const size_t *src_origin, const size_t *region, size_t dst_offset,
746 cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
747 {
748 OHOS::InitOpenCL();
749 auto func = OHOS::clEnqueueCopyImageToBuffer;
750 MS_ASSERT(func != nullptr);
751 return func(command_queue, src_image, dst_buffer, src_origin, region, dst_offset, num_events_in_wait_list,
752 event_wait_list, event);
753 }
754
755 #if defined(CL_TARGET_OPENCL_VERSION) && CL_TARGET_OPENCL_VERSION >= 120
756
757 // clRetainDevice wrapper, use OpenCLWrapper function.
clRetainDevice(cl_device_id device)758 cl_int clRetainDevice(cl_device_id device)
759 {
760 OHOS::InitOpenCL();
761 auto func = OHOS::clRetainDevice;
762 MS_ASSERT(func != nullptr);
763 return func(device);
764 }
765
766 // clReleaseDevice wrapper, use OpenCLWrapper function.
clReleaseDevice(cl_device_id device)767 cl_int clReleaseDevice(cl_device_id device)
768 {
769 OHOS::InitOpenCL();
770 auto func = OHOS::clReleaseDevice;
771 MS_ASSERT(func != nullptr);
772 return func(device);
773 }
774
775 // clCreateImage wrapper, use OpenCLWrapper function.
clCreateImage(cl_context context,cl_mem_flags flags,const cl_image_format * image_format,const cl_image_desc * image_desc,void * host_ptr,cl_int * errcode_ret)776 cl_mem clCreateImage(cl_context context, cl_mem_flags flags, const cl_image_format *image_format,
777 const cl_image_desc *image_desc, void *host_ptr, cl_int *errcode_ret)
778 {
779 OHOS::InitOpenCL();
780 auto func = OHOS::clCreateImage;
781 MS_ASSERT(func != nullptr);
782 return func(context, flags, image_format, image_desc, host_ptr, errcode_ret);
783 }
784
clEnqueueFillImage(cl_command_queue command_queue,cl_mem image,const void * fill_color,const size_t * origin,const size_t * region,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)785 cl_int clEnqueueFillImage(cl_command_queue command_queue, cl_mem image, const void *fill_color, const size_t *origin,
786 const size_t *region, cl_uint num_events_in_wait_list, const cl_event *event_wait_list,
787 cl_event *event)
788 {
789 OHOS::InitOpenCL();
790 auto func = OHOS::clEnqueueFillImage;
791 MS_ASSERT(func != nullptr);
792 return func(command_queue, image, fill_color, origin, region, num_events_in_wait_list, event_wait_list, event);
793 }
794
795 #endif
796
797 #if defined(CL_TARGET_OPENCL_VERSION) && CL_TARGET_OPENCL_VERSION >= 200
798
799 // clCreateCommandQueueWithProperties wrapper, use OpenCLWrapper function.
clCreateCommandQueueWithProperties(cl_context context,cl_device_id device,const cl_queue_properties * properties,cl_int * errcode_ret)800 cl_command_queue clCreateCommandQueueWithProperties(cl_context context, cl_device_id device,
801 const cl_queue_properties *properties, cl_int *errcode_ret)
802 {
803 OHOS::InitOpenCL();
804 auto func = OHOS::clCreateCommandQueueWithProperties;
805 MS_ASSERT(func != nullptr);
806 return func(context, device, properties, errcode_ret);
807 }
808
809 // clGetExtensionFunctionAddress wrapper, use OpenCLWrapper function.
clGetExtensionFunctionAddress(const char * func_name)810 void *clGetExtensionFunctionAddress(const char *func_name)
811 {
812 OHOS::InitOpenCL();
813 auto func = OHOS::clGetExtensionFunctionAddress;
814 MS_ASSERT(func != nullptr);
815 return func(func_name);
816 }
817 // clCreateProgramWithIL wrapper, use OpenCLWrapper function.
clCreateProgramWithIL(cl_context context,const void * il,size_t length,cl_int * ret)818 cl_program clCreateProgramWithIL(cl_context context, const void *il, size_t length, cl_int *ret)
819 {
820 OHOS::InitOpenCL();
821 auto func = OHOS::clCreateProgramWithIL;
822 MS_ASSERT(func != nullptr);
823 return func(context, il, length, ret);
824 }
825
826 // clSVMAlloc wrapper, use OpenCLWrapper function.
clSVMAlloc(cl_context context,cl_mem_flags flags,size_t size,cl_uint align)827 void *clSVMAlloc(cl_context context, cl_mem_flags flags, size_t size, cl_uint align)
828 {
829 OHOS::InitOpenCL();
830 auto func = OHOS::clSVMAlloc;
831 MS_ASSERT(func != nullptr);
832 return func(context, flags, size, align);
833 }
834
835 // clSVMFree wrapper, use OpenCLWrapper function.
clSVMFree(cl_context context,void * buffer)836 void clSVMFree(cl_context context, void *buffer)
837 {
838 OHOS::InitOpenCL();
839 auto func = OHOS::clSVMFree;
840 MS_ASSERT(func != nullptr);
841 func(context, buffer);
842 }
843
844 // clEnqueueSVMMap wrapper, use OpenCLWrapper function.
clEnqueueSVMMap(cl_command_queue command_queue,cl_bool blocking,cl_map_flags flags,void * host_ptr,size_t size,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)845 cl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking, cl_map_flags flags, void *host_ptr,
846 size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
847 {
848 OHOS::InitOpenCL();
849 auto func = OHOS::clEnqueueSVMMap;
850 MS_ASSERT(func != nullptr);
851 return func(command_queue, blocking, flags, host_ptr, size, num_events_in_wait_list, event_wait_list, event);
852 }
853
854 // clEnqueueSVMUnmap wrapper, use OpenCLWrapper function.
clEnqueueSVMUnmap(cl_command_queue command_queue,void * host_ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)855 cl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *host_ptr, cl_uint num_events_in_wait_list,
856 const cl_event *event_wait_list, cl_event *event)
857 {
858 OHOS::InitOpenCL();
859 auto func = OHOS::clEnqueueSVMUnmap;
860 MS_ASSERT(func != nullptr);
861 return func(command_queue, host_ptr, num_events_in_wait_list, event_wait_list, event);
862 }
863
864 // clSetKernelArgSVMPointer wrapper, use OpenCLWrapper function.
clSetKernelArgSVMPointer(cl_kernel kernel,cl_uint index,const void * host_ptr)865 cl_int clSetKernelArgSVMPointer(cl_kernel kernel, cl_uint index, const void *host_ptr)
866 {
867 OHOS::InitOpenCL();
868 auto func = OHOS::clSetKernelArgSVMPointer;
869 MS_ASSERT(func != nullptr);
870 return func(kernel, index, host_ptr);
871 }
872 #endif
873
874 #endif // USE_OPENCL_WRAPPER
875