因為tvm版本變化較大,v5.0-v6.0目錄結構都不一樣,所以安裝要參照官方文檔
https://tvm.apache.org/docs/install/from_source.html
之前在服務器上按照官方文檔裝都裝不上,在運行sudo apt-get update命令時候一直無法更新軟件列表,我也沒把這個問題放到心上,后來發現公司的代理不能連上阿里源,所以我把源換回了官方,后來按照官方文檔裝就好了,但是還有幾個python的依賴沒裝上,以后再說吧。
源文件 /etc/apt/sources.list
換源的時候記得要備份以前的源文件,換完了不好使也可以直接換回去
ubuntu18.04官方源
# deb cdrom:[Ubuntu 18.04.3 LTS _Bionic Beaver_ - Release amd64 (20190805)]/ bionic main restricted # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. deb http://us.archive.ubuntu.com/ubuntu/ bionic main restricted # deb-src http://us.archive.ubuntu.com/ubuntu/ bionic main restricted ## Major bug fix updates produced after the final release of the ## distribution. deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted # deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team. Also, please note that software in universe WILL NOT receive any ## review or updates from the Ubuntu security team. deb http://us.archive.ubuntu.com/ubuntu/ bionic universe # deb-src http://us.archive.ubuntu.com/ubuntu/ bionic universe deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates universe # deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates universe ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team, and may not be under a free licence. Please satisfy yourself as to ## your rights to use the software. Also, please note that software in ## multiverse WILL NOT receive any review or updates from the Ubuntu ## security team. deb http://us.archive.ubuntu.com/ubuntu/ bionic multiverse # deb-src http://us.archive.ubuntu.com/ubuntu/ bionic multiverse deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates multiverse # deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates multiverse ## N.B. software from this repository may not have been tested as ## extensively as that contained in the main release, although it includes ## newer versions of some applications which may provide useful features. ## Also, please note that software in backports WILL NOT receive any review ## or updates from the Ubuntu security team. deb http://us.archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse # deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse ## Uncomment the following two lines to add software from Canonical's ## 'partner' repository. ## This software is not part of Ubuntu, but is offered by Canonical and the ## respective vendors as a service to Ubuntu users. # deb http://archive.canonical.com/ubuntu bionic partner # deb-src http://archive.canonical.com/ubuntu bionic partner deb http://security.ubuntu.com/ubuntu bionic-security main restricted # deb-src http://security.ubuntu.com/ubuntu bionic-security main restricted deb http://security.ubuntu.com/ubuntu bionic-security universe # deb-src http://security.ubuntu.com/ubuntu bionic-security universe deb http://security.ubuntu.com/ubuntu bionic-security multiverse # deb-src http://security.ubuntu.com/ubuntu bionic-security multiverse
換源之后進行更新
sudo apt-get update
sudo apt-get upgrade
新建目錄存放tvm源碼
sudo mkdir tvm
clone代碼到本地
sudo git clone --recursive https://github.com/apache/tvm tvm
--recursive一定要加上
查看一下源碼結構
安裝需要的庫
sudo apt-get install -y python3 python3-dev python3-setuptools gcc libtinfo-dev zlib1g-dev build-essential cmake libedit-dev libxml2-dev
在tvm目錄中新建build文件夾,后面再build文件夾中進行編譯
sudo mkdir build
將配置文件拷貝到build文件夾中
sudo cp cmake/config.cmake build
在開始編譯前需要下載llvm
下載地址:https://releases.llvm.org/download.html
直接選擇自己系統對應的版本
點擊下載,下載到對應目錄中,查看下文件的全名然后進行解壓
sudo xz –d clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz
sudo tar –xvf clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar
我的路徑是這樣的
接下來將路徑添加到環境變量中,完整路徑可以進入到llvm文件夾中,然后用pwd命令獲取
sudo vim ~/.bashrc
在.bashrc文件的末尾加上llvm的路徑,每個人的路徑不一樣,要看自己解壓的位置
然后
source ~/.bashrc
輸入命令
llvm-config --version
查看配置是否成功
成功
然后要修改build文件夾中的config.cmake文件,將如下選項改為ON
因為我用llvm所以llvm設置為ON,如果用到其他東西,對應選項都要置為ON,詳細參照官方文檔
修改完成后開始編譯tvm
先進入到build目錄
cd /home/montage/tvm/build
開始編譯
sudo cmake ..
如果編譯的時候出現找不到llvm-config的情況,如下:
CMake Error at cmake/utils/FindLLVM.cmake:47 (find_package): Could not find a package configuration file provided by "LLVM" with any of the following names: LLVMConfig.cmake llvm-config.cmake Add the installation prefix of "LLVM" to CMAKE_PREFIX_PATH or set "LLVM_DIR" to a directory containing one of the above files. If "LLVM" provides a separate development package or SDK, be sure it has been installed. Call Stack (most recent call first): cmake/modules/LLVM.cmake:31 (find_llvm) CMakeLists.txt:337 (include) -- Configuring incomplete, errors occurred! See also "/home/aiteam/tvm/build/CMakeFiles/CMakeOutput.log". See also "/home/aiteam/tvm/build/CMakeFiles/CMakeError.log".
說明你的服務器中安裝了多個版本的llvm,cmake不能找到明確位置
解決方法:
找到之前llvm下載安裝的位置,然后將這個llvm-config文件的位置加到tvm/build/config.cmake中
把ON替換成llvm的位置,如紅線所示
再編譯就沒問題了
sudo make -j4
編譯完成
安裝conda環境
服務器上已經裝了anaconda,所以直接運行命令就可以了
出現問題,是網絡問題,anaconda是一個集成環境,所以我覺得不裝在conda中,直接裝在python里應該也不影響,所以繼續安裝python包
安裝python包
官方文檔一共提供了兩種方法
方法1
在~/.bashrc中加入路徑,然后保存退出,這里TVM_HOME路徑通過pwd查看
方法2
在環境變量中加入
export MACOSX_DEPLOYMENT_TARGET=10.9
進入tvm文件夾中的python文件夾執行如下命令
python setup.py install --user
方法2失敗,我在自己的虛擬機上也試過這么裝,也是同樣的錯誤,所以還是推薦用第一種方法
安裝python依賴
pip3 install --user numpy decorator attrs
這個是必需的依賴
pip3 install --user tornado
使用RPC Tracker需要安裝依賴
pip3 install --user tornado psutil xgboost cloudpickle
使用自動debug需要安裝的依賴
就只有前兩個包能找到,其他的都找不到
嘗試運行一下官方demo
from __future__ import absolute_import, print_function import tvm import tvm.testing from tvm import te import numpy as np # Global declarations of environment. tgt_host = "llvm" # Change it to respective GPU if gpu is enabled Ex: cuda, opencl, rocm tgt = "cuda" n = te.var("n") A = te.placeholder((n,), name="A") B = te.placeholder((n,), name="B") C = te.compute(A.shape, lambda i: A[i] + B[i], name="C") print(type(C))
在spyder中也可以運行
基本上算是成功了,docker安裝官網的文檔似乎有些問題,所以還是得自己編譯安裝
如果編譯都成功了,但是在python中導入tvm時出現如下錯誤
可能是你的python版本過低,這是我在虛擬機上安裝tvm遇到的情況,在python3.6中運行就正常了