HLS (C/C++ → RTL)
Doctrine (v0.1.50): 把修法寫進工具,而非寫進 prompt. The HLS tool is the source of RTL; AI is the backstop on pragma narrative.
High-Level Synthesis is the entry point for DSP / AI accelerator /
image-processing blocks where the algorithm is already written in
C/C++. This skill guides the lowering from algorithm to RTL with
pragmas / directives and hands off to /rtl-review.
Mandatory Deterministic Preflight
Review clock/reset domains and use native elaboration, simulation and CDC/RDC results to check the specified reset polarity, assertion and release behavior.
Run the selected native RTL lint/elaboration tools and read their diagnostics, then review unresolved semantic requirements independently. A review score or receipt is not a native result.
HLS-emitted RTL is NOT exempt from plugin gates — many HLS tools emit RTL with subtle latch / reset-discipline issues that downstream synthesis catches only after wasted hours. Refuse to claim "HLS RTL is correct" without running the same gates a hand-authored RTL would face.
When to use
- Algorithmic block (filter, matrix multiply, feature extractor) exists in C/C++/SystemC
- Dataflow-heavy pipeline where manual RTL would be error-prone
- Design-space exploration across latency vs throughput vs area
- Target flow: Vitis HLS, Catapult HLS, Stratus HLS, XLS (open source, Google)
Inputs
- Source file(s) — C/C++/SystemC
- Test vectors (golden I/O pairs)
- Target: FPGA (bitstream) vs ASIC (Verilog netlist)
- Constraints: target clock period, latency budget, throughput, resource limits
- Tool choice
Workflow
- Clean the source: remove pointer chasing, dynamic allocation, recursion — HLS only digests statically-bounded C
- Interface synthesis: decide on AXI-Stream, AXI-Lite, memory-mapped BRAM, or wire handshake for each argument
- Apply pragmas / directives:
#pragma HLS PIPELINE II=1for loops#pragma HLS UNROLL factor=N#pragma HLS DATAFLOWfor stream pipelines#pragma HLS ARRAY_PARTITIONfor memory banks
- Co-simulate C vs generated RTL using the test vectors
- Emit RTL and hand off to
/rtl-reviewand/testbench-gen - Report PPA — estimated from HLS tool's synthesis report
Output format
hls/<module>.cpp— cleaned, annotated sourcehls/<module>.tcl— HLS tool run scripthls/<module>_rpt.md— directive log + PPA estimate + handoff notes
Tool prerequisites
Open source: XLS (https://github.com/google/xls). Commercial: Vitis HLS, Catapult, Stratus.
Technical basis
HLS is a mature commercial flow. XLS is Google's open-source DSL-based HLS. Key principle: the algorithm must be rewritten with hardware-friendly idioms (bounded loops, no dynamic memory, explicit streaming) before HLS can produce good QoR.
Handoff
- Generated RTL →
/rtl-reviewthen/testbench-gen - Golden C model → reuse as reference in
/testbench-gen - PPA →
/ppa-predictfor cross-check