Compiling method of multilayer intermediate representation based on field programmable logic gate array
Through the combination of multi-layer intermediate representation and automatic design space exploration engine, the problems of FPGA programming complexity and insufficient optimization are solved, efficient accelerator generation and performance improvement are achieved, and the compiler development and debugging process is simplified.
Patent Information
- Application Number
- CN202410731720.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-06
- Publication Date
- 2024-09-24
AI Technical Summary
The existing compilation framework has high programming complexity and insufficient optimization in the FPGA backend, making it difficult to generate efficient accelerators. Especially in complex applications, performance improvement is limited, and the scalability based on single-layer intermediate representation design is limited, which increases the need for compiler development. and debugging difficulty.
A compilation method of multi-layer intermediate representation based on field programmable logic gate arrays is adopted, including dependency graph intermediate representation, polyhedral intermediate representation and MLIR affine dialect intermediate representation with hardware description language HLS primitive attributes, through the construction of data dependency graph and loop transformations, perform hardware optimization, and integrate an automatic design space exploration engine to achieve code conversion and optimization.
It reduces the complexity of FPGA programming, generates high-quality accelerators, improves programming efficiency and readability, achieves a high degree of scalability and performance improvement, ensures the stability and reliability of the generated accelerators, and uses an automatic design space exploration engine Compilation efficiency is greatly improved.
Smart Images

Figure 00000000_0000
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of advanced programmable logic compilation, and in particular to a compilation method of multi-layer intermediate representation based on field programmable logic gate array. Background Art
[0002] With the rapid development of computing-intensive applications, field-programmable gate arrays (FPGAs) have attracted much attention due to their high processing speed and resource-energy efficiency. However, the programming complexity of FPGAs has greatly hindered their widespread application. Although high-level synthesis (HLS) technology provides a way to convert algorithms written in high-level languages (such as C / C++) into dedicated hardware accelerators, the performance of the generated accelerators is highly dependent on the user's manual optimization capabilities, including source code reconstruction to eliminate data dependencies and selecting appropriate HLS compilation instructions. This reliance on hardware knowledge and the iterative process of performance verification increase the difficulty of programming and optimization.
[0003] At present, the progress of compilation technology has alleviated the programming and optimization challenges of different computing platforms to a certain extent. For non-FPGA backends (such as CPU, GPU and domain-specific accelerator DSA), existing compilation frameworks have achieved the decoupling of algorithms and scheduling, allowing developers to focus on algorithm definition while the compiler automatically performs optimization tasks. However, these frameworks are mainly targeted at specific application scenarios (such as image processing or deep learning), lack versatility, and are difficult to be directly applied to FPGA backends.
[0004] For the FPGA backend, although there are existing compilation frameworks that support the generation of efficient spatial architectures, these frameworks often rely on a single loop-level intermediate representation (IR) for code optimization, which may be inadequate when dealing with complex applications. In addition, existing frameworks have deficiencies in key compilation optimization technologies such as data dependency analysis and loop transformation, which limits their performance improvement in complex applications.
[0005] Therefore, the current compilation framework has significant deficiencies in supporting FPGA accelerators. Compilation frameworks without FPGA backends have difficulty generating efficient accelerators for FPGAs, while compilation frameworks for FPGA backends lack sufficient support for data dependency analysis and loop transformation. At the same time, compilation frameworks designed based on a single-layer intermediate representation have limited scalability and are difficult to cope with compilation optimization requirements of different granularities, which increases the difficulty of compiler development and debugging. These problems urgently need to be solved by a new type of compilation framework to achieve effective optimization and efficient generation of FPGA accelerators. Summary of the invention
[0006] In view of this, the present invention proposes a compilation method of a multi-layer intermediate representation based on a field programmable gate array to solve the problems of high difficulty and insufficient optimization of FPGA programming in the prior art.
[0007] The specific technical solutions of the present invention are as follows:
[0008] A compilation method for a multi-layer intermediate representation based on a field programmable logic gate array, comprising:
[0009] Step 1: Receive the algorithm input by the user, and divide the input algorithm into three intermediate representations of different abstraction levels through the compilation process of the compiler, including dependency graph intermediate representation, polyhedron intermediate representation, and MLIR affine dialect intermediate representation with hardware description language HLS primitive attributes;
[0010] Step 2: In the intermediate representation phase of the dependency graph, a data dependency graph containing coarse-grained data dependencies between computing blocks is constructed, the producer-consumer relationship of data read and write operations is explicitly expressed through the POM domain-specific language DSL, and data read and write operations are extracted and analyzed;
[0011] Step 3, converting the dependency graph intermediate representation into a polyhedral intermediate representation, including: extracting polyhedral semantics from each node of the dependency graph intermediate representation and efficiently representing it with integer sets and mappings; performing corresponding loop transformations according to the scheduling strategy specified by the user in the POM DSL, while ensuring the correct order of calculation execution; constructing a polyhedral abstract syntax tree AST containing if nodes, for nodes, block nodes and user nodes;
[0012] Step 4, further converting the polyhedral intermediate representation into an MLIR affine dialect intermediate representation with HLS primitive attributes to perform hardware optimization, including: mapping different types of nodes in the polyhedral AST to corresponding operations represented by the MLIR affine dialect to capture loop properties; parsing the calculation statements and data access patterns described in the POM DSL and converting them into correct MLIR affine dialect representations; performing HLS attribute-based hardware optimization on the MLIR affine dialect and generating a fully optimized intermediate representation containing HLS primitives.
[0013] Specifically, in step 3, the polyhedron semantics includes iteration domain and data reading and writing information.
[0014] Specifically, in step 3, the user node adds key information of the calculation statement.
[0015] Specifically, in step 4, the loop attributes include the loop lower bound, upper bound, and iteration interval.
[0016] Specifically, the compilation method also includes: step 5, implementing automatic design space exploration DSE, including: dependency-aware code transformation, by traversing the data dependency graph, applying loop transformation to reduce or eliminate loop dependencies, and iteratively rechecking loop dependencies until the conditions are met; bottleneck-oriented code optimization, by evaluating different loop splitting strategies and HLS hardware optimization combinations, giving priority to performance optimization of bottleneck nodes in the critical path, and gradually increasing the degree of parallelism until the exit mechanism is met.
[0017] Specifically, the compilation method also includes: step 6, sending the optimized MLIR affine dialect intermediate representation to the compiler backend to generate synthesizable HLS C code, in which all HLS attributes are converted into corresponding HLS primitives for use by the FPGA accelerator.
[0018] Specifically, in step 2, in the intermediate representation of the dependency graph, the coarse-grained dependency analysis captures the coarse-grained data dependencies between computing blocks by extracting and analyzing data read and write operations and retaining them using dependency mapping, while the fine-grained dependency analysis analyzes the dependency between two adjacent iterations in a loop to identify loop-carried dependencies and guide lower-level code transformation and optimization.
[0019] Specifically, fine-grained dependency analysis analyzes dependencies by calculating the distance and direction vectors of loops, and stores the relevant information as node attributes to guide loop transformations to increase dependency distances and as hints to users to guide the setting of HLSDEPENDENCE primitives.
[0020] Specifically, in step 3, when loop transformation is performed according to the scheduling strategy specified by the user in the POM DSL, it also involves exchanging the inner loop carrying data dependency with the outer loop to increase the dependency distance, thereby improving data parallelism.
[0021] Specifically, when constructing a data dependency graph containing coarse-grained data dependencies between computing blocks, a depth-first search (DFS)-based method is used to traverse the graph and collect all data paths as key information for subsequent design space exploration.
[0022] The beneficial effects of the present invention are:
[0023] (1) POM was proposed. The core of POM lies in its decoupled domain-specific language, which can efficiently describe complex structures such as functions, loops, and arrays. In addition, POM also provides a series of flexible scheduling primitives, which significantly reduce the number of lines of code while maintaining high performance, improving programming efficiency and readability;
[0024] (2) By introducing a three-layer intermediate representation, a unified compilation framework POM is constructed. This framework makes it possible to perform various optimizations at different abstraction levels, thus achieving high scalability. The design of the three-layer intermediate representation not only simplifies the implementation and debugging process, but also reduces the workload of supporting various optimization methods;
[0025] (3) Focus on generating high-quality accelerator designs. It provides a wealth of optimization methods and performs FPGA-oriented scheduling and optimization at the appropriate level. These optimization methods alleviate tight loop dependencies and improve code parallelism, thereby achieving overall performance improvements. The generated accelerator design not only has excellent performance, but also has guaranteed stability and reliability;
[0026] (4) It integrates a design space exploration (DSE) engine that can automatically search for high-performance scheduling solutions, greatly improving compilation efficiency. At the same time, POM also supports user-defined scheduling strategies, providing flexible solutions for different application scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0028] Figure 1 It is a schematic diagram of the overall architecture of the compilation framework of the compilation method of the multi-layer intermediate representation based on the field programmable logic gate array of the present invention;
[0029] Figure 2 A schematic diagram of the code description of the matrix multiplication described by the POM DSL of the present invention;
[0030] Figure 3 It is a schematic diagram of the layer-by-layer conversion process of the POM multi-level intermediate representation of the present invention;
[0031] Figure 4 It is a schematic diagram of the design of the intermediate representation of the dependency graph of the present invention;
[0032] Figure 5 Schematic diagram illustrating dependency-aware code conversion according to the present invention. DETAILED DESCRIPTION
[0033] In order to make the technical problems, technical solutions and beneficial effects to be solved by the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0034] Aiming at the shortcomings of existing compilation frameworks in FPGA programming, the present invention proposes a compilation method based on multi-layer intermediate representation of field programmable gate array (FPGA) and compiles POM. This method not only greatly reduces the complexity of FPGA programming, but also generates high-quality accelerator design.
[0035] 1.1 Compilation architecture of the present invention
[0036] Figure 1 The overall design of the POM framework is clearly shown. The core of POM lies in its custom domain-specific language (DSL), which is used not only to describe the specific implementation of the algorithm, but also to define the scheduling strategy of the algorithm.
[0037] POM adopts a multi-layer intermediate representation design between algorithm description and hardware implementation. First, POM captures the data dependencies in the input program and constructs a detailed data dependency graph, namely the dependency graph intermediate representation. This step provides a solid foundation for subsequent semantic analysis and optimization.
[0038] Based on the dependency graph intermediate representation, POM uses the polyhedron model to extract the polyhedron semantics of the input program. The polyhedron model is a powerful mathematical tool that can accurately describe the semantics of the loop structure in the program. Through the polyhedron model, POM can deeply understand the structure and properties of the algorithm and perform loop-level optimizations. These optimizations include but are not limited to loop tilting, loop blocking, loop fusion, etc., which aim to improve the parallelism and locality characteristics of the algorithm to adapt to the characteristics of hardware accelerators.
[0039] After the polyhedral model is optimized, POM further converts the polyhedral intermediate representation into the MLIR affine dialect with HLS attributes. MLIR is a flexible intermediate representation that can support a variety of different hardware platforms and optimization strategies. Based on the MLIR affine dialect, POM's compiler can perform HLS hardware optimizations to convert algorithm descriptions into efficient hardware implementations. These optimizations include but are not limited to loop pipelining, array partitioning, memory optimization, etc., aimed at improving hardware performance and efficiency.
[0040] Finally, the optimized MLIR affine dialect is translated into synthesizable HLS code. These HLS codes can be directly used to guide hardware design and implementation, ensuring that the generated hardware can meet the performance requirements of the algorithm. POM ensures the efficiency and flexibility of the entire framework by performing different code analysis, conversion, and optimization operations on different intermediate representations.
[0041] POM integrates an automatic design space exploration (DSE) engine into the framework. The engine uses advanced search algorithms and evaluation strategies to quickly find high-performance design solutions in a huge design space. Users only need to define the description and constraints of the algorithm, and the DSE engine can automatically explore different design options and generate high-quality hardware implementations. This not only greatly reduces the workload of manual design, but also improves the quality and efficiency of design.
[0042] 1.2 Programming Model
[0043] POM's programming model is based on a C++-based declarative DSL, which aims to simplify the process of algorithm description and hardware optimization.
[0044] POM's DSL inherits the concept of Halide, separating algorithm description from scheduling strategy. This decoupled programming model allows users to focus on the implementation of the algorithm without paying too much attention to the details of the underlying hardware. Users only need to write an algorithm description that is independent of the underlying architecture, and then determine the execution order of different components of the algorithm by setting specified scheduling primitives. This design enables users to flexibly explore different transformation and optimization strategies without having to refactor the original code.
[0045] POM DSL uses the compute interface to describe algorithms. Figure 2 For example, the user only needs to declare the name and scope of the loop iteration variable, array placeholders, and calculation operations to fully describe the algorithm. This description method simplifies the conversion process of the input algorithm to its polyhedral representation, allowing the compiler to obtain the polyhedral semantics and data dependencies directly from the definition of the calculation. In addition, POM's DSL also supports multiple data types and calculation functions, which can fully describe various computationally intensive algorithms.
[0046] POM provides a rich set of scheduling primitives, as shown in Listing 1 below, for performing performance optimization.
[0047] These primitives include loop transformation primitives and HLS hardware optimized primitives.
[0048]
[0049] Loop transformation primitives: such as loop skew and loop blocking, which can be used to transform loops by modifying the iteration domain. For example, loop skew can change the dependency direction to improve parallelism, while loop blocking can split a specified loop dimension into two new dimensions to increase data locality. These primitives allow users to flexibly restructure the code and make it better adaptable to subsequent hardware optimizations.
[0050] HLS hardware optimized primitives, such as loop pipelining and array partitioning, are converted to corresponding HLS primitives during code generation to improve hardware performance. For example, loop pipelining can improve hardware throughput and efficiency, while array partitioning can optimize memory access patterns to improve memory performance.
[0051] In addition, POM also provides a primitive f.auto_DSE() for automatic design space exploration. By calling this primitive, users can use POM's automatic design space exploration engine to automatically generate high-quality accelerator design solutions. This greatly reduces the workload of manual design and improves the quality and efficiency of design.
[0052] 1.3 Application of Multi-layer Intermediate Representation Design in Compilation Optimization
[0053] In the POM compilation framework, in order to optimize the code more effectively and adapt to different hardware architectures, the compilation process is explicitly divided into three layers, using intermediate representations with gradually decreasing abstraction levels to gradually transform the input algorithm. These intermediate representations include dependency graph intermediate representation, polyhedral intermediate representation, and MLIR affine dialect with HLS primitive attributes.
[0054] Figure 3 The complete process of the POM compilation framework is shown. POM explicitly divides the compilation steps into three layers, uses intermediate representations with gradually decreasing abstraction levels to gradually transform the input algorithm, and uses corresponding scheduling strategies to transform the code at different abstraction levels. Among them, dependency analysis, code transformation, and hardware optimization are performed on appropriate intermediate representations, namely, dependency graph intermediate representation, polyhedral intermediate representation, and MLIR affine dialect with HLS primitive attributes.
[0055] 1.3.1 Dependency Graph Intermediate Representation
[0056] The first-level intermediate representation of POM is called the dependency graph intermediate representation, which is used to perform data dependency analysis at both coarse and fine granularity levels.
[0057] Coarse-grained dependency analysis: Figure 4 ②Describes the process of building a data dependency graph and the dependency analysis performed on it. POM DSL explicitly expresses the producer-consumer relationship in the computational definition, reflecting the coarse-grained data dependencies between different loops. POM captures coarse-grained data dependencies between computational blocks by extracting and analyzing data read and write operations and preserving them using dependency mapping. With the information of dependency mapping, POM is able to construct an intermediate representation of the dependency graph, where each node represents a nested loop and each edge represents the data dependency between two loops. POM uses a depth-first search (DFS)-based method to traverse the graph and collect all data paths, which is key information for subsequent design space exploration.
[0058] Fine-grained dependency analysis: After the dependency graph is built, POM further performs fine-grained data dependency analysis to analyze the dependencies between two adjacent iterations in the loop. In the FPGA-based accelerator scenario, these data dependencies will greatly hinder the improvement of data parallelism. Therefore, it is very important to represent this level in the middle of the dependency graph to identify loop-carried dependencies and guide lower-level code transformations and optimizations. Specifically, POM traverses each node in the graph, analyzes dependencies by calculating the distance and direction vectors of the loop, and stores relevant information as node attributes. Figure 4 ③ An example is given to illustrate the fine-grained data dependency analysis of node S4. POM first extracts the data access pattern of placeholder D, i.e. (i, j). Taking into account the data access pattern and iteration dimension (i, j, k), POM determines the reduction dimension k, and then calculates the distance vector (0,0,1) of node S4, indicating that there is a loop-carrying dependency in the k dimension. This information is used to guide loop transformation, in this case loop swapping, that is, swapping the inner loop k carrying data dependency with the outer loop to increase the dependency distance. In addition, the loop dependencies identified by the compiler can be used as hints to users, guiding them to set primitives such as HLSDEPENDENCE to further optimize the code.
[0059] 1.3.2 Polyhedral Intermediate Representation
[0060] After completing the coarse and fine granularity dependency analysis, the dependency graph intermediate representation is converted to a polyhedral intermediate representation. Various loop transformations are implemented at this level.
[0061] Construction of polyhedron intermediate representation: Figure 3 (c) depicts the construction process of the polyhedral intermediate representation. In the first step, POM extracts polyhedral semantics, such as iteration domain and data reading and writing information, from each node (nested loop) in the intermediate representation of the dependency graph, and efficiently represents it using integer sets and mappings. In the second step, the corresponding loop transformation is performed according to the scheduling strategy specified by the user at the DSL level, and the correct order of calculation execution is guaranteed. In the third step, POM creates a new mapping by taking the union of the iteration domains of all loops in the entire input program to construct a polyhedral abstract syntax tree (AST). This AST contains four types of nodes: if nodes, for nodes, block nodes, and user nodes, which can be naturally converted into MLIR affine dialects. In order to make up for the lack of representation of specific calculation content in the existing AST, POM attaches key information such as calculation statements to user nodes, so that optimization information can be saved and utilized in the next layer of intermediate representation.
[0062] Implementation of loop transformation: By representing nested loops with integer sets and mappings at the polyhedral intermediate representation level, loop transformation can be converted into a series of operations on polyhedral semantics. These operations include swapping between loop dimensions, calculating new iteration domains by mathematical methods, modifying array indexes, etc. For example, applying loop blocking to loop level i with a size of 8 will change the iteration domain {S(t,i)}. The calculation process of the new iteration domain is {S(t,i0,i1):0≤t≤31∧i0=floor(i / 8)∧i1=i%8∧0≤i≤31}, that is, {S(t,i0,i1):0≤t≤31∧0≤i0≤3∧0≤i1≤7}. In addition to operations on rectangular iteration domains, POM is able to handle non-rectangular iteration domains through more complex loop transformations such as loop tilting, which are performed under the guidance of dependency analysis. POM implements the most commonly used loop transformations as a library. Users only need to specify the API provided by the DSL and call POM for automatic transformation. Due to its efficient representation using integer sets and maps, POM can be easily extended to support more customized loop transformations.
[0063] The advantage of the multi-layer intermediate representation design is that it allows the compiler to perform specific optimization tasks at different levels of abstraction. The dependency graph intermediate representation allows the compiler to perform coarse-grained and fine-grained dependency analysis, providing key information for subsequent loop transformations and hardware optimizations. The polyhedral intermediate representation provides a powerful framework for implementing various complex loop transformations and supports customized optimizations through efficient representations of integer sets and mappings. Finally, the MLIR affine dialect with HLS primitive attributes enables seamless integration between the compiler and the hardware description language, enabling the compiler to generate code optimized for specific hardware.
[0064] Through the multi-layer intermediate representation design, the POM compilation framework can fully utilize the advantages of different abstraction levels to achieve efficient code optimization and hardware acceleration. The dependency graph intermediate representation and polyhedron intermediate representation are used for data dependency analysis and loop transformation respectively, while the MLIR affine dialect with HLS primitive attributes provides a bridge for integration with hardware description languages. This design enables POM to generate code optimized for specific hardware and effectively improve the performance of hardware accelerators such as FPGAs.
[0065] 1.3.3 MLIR Affine Dialect with HLS Attributes
[0066] After completing the optimization of the polyhedral intermediate representation, POM further converts it to the MLIR affine dialect with HLS attributes to perform hardware-specific optimizations. The affine dialect provides a direct abstract representation for affine operations that can be naturally mapped from the polyhedral abstract syntax tree (AST). In addition, the affine dialect provides the explicit loop structure required for hardware optimization, which is lacking in the abstract polyhedral intermediate representation.
[0067] Mapping from polyhedral AST to affine dialect: Given a polyhedral intermediate representation consisting of an abstract syntax tree with hardware optimization information, POM maps different types of nodes in the abstract syntax tree to corresponding operations represented by the affine dialect. Figure 3 As shown in (d), for example, the for node in the abstract syntax tree represents a for loop in the affine dialect (①③④⑤), which captures important loop properties such as loop lower bounds, upper bounds, and iteration intervals. The user node in the abstract syntax tree represents the statement defined by the user in the calculation (⑥⑦). POM is equipped with a recursive method for parsing the calculation statements and data access patterns described in the POM DSL and converting them into the correct affine dialect representation. By implementing automatic conversion from the polyhedral intermediate representation to the MLIR affine dialect, POM builds a bridge between the polyhedral model and MLIR. Therefore, it can freely interact with other excellent work in the MLIR ecosystem while taking full advantage of the advantages of the polyhedral model.
[0068] Implementation of hardware optimizations: After completing the conversion of the polyhedral intermediate representation to the MLIR affine dialect, we perform hardware optimizations based on the HLS properties attached to the affine dialect. For example, by specifying the scheduling primitive S3.pipeline(i,1) in the DSL, Figure 3 In (d), a relevant pipeline attribute is attached to the loop level i of the affine dialect, and its activation interval is one, which is used to represent the loop pipeline optimization and its parameter information. After completing the hardware optimization based on the affine dialect, the fully optimized intermediate representation will be sent to the compiler backend to generate synthesizable HLS C code, in which all HLS attributes are converted into corresponding HLS primitives.
[0069] 1.4 Automatic Design Space Exploration
[0070] The code transformation and optimization methods provided by POM constitute an exponentially growing design space. To reduce the workload, POM provides a two-stage design space exploration (DSE) engine to automatically search for design points that can generate high-quality FPGA accelerators.
[0071] 1.4.1 Dependency-aware code conversion
[0072] To maximize the parallelism of the code, POM first performs dependency-aware code transformations to mitigate or eliminate tight cyclic dependencies as much as possible. The input function is represented as a data dependency graph, where each node represents a cycle. Figure 5 For example, in the first iteration, the dependency analysis tool checks the circular dependencies in S1 and S2 and detects contradictory loop swap strategies: S1 can be effectively executed in the inner loop without circular dependencies, so the current loop order should be maintained, while S2 has a circular dependency in the j-level loop and the i and j dimensions should be swapped. To solve this problem, POM splits S1 and S2 into two independent loops (such as Figure 5 Then, the dependency analysis tool continues to repeatedly recheck the dependencies within each node, and in the second iteration, it performs a loop swap on S2 ( Figure 5 ②), and in the third iteration, S1 and S2 are fused together ( Figure 5 ③). After a series of transformations based on dependency analysis, the potential parallelism in the code can be fully utilized.
[0073] 1.4.2 Bottleneck-oriented code optimization
[0074] Since loop dependencies are mitigated as much as possible in the first phase, we can focus on exploring parallelism by evaluating different combinations of loop partitioning strategies and HLS hardware optimizations. The key idea is to prioritize performance optimization of bottleneck nodes in the critical path. First, POM estimates the latency of each node in the dependency graph and calculates the latency of each path from it. After that, the paths are sorted according to the latency size and the critical path with the longest latency is selected to be optimized first. POM DSE further selects the node with the longest latency in the critical path and performs a series of optimizations on it, trying different combinations of loop partitioning parameters and HLS optimizations, covering different degrees of parallelism. When optimizing the bottleneck node in the critical path, the DSE engine gradually increases the degree of parallelism of the optimization strategy. Once the current node or path is no longer a bottleneck, the algorithm switches to a new bottleneck for optimization and repeats the process. To avoid continuously optimizing the same node, we consider an exit mechanism: if the current node reaches its maximum parallelism or consumes more resources than the resource constraint, the optimization will stop. We use a buffer array to store all nodes that need to be optimized. If a node triggers the exit mechanism, then this node will be removed from the array. When the optimization array is empty, the design space exploration terminates.
[0075] The beneficial effects of the present invention are as follows:
[0076] (1) Highly programmable: POM introduces a decoupled domain-specific language that can efficiently describe complex structures such as functions, loops, and arrays. This greatly improves the intuitiveness and efficiency of programming. To further optimize accelerator performance, POM provides a series of flexible scheduling primitives. These primitives allow developers to significantly reduce the number of lines of code without sacrificing performance, thereby improving code readability and maintainability.
[0077] (2) Excellent scalability: POM builds a unified compilation framework by explicitly introducing a three-layer intermediate representation. This framework allows various optimizations to be performed at different abstraction levels, thus achieving high scalability. The design of the three-layer intermediate representation simplifies the implementation and debugging process, making it easier for the compiler to support various optimization methods and reducing the workload of developers.
[0078] (3) Generate high-quality designs: POM provides a variety of optimization methods that are executed at the appropriate level, with FPGA-oriented scheduling and optimization as the core. By alleviating tight loop dependencies and improving code parallelism, POM can significantly improve the performance of the final generated accelerator design. These optimizations not only improve the execution efficiency of the code, but also ensure the stability and reliability of the design, so that the generated accelerator performs well in practical applications.
[0079] (4) High degree of automation: POM integrates a design space exploration (DSE) engine that can automatically search for high-performance scheduling solutions. This automation mechanism greatly reduces the workload of developers and improves compilation efficiency. At the same time, POM also allows users to set specific scheduling strategies according to specific needs. This flexibility enables POM to meet the needs of different application scenarios, further improving its applicability and practicality.
[0080] (5) Significant performance improvement: Experimental results show that compared with the current state-of-the-art technology, POM achieves an average speedup of 6.46 times on typical test cases. This data fully demonstrates the advantage of POM in compilation efficiency. In practical applications, such as EdgeDetect, VGG-16, and ResNet-18, POM also shows strong performance advantages, achieving an average speedup of 6.06 times. These practical application cases further verify the practicality and effectiveness of the POM compilation method.
[0081] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for compiling a multi-layer intermediate representation based on a field programmable gate array, characterized in that: include: Step 1: Receive the algorithm input by the user, and divide the input algorithm into three intermediate representations of different abstraction levels through the compilation process of the compiler, including dependency graph intermediate representation, polyhedron intermediate representation, and MLIR affine dialect intermediate representation with hardware description language HLS primitive attributes; Step 2: In the intermediate representation phase of the dependency graph, a data dependency graph containing coarse-grained data dependencies between computing blocks is constructed, the producer-consumer relationship of data read and write operations is explicitly expressed through the POM domain-specific language DSL, and data read and write operations are extracted and analyzed; Step 3, converting the dependency graph intermediate representation into a polyhedral intermediate representation, including: extracting polyhedral semantics from each node of the dependency graph intermediate representation and efficiently representing it with integer sets and mappings; performing corresponding loop transformations according to the scheduling strategy specified by the user in the POM DSL, while ensuring the correct order of calculation execution; constructing a polyhedral abstract syntax tree AST containing if nodes, for nodes, block nodes and user nodes; Step 4, further converting the polyhedral intermediate representation into an MLIR affine dialect intermediate representation with HLS primitive attributes to perform hardware optimization, including: mapping different types of nodes in the polyhedral AST to corresponding operations represented by the MLIR affine dialect to capture loop properties; parsing the calculation statements and data access patterns described in the POM DSL and converting them into correct MLIR affine dialect representations; performing HLS attribute-based hardware optimization on the MLIR affine dialect and generating a fully optimized intermediate representation containing HLS primitives.
2. The method for compiling a multi-layer intermediate representation based on a field programmable gate array according to claim 1, characterized in that: In step 3, the polyhedron semantics includes iteration domain and data reading and writing information.
3. The method for compiling a multi-layer intermediate representation based on a field programmable gate array according to claim 1, characterized in that: In step 3, the user node adds key information of the calculation statement.
4. The method for compiling a multi-layer intermediate representation based on a field programmable gate array according to claim 1, characterized in that: In step 4, the loop attributes include the loop lower bound, upper bound and iteration interval.
5. The method for compiling a multi-layer intermediate representation based on a field programmable gate array according to claim 1, characterized in that: The compilation method also includes: step 5, implementing automatic design space exploration DSE, including: dependency-aware code transformation, by traversing the data dependency graph, applying loop transformation to reduce or eliminate loop dependencies, and iteratively rechecking loop dependencies until conditions are met; bottleneck-oriented code optimization, by evaluating different loop splitting strategies and HLS hardware optimization combinations, giving priority to performance optimization of bottleneck nodes in the critical path, and gradually increasing parallelism until the exit mechanism is met.
6. The method for compiling a multi-layer intermediate representation based on a field programmable gate array according to claim 5, characterized in that: The compilation method further includes: step 6, sending the optimized MLIR affine dialect intermediate representation to the compiler backend to generate synthesizable HLS C code, wherein all HLS attributes are converted into corresponding HLS primitives for use by the FPGA accelerator.
7. The method for compiling a multi-layer intermediate representation based on a field programmable gate array according to claim 1, characterized in that: In step 2, in the intermediate representation of the dependency graph, coarse-grained dependency analysis captures coarse-grained data dependencies between computing blocks by extracting and analyzing data read and write operations and retaining them using dependency mapping, while fine-grained dependency analysis analyzes the dependency between two adjacent iterations in a loop to identify loop-carried dependencies and guide lower-level code transformation and optimization.
8. The method for compiling a multi-layer intermediate representation based on a field programmable gate array according to claim 1, characterized in that: The fine-grained dependency analysis analyzes dependencies by calculating the distance and direction vector of the loop, and stores the relevant information as node attributes for guiding loop transformation to increase the dependency distance and as a hint to the user to guide the setting of the HLSDEPENDENCE primitive.
9. The method for compiling a multi-layer intermediate representation based on a field programmable gate array according to claim 1, characterized in that: In step 3, when loop transformation is performed according to the scheduling strategy specified by the user in the POM DSL, it also involves exchanging the inner loop carrying data dependency with the outer loop to increase the dependency distance, thereby improving data parallelism.
10. The method for compiling a multi-layer intermediate representation based on a field programmable gate array according to claim 1, characterized in that: When constructing a data dependency graph containing coarse-grained data dependencies between computing blocks, a depth-first search (DFS)-based method is used to traverse the graph and collect all data paths as key information for subsequent design space exploration.
Citation Information
Cited By
Domain-specific language compiler optimization method and system based on multi-layer intermediate representation
CN119512557A
Method and system for compiler optimization of domain specific languages based on multi-layer intermediate representations
CN119512557B
Accelerator card operator adaptation method and device, computer equipment and storage medium
CN119539036A
Compiling method and system for near storage computing architecture, electronic equipment and storage medium
CN120144134A
Compiling method and device of operator, equipment and medium
CN120653254A
