High-level Synthesis using the Julia Language

Benjamin Biggs, Ian McInerney, Eric C. Kerrigan, George A. ConstantinidesarXiv 2022 · arXiv

Abstract

This paper explores the use of the Julia language as a front-end for High-Level Synthesis (HLS), aiming to bridge the gap between high-level algorithmic research and low-level FPGA hardware implementation. By leveraging Julia's native compiler infrastructure, specifically its typed intermediate representation and multiple dispatch capabilities, the authors present a prototype tool that translates high-level Julia code into synthesizable VHDL. While the prototype currently shows an optimization gap compared to mature C++ tools, it demonstrates the potential for a unified language approach to hardware-software co-design.

Introduction

Field-Programmable Gate Arrays (FPGAs) offer significant performance and energy efficiency for specialized tasks like machine learning and real-time control. However, they suffer from a persistent "two-language problem." Researchers typically prototype algorithms in high-level, math-friendly languages like Python or MATLAB, while hardware engineers must manually translate these algorithms into low-level Hardware Description Languages (HDLs) like VHDL or Verilog, or use C++-based HLS tools that still require hardware-specific expertise.

Julia is uniquely positioned to solve this problem. Designed to combine the ease of Python with the performance of C, Julia’s architecture allows the same code used for research to be compiled directly to hardware, potentially unifying the development workflow.

Methods

The authors developed a prototype HLS toolflow integrated directly into the Julia ecosystem. Unlike traditional HLS tools that require custom parsers, this tool hooks into the existing Julia compiler at the Typed Intermediate Representation (IR) stage, where data types for every variable have already been inferred.

The Julia-to-VHDL HLS toolflow pipeline, illustrating the transformation from source code to scheduled hardware.

The process involves several key steps:

  1. Compiler Hooking: Extracting the Typed IR from the Julia compiler.
  2. Graph Construction: Converting the IR into a Control Data-Flow Graph (CDFG) using the SSATools.jl package.
  3. Dynamic Scheduling: Utilizing "elastic components" (based on the Dynamatics tool) to allow for data-driven execution.
  4. VHDL Generation: Translating the graph into synthesizable VHDL via the DynamicScheduling.jl package.

This flow leverages Julia's Multiple Dispatch to automatically replace standard CPU operators with hardware-optimized versions without requiring changes to the user's source code.

Key Insights and Ideas

  • The "Pure Julia" Advantage: Many Julia libraries are written in Julia itself rather than wrapping C++ code. This allows the HLS tool to recurse into standard libraries and generate hardware automatically.
  • Type Stability: Julia’s built-in data-flow type inference ensures types are known at compile-time, which is essential for defining bit-widths and circuitry in hardware synthesis.
  • Metaprogramming: Julia’s macro system allows the tool to manipulate the Abstract Syntax Tree (AST) for hardware-specific optimizations like loop unrolling or pipeline balancing.

Key Results

The prototype was evaluated using three programmatic test cases: if_else (conditional branching), power (loop-based exponentiation), and newton_raphson (complex root-finding). These were compared against a baseline generated from C++ using the Dynamatics tool.

Comparison of hardware resource metrics (Basic Blocks and Components) between Julia and C++ implementations.

While the tool successfully generated synthesizable VHDL for all cases, the Julia-to-hardware path is currently less efficient than the C++ path. In the complex Newton-Raphson test, the Julia tool produced significantly more "Basic Blocks" and "Components." This discrepancy is attributed to the lack of mature optimization passes in the Julia prototype compared to those found in established LLVM-based C++ compilers.

Limitations and Future Work

The current prototype faces several challenges that define future research directions:

  • Optimization Gap: Implementing sophisticated optimization passes for the Julia IR to consolidate code blocks.
  • Memory Integration: Adding support for data memory (RAM) to handle large arrays and complex structures.
  • Scheduling: Moving from purely dynamic scheduling to static scheduling for more resource-efficient and deterministic designs.
  • Ecosystem Integration: Ensuring compatibility with open-source synthesis tools like Yosys and libraries like FloPoCo.

Summary updated

Abstract

The growing proliferation of FPGAs and High-level Synthesis (HLS) tools has led to a large interest in designing hardware accelerators for complex operations and algorithms. However, existing HLS toolflows typically require a significant amount of user knowledge or training to be effective in both industrial and research applications. In this paper, we propose using the Julia language as the basis for an HLS tool. The Julia HLS tool aims to decrease the barrier to entry for hardware acceleration by taking advantage of the readability of the Julia language and by allowing the use of the existing large library of standard mathematical functions written in Julia. We present a prototype Julia HLS tool, written in Julia, that transforms Julia code to VHDL. We highlight how features of Julia and its compiler simplified the creation of this tool, and we discuss potential directions for future work.
BibTeX
@misc{biggs2022high,
  author = {Benjamin Biggs and Ian McInerney and Eric C. Kerrigan and George A. Constantinides},
  title = {{High-level Synthesis using the Julia Language}},
  year = {2022},
  eprint = {2201.11522},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2201.11522},
}
Figure