UPM – CGRA Compilation Framework
| ID: R21 | Licence: Apache License v2.0 with LLVM Exceptions |
Owner: UPM |
Contacts: joseandres.otero@upm.es alfonso.rodriguezm@upm.es |
| Short Description | The multi-grain reconfigurable CGRA requires compilation support to generate the CGRA configuration bitstream from the user’s application code. |
| Key features | – Code compilation for its execution on the CGRA, built on MLIR with a custom cgra dialect – Automatic selection of the loops to offload and hardware/software partitioning – C programs and quantized neural networks as inputs – Automatic partitioning of kernels that do not fit the CGRA into multiple configurations, and automatic selection of the unrolling factor – ILP-based mapping onto the processing elements of the CGRA – Generation of the RISC-V driver, so that the acceleration is transparent to the user |
| Require | Application code; the sections of code to be offloaded on the CGRA accelerator are identified automatically by the compiler. |
| Provide | Configuration binary for the multi-grain CGRA, together with the RISC-V application that drives it. |
| Input | – Application code (C programs, quantized neural networks, or MLIR in the dfg or linalg dialects) – Description and parameters of the CGRA – Optimization goals and expected metrics for the CGRA |
| Output | – Configuration binaries for the CGRA – RISC-V application with the generated driver, which controls the CGRA through memory-mapped registers |
| User | – Embedded system developers, with application programming skills. Hardware knowledge is not required. – Tool vendors, EDA companies and providers of software development frameworks that build automated toolchains for CGRAs. |
| Benefits for the user | – Automatic generation of accelerators with minor intervention from the users. This implies higher energy efficiency and throughput, with minor design costs. – Reusable MLIR dialect and passes for CGRA mapping, so that a CGRA toolchain does not have to be built from scratch, without RTL coding or proprietary synthesis tools. |
| Download | github.com/des-cei/cgra_gen |
| Position in the MYRTUS DPE | Step 3 – Node-Level Optimization and Deployment. |
| TRL@M0 | 2-3 |
| TRL@M36 | 4-5 |
General description
Based on MLIR, the compiler generates the configuration bitstreams for the multi-grain CGRA of the RISC-V processor with custom CGRA-based extensions, which acts as a domain-specific accelerator, in an automated manner for the user and without requiring the design of custom logic. It decides which parts of an application run on the CGRA and which on the RISC-V cores, maps the former onto the array and generates the software that controls the accelerator, so that hardware accelerators can be obtained at the edge without additional effort for the user.
Role in the MYRTUS DPE
The compiler allows users to deploy computing-intensive sections of code on the CGRA without further intervention, generating the accelerator configurations automatically and potentially adapting the architecture to different operation points, which differ in the use of resources versus the achieved throughput. It is the CGRA backend of the MLIR-based PICEA compiler: starting from the same dataflow representation of an application, a kernel can be compiled for the CGRA, for FPGA accelerators (for example with MDC) or for CPUs. The resulting implementation variants, to be executed on the computing continuum infrastructure, are provided to the MIRTO cognitive engine, which decides at run time where they are deployed.
MYRTUS Extension/Contribution
The original compilation framework of this multi-grain CGRA relied on LLVM, with limited automatic parallelization capabilities; LLVM is also less extensible than MLIR and has portability limitations. Within MYRTUS, the framework has been rebuilt on MLIR, with a custom cgra dialect and passes that offload nested loops, legalize operations to 32-bit arithmetic and turn comparisons into structures supported by the CGRA. The main contributions are the possibility to deploy AI models on the CGRA, while keeping C programs as inputs, since middle- and back-ends are common, and the automatic annotation of the loops that can be deployed. The work is organised in four closely related steps, shown in Figure 1:
- Hardware/software partitioning. The compiler identifies the loops suitable for the CGRA, transforms their operations to make them compatible with it (for example rewriting convolutions as dot products and reductions as accumulators) and separates them from the control-oriented code that remains on the RISC-V core, transparently to the user.
- DFG extraction. Each selected loop body is exported as a dataflow graph (DFG), unrolled when it fits to exploit the parallelism of the CGRA; an automated selector chooses the unrolling factor. Kernels that do not fit entirely within the CGRA are partitioned automatically into several configurations, executed one after the other.
- Mapping. An Integer Linear Programming (ILP) model, running as an MLIR pass, assigns each node of the DFG to a processing element and routes every edge through the interconnect, reducing either the number of processing elements used, so that the others can be power-gated, or the switching activity, to save energy.
- CGRA configuration and driver. Each mapping produces a configuration bitstream. A driver, generated with an MLIR translation, controls the memory-mapped reads and writes of the accelerator and synchronises it with the host, while the code that is not offloaded is compiled independently to RISC-V through LLVM and linked with it, keeping the execution transparent to the user.
Figure 1. Architecture of the CGRA compiler.
Technology Benefits and Innovations
The main advantages of this technology are:
- No vendor lock-in: built entirely on MLIR and open components. The current ILP solver is Gurobi, free with an academic licence, but the mapper writes standard linear programming files.
- Retargetability: the constraints of the fabric are compiler parameters, so the compiler can be extended to other hardware.
- Modularity: the dialect and passes are reusable components that fit into existing MLIR-based compilers and AI model frameworks, hide the hardware-specific details while still allowing fine-grained optimizations, and can evolve with the open-source MLIR community.
- User transparency: the compiler decides automatically what can be offloaded, which is then mapped and deployed without any further user intervention. This closes the usability gap of CGRAs.
- Verifiable results: results are checked with a cycle-accurate RTL simulation, compared against a CPU reference and a native x86 run for correctness.
- Efficiency: stable accelerations across multiple kernels and models, making programs run faster and with a measured better energy efficiency than on the RISC-V core alone.
Other CGRA compilation frameworks are mainly designed for architecture exploration: the programmer annotates a loop, its dataflow graph is extracted and mapped, and the synchronization with the CPU is left to the user. The MYRTUS CGRA compiler, instead, accelerates complete programs and quantized networks without annotations, deciding automatically which loops run on the fabric, and generates the complete RISC-V host application, including memory placement, fabric configuration, synchronization and verification.
Users
The primary users are embedded system designers who need performance and energy efficiency from reconfigurable hardware but cannot absorb the specialist effort of hand-mapping applications on CGRAs. They can use the flow to turn existing C code or a trained quantized network into a deployable, self-checking accelerated application, which also helps them evaluate whether an accelerator is suitable for their real workload before committing to it.
The framework is also of interest to tool vendors, EDA companies and providers of software development frameworks, who can build automated toolchains for CGRAs and other heterogeneous architectures on its dialect and passes instead of developing a full compiler stack, shortening the development of hardware/software co-design solutions and making them usable without low-level hardware design expertise. Further users include CGRA designers, who gain an open front-end to evaluate design choices with real applications, and compiler engineers, who can reuse the dialect and passes as a reference for targeting spatial accelerators.
Application Domains
The framework can be used by data-intensive applications for embedded systems, such as:
- Signal processing: matrix algebra, convolution and filtering.
- Edge AI: quantized convolutional and fully-connected neural networks imported from TFLite, including TinyML anomaly detection and keyword spotting.
References
- D. Vázquez, A. Rodríguez, A. Otero, E. de la Torre, “Extending RISC-V Processor Datapaths with Multi-Grain Reconfigurable Overlays”, in Proc. 37th Conference on Design of Circuits and Integrated Circuits (DCIS), IEEE, 2022, pp. 1-6.
- Source code: github.com/des-cei/cgra_gen
- MLIR: mlir.llvm.org