Manual LLVM and HCL-MLIR installation for developers
mainIf you prefer to manage LLVM manually, you must use version v15.0.0. This process involves three main stages: building LLVM with Python bindings, building the HCL-MLIR dialect, and configuring the HeteroCL environment.
1. Build LLVM (v15.0.0)
Clone the LLVM project, checkout the specific tag, install requirements, and build with MLIR and Python bindings enabled.
2. Build HCL-MLIR Dialect
Clone the hcl-dialect repository and build it using the MLIR_DIR and LLVM_EXTERNAL_LIT paths from your LLVM build directory.
3. Configure Environment
Set the PYTHONPATH to include the generated HCL-MLIR library and the HeteroCL root folder, and add the LLVM bin directory to your PATH.
# 1. Build LLVM
$ git clone https://github.com/llvm/llvm-project.git
$ cd llvm-project
$ git checkout tags/llvmorg-15.0.0
$ python3 -m pip install -r mlir/python/requirements.txt
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" ../llvm \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_BUILD_EXAMPLES=ON \
-DLLVM_TARGETS_TO_BUILD="host" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_INSTALL_UTILS=ON \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
-DPython3_EXECUTABLE=`which python3`
$ make -j8
$ export LLVM_BUILD_DIR=$(pwd)
$ export LLVM_SYMBOLIZER_PATH=$(pwd)/bin/llvm-symbolizer
# 2. Build HCL-MLIR
$ git clone git@github.com:cornell-zhang/hcl-dialect.git
$ cd hcl-dialect
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" .. \
-DMLIR_DIR=$LLVM_BUILD_DIR/lib/cmake/mlir \
-DLLVM_EXTERNAL_LIT=$LLVM_BUILD_DIR/bin/llvm-lit \
-DPYTHON_BINDING=ON \
-DOPENSCOP=OFF \
-DPython3_EXECUTABLE=`which python3`
$ make -j8
$ export PYTHONPATH=$(pwd)/tools/hcl/python_packages/hcl_core:${PYTHONPATH}
# 3. Final HeteroCL Setup
$ cd /path/to/heterocl-root
$ export PYTHONPATH=$(pwd):${PYTHONPATH}
$ export PATH=${LLVM_BUILD_DIR}/bin:${PATH}
$ python3 -m pytest test