参考了很多资料,apt-get太慢了,中断;svn co http://llvm.org/svn/llvm-project/cfe/trunk clang下载中断。
还是从官网下载源码靠谱。
下载源码
官网
http://releases.llvm.org/download.html#8.0.0
wget http://releases.llvm.org/8.0.0/llvm-8.0.0.src.tar.xz
wget http://releases.llvm.org/8.0.0/cfe-8.0.0.src.tar.xz
解压到llvm和clang
mkdir /tmp/llvm_source_build
cd /tmp/llvm_source_build
将llvm移到文件夹中,将clang移到llvm/tool文件夹下。
mv lllvm /tmp/llvm_source_build
mv clang /tmp/llvm_source_build/llvm/tools
获取cmake文件
#新建build目录
cd /tmp/llvm_source_build
mkdir build
cd /build
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" ../llvm
或者
cmake -G "Unix Makefiles" -DLLVM_ENABLE_ASSERTIONS=On -DCMAKE_BUILD_TYPE=Release ../llvm
上面的-CMAKE_INSTALL_PREDIX=/opt/llvm 表示要安装的目录。
存储空间一定要够,5G左右
得到Makefiile文件之后几可以进行编译和安装了
sudo make -j 8
sudo make install
最后还需要配置一下环境变量。
vim /etc/profile
#在末尾添加
export PATH=$PATH:/opt/llvm/bin
检测是否安装成功
clang --version
$ clang --version
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
下载tvm源码。
git clone --recursive https://github.com/dmlc/tvm/
apt-get update
apt-get install -y python python-dev python-setuptools gcc libtinfo-dev zlib1g-dev
将cmake文件复制到build文件下,准备编译
$ cd tvm
$ mkdir build
$ cp cmake/config.cmake build
$ cd build
修改config.cmake文件
(可选)安装opencl
sudo apt install ocl-icd-opencl-dev
set(USE_CUDA ON) #可选
set(USE_LLVM ON)
开始编译和安装
nohup cmake .. >> build.txt &
tailf build.txt
nohup sudo make -j8 >> build.txt &
/usr/bin/ld: cannot find -lcudart
/usr/bin/ld: cannot find -lcuda
/usr/bin/ld: cannot find -lnvrtc
collect2: error: ld returned 1 exit status
CMakeFiles/tvm_runtime.dir/build.make:799: recipe for target 'libtvm_runtime.so' failed
make[2]: *** [libtvm_runtime.so] Error 1
CMakeFiles/Makefile2:279: recipe for target 'CMakeFiles/tvm_runtime.dir/all' failed
可能是空间不足,cuda不对,解决方式如下
错误/sbin/ldconfig.real: /usr/local/cuda-9.0/targets/x86_64-linux/lib/libcudnn.so.7 is not a symbolic link的原因及解决方法(https://blog.csdn.net/CAU_Ayao/article/details/83512036)
sudo ln -sf /usr/local/cuda-9.0/lib64/libcudnn.so.7.0.5 /usr/local/cuda-9.0/lib64/libcudnn.so.7
如果编译正常完成之后,会在tvm的build目录下面生成一些库文件。
libnnvm_compiler.so
libtvm_runtime.so
libtvm.so
libtvm_topi.so
编译python
$ cd python; python setup.py install --user; cd ..
$ cd topi/python; python setup.py install --user; cd ../..
$ cd nnvm/python; python setup.py install --user; cd ../..
设置PYTHONPATH环境变量
添加环境变量
$ vim ~/.bashrc
添加:
export TVM_PATH=yourpath/to/tvm
export PYTHONPATH=$TVM_PATH/python:$TVM_PATH/topi/python:$TVM_PATH/nnvm/python:${PYTHONPATH}
source ~/.bashrc
TVM社区讨论
https://discuss.tvm.ai/
https://blog.csdn.net/qq_39790992/article/details/90610770
https://blog.csdn.net/l2563898960/article/details/82871826
https://blog.csdn.net/kaien1226/article/details/84953558
https://blog.csdn.net/sanallen/article/details/81430150(交叉编译)
https://github.com/deepinsight/insightface/wiki/Tutorial:-Deploy-Face-Recognition-Model-via-TVM(insightface 教程)