TL;DR
DiffHLS introduces a differential learning framework that significantly improves Quality-of-Result (QoR) predictions for High-Level Synthesis (HLS). By predicting a baseline kernel value alongside a pragma-induced "delta" and incorporating frozen Large Language Model (LLM) code embeddings, DiffHLS bypasses the high variance of absolute target regression to accelerate hardware design space exploration.
What Problem Does This Paper Address?
High-Level Synthesis (HLS) is a vital tool in hardware design, allowing engineers to compile high-level languages like C/C++ into register-transfer level (RTL) descriptions for FPGAs. To optimize these designs for area, power, or speed, designers insert compiler directives called pragmas (e.g., loop unrolling, pipelining, array partitioning).
Finding the optimal pragma configuration requires exploring a massive design space. Unfortunately, running full HLS synthesis for every single design point is computationally expensive and slow. While Graph Neural Networks (GNNs) applied to compiler Intermediate Representations (IR) have emerged as a fast alternative for predicting Quality-of-Result (QoR) metrics, they face two major hurdles:
- High Inter-Kernel Variance: The baseline resource usage across different algorithms (kernels) varies by orders of magnitude. Standard models struggle to simultaneously learn these massive baseline differences while capturing the subtle, pragma-driven variations within a single kernel.
- Semantic Loss during Lowering: When source code is lowered into compiler IR graphs, explicit source-level hints and pragma annotations can be weakened or lost, depriving the GNN of critical context.
Methods
DiffHLS tackles these challenges using a novel differential learning formulation. Instead of directly regressing the absolute QoR target of a modified design ($y_d$), it decomposes the prediction into a graph-only kernel baseline ($y_k$) and a design-induced change ($\Delta$):
$$\Delta = y_d - y_k$$
The architecture consists of three main components:
- Dual Graph Encoders: Two parameter-disjoint GNN branches encode the Control-Data Flow Graphs (CDFG) of both the original unoptimized kernel and the pragma-modified design variant.
- LLM Code Embeddings: To preserve source-level pragma semantics, the raw design source code is tokenized and passed through a frozen, pretrained code LLM (such as Qwen2.5-Coder-1.5B). A lightweight adapter projects this embedding to match the GNN's dimensions.
- Differential Heads: A Kernel Head estimates the baseline metric solely from the kernel graph embedding. Concurrently, a Delta Head ingests the kernel graph, design graph, and LLM code embeddings to predict the pragma-driven change.
The entire framework is trained jointly using a three-term SmoothL1 loss function that supervises the baseline prediction, the delta prediction, and the final composed design prediction ($y_d = y_k + \Delta$) to ensure consistency and prevent error accumulation.
Datasets
The authors evaluated DiffHLS on two primary benchmarks:
- PolyBench: Consists of 27 C kernels generating 10,108 distinct design points via pragma insertions (derived from the ForgeHLS PolyBench subset). The models predict four critical QoR targets: DSP, FF, LUT, and Critical Path (CP) delay.
- ForgeHLS: A larger-scale, diverse dataset used to validate the scalability and generalization capabilities of the framework.
Key Insights and Ideas
- Predicting Changes is Easier Than Predicting Absolutes: By isolating the baseline kernel footprint, the model's delta pathway can focus entirely on modeling the local, pragma-driven variations. This drastically reduces target variance within kernel clusters.
- Graphs and Text are Complementary: IR graphs excel at capturing structural control and data dependencies across a program. Meanwhile, frozen LLM code embeddings act as an excellent safety net, retaining explicit pragma annotations and local text patterns that are often diluted during compiler lowering.
- Lightweight Fusion Avoids Heavy Fine-Tuning: Keeping the LLM frozen and using a simple adapter allows the model to leverage massive pretrained code semantics without the prohibitive computational cost of fine-tuning billions of parameters.
Key Results
DiffHLS was evaluated against standard GNN baselines across four popular backbones: PNA, GraphSAGE, GCN, and GAT.
- Substantial Error Reduction: Under the GraphSAGE backbone, DiffHLS reduced the Mean Absolute Percentage Error (MAPE) for DSP from 17.01% to 3.31%, and for LUT from 28.09% to 5.12%.
- Ablation Verification: Disabling the differential learning mechanism (
w/o diff) consistently degraded performance across all backbones. Similarly, removing the LLM code embeddings (w/o code emb.) led to higher errors, proving that text-based semantic cues are vital for tracking pragma impacts.
Limitations and Future Work
While highly effective, the authors noted that the optimal choice of the code LLM backbone (e.g., Qwen vs. Llama) can fluctuate depending on the specific GNN architecture and target metric being predicted, indicating that selecting the right embedding model requires careful tuning. Additionally, because DiffHLS relies on paired samples (base kernel vs. modified design), its current formulation assumes a clear unoptimized baseline is readily available, which might not always be straightforward in highly complex, multi-file commercial projects. Future work could explore extending this differential approach to structural code refactoring beyond simple pragma insertions.
Summary updated