Error while enabling OpenCL on TVM Android Demo Application

Dear All , I am trying to run TVM compiled GPU models on Android Device

I have followed https://github.com/apache/tvm/blob/main/apps/android_deploy/README.md link to run TVM complied GPU models on Android Device.

I have modified https://github.com/apache/tvm/blob/main/apps/android_deploy/app/src/main/jni/make/config.mk as below

APP_ABI = arm64-v8a APP_PLATFORM = android-30

whether enable OpenCL during compile

USE_OPENCL = 1

the additional include headers you want to add, e.g., SDK_PATH/adrenosdk/Development/Inc

ADD_C_INCLUDES += /opt/tools/opencl-sdk-1.3/inc

the additional link libs you want to add, e.g., ANDROID_LIB_PATH/libOpenCL.so

ADD_LDLIBS = /opt/tools/libs/libOpenCL.so

I have openCL SDK at “/opt/tools/” and I have pulled libOpenCL.so from S21 device and kept at “/opt/tools/libs/”

But I am getting below error during compilation, make: Entering directory ‘/home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni’ [arm64-v8a] Compile++ : tvm4j_runtime_packed <= org_apache_tvm_native_c_api.cc [arm64-v8a] SharedLibrary : libtvm4j_runtime_packed.so /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/objs/tvm4j_runtime_packed/org_apache_tvm_native_c_api.o: In function tvm::runtime::cl::OpenCLWorkspace::AllocDataSpace(DLContext, unsigned long, unsigned long, DLDataType)': /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_device_api.cc:124: undefined reference to clCreateBuffer’ /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/objs/tvm4j_runtime_packed/org_apache_tvm_native_c_api.o: In function tvm::runtime::cl::OpenCLWorkspace::FreeDataSpace(DLContext, void*)': /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_device_api.cc:132: undefined reference to clFinish’ /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/…/…/…/…/…/…/include/…/src/runtime/opencl/opencl_device_api.cc:135: undefined reference to clReleaseMemObject' /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/objs/tvm4j_runtime_packed/org_apache_tvm_native_c_api.o: In function tvm::runtime::cl::OpenCLWorkspace::CopyDataFromTo(void const*, unsigned long, void*, unsigned long, unsigned long, DLContext, DLContext, DLDataType, void*)’: /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/…/…/…/…/…/…/include/…/src/runtime/opencl/opencl_device_api.cc:145: undefined reference to clEnqueueCopyBuffer' /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_device_api.cc:150: undefined reference to clEnqueueReadBuffer’ /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/…/…/…/…/…/…/include/…/src/runtime/opencl/opencl_device_api.cc:154: undefined reference to clFinish' /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_device_api.cc:156: undefined reference to clEnqueueWriteBuffer’ /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/…/…/…/…/…/…/include/…/src/runtime/opencl/opencl_device_api.cc:159: undefined reference to clFinish' /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/objs/tvm4j_runtime_packed/org_apache_tvm_native_c_api.o: In function tvm::runtime::cl::OpenCLWorkspace::StreamSync(DLContext, void*)’: /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/…/…/…/…/…/…/include/…/src/runtime/opencl/opencl_device_api.cc:167: undefined reference to clFinish' /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/objs/tvm4j_runtime_packed/org_apache_tvm_native_c_api.o: In function tvm::runtime::cl::GetPlatformInfo(_cl_platform_id*, unsigned int)’: /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/…/…/…/…/…/…/include/…/src/runtime/opencl/opencl_device_api.cc:184: undefined reference to clGetPlatformInfo' /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_device_api.cc:187: undefined reference to clGetPlatformInfo’ /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/objs/tvm4j_runtime_packed/org_apache_tvm_native_c_api.o: In function tvm::runtime::cl::GetDeviceInfo(_cl_device_id*, unsigned int)': /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_device_api.cc:193: undefined reference to clGetDeviceInfo’ /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/…/…/…/…/…/…/include/…/src/runtime/opencl/opencl_device_api.cc:196: undefined reference to clGetDeviceInfo' /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/objs/tvm4j_runtime_packed/org_apache_tvm_native_c_api.o: In function tvm::runtime::cl::GetPlatformIDs()’: /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/…/…/…/…/…/…/include/…/src/runtime/opencl/opencl_device_api.cc:202: undefined reference to clGetPlatformIDs' /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_device_api.cc:206: undefined reference to clGetPlatformIDs’ /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/objs/tvm4j_runtime_packed/org_apache_tvm_native_c_api.o: In function tvm::runtime::cl::GetDeviceIDs(_cl_platform_id*, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >)': /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_device_api.cc:216: undefined reference to clGetDeviceIDs’ /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/…/…/…/…/…/…/include/…/src/runtime/opencl/opencl_device_api.cc:220: undefined reference to clGetDeviceIDs' /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/objs/tvm4j_runtime_packed/org_apache_tvm_native_c_api.o: In function tvm::runtime::cl::OpenCLWorkspace::Init(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const&)’: /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/…/…/…/…/…/…/include/…/src/runtime/opencl/opencl_device_api.cc:266: undefined reference to clCreateContext' /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_device_api.cc:272: undefined reference to clCreateCommandQueue’ /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/objs/tvm4j_runtime_packed/org_apache_tvm_native_c_api.o: In function ~OpenCLModuleNode': /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_module.cc:106: undefined reference to clReleaseKernel’ /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/…/…/…/…/…/…/include/…/src/runtime/opencl/opencl_module.cc:109: undefined reference to clReleaseProgram' /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/objs/tvm4j_runtime_packed/org_apache_tvm_native_c_api.o: In function tvm::runtime::OpenCLModuleNode::InstallKernel(tvm::runtime::cl::OpenCLWorkspace*, tvm::runtime::cl::OpenCLThreadEntry*, std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const&, tvm::runtime::OpenCLModuleNode::KTRefEntry const&)’: /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/…/…/…/…/…/…/include/…/src/runtime/opencl/opencl_module.cc:205: undefined reference to clCreateProgramWithBinary' /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_module.cc:197: undefined reference to clCreateProgramWithSource’ /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/…/…/…/…/…/…/include/…/src/runtime/opencl/opencl_module.cc:213: undefined reference to clBuildProgram' /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_module.cc:217: undefined reference to clGetProgramBuildInfo’ /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/…/…/…/…/…/…/include/…/src/runtime/opencl/opencl_module.cc:219: undefined reference to clGetProgramBuildInfo' /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_module.cc:226: undefined reference to clCreateKernel’ /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/objs/tvm4j_runtime_packed/org_apache_tvm_native_c_api.o: In function ~OpenCLWorkspace': /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_common.h:213: undefined reference to clReleaseContext’ /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/objs/tvm4j_runtime_packed/org_apache_tvm_native_c_api.o: In function tvm::runtime::OpenCLWrappedFunc::operator()(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*, void**) const': /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_module.cc:66: undefined reference to clSetKernelArg’ /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni/…/…/…/…/…/…/include/…/src/runtime/opencl/opencl_module.cc:75: undefined reference to clEnqueueNDRangeKernel' /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/objs/tvm4j_runtime_packed/org_apache_tvm_native_c_api.o: In function OUTLINED_FUNCTION_77’: org_apache_tvm_native_c_api.cc:(.text.OUTLINED_FUNCTION_77+0x8): undefined reference to `clGetDeviceInfo’ clang++: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [/opt/tools/android-ndk-r21e/build/core/build-binary.mk:725: /home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/libtvm4j_runtime_packed.so] Error 1 make: Leaving directory ‘/home/test/srividya/TVM/tvm/apps/android_deploy/app/src/main/jni’ :app:buildJni FAILED

Environment : Laptop:: Description: Ubuntu 20.04.3 LTS Release: 20.04

Target:: Samsung Galaxy S21 GLES: Qualcomm, Adreno ™ 660, OpenGL ES 3.2 V@0530.0 (GIT@a3316bc, I2fb6e682e6, 1630041608) (Date:08/27/21)

Kindly guide how to resolve the Error…