Author: Zihao Ye
This article introduces how to build RAF using CMake on macOS.
(Required) Build dependency
brew install ccache # ccache is used to accelerate build
cmake # cmake is required to run cmake
git
(Optional) LLVM. LLVM is required to enable operators written in TVM.
brew install llvm
Below we introduce an environment variable that indicates where RAF is.
# Create the build directory
git clone https://github.com/awslabs/raf --recursive && cd raf
export RAF_HOME=$(pwd)
mkdir $RAF_HOME/build && cd $RAF_HOME/build
# Configuration file for CMake
cp ../cmake/config.cmake .
# Edit the configuration file
vim config.cmake
# Configure the project
cmake ..
# Finally let's trigger build
make -j$(nproc)
Customize build. By editing the configuration file config.cmake
, one can easily customize the process of RAF build. Instructions are directly put inside the configuration file for convenience.
Here we come to the not-that-good part: to run RAF, one should properly set the environment variables.
export PYTHONPATH=$RAF_HOME/python/:$RAF_HOME/3rdparty/tvm/topi/python:$RAF_HOME/3rdparty/tvm/python
# The following commands can verify if the environments are set up correctly.
python -c "import raf"
It is often annoying that environment variables are gone every time we open a new terminal, so sometimes we may want to set those variables globally, or inside a conda environment.
Setting globally. RC file is loaded automatically every time when a shell is set up. To determine which shell currently using, you may use "echo $SHELL".
# If using bash
vim $HOME/.bashrc
# If using zsh
vim $HOME/.zshrc
# Adding the export commands to the end of those RC files
export RAF_HOME=PATH-TO-RAF
export PYTHONPATH=$RAF_HOME/python/:$RAF_HOME/3rdparty/tvm/topi/python:$RAF_HOME/3rdparty/tvm/python
Set up in conda environment. If you are concerned that the solution above may make the RC files cumbersome, another possible way is that we can set environment variables in conda's activation script.
# First, enter your conda environment
conda activate your-conda-env
# Put export commands into this file
mkdir -p $CONDA_PREFIX/etc/conda/activate.d/
vim $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh