Automatic Hardware Pragma Insertion in High-Level Synthesis: A Non-Linear Programming Approach

Stéphane Pouget, Louis-Noël Pouchet, Jason Cong

Abstract

High-Level Synthesis (HLS) simplifies FPGA design by allowing developers to use C/C++, but achieving high performance requires the manual insertion of optimization pragmas. Tuning these pragmas is difficult because the resulting design space is often astronomical. This paper introduces NLP-DSE, a framework that automates pragma insertion by modeling the problem as a Non-Linear Program (NLP). By using static analysis to create an analytical performance model that acts as a guaranteed lower bound on latency, the system can prune billions of sub-optimal hardware designs in seconds. Experimental results show that NLP-DSE delivers up to 17x better performance than state-of-the-art tools while significantly reducing exploration time.

Introduction: The HLS Bottleneck

High-Level Synthesis (HLS) transforms software descriptions into digital logic (RTL) for FPGAs. However, the performance of the generated hardware depends heavily on "pragmas"—directives that control loop unrolling, pipelining, and data caching. The challenge lies in the "design space," which represents the combination of all possible pragma settings. This space often exceeds billions of configurations, making manual tuning impossible.

Existing Design Space Exploration (DSE) methods typically suffer from two major drawbacks. Traditional search-based methods are extremely slow because they require running the full HLS toolchain for every candidate design. Conversely, machine learning "black-box" models, while faster, often fail to generalize to new code structures or large problem sizes. NLP-DSE aims to bridge this gap with a mathematically rigorous, analytical model.

Methodology: Modeling Pragmas as Non-Linear Programs

NLP-DSE treats pragma insertion as a mathematical optimization problem. The framework consists of several key stages:

  1. Polyhedral Analysis: The system uses static analysis (specifically for "affine" programs) to extract an Abstract Syntax Tree (AST) and property vectors for every loop.
  2. Analytical Modeling: The authors developed a performance and resource model where variables like unroll factors and initiation intervals are the unknowns. Because optimizations in nested loops involve products of variables, the model is inherently non-linear.
  3. The Lower Bound Property: A critical innovation is the proof that their model provides a lower bound on actual HLS latency. This allows the search algorithm to safely discard billions of designs if their predicted "best-case" latency is worse than a design already found.
  4. NLP Solver: These constraints are encoded into the AMPL modeling language and solved using BARON, a global optimization solver.
Design space exploration statistics showing the efficiency of the pruning mechanism.

As shown in the table above, the pruning mechanism is highly effective. For the 2mm kernel, the solver navigated a space of $1.37 \times 10^{10}$ valid designs while only needing to explore 101 candidates and synthesize 15.

Key Results and Performance

The framework was evaluated using the Polybench/C 4.2.1 suite and modern CNN layers on an AMD/Xilinx Alveo U200 FPGA. NLP-DSE was compared against AutoDSE (a bottleneck-driven tool) and HARP (a machine-learning-based tool).

Comprehensive performance comparison of NLP-DSE against state-of-the-art tools across various kernels and data types.

Throughput and Speed

NLP-DSE achieved an average 17.24x higher throughput (GigaFlops/s) compared to AutoDSE. Furthermore, the exploration process was 5.69x faster on average. In several instances, NLP-DSE identified superior designs in minutes that AutoDSE failed to find even after 20 hours of exploration. For 20 out of 47 benchmarks, the very first design suggested by the NLP solver was the best one found in the entire search.

Generalization and Efficiency

Unlike machine learning models like HARP, which struggled with large problem sizes or kernels outside their training set, the NLP approach remained accurate. Because it is based on the fundamental logic of the code rather than statistical patterns, it generalizes across different algorithms and data footprints. The model also includes optimistic estimates for DSP and BRAM usage, ensuring that suggested designs fit within the physical constraints of the target hardware.

Conclusion and Future Work

NLP-DSE demonstrates that mathematical optimization can outperform heuristics and black-box models in hardware design. By proving a lower bound on latency, the framework can mathematically ignore 99.9% of the search space, focusing only on the most promising candidates.

Current limitations include a restriction to "affine" programs (regular loops) and a lack of support for complex control flow like data-dependent while loops. Future work aims to integrate code transformations—such as loop reordering or tiling—directly into the NLP formulation to enable the discovery of even more efficient hardware architectures.

Summary updated

BibTeX
@inproceedings{pouget2024automatic,
  author = {Stéphane Pouget and Louis-Noël Pouchet and Jason Cong},
  title = {{Automatic Hardware Pragma Insertion in High-Level Synthesis: A Non-Linear Programming Approach}},
  booktitle = {FPGA},
  year = {2024},
  doi = {10.1145/3626202.3637593},
}
Figure