Hello,
I have created simple instruction how to create runtime with opencl
-
TVM_REPO
is place where you clones tvm - install in the system llvm in version 12
- clone https://github.com/KhronosGroup/OpenCL-Headers inside $TVM_REPO
- time to find OpenCL library. I have found it, on target devices. Inside android, it’s usually
/system/vendor/lib64/
. I have placed it in folder$TVM_REPO/opencl_external_libs/system/vendor/lib64
rm -rf $TVM_REPO/build-llvm12-arm-api-28-opencl/*
mkdir -p $TVM_REPO/build-llvm12-arm-api-28-opencl
cp $TVM_REPO/cmake/config.cmake $TVM_REPO/build-llvm12-arm-api-28-opencl
cd $TVM_REPO/build-llvm12-arm-api-28-opencl
sed -i 's/set(USE_OPENCL OFF)/set(USE_OPENCL ON)/g' config.cmake
sed -i 's/set(USE_LLVM OFF)/set(USE_LLVM \/usr\/lib\/llvm-12\/bin\/llvm-config)/g' config.cmake
cmake .. \
-DUSE_RPC=ON \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_VERSION=1 \
-DCMAKE_C_COMPILER=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang \
-DCMAKE_CXX_COMPILER=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang++ \
-DCMAKE_FIND_ROOT_PATH=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/ \
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
-DMACHINE_NAME=armv7a-linux-gnu \
-DOpenCL_INCLUDE_DIR=$TVM_REPO/OpenCL-Headers \
-DOpenCL_LIBRARY=$TVM_REPO/opencl_external_libs/system/vendor/lib64/libOpenCL.so \
-DUSE_LLVM=/usr/lib/llvm-12/bin/llvm-config
make -j4 runtime
Few notes:
- do not use OpenCL headers/sdk from ubuntu repository - it doesn’t work
- specify manually headers and from-phone library (DOpenCL_INCLUDE_DIR and DOpenCL_LIBRARY)
- do not specify OpenCL-SDK(https://github.com/KhronosGroup/OpenCL-SDK) in cmake.config as USE_OPENCL value - it doesn’t work
- make sure you have library and cross-compiler in the same architecture