TL;DR
HLSmith is an expert-guided agentic framework that automates the translation of standard C/C++ code into highly optimized High-Level Synthesis (HLS) designs for FPGAs. By combining a structured library of hardware optimization recipes with a staged, feedback-driven orchestration flow, HLSmith achieves up to a 252× speedup over baseline designs and a 100% functional correctness rate, significantly outperforming prior LLM-based HLS approaches.
What Problem Does This Paper Address?
Field-Programmable Gate Arrays (FPGAs) offer massive performance and energy-efficiency advantages, but programming them is notoriously difficult. High-Level Synthesis (HLS) tools attempt to bridge this gap by compiling standard C/C++ code into hardware description languages (RTL). However, standard algorithmic C/C++ code rarely contains the spatial structures—like memory banking, loop pipelining, or double buffering—needed to run efficiently on hardware.
While Large Language Models (LLMs) excel at generating software, they lack the hardware intuition and procedural knowledge required for HLS design. They struggle to identify hardware bottlenecks, apply optimizations in the correct order, or maintain functional correctness. Prior agentic frameworks like ChatHLS focus primarily on inserting optimization directives (pragmas) rather than refactoring the underlying C/C++ source code, leading to sub-optimal performance and low valid-design compilation rates.
Methods
HLSmith introduces a multi-agent framework that mimics the iterative development process of an expert hardware designer. Its architecture consists of four main pillars:
- HLS Optimization Expertise Library: A structured repository of "guarded transformation recipes" distilled from expert HLS implementations. Each recipe maps a specific hardware bottleneck to a set of structural prerequisites, code-refactoring actions, safety checklists, and expected outcomes.
- Staged, Feedback-Driven Orchestration: Instead of a one-shot generation, the framework iteratively refines the code. A Translator Agent creates an initial baseline; a Toolchain Evaluator runs Vitis HLS simulation and synthesis; a QoR (Quality of Results) Check diagnoses bottlenecks; and an Optimizer Agent applies targeted recipes from the library.
- Hybrid Early-Prediction Setup Router: To save time and LLM token costs, this component analyzes the initial HLS report and source code to prune inefficient optimization pathways, selecting only the top workflow configurations to execute.
- Tool-Grounded Model Adaptation: HLSmith uses successful optimization trajectories from commercial frontier models (like Claude 3.5 Sonnet) to post-train smaller, open-weight models (like Qwen2.5-Coder-7B) using Supervised Fine-Tuning (SFT) and Group-Relative Policy Optimization (GRPO) reinforcement learning.
Datasets
- Rodinia-HLS: Used as the source for learning and distilling expert human HLS optimization behaviors and patterns.
- HLSFactory-28: A fixed benchmark set of 28 PolyBench kernels used to evaluate the framework's translation and optimization performance.
- ML4Accel / Rodinia Tasks: Used as the training corpora for the open-weight model reinforcement learning (GRPO) pipeline.
Key Insights and Ideas
- Prerequisites Matter: HLS optimizations cannot be applied arbitrarily. For example, unrolling a loop requires memory banking to feed the parallel compute lanes, and double buffering requires separating the code into distinct load, compute, and store stages. HLSmith explicitly enforces these structural dependencies.
- Source-Level Refactoring vs. Pragma Tuning: True hardware acceleration cannot be achieved merely by slapping
#pragma HLS UNROLLonto naive code. The underlying algorithm must be structurally transformed (e.g., via loop tiling or array partitioning) to maximize memory bandwidth and parallelism. - Compiler-in-the-Loop Reinforcement: By tying the reward function directly to actual Vitis HLS synthesis metrics (latency, timing slack, and resource utilization), open-weight models can be effectively trained to think like hardware engineers.
Key Results
- 100% Reliability: HLSmith achieved a 100% valid-design rate (passing both C simulation and RTL co-simulation) across all evaluated PolyBench benchmarks, compared to just 57% for ChatHLS.
- Massive Speedups: HLSmith delivered a 4.24× geometric mean speedup over ChatHLS.
- Peak Performance: When powered by commercial frontier models, it achieved up to a 252× speedup over reference HLS baselines. With fine-tuned open-weight models, it achieved up to a 138× speedup.
- Effective Distillation: Applying GRPO to a smaller 7B parameter model (Qwen2.5-Coder) increased its RTL-correct passes from 10 to 13 and yielded a 1.70× synthesis performance gain.
Limitations and Future Work
While HLSmith represents a major leap forward, the authors note that smaller open-weight models, even after post-training, still struggle to implement highly complex global transformations. While they successfully master loop fission, pipelining, and array partitioning, they frequently fail to correctly generate advanced architectures involving full double buffering, dataflow pipelines, or AXI-burst memory restructuring. Future work will focus on improving the reasoning capabilities of open-weight models for these complex, multi-stage structural refactorings.
Summary updated