ProgSG: Cross-Modality Representation Learning for Programs in Electronic Design Automation

Yizhou SunarXiv 2023 · DOI

TL;DR

This paper introduces PROGSG, a novel method for learning representations of hardware designs described in high-level synthesis (HLS) code. By jointly learning from the source code and its corresponding control data flow graph (CDFG), PROGSG significantly improves the prediction of design quality, a crucial step for automating the design of specialized hardware accelerators.

What Problem Does This Paper Address?

Designing specialized hardware accelerators (DSAs) for tasks like deep learning or autonomous driving is complex. High-level synthesis (HLS) tools aim to simplify this by allowing designers to use C/C++ code, but they still require intricate manual tuning of "pragmas" (directives) to optimize performance and resource usage. Automating these decisions with machine learning is challenging because it requires a deep understanding of the program's structure and its potential hardware implementations. Existing methods often focus on either the source code or the control data flow graph (CDFG) derived from it, but fail to effectively combine the rich semantic information of the code with the structural insights of the CDFG, or leverage the fine-grained alignment information provided by compilers.

Methods

PROGSG employs a multi-modal approach, combining a transformer model for the source code sequence and a graph neural network (GNN) for the CDFG. The core innovations lie in how these two modalities are integrated:

  • Graph-Summary-Augmented Sequence Representation (PROGSG-SI): The GNN first generates a summary embedding of the CDFG. This summary is then prepended to the source code sequence as a special token, allowing the transformer to attend to it during its self-attention mechanism. This provides a coarse interaction between the two modalities.
  • Fine-grained Node-Token Message Passing: PROGSG leverages compiler-provided alignment information between CDFG nodes and source code tokens. It implements a message-passing mechanism where nodes and tokens can exchange information, enabling a deeper, more granular collaboration between the modalities. This is performed iteratively within the transformer layers.
  • Pre-training for GNNs: To address the scarcity of labeled HLS design data, the paper proposes a novel pre-training strategy for the GNN. This involves training the GNN on compiler-derived data flow analysis tasks (like control reachability, dominators, data dependencies, and liveness) on CDFGs. This teaches the GNN to extract essential structural information from programs.

Datasets

The paper evaluates PROGSG on two datasets derived from two different versions of AMD/Xilinx HLS tools (SDX 2018.3 and VITIS 2020.2). These datasets consist of 40 kernels from the MachSuite and Polybench benchmark suites, covering various computation types. For each kernel, multiple design points are generated by varying HLS pragmas, and their quality (latency and resource utilization) is recorded.

Key Insights and Ideas

  • Complementary Modalities: Source code and CDFGs offer distinct but complementary information. Source code captures high-level semantics, while CDFGs reveal the underlying control and data flow crucial for hardware implementation.
  • Alignment is Key: The compiler-provided alignment between source code tokens and CDFG nodes is a valuable, underutilized resource for cross-modal learning. PROGSG's fine-grained interaction leverages this effectively.
  • Pre-training for Domain Specificity: General-purpose GNN pre-training is insufficient. Training GNNs on compiler-specific tasks (like data flow analysis) on CDFGs provides domain-relevant knowledge that significantly boosts downstream performance.
  • Generalizability: The proposed approach aims to improve the automation of HLS design decisions, making it easier for software programmers to design efficient hardware accelerators.

Key Results

PROGSG consistently outperforms baseline methods, including single-modality approaches (CODE2VEC, CODET5, GNN-DSE) and simpler multi-modal combinations (PROGSG-CA, PROGSG-SI), across both benchmark datasets and in both transductive (seen programs) and inductive (unseen programs) settings. Notably, in the inductive setting, PROGSG achieves the lowest overall prediction error, demonstrating its ability to generalize to new programs and pragma configurations. For instance, on the VITIS 2020.2 dataset, the full PROGSG model achieves an RMSE of 0.8199 in the inductive setting, significantly lower than other methods.

Limitations and Future Work

A key limitation acknowledged is the dependence of the model on the specific HLS tool version used for synthesis. Different tool versions can employ varying optimization heuristics, impacting the final microarchitecture and thus the design quality. Improving the generalization of PROGSG across different HLS tool versions is identified as a challenge and a direction for future work.

Summary updated

Abstract

Recent years have witnessed the growing popularity of domain-specific accelerators (DSAs), such as Google's TPUs, for accelerating various applications such as deep learning, search, autonomous driving, etc. To facilitate DSA designs, high-level synthesis (HLS) is used, which allows a developer to compile a high-level description in the form of software code in C and C++ into a design in low-level hardware description languages (such as VHDL or Verilog) and eventually synthesized into a DSA on an ASIC (application-specific integrated circuit) or FPGA (field-programmable gate arrays). However, existing HLS tools still require microarchitecture decisions, expressed in terms of pragmas (such as directives for parallelization and pipelining). To enable more people to design DSAs, it is desirable to automate such decisions with the help of deep learning for predicting the quality of HLS designs. This requires us a deeper understanding of the program, which is a combination of original code and pragmas. Naturally, these programs can be considered as sequence data, for which large language models (LLM) can help. In addition, these programs can be compiled and converted into a control data flow graph (CDFG), and the compiler also provides fine-grained alignment between the code tokens and the CDFG nodes. However, existing works either fail to leverage both modalities or combine the two in shallow or coarse ways. We propose ProgSG allowing the source code sequence modality and the graph modalities to interact with each other in a deep and fine-grained way. To alleviate the scarcity of labeled designs, a pre-training method is proposed based on a suite of compiler's data flow analysis tasks. Experimental results on two benchmark datasets show the superiority of ProgSG over baseline methods that either only consider one modality or combine the two without utilizing the alignment information.
BibTeX
@misc{sun2023progsg,
  author = {Yizhou Sun},
  title = {{ProgSG: Cross-Modality Representation Learning for Programs in Electronic Design Automation}},
  year = {2023},
  eprint = {2305.10838},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.10838},
}
Figure