Go to file
Hanchen Ye 36d5083315 [Samples] Update all onnx-mlir samples 2021-11-12 02:32:40 -06:00
include [PartialAffineLoopTiling] Support to simplify loop structure after tiling 2021-11-12 01:51:15 -06:00
lib [Samples] Update all onnx-mlir samples 2021-11-12 02:32:40 -06:00
polygeist@1cb9d69209 Add build-scalehls.sh script; [README] Update build and test instructions; [Polygeist] Update polygeist submodule to avoid gettimeofday failure 2021-11-09 00:49:06 -06:00
samples [Samples] Update all onnx-mlir samples 2021-11-12 02:32:40 -06:00
test [Samples] Update all polybench samples 2021-11-12 02:09:50 -06:00
tools [PartialAffineLoopTiling] Support to simplify loop structure after tiling 2021-11-12 01:51:15 -06:00
.clang-format mechanical rename hlsld to scalehls; update file structure 2020-09-06 18:05:16 -05:00
.gitignore Add pyscalehls tool; Python binding for applyArrayPartition 2021-10-03 10:18:25 -05:00
.gitmodules Rename Polygeist to polygeist 2021-09-30 12:20:01 -05:00
CMakeLists.txt Add build-scalehls.sh script; [README] Update build and test instructions; [Polygeist] Update polygeist submodule to avoid gettimeofday failure 2021-11-09 00:49:06 -06:00
LICENSE add license 2021-01-06 11:31:03 -06:00
README.md [Samples] Update all polybench samples 2021-11-12 02:09:50 -06:00
build-scalehls.sh Add build-scalehls.sh script; [README] Update build and test instructions; [Polygeist] Update polygeist submodule to avoid gettimeofday failure 2021-11-09 00:49:06 -06:00

README.md

ScaleHLS Project

ScaleHLS is a High-level Synthesis (HLS) framework on MLIR. ScaleHLS can compile HLS C/C++ or ONNX model to optimized HLS C/C++ in order to generate high-efficiency RTL design using downstream tools, such as Vivado HLS.

By using the MLIR framework that can be better tuned to particular algorithms at different representation levels, ScaleHLS is more scalable and customizable towards various applications coming with intrinsic structural or functional hierarchies. ScaleHLS represents HLS designs at multiple levels of abstraction and provides an HLS-dedicated analysis and transform library (in both C++ and Python) to solve the optimization problems at the suitable representation levels. Using this library, we've developed a design space exploration engine to generate optimized HLS designs automatically.

For more details, please see our HPCA'22 paper.

Quick Start

Prerequisites

  • cmake
  • ninja (recommended)
  • clang and lld (recommended)
  • pybind11
  • python3 with numpy

Build ScaleHLS

First, make sure this repository has been cloned recursively.

$ git clone --recursive git@github.com:hanchenye/scalehls.git
$ cd scalehls

Then, run the following script to build ScaleHLS. Note that you can use -j xx to specify the number of parallel linking jobs.

$ ./build-scalehls.sh

After the build, we suggest to export the following paths.

$ export PATH=$PATH:$PWD/build/bin:$PWD/polygeist/build/mlir-clang
$ export PYTHONPATH=$PYTHONPATH:$PWD/build/tools/scalehls/python_packages/scalehls_core

Try ScaleHLS

To launch the automatic kernel-level design space exploration, run:

$ mlir-clang samples/polybench/gemm/test_gemm.c -function=test_gemm -memref-fullrank -raise-scf-to-affine -S \
    | scalehls-opt -dse="top-func=test_gemm target-spec=samples/polybench/target-spec.ini" -debug-only=scalehls > /dev/null \
    && scalehls-translate -emit-hlscpp test_gemm_pareto_0.mlir > test_gemm_pareto_0.cpp

Meanwhile, we provide a pyscalehls tool to showcase the scalehls Python library:

$ pyscalehls.py samples/polybench/syrk/test_syrk.c -f test_syrk

Integration with ONNX-MLIR

If you have installed ONNX-MLIR or established ONNX-MLIR docker to $ONNXMLIR_DIR, you should be able to run the following integration test:

$ cd samples/onnx-mlir/resnet18

$ # Export PyTorch model to ONNX.
$ python3 export_resnet18.py

$ # Parse ONNX model to MLIR.
$ $ONNXMLIR_DIR/build/bin/onnx-mlir -EmitONNXIR resnet18.onnx

$ # Lower from ONNX dialect to Affine dialect.
$ $ONNXMLIR_DIR/build/bin/onnx-mlir-opt resnet18.onnx.mlir \
    -shape-inference -convert-onnx-to-krnl -pack-krnl-constants \
    -convert-krnl-to-affine > resnet18.mlir

$ # (Optional) Print model graph.
$ scalehls-opt resnet18.tmp -print-op-graph 2> resnet18.gv
$ dot -Tpng resnet18.gv > resnet18.png

$ # Legalize the output of ONNX-MLIR, optimize and emit C++ code.
$ scalehls-opt resnet18.mlir -allow-unregistered-dialect -legalize-onnx \
    -affine-loop-normalize -canonicalize -legalize-dataflow="insert-copy=true min-gran=3" \
    -split-function -convert-linalg-to-affine-loops -legalize-to-hlscpp="top-func=main_graph" \
    -affine-loop-perfection -affine-loop-order-opt -loop-pipelining -simplify-affine-if \
    -affine-store-forward -simplify-memref-access -array-partition -cse -canonicalize \
    | scalehls-translate -emit-hlscpp > resnet18.cpp

Please refer to the samples/onnx-mlir folder for more test cases, and sample/onnx-mlir/ablation_int_test.sh for how to conduct the graph, loop, and directive optimizations.

References

  • CIRCT: Circuit IR Compilers and Tools
  • CIRCT-HLS: A HLS flow around CIRCT project