Taichi编译环境搭建
一、Taichi编译环境搭建
1.1、软件要求:
以下是在虚拟机中安装Ubuntu的步骤。
下载虚拟机软件VirtualBox:https://www.virtualbox.org/
下载Ubuntu系统(中科大镜像站):https://mirrors.ustc.edu.cn/ 版本:20.04(amd64, desktop LiveCD)
1.2、安装虚拟机就是按照步骤来就行
1.3、安装Ubuntu也是按照步骤来就行
1.4、更换清华镜像:
更改etc/apt/sources.list文件: sudo gedit sources.list
在[https://mirrors.tuna.tsinghu a.edu.cn/help/ubuntu/](https://mirrors.tuna.tsinghu a.edu.cn/help/ubuntu/)中根据Ubuntu的不同版本添加不同配置
20.04版本如下:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
更改配置后需要更新:sudo apt-get update
2、Taichi基础环境配置
2.1、Python以及Python依赖的安装
python3 -m pip install --user setuptools astpretty astor pybind11 Pillow dill
python3 -m pip install --user pytest pytest-rerunfailures pytest-xdist yapf
python3 -m pip install --user numpy GitPython coverage colorama autograd
2.2、安装并更换编译器为clang(version>7)
#安裝
sudo apt install libtinfo-dev clang-81
#更改編譯器
sudo update-alternatives --config c++
sudo update-alternatives --config cc
2.3、构建LLVM
#下载LLVM文件
wget https://github.com/llvm/llvm-project/releases/download/llvmorg10.0.0/llvm-10.0.0.src.tar.xz
#解压
tar xvJf llvm-10.0.0.src.tar.xz
cd llvm-10.0.0.src
#新建build文件夹
mkdir build
cd build
cmake .. -DLLVM_ENABLE_RTTI:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=OFF DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86;NVPTX" DLLVM_ENABLE_ASSERTIONS=ON
# If you are building on NVIDIA Jetson TX2, use DLLVM_TARGETS_TO_BUILD="ARM;NVPTX"
make -j 8 (构建时长大约为30分钟)
sudo make install
# Check your LLVM installation
llvm-config --version
# You should get 10.0.0
3、开发者配置
3.1、给配置文件末尾添加Taichi路径(vim ~/.bashrc)
// 下载Taichi源码存放的位置
export TAICHI_REPO_DIR=/path/to/taichi
# Path to your taichi repository
export PYTHONPATH=$TAICHI_REPO_DIR/python:$PYTHONPATH
export PATH=$TAICHI_REPO_DIR/bin:$PATH
# export CXX=/path/to/clang
# Uncomment if you encounter issue about compiler in the next step.
# export PATH=/opt/llvm/bin:$PATH
# Uncomment if your llvm or clang is installed in /opt
3.2、加载配置文件
source ~/.bashrc
3.3、编译Taichi,在build文件夹下执行’‘python3 -m taichi test’’(约5分钟)
git clone https://github.com/taichi-dev/taichi --depth=1 --branch=master
#Taichi源码存放的位置要与.bashrc指定的位置相同
cd taichi
git submodule update --init --recursive --depth=1 # 必不可少
mkdir build
cd build
cmake ..
# On Linux / OS X, if you do not set clang as the default compiler
# use the line below:
# cmake .. -DCMAKE_CXX_COMPILER=clang
#
# Alternatively, if you would like to set clang as the default compiler # On Unix CMake honors environment variables $CC and $CXX upon deciding which C and C++ compilers to use
make -j 8
#修改源码后需要重新cmake、make即可生效,至此Taichi的编译环境安装成功。
还没有评论,来说两句吧...