TVM源码框架安装方法
本文提供如何在各种系统上从零构建和安装TVM包的说明。它包括两个步骤:
首先从C++代码中构建共享库(linux的libtvm.so,macOS的libtvm.dylib和windows的libtvm.dll)。
编程语言包的设置(例如Python包)。
实现,请从下载页面下载tvm源代码。
https://tvm.apache.org/download
Developers: Get Source from Github
还可以选择从github 上clone源repo。使用--recursive选项clone子模块很重要。
git clone --recursive https://github.com/apache/tvm tvm
使用github工具的windows用户,可以使用git shell,再键入以下命令。
git submodule init
git submodule update
Build the Shared Library
目标是build 共享库:
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
最低building需求
一个支持C++ 14(g++—5或更高)的C++编译器
CMake 3.5或更高
强烈建议使用LLVM构建以启用所有功能。
如果要使用CUDA,则需要CUDA toolkit版本>=8.0。如果要从旧版本升级,请确保删除旧版本并在安装后重新启动。
在macOS上,可能需要安装自制程序https://brew.sh,便于简化安装和管理依赖项。
使用cmake来构建库。TVM的配置可以通过以下方式进行config.cmake配置文件完成。
首先,检查系统中的cmake。如果您没有cmake,您可以从官方网站获取最新版本
首先创建一个构建目录,复制cmake/config.cmake文件到该目录。
mkdir build
cp cmake/config.cmake build
OFF) to set(USE_CUDA
ON) to enable CUDA backend. Do the same for other backends and libraries you want to build for (OpenCL, RCOM, METAL, VULKAN, …).
ON) and set(USE_GRAPH_RUNTIME_DEBUG
ON)
/path/to/your/llvm/bin/llvm-config)
ON) and let cmake search for a usable version of LLVM.
llvm-config-10) if you installed LLVM 10 package· cd build
· cmake ..
· make -j4
· cd build
· cmake .. -G Ninja
· ninja
If everything goes well, we can go to Python Package Installation
https://tvm.apache.org/docs/install/from_source.html#python-package-installation
Building with a Conda Environment
Conda是获取运行TVM所需依赖项的一种非常方便的方法。
首先,如果系统中还没有conda,请按照conda的安装指南(https://docs.conda.io/projects/conda/en/latest/user-guide/install/)
安装miniconda或anaconda。在conda环境中运行以下命令:
# Create a conda environment with the dependencies specified by the yaml
conda env create --file conda/build-environment.yaml
# Activate the created environment
conda activate tvm-build
上面的命令将安装所有必要的构建依赖项,如cmake和LLVM。可以在后面运行标准build过程。
如果要在conda环境之外使用编译后的二进制文件,可以将LLVM设置为static linking mode set(USE_LLVM "llvm-config --link-static")。这样,生成的库就不会依赖于conda环境中的动态LLVM库。
上面的说明展示了如何使用conda提供构建libtvm所需的构建依赖项。如果已经使用conda作为包管理器,并且希望直接将tvm作为conda包来构建和安装,则可以按照以下说明进行操作:
conda build --output-folder=conda/pkg conda/recipe
# Run conda/build_cuda.sh to build with cuda enabled
conda install tvm -c ./conda/pkg
Building on Windows
使用cmake通过MSVC构建TVM支持。您将需要包含一个visualstudio编译器。最低要求的VS版本是Visual Studio Community 2015 Update 3。我们建议使用Conda环境进行后续构建,以获得必要的依赖关系并获得激活的tvm构建环境。然后可以运行以下命令来构建。
mkdir build
cd build
cmake -A x64 -Thost=x64 ..
cd ..
上面的命令在build目录下生成解决方案文件。可以运行以下命令来build
cmake --build build --config Release -- /m
Building ROCm support
目前,ROCm只在linux上受支持,所以所有的指令都是用linux编写的。
Set Set(USE_ROCM ON),将ROCM_PATH设置为正确的路径。
首先需要从ROCm安装HIP运行时。确保安装系统中安装了ROCm。
安装最新稳定版本的LLVM(v6.0.1)和LLD,确保ld.lld可通过命令行使用。
根据开发环境,可使用虚拟环境和包管理器(如virtualenv或conda)来管理python包和依赖项。
安装和维护python开发环境。
python包位于tvm/python。有两种安装方法:
Method 1
此方法推荐给可能更改代码的开发人员。
设置环境变量PYTHONPATH,表示python在哪里可以找到库。例如,假设在目录/path/to/tvm上cloned了tvm,那么我们可以在~/.bashrc中添加以下行。一旦获取代码并重新build项目,修改将立即显现出来(无需再次调用setup安装程序)。
export TVM_HOME=/path/to/tvm
export PYTHONPATH=$TVM_HOME/python:${PYTHONPATH}
Method 2
Install TVM python bindings by setup.py:
# install tvm package for the current user
# NOTE: if you installed python via homebrew, --user is not needed during installaiton
# it will be automatically installed to your user directory.
# providing --user flag may trigger error during installation in such case.
export MACOSX_DEPLOYMENT_TARGET=10.9 # This is required for mac to avoid symbol conflicts with libstdc++
cd python; python setup.py install --user; cd ..
Note that the --user flag is not necessary if you’re installing to a managed local environment, like virtualenv.
pip3 install --user numpy decorator attrs
pip3 install --user tornado
pip3 install --user tornado psutil xgboost
We use Google Test to drive the C++ tests in TVM. The easiest way to install GTest is from source.
git clone https://github.com/google/googletest
cd googletest
mkdir build
cd build
cmake ..
make
sudo make install
After installing GTest, the C++ tests can be built and started with ./tests/scripts/task_cpp_unittest.sh or just built with make
cpptest.
原文:https://www.cnblogs.com/wujianming-110117/p/14051492.html