Go to file
Hanchen Ye 02dcdd1438 [PyTorchPipeline] Rename from scalehls-pipeline to scalehls-pytorch-pipeline; [QoREstimation] Remove the depAnalysis option, always set to true 2022-02-23 17:09:09 -06:00
include [PyTorchPipeline] Rename from scalehls-pipeline to scalehls-pytorch-pipeline; [QoREstimation] Remove the depAnalysis option, always set to true 2022-02-23 17:09:09 -06:00
lib [PyTorchPipeline] Rename from scalehls-pipeline to scalehls-pytorch-pipeline; [QoREstimation] Remove the depAnalysis option, always set to true 2022-02-23 17:09:09 -06:00
polygeist@642b664c2a Bump LLVM to af6b993 2022-02-22 01:18:14 -06:00
samples Remove onnx front-end option from scalehls pipeline; Deprecate onnx-mlir samples 2022-02-22 23:46:10 -06:00
test [EmitHLSCpp][SplitFunction] Support tensor/memref reshape ops 2022-02-23 17:02:25 -06:00
tools [Conversions] Remove this directory 2022-02-22 23:35:32 -06:00
.clang-format mechanical rename hlsld to scalehls; update file structure 2020-09-06 18:05:16 -05:00
.gitignore [Samples] Update the structure of the samples folder 2022-02-20 17:15:16 -06:00
.gitmodules Rename Polygeist to polygeist 2021-09-30 12:20:01 -05:00
CMakeLists.txt Update the path of mlir-clang 2022-01-26 11:33:56 -06:00
LICENSE Update license to Apache 2.0 with LLVM exceptions 2022-01-05 20:34:39 -06:00
README.md [PyTorchPipeline] Rename from scalehls-pipeline to scalehls-pytorch-pipeline; [QoREstimation] Remove the depAnalysis option, always set to true 2022-02-23 17:09:09 -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 PyTorch 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:

@article{ye2021scalehls,
  title={ScaleHLS: A New Scalable High-Level Synthesis Framework on Multi-Level Intermediate Representation},
  author={Ye, Hanchen and Hao, Cong and Cheng, Jianyi and Jeong, Hyunmin and Huang, Jack and Neuendorffer, Stephen and Chen, Deming},
  journal={arXiv preprint arXiv:2107.11673},
  year={2021}
}

Setting this up

Prerequisites

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

Clone ScaleHLS

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

Build ScaleHLS

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/bin
$ export PYTHONPATH=$PYTHONPATH:$PWD/build/tools/scalehls/python_packages/scalehls_core

Compiling HLS C/C++

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/config.json" -debug-only=scalehls \
    | scalehls-translate -emit-hlscpp > test_gemm_dse.cpp

$ mlir-clang samples/rosetta/spam-filter/sgd_sw.c -function=SgdLR_sw -memref-fullrank -raise-scf-to-affine -S \
    | scalehls-opt -materialize-reduction -dse="top-func=SgdLR_sw target-spec=samples/rosetta/config.json" -debug-only=scalehls \
    | scalehls-translate -emit-hlscpp > sgd_sw_dse.cpp

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

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

Compiling PyTorch model

If you have installed Torch-MLIR, you should be able to run the following test:

$ cd resnet18

$ # Parse PyTorch model to TOSA dialect (with mlir_venv activated).
$ # This may take several minutes to compile due to the large amount of weights.
$ python3 export_resnet18_mlir.py | torch-mlir-opt \
    -torchscript-module-to-torch-backend-pipeline="optimize=true" \
    -torch-backend-to-tosa-backend-pipeline="optimize=true" \
    -canonicalize > resnet18.mlir

$ # Optimize the model and emit C++ code.
$ # This may take several minutes to compile due to the large amount of weights.
$ scalehls-opt resnet18.mlir \
    -scalehls-pytorch-pipeline="top-func=forward opt-level=2 frontend=torch" \
    | scalehls-translate -emit-hlscpp > resnet18.cpp

Repository Layout

The project follows the conventions of typical MLIR-based projects:

  • include/scalehls and lib for C++ MLIR compiler dialects/passes.
  • polygeist for the HLS C/C++ front-end.
  • samples for example test cases.
  • test for holding regression tests.
  • tools for command line tools, such as scalehls-opt and pyscalehls.