C2HLSC: Can LLMs Bridge the Software-to-Hardware Design Gap?

Luca Collini,Siddharth Garg,Ramesh Karri
2024-06-13
Abstract:High Level Synthesis (HLS) tools offer rapid hardware design from C code, but their compatibility is limited by code constructs. This paper investigates Large Language Models (LLMs) for refactoring C code into HLS-compatible formats. We present several case studies by using an LLM to rewrite C code for NIST 800-22 randomness tests, a QuickSort algorithm and AES-128 into HLS-synthesizable c. The LLM iteratively transforms the C code guided by user prompts, implementing functions like streaming data and hardware-specific signals. This evaluation demonstrates the LLM's potential to assist hardware design refactoring regular C code into HLS synthesizable C code.
Hardware Architecture
What problem does this paper attempt to address?
### Problems the Paper Attempts to Solve This paper aims to explore whether large language models (LLMs) can bridge the gap between software and hardware design. Specifically, the paper investigates how to use LLMs to refactor C code into a format suitable for high-level synthesis (HLS) tools. HLS tools can quickly generate hardware designs from C code, but their compatibility is limited by the code structure. Therefore, the paper demonstrates through several case studies how to use LLMs to refactor C code into HLS-compatible formats, including the NIST 800-22 randomness tests, the QuickSort algorithm, and the AES-128 encryption algorithm. ### Main Contributions 1. **Case Studies**: The paper demonstrates the process of deriving HLS-usable C code from general C code and compares the differences in development time and resource usage between LLM-assisted development and manual methods. 2. **Prototype Tool**: The paper introduces an automated LLM-based C2HLSC tool that can automatically convert C code into HLS-compatible formats and is released as open-source. ### Case Studies 1. **NIST 800-22 Randomness Tests**: - **Challenge**: Changing the processing of preloaded random sequences in memory to bitwise streaming. - **Result**: The LLM successfully refactored the code into a streaming interface, but multiple iterations were needed to achieve the desired effect in some details. 2. **QuickSort Algorithm**: - **Challenge**: Removing pointers and recursion, using a fixed-size stack to track high and low values instead. - **Result**: The LLM successfully removed pointers and recursion, but there were errors in the stack management logic that required manual intervention to correct. 3. **AES-128 Encryption Algorithm**: - **Challenge**: Refactoring loops and function parameters into fixed-size arrays. - **Result**: The LLM successfully performed most of the refactoring, but multiple iterations were needed to correctly implement certain functions like MixColumn and ShiftRows. ### Discussion Using LLMs to refactor C code into HLS-compatible formats is a promising direction. LLMs can significantly reduce the manual effort required to adjust code to fit HLS tools, especially in repetitive tasks. Although LLMs perform well in core functionalities, multiple iterations and manual intervention are still needed to handle some details. Future work includes using LLMs to discover architectural trade-offs and optimize hardware architectures by applying compilation directives and guidelines. ### Conclusion The case studies show that LLMs have great potential in assisting HLS. The implemented prototype tool demonstrates the application prospects of LLMs in aiding hardware design, enabling a seamless transition from C code to optimized hardware architectures when combined with HLS technology. Future work will further explore the application of LLMs in discovering architectural trade-offs.