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