#!/bin/bash
set -e
sudo apt-get update
sudo apt-get install -y python python-dev python-setuptools gcc libtinfo-dev zlib1g-dev build-essential cmake #安环境
cd ~
git clone git://github.com/ninja-build/ninja.git
cd ninja
./configure.py --bootstrap
echo 'export PATH="${PATH}:~/ninja"' >> ~/.bashrc
source .bashrc
cd ~
git clone --recursive https://github.com/Maratyszcza/NNPACK.git
cd NNPACK
# Add PIC option in CFLAG and CXXFLAG to build NNPACK shared library
sed -i "s|gnu99|gnu99 -fPIC|g" CMakeLists.txt
sed -i "s|gnu++11|gnu++11 -fPIC|g" CMakeLists.txt
mkdir build
cd build
# Generate ninja build rule and add shared library in configuration
cmake -G Ninja -D BUILD_SHARED_LIBS=ON ..
ninja
sudo ../../ninja/ninja install
# Add NNPACK lib folder in your ldconfig
sudo echo "/usr/local/lib" > /etc/ld.so.conf.d/nnpack.conf
sudo ldconfig
cd ~
git clone --recursive https://github.com/dmlc/tvm #下载
#wget http://releases.llvm.org/8.0.0/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz
#sudo xz -d clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz
#tar -xvf clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04.tar #install llvm
apt install llvm
sudo echo "
llmv_bin_path="/root/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04/bin"
if [ -n "${PATH##*${llmv_bin_path}}" -a -n "${PATH##*${llmv_bin_path}:*}" ]; then
export PATH=$PATH:${llmv_bin_path}
fi
" > /etc/profile.d/apps-bin-path.sh
cd tvm
mkdir build
cp cmake/config.cmake build
#改配置
#sed -i 's/set(USE_CUDA OFF)/set(USE_CUDA ON)/' build/config.cmake
sed -i 's/set(USE_NNPACK OFF)/set(USE_NNPACK ON)\nset(NNPACK_PATH ~\/NNPACK)/' build/config.cmake
#Set set(USE_NNPACK ON) in config.cmake.
#Set NNPACK_PATH to the $(YOUR_NNPACK_INSTALL_PATH)
sed -i 's/set(USE_LLVM OFF)/set(USE_LLVM ~\/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04\/bin\/llvm-config)/' build/config.cmake
#sed -i 's/set(USE_LLVM OFF)/set(USE_LLVM ON)/' build/config.cmake
cd build
cmake ..
cd ..
make -j4
#cmake ..
#make runtime
#echo 'export TVM_HOME=~/tvm
#export PYTHONPATH=$TVM_HOME/python:$TVM_HOME/topi/python:$TVM_HOME/nnvm/python:${PYTHONPATH}' >> ~/.bashrc
#source ~/.bashrc
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 ..
cd topi/python; python setup.py install --user; cd ../..
cd nnvm/python; python setup.py install --user; cd ../..
pip install --user numpy decorator attrs
pip install --user tornado
pip install --user tornado psutil xgboost
pip install --user mypy orderedset antlr4-python3-runtime
#install onnx
git clone https://github.com/onnx/onnx.git
cd onnx
git submodule update --init --recursive
python setup.py install