Install TVM and NNVM from source

Do not miss this exclusive book on Binary Tree Problems. Get it now for free.

Reading time: 10 minutes | Installing time: 15 minutes

In this guide, we will walk you through the process of installing TVM and NNVM compiler from source along with all its dependencies such as HalideIR, DMLC-CORE, DLPACK and COMPILER-RT. Once installed, you can enjoy compiling models in any frameworks on any backend of your choice.

Installation

Step 1: Clone the source

Clone the source code of TVM using the following command:

git clone --recursive https://github.com/dmlc/tvm.git

Once done, move to the cloned repository using the following command:

cd tvm

Step 2: Prepare your build settings

Update your system and install the dependencies:

sudo apt-get update
sudo apt-get install -y python python-dev python-setuptools gcc libtinfo-dev zlib1g-dev
mkdir build
cp cmake/config.cmake build

Edit build/config.cmake to change SET(USE_LLVM OFF) to SET(USE_LLVM ON).

If you want to use another backend like CUDA, then change SET(USE_CUDA OFF) to SET(USE_CUDA ON) and accordingly for other available backends.

vi build/config.cmake

Step 3: Install LLVM as a backend

For TVM, you need a backend like LLVM, CUDA, METAL and others. We will install LLVM as a backend:

sudo apt-get install clang-6.0 lldb-6.0 lld-6.0

Step 4: Build the shared libraries

cd build
cmake ..
make -j4

Step 5: Build dependent libraries

First, we need to build the Python libraries of TVM:

cd ..
cd python
python setup.py install --user
cd ..

Next, we need to build NNVM:

cd nnvm
python setup.py install --user
cd ..

Next, we need to build the dependent libraries like HalideIR:

cd 3rdparty
cd HalideIR
make -j4
cd ..
cd dmlc-core
make -j4
cd ..
cd dlpack
make -j4
cd ..
cd ..

Step 6: Install some other dependencies

pip install --user numpy decorator
pip install --user tornado psutil xgboost
pip install --user tornado

Congratulations, you have successfully installed TVM Stack

You can, now, move to using TVM and realizing its performance compared to other frameworks.

Sign up for FREE 3 months of Amazon Music. YOU MUST NOT MISS.