从源安装
系统:Ubuntu18.04
tvm版本:0.7.0
llvm版本:10.0.0
1. 从Github获取TVM源码
git clone --recursive https://github.com/apache/tvm tvm
2. 获取TVM所需环境库
(The minimal building requirements for the TVM libraries are:)
• A recent c++ compiler supporting C++ 14 (g++-5 or higher)
• CMake 3.5 or higher
• We highly recommend to build with LLVM to enable all the features.
• If you want to use CUDA, CUDA toolkit version >= 8.0 is required. If you are upgrading from an older version, make sure you purge the older version and reboot after installation.
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. 安装CMake
# 获取cmake源码包
wget https://cmake.org/files/v3.3/cmake-3.3.2.tar.gz
# 解压源码包
tar xzvf cmake-3.3.2.tar.gz
cd cmake-3.3.2
./bootstrap
make
make install
cd到/tvm
mkdir build
# copy the cmake/config.cmake to the directory.
cp cmake/config.cmake build
4. 安装LLVM(和CLANG)
• Since LLVM takes long time to build from source, you can download pre-built version of LLVM from LLVM Download Page.
• Unzip to a certain location, modify build/config.cmake to add set(USE_LLVM /path/to/your/llvm/bin/llvm-config)
解压缩到某个位置,然后编辑
/tvm/build/config.cmake
文件
在这一行将set(USE_LLVM off)
改成set(USE_LLVM /path/to/your/llvm/bin/llvm-config)
/path/to/your # llvm解压缩的路径
5. Build TVM
build tvm and related libraries.
cd build
cmake ..
make -j4
6.安装python
Method 1
- This method is recommended for developers who may change the codes.
- Set the environment variable PYTHONPATH to tell python where to find the library. For example, assume we cloned tvm on the directory /path/to/tvm then we can add the following line in ~/.bashrc. The changes will be immediately reflected once you pull the code and rebuild the project (no need to call setup again)
vim ~/.bashrc.
#添加两行
export TVM_HOME=/path/to/tvm #/path/to,tvm的目录
export PYTHONPATH=$TVM_HOME/python:${PYTHONPATH}
安装必要的依赖项
pip3 install --user numpy decorator attrs
7. 验证TVM安装
python
import tvm
tvm.__version__