Improved data processing method for accelerating computation of large complex sparse matrices in CSR

By converting the plural sparse linear rigid matrix into four sub-matrix formal matrix, and using the improved Fill-CSR format storage, the problem of high-speed caching caused by the CSR storage format has been solved, and more efficient vector accelerates hardware utilization. It has significantly improved the solution of the large -scale plural dilute matrix division in the field of electromagnetic computing.

CN118296289BActive Publication Date: 2025-01-24NAT UNIV OF DEFENSE TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410400840.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-03
Publication Date
2025-01-24
Estimated Expiration
2044-04-03

AI Technical Summary

Technical Problem

In the field of electromagnetic computing, when solving large complex sparse matrix equations, the existing CSR storage format leads to a large number of cache missing, unable to make full use of vector acceleration hardware, increasing memory access overhead and slowing down the overall running speed.

Method used

By converting the plural sparse linear rigid matrix into the sub-matrix formation of four real number matrix forms, and the improved Fill-CSR format is used for storage, the Fill-CSR format forms an element group by traversing and consolidated or zero-supplementing to ensure data alignment alignment alignment alignment , Adapt to the instruction set of vectorization to accelerate hardware.

Benefits of technology

Through the improved storage format, the lack of high -speed cache is reduced, the computing visitor ratio is improved, and the performance of the vector accelerates the hardware has been used to significantly improve the iterative solution of the large plural sparse matrix equations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118296289B_ABST
    Figure CN118296289B_ABST
Patent Text Reader

Abstract

The present application provides a data processing method for accelerating the calculation of large complex sparse matrices with improved CSR, which is applied to the iterative solution of large complex sparse matrix equations in the fields of electromagnetic calculation, etc., and uses the differential equation method to perform numerical simulation / emulation on the physical model to be calculated, determine the complex sparse linear stiffness matrix, and convert the complex sparse linear stiffness matrix into four sub-matrices in the form of real matrices, and store them in the CSR storage format after forming the real matrix, and then convert the CSR storage format into the improved Fill-CSR format, so as to realize SPMV optimization in iterative solution and accelerate solution calculation. This scheme can make full use of the performance of vectorized acceleration hardware, increase the amount of single memory access calculation, improve the calculation memory access ratio, and thus improve the overall running speed. The number of elements in the even array can align the data to adapt to the code structure of 2-fold loop expansion, so as to achieve better acceleration effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of electromagnetic computing technology, and in particular to a data processing method for accelerating the calculation of large complex sparse matrices using improved CSR. Background Art

[0002] Industrial technology based on electromagnetic fields has played a crucial role in the development of modern human civilization, and will also be an important basic technology in the future. In recent years, my country has made a series of important progress in fields closely related to electromagnetics, such as the successful commissioning of airborne early warning and command aircraft, and the exploration of deep-earth and marine mineral resources. Generally speaking, commonly used numerical calculation methods for electromagnetic fields can be divided into two categories: one is based on the solution of differential equations; the other is based on the solution of integral equations. Among them, electromagnetic calculations based on differential equation methods such as finite element method, finite difference method, and finite volume method usually require solving large complex sparse matrix equations in the end, and the process of solving the equations usually occupies more than 90% of the time of the entire calculation process.

[0003] In order to be suitable for applications in multimedia audio, image processing and other fields, current multi-core processors have expanded the vector register architecture, such as X86's AVX architecture and ARM's NEON architecture. The principle of vector registers is SIMD (Single Instruction Multiple Data), which aims to use one instruction to process multiple data at the same time, such as the fmal multiplication and addition instruction and the fadd addition instruction in the ARMv8 architecture. There are similar instructions in the X86 system. In the ARMv8 architecture, the vector register has a size of 128 bits and can store 2-bit double type data or 4-bit float type data.

[0004] Here is a brief introduction to the working process of vector storage, such as Figure 1 As shown, v1, v2, and v3 are 128-bit vector registers, which store two arrays a and b. Now, to multiply the corresponding elements of the two arrays a and b, the ordinary multiplication instruction needs to be called 4 times to implement this process (such as Figure 1 As shown), the vectorized instruction only needs one fmul multiplication instruction to complete the task, such as Figure 2 As shown in the figure, it can be seen that when the processed data can be scaled and aligned, SIMD technology can greatly improve the computing speed.

[0005] Generally speaking, large complex sparse matrices are stored in compressed storage formats such as CSR, COO, and SELL to save space. SPMV operations are computationally memory-intensive operations, but these storage formats make the equation system discontinuous in memory access, especially the access to the x vector. This results in a large number of cache misses when calculating large complex sparse matrix equation systems, making it impossible to fully utilize the performance of vector acceleration hardware, increasing memory access overhead and slowing down the overall operation speed. Summary of the invention

[0006] The purpose of the embodiments of the present application is to provide a data processing method for accelerating the calculation of large complex sparse matrices of an improved CSR, so as to achieve accelerated solution of large complex sparse matrices in the field of electromagnetic computing, better utilize the performance of vector acceleration hardware, and improve the overall operating speed.

[0007] In order to achieve the above purpose, the embodiments of the present application are implemented in the following manner:

[0008] In the first aspect, an embodiment of the present application provides a data processing method for accelerating the calculation of large complex sparse matrices with an improved CSR, which is applied to the iterative solution of large complex sparse matrix equations in the field of electromagnetic computing, including: using the differential equation method to perform numerical simulation / emulation on the model to be calculated, determining the complex sparse linear stiffness matrix, and converting the complex sparse linear stiffness matrix into four sub-matrices in the form of real matrices; storing the real matrix formed by the sub-matrices in the form of four real matrices in the CSR storage format; converting the CSR storage format into an improved Fill-CSR format, wherein, when the Fill-CSR format is used to store matrix non-zero element values, each group of elements contains two values, and a group of elements contains 2, 1 or 0 matrix non-zero element values; based on the data stored in the Fill-CSR format, SPMV optimization in iterative solution is implemented to accelerate the solution calculation.

[0009] In combination with the first aspect, in a first possible implementation of the first aspect, the complex sparse linear stiffness matrix is ​​converted into four sub-matrices in the form of real matrices, including: the complex sparse linear stiffness matrix satisfies:

[0010] Kx=b,

[0011]

[0012] Among them, K is the complex sparse linear stiffness matrix, x is the unknown vector, b is the right-hand vector, K r and K i is the real part and imaginary part of K, b r and b i is the real and imaginary part of b, x r and xi is the real part and imaginary part of x; then, K r , -K i , -K i , -K r The four sub-matrices corresponding to the real number matrix form are recorded as the first sub-matrix, the second sub-matrix, the third sub-matrix, and the fourth sub-matrix. The first sub-matrix, the second sub-matrix, the third sub-matrix, and the fourth sub-matrix are distributed from left to right and from top to bottom to form a real number composite matrix.

[0013] In combination with the first possible implementation method of the first aspect, in a second possible implementation method of the first aspect, after the real number composite matrix formed by the sub-matrices in the form of four real number matrices is stored in the CSR storage format, the real number composite matrix includes a values ​​group, a columns group and a row-offsets group, and the CSR storage format is converted into the designed Fill-CSR format, including: traversing the values ​​group in the CSR storage format in a row, forming a Fill-CSR based on the adjacent relationship between the columns where the non-zero element values ​​of the two adjacent matrices in the values ​​are located, and the number of element groups formed after traversing the row. The new-values ​​group in the Fill-CSR format is a new-columns group in the Fill-CSR format. The values ​​group corresponds to multiple rows of the real matrix. The in-row traversal of the values ​​group in the CSR storage format is essentially an in-row traversal of the non-zero element values ​​of the real matrix row by row. Based on the new-values ​​group in the Fill-CSR format, the columns group is updated to form a new-columns group in the Fill-CSR format. Based on the new-values ​​group in the Fill-CSR format, the row-offsets group is updated to form a new-row-offsets group in the Fill-CSR format.

[0014] In combination with the second possible implementation method of the first aspect, in a third possible implementation method of the first aspect, the values ​​group in the CSR storage format is traversed in the row, and based on the adjacent relationship between the columns where the non-zero element values ​​of the two adjacent matrices in the values ​​are located, and the number of element groups formed after traversing the row, a new-values ​​group in the Fill-CSR format is formed, including: traversing the values ​​group in the CSR storage format from left to right in the row: if the column where the non-zero element value of the current matrix is ​​located is adjacent to the column where the non-zero element value of the next matrix is ​​located, the non-zero element value of the current matrix and the non-zero element value of the next matrix are combined into a group of elements for storage, and the processing of the non-zero element value of the current matrix and the non-zero element value of the next matrix is ​​completed, wherein each group of elements occupies 2 capacity bits; if the column where the non-zero element value of the current matrix is ​​located is not adjacent to the column where the non-zero element value of the next matrix is ​​located, the non-zero element value of the current matrix is ​​padded with zero to form a group of elements composed of the non-zero element value of the current matrix and a value of zero, and the processing of the non-zero element value of the current matrix is ​​completed; after completing the intra-row traversal of a row of the values ​​group in the CSR storage format: if the number of element groups formed by the current row is an odd number, the elements of each group are stored in sequence, and a group of pure zero elements [0, 0] is added at the end; if the number of element groups formed by the current row is an even number, the elements of each group are stored in sequence; after completing the intra-row traversal of all rows of the values ​​group in the CSR storage format, each group of elements formed in each row is stored in sequence to form a new-values ​​group in the Fill-CSR format.

[0015] In combination with the third possible implementation manner of the first aspect, in a fourth possible implementation manner of the first aspect, based on the new-values ​​group in the Fill-CSR format, the columns group is updated to form a new-columns group in the Fill-CSR format, including: calculating column coordinates based on each group of elements in the new-values ​​group in the Fill-CSR format, updating the columns group, and forming a new-columns group in the Fill-CSR format.

[0016] In combination with the third possible implementation method of the first aspect, in a fifth possible implementation method of the first aspect, based on the new-values ​​group in the Fill-CSR format, the row-offsets group is updated to form a new-row-offsets group in the Fill-CSR format, including: calculating the row offset based on each group of elements in the new-values ​​group in the Fill-CSR format, updating the row-offsets group, and forming a new-row-offsets group in the Fill-CSR format.

[0017] In combination with the third possible implementation method of the first aspect, in a sixth possible implementation method of the first aspect, based on data stored in the Fill-CSR format, SPMV optimization in iterative solution is implemented to accelerate solution calculation, including: defining aa_1 as a double type array storing non-zero element values ​​of the sparse matrix, that is, the new-values ​​group in the Fill-CSR format, defining aj as an int type array storing column coordinates of non-zero element values ​​of the sparse matrix, that is, the new-columns group in the Fill-CSR format, and defining ii_ as storing each row of the sparse matrix The int type array of the coordinates of the first non-zero element value in aa_1, that is, the new-row-offsets group in Fill-CSR format, define x as the vector in the sparse matrix-vector multiplication, and define y as the final result; traverse the data stored in Fill-CSR format row by row; assign the initial value of 0 to the vector register temp_y_1 and the vector register temp_y_2; traverse the data in the row, read the current 2 double type data from aa_1, that is, a group of elements, recorded as the current element, read the column coordinates corresponding to the current element from aj, and read from the vector x at the same time , read the following 2 double type data from aa_1, that is, the next group of elements of the current element, and read the column coordinates corresponding to this group of elements from aj, and read the corresponding 2 double type data from vector x at the same time; perform corresponding multiplication and addition operations on the 2 double type data of the current element read from aa_1 and the corresponding 2 double type data read from vector x, and add them to vector register temp_y_1 to obtain 2 double type data; perform corresponding multiplication and addition operations on the 2 double type data of the next group of elements read from aa_1 and the corresponding 2 double type data read from vector x, and add them to vector register temp_y_2 to obtain 2 double type data; add the two double type data in vector register temp_y_1 and the two double type data in vector register temp_y_2 to obtain the calculation result of these four double type data, and assign the calculation result to the final result y, until the data stored in Fill-CSR format is traversed.

[0018] In a second aspect, an embodiment of the present application provides a computer device comprising a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of a data processing method for accelerating calculation of large complex sparse matrices of an improved CSR as described in any one of the first aspect or any possible implementation of the first aspect.

[0019] In a third aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, characterized in that when the computer program is executed by a processor, the steps of the data processing method for accelerating the calculation of large complex sparse matrices of the improved CSR are implemented as described in any one of the first aspect or the possible implementation methods of the first aspect.

[0020] In a fourth aspect, an embodiment of the present application provides a computer program product, including a computer program, characterized in that when the computer program is executed by a processor, it implements the steps of the data processing method for accelerating the calculation of large complex sparse matrices of the improved CSR described in any one of the first aspect or the possible implementation methods of the first aspect.

[0021] Beneficial effects:

[0022] 1. This solution is aimed at electromagnetic computing and other fields, and is suitable for Feiteng NEON (i.e., NEON instruction set of ARM architecture) or other similar instruction sets for SIMD (such as MSA instruction set of MIPS and AVX / SSE / MMX instruction set of Intel X86 architecture, etc.). The differential equation method (such as finite element method, finite difference method, finite volume method, etc.) is used to perform numerical simulation / emulation on the model to be calculated, and the complex sparse linear stiffness matrix is ​​determined, and the complex sparse linear stiffness matrix is ​​converted into four sub-matrices in the form of real matrices. After the real matrix is ​​formed, it is stored in CSR storage format, and then the CSR storage format is converted into the designed Fill-CSR format to realize SPMV optimization in iterative solution and accelerate the solution calculation. The Fill-CSR format mainly traverses the values ​​group in the CSR storage format in the row, and determines whether to form a group of elements by merging (if adjacent, merge the two non-zero values ​​into a group of elements) or filling with zeros (if not adjacent, use a non-zero value plus a zero element to form a group of elements) based on the relationship between the non-zero values ​​of the two adjacent matrices stored in the CSR format in the columns in the large complex sparse matrix, and the number of element groups formed in the row after traversing (determine whether to fill a group of pure zero elements based on whether the number of element groups in the row is odd or even, to ensure that the number of element groups is even), and forms a new-values ​​group in the Fill-CSR format after traversing all rows. Each group of elements in the new-values ​​group contains 2 numerical elements, which can make the non-continuously stored single non-zero value be stored in the vector register, fully utilize the performance of the vectorized acceleration hardware, increase the amount of single memory access calculation, improve the calculation memory access ratio, and thus improve the overall running speed. The number of elements in the even array can align the data to adapt to the code structure of the 2x loop expansion, thereby achieving better acceleration effect. Overall, the improved CSR data processing method for accelerating the calculation of large complex sparse matrices can make full use of vectorized acceleration hardware, improve the SPMV calculation speed in iterative solution to improve the overall calculation speed, and effectively improve the efficiency of solving large complex sparse matrices in the field of electromagnetic calculation.

[0023] 2. Converting the CSR storage format to the improved Fill-CSR format is essentially a preprocessing process. Since SPMV will be used multiple times in the FGMRES iterative processing, the preprocessing overhead of converting to the Fill-CSR format can be spread over multiple SPMV calculations and is almost negligible.

[0024] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0026] Figure 1 This is a schematic diagram of the working process of ordinary multiplication instructions during the vector storage process.

[0027] Figure 2 This is a schematic diagram of the working process of vectorized instructions during the vector register working process.

[0028] Figure 3 A flowchart of a data processing method for accelerating the calculation of large complex sparse matrices of improved CSR provided in an embodiment of the present application.

[0029] Figure 4 Schematic diagram of the non-zero element distribution of the complex sparse linear stiffness matrix.

[0030] Figure 5 Schematic diagram of the distribution of non-zero elements of a real composite matrix.

[0031] Figure 6 The example image is stored in a 6*6 sparse matrix.

[0032] Figure 7 The traditional CSR format corresponding to the example image is stored in a 6*6 sparse matrix.

[0033] Figure 8 The FILL_CSR format corresponding to the example image is stored in a 6*6 sparse matrix. DETAILED DESCRIPTION

[0034] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.

[0035] In this embodiment, the data processing method for accelerating the calculation of large complex sparse matrices of the improved CSR can be applied to computer equipment (such as terminals or servers). In the field of electromagnetic computing (in addition to the electromagnetic computing field in the popular sense, the present invention is also applicable in other scenarios or fields where electrical engineers solve equations involving current. Therefore, the electromagnetic computing field in this application should be understood in a relatively broad sense), when the differential equation method (such as finite element method, finite difference method, finite volume method, etc.) is used for forward modeling, a large complex sparse matrix equation group will be formed. The sparse matrix equation group is usually solved by an iterative method, and SPMV (sparse matrix vector multiplication) is required in the iterative solution. The core of this solution is a solution to improve the storage format to accelerate SPMV, which is used for iterative solution of large complex sparse matrix equation groups in numerical simulation / emulation in the field of electromagnetic computing. This solution is applicable to Feiteng NEON (i.e., the NEON instruction set of the ARM architecture) or other similar instruction sets for SIMD (such as the MSA instruction set of MIPS and the AVX / SSE / MMX instruction set of the Intel X86 architecture, etc.). This embodiment is introduced using the solution applicable to Feiteng NEON as an example and should not be regarded as a limitation of this application.

[0036] See also Figure 3 , Figure 3 The flowchart of the data processing method for accelerating the calculation of large complex sparse matrices by improving CSR provided by the embodiment of the present application. The data processing method for accelerating the calculation of large complex sparse matrices by improving CSR may include step S10, step S20, step S30 and step S40.

[0037] First, the computer device may execute step S10.

[0038] Step S10: numerically simulate / emulate the physical model to be calculated by using the differential equation method to determine the complex sparse linear stiffness matrix, and convert the complex sparse linear stiffness matrix into four sub-matrices in the form of real matrices.

[0039] In this embodiment, the computer device can use the differential equation method to perform numerical simulation / emulation on the physical model to be calculated (such as various physical models such as earth medium, aircraft, and ship), and determine the complex sparse linear stiffness matrix. The non-zero element distribution of the complex sparse linear stiffness matrix is ​​as follows: Figure 4 shown.

[0040] Since the complex sparse linear stiffness matrix satisfies:

[0041] Kx=b, (1)

[0042]

[0043] Among them, K is the complex sparse linear stiffness matrix, x is the unknown vector, b is the right-hand vector, K r and K i is the real part and imaginary part of K, b r and b i is the real and imaginary part of b, x r and x i are the real and imaginary parts of x.

[0044] Therefore, the complex sparse linear stiffness matrix can be converted into four sub-matrices in the form of real matrices. Then, K r , -K i , -K i , -K r Corresponding to four sub-matrices in the form of real matrices, they are recorded as the first sub-matrix, the second sub-matrix, the third sub-matrix, and the fourth sub-matrix. The first sub-matrix, the second sub-matrix, the third sub-matrix, and the fourth sub-matrix are distributed from left to right and from top to bottom to form a real composite matrix. The non-zero element distribution of the real composite matrix (i.e., the real complex sparse linear stiffness matrix converted from the complex sparse linear stiffness matrix) is as follows Figure 5 shown.

[0045] Based on this, the computer device may execute step S20.

[0046] Step S20: storing the real number composite matrix formed by the four sub-matrices in the form of real number matrices in the CSR storage format.

[0047] In this embodiment, the computer device can store the real number composite matrix formed by four sub-matrices in the form of real number matrices in the CSR storage format. Since almost all traditional solutions support converting sparse matrices into the CSR storage format, this solution does not elaborate on this process.

[0048] After storing the real composite matrix formed by the four sub-matrices in the form of real matrices in the CSR storage format, a sparse matrix (ie, the real composite matrix) stored in the CSR storage format is obtained, which includes a values ​​group, a columns group, and a row-offsets group.

[0049] In order to adapt to the acceleration hardware of Feiteng Neon (or other similar instruction sets for SIMD, such as MSA instruction set of MIPS and AVX / SSE / MMX instruction set of IntelX86 architecture, etc.), this solution proposes a new CSR storage structure, namely Fill-CSR format. At this time, the computer device can run step S30.

[0050] Step S30: converting the CSR storage format into an improved Fill-CSR format, wherein when the Fill-CSR format stores matrix non-zero element values, each group of elements contains two values, and a group of elements contains 2, 1 or 0 matrix non-zero element values.

[0051] In this embodiment, the computer device may convert the CSR storage format into an improved Fill-CSR format.

[0052] Exemplarily, a computer device may perform an intra-row traversal of a values ​​group in a CSR storage format, and based on the adjacent relationship between the columns containing the non-zero element values ​​of two adjacent matrices in values ​​and the number of element groups formed after traversing the row, form a new-values ​​group in a Fill-CSR format, wherein the values ​​group corresponds to multiple rows of a real number composite matrix, and the intra-row traversal of the values ​​group in the CSR storage format is essentially an intra-row traversal of the non-zero element values ​​of the real number composite matrix row by row.

[0053] Three main rules are designed for the formation of new-values ​​groups: (1) If the current element and the next element are adjacent in column, they are stored in the new element with capacity position 2; (2) If the current element and the next element are not adjacent in column, the current element is placed in a new element and padded with zeros; (3) If the last element of the current row has been traversed and the number of new elements is odd, a new element [0, 0] needs to be added at the end to make it an even number.

[0054] Specifically, the computer device can traverse the values ​​group in the CSR storage format from left to right line by line:

[0055] If the column where the non-zero element values ​​of the current matrix are located is adjacent to the column where the non-zero element values ​​of the subsequent matrix are located, the non-zero element values ​​of the current matrix and the non-zero element values ​​of the subsequent matrix are combined into a group of elements for storage, completing the processing of the non-zero element values ​​of the current matrix and the non-zero element values ​​of the subsequent matrix, where each group of elements occupies 2 capacity bits in the values ​​group.

[0056] If the column where the non-zero element values ​​of the current matrix are located is not adjacent to the column where the non-zero element values ​​of the next matrix are located, the non-zero element values ​​of the current matrix are padded with zeros (this embodiment takes the method of padding with zeros at the end as an example, such as [1.5, 0], [4, 0], etc., but this is not a limitation of the present application. In other schemes, the method of padding with zeros at the beginning may also be adopted, such as [0, 1.5], [0, 4], etc., but in one scheme, a unified zero padding method is required) to form a group of elements composed of the non-zero element values ​​of the current matrix and a value of zero, thereby completing the processing of the non-zero element values ​​of the current matrix.

[0057] After completing the intra-row traversal of a row of the values ​​group in the CSR storage format: If the number of element groups formed by the current row is odd, the elements forming each group are stored in order, and a group of pure zero elements [0, 0] is added at the end. If the number of element groups formed by the current row is even, the elements forming each group are stored in order.

[0058] After completing the intra-row traversal of all rows of the values ​​group in the CSR storage format, each group of elements formed in each row is stored sequentially to form a new-values ​​group in the Fill-CSR format.

[0059] After obtaining the new-values ​​group in the Fill-CSR format, the computer device may update the columns group based on the new-values ​​group in the Fill-CSR format to form a new-columns group in the Fill-CSR format.

[0060] Specifically, the computer device may calculate the column coordinates using each group of elements in the new-values ​​group in the Fill-CSR format as a unit, update the columns group, and form a new-columns group in the Fill-CSR format.

[0061] Furthermore, the computer device may update the row-offsets group based on the new-values ​​group in the Fill-CSR format to form a new-row-offsets group in the Fill-CSR format.

[0062] Specifically, the computer device may calculate the row offset based on each group of elements in the new-values ​​group in the Fill-CSR format, update the row-offsets group, and form a new-row-offsets group in the Fill-CSR format.

[0063] Thus, we can obtain the new-values ​​group, new-columns group and new-row-offsets group, complete the improvement of the CSR storage format, and obtain the Fill-CSR format.

[0064] For ease of understanding, a 6*6 sparse matrix storage example is used as an example. Figure 6 As shown, Figure 6 is a sparse matrix, in which all non-zero values ​​are double type, converted to the traditional CSR storage format, such as Figure 7 shown.

[0065] To get the Fill_CSR format, such as Figure 6The two elements 2 and -1 in the first row of are padded with zeros to become [2,0] and [-1,0] respectively, so that they can participate in the calculation in one cycle. Figure 6 The second row of data converted to Fill_CSR format is [-1,2], [-1.5,0], because -1 and 2 are consecutive in memory and can be placed in the same register, so they can be used as a group of elements, and zero padding is performed after -1.5, so that three data can be calculated in one loop. Figure 6 The third row of data, converted to Fill_CSR format, is [-1,2], [-1.5,0], [-1.6,0], [0,0]. Two zero-filling methods are used here. [-1.5,0] and [-1.6,0] are the first zero-filling method, which allows non-continuously stored single elements to be stored in the vector register, and the group of pure zero elements [0,0] at the end is to align the data to adapt to the code structure of the 2-fold loop expansion. The update of column coordinates (new-columns group stores non-zero element numerical column coordinates) and row offsets (new-row-offsets group stores non-zero element numerical row offsets) will not be repeated here.

[0066] Based on this, Figure 7 and Figure 8 As shown, Figure 7 The traditional CSR format corresponding to the 6*6 sparse matrix storage example is shown. Figure 8 It is an improved FILL_CSR format. The Feiteng architecture has two floating-point multiplication units, and each vector register is 128 bits, which can store 2 double data. In order to give full play to the performance of the hardware, the new FILL_CSR format is filled with 0 to ensure the neatness of the data. Therefore, the FILL_CSR format is obviously more suitable for Figure 6 The sparse matrix format can achieve better acceleration effect.

[0067] Similarly, for the storage of the vector x (ie, x in y=Ax) inside the loop in fgmres, the same improved FILL_CSR storage mode is adopted (mainly referring to the element formation rules during intra-row traversal), which will not be repeated here.

[0068] After converting the CSR storage format into the FILL-CSR format, the computer device may execute step S40.

[0069] Step S40: Based on the data stored in the Fill-CSR format, SPMV optimization is implemented in the iterative solution to accelerate the solution calculation.

[0070] This embodiment uses Feiteng NEON for SPMV optimization as an example. SIMD (Single Instruction Multiple Data) is a technology that uses one controller to control multiple processors and simultaneously performs the same operation on each of a set of data (also known as "data vectors") to achieve spatial parallelism. Simply put, one instruction can process multiple data at the same time. This solution implements SPMV optimization in iterative solving based on the ARMv8 architecture of the Tianhe supercomputer. The ARMv8 architecture uses out-of-order emission instructions, in which there are two multipliers fmul that can be executed in parallel to a certain extent.

[0071] Then, the computer device can implement SPMV optimization in iterative solution based on the data stored in the Fill-CSR format to accelerate the solution calculation.

[0072] Exemplarily, aa_1 is defined as a double type array storing non-zero element values ​​of the sparse matrix, that is, the new-values ​​group in the Fill-CSR format, aj is defined as an int type array storing the column coordinates of the non-zero element values ​​of the sparse matrix, that is, the new-columns group in the Fill-CSR format, ii_ is defined as an int type array storing the coordinates of the first non-zero element value of each row of the sparse matrix in aa_1, that is, the new-row-offsets group in the Fill-CSR format, x is defined as the vector in the sparse matrix vector multiplication, and y is defined as the final result.

[0073] Traverse the data stored in Fill-CSR format row by row; assign the initial value of 0 to the vector register temp_y_1 and the vector register temp_y_2; traverse the data in the row, read the current 2 double type data from aa_1, that is, a group of elements, recorded as the current element, read the column coordinates corresponding to the current element from aj, and read the corresponding 2 double type data from vector x; and read the next 2 double type data from aa_1, that is, the next group of elements of the current element, and read the column coordinates corresponding to this group of elements from aj, and read the corresponding 2 double type data; perform corresponding multiplication and addition operations on the 2 double type data of the current element read from aa_1 and the corresponding 2 double type data read from vector x, and add them to vector register temp_y_1 to obtain 2 double type data; and perform corresponding multiplication and addition operations on the 2 double type data of the next group of elements read from aa_1 and the corresponding 2 double type data read from vector x, and add them to vector register temp_y_2 to obtain 2 double type data. Then add the two double type data in vector register temp_y_1 and the two double type data in vector register temp_y_2 to obtain the calculation results of the four double type data, and assign the calculation results to the final result y, until the data stored in the Fill-CSR format is traversed, thus reducing the number of memory accesses, increasing the amount of calculation for a single memory access, and improving the calculation memory access ratio, thereby improving performance.

[0074] The following is the Neon vectorization pseudo code for the ARMv8 architecture:

[0075] Input: aa_1: double type array storing non-zero element values ​​of sparse matrix

[0076] aj: an int type array storing the non-zero element numerical column coordinates of the sparse matrix

[0077] ii_: An int type array storing the coordinates of the first non-zero element value in each row of the sparse matrix in aa_1

[0078] x: vector in sparse matrix-vector multiplication

[0079] Output: y: final result

[0080]

[0081] Based on the Feiteng series CPU of the Tianhe supercomputer, the effects of the original CSR algorithm (adapted to the CSR storage format) and the Fill-CSR algorithm (i.e. the specific process of step S40 and the above code, adapted to the Fill-CSR format) are compared on the iterative solver FGMRES of the PETSC open source library.

[0082] In order to more intuitively see the gap between the original CSR algorithm and the Fill-CSR algorithm, Table 1 shows the comparison results of several sets of sparse matrix-vector multiplications with a matrix size of 49438*49438 and a number of non-zero elements of 753935. It can be seen that the Fill-CSR algorithm is 12% to 18% higher than the original CSR algorithm, with significant results.

[0083] Table 1. SPMV acceleration effect

[0084]

[0085] Table 2 shows the overall acceleration effect of sparse matrix-vector multiplication of two sizes, 49438*49438 and 1030208*1030208. It can also be seen that the Fill_CSR algorithm has a very significant improvement over the CSR algorithm, reaching about 7.5%:

[0086] Table 2. Overall acceleration effect

[0087] Matrix size Number of non-zero elements Storage Format Iterations Running time / s 49438*49438 753935 csr 1e4 114.6 49438*49438 753935 fill_csr 1e4 105.9 1030208*1030208 1597932 csr 1e4 244.2 1030208*1030208 1597932 fill_csr 1e4 224.4

[0088] An embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the data processing method of the present embodiment for accelerating the calculation of large complex sparse matrices of improved CSR.

[0089] An embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, characterized in that when the computer program is executed by a processor, the steps of the data processing method for accelerating calculation of large complex sparse matrices of improved CSR of the present embodiment are implemented.

[0090] Furthermore, an embodiment of the present application provides a computer program product, including a computer program, characterized in that when the computer program is executed by a processor, the steps of the data processing method for accelerating the calculation of large complex sparse matrices of the improved CSR of the present embodiment are implemented.

[0091] In summary, the embodiment of the present application provides a data processing method for accelerating the calculation of large complex sparse matrices with improved CSR, which is applied to the iterative solution of large complex sparse matrix equations in the field of electromagnetic computing, and is suitable for Feiteng NEON (i.e., the NEON instruction set of the ARM architecture) or other similar instruction sets for SIMD (such as the MSA instruction set of MIPS and the AVX / SSE / MMX instruction set of the IntelX86 architecture, etc.). The differential equation method (such as the finite element method, the finite difference method, the finite volume method, etc.) is used to perform numerical simulation / emulation on the model to be calculated, and the complex sparse linear stiffness matrix is ​​determined, and the complex sparse linear stiffness matrix is ​​converted into four sub-matrices in the form of real matrices. After the real matrix is ​​formed, it is stored in the CSR storage format, and then the CSR storage format is converted into the designed Fill-CSR format, so as to realize the SPMV optimization in the iterative solution and perform the accelerated solution calculation. The Fill-CSR format mainly traverses the values ​​group in the CSR storage format in the row, and determines whether to form a group of elements by merging (if adjacent, merge the two non-zero values ​​into a group of elements) or filling with zeros (if not adjacent, use a non-zero value plus a zero element to form a group of elements) based on the relationship between the non-zero values ​​of the two adjacent matrices stored in the CSR format in the columns in the large complex sparse matrix, and traverses the number of element groups formed in the row (determine whether to fill a group of pure zero elements based on whether the number of element groups is odd or even, to ensure that the number of element groups is even), and forms a new-values ​​group in the Fill-CSR format. Each group of elements in the new-values ​​group contains 2 numerical elements, which can make the non-continuously stored single non-zero value be stored in the vector register, make full use of the performance of the vectorized acceleration hardware, increase the amount of single memory access calculation, improve the calculation memory access ratio, and thus improve the overall running speed. The number of elements in the even group can align the data to adapt to the code structure of the 2x loop expansion, thereby achieving a better acceleration effect. In general, improving CSR's data processing method for accelerating the calculation of large complex sparse matrices can make full use of vectorized acceleration hardware, increase the amount of calculation in a single memory access, improve the calculation-to-memory ratio, and increase the SPMV calculation speed in iterative solutions to improve the overall calculation speed. This can effectively improve the efficiency of solving large complex sparse matrices in the field of electromagnetic computing.

[0092] Converting the CSR storage format to the improved Fill-CSR format is essentially a preprocessing process. Since SPMV will be used multiple times in the FGMRES iterative processing, the preprocessing overhead of converting to the Fill-CSR format can be amortized into multiple SPMV calculations and is almost negligible.

[0093] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.

[0094] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A data processing method for accelerating the calculation of large complex sparse matrices based on improved CSR, characterized in that: Iterative solution of large complex sparse matrix equations for electromagnetic computing, including: A differential equation method is used to perform numerical simulation / emulation on the physical model to be calculated, a complex sparse linear stiffness matrix is ​​determined, and the complex sparse linear stiffness matrix is ​​converted into four sub-matrices in the form of real matrices; The real matrix formed by the four real matrix sub-matrices is stored in CSR storage format; Convert the CSR storage format to the improved Fill-CSR format, wherein when the Fill-CSR format stores matrix non-zero element values, each group of elements contains two values, and a group of elements contains 2, 1 or 0 matrix non-zero element values; Based on the data stored in Fill-CSR format, SPMV optimization in iterative solution is realized to accelerate the solution calculation; Convert the complex sparse linear stiffness matrix into four sub-matrices in real matrix form, including: The complex sparse linear stiffness matrix satisfies: Kx=b, Among them, K is the complex sparse linear stiffness matrix, x is the unknown vector, b is the right-hand vector, K r and K i is the real part and imaginary part of K, b r and b i is the real and imaginary part of b, x r and x i is the real part and imaginary part of x; then, K r , -K i , -K i , -K r The four sub-matrices corresponding to the real number matrix form are recorded as the first sub-matrix, the second sub-matrix, the third sub-matrix, and the fourth sub-matrix. The first sub-matrix, the second sub-matrix, the third sub-matrix, and the fourth sub-matrix are distributed from left to right and from top to bottom to form a real number composite matrix; After storing the real matrix formed by the four sub-matrices in the form of real matrices in the CSR storage format, including the values ​​group, the columns group and the row-offsets group, the CSR storage format is converted into the designed Fill-CSR format, including: Perform an in-row traversal of the values ​​group in the CSR storage format, and form a new-values ​​group in the Fill-CSR format based on the adjacent relationship between the columns of the non-zero values ​​of the two adjacent matrices in values ​​and the number of element groups formed after traversing the row. The values ​​group corresponds to multiple rows of the real composite matrix, and the in-row traversal of the values ​​group in the CSR storage format is essentially to perform an in-row traversal of the non-zero values ​​of the real composite matrix row by row. Based on the new-values ​​group in the Fill-CSR format, update the columns group to form a new-columns group in the Fill-CSR format; Based on the new-values ​​group in the Fill-CSR format, the row-offsets group is updated to form a new-row-offsets group in the Fill-CSR format.

2. The data processing method for accelerating the calculation of large complex sparse matrices by improving CSR according to claim 1, characterized in that: Traverse the values ​​group in the CSR storage format in the row, and form a new-values ​​group in the Fill-CSR format based on the adjacent relationship between the columns of the non-zero element values ​​of the two adjacent matrices in values ​​and the number of element groups formed after traversing the row, including: Traverse the values ​​group in the CSR storage format from left to right line by line: If the column where the current matrix non-zero element value is located is adjacent to the column where the next matrix non-zero element value is located, the current matrix non-zero element value and the next matrix non-zero element value are combined into a group of elements for storage, and the processing of the current matrix non-zero element value and the next matrix non-zero element value is completed, wherein each group of elements occupies 2 capacity bits in the values ​​group; If the column where the non-zero element value of the current matrix is ​​located is not adjacent to the column where the non-zero element value of the next matrix is ​​located, the non-zero element value of the current matrix is ​​padded with zero to form a group of elements composed of the non-zero element value of the current matrix and a value of zero, thereby completing the processing of the non-zero element value of the current matrix; After completing the inline traversal of a row of the values ​​group in the CSR storage format: If the number of element groups formed by the current row is an odd number, the elements forming each group are stored in order, and a group of pure zero elements [0, 0] is added at the end; if the number of element groups formed by the current row is an even number, the elements forming each group are stored in order; After completing the intra-row traversal of all rows of the values ​​group in the CSR storage format, each group of elements formed in each row is stored sequentially to form a new-values ​​group in the Fill-CSR format.

3. The data processing method for accelerating the calculation of large complex sparse matrices by improving CSR according to claim 2, characterized in that: Based on the new-values ​​group in the Fill-CSR format, update the columns group to form a new-columns group in the Fill-CSR format, including: Calculate the column coordinates based on each element in the new-values ​​group in the Fill-CSR format, update the columns group, and form the new-columns group in the Fill-CSR format.

4. The data processing method for accelerating the calculation of large complex sparse matrices by improving CSR according to claim 2, characterized in that: Based on the new-values ​​group in the Fill-CSR format, the row-offsets group is updated to form a new-row-offsets group in the Fill-CSR format, including: The row offset is calculated based on each element in the new-values ​​group in the Fill-CSR format, and the row-offsets group is updated to form a new-row-offsets group in the Fill-CSR format.

5. The data processing method for accelerating the calculation of large complex sparse matrices by improving CSR according to claim 2, characterized in that: Based on the data stored in Fill-CSR format, SPMV optimization in iterative solution is implemented to accelerate solution calculation, including: Define aa_1 as a double type array storing non-zero element values ​​of the sparse matrix, that is, the new-values ​​group in the Fill-CSR format, define aj as an int type array storing the column coordinates of the non-zero element values ​​of the sparse matrix, that is, the new-columns group in the Fill-CSR format, define ii_ as an int type array storing the coordinates of the first non-zero element value of each row of the sparse matrix in aa_1, that is, the new-row-offsets group in the Fill-CSR format, define x as the vector in the sparse matrix vector multiplication, and define y as the final result; Traverse the data stored in Fill-CSR format line by line; Assign the initial value of vector register temp_y_1 and vector register temp_y_2 to 0; Traverse the data in the row, read the current two double type data from aa_1, that is, a group of elements, recorded as the current element, read the column coordinates corresponding to the current element from aj, and read the corresponding two double type data from the vector x; And, read the next two double data from aa_1, that is, the next group of elements after the current element, and read the column coordinates corresponding to this group of elements from aj, and read the corresponding two double data from vector x; Perform multiplication and addition operations on the two double data of the current element read from aa_1 and the corresponding two double data read from vector x, and add them to the vector register temp_y_1 to obtain two double data. Perform multiplication and addition operations on the two double data of the next group of elements read from aa_1 and the corresponding two double data read from vector x, and add them to the vector register temp_y_2 to obtain two double data. Add the two double data in the vector register temp_y_1 and the two double data in the vector register temp_y_2 to obtain the calculation results of the four double data, and assign the calculation results to the final result y until all the data stored in the Fill-CSR format are traversed.

6. A computer device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the data processing method for accelerating the calculation of large complex sparse matrices for improving CSR according to any one of claims 1 to 5.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the data processing method for accelerating the calculation of large complex sparse matrices for improving CSR described in any one of claims 1 to 5 are implemented.

8. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the data processing method for accelerating the calculation of large complex sparse matrices for improving CSR described in any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Sparse matrix storage method CSRL (Compressed Sparse Row with Local Information) and SpMV (Sparse Matrix Vector Multiplication) realization method based on same

    CN103336758A

  • SpMV implementation method and system based on many-core processor in BCSR storage format

    CN114780239A