HeteroCL dialect is an out-of-tree MLIR dialect for accelerator design. HeteroCL dialect decouples algorithm from hardware customizations, and classifies them into compute and data customizations. The HeteroCL dialect is part of the HeteroCL compilation flow. HeteroCL provides an end-to-end flow from Python to LLVM backend or C HLS FPGA backends. With HeteroCL, designers can explore tradeoffs with hardware customizations in a systematic manner and quickly obtain high-performance design with little manual effort.
Download LLVM from llvm-project or checkout the Github branch
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
git checkout tags/llvmorg-18-init
Build
mkdir build && cd build
cmake -G "Unix Makefiles" ../llvm \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_BUILD_EXAMPLES=ON \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_INSTALL_UTILS=ON
make -j8
# You can either use ninja to build
# cmake -G Ninja
# ninja
hcl-dev
using Python venv, but we prefer you to install Anaconda3 and create an environment there. If you want to use your own Python environment, please specify the path for -DPython3_EXECUTABLE
.
# Create a virtual environment. Make sure you have installed Python3.
which python3
python3 -m venv ~/.venv/hcl-dev
source ~/.venv/hcl-dev/bin/activate
python3 -m pip install --upgrade pip
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
This setup assumes that you have built LLVM and MLIR in $LLVM_BUILD_DIR
. Please firstly clone our repository.
git clone --recursive git@github.com:cornell-zhang/hcl-dialect.git
cd hcl-dialect
mkdir build && cd build
NOTE: The HeteroCL dialect is a standalone system that works without a frontend. If you are using it with the HeteroCL frontend, the minimum requirement is to build with Python binding. Building with OpenSCoP extraction is optional.
Build without Python binding
cmake -G "Unix Makefiles" .. \
-DMLIR_DIR=$LLVM_BUILD_DIR/lib/cmake/mlir \
-DLLVM_EXTERNAL_LIT=$LLVM_BUILD_DIR/bin/llvm-lit \
-DPYTHON_BINDING=OFF \
-DOPENSCOP=OFF
make -j8
Build with Python binding
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` \
-DCMAKE_CXX_FLAGS="-Wfatal-errors -std=c++17"
make -j8
export PYTHONPATH=$(pwd)/tools/hcl/python_packages/hcl_core:${PYTHONPATH}
- Build with OpenSCoP extraction enabled: Set `-DOPENSCOP=ON` and export the library path.
```sh
export LD_LIBRARY_PATH=$(pwd)/openscop/lib:$LD_LIBRARY_PATH
Lastly, you can use the following integration test to see whether your built dialect works properly.
cmake --build . --target check-hcl
# perform loop transformation passes
./bin/hcl-opt -opt ../test/Transforms/compute/tiling.mlir
# generate C++ HLS code
./bin/hcl-opt -opt ../test/Transforms/compute/tiling.mlir | \
./bin/hcl-translate -emit-vivado-hls
# generate OpenSCoP
# An hcl.openscop file will be generated in the build folder
./bin/hcl-opt -opt ../test/Transforms/memory/buffer_add.mlir | \
./bin/hcl-translate --extract-scop-stmt
# run code on CPU
./bin/hcl-opt -opt -jit ../test/Translation/mm.mlir
Make sure you have correctly built the above HCL-MLIR dialect, and follow the instruction below.
# clone the HeteroCL repo
git clone https://github.com/cornell-zhang/heterocl.git heterocl-mlir
cd heterocl-mlir
# install dependencies
python3 -m pip install -r requirements.txt
# export the library
export HCL_HOME=$(pwd)
export PYTHONPATH=$HCL_HOME/python:${PYTHONPATH}
# run regression tests in the HeteroCL repo
cd tests && python3 -m pytest
We follow Google Style Guides and use
To install clang-format
, you can reuse the LLVM project by specifying the following CMake options:
# Inside the llvm-project folder
mkdir build-clang && cd build-clang
cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS="clang" \
-DLLVM_BUILD_EXAMPLES=ON \
-DLLVM_TARGETS_TO_BUILD="host" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_INSTALL_UTILS=ON
ninja clang-format