本文记录TVM的安装方式,主要验证官方教程中从源码安装是否对WSL可行,同时在VS Code上配置相应的开发环境。
下面代码都在WSL环境中运行,同时用virtualenv创建了Python 3.6的虚拟环境。
# 1. Clone the project
git clone --recursive https://github.com/apache/incubator-tvm tvm
# 2. Install Linux dependencies
sudo apt-get update
sudo apt-get install -y python3 python3-dev python3-setuptools gcc libtinfo-dev zlib1g-dev build-essential cmake libedit-dev libxml2-dev
# 3. Build the shared library
mkdir build
cp cmake/config.cmake build # change settings in cmake file
# for cpu and gpu, need to install LLVM first
# i) Download LLVM pre-built version 9.0 from http://releases.llvm.org/download.html
# 2) set (USE_LLVM /path/to/llvm/bin/llvm-config) in config.cmake
cd build
cmake ..
make -j4
# 4. Python package installation
# Recommended for developers, no need to call setup!
# It would be better if adding them to ~/.bashrc
export TVM_HOME=/path/to/tvm
export PYTHONPATH=$TVM_HOME/python:$TVM_HOME/topi/python:${PYTHONPATH}
# after v0.6
export TVM_HOME=/path/to/tvm
export PYTHONPATH=$TVM_HOME/python:${PYTHONPATH}
# 5. Install python dependencies
pip install numpy decorator attrs
事实证明官方教程讲得很清晰,之后就可以顺利在Python里import tvm
啦!
可以通过测试GEMM在CPU上的例子看是否能正常编译。
虽然TVM的安装很简单,但是对于LLVM来说依然需要重新配置。
# 1. Download and install cmake first
# https://cmake.org/download/
wget https://github.com/Kitware/CMake/releases/download/v3.22.0-rc1/cmake-3.22.0-rc1.tar.gz
tar -xzvf cmake-3.22.0-rc1.tar.gz
cd cmake-3.22.0-rc1.tar.gz
./bootstrap
makemake install
# 2. Download and install LLVM from
# https://releases.llvm.org/download.html
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.1/llvm-10.0.1.src.tar.xz
tar -xf llvm-10.0.1.src.tar.xz
cd llvm-10.0.1.src
mkdir build
cd build
/path/to/cmake -DCMAKE_C_COMPILER=/path/to/usr/bin/gcc \
-DCMAKE_CXX_COMPILER=/path/to/usr/bin/g++ \
-DGCC_INSTALL_PREFIX=/path/to/usr ..
/path/to/cmake --build .
/path/to/cmake --build . --target install