TVM 설치 방법


서브모듈까지 모두 다운받기 위해서 --recursive 옵션을 사용한다.

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

Build the Shared Library

여기선 shared libaries를 빌드하는 것이 목적
각각의 운영체제에 따라서 지원하는 공유라이브러리가 다르다.

Linux: libtvm.so, libtvm_topi.so
OSX: libtvm.dylib, libtvm_topi.dylib
Windows: libtvm.dll, libtvm_topi.dll

sudo apt-get update
sudo apt-get install -y python python-dev python-setuptools gcc libtinfo-dev zlib1g-dev build-essential cmake

설치전 최소 요구사항

  • C++11 (g++ 4.8 or higher)
  • Cmake 3.5 or higher

    cmake --version

  • LLVM 설치 (Build)
  • CUDA or openCL을 사용한다면 LLVM을 설치하지 않아도 된다.
  • NNVM compiler를 사용하고 싶다면 LLVM을 설치 해야함.

Build Libary config.

  • config.cmake파일을 수정해서 빌드에 사용할 libary들을 선택 한다.
  • macOS의 경우 에러가 발생하면 XCdoe에서 어쩌면 LDFLAGS에 -lc++abi를 추가하면 된다.
  • CUDA backend를 사용하고 싶으면, set(USE_CUDA_OFF) set(USE_CUDA_ON)으로 변경 한다.

LLVM 의존성
apt로 설치하면 4.0보다 낮은 버전이 설치되므로 사용을 위해선 직접 빌드해서 써야한다.

빌드에 오랜 시간이 걸리므로 pre-build를 아래 링크에서 다운 받는다.

unzip후 build/config.cmake set(USE_LLVM /path/to/your/llvm/bin/llvm-config)

1080 PC 에서

default mode
-> LLVM 없는 상태

실행 로그

jemin@jemin-desktop:~/Users/jemin/tvm$ make -j4
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test SUPPORT_CXX11
-- Performing Test SUPPORT_CXX11 - Success
-- Build with RPC support...
-- Build with Graph runtime support...
-- Build VTA runtime with target: sim
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jemin/Users/jemin/tvm/build
...
...
...
[ 99%] Building CXX object CMakeFiles/nnvm_compiler.dir/nnvm/src/top/vision/yolo/reorg.cc.o
[100%] Linking CXX shared library libnnvm_compiler.so
make[3]: 디렉터리 '/home/jemin/Users/jemin/tvm/build' 나감
[100%] Built target nnvm_compiler
make[2]: 디렉터리 '/home/jemin/Users/jemin/tvm/build' 나감
make[1]: 디렉터리 '/home/jemin/Users/jemin/tvm/build' 나감

LLVM ON

-- Build with RPC support...
-- Build with Graph runtime support...
-- Build VTA runtime with target: sim
-- Use llvm-config=/home/jemin/Users/jemin/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/bin/llvm-config
-- /home/jemin/Users/jemin/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/include
-- Found LLVM_INCLUDE_DIRS=/home/jemin/Users/jemin/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/include
-- Found LLVM_DEFINITIONS= -DNDEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-- Found TVM_LLVM_VERSION=70
-- Build with LLVM
-- Set TVM_LLVM_VERSION=70
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jemin/Users/jemin/tvm/build

Xavier에서 CUDA ON

nvidia@jetson-0423718017159:~/tvm$ make -j4
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test SUPPORT_CXX11
-- Performing Test SUPPORT_CXX11 - Success
-- Build with RPC support...
-- Build with Graph runtime support...
-- Build VTA runtime with target: sim
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.0
-- Found CUDA_CUDA_LIBRARY=/usr/local/cuda-10.0/lib64/stubs/libcuda.so
-- Found CUDA_CUDART_LIBRARY=/usr/local/cuda-10.0/lib64/libcudart.so
-- Found CUDA_NVRTC_LIBRARY=/usr/local/cuda-10.0/lib64/libnvrtc.so
-- Found CUDA_CUDNN_LIBRARY=/usr/lib/aarch64-linux-gnu/libcudnn.so
-- Found CUDA_CUBLAS_LIBRARY=/usr/local/cuda-10.0/lib64/libcublas.so
-- Build with CUDA support
-- Configuring done
-- Generating done
....
....
[ 99%] Building CXX object CMakeFiles/nnvm_compiler.dir/nnvm/src/top/vision/yolo/reorg.cc.o
[100%] Linking CXX shared library libnnvm_compiler.so
make[3]: Leaving directory /home/nvidia/tvm/build
[100%] Built target nnvm_compiler
make[2]: Leaving directory /home/nvidia/tvm/build
make[1]: Leaving directory /home/nvidia/tvm/build

OSX에 설치하기

llvm을 프리 빌드 버전을 다운받는다.
7.0 버전: http://releases.llvm.org/7.0.0/clang+llvm-7.0.0-x86_64-apple-darwin.tar.xz
압축푼 경로에서 bin/llvm-config가 정상적으로 동작 하는지를 파악한다.

mkdir Build
cp cmake/config.cmake build
cd build
cmake ..
-- The C compiler identification is AppleClang 10.0.0.10001044
-- The CXX compiler identification is AppleClang 10.0.0.10001044
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test SUPPORT_CXX11
-- Performing Test SUPPORT_CXX11 - Success
-- Build with RPC support...
-- Build with Graph runtime support...
-- Build VTA runtime with target: sim
-- Use llvm-config=/Users/jeminlee/development/llvm/clang+llvm-7.0.0-x86_64-apple-darwin/bin/llvm-config
-- /Users/jeminlee/development/llvm/clang+llvm-7.0.0-x86_64-apple-darwin/include
-- Found LLVM_INCLUDE_DIRS=/Users/jeminlee/development/llvm/clang+llvm-7.0.0-x86_64-apple-darwin/include
-- Found LLVM_DEFINITIONS= -DNDEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-- Found TVM_LLVM_VERSION=70
-- Build with LLVM
-- Set TVM_LLVM_VERSION=70
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/jeminlee/development/tvm/build

make -j8
Scanning dependencies of target vta
Scanning dependencies of target tvm_runtime
Scanning dependencies of target tvm
[  0%] Building CXX object CMakeFiles/vta.dir/vta/src/device_api.cc.o
[  1%] Building CXX object CMakeFiles/vta.dir/vta/src/sim/sim_driver.cc.o
...
...
[ 99%] Building CXX object CMakeFiles/nnvm_compiler.dir/nnvm/src/top/vision/ssd/mutibox_op.cc.o
[100%] Building CXX object CMakeFiles/nnvm_compiler.dir/nnvm/src/top/vision/yolo/region.cc.o
[100%] Building CXX object CMakeFiles/nnvm_compiler.dir/nnvm/src/top/vision/yolo/reorg.cc.o
[100%] Linking CXX shared library libtvm_topi.dylib
[100%] Built target tvm_topi
[100%] Linking CXX shared library libnnvm_compiler.dylib
[100%] Built target nnvm_compiler

단 llvm을 사용해서 nnvm을 활성화 하는 방법은 build 디렉터리내의 cofnig.cmake를 수정해서 set(USE_LLVM 경로)를 삽입한다.

Python Package Installation

tvm/python에 위치한 python package를 설치하는 방법으로 두 가지 방법이 존재 한다.

방법 1 (개발자)

  • export TVM_HOME=/path/to/tvm
  • export PYTHONPATH=$TVM_HOME/python:$TVM_HOME/topi/python:$TVM_HOME/nnvm/python:${PYTHONPATH}

방법 2

Python dependencies

  • Necessary dependencies
    • pip install --user numpy decorator
  • RPC Tracker
    • pip install --user tornado
  • Auto-tuning module
    • pip install --user tornado psutil xgboost

Troubleshooting

tensor error
Python 3.x 버전으로 변경한다.

모델 컴파일 에러
llvm 6.0.1에 최적화 되어 있으므로 7버전의 것을 사용하지 않는다.


'AI > TVM' 카테고리의 다른 글

TVM Pycharm 설정법  (0) 2021.03.09
VTA on FPGA Board  (4) 2019.04.02
PYNQ: Python productivity on ZYNQ  (0) 2019.04.02

+ Recent posts