本文主要讲述如何在ubuntu20.04平台上编译TVM代码并在python中import tvm成功。
源代码下载:
git clone --recursive https://github.com/apache/tvm tvm
平台环境升级:
1) sudo apt-get update
2) sudo apt-get install -y python3 python3-dev python3-setuptools gcc libtinfo-dev zlib1g-dev build-essential cmake libedit-dev libxml2-dev
cmake时遇到cmake版本过低的问题(当前是3.16,但tvm源码的CMakeLists.txt要求至少3.18):
cd tvm/
sudo mkdir build
cd build/
sudo chmod 777 -R ./
cmake ..
想通过apt-get install cmake==xxx来安装指定版本的cmake但失败:
aptitude versions cmake
sudo apt-get update
sudo apt-get install aptitude
aptitude versions cmake #寻找可以安装的cmake版本
sudo apt-get install cmake=3.20.2 #失败
sudo apt-get install cmake=3.20.0 #失败
通过源代码来编译安装cmake指定版本成功!
cd /work/
wget https://cmake.org/files/v3.22/cmake-3.22.0.tar.gz
tar xvzf cmake-3.22.0.tar.gz
cd cmake-3.22.0/
./configure
./configure时遇到下面的错误:
CMake Error at Utilities/cmcurl/CMakeLists.txt:562 (message): Could not find OpenSSL. Install an OpenSSL development package or configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL.
通过下面命令解决并./configure成功
sudo apt-get install libssl-dev
./configure
cmake安装成功,并显示版本号为3.22
sudo make install
cmake --version
解决cmake版本问题后,tvm代码就顺利编译成功
cd tvm/build/
cp ../cmake/config.cmake build
cmake ..
make -j16
选择适当的LLVM已经编译好的安装包并下载
tar -xf clang+llvm-13.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz
在tvm中指定llvm binary所在的路径
vi /work/tvm/build/config.cmake,并作如下修改
重新编译tvm
cd /work/tvm/build
make clean;make -j16
最后在python环境验证tvm是否安装成功:
需要先安装pip,numpy以及decorator安装包
sudo apt install python3-pip
pip3 install numpy
pip3 install decorator
并将tvm的安装路径添加到PYTHONPATH
export TVM_HOME=/work/tvm
export PYTHONPATH=TVM_HOME/python:PYTHONPATH
最后python中成功import tvm: