180d59932Sopenharmony_ci/* 280d59932Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 380d59932Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 480d59932Sopenharmony_ci * you may not use this file except in compliance with the License. 580d59932Sopenharmony_ci * You may obtain a copy of the License at 680d59932Sopenharmony_ci * 780d59932Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 880d59932Sopenharmony_ci * 980d59932Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1080d59932Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1180d59932Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1280d59932Sopenharmony_ci * See the License for the specific language governing permissions and 1380d59932Sopenharmony_ci * limitations under the License. 1480d59932Sopenharmony_ci */ 1580d59932Sopenharmony_ci#define USE_OPENCL_WRAPPER 1680d59932Sopenharmony_ci#ifdef USE_OPENCL_WRAPPER 1780d59932Sopenharmony_ci 1880d59932Sopenharmony_ci#include "opencl_wrapper.h" 1980d59932Sopenharmony_ci#include <algorithm> 2080d59932Sopenharmony_ci#include <dlfcn.h> 2180d59932Sopenharmony_ci#include <memory> 2280d59932Sopenharmony_ci#include <mutex> 2380d59932Sopenharmony_ci#include <string> 2480d59932Sopenharmony_ci#include <vector> 2580d59932Sopenharmony_ci#include <iostream> 2680d59932Sopenharmony_ci 2780d59932Sopenharmony_cinamespace OHOS { 2880d59932Sopenharmony_ci// default opencl library path 2980d59932Sopenharmony_cistatic const std::vector<std::string> g_opencl_library_paths = { 3080d59932Sopenharmony_ci#if defined(__APPLE__) || defined(__MACOSX) 3180d59932Sopenharmony_ci "libOpenCL.so", "/System/Library/Frameworks/OpenCL.framework/OpenCL" 3280d59932Sopenharmony_ci#else 3380d59932Sopenharmony_ci "/vendor/lib64/chipsetsdk/libGLES_mali.so", 3480d59932Sopenharmony_ci "/system/lib64/libGLES_mali.so", 3580d59932Sopenharmony_ci "libGLES_mali.so", 3680d59932Sopenharmony_ci "/vendor/lib64/chipsetsdk/libhvgr_v200.so", 3780d59932Sopenharmony_ci "/vendor/lib64/chipsetsdk/libEGL_impl.so", 3880d59932Sopenharmony_ci#endif 3980d59932Sopenharmony_ci}; 4080d59932Sopenharmony_ci 4180d59932Sopenharmony_cistatic std::mutex g_initMutex; 4280d59932Sopenharmony_cistatic bool g_isInit = false; 4380d59932Sopenharmony_cistatic bool g_loadSuccess = false; 4480d59932Sopenharmony_cistatic void *g_handle{nullptr}; 4580d59932Sopenharmony_ci 4680d59932Sopenharmony_cibool InitOpenCL() 4780d59932Sopenharmony_ci{ 4880d59932Sopenharmony_ci std::lock_guard<std::mutex> lock(g_initMutex); 4980d59932Sopenharmony_ci if (g_isInit) { 5080d59932Sopenharmony_ci return g_loadSuccess; 5180d59932Sopenharmony_ci } 5280d59932Sopenharmony_ci g_isInit = true; 5380d59932Sopenharmony_ci g_loadSuccess = LoadOpenCLLibrary(&g_handle); 5480d59932Sopenharmony_ci return g_loadSuccess; 5580d59932Sopenharmony_ci} 5680d59932Sopenharmony_ci 5780d59932Sopenharmony_cibool UnLoadOpenCLLibrary(void *handle) 5880d59932Sopenharmony_ci{ 5980d59932Sopenharmony_ci if (handle != nullptr) { 6080d59932Sopenharmony_ci if (dlclose(handle) != 0) { 6180d59932Sopenharmony_ci return false; 6280d59932Sopenharmony_ci } 6380d59932Sopenharmony_ci return true; 6480d59932Sopenharmony_ci } 6580d59932Sopenharmony_ci return true; 6680d59932Sopenharmony_ci} 6780d59932Sopenharmony_ci 6880d59932Sopenharmony_cibool InitOpenCLExtern(void **clSoHandle) 6980d59932Sopenharmony_ci{ 7080d59932Sopenharmony_ci if (clSoHandle == nullptr) { 7180d59932Sopenharmony_ci return false; 7280d59932Sopenharmony_ci } 7380d59932Sopenharmony_ci return LoadOpenCLLibrary(clSoHandle); 7480d59932Sopenharmony_ci} 7580d59932Sopenharmony_ci 7680d59932Sopenharmony_cibool UnLoadCLExtern(void *clSoHandle) 7780d59932Sopenharmony_ci{ 7880d59932Sopenharmony_ci if (clSoHandle == nullptr) { 7980d59932Sopenharmony_ci return false; 8080d59932Sopenharmony_ci } 8180d59932Sopenharmony_ci if (dlclose(clSoHandle) != 0) { 8280d59932Sopenharmony_ci return false; 8380d59932Sopenharmony_ci } 8480d59932Sopenharmony_ci return true; 8580d59932Sopenharmony_ci} 8680d59932Sopenharmony_ci 8780d59932Sopenharmony_cistatic bool LoadLibraryFromPath(const std::string &library_path, void **handle_ptr) 8880d59932Sopenharmony_ci{ 8980d59932Sopenharmony_ci if (handle_ptr == nullptr) { 9080d59932Sopenharmony_ci return false; 9180d59932Sopenharmony_ci } 9280d59932Sopenharmony_ci 9380d59932Sopenharmony_ci *handle_ptr = dlopen(library_path.c_str(), RTLD_NOW | RTLD_LOCAL); 9480d59932Sopenharmony_ci if (*handle_ptr == nullptr) { 9580d59932Sopenharmony_ci return false; 9680d59932Sopenharmony_ci } 9780d59932Sopenharmony_ci 9880d59932Sopenharmony_ci// load function ptr use dlopen and dlsym. 9980d59932Sopenharmony_ci#define LOAD_OPENCL_FUNCTION_PTR(func_name) \ 10080d59932Sopenharmony_ci func_name = reinterpret_cast<func_name##Func>(dlsym(*handle_ptr, #func_name)); \ 10180d59932Sopenharmony_ci if (func_name == nullptr) { \ 10280d59932Sopenharmony_ci return false; \ 10380d59932Sopenharmony_ci } 10480d59932Sopenharmony_ci 10580d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clGetPlatformIDs); 10680d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clGetPlatformInfo); 10780d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clBuildProgram); 10880d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clEnqueueNDRangeKernel); 10980d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clSetKernelArg); 11080d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clReleaseKernel); 11180d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clCreateProgramWithSource); 11280d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clCreateBuffer); 11380d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clCreateImage2D); 11480d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clCreateImage3D); 11580d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clRetainKernel); 11680d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clCreateKernel); 11780d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clGetProgramInfo); 11880d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clFlush); 11980d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clFinish); 12080d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clReleaseProgram); 12180d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clRetainContext); 12280d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clGetContextInfo); 12380d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clCreateProgramWithBinary); 12480d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clCreateCommandQueue); 12580d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clGetCommandQueueInfo); 12680d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clReleaseCommandQueue); 12780d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clEnqueueMapBuffer); 12880d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clEnqueueMapImage); 12980d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clRetainProgram); 13080d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clGetProgramBuildInfo); 13180d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clEnqueueReadBuffer); 13280d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clEnqueueReadBufferRect); 13380d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clEnqueueWriteBuffer); 13480d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clEnqueueReadImage); 13580d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clEnqueueWriteImage); 13680d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clWaitForEvents); 13780d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clReleaseEvent); 13880d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clCreateContext); 13980d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clCreateContextFromType); 14080d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clReleaseContext); 14180d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clRetainCommandQueue); 14280d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clEnqueueUnmapMemObject); 14380d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clRetainMemObject); 14480d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clReleaseMemObject); 14580d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clGetDeviceInfo); 14680d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clGetDeviceIDs); 14780d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clRetainEvent); 14880d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clGetKernelWorkGroupInfo); 14980d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clGetEventInfo); 15080d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clGetEventProfilingInfo); 15180d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clGetImageInfo); 15280d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clEnqueueCopyImage); 15380d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clEnqueueCopyBufferToImage); 15480d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clEnqueueCopyImageToBuffer); 15580d59932Sopenharmony_ci#if defined(CL_TARGET_OPENCL_VERSION) && CL_TARGET_OPENCL_VERSION >= 120 15680d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clRetainDevice); 15780d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clReleaseDevice); 15880d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clCreateImage); 15980d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clEnqueueFillImage); 16080d59932Sopenharmony_ci#endif 16180d59932Sopenharmony_ci#if defined(CL_TARGET_OPENCL_VERSION) && CL_TARGET_OPENCL_VERSION >= 200 16280d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clCreateCommandQueueWithProperties); 16380d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clGetExtensionFunctionAddress); 16480d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clSVMAlloc); 16580d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clSVMFree); 16680d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clEnqueueSVMMap); 16780d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clEnqueueSVMUnmap); 16880d59932Sopenharmony_ci LOAD_OPENCL_FUNCTION_PTR(clSetKernelArgSVMPointer); 16980d59932Sopenharmony_ci#endif 17080d59932Sopenharmony_ci 17180d59932Sopenharmony_ci return true; 17280d59932Sopenharmony_ci} 17380d59932Sopenharmony_ci// load default library path 17480d59932Sopenharmony_cibool LoadOpenCLLibrary(void **handle_ptr) 17580d59932Sopenharmony_ci{ 17680d59932Sopenharmony_ci if (handle_ptr == nullptr) { 17780d59932Sopenharmony_ci return false; 17880d59932Sopenharmony_ci } 17980d59932Sopenharmony_ci auto it = 18080d59932Sopenharmony_ci std::find_if(g_opencl_library_paths.begin(), g_opencl_library_paths.end(), 18180d59932Sopenharmony_ci [&](const std::string &lib_path) { return OHOS::LoadLibraryFromPath(lib_path, handle_ptr); }); 18280d59932Sopenharmony_ci if (it != g_opencl_library_paths.end()) { 18380d59932Sopenharmony_ci return true; 18480d59932Sopenharmony_ci } 18580d59932Sopenharmony_ci return false; 18680d59932Sopenharmony_ci} 18780d59932Sopenharmony_ci 18880d59932Sopenharmony_ci#define CL_DEFINE_FUNC_PTR(func) func##Func func = nullptr 18980d59932Sopenharmony_ci 19080d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clGetPlatformIDs); 19180d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clGetPlatformInfo); 19280d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clBuildProgram); 19380d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clEnqueueNDRangeKernel); 19480d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clSetKernelArg); 19580d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clReleaseKernel); 19680d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clCreateProgramWithSource); 19780d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clCreateBuffer); 19880d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clCreateImage2D); 19980d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clImportMemoryARM); 20080d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clCreateImage3D); 20180d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clRetainKernel); 20280d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clCreateKernel); 20380d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clGetProgramInfo); 20480d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clFlush); 20580d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clFinish); 20680d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clReleaseProgram); 20780d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clRetainContext); 20880d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clGetContextInfo); 20980d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clCreateProgramWithBinary); 21080d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clCreateCommandQueue); 21180d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clGetCommandQueueInfo); 21280d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clReleaseCommandQueue); 21380d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clEnqueueMapBuffer); 21480d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clEnqueueMapImage); 21580d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clEnqueueCopyImage); 21680d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clRetainProgram); 21780d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clGetProgramBuildInfo); 21880d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clEnqueueReadBuffer); 21980d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clEnqueueReadBufferRect); 22080d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clEnqueueWriteBuffer); 22180d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clEnqueueWriteImage); 22280d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clEnqueueReadImage); 22380d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clWaitForEvents); 22480d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clReleaseEvent); 22580d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clCreateContext); 22680d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clCreateContextFromType); 22780d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clReleaseContext); 22880d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clRetainCommandQueue); 22980d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clEnqueueUnmapMemObject); 23080d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clRetainMemObject); 23180d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clReleaseMemObject); 23280d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clGetDeviceInfo); 23380d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clGetDeviceIDs); 23480d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clRetainEvent); 23580d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clGetKernelWorkGroupInfo); 23680d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clGetEventInfo); 23780d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clGetEventProfilingInfo); 23880d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clGetImageInfo); 23980d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clEnqueueCopyBufferToImage); 24080d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clEnqueueCopyImageToBuffer); 24180d59932Sopenharmony_ci#if defined(CL_TARGET_OPENCL_VERSION) && CL_TARGET_OPENCL_VERSION >= 120 24280d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clRetainDevice); 24380d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clReleaseDevice); 24480d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clCreateImage); 24580d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clEnqueueFillImage); 24680d59932Sopenharmony_ci#endif 24780d59932Sopenharmony_ci#if defined(CL_TARGET_OPENCL_VERSION) && CL_TARGET_OPENCL_VERSION >= 200 24880d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clGetKernelSubGroupInfoKHR); 24980d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clCreateCommandQueueWithProperties); 25080d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clGetExtensionFunctionAddress); 25180d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clCreateProgramWithIL); 25280d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clSVMAlloc); 25380d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clSVMFree); 25480d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clEnqueueSVMMap); 25580d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clEnqueueSVMUnmap); 25680d59932Sopenharmony_ciCL_DEFINE_FUNC_PTR(clSetKernelArgSVMPointer); 25780d59932Sopenharmony_ci#endif 25880d59932Sopenharmony_ci#undef LOAD_OPENCL_FUNCTION_PTR 25980d59932Sopenharmony_ci} // namespace OHOS 26080d59932Sopenharmony_ci 26180d59932Sopenharmony_ci// clGetPlatformIDs wrapper, use OpenCLWrapper function. use OpenCLWrapper function. 26280d59932Sopenharmony_cicl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms) 26380d59932Sopenharmony_ci{ 26480d59932Sopenharmony_ci OHOS::InitOpenCL(); 26580d59932Sopenharmony_ci auto func = OHOS::clGetPlatformIDs; 26680d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 26780d59932Sopenharmony_ci return func(num_entries, platforms, num_platforms); 26880d59932Sopenharmony_ci} 26980d59932Sopenharmony_ci 27080d59932Sopenharmony_ci// clGetPlatformInfo wrapper, use OpenCLWrapper function. use OpenCLWrapper function. 27180d59932Sopenharmony_cicl_int clGetPlatformInfo(cl_platform_id platform, cl_platform_info param_name, size_t param_value_size, 27280d59932Sopenharmony_ci void *param_value, size_t *param_value_size_ret) 27380d59932Sopenharmony_ci{ 27480d59932Sopenharmony_ci OHOS::InitOpenCL(); 27580d59932Sopenharmony_ci auto func = OHOS::clGetPlatformInfo; 27680d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 27780d59932Sopenharmony_ci return func(platform, param_name, param_value_size, param_value, param_value_size_ret); 27880d59932Sopenharmony_ci} 27980d59932Sopenharmony_ci 28080d59932Sopenharmony_ci// clGetDeviceIDs wrapper, use OpenCLWrapper function. 28180d59932Sopenharmony_cicl_int clGetDeviceIDs(cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id *devices, 28280d59932Sopenharmony_ci cl_uint *num_devices) 28380d59932Sopenharmony_ci{ 28480d59932Sopenharmony_ci OHOS::InitOpenCL(); 28580d59932Sopenharmony_ci auto func = OHOS::clGetDeviceIDs; 28680d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 28780d59932Sopenharmony_ci return func(platform, device_type, num_entries, devices, num_devices); 28880d59932Sopenharmony_ci} 28980d59932Sopenharmony_ci 29080d59932Sopenharmony_ci// clGetDeviceInfo wrapper, use OpenCLWrapper function. 29180d59932Sopenharmony_cicl_int clGetDeviceInfo(cl_device_id device, cl_device_info param_name, size_t param_value_size, void *param_value, 29280d59932Sopenharmony_ci size_t *param_value_size_ret) 29380d59932Sopenharmony_ci{ 29480d59932Sopenharmony_ci OHOS::InitOpenCL(); 29580d59932Sopenharmony_ci auto func = OHOS::clGetDeviceInfo; 29680d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 29780d59932Sopenharmony_ci return func(device, param_name, param_value_size, param_value, param_value_size_ret); 29880d59932Sopenharmony_ci} 29980d59932Sopenharmony_ci 30080d59932Sopenharmony_ci// clCreateContext wrapper, use OpenCLWrapper function. 30180d59932Sopenharmony_cicl_context clCreateContext(const cl_context_properties *properties, cl_uint num_devices, const cl_device_id *devices, 30280d59932Sopenharmony_ci void(CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *), void *user_data, 30380d59932Sopenharmony_ci cl_int *errcode_ret) 30480d59932Sopenharmony_ci{ 30580d59932Sopenharmony_ci OHOS::InitOpenCL(); 30680d59932Sopenharmony_ci auto func = OHOS::clCreateContext; 30780d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 30880d59932Sopenharmony_ci return func(properties, num_devices, devices, pfn_notify, user_data, errcode_ret); 30980d59932Sopenharmony_ci} 31080d59932Sopenharmony_ci 31180d59932Sopenharmony_ci// clCreateContextFromType wrapper, use OpenCLWrapper function. 31280d59932Sopenharmony_cicl_context clCreateContextFromType(const cl_context_properties *properties, cl_device_type device_type, 31380d59932Sopenharmony_ci void(CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *), 31480d59932Sopenharmony_ci void *user_data, cl_int *errcode_ret) 31580d59932Sopenharmony_ci{ 31680d59932Sopenharmony_ci OHOS::InitOpenCL(); 31780d59932Sopenharmony_ci auto func = OHOS::clCreateContextFromType; 31880d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 31980d59932Sopenharmony_ci return func(properties, device_type, pfn_notify, user_data, errcode_ret); 32080d59932Sopenharmony_ci} 32180d59932Sopenharmony_ci 32280d59932Sopenharmony_ci// clRetainContext wrapper, use OpenCLWrapper function. 32380d59932Sopenharmony_cicl_int clRetainContext(cl_context context) 32480d59932Sopenharmony_ci{ 32580d59932Sopenharmony_ci OHOS::InitOpenCL(); 32680d59932Sopenharmony_ci auto func = OHOS::clRetainContext; 32780d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 32880d59932Sopenharmony_ci return func(context); 32980d59932Sopenharmony_ci} 33080d59932Sopenharmony_ci 33180d59932Sopenharmony_ci// clReleaseContext wrapper, use OpenCLWrapper function. 33280d59932Sopenharmony_cicl_int clReleaseContext(cl_context context) 33380d59932Sopenharmony_ci{ 33480d59932Sopenharmony_ci OHOS::InitOpenCL(); 33580d59932Sopenharmony_ci auto func = OHOS::clReleaseContext; 33680d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 33780d59932Sopenharmony_ci return func(context); 33880d59932Sopenharmony_ci} 33980d59932Sopenharmony_ci 34080d59932Sopenharmony_ci// clGetContextInfo wrapper, use OpenCLWrapper function. 34180d59932Sopenharmony_cicl_int clGetContextInfo(cl_context context, cl_context_info param_name, size_t param_value_size, void *param_value, 34280d59932Sopenharmony_ci size_t *param_value_size_ret) 34380d59932Sopenharmony_ci{ 34480d59932Sopenharmony_ci OHOS::InitOpenCL(); 34580d59932Sopenharmony_ci auto func = OHOS::clGetContextInfo; 34680d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 34780d59932Sopenharmony_ci return func(context, param_name, param_value_size, param_value, param_value_size_ret); 34880d59932Sopenharmony_ci} 34980d59932Sopenharmony_ci 35080d59932Sopenharmony_ci// clCreateProgramWithSource wrapper, use OpenCLWrapper function. 35180d59932Sopenharmony_cicl_program clCreateProgramWithSource(cl_context context, cl_uint count, const char **strings, const size_t *lengths, 35280d59932Sopenharmony_ci cl_int *errcode_ret) 35380d59932Sopenharmony_ci{ 35480d59932Sopenharmony_ci OHOS::InitOpenCL(); 35580d59932Sopenharmony_ci auto func = OHOS::clCreateProgramWithSource; 35680d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 35780d59932Sopenharmony_ci return func(context, count, strings, lengths, errcode_ret); 35880d59932Sopenharmony_ci} 35980d59932Sopenharmony_ci 36080d59932Sopenharmony_ci// clCreateProgramWithBinary wrapper, use OpenCLWrapper function. 36180d59932Sopenharmony_cicl_program clCreateProgramWithBinary(cl_context context, cl_uint num_devices, const cl_device_id *devices_list, 36280d59932Sopenharmony_ci const size_t *lengths, const unsigned char **binaries, cl_int *binary_status, 36380d59932Sopenharmony_ci cl_int *errcode_ret) 36480d59932Sopenharmony_ci{ 36580d59932Sopenharmony_ci OHOS::InitOpenCL(); 36680d59932Sopenharmony_ci auto func = OHOS::clCreateProgramWithBinary; 36780d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 36880d59932Sopenharmony_ci return func(context, num_devices, devices_list, lengths, binaries, binary_status, errcode_ret); 36980d59932Sopenharmony_ci} 37080d59932Sopenharmony_ci 37180d59932Sopenharmony_ci// clGetProgramInfo wrapper, use OpenCLWrapper function. 37280d59932Sopenharmony_cicl_int clGetProgramInfo(cl_program program, cl_program_info param_name, size_t param_value_size, void *param_value, 37380d59932Sopenharmony_ci size_t *param_value_size_ret) 37480d59932Sopenharmony_ci{ 37580d59932Sopenharmony_ci OHOS::InitOpenCL(); 37680d59932Sopenharmony_ci auto func = OHOS::clGetProgramInfo; 37780d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 37880d59932Sopenharmony_ci return func(program, param_name, param_value_size, param_value, param_value_size_ret); 37980d59932Sopenharmony_ci} 38080d59932Sopenharmony_ci 38180d59932Sopenharmony_ci// clGetProgramBuildInfo wrapper, use OpenCLWrapper function. 38280d59932Sopenharmony_cicl_int clGetProgramBuildInfo(cl_program program, cl_device_id device, cl_program_build_info param_name, 38380d59932Sopenharmony_ci size_t param_value_size, void *param_value, size_t *param_value_size_ret) 38480d59932Sopenharmony_ci{ 38580d59932Sopenharmony_ci OHOS::InitOpenCL(); 38680d59932Sopenharmony_ci auto func = OHOS::clGetProgramBuildInfo; 38780d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 38880d59932Sopenharmony_ci return func(program, device, param_name, param_value_size, param_value, param_value_size_ret); 38980d59932Sopenharmony_ci} 39080d59932Sopenharmony_ci 39180d59932Sopenharmony_ci// clRetainProgram wrapper, use OpenCLWrapper function. 39280d59932Sopenharmony_cicl_int clRetainProgram(cl_program program) 39380d59932Sopenharmony_ci{ 39480d59932Sopenharmony_ci OHOS::InitOpenCL(); 39580d59932Sopenharmony_ci auto func = OHOS::clRetainProgram; 39680d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 39780d59932Sopenharmony_ci return func(program); 39880d59932Sopenharmony_ci} 39980d59932Sopenharmony_ci 40080d59932Sopenharmony_ci// clReleaseProgram wrapper, use OpenCLWrapper function. 40180d59932Sopenharmony_cicl_int clReleaseProgram(cl_program program) 40280d59932Sopenharmony_ci{ 40380d59932Sopenharmony_ci OHOS::InitOpenCL(); 40480d59932Sopenharmony_ci auto func = OHOS::clReleaseProgram; 40580d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 40680d59932Sopenharmony_ci return func(program); 40780d59932Sopenharmony_ci} 40880d59932Sopenharmony_ci 40980d59932Sopenharmony_ci// clBuildProgram wrapper, use OpenCLWrapper function. 41080d59932Sopenharmony_cicl_int clBuildProgram(cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, 41180d59932Sopenharmony_ci void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data), void *user_data) 41280d59932Sopenharmony_ci{ 41380d59932Sopenharmony_ci OHOS::InitOpenCL(); 41480d59932Sopenharmony_ci auto func = OHOS::clBuildProgram; 41580d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 41680d59932Sopenharmony_ci return func(program, num_devices, device_list, options, pfn_notify, user_data); 41780d59932Sopenharmony_ci} 41880d59932Sopenharmony_ci 41980d59932Sopenharmony_ci// clCreateKernel wrapper, use OpenCLWrapper function. 42080d59932Sopenharmony_cicl_kernel clCreateKernel(cl_program program, const char *kernelName, cl_int *errcode_ret) 42180d59932Sopenharmony_ci{ 42280d59932Sopenharmony_ci OHOS::InitOpenCL(); 42380d59932Sopenharmony_ci auto func = OHOS::clCreateKernel; 42480d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 42580d59932Sopenharmony_ci return func(program, kernelName, errcode_ret); 42680d59932Sopenharmony_ci} 42780d59932Sopenharmony_ci 42880d59932Sopenharmony_ci// clRetainKernel wrapper, use OpenCLWrapper function. 42980d59932Sopenharmony_cicl_int clRetainKernel(cl_kernel kernel) 43080d59932Sopenharmony_ci{ 43180d59932Sopenharmony_ci OHOS::InitOpenCL(); 43280d59932Sopenharmony_ci auto func = OHOS::clRetainKernel; 43380d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 43480d59932Sopenharmony_ci return func(kernel); 43580d59932Sopenharmony_ci} 43680d59932Sopenharmony_ci 43780d59932Sopenharmony_ci// clReleaseKernel wrapper, use OpenCLWrapper function. 43880d59932Sopenharmony_cicl_int clReleaseKernel(cl_kernel kernel) 43980d59932Sopenharmony_ci{ 44080d59932Sopenharmony_ci OHOS::InitOpenCL(); 44180d59932Sopenharmony_ci auto func = OHOS::clReleaseKernel; 44280d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 44380d59932Sopenharmony_ci return func(kernel); 44480d59932Sopenharmony_ci} 44580d59932Sopenharmony_ci 44680d59932Sopenharmony_ci// clSetKernelArg wrapper, use OpenCLWrapper function. 44780d59932Sopenharmony_cicl_int clSetKernelArg(cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value) 44880d59932Sopenharmony_ci{ 44980d59932Sopenharmony_ci OHOS::InitOpenCL(); 45080d59932Sopenharmony_ci auto func = OHOS::clSetKernelArg; 45180d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 45280d59932Sopenharmony_ci return func(kernel, arg_index, arg_size, arg_value); 45380d59932Sopenharmony_ci} 45480d59932Sopenharmony_ci 45580d59932Sopenharmony_ci// clCreateBuffer wrapper, use OpenCLWrapper function. 45680d59932Sopenharmony_cicl_mem clCreateBuffer(cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret) 45780d59932Sopenharmony_ci{ 45880d59932Sopenharmony_ci OHOS::InitOpenCL(); 45980d59932Sopenharmony_ci auto func = OHOS::clCreateBuffer; 46080d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 46180d59932Sopenharmony_ci return func(context, flags, size, host_ptr, errcode_ret); 46280d59932Sopenharmony_ci} 46380d59932Sopenharmony_ci 46480d59932Sopenharmony_ci// clRetainMemObject wrapper, use OpenCLWrapper function. 46580d59932Sopenharmony_cicl_int clRetainMemObject(cl_mem memobj) 46680d59932Sopenharmony_ci{ 46780d59932Sopenharmony_ci OHOS::InitOpenCL(); 46880d59932Sopenharmony_ci auto func = OHOS::clRetainMemObject; 46980d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 47080d59932Sopenharmony_ci return func(memobj); 47180d59932Sopenharmony_ci} 47280d59932Sopenharmony_ci 47380d59932Sopenharmony_ci// clReleaseMemObject wrapper, use OpenCLWrapper function. 47480d59932Sopenharmony_cicl_int clReleaseMemObject(cl_mem memobj) 47580d59932Sopenharmony_ci{ 47680d59932Sopenharmony_ci OHOS::InitOpenCL(); 47780d59932Sopenharmony_ci auto func = OHOS::clReleaseMemObject; 47880d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 47980d59932Sopenharmony_ci return func(memobj); 48080d59932Sopenharmony_ci} 48180d59932Sopenharmony_ci 48280d59932Sopenharmony_ci// clGetImageInfo wrapper, use OpenCLWrapper function. 48380d59932Sopenharmony_cicl_int clGetImageInfo(cl_mem image, cl_image_info param_name, size_t param_value_size, void *param_value, 48480d59932Sopenharmony_ci size_t *param_value_size_ret) 48580d59932Sopenharmony_ci{ 48680d59932Sopenharmony_ci OHOS::InitOpenCL(); 48780d59932Sopenharmony_ci auto func = OHOS::clGetImageInfo; 48880d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 48980d59932Sopenharmony_ci return func(image, param_name, param_value_size, param_value, param_value_size_ret); 49080d59932Sopenharmony_ci} 49180d59932Sopenharmony_ci 49280d59932Sopenharmony_ci// clRetainCommandQueue wrapper, use OpenCLWrapper function. 49380d59932Sopenharmony_cicl_int clRetainCommandQueue(cl_command_queue command_queue) 49480d59932Sopenharmony_ci{ 49580d59932Sopenharmony_ci OHOS::InitOpenCL(); 49680d59932Sopenharmony_ci auto func = OHOS::clRetainCommandQueue; 49780d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 49880d59932Sopenharmony_ci return func(command_queue); 49980d59932Sopenharmony_ci} 50080d59932Sopenharmony_ci 50180d59932Sopenharmony_ci// clReleaseCommandQueue wrapper, use OpenCLWrapper function. 50280d59932Sopenharmony_cicl_int clReleaseCommandQueue(cl_command_queue command_queue) 50380d59932Sopenharmony_ci{ 50480d59932Sopenharmony_ci OHOS::InitOpenCL(); 50580d59932Sopenharmony_ci auto func = OHOS::clReleaseCommandQueue; 50680d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 50780d59932Sopenharmony_ci return func(command_queue); 50880d59932Sopenharmony_ci} 50980d59932Sopenharmony_ci 51080d59932Sopenharmony_ci// clEnqueueReadBuffer wrapper, use OpenCLWrapper function. 51180d59932Sopenharmony_cicl_int clEnqueueReadBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, size_t offset, 51280d59932Sopenharmony_ci size_t size, void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, 51380d59932Sopenharmony_ci cl_event *event) 51480d59932Sopenharmony_ci{ 51580d59932Sopenharmony_ci OHOS::InitOpenCL(); 51680d59932Sopenharmony_ci auto func = OHOS::clEnqueueReadBuffer; 51780d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 51880d59932Sopenharmony_ci return func(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, 51980d59932Sopenharmony_ci event_wait_list, event); 52080d59932Sopenharmony_ci} 52180d59932Sopenharmony_ci 52280d59932Sopenharmony_ci// clEnqueueReadBufferRect wrapper, use OpenCLWrapper function. 52380d59932Sopenharmony_cicl_int clEnqueueReadBufferRect(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, 52480d59932Sopenharmony_ci const size_t *buffer_origin, const size_t *host_origin, const size_t *region, 52580d59932Sopenharmony_ci size_t buffer_row_pitch, size_t buffer_slice_pitch, size_t host_row_pitch, 52680d59932Sopenharmony_ci size_t host_slice_pitch, void *ptr, cl_uint num_events_in_wait_list, 52780d59932Sopenharmony_ci const cl_event *event_wait_list, cl_event *event) 52880d59932Sopenharmony_ci{ 52980d59932Sopenharmony_ci OHOS::InitOpenCL(); 53080d59932Sopenharmony_ci auto func = OHOS::clEnqueueReadBufferRect; 53180d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 53280d59932Sopenharmony_ci return func(command_queue, buffer, blocking_read, buffer_origin, host_origin, region, buffer_row_pitch, 53380d59932Sopenharmony_ci buffer_slice_pitch, host_row_pitch, host_slice_pitch, ptr, num_events_in_wait_list, 53480d59932Sopenharmony_ci event_wait_list, event); 53580d59932Sopenharmony_ci} 53680d59932Sopenharmony_ci 53780d59932Sopenharmony_ci// clEnqueueWriteBuffer wrapper, use OpenCLWrapper function. 53880d59932Sopenharmony_cicl_int clEnqueueWriteBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, size_t offset, 53980d59932Sopenharmony_ci size_t size, const void *ptr, cl_uint num_events_in_wait_list, 54080d59932Sopenharmony_ci const cl_event *event_wait_list, cl_event *event) 54180d59932Sopenharmony_ci{ 54280d59932Sopenharmony_ci OHOS::InitOpenCL(); 54380d59932Sopenharmony_ci auto func = OHOS::clEnqueueWriteBuffer; 54480d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 54580d59932Sopenharmony_ci return func(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, 54680d59932Sopenharmony_ci event); 54780d59932Sopenharmony_ci} 54880d59932Sopenharmony_ci 54980d59932Sopenharmony_ci// clEnqueueWriteImage wrapper, use OpenCLWrapper function. 55080d59932Sopenharmony_cicl_int clEnqueueWriteImage(cl_command_queue command_queue, cl_mem image, cl_bool blocking_write, const size_t *origin, 55180d59932Sopenharmony_ci const size_t *region, size_t input_row_pitch, size_t input_slice_pitch, const void *ptr, 55280d59932Sopenharmony_ci cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) 55380d59932Sopenharmony_ci{ 55480d59932Sopenharmony_ci OHOS::InitOpenCL(); 55580d59932Sopenharmony_ci auto func = OHOS::clEnqueueWriteImage; 55680d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 55780d59932Sopenharmony_ci return func(command_queue, image, blocking_write, origin, region, input_row_pitch, input_slice_pitch, ptr, 55880d59932Sopenharmony_ci num_events_in_wait_list, event_wait_list, event); 55980d59932Sopenharmony_ci} 56080d59932Sopenharmony_ci 56180d59932Sopenharmony_ci// clEnqueueReadImage wrapper, use OpenCLWrapper function. 56280d59932Sopenharmony_cicl_int clEnqueueReadImage(cl_command_queue command_queue, cl_mem image, cl_bool blocking_read, const size_t *origin, 56380d59932Sopenharmony_ci const size_t *region, size_t row_pitch, size_t slice_pitch, void *ptr, 56480d59932Sopenharmony_ci cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) 56580d59932Sopenharmony_ci{ 56680d59932Sopenharmony_ci OHOS::InitOpenCL(); 56780d59932Sopenharmony_ci auto func = OHOS::clEnqueueReadImage; 56880d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 56980d59932Sopenharmony_ci return func(command_queue, image, blocking_read, origin, region, row_pitch, slice_pitch, ptr, 57080d59932Sopenharmony_ci num_events_in_wait_list, event_wait_list, event); 57180d59932Sopenharmony_ci} 57280d59932Sopenharmony_ci 57380d59932Sopenharmony_ci// clEnqueueMapBuffer wrapper, use OpenCLWrapper function. 57480d59932Sopenharmony_civoid *clEnqueueMapBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_map, cl_map_flags map_flags, 57580d59932Sopenharmony_ci size_t offset, size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, 57680d59932Sopenharmony_ci cl_event *event, cl_int *errcode_ret) 57780d59932Sopenharmony_ci{ 57880d59932Sopenharmony_ci OHOS::InitOpenCL(); 57980d59932Sopenharmony_ci auto func = OHOS::clEnqueueMapBuffer; 58080d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 58180d59932Sopenharmony_ci return func(command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, 58280d59932Sopenharmony_ci event, errcode_ret); 58380d59932Sopenharmony_ci} 58480d59932Sopenharmony_ci 58580d59932Sopenharmony_ci// clEnqueueMapImage wrapper, use OpenCLWrapper function. 58680d59932Sopenharmony_civoid *clEnqueueMapImage(cl_command_queue command_queue, cl_mem image, cl_bool blocking_map, cl_map_flags map_flags, 58780d59932Sopenharmony_ci const size_t *origin, const size_t *region, size_t *image_row_pitch, size_t *image_slice_pitch, 58880d59932Sopenharmony_ci cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event, 58980d59932Sopenharmony_ci cl_int *errcode_ret) 59080d59932Sopenharmony_ci{ 59180d59932Sopenharmony_ci OHOS::InitOpenCL(); 59280d59932Sopenharmony_ci auto func = OHOS::clEnqueueMapImage; 59380d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 59480d59932Sopenharmony_ci return func(command_queue, image, blocking_map, map_flags, origin, region, image_row_pitch, image_slice_pitch, 59580d59932Sopenharmony_ci num_events_in_wait_list, event_wait_list, event, errcode_ret); 59680d59932Sopenharmony_ci} 59780d59932Sopenharmony_ci 59880d59932Sopenharmony_ci// clEnqueueUnmapMemObject wrapper, use OpenCLWrapper function. 59980d59932Sopenharmony_cicl_int clEnqueueUnmapMemObject(cl_command_queue command_queue, cl_mem memobj, void *mapped_ptr, 60080d59932Sopenharmony_ci cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) 60180d59932Sopenharmony_ci{ 60280d59932Sopenharmony_ci OHOS::InitOpenCL(); 60380d59932Sopenharmony_ci auto func = OHOS::clEnqueueUnmapMemObject; 60480d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 60580d59932Sopenharmony_ci return func(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event); 60680d59932Sopenharmony_ci} 60780d59932Sopenharmony_ci 60880d59932Sopenharmony_ci// clGetKernelWorkGroupInfo wrapper, use OpenCLWrapper function. 60980d59932Sopenharmony_cicl_int clGetKernelWorkGroupInfo(cl_kernel kernel, cl_device_id device, cl_kernel_work_group_info param_name, 61080d59932Sopenharmony_ci size_t param_value_size, void *param_value, size_t *param_value_size_ret) 61180d59932Sopenharmony_ci{ 61280d59932Sopenharmony_ci OHOS::InitOpenCL(); 61380d59932Sopenharmony_ci auto func = OHOS::clGetKernelWorkGroupInfo; 61480d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 61580d59932Sopenharmony_ci return func(kernel, device, param_name, param_value_size, param_value, param_value_size_ret); 61680d59932Sopenharmony_ci} 61780d59932Sopenharmony_ci 61880d59932Sopenharmony_ci// clGetEventProfilingInfo wrapper, use OpenCLWrapper function. 61980d59932Sopenharmony_cicl_int clGetEventProfilingInfo(cl_event event, cl_profiling_info param_name, size_t param_value_size, void *param_value, 62080d59932Sopenharmony_ci size_t *param_value_size_ret) 62180d59932Sopenharmony_ci{ 62280d59932Sopenharmony_ci OHOS::InitOpenCL(); 62380d59932Sopenharmony_ci auto func = OHOS::clGetEventProfilingInfo; 62480d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 62580d59932Sopenharmony_ci return func(event, param_name, param_value_size, param_value, param_value_size_ret); 62680d59932Sopenharmony_ci} 62780d59932Sopenharmony_ci 62880d59932Sopenharmony_ci// clEnqueueNDRangeKernel wrapper, use OpenCLWrapper function. 62980d59932Sopenharmony_cicl_int clEnqueueNDRangeKernel(cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim, 63080d59932Sopenharmony_ci const size_t *global_work_offset, const size_t *global_work_size, 63180d59932Sopenharmony_ci const size_t *local_work_size, cl_uint num_events_in_wait_list, 63280d59932Sopenharmony_ci const cl_event *event_wait_list, cl_event *event) 63380d59932Sopenharmony_ci{ 63480d59932Sopenharmony_ci OHOS::InitOpenCL(); 63580d59932Sopenharmony_ci auto func = OHOS::clEnqueueNDRangeKernel; 63680d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 63780d59932Sopenharmony_ci return func(command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size, 63880d59932Sopenharmony_ci num_events_in_wait_list, event_wait_list, event); 63980d59932Sopenharmony_ci} 64080d59932Sopenharmony_ci 64180d59932Sopenharmony_ci// clWaitForEvents wrapper, use OpenCLWrapper function. 64280d59932Sopenharmony_cicl_int clWaitForEvents(cl_uint num_events, const cl_event *event_list) 64380d59932Sopenharmony_ci{ 64480d59932Sopenharmony_ci OHOS::InitOpenCL(); 64580d59932Sopenharmony_ci auto func = OHOS::clWaitForEvents; 64680d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 64780d59932Sopenharmony_ci return func(num_events, event_list); 64880d59932Sopenharmony_ci} 64980d59932Sopenharmony_ci 65080d59932Sopenharmony_ci// clRetainEvent wrapper, use OpenCLWrapper function. 65180d59932Sopenharmony_cicl_int clRetainEvent(cl_event event) 65280d59932Sopenharmony_ci{ 65380d59932Sopenharmony_ci OHOS::InitOpenCL(); 65480d59932Sopenharmony_ci auto func = OHOS::clRetainEvent; 65580d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 65680d59932Sopenharmony_ci return func(event); 65780d59932Sopenharmony_ci} 65880d59932Sopenharmony_ci 65980d59932Sopenharmony_ci// clReleaseEvent wrapper, use OpenCLWrapper function. 66080d59932Sopenharmony_cicl_int clReleaseEvent(cl_event event) 66180d59932Sopenharmony_ci{ 66280d59932Sopenharmony_ci OHOS::InitOpenCL(); 66380d59932Sopenharmony_ci auto func = OHOS::clReleaseEvent; 66480d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 66580d59932Sopenharmony_ci return func(event); 66680d59932Sopenharmony_ci} 66780d59932Sopenharmony_ci 66880d59932Sopenharmony_ci// clGetEventInfo wrapper, use OpenCLWrapper function. 66980d59932Sopenharmony_cicl_int clGetEventInfo(cl_event event, cl_event_info param_name, size_t param_value_size, void *param_value, 67080d59932Sopenharmony_ci size_t *param_value_size_ret) 67180d59932Sopenharmony_ci{ 67280d59932Sopenharmony_ci OHOS::InitOpenCL(); 67380d59932Sopenharmony_ci auto func = OHOS::clGetEventInfo; 67480d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 67580d59932Sopenharmony_ci return func(event, param_name, param_value_size, param_value, param_value_size_ret); 67680d59932Sopenharmony_ci} 67780d59932Sopenharmony_ci 67880d59932Sopenharmony_ci// clFlush wrapper, use OpenCLWrapper function. 67980d59932Sopenharmony_cicl_int clFlush(cl_command_queue command_queue) 68080d59932Sopenharmony_ci{ 68180d59932Sopenharmony_ci OHOS::InitOpenCL(); 68280d59932Sopenharmony_ci auto func = OHOS::clFlush; 68380d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 68480d59932Sopenharmony_ci return func(command_queue); 68580d59932Sopenharmony_ci} 68680d59932Sopenharmony_ci 68780d59932Sopenharmony_ci// clFinish wrapper, use OpenCLWrapper function. 68880d59932Sopenharmony_cicl_int clFinish(cl_command_queue command_queue) 68980d59932Sopenharmony_ci{ 69080d59932Sopenharmony_ci OHOS::InitOpenCL(); 69180d59932Sopenharmony_ci auto func = OHOS::clFinish; 69280d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 69380d59932Sopenharmony_ci return func(command_queue); 69480d59932Sopenharmony_ci} 69580d59932Sopenharmony_ci 69680d59932Sopenharmony_ci// clCreateImage2D wrapper, use OpenCLWrapper function. 69780d59932Sopenharmony_cicl_mem clCreateImage2D(cl_context context, cl_mem_flags flags, const cl_image_format *image_format, size_t imageWidth, 69880d59932Sopenharmony_ci size_t imageHeight, size_t image_row_pitch, void *host_ptr, cl_int *errcode_ret) 69980d59932Sopenharmony_ci{ 70080d59932Sopenharmony_ci OHOS::InitOpenCL(); 70180d59932Sopenharmony_ci auto func = OHOS::clCreateImage2D; 70280d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 70380d59932Sopenharmony_ci return func(context, flags, image_format, imageWidth, imageHeight, image_row_pitch, host_ptr, errcode_ret); 70480d59932Sopenharmony_ci} 70580d59932Sopenharmony_ci 70680d59932Sopenharmony_ci// clCreateImage3D wrapper, use OpenCLWrapper function. 70780d59932Sopenharmony_cicl_mem clCreateImage3D(cl_context context, cl_mem_flags flags, const cl_image_format *image_format, size_t imageWidth, 70880d59932Sopenharmony_ci size_t imageHeight, size_t imageDepth, size_t image_row_pitch, size_t image_slice_pitch, 70980d59932Sopenharmony_ci void *host_ptr, cl_int *errcode_ret) 71080d59932Sopenharmony_ci{ 71180d59932Sopenharmony_ci OHOS::InitOpenCL(); 71280d59932Sopenharmony_ci auto func = OHOS::clCreateImage3D; 71380d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 71480d59932Sopenharmony_ci return func(context, flags, image_format, imageWidth, imageHeight, imageDepth, image_row_pitch, image_slice_pitch, 71580d59932Sopenharmony_ci host_ptr, errcode_ret); 71680d59932Sopenharmony_ci} 71780d59932Sopenharmony_ci 71880d59932Sopenharmony_ci// clCreateCommandQueue wrapper, use OpenCLWrapper function. 71980d59932Sopenharmony_cicl_command_queue clCreateCommandQueue(cl_context context, cl_device_id device, cl_command_queue_properties properties, 72080d59932Sopenharmony_ci cl_int *errcode_ret) 72180d59932Sopenharmony_ci{ 72280d59932Sopenharmony_ci OHOS::InitOpenCL(); 72380d59932Sopenharmony_ci auto func = OHOS::clCreateCommandQueue; 72480d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 72580d59932Sopenharmony_ci return func(context, device, properties, errcode_ret); 72680d59932Sopenharmony_ci} 72780d59932Sopenharmony_ci 72880d59932Sopenharmony_ci// clGetCommandQueueInfo wrapper, use OpenCLWrapper function. 72980d59932Sopenharmony_cicl_int clGetCommandQueueInfo(cl_command_queue command_queue, cl_command_queue_info param_name, size_t param_value_size, 73080d59932Sopenharmony_ci void *param_value, size_t *param_value_size_ret) 73180d59932Sopenharmony_ci{ 73280d59932Sopenharmony_ci OHOS::InitOpenCL(); 73380d59932Sopenharmony_ci auto func = OHOS::clGetCommandQueueInfo; 73480d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 73580d59932Sopenharmony_ci return func(command_queue, param_name, param_value_size, param_value, param_value_size_ret); 73680d59932Sopenharmony_ci} 73780d59932Sopenharmony_ci 73880d59932Sopenharmony_ci// clEnqueueCopyImage wrapper, use OpenCLWrapper function. 73980d59932Sopenharmony_cicl_int clEnqueueCopyImage(cl_command_queue queue, cl_mem src_image, cl_mem dst_image, const size_t *src_origin, 74080d59932Sopenharmony_ci const size_t *dst_origin, const size_t *region, cl_uint num_events_in_wait_list, 74180d59932Sopenharmony_ci const cl_event *event_wait_list, cl_event *event) 74280d59932Sopenharmony_ci{ 74380d59932Sopenharmony_ci OHOS::InitOpenCL(); 74480d59932Sopenharmony_ci auto func = OHOS::clEnqueueCopyImage; 74580d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 74680d59932Sopenharmony_ci return func(queue, src_image, dst_image, src_origin, dst_origin, region, num_events_in_wait_list, event_wait_list, 74780d59932Sopenharmony_ci event); 74880d59932Sopenharmony_ci} 74980d59932Sopenharmony_ci 75080d59932Sopenharmony_ci// clEnqueueCopyBufferToImage wrapper, use OpenCLWrapper function. 75180d59932Sopenharmony_cicl_int clEnqueueCopyBufferToImage(cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_image, 75280d59932Sopenharmony_ci size_t src_offset, const size_t *dst_origin, const size_t *region, 75380d59932Sopenharmony_ci cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) 75480d59932Sopenharmony_ci{ 75580d59932Sopenharmony_ci OHOS::InitOpenCL(); 75680d59932Sopenharmony_ci auto func = OHOS::clEnqueueCopyBufferToImage; 75780d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 75880d59932Sopenharmony_ci return func(command_queue, src_buffer, dst_image, src_offset, dst_origin, region, num_events_in_wait_list, 75980d59932Sopenharmony_ci event_wait_list, event); 76080d59932Sopenharmony_ci} 76180d59932Sopenharmony_ci 76280d59932Sopenharmony_ci// clEnqueueCopyImageToBuffer wrapper, use OpenCLWrapper function. 76380d59932Sopenharmony_cicl_int clEnqueueCopyImageToBuffer(cl_command_queue command_queue, cl_mem src_image, cl_mem dst_buffer, 76480d59932Sopenharmony_ci const size_t *src_origin, const size_t *region, size_t dst_offset, 76580d59932Sopenharmony_ci cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) 76680d59932Sopenharmony_ci{ 76780d59932Sopenharmony_ci OHOS::InitOpenCL(); 76880d59932Sopenharmony_ci auto func = OHOS::clEnqueueCopyImageToBuffer; 76980d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 77080d59932Sopenharmony_ci return func(command_queue, src_image, dst_buffer, src_origin, region, dst_offset, num_events_in_wait_list, 77180d59932Sopenharmony_ci event_wait_list, event); 77280d59932Sopenharmony_ci} 77380d59932Sopenharmony_ci 77480d59932Sopenharmony_ci#if defined(CL_TARGET_OPENCL_VERSION) && CL_TARGET_OPENCL_VERSION >= 120 77580d59932Sopenharmony_ci 77680d59932Sopenharmony_ci// clRetainDevice wrapper, use OpenCLWrapper function. 77780d59932Sopenharmony_cicl_int clRetainDevice(cl_device_id device) 77880d59932Sopenharmony_ci{ 77980d59932Sopenharmony_ci OHOS::InitOpenCL(); 78080d59932Sopenharmony_ci auto func = OHOS::clRetainDevice; 78180d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 78280d59932Sopenharmony_ci return func(device); 78380d59932Sopenharmony_ci} 78480d59932Sopenharmony_ci 78580d59932Sopenharmony_ci// clReleaseDevice wrapper, use OpenCLWrapper function. 78680d59932Sopenharmony_cicl_int clReleaseDevice(cl_device_id device) 78780d59932Sopenharmony_ci{ 78880d59932Sopenharmony_ci OHOS::InitOpenCL(); 78980d59932Sopenharmony_ci auto func = OHOS::clReleaseDevice; 79080d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 79180d59932Sopenharmony_ci return func(device); 79280d59932Sopenharmony_ci} 79380d59932Sopenharmony_ci 79480d59932Sopenharmony_ci// clCreateImage wrapper, use OpenCLWrapper function. 79580d59932Sopenharmony_cicl_mem clCreateImage(cl_context context, cl_mem_flags flags, const cl_image_format *image_format, 79680d59932Sopenharmony_ci const cl_image_desc *image_desc, void *host_ptr, cl_int *errcode_ret) 79780d59932Sopenharmony_ci{ 79880d59932Sopenharmony_ci OHOS::InitOpenCL(); 79980d59932Sopenharmony_ci auto func = OHOS::clCreateImage; 80080d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 80180d59932Sopenharmony_ci return func(context, flags, image_format, image_desc, host_ptr, errcode_ret); 80280d59932Sopenharmony_ci} 80380d59932Sopenharmony_ci 80480d59932Sopenharmony_cicl_int clEnqueueFillImage(cl_command_queue command_queue, cl_mem image, const void *fill_color, const size_t *origin, 80580d59932Sopenharmony_ci const size_t *region, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, 80680d59932Sopenharmony_ci cl_event *event) 80780d59932Sopenharmony_ci{ 80880d59932Sopenharmony_ci OHOS::InitOpenCL(); 80980d59932Sopenharmony_ci auto func = OHOS::clEnqueueFillImage; 81080d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 81180d59932Sopenharmony_ci return func(command_queue, image, fill_color, origin, region, num_events_in_wait_list, event_wait_list, event); 81280d59932Sopenharmony_ci} 81380d59932Sopenharmony_ci 81480d59932Sopenharmony_ci#endif 81580d59932Sopenharmony_ci 81680d59932Sopenharmony_ci#if defined(CL_TARGET_OPENCL_VERSION) && CL_TARGET_OPENCL_VERSION >= 200 81780d59932Sopenharmony_ci 81880d59932Sopenharmony_ci// clCreateCommandQueueWithProperties wrapper, use OpenCLWrapper function. 81980d59932Sopenharmony_cicl_command_queue clCreateCommandQueueWithProperties(cl_context context, cl_device_id device, 82080d59932Sopenharmony_ci const cl_queue_properties *properties, cl_int *errcode_ret) 82180d59932Sopenharmony_ci{ 82280d59932Sopenharmony_ci OHOS::InitOpenCL(); 82380d59932Sopenharmony_ci auto func = OHOS::clCreateCommandQueueWithProperties; 82480d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 82580d59932Sopenharmony_ci return func(context, device, properties, errcode_ret); 82680d59932Sopenharmony_ci} 82780d59932Sopenharmony_ci 82880d59932Sopenharmony_ci// clGetExtensionFunctionAddress wrapper, use OpenCLWrapper function. 82980d59932Sopenharmony_civoid *clGetExtensionFunctionAddress(const char *func_name) 83080d59932Sopenharmony_ci{ 83180d59932Sopenharmony_ci OHOS::InitOpenCL(); 83280d59932Sopenharmony_ci auto func = OHOS::clGetExtensionFunctionAddress; 83380d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 83480d59932Sopenharmony_ci return func(func_name); 83580d59932Sopenharmony_ci} 83680d59932Sopenharmony_ci// clCreateProgramWithIL wrapper, use OpenCLWrapper function. 83780d59932Sopenharmony_cicl_program clCreateProgramWithIL(cl_context context, const void *il, size_t length, cl_int *ret) 83880d59932Sopenharmony_ci{ 83980d59932Sopenharmony_ci OHOS::InitOpenCL(); 84080d59932Sopenharmony_ci auto func = OHOS::clCreateProgramWithIL; 84180d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 84280d59932Sopenharmony_ci return func(context, il, length, ret); 84380d59932Sopenharmony_ci} 84480d59932Sopenharmony_ci 84580d59932Sopenharmony_ci// clSVMAlloc wrapper, use OpenCLWrapper function. 84680d59932Sopenharmony_civoid *clSVMAlloc(cl_context context, cl_mem_flags flags, size_t size, cl_uint align) 84780d59932Sopenharmony_ci{ 84880d59932Sopenharmony_ci OHOS::InitOpenCL(); 84980d59932Sopenharmony_ci auto func = OHOS::clSVMAlloc; 85080d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 85180d59932Sopenharmony_ci return func(context, flags, size, align); 85280d59932Sopenharmony_ci} 85380d59932Sopenharmony_ci 85480d59932Sopenharmony_ci// clSVMFree wrapper, use OpenCLWrapper function. 85580d59932Sopenharmony_civoid clSVMFree(cl_context context, void *buffer) 85680d59932Sopenharmony_ci{ 85780d59932Sopenharmony_ci OHOS::InitOpenCL(); 85880d59932Sopenharmony_ci auto func = OHOS::clSVMFree; 85980d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 86080d59932Sopenharmony_ci func(context, buffer); 86180d59932Sopenharmony_ci} 86280d59932Sopenharmony_ci 86380d59932Sopenharmony_ci// clEnqueueSVMMap wrapper, use OpenCLWrapper function. 86480d59932Sopenharmony_cicl_int clEnqueueSVMMap(cl_command_queue command_queue, cl_bool blocking, cl_map_flags flags, void *host_ptr, 86580d59932Sopenharmony_ci size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) 86680d59932Sopenharmony_ci{ 86780d59932Sopenharmony_ci OHOS::InitOpenCL(); 86880d59932Sopenharmony_ci auto func = OHOS::clEnqueueSVMMap; 86980d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 87080d59932Sopenharmony_ci return func(command_queue, blocking, flags, host_ptr, size, num_events_in_wait_list, event_wait_list, event); 87180d59932Sopenharmony_ci} 87280d59932Sopenharmony_ci 87380d59932Sopenharmony_ci// clEnqueueSVMUnmap wrapper, use OpenCLWrapper function. 87480d59932Sopenharmony_cicl_int clEnqueueSVMUnmap(cl_command_queue command_queue, void *host_ptr, cl_uint num_events_in_wait_list, 87580d59932Sopenharmony_ci const cl_event *event_wait_list, cl_event *event) 87680d59932Sopenharmony_ci{ 87780d59932Sopenharmony_ci OHOS::InitOpenCL(); 87880d59932Sopenharmony_ci auto func = OHOS::clEnqueueSVMUnmap; 87980d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 88080d59932Sopenharmony_ci return func(command_queue, host_ptr, num_events_in_wait_list, event_wait_list, event); 88180d59932Sopenharmony_ci} 88280d59932Sopenharmony_ci 88380d59932Sopenharmony_ci// clSetKernelArgSVMPointer wrapper, use OpenCLWrapper function. 88480d59932Sopenharmony_cicl_int clSetKernelArgSVMPointer(cl_kernel kernel, cl_uint index, const void *host_ptr) 88580d59932Sopenharmony_ci{ 88680d59932Sopenharmony_ci OHOS::InitOpenCL(); 88780d59932Sopenharmony_ci auto func = OHOS::clSetKernelArgSVMPointer; 88880d59932Sopenharmony_ci MS_ASSERT(func != nullptr); 88980d59932Sopenharmony_ci return func(kernel, index, host_ptr); 89080d59932Sopenharmony_ci} 89180d59932Sopenharmony_ci#endif 89280d59932Sopenharmony_ci 89380d59932Sopenharmony_ci#endif // USE_OPENCL_WRAPPER 894