How uiuc-chenlab/scalehls works
Project Type and Purpose
• This is an MLIR-based compiler/framework (not a web app).
• ScaleHLS takes HLS C/C++ or PyTorch models as input, represents them in MLIR at multiple abstraction levels, applies analyses and transformations (including design-space exploration), and emits optimized HLS C++ suitable for downstream RTL generation (e.g., Vivado HLS).
• It also exposes Python and C APIs and ships command-line tools for integration into user workflows.
File Structure Analysis
• Top-Level
• CMakeLists.txt, build-scalehls.sh, .github/workflows – build and CI orchestration
• /scalehls – C++ headers for dialects, passes, transforms, translations
• lib/… – C++ implementations: Dialects (HLS), Transforms (Dataflow, Directive, Loop, Memory, Tensor), Translation (EmitHLSCpp)
• lib/Bindings – Python (pybind11) and C API layers
• polygeist – C/C++ front-end integration (cgeist)
• tools – Executables: scalehls-opt, scalehls-translate, pyscalehls
• samples – Example kernels and PyTorch models
• test – Regression tests (MLIR files, Python tests)
• Patterns:
• Compiler front-end(s) → MLIR Dialect/APIs → Transformation Pass Pipelines → Translator back-end
• Modular grouping by functionality (Dialect vs. Transforms vs. Binding vs. Tools)
README Insights
• Confirms MLIR foundation, purpose (HLS code optimization & DSE), CLI usage patterns, Python binding usage.
a. Main Components
1. Front-End Layer
• C/C++ Parser: polygeist (cgeist)
• PyTorch Parser: Torch-MLIR front-end (optional Python venv)
2. MLIR Core
• MLIR Context & IR data structures
• ScaleHLS Dialect (HLS dialect definitions in include/scalehls/Dialect)
3. Analysis & Transformation Library
• HLS-dedicated analyses (Estimator, Explorer)
• Transform passes (Dataflow, Directive, Loop, Memory, Tensor)
• Design-Space Exploration Engine (DSE pipeline)
4. Translator / Back-End
• EmitHLSCpp translator
5. Bindings & Tools
• Python binding (pybind11 layer, pyscalehls.py)
• C API
• CLI tools (scalehls-opt, scalehls-translate)
6. External Systems
• LLVM/MLIR infrastructure
• Xilinx Vivado HLS (downstream tool)
• Torch-MLIR package (for PyTorch models)
b. Relationships & Data Flow
1. User code (C/C++ or Python) → Front-End → MLIR IR
2. MLIR IR + ScaleHLS Dialect registration → scalehls-opt CLI
3. scalehls-opt invokes analysis & transform passes → optimized MLIR IR
4. Optimized IR → scalehls-translate → HLS C++ code
5. HLS C++ → downstream HLS tool (Vivado) → RTL
6. Python binding offers the same sequence via API calls
c. Architectural Patterns & Principles
• Multi-Stage Pipeline: separate front-end, IR, transforms, back-end
• Modular Dialects & Passes: plug-and-play transforms
• Design-Space Exploration as a first-class pass pipeline
• Bindings layer to expose core library to Python/C
• CMake-driven build for modular components
d. Key Technologies & Frameworks
• LLVM/MLIR core libraries
• C++17
• CMake + Ninja
• pybind11, numpy (Python binding)
• Torch-MLIR (external PyTorch front-end)
• Vivado HLS (external hardware tool)