Skip to content

Instantly share code, notes, and snippets.

@KellenSunderland
Last active November 16, 2019 00:30
Show Gist options
  • Save KellenSunderland/ee1ce77c0d300beee98a56803416c9f3 to your computer and use it in GitHub Desktop.
Save KellenSunderland/ee1ce77c0d300beee98a56803416c9f3 to your computer and use it in GitHub Desktop.
MXNet with TensorRT support compilation guide

FROM UBUNTU 18.04

sudo apt-get install tmux htop libssl-dev
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub && sudo apt update
sudo dpkg -i cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
sudo apt update
sudo apt install -y cuda
wget https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo dpkg -i nvidia-machine-learning-repo-*.deb
sudo apt-get update
sudo apt-get install libnvinfer5=5.1.5-1+cuda10.1 libnvinfer-dev=5.1.5-1+cuda10.1
cd ~
sudo apt-get install python python-pip python3 python3-pip
export PATH=$PATH:/usr/local/cuda/bin/

mkdir ~/cmake
cd ~/cmake
git clone --recurse https://github.com/Kitware/CMake.git -b v3.15.5
cd ~/cmake/CMake
./bootstrap && make && sudo make install

Install protobuf
mkdir protobuf-src && cd protobuf
apt-get update
sudo apt-get install -y automake libtool zip
git clone --recursive -b 3.5.1.1 https://github.com/google/protobuf.git
cd protobuf
./autogen.sh
./configure --disable-shared CXXFLAGS=-fPIC
make -j$(nproc)
make install
rm -rf /usr/local/lib/libprotobuf-lite.so*
rm -rf /usr/local/lib/libprotobuf.so*
rm -rf /usr/local/lib/libprotoc.so*
ldconfig

sudo apt-get install cmake ninja-build
cd ~/incubator-mxnet/3rdparty/onnx-tensorrt/third_party/onnx/
mkdir -p build
cd build
cmake \
    -DCMAKE_CXX_FLAGS=-I/usr/include/python${PYVER}\
    -DBUILD_SHARED_LIBS=ON ..\
    -G Ninja
ninja -j 1 -v onnx/onnx.proto
ninja -j 1 -v
export LIBRARY_PATH=`pwd`:`pwd`/onnx/:$LIBRARY_PATH
export CPLUS_INCLUDE_PATH=`pwd`:$CPLUS_INCLUDE_PATH

export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/cuda-10.1/targets/x86_64-linux/include/
cd ~/incubator-mxnet/3rdparty/onnx-tensorrt/
mkdir -p build
cd build
cmake ..
make -j$(nproc)
export LIBRARY_PATH=`pwd`:$LIBRARY_PATH

sudo apt-get install libopenblas-dev
mkdir -p ~/incubator-mxnet/build
cd ~/incubator-mxnet/build/
cmake -DUSE_CUDA=1                            \
      -DUSE_CUDNN=1                           \
      -DUSE_OPENCV=0                          \
      -DUSE_TENSORRT=1                        \
      -DUSE_OPENMP=1                          \
      -DUSE_MKLDNN=0                          \
      -DUSE_MKL_IF_AVAILABLE=OFF              \
      -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
      -G Ninja                                \
      ..

ninja -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment