Hello,
I’m trying to build tvm_rpc executable, I’m getting following error, that is saying no opencl library present in system:
#11 29.55 [ 90%] Built target tvm_runtime
#11 29.60 Scanning dependencies of target tvm_rpc
#11 29.61 [ 90%] Building CXX object apps/cpp_rpc/CMakeFiles/tvm_rpc.dir/main.cc.o
#11 29.62 [ 90%] Building CXX object apps/cpp_rpc/CMakeFiles/tvm_rpc.dir/rpc_server.cc.o
#11 29.62 [100%] Building CXX object apps/cpp_rpc/CMakeFiles/tvm_rpc.dir/rpc_env.cc.o
#11 32.04 [100%] Linking CXX executable ../../tvm_rpc
#11 32.08 /opt/android-sdk-linux/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: warning: libOpenCL.so, needed by ../../libtvm_runtime.so, not found (try using -rpath or -rpath-link)
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clBuildProgram'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clFinish'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clCreateProgramWithSource'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clReleaseKernel'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clCreateBuffer'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clReleaseProgram'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clGetDeviceIDs'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clGetDeviceInfo'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clEnqueueNDRangeKernel'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clCreateCommandQueue'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clGetPlatformIDs'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clGetPlatformInfo'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clEnqueueCopyBuffer'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clGetEventProfilingInfo'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clCreateContext'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clGetProgramBuildInfo'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clEnqueueWriteImage'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clEnqueueReadBuffer'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clReleaseContext'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clEnqueueReadImage'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clReleaseMemObject'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clWaitForEvents'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clCreateKernel'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clCreateProgramWithBinary'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clCreateImage'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clSetKernelArg'
#11 32.10 ../../libtvm_runtime.so: undefined reference to `clEnqueueWriteBuffer'
What is strange I’m getting some informations during cmake configuration that opencl is enabled:
#11 4.641 -- OpenCL_INCLUDE_DIRS=/workspace/3rdparty/OpenCL-Headers
#11 4.641 -- OpenCL_LIBRARIES=/workspace/3rdparty/opencl_libs/libOpenCL.so
#11 4.641 -- Build with OpenCL support
This is my command:
sed -i 's/set(USE_LIBBACKTRACE AUTO)/set(USE_LIBBACKTRACE OFF)/g' config.cmake && \
sed -i 's/set(USE_CPP_RPC OFF)/set(USE_CPP_RPC ON)/g' config.cmake && \
sed -i 's/set(USE_OPENCL OFF)/set(USE_OPENCL ON)/g' config.cmake && \
sed -i 's/set(USE_OPENGL OFF)/set(USE_OPENGL ON)/g' config.cmake && \
sed -i 's/if (BUILD_FOR_ANDROID AND USE_HEXAGON_SDK)/if (BUILD_FOR_ANDROID AND USE_HEXAGON)/g' ../apps/cpp_rpc/CMakeLists.txt && \
echo 'set(OpenCL_INCLUDE_DIR /workspace/3rdparty/OpenCL-Headers)' >> config.cmake && \
echo 'set(OpenCL_LIBRARY /workspace/3rdparty/opencl_libs/libOpenCL.so)' >> config.cmake && \
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DCMAKE_C_COMPILER=${ANDROID_NDK_HOME}toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang \
-DCMAKE_CXX_COMPILER=${ANDROID_NDK_HOME}toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang++ \
-DCMAKE_FIND_ROOT_PATH=${ANDROID_NDK_HOME}toolchains/llvm/prebuilt/linux-x86_64/ \
-DUSE_LLVM=${ANDROID_NDK_HOME}toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-config \
-DUSE_SORT=ON \
-DUSE_RPC=ON \
-DUSE_HEXAGON_SDK=OFF \
-DUSE_OPENCL=ON \
-DUSE_OPENGL=ON \
-DUSE_LIBBACKTRACE=OFF \
-DUSE_CPP_RPC=ON \
-DUSE_PROFILER=OFF \
-DANDROID_ABI=arm64-v8a \
-DANDROID_PLATFORM=28 \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
&& \
# make VERBOSE=1 -j10 tvm_rpc \
make -j10 tvm_rpc
When I digg more in, I can modify CMakeLists.txt in cpp_rpc, and added:
add_library(openCL SHARED IMPORTED) # or STATIC instead of SHARED
set_target_properties(openCL PROPERTIES
IMPORTED_LOCATION "${OpenCL_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${OpenCL_INCLUDE_DIR}"
)
list(APPEND TVM_RPC_LINKER_LIBS openCL)
Then error with missing OpenCL function is gone, but OpenCL dependencies are not found (log, cutils, utils and libc++):
#11 32.79 [100%] Linking CXX executable ../../tvm_rpc
#11 32.81 /opt/android-sdk-linux/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: warning: libcutils.so, needed by ../../../3rdparty/opencl_libs/libOpenCL.so, not found (try using -rpath or -rpath-link)
#11 32.81 /opt/android-sdk-linux/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: warning: libutils.so, needed by ../../../3rdparty/opencl_libs/libOpenCL.so, not found (try using -rpath or -rpath-link)
#11 32.81 /opt/android-sdk-linux/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: warning: liblog.so, needed by ../../../3rdparty/opencl_libs/libOpenCL.so, not found (try using -rpath or -rpath-link)
#11 32.81 /opt/android-sdk-linux/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: warning: libc++.so, needed by ../../../3rdparty/opencl_libs/libOpenCL.so, not found (try using -rpath or -rpath-link)
#11 32.82 ../../../3rdparty/opencl_libs/libOpenCL.so: undefined reference to `atrace_begin_body'
#11 32.82 ../../../3rdparty/opencl_libs/libOpenCL.so: undefined reference to `atrace_end_body'
#11 32.82 ../../../3rdparty/opencl_libs/libOpenCL.so: undefined reference to `__android_log_print@LIBLOG'
#11 32.82 ../../../3rdparty/opencl_libs/libOpenCL.so: undefined reference to `property_get'
#11 32.82 ../../../3rdparty/opencl_libs/libOpenCL.so: undefined reference to `atrace_get_enabled_tags'
#11 32.82 clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Do I need to copy these libraries from android device (I do not care now about compatibility with other devices)?