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 automatically refactoring C code into HLS-compatible formats. We present a case study 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 the, implementing functions like streaming data and hardware-specific signals. With the hindsight obtained from the case study, we implement a fully automated framework to refactor C code into HLS-compatible formats using LLMs. To tackle complex designs, we implement a preprocessing step that breaks down the hierarchy in order to approach the problem in a divide-and-conquer bottom-up way. We validated our framework on three ciphers, one hash function, five NIST 800-22 randomness tests, and a QuickSort algorithm. Our results show a high success rate on benchmarks that are orders of magnitude more complex than what has been achieved generating Verilog with LLMs.
翻译:高层次综合(HLS)工具能够从C代码快速生成硬件设计,但其兼容性受限于代码结构。本文研究了利用大型语言模型(LLMs)自动将C代码重构为HLS兼容格式的方法。我们通过案例研究,展示了使用LLM将NIST 800-22随机性测试、快速排序算法和AES-128的C代码重写为可HLS综合的C代码。该LLM在工具链指导下迭代转换C代码,实现了流式数据和硬件专用信号等功能。基于案例研究的经验,我们实现了一个全自动框架,利用LLMs将C代码重构为HLS兼容格式。针对复杂设计,我们实现了预处理步骤,通过分解层次结构以自底向上的分治方式解决问题。我们在三种密码算法、一种哈希函数、五项NIST 800-22随机性测试以及快速排序算法上验证了该框架。实验结果表明,在比现有LLM生成Verilog方法复杂数个数量级的基准测试中,我们的框架取得了极高的成功率。