Hardware description language generation method and device, equipment, medium and product

By processing the basic matrix based on the target folding factor to generate the folded systolic array and control module, the hardware description language is automatically generated, which solves the problem of low multiplication efficiency of the systolic array mapping matrix and improves hardware utilization and design efficiency.

CN118734591APending Publication Date: 2024-10-01PURPLE MOUNTAIN LAB
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410926034.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-10
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

The crude use of systolic array mapping matrix multiplication in the existing technology has low efficiency, the hardware utilization rate is less than 20%, and the design is complex, consumes a lot of manual effort, and is error-prone.

Method used

By processing the basic matrix based on the target folding factor, the folding pulsation array and control module are generated, and the hardware description language is automatically generated, which improves the efficiency of hardware description language generation and reduces manual participation.

Benefits of technology

It improves the hardware utilization of the systolic array, reduces design time and manual participation, reduces the probability of design errors, and meets the needs of different users.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118734591A_ABST
    Figure CN118734591A_ABST
Patent Text Reader

Abstract

The invention discloses a hardware description language generation method and device, equipment, a medium and a product, which are applied to the technical field of integrated circuits, and comprise the following steps: processing a basic matrix based on a target folding factor to obtain a folded systolic array and a control module; generating a hardware description language of the folded systolic array based on the hardware description language of the basic processing element and the parameters corresponding to the folded systolic array; generating a hardware description language of the control module based on the parameters corresponding to the folded systolic array and the parameters corresponding to the control module; the parameters corresponding to the control module comprise a memory reading sequence corresponding to the folded systolic array. According to the method, the corresponding folded systolic array and the control module are obtained through the target folding factor, the basic matrix and the memory reading sequence, the hardware utilization rate of the systolic array is improved due to the folding design, and the hardware description language corresponding to the folded systolic array and the control module is directly generated; and the hardware description language generation efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of integrated circuit technology, and in particular to a method, device, equipment, medium and product for generating a hardware description language. Background Art

[0002] With the continuous development of modern chip technology, people's pursuit of hardware performance is constantly improving. In order to improve hardware performance, in addition to the basic operation modules, people add various special structures to handle specific problems. In order to solve the wiring difficulties under large-scale matrix multiplication and the problem of too many memory reads and bandwidth occupation, people proposed to use systolic arrays for matrix multiplication.

[0003] However, the crude use of systolic arrays to map matrix multiplication is extremely inefficient. In actual use, the hardware utilization rate may drop below 20% in some cases. Detailed processing requires a lot of manual intervention, which will consume a lot of energy of designers and is prone to errors.

[0004] Therefore, how to improve the efficiency of hardware description language generation while improving the hardware utilization of systolic array mapping matrix multiplication is a technical problem that technical personnel in this field urgently need to solve. Summary of the invention

[0005] In view of this, the purpose of the present invention is to provide a hardware description language generation method, device, equipment, readable storage medium and product, which solves the technical problem of low efficiency of hardware description language generation in the prior art, and reduces manual participation and improves the efficiency of hardware description language generation by automatically generating hardware description language.

[0006] In order to solve the above technical problems, the present invention provides a method for generating a hardware description language, comprising:

[0007] The basic matrix is ​​processed based on the target folding factor to obtain a folded systolic array and a control module; wherein the basic matrix is ​​a matrix determined by multiplying two matrices required to generate the folded systolic array; the target folding factor includes a folding factor of a matrix row and a folding factor of a matrix column; the control module is used to control the input and output of the folded systolic array;

[0008] Generate a hardware description language of the folded systolic array based on the hardware description language of the basic processing element and the parameters corresponding to the folded systolic array;

[0009] A hardware description language of the control module is generated based on the parameters corresponding to the folded systolic array and the parameters corresponding to the control module; wherein the parameters corresponding to the control module include a memory read sequence corresponding to the folded systolic array.

[0010] Optionally, before the basic matrix is ​​processed based on the target folding factor to obtain the folded systolic array, the method further includes:

[0011] A memory read order corresponding to the folded systolic array is determined to be row-first, or a memory read order is determined to be column-first.

[0012] Optionally, the processing of the basic matrix based on the target folding factor to obtain the folded systolic array includes:

[0013] The basic matrix is ​​determined by using matrix A and matrix B; wherein the matrix A is, and the matrix B is;

[0014] The basic matrix is ​​folded based on the folding factor m of the matrix rows and the folding factor n of the matrix columns to obtain the folded systolic array.

[0015] Optionally, the generating of the hardware description language of the folded systolic array based on the hardware description language of the basic processing element and the parameters corresponding to the folded systolic array includes:

[0016] By calling each basic processing element, the connection relationship between the internal basic processing elements of the folded systolic array is automatically generated;

[0017] A hardware description language of the folded systolic array is generated based on the memory read sequence and the connection relationship between the internal basic processing elements.

[0018] Optionally, generating a hardware description language of the control module based on the parameters corresponding to the folded systolic array and the parameters corresponding to the control module includes:

[0019] Determining the number of row and column memory channels to be controlled, the number of cycles required for each round of matrix operations, and the systolic array control timing for the output of the folded systolic array through the folded systolic array;

[0020] Determining the number of times the folded systolic array needs to perform matrix calculations according to the target folding factor, and determining the order in which the block matrices in the folded systolic array perform matrix calculations according to the memory reading order;

[0021] A hardware description language of a control module is generated based on the number of memory channels, the number of cycles required for each round of matrix operation, the systolic array control timing, the number of times the folded systolic array needs to perform matrix calculations, and the order in which the block matrices in the folded systolic array perform matrix operations.

[0022] Optionally, after generating the hardware description language, it also includes:

[0023] Testing the correctness of the hardware description language by using a software simulation tool;

[0024] When the hardware description language does not meet the requirements, a new folding systolic array and a control module are regenerated based on a new target folding factor, and then a new hardware description language is generated.

[0025] The present application also provides a hardware description language generation device, comprising:

[0026] A folded systolic array and control module determination module, used to process a basic matrix based on a target folding factor to obtain a folded systolic array and a control module; wherein the basic matrix is ​​a matrix determined by multiplying two matrices required to generate the folded systolic array; the target folding factor includes a folding factor of a matrix row and a folding factor of a matrix column; the control module is used to control the input and output of the folded systolic array;

[0027] A hardware description language determination module for the folded systolic array, configured to generate a hardware description language for the folded systolic array based on the hardware description language of the basic processing element and parameters corresponding to the folded systolic array;

[0028] The hardware description language determination module of the control module is used to generate the hardware description language of the control module based on the parameters corresponding to the folded systolic array and the parameters corresponding to the control module; wherein the parameters corresponding to the control module include the memory reading order corresponding to the folded systolic array.

[0029] The present application also provides a hardware description language generation device, comprising:

[0030] Memory for storing computer programs;

[0031] A processor is used to implement the steps of the hardware description language generation method as described above when executing the computer program.

[0032] The present application also provides a readable storage medium, in which computer executable instructions are stored. When the computer executable instructions are loaded and executed by a processor, the steps of the hardware description language generation method as described above are implemented.

[0033] The present application also provides a computer program product, including a computer program / instruction, which implements the steps of the hardware description language generation method as described above when the computer program / instruction is executed by a processor.

[0034] It can be seen that the present invention obtains a folded systolic array and a control module by processing the basic matrix based on the target folding factor; wherein the basic matrix is ​​a matrix determined by multiplying two matrices required to generate the folded systolic array; the target folding factor includes the folding factor of the matrix row and the folding factor of the matrix column; the control module is used to control the input and output of the folded systolic array; based on the hardware description language of the basic processing element and the parameters corresponding to the folded systolic array, the hardware description language of the folded systolic array is generated; based on the parameters corresponding to the folded systolic array and the parameters corresponding to the control module, the hardware description language of the control module is generated; wherein the parameters corresponding to the control module include the memory reading order corresponding to the folded systolic array. The present application obtains the design of the corresponding folded systolic array and the control module through parameters such as the target folding factor and the basic matrix, improves the hardware utilization of the systolic array, and directly generates the hardware description language corresponding to the folded systolic array, and generates the hardware description language corresponding to the control module, and reduces the time for designing hardware and reduces the probability of errors caused by manual participation in the design by reducing the degree of manual participation in the design of the systolic array.

[0035] In addition, the present invention also provides a hardware description language generation device, equipment, readable storage medium and product, which also have the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, 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 embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0037] Figure 1 A flowchart of a method for generating a hardware description language provided by an embodiment of the present invention;

[0038] Figure 2 A schematic diagram of hardware efficiency provided by an embodiment of the present invention;

[0039] Figure 3 An example flow chart of a method for implementing a systolic array matrix multiplier provided in an embodiment of the present invention;

[0040] Figure 4 A schematic diagram of a systolic array provided by an embodiment of the present invention;

[0041] Figure 5 A schematic diagram of a PE structure provided by an embodiment of the present invention;

[0042] Figure 6A schematic diagram of a structure automatically generated by a hardware description language provided in an embodiment of the present invention;

[0043] Figure 7 A schematic diagram of memory reading provided by an embodiment of the present invention;

[0044] Figure 8 A schematic diagram of the structure of a hardware description language generation device provided by an embodiment of the present invention;

[0045] Fig. 9 A schematic diagram of the structure of a hardware description language generating device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0046] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0047] Some of the terms that appear in the description of the embodiments of the present application may be interpreted as follows:

[0048] Systolic array: An array structure in which data "flows" rhythmically between the processing units of the array in a predetermined "pipeline" manner. During the data flow, all processing units process the data flowing through them simultaneously and in parallel;

[0049] PE: Processing Element, an independent unit for processing computational information. In this application, it is used for multiplication and addition calculations, storing results, and transmitting data. The structure is described in more detail below.

[0050] Please refer to Figure 1 , Figure 1 A flowchart of a method for generating a hardware description language provided by an embodiment of the present invention. The method may include:

[0051] S101, processing a basic matrix based on a target folding factor to obtain a folded systolic array and a control module; wherein the basic matrix is ​​a matrix determined by multiplying two matrices required to generate the folded systolic array; the target folding factor includes a folding factor of a matrix row and a folding factor of a matrix column; and the control module is used to control the input and output of the folded systolic array.

[0052] The execution subject of this embodiment is an electronic device. It is understandable that it is difficult to directly describe the folded systolic array and the control module, and parameter generation is conducive to automatically generating hardware. The hardware description language of the folded systolic array is composed of the hardware description language of the basic processing unit, the folded systolic array, and the hardware description language of the basic processing unit. and memory read order as parameter generation; the control module is composed of a folded systolic array , target folding factor and memory read order are generated as parameters. This embodiment does not limit the method for determining the target folding factor. For example, this embodiment can determine the target folding factor according to the following factors: System cost: When designing a systolic array, simplicity and regularity are important principles, which help to reduce the cost of the system. Therefore, when determining the folding factor, it should be considered how to minimize the cost of the system while meeting the application requirements. Data flow mode: The data flow mode within the systolic array includes static, directional transmission and broadcast. Different data flow modes may affect the selection of the folding factor because it is directly related to the efficiency and speed of data processing. Processing requirement analysis: According to specific application requirements, such as the parameter bit width requirements of the neural network, select a folding factor that can effectively support the multiplication calculation of weight parameters with different precision changes in different network layers. For example, a systolic array structure based on a variable precision multiplier can be designed to adapt to the computing requirements of different precisions. Performance optimization: Optimizing cache access and improving data reuse are the keys to improving the performance of the systolic array. When determining the folding factor, it should be considered how to improve the overall computing efficiency by optimizing the data flow and the configuration of the processing unit. Experiments and simulations: Before actually determining the folding factor, the effects of different folding factors on system performance can be tested through experiments and simulations. This allows the correctness of the theoretical analysis to be verified in actual applications and adjustments to be made based on actual conditions. This embodiment does not limit the specific target matrix size. The target size in this embodiment is the matrix size of the matrix multiplication used. For ease of understanding, the systolic array is generated based on the PE generated in the previous stage, the target folding factor, and the target matrix size. If the size of the A matrix is , the size of the B matrix is , the size of the systolic array directly mapped should be (Basic Matrix). When it is folded, if the folding factor for the columns is m and the folding factor for the rows is n, the size of the systolic array will become The values ​​of m and n must be and At the same time, the entire matrix multiplication will be divided into In order to reduce the number of memory reads of the systolic array after folding, a corresponding cache needs to be added in the output direction to store the results of the row and column so that they can be circulated inside the systolic array. It can be understood that when there is a matrix multiplication A×B, if A is ( , ), B is ( , ), then the size of the output result C is ( , ). The two values ​​of must be the same) This is determined by the nature of matrix operations. Therefore, when the dimensions of the input A and B are determined, the output matrix size (matrix dimensions) is determined.

[0053] Further, in order to improve the hardware efficiency when using the systolic array, the above processing of the basic matrix based on the target folding factor to obtain the folded systolic array may include: using the matrix A and the matrix B to determine the basic matrix as ; Among them, the matrix A is , the matrix B is ; The basic matrix is ​​folded based on the folding factor m of the matrix row and the folding factor n of the matrix column, and the folded systolic array is obtained as It is understandable that since the systolic array transmits the data of the first row and column to the subsequent PE units in a pulsating manner, the modules of the systolic array cannot work at the same time, which eventually causes a certain delay in the modules. Its hardware efficiency is as follows:

[0054] .

[0055] U is the hardware utilization. When U is 1, it means that the hardware is always working. Otherwise, it means that part of the hardware is idle while working. 2 When it is not large enough, the larger the size of the final matrix C, the lower the hardware efficiency. In extreme cases, Figure 2 As shown, Figure 2 A schematic diagram of hardware efficiency provided by an embodiment of the present invention: Taking A as (64, 32) and B as (32, 64) as an example, when the systolic array is used directly, its hardware efficiency is only 20%. To solve this problem, it is necessary to fold the matrix. Through the folding process, the folded systolic array continuously calculates smaller-scale matrix multiplications, reducing the probability of idle PE units in the systolic array, so the utilization rate of the hardware can be improved.

[0056] Furthermore, in order to improve the user experience, before generating the required folded systolic array and control module based on the target folding factor and the target matrix size, it may also include: determining that the reading order of the memory in the control module is row-first, or determining that the reading order of the memory is column-first. In this embodiment;

[0057] The row-first reading order is to first calculate the result of the same row of the matrix operation, and cache the data input from the row to the folded systolic array until the data is no longer used by the folded systolic array; the column-first reading order is to first calculate the result of the same column of the matrix operation, and cache the data input from the column to the folded systolic array until the data is no longer used by the folded systolic array;

[0058] by Figure 7 For example, when the matrix size A and B are (4,4) and the folded systolic array is (2,2), it is equivalent to the following block matrix operation. The folded systolic array will be calculated in each round , , and A set of results is obtained, and the operation of the entire matrix is ​​completed after 4 rounds.

[0059] .

[0060] When performing row-first read order, the first and data, and give priority to calculating and Data related results. Figure 7 For example, the folded systolic array reads the blue and green rows of matrix A and the purple and dark green columns of matrix B to compute In the next operation of the folded systolic array, it will reuse the blue and green rows of matrix A that it read previously, and additionally read the orange and brown columns of matrix B to calculate As a result, data is no longer read from matrix A during the process, thus reducing the number of memory accesses. and After all relevant block matrices are calculated, the folded systolic array will be read from matrix A. and In the same way and Calculation.

[0061] The memory-based reading order provides a reference for the subsequent generation of the hardware description language of the folded systolic array and the control module. The row-major advantage of this embodiment: when the data locality is in a row, row-major storage can provide better spatial locality. For many common matrix operations, such as matrix multiplication, elements are more efficiently processed in consecutive rows. The column-major advantage of this embodiment: in some mathematical operations, such as matrix and vector multiplication, the column-major access mode may be more natural because it allows continuous access to the elements of the vector without jumping to different rows. Using column-major can better utilize the cache mechanism and improve memory access efficiency. It can be understood that the row-major and column-major reading orders can meet the needs of different users and improve the user experience.

[0062] S102: Generate a hardware description language of the folded systolic array based on the hardware description language of the basic processing element and parameters corresponding to the folded systolic array.

[0063] In this embodiment, the parameters corresponding to the folded systolic array may include a target folding factor, a size of the folded systolic array, and a memory read order (row-first or column-first).

[0064] S103, generating a hardware description language of the control module based on parameters corresponding to the folded systolic array and parameters corresponding to the control module; wherein the parameters corresponding to the control module include a memory read sequence corresponding to the folded systolic array.

[0065] In this embodiment, the hardware description language of the folded systolic array and the hardware description language of the control module constitute the target hardware description language ultimately required.

[0066] The control module in this embodiment is a module for controlling the reading of the memory and the operation and output of the systolic array. This embodiment does not limit the specific target hardware description language. For example, the target hardware description language (HDL) in this embodiment is a language for describing digital circuits and systems, which can be designed and simulated layer by layer from high level to low level. The target hardware description language in this embodiment can be VHDL (VHSIC Hardware Description Language): VHDL is a high-level language originally developed by the US Department of Defense to improve the reliability of the design and shorten the development cycle. It is mainly used to describe the structure, behavior, function and interface of the digital system. Or the target hardware description language in this embodiment can be Verilog HDL: Verilog HDL is similar to a high-level programming language (such as C language). It is a language that describes the structure and behavior of digital system hardware in text form. It can be used to represent logic circuit diagrams, logic expressions, and more complex digital logic systems. The hardware description language in this embodiment can also be SystemC: SystemC is a system-level hardware description language that supports system modeling and design at a higher level of abstraction. With the continuous increase in the scale of logic system development, SystemC has been increasingly used. The hardware description language in this embodiment can also be a register transfer level (RTL). The advantages of RTL hardware code include: in RTL design, complex systems can be decomposed into smaller and more manageable modules. Each module is responsible for a specific function. This modular design helps to improve the readability, maintainability and reusability of the code. It is conducive to verification and optimization: the RTL-based design process provides a solid foundation for hardware verification and optimization. The design team can use system models for verification, which are more advantageous than RTL because they are easy to develop and have excellent operating performance. Improve the readability and maintainability of the design: RTL design not only improves the readability of the design, but also makes the design easier to maintain. This is very important for subsequent design iterations and problem debugging. It is conducive to the design of sequential logic circuits: RTL is particularly suitable for the design of sequential logic circuits because it can clearly describe the data transmission and state changes between registers, which is a very critical part of synchronous circuit design. According to the above discussion, the use of register transfer level (RTL) hardware code can improve applicability and be applicable to multiple platforms.

[0067] It should be further explained that, in order to improve the accuracy of the hardware description language generation of the folded systolic array, the hardware description language of the folded systolic array may be generated based on the hardware description language of the basic processing element and the parameters corresponding to the folded systolic array, and may include: calling The basic processing element is used to automatically generate the connection relationship between the internal basic processing elements of the folded systolic array; the hardware description language of the folded systolic array is generated based on the memory reading order and the connection relationship between the internal basic processing elements. This embodiment provides the specific parameters required for generating the hardware description language of the folded systolic array. The specific parameters required for the hardware description language include the basic processing element (PE), the memory reading order, and the connection relationship between the internal basic processing elements. The connection relationship between the internal PEs in this embodiment is as follows: Figure 5 Taking the PE as an example, if the processing element is located at the i-th row and j-th column, the "data input 1 (delay 1 cycle)" will be connected to the "data input 1" of the PE at the i+1-th row and j-th column; the "data input 2 (delay 1 cycle)" will be connected to the "data input 2" of the PE at the i-th row and j+1-th column; the "result output signal (delay 1 cycle)" will be connected to the "result output signal" of the PEs at the i+1-th row and j-th column and the i-th row and j+1-th column; in particular, when the PE to be connected does not exist, the output interface is vacant.

[0068] It should be further explained that in order to improve the accuracy of the hardware description language generated by the control module, the generation of the hardware description language of the control module based on the parameters corresponding to the folded systolic array and the parameters corresponding to the control module may include: determining the number of row and column memory channels that need to be controlled, the number of cycles required for each round of matrix operations, and the systolic array control timing for the output of the folded systolic array through the folded systolic array; determining the number of times the folded systolic array needs to perform matrix calculations through the target folding factor, and determining the order of matrix operations for the block matrices in the folded systolic array through the memory reading order; generating the hardware description language of the control module based on the number of memory channels, the number of cycles required for each round of matrix operations, the systolic array control timing, the number of times the folded systolic array needs to perform matrix calculations, and the order of matrix operations for the block matrices in the folded systolic array. The number of row and column memory channels that need to be controlled in this embodiment refers to the number of memory groups that need to be individually controlled by the control module, which is generally , for example for Figure 7 In the folded systolic array, a total of 2 rows and 2 columns of data are input in different ways, so the number of memory channels is 4. The number of cycles required for each round of matrix operation in this embodiment is For example, for Figure 7, the size of the input matrix is ​​(4,4), and after folding, it is still equivalent to performing matrix multiplication of (2,4) and (4,2), so the number of cycles required for each round of matrix operation is 4. In this embodiment, the systolic array control timing of the folded systolic array output refers to the control of the control module on the order of reading the input matrix data and outputting the systolic array data. In this embodiment, the number of times the folded systolic array needs to perform matrix calculations is determined according to the target folding factor. For example, when the target folding factor is m and n, the number is The process of determining the order of matrix operations of block matrices in the folded systolic array by the memory read order is that if the read order is row-first, the operations of block matrices in the same row are calculated first. If the read order is column-first, the operations of block matrices in the same column are calculated first.

[0069] Furthermore, in order to improve the accuracy of the target hardware description language generation, after the hardware description language is generated, the above may also include: testing the correctness of the hardware description language through a software simulation tool; when the hardware description language does not meet the requirements, re-generating a new folded systolic array and control module based on the new target folding factor, and then generating a new hardware description language. It can be understood that in digital circuit design, using software simulation tools to test the correctness of the hardware description language code is an important step. If the hardware description language does not meet the requirements, testing the hardware description language through a software simulation tool can verify the functional correctness of the design before actually manufacturing the hardware. This helps to discover and fix logical errors in the design, reducing development cycles and costs.

[0070] The hardware description language generation method provided by the embodiment of the present invention may include: S101, processing the basic matrix based on the target folding factor to obtain a folded systolic array and a control module; wherein the basic matrix is ​​a matrix determined by multiplying two matrices required to generate the folded systolic array; the target folding factor includes the folding factor of the matrix row and the folding factor of the matrix column; the control module is used to control the input and output of the folded systolic array; S102, generating the hardware description language of the folded systolic array based on the hardware description language of the basic processing element and the parameters corresponding to the folded systolic array; S103, generating the hardware description language of the control module based on the parameters corresponding to the folded systolic array and the parameters corresponding to the control module; wherein the parameters corresponding to the control module include the memory reading order corresponding to the folded systolic array. Compared with the current direct use of the systolic array for direct mapping, the actual hardware efficiency is extremely low, and the design of high hardware efficiency requires a lot of manual participation, which requires high labor and time costs, the present application obtains the corresponding folded systolic array design through parameters such as the target folding factor, the basic matrix and the memory reading order, thereby improving the hardware utilization of the systolic array. And directly generate RTL (register-transfer level) hardware code corresponding to the folded systolic array and the control module, by reducing the manual participation in the design of the systolic array, reducing the time for designing hardware and reducing the probability of errors caused by manual participation in the design. In addition, the row-first and column-first reading orders can meet the needs of different users and improve the user experience; and, this embodiment gives the folding factor of the row array and the folding factor of the column array respectively, improves the accuracy of folding, and prevents the use of one folding factor from being unable to simultaneously achieve the folding of rows and columns, thereby improving the hardware efficiency when using the systolic array; and, using the register transfer level (RTL) hardware code can improve applicability and be applicable to multiple platforms; and, the specific parameters required for generating the hardware description language of the control module and the parameters required for generating the hardware description language of the folded systolic array are given, which improves the accuracy of generation.

[0071] In order to make the present invention easier to understand, please refer to Figure 3 , Figure 3 An example flow chart of a method for implementing a systolic array matrix multiplier provided in an embodiment of the present invention may specifically include:

[0072] S201, determining a folded systolic array according to a target folding factor and a target matrix size; the target folding factor is a row folding ratio and a column folding ratio set according to requirements.

[0073] Determining the folded systolic array in this embodiment corresponds to generating the required folded systolic array based on the target folding factor and the target matrix size in the above text. The target matrix size in this embodiment corresponds to the basic matrix in the above text. The present invention provides a solution for automatically generating a hardware design for matrix multiplication of a systolic array. Before specifically introducing the invention, it is necessary to briefly introduce matrix multiplication and systolic array.

[0074] Matrix multiplication: Let the formula for matrix multiplication generated by the matrix and be as follows:

[0075] .

[0076] in, Representative Matrix The value in the i-th row and k-th column. If the size of the matrix A is , the size of the B matrix is , then theoretically a matrix multiplication requires Multiply-add operations.

[0077] Systolic array: In order to reduce the number of memory reads during matrix calculations and reduce wiring difficulty, a systolic array is needed to perform matrix multiplication operations. A common systolic array is Figure 4 As shown, Figure 4 A schematic diagram of a systolic array provided by an embodiment of the present invention. The lower right corner shows the basic structure of a systolic array. PE (Processing Element) is the basic operation module used by the systolic array. When it is used for matrix multiplication, it represents a multiplication-addition module. Except for the first row and the first column, the data of all PEs are provided by the previous row or column. If the size of the A matrix is , the size of the B matrix is , we can use a scale of The matrix composed of PEs generates a systolic array. When the data in the A and B matrices are input into the systolic array at intervals under the clock drive, the desired results can be obtained from the PE corresponding to the systolic array. The main advantage of the systolic array is that the hardware design is neat and easy to wire. And the number of memory reads is small. Figure 4 In this case, both matrices only need to be read once. PE structure: It is mainly used to generate the structure of the basic computing unit required for the systolic array. It can be understood that when no folding is performed, the systolic array requires an N 1 ×N 3 PE matrix is ​​implemented as Figure 4 PE itself has not changed. This step uses N 1 ×N 3 The same PEs are connected to each other to form a matrix. Figure 5A schematic diagram of a PE structure provided by an embodiment of the present invention, wherein D represents a register. Data inputs 1 and 2 represent data obtained from a memory or a previous PE, respectively, which will be stored in the intermediate memory after multiplication and addition operations. When the result output signal is input, the data is output to the output data register, and the original register is cleared and waits for the next round of input.

[0078] This embodiment generates a systolic array based on the pre-provided PE and target folding factor and target matrix size. If the size of the A matrix is , the size of the B matrix is , the size of the systolic array directly mapped should be When folding, if the folding factor for the columns is m and the folding factor for the rows is n, the size of the systolic array will become At the same time, the entire matrix multiplication will be divided into In order to reduce the number of memory reads of the systolic array after folding, a corresponding cache needs to be added in the output direction to store the results of the row and column so that they can be circulated inside the systolic array.

[0079] For easier understanding, please refer to Figure 6 , Figure 6 A schematic diagram of a structure automatically generated by a hardware description language provided in an embodiment of the present invention, from Figure 6 As can be seen, the parameters select the folding factor, matrix dimension (size) and output direction, and finally the RTL Verilog code (register transfer level hardware code) is generated.

[0080] S202: Determine a memory read order according to row priority or column priority and a target folding factor and a size of a folding systolic array.

[0081] In this embodiment, the order of reading the memory is determined by the memory reading order (row priority or column priority) of the systolic array and the folding factor as well as the size of the systolic array. The folding factor determines how many blocks the matrix is ​​divided into, thereby determining how many times it needs to be read, and together with the row priority or column priority, determines the specific reading order of the memory. If the output is row priority, after reading the row data once, all the columns of the block matrix are completed before continuing to read the row data. If the output is column priority, after reading the column data once, all the rows of the block matrix are completed before continuing to read the column data. Figure 7 A schematic diagram of memory reading provided by an embodiment of the present invention, when two (4,4) matrices are multiplied, 16 PEs are required when directly mapped to a systolic array. When the rows and columns are folded with a folding factor of 2, the size of the systolic array is (2,2), and 4 PEs are required, which is equivalent to performing 4 consecutive block matrix multiplications of the (2,4) and (4,2) matrices to complete the same function. Specifically, as shown in the following formula:

[0082] .

[0083] Among them For example, it represents the block matrix in the first row and first column after A is divided into blocks, and The matrix operation can be performed multiple times in smaller scales by dividing the matrix into blocks. The folding factor determines how many blocks the matrix is ​​divided into in rows and columns for calculation.

[0084] Since the decision is to output rows first, that is, to output the results of each row in full first, the first and second rows of matrix A will be used first when performing sub-block multiplication (the sub-blocks in the above block matrix). and When they complete the first round of sub-block operations, since the second round of sub-block operations still require the first and second rows, they have been stored in the cache of the systolic array and do not need to be read again in the second round of calculations. When all the results related to the first and second rows are calculated, the calculation is completed. and After the results are obtained, the third and fourth rows of matrix A are read and input into the systolic array.

[0085] S203, setting the reading and writing mode of the memory in the control module and the working and output mode of the systolic array according to the memory reading sequence.

[0086] The control module of this embodiment corresponds to the above and is used to control the input and output of the systolic array after folding. After determining the memory read order, this embodiment requires a hardware control module to control the reading and writing of the memory and the operation and output of the systolic array. The control module will be composed of a counter and a state machine. According to the folding factors m and n, the state machine will be divided into idle and The state of the sub-blocks is calculated, and the transition between sub-blocks will be controlled by the counter. Whenever the state machine enters a new state, the control module will read the corresponding data from the memory, control the systolic array to reset the register and output the data.

[0087] S204: Generate register transfer level hardware code according to the control module and the folded systolic array.

[0088] This embodiment corresponds to the hardware description language of the folded systolic array based on the hardware description language of the basic processing element and the parameters corresponding to the folded systolic array, and generates the hardware description language of the control module based on the parameters corresponding to the folded systolic array and the parameters corresponding to the control module; wherein the parameters corresponding to the control module include the memory read sequence corresponding to the folded systolic array. In this embodiment, the state machine in the control module can be divided into idle and multiple computing sub-block states according to the folding factor.

[0089] Compared with the traditional hardware design solution, the embodiment of the present invention can directly derive the RTL (register-transfer level) hardware code required by the systolic array through some more intuitive parameters, and no longer requires more manual participation in the design details. The automatic generation solution proposed in this solution has the following advantages:

[0090] 1) Automatically generate RTL code, designers only need to focus on the interface, not the internal functions. Through the parameter selection of folding factor, input matrix size, and memory read order, designers can make choices in hardware efficiency, throughput, and function within a certain range to meet the needs of different users, reduce the designer's labor cost and reduce the probability of error.

[0091] 2) Unlike the implementation based on HLS (High-level Synthesis) technology, which is currently mainly used on FPGA platforms, the generated RTL code can be used on more platforms and has high versatility.

[0092] 3) Using the target folding factor to perform folding allows the folded systolic array to continuously calculate smaller-scale matrix multiplications, reducing the probability of idle PE units in the systolic array, thereby improving hardware utilization.

[0093] The hardware description language generating device provided in an embodiment of the present invention is introduced below. The hardware description language generating device described below and the hardware description language generating method described above can be referred to each other.

[0094] Please refer to Figure 8 , Figure 8 A schematic diagram of the structure of a hardware description language generation device provided in an embodiment of the present invention may include:

[0095] The folded systolic array and control module determination module 100 is used to process the basic matrix based on the target folding factor to obtain the folded systolic array and the control module; wherein the basic matrix is ​​a matrix determined by multiplying two matrices required to generate the folded systolic array; the target folding factor includes the folding factor of the matrix row and the folding factor of the matrix column; the control module is used to control the input and output of the folded systolic array;

[0096] A hardware description language determination module 200 for a folded systolic array, configured to generate a hardware description language for the folded systolic array based on the hardware description language of the basic processing element and parameters corresponding to the folded systolic array;

[0097] The hardware description language determination module 300 of the control module is used to generate the hardware description language of the control module based on the parameters corresponding to the folded systolic array and the parameters corresponding to the control module; wherein the parameters corresponding to the control module include the memory reading order corresponding to the folded systolic array.

[0098] Further, based on the above embodiment, the hardware description language generating device may further include:

[0099] The memory read sequence determination module is used to determine that the memory read sequence corresponding to the folded systolic array is row-first, or to determine that the memory read sequence is column-first.

[0100] Further, based on any of the above embodiments, the folded systolic array and control module determination module 100 may include:

[0101] A basic matrix determination unit is used to determine the basic matrix using matrix A and matrix B: ; Wherein, the matrix A is , the matrix B is ;

[0102] A folding processing unit is used to fold the basic matrix based on the folding factor m of the matrix row and the folding factor n of the matrix column to obtain the folded systolic array as .

[0103] Further, based on any of the above embodiments, the hardware description language determination module 200 of the folded systolic array may include:

[0104] The connection relationship determination unit between the internal basic processing elements is used to call Basic processing elements are automatically generated to connect the internal basic processing elements of the folded systolic array;

[0105] A hardware description language generation unit for the folded systolic array is used to generate a hardware description language for the folded systolic array based on the memory read sequence and the connection relationship between the internal basic processing elements.

[0106] Further, based on any of the above embodiments, the hardware description language determination module 300 of the above control module may include:

[0107] A channel number, cycle number and control timing determination unit, used to determine the number of row and column memory channels to be controlled, the number of cycles required for each round of matrix operation, and the systolic array control timing output by the folded systolic array through the folded systolic array;

[0108] A unit for determining the order of performing matrix operations on block matrices, configured to determine the number of times the folded systolic array needs to perform matrix calculations according to the target folding factor, and to determine the order of performing matrix operations on block matrices in the folded systolic array according to the memory reading order;

[0109] The hardware description language generation unit of the control module is used to generate the hardware description language of the control module based on the number of memory channels, the number of cycles required for each round of matrix operation, the systolic array control timing, the number of times the folded systolic array needs to perform matrix calculations, and the order in which the block matrices in the folded systolic array perform matrix operations.

[0110] Further, based on any of the above embodiments, the hardware description language generating device may further include:

[0111] A hardware description language testing unit, used to test the correctness of the hardware description language through a software simulation tool;

[0112] The hardware description language regeneration unit is used to regenerate a new folding systolic array and a control module based on a new target folding factor when the hardware description language does not meet the requirements, and then generate a new hardware description language.

[0113] It should be noted that the order of the modules and units in the above hardware description language generating device can be changed without affecting the logic.

[0114] The hardware description language generation device provided by the embodiment of the present invention may include: a folded systolic array and control module determination module 100, which is used to process a basic matrix based on a target folding factor to obtain a folded systolic array and a control module; wherein the basic matrix is ​​a matrix determined by multiplying two matrices required to generate the folded systolic array; the target folding factor includes a folding factor of a matrix row and a folding factor of a matrix column; the control module is used to control the input and output of the folded systolic array;

[0115] A hardware description language determination module 200 for a folded systolic array, configured to generate a hardware description language for the folded systolic array based on the hardware description language of the basic processing element and parameters corresponding to the folded systolic array;

[0116] The hardware description language determination module 300 of the control module is used to generate the hardware description language of the control module based on the parameters corresponding to the folded systolic array and the parameters corresponding to the control module; wherein the parameters corresponding to the control module include the memory reading order corresponding to the folded systolic array. Compared with the current direct mapping using the systolic array, the actual hardware efficiency is extremely low, and the design of high hardware efficiency requires a lot of manual participation, which requires high labor and time costs, the present application obtains the corresponding folded systolic array design through parameters such as the target folding factor, the basic matrix and the memory reading order, thereby improving the hardware utilization of the systolic array. And directly generate the RTL (register-transfer level) hardware code corresponding to the folded systolic array and the control module, by reducing the manual participation in the design of the systolic array, reducing the time for designing hardware and reducing the probability of errors caused by manual participation in the design. Furthermore, the row-first and column-first reading orders can meet the needs of different users and improve the user experience; further, the embodiment provides the folding factor of the row array and the folding factor of the column array respectively, thereby improving the accuracy of folding and preventing the situation where one folding factor cannot simultaneously realize the folding of rows and columns, thereby improving the hardware efficiency when using a systolic array; further, the use of register transfer level (RTL) hardware code can improve the applicability and be applicable to a variety of platforms; further, the specific parameters required for generating a hardware description language for a control module and the parameters required for generating a hardware description language for a folded systolic array are provided, thereby improving the accuracy of generation.

[0117] A hardware description language generating device provided by an embodiment of the present invention is introduced below. The hardware description language generating device described below and the hardware description language generating method described above can refer to each other.

[0118] Please refer to Fig. 9 , Fig. 9 A schematic diagram of the structure of a hardware description language generation device provided in an embodiment of the present invention may include:

[0119] A memory 10, used for storing computer programs;

[0120] The processor 20 is used to execute a computer program to implement the above-mentioned hardware description language generation method.

[0121] The memory 10 , the processor 20 , and the communication interface 30 all communicate with each other via a communication bus 40 .

[0122] In the embodiment of the present invention, the memory 10 is used to store one or more programs, and the program may include program code, and the program code includes computer operation instructions. In the embodiment of the present invention, the memory 10 may store programs for implementing the following functions:

[0123] The basic matrix is ​​processed based on the target folding factor to obtain a folded systolic array and a control module; wherein the basic matrix is ​​a matrix determined by multiplying two matrices required to generate the folded systolic array; the target folding factor includes a folding factor of a matrix row and a folding factor of a matrix column; and the control module is used to control the input and output of the folded systolic array.

[0124] Generate a hardware description language of the folded systolic array based on the hardware description language of the basic processing element and the parameters corresponding to the folded systolic array;

[0125] A hardware description language of the control module is generated based on parameters corresponding to the folded systolic array and parameters corresponding to the control module; wherein the parameters corresponding to the control module include a memory read sequence corresponding to the folded systolic array.

[0126] In a possible implementation, the memory 10 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function, etc.; the data storage area may store data created during use.

[0127] In addition, the memory 10 may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include an NVRAM. The memory stores an operating system and operating instructions, executable modules or data structures, or a subset thereof, or an extended set thereof, wherein the operating instructions may include various operating instructions for implementing various operations. The operating system may include various system programs for implementing various basic tasks and processing hardware-based tasks.

[0128] The processor 20 may be a central processing unit (CPU), an application specific integrated circuit, a digital signal processor, a field programmable gate array or other programmable logic device, a microprocessor or any conventional processor, etc. The processor 20 may call a program stored in the memory 10 .

[0129] The communication interface 30 may be an interface of a communication module, and is used to connect to other devices or systems.

[0130] Of course, it should be noted that Fig. 9 The structure shown does not constitute a limitation on the hardware description language generating device in the embodiment of the present invention. In actual applications, the hardware description language generating device may include Fig. 9 More or fewer components than shown, or combinations of certain components.

[0131] The following is an introduction to the computer-readable storage medium provided in the embodiment of the present invention. The computer-readable storage medium described below and the hardware description language generation method described above can be referenced to each other.

[0132] The present invention also provides a readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned hardware description language generation method are implemented.

[0133] The readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.

[0134] The present application also provides a computer program product, including a computer program / instruction, characterized in that when the computer program / instruction is executed by a processor, the steps of the hardware description language generation method as described above are implemented.

[0135] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0136] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0137] Finally, it should be noted that, in this article, relationships such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprises" or any other variations are intended to cover non-exclusive inclusion, so that a process, method, article or device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.

[0138] The above is a detailed introduction to a hardware description language generation method, device, equipment, medium and product provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for general technical personnel in this field, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A method for generating a hardware description language, It is characterized in that include: The basic matrix is ​​processed based on the target folding factor to obtain a folded systolic array and a control module; wherein the basic matrix is ​​a matrix determined by multiplying two matrices required to generate the folded systolic array; the target folding factor includes a folding factor of a matrix row and a folding factor of a matrix column; the control module is used to control the input and output of the folded systolic array; Generate a hardware description language of the folded systolic array based on the hardware description language of the basic processing element and the parameters corresponding to the folded systolic array; A hardware description language of the control module is generated based on the parameters corresponding to the folded systolic array and the parameters corresponding to the control module; wherein the parameters corresponding to the control module include a memory read sequence corresponding to the folded systolic array.

2. The method for generating a hardware description language according to claim 1, It is characterized in that Before the basic matrix is ​​processed based on the target folding factor to obtain the folded systolic array, the method further includes: A memory read order corresponding to the folded systolic array is determined to be row-first, or a memory read order is determined to be column-first.

3. The method for generating a hardware description language according to claim 1, It is characterized in that The step of processing the basic matrix based on the target folding factor to obtain a folded systolic array includes: The basic matrix is ​​determined by using matrix A and matrix B: ; Wherein, the matrix A is , the matrix B is ; The basic matrix is ​​folded based on the folding factor m of the matrix row and the folding factor n of the matrix column, and the folded systolic array is obtained as .

4. The method for generating a hardware description language according to any one of claims 1 to 3, It is characterized in that The generating of the hardware description language of the folded systolic array based on the hardware description language of the basic processing element and the parameters corresponding to the folded systolic array comprises: By calling Basic processing elements are automatically generated to connect the internal basic processing elements of the folded systolic array; A hardware description language of the folded systolic array is generated based on the memory read sequence and the connection relationship between the internal basic processing elements.

5. The method for generating a hardware description language according to claim 4, It is characterized in that The generating of the hardware description language of the control module based on the parameters corresponding to the folded systolic array and the parameters corresponding to the control module comprises: Determining the number of row and column memory channels to be controlled, the number of cycles required for each round of matrix operations, and the systolic array control timing for the output of the folded systolic array through the folded systolic array; Determining the number of times the folded systolic array needs to perform matrix calculations according to the target folding factor, and determining the order in which the block matrices in the folded systolic array perform matrix calculations according to the memory reading order; A hardware description language of a control module is generated based on the number of memory channels, the number of cycles required for each round of matrix operation, the systolic array control timing, the number of times the folded systolic array needs to perform matrix calculations, and the order in which the block matrices in the folded systolic array perform matrix operations.

6. The method for generating a hardware description language according to claim 1, It is characterized in that After generating the hardware description language, it also includes: Testing the correctness of the hardware description language by using a software simulation tool; When the hardware description language does not meet the requirements, a new folding systolic array and a control module are regenerated based on a new target folding factor, and then a new hardware description language is generated.

7. A hardware description language generating device, It is characterized in that include: A folded systolic array and control module determination module, used to process a basic matrix based on a target folding factor to obtain a folded systolic array and a control module; wherein the basic matrix is ​​a matrix determined by multiplying two matrices required to generate the folded systolic array; the target folding factor includes a folding factor of a matrix row and a folding factor of a matrix column; the control module is used to control the input and output of the folded systolic array; A hardware description language determination module for the folded systolic array, configured to generate a hardware description language for the folded systolic array based on the hardware description language of the basic processing element and parameters corresponding to the folded systolic array; The hardware description language determination module of the control module is used to generate the hardware description language of the control module based on the parameters corresponding to the folded systolic array and the parameters corresponding to the control module; wherein the parameters corresponding to the control module include the memory reading order corresponding to the folded systolic array.

8. A hardware description language generating device, It is characterized in that include: Memory for storing computer programs; A processor, configured to implement the steps of the method for generating a hardware description language according to any one of claims 1 to 6 when executing the computer program.

9. A readable storage medium, It is characterized in that The readable storage medium stores computer executable instructions, and when the computer executable instructions are loaded and executed by a processor, the steps of the hardware description language generation method according to any one of claims 1 to 6 are implemented.

10. A computer program product comprising a computer program / instructions, It is characterized in that When the computer program / instructions are executed by a processor, the steps of the hardware description language generation method according to any one of claims 1 to 6 are implemented.