Taichi编译环境搭建

太过爱你忘了你带给我的痛 2022-11-30 01:25 357阅读 0赞

一、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版本如下:

  1. # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
  2. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
  3. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
  4. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
  5. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
  6. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
  7. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
  8. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
  9. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
  10. # 预发布软件源,不建议启用
  11. # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
  12. # 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依赖的安装

  1. python3 -m pip install --user setuptools astpretty astor pybind11 Pillow dill
  2. python3 -m pip install --user pytest pytest-rerunfailures pytest-xdist yapf
  3. python3 -m pip install --user numpy GitPython coverage colorama autograd

2.2、安装并更换编译器为clang(version>7)

  1. #安裝
  2. sudo apt install libtinfo-dev clang-81
  3. #更改編譯器
  4. sudo update-alternatives --config c++
  5. sudo update-alternatives --config cc

2.3、构建LLVM

  1. #下载LLVM文件
  2. wget https://github.com/llvm/llvm-project/releases/download/llvmorg10.0.0/llvm-10.0.0.src.tar.xz
  3. #解压
  4. tar xvJf llvm-10.0.0.src.tar.xz
  5. cd llvm-10.0.0.src
  6. #新建build文件夹
  7. mkdir build
  8. cd build
  9. 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
  10. # If you are building on NVIDIA Jetson TX2, use DLLVM_TARGETS_TO_BUILD="ARM;NVPTX"
  11. make -j 8 (构建时长大约为30分钟)
  12. sudo make install
  13. # Check your LLVM installation
  14. llvm-config --version
  15. # You should get 10.0.0

3、开发者配置

3.1、给配置文件末尾添加Taichi路径(vim ~/.bashrc)

  1. // 下载Taichi源码存放的位置
  2. export TAICHI_REPO_DIR=/path/to/taichi
  3. # Path to your taichi repository
  4. export PYTHONPATH=$TAICHI_REPO_DIR/python:$PYTHONPATH
  5. export PATH=$TAICHI_REPO_DIR/bin:$PATH
  6. # export CXX=/path/to/clang
  7. # Uncomment if you encounter issue about compiler in the next step.
  8. # export PATH=/opt/llvm/bin:$PATH
  9. # Uncomment if your llvm or clang is installed in /opt

3.2、加载配置文件

  1. source ~/.bashrc

3.3、编译Taichi,在build文件夹下执行’‘python3 -m taichi test’’(约5分钟)

  1. git clone https://github.com/taichi-dev/taichi --depth=1 --branch=master
  2. #Taichi源码存放的位置要与.bashrc指定的位置相同
  3. cd taichi
  4. git submodule update --init --recursive --depth=1 # 必不可少
  5. mkdir build
  6. cd build
  7. cmake ..
  8. # On Linux / OS X, if you do not set clang as the default compiler
  9. # use the line below:
  10. # cmake .. -DCMAKE_CXX_COMPILER=clang
  11. #
  12. # 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
  13. make -j 8
  14. #修改源码后需要重新cmake、make即可生效,至此Taichi的编译环境安装成功。

发表评论

表情:
评论列表 (有 0 条评论,357人围观)

还没有评论,来说两句吧...

相关阅读