A data storage format for banded sparse matrices and its multiplication acceleration method
By proposing the data storage format BRCV and multiplication acceleration method of strip sparse matrix, the storage redundancy and performance loss problems of sparse matrix multiplication algorithm during calculation on GPU in the prior art are solved, and more efficient storage and computing performance is achieved.
Patent Information
- Application Number
- CN202210931011.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-29
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2042-07-29
AI Technical Summary
When existing sparse matrix multiplication algorithms are calculated on GPU, especially the striped sparse matrix storage format, there are problems of storage redundancy and performance losses.
A data storage format BRCV of a strip-shaped sparse matrix is proposed. The height of the sparse band, the first row non-zero element, the total number of non-zero elements, the column subscript of the first row non-zero element and the non-zero element value are used to reduce redundant storage, and parallel calculations are used to accelerate multiplication operations.
It effectively reduces the storage complexity of sparse matrices and improves computing efficiency. Especially in the strip structure, the consumption of global memory data transmission is reduced by the multiplexing of dense matrix rows.
Smart Images

Figure CN115309333B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to an implementation method for improving banded sparse matrix multiplication, belongs to the field of matrix data storage format and high-performance multiplication calculation, and is particularly suitable for a banded sparse matrix data storage format and a multiplication acceleration method thereof. Background Art
[0002] A sparse matrix is a matrix whose elements are mostly zero, while the proportion of non-zero elements is very small, often less than 1% of the total. Sparse matrix multiplication is widely used in large-scale scientific computing, deep learning, graph analysis, and economic modeling. The sparse matrix multiplication problem in the field of deep learning is usually expressed as sparse-dense matrix multiplication (SpMM), which is generally expressed as a process of finding a matrix C of size m*n given a sparse matrix A of size m*k and a dense matrix B of size k*n. In the specific context of deep learning, efficient sparsity multiplication has become one of the main methods to improve training and inference performance and reduce model size while maintaining accuracy. In particular, in graph neural networks (GNNs), the structure of the input graph is represented as an adjacency matrix or adjacency list, which is usually sparse. As the main operation in GNNs, SpMM is a time-consuming step even on parallel hardware such as GPUs. In order to achieve high performance in training and inference of GNN applications, it is of great significance to accelerate the SpMM algorithm.
[0003] In order to save storage space and reduce the number of matrix multiplications, sparse matrices are usually stored in a compressed manner, that is, only the non-zero elements in the matrix are stored. This efficient storage method can improve the overall performance of matrix multiplication. The most commonly used storage format is the CSR method, see reference [1]. Assume that the size of the sparse matrix A is m*k, and the number of non-zero elements is nnz. The CSR format compresses the non-zero elements by row, and three arrays are required to represent the matrix A:
[0004] val[nnz]: stores the value of each non-zero element;
[0005] colInd[nnz]: stores the column index of each non-zero element;
[0006] rowPtr[m+1]: stores the starting offset position of the first non-zero element in each row at val and colInd, that is, the total number of non-zero elements before the row, so the last element represents the total number of non-zero elements in the matrix, nnz.
[0007] The core code for SpMM implementation based on CSR format is as follows:
[0008]
[0009]
[0010] With the development of technology, the existing sparse matrix multiplication based on GPU has mainly adopted the block technology to improve the sparse matrix storage format, which aggregates the data into dense blocks and then performs calculations. At present, the common sparse matrix block storage format for general-purpose processors is the BCSR format proposed by Vuduc in 2005. The BCSR format is an extension of CSR. Its storage method is to divide the sparse matrix as a whole into blocks of fixed size. The size of each block can be set to r*c, so the sparse matrix is divided into rows. The blocks are stored in the same way as CSR, and the overall storage method is roughly the same as CSR, where: Indicates rounding up. BCSR has the advantage of data continuity over CSR, and the fixed-size blocks improve the efficiency of parallel optimization, which is conducive to the realization of load balancing. However, BCSR regards each block as a dense matrix and stores it as a dense matrix during the storage process, so it will explicitly introduce zero elements, especially when the non-zero elements are more dispersed in the sparse matrix, which brings storage cost and performance loss. In addition, BCSR has the following restrictions when storing non-zero element sub-blocks: ① The row and column values of the index coordinates must be multiples of the row and column sizes of the block size, otherwise the entire column or row needs to be filled with zero elements; ② Since the entire matrix uses a single block size, the small dense blocks of the original matrix must be filled with more zero elements to maintain the structure of the separated blocks.
[0011] [1] M.Naumov, L.Chien, P.Vandermersch, and U.Kapasi: Cusparselibrary.2010.
[0012] [2] Huang, G., et al., GE-SpMM: General-purpose Sparse Matrix-MatrixMultiplication on GPUs for Graph Neural Networks. 2020.
[0013] [3] URL: https: / / docs.nvidia.com / cuda / cusparse Summary of the invention
[0014] There is a common type of sparse matrix with a local characteristic structure: a banded sparse matrix, that is, in a sparse matrix, there are several sparse bands, such as Figure 1In view of this, the present invention improves the sparse matrix storage format CSR according to the properties of the banded sparse matrix, and proposes a banded sparse matrix data storage format (band sparse matrix format): BRCV, which aims to reduce the redundant storage space to a certain extent, and at the same time, compared with the CSR format, realizes the efficient calculation of the banded sparse matrix SpMM algorithm on the GPU.
[0015] In order to achieve the above object, the present invention provides the following technical solutions:
[0016] A data storage format for a banded sparse matrix, characterized in that it consists of five arrays: b, rc, rv, c, v. For a sparse band containing p {D 1 , …, D p} is an m*k dimensional banded sparse matrix A, b is the accumulated value of the height of the sparse band, rc is the accumulated value of the number of non-zero elements in the first row of the sparse band, rv is the accumulated value of the total number of all non-zero elements in the sparse band, c is the column subscript of the non-zero elements in the first row of each sparse band, and v is the value of each non-zero element in the banded sparse matrix A; the sparse band is a number of consecutive rows in the matrix with the same number of non-zero elements and corresponding column subscripts.
[0017] Furthermore, the storage format is selected by comparing the number p of sparse bands and the dimension m of the sparse matrix A in advance, and when p < (2m-1) / 4, a banded sparse matrix data storage format is used for processing, otherwise, the CSR format is used for processing.
[0018] The method for storing data in a banded sparse matrix A is characterized by comprising the following steps:
[0019] S31: traverse the banded sparse matrix A and identify p sparse bands {D 1 , …, D p}, in D 1 Insert an empty sparse band D before 0 , and its array sparse band {D 0 , D 1 , …, D p};
[0020] S32: Traverse the sparse band of the array and convert D 0 To D i The heights are accumulated to obtain the values of b[i] respectively; and then the p+1-dimensional array b={b[i]|0≤i≤p} is obtained;
[0021] S33: Traverse the sparse band of the array and convert D 0 To D iThe non-zero numbers of the first row are accumulated to obtain the values of rc[i] respectively; and then the p+1-dimensional array rc={rc[i]|0≤i≤p} is obtained;
[0022] S34: Traverse the first p array sparse bands and convert the sparse band D 0 To D i Accumulate the total number of non-zero elements in all rows to obtain the value of rv[i], and then obtain a p-dimensional array rv={rv[i]|0≤i≤p-1};
[0023] S35: Traverse the sparse bands of the banded sparse matrix A {D 1 , …, D p}, extract the column subscripts of all non-zero elements in the first row of each sparse band in turn, and store them in array c in order;
[0024] S36: traverse the banded sparse matrix A, record the value v[i] of each non-zero element, and obtain an array v={v[i]|1≤i≤nnz}, where nnz is the total number of non-zero elements in the banded sparse matrix;
[0025] S37: Pack the five arrays b, rc, rv, c, and v as the data storage format of the banded sparse matrix A.
[0026] For multiplication C=A*B, where B is a k*n dimensional dense matrix, a multiplication acceleration method applied to a data storage format of a banded sparse matrix A is characterized by comprising the following steps:
[0027] S41: From the first sparse band D of the banded sparse matrix A 1 First, calculate the i-th sparse band D according to array b i The corresponding height h i = b[i]-b[i-1];
[0028] S42: Calculate the i-th sparse band D according to the array rc i The corresponding number of non-zero elements in each row is T = rc[i]-rc[i-1];
[0029] S43: Traverse the i-th sparse band D i , for the T non-zero elements in each row, obtain the value of each non-zero element according to the array v, and calculate its column subscript col according to the array c, thereby obtaining the value of the element on the col-th row corresponding to the matrix B multiplied by the non-zero element;
[0030] S44: Sparse band D i The corresponding row non-zero element is multiplied by the value of the column element on the col row corresponding to the matrix B, and the resulting products are accumulated to obtain D iThe product of each row in and B;
[0031] S45: Repeat steps S41 to S44 to traverse all sparse bands {D 1 , …, D p}, and then get the sparse band D 1 , …, D p The product of A and B is accumulated to get the value of matrix C.
[0032] A multiplication acceleration method for a banded sparse matrix data storage format applied to matrix multiplication C=A*B. The specific algorithm is as follows:
[0033]
[0034]
[0035] From the perspective of storage complexity, the storage space of the CSR format is related to the row size m of the sparse matrix and the total number of non-zero elements nnz of the entire matrix. For matrices with band sparsity, the CSR format needs to store the column subscript of each non-zero element. However, the column subscripts of non-zero elements between rows in a band are the same, which will cause redundant storage; and the data storage format of a banded sparse matrix provided by the present invention only needs to store the column subscripts of the first row for non-zero elements in the same band, thereby reducing the storage space of the column subscripts, especially for the case where the band height is high, thereby reducing the storage complexity of the sparse matrix. Specifically, for a sparse matrix with a banded structure, if the number of non-zero elements in each row is nz, the storage complexity of the CSR format is: 2nnz+m+1=2m*nz+m+1(1); the storage complexity of the data storage format of a banded sparse matrix of the present invention is: (p+1)+(p+1)+p+p*nz+m*nz=m*nz+p*nz+3p+2(2). Obviously, by taking the difference, (1)-(2)=(mp)*nz+m-3p-1(3). From formula (3), we can see that when p≤m and nz is large, the storage complexity of CSR format is higher than that of BRCV format. On the other hand, assuming nz=1, formula (3) can be simplified to 2m-4p-1. It can be concluded that when p is much smaller than m, the storage complexity required by CSR format is also higher than that of BRCV format.
[0036] Furthermore, the sparse band D i The multiplication calculations of the corresponding row non-zero elements and the values of the column elements on the col row corresponding to the matrix B are independent of each other and can be accelerated by parallel computing. At the same time, the products of all sparse bands in the banded sparse matrix A and B are independent of each other in the process and can also be accelerated by parallel computing.
[0037] Furthermore, due to the sparse band {D 1 , …, D p The column subscripts of each row in} are the same, and the i-th sparse band D can be determined by accessing the rc array i The column subscript of each non-zero element in , thereby determining the calculation of D i The row information of the dense matrix B required for the multiplication of all consecutive rows is read once, thereby realizing the reuse of the same rows of the matrix B in steps S43 to S45 to improve the calculation efficiency.
[0038] The beneficial effects of the present invention are as follows: the present invention provides a data storage format of a banded sparse matrix and a multiplication acceleration method thereof, and utilizes the special structure of the sparse band of the matrix to provide a data storage format of a banded sparse matrix, which is an efficient compressed storage format; at the same time, based on the data storage format, the present invention provides a multiplication acceleration method of the data storage format of a banded sparse matrix, thereby realizing the reuse of the rows of the dense matrix, reducing the consumption of global memory data transmission, and improving the computing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to make the purpose and technical solution of the present invention, the present invention provides the following drawings for explanation:
[0040] Figure 1 It is a schematic diagram of a banded sparse matrix, where the black part is the sparse band and the blank part is 0;
[0041] Figure 2 is an example of a banded sparse matrix A according to Embodiment 1 of the present invention;
[0042] Figure 3 A data storage format flow chart of a banded sparse matrix according to the present invention;
[0043] Figure 4 A flow chart of a multiplication acceleration method for a banded sparse matrix data storage format according to the present invention;
[0044] Figure 5 This is an example of BCSR partitioning of the banded sparse matrix A in Embodiment 1 of the present invention;
[0045] Figure 6 A large-scale banded sparse matrix format diagram in Embodiment 2 of the present invention;
[0046] Figure 7 This is a performance comparison experiment result diagram under the NVIDIA GPU RTX2060 environment in Example 2 of the present invention, where the matrix dimension is m=k=n=1024; wherein the number of non-zero elements in each row of the sparse matrix is 2 i (32≤2 i ≤512);
[0047] Figure 8 This is a performance comparison experiment result diagram under the NVIDIA GPU RTX2060 environment in Example 2 of the present invention, where the matrix dimension is m=k=n=2048; wherein the number of non-zero elements in each row of the sparse matrix is 2 i (32≤2 i ≤1024);
[0048] Fig. 9 This is a performance comparison experiment result diagram under the NVIDIA GPURTX3080 environment in Example 2 of the present invention, where the matrix dimension is m=k=n=1024; wherein the number of non-zero elements in each row of the sparse matrix is 2 i (32≤2 i ≤512);
[0049] Fig.10 This is a performance comparison experiment result diagram under the NVIDIA GPU RTX3080 environment in Example 2 of the present invention, where the matrix dimension is m=k=n=2048; wherein the number of non-zero elements in each row of the sparse matrix is 2 i (32≤2 i ≤1024). DETAILED DESCRIPTION
[0050] In order to make the technical solution, purpose of the embodiment and advantages of the system architecture of the present invention clearer, the following will be combined with the attached Figure 2 and attached Figure 4 , the preferred embodiments of the present invention are described in detail.
[0051] Example 1: For example Figure 2 The 7*7 dimensional banded sparse matrix A shown in the figure, and for the multiplication C=A*B, where B is a 7*n dimensional dense matrix, in order to improve the storage efficiency and the computational efficiency of other matrix multiplications, the present invention provides "a data storage format of a banded sparse matrix and a multiplication acceleration method thereof", combined with Figure 3 , the specific steps are:
[0052] Step 1: Traverse the banded sparse matrix A and identify two sparse bands {D 1 , D 2}, in D 1 Insert an empty sparse band D before 0 , and its array sparse band {D 0 , D 1 , D 2};
[0053] Step 2: Traverse the sparse band of the array and convert D 0 To D 0 , D 0 To D1 , D 0 To D 2 The heights are accumulated to obtain the values of b[0], b[1] and b[2] respectively, and then the array b = [0, 4, 7] is obtained;
[0054] Step 3: Traverse the sparse band of the array and convert D 0 To D 0 , D 0 To D 1 , D 0 To D 2 The non-zero numbers in the first row of are accumulated to obtain the values of rc[0], rc[1], and rc[2], and then the array rc = [0, 3, 5] is obtained;
[0055] Step 4: Traverse the first two array sparse bands and convert the sparse band D 0 To D 0 and D 0 To D 1 The total number of non-zero elements in all rows is accumulated to obtain the values of rv[0] and rv[1] respectively, and then the array rv=[0,12] is obtained;
[0056] Step 5: Traverse the sparse bands of the banded sparse matrix {D 1 , D 2}, extract the column subscripts of all non-zero elements in the first row of each sparse band in turn, and store them in array c in order, thereby obtaining array c = [1, 5, 6, 2, 4];
[0057] Step 6: Traverse the banded sparse matrix A, record the value of each non-zero element, and obtain the array v = [2, 7, 3, 3, 2, 8, 2, 2, 1, 4, 1, 4, 1, 3, 5, 1, 2, 2].
[0058] Step 7: Pack the five arrays b, rc, rv, c, and v as the data storage format of the banded sparse matrix A in this embodiment.
[0059] In order to better demonstrate the advantages of the method of the present invention, this embodiment 1 also provides the corresponding storage representations of the CSR format and the BCSR format.
[0060] Combination Figure 2When the banded sparse matrix A is stored in the CSR data format, combined with the relevant introduction of the background technology, the CSR data storage format is expressed as: rowPtr[8]=[0,3,6,9,12,14,16,18]; colInd
[18] =[1,5,6,1,5,6,1,5,6,1,5,6,2,4,2,4,2,4,2,4]; val
[18] =[2,7,3,3,2,8,2,2,1,4,1,4,1,3,5,1,2,2].
[0061] Furthermore, when the banded sparse matrix A adopts the BCSR data storage format, its partitioning method is as follows: Figure 5 As shown, the BCSR data storage format can be expressed as: rowPtr[5] = [0, 3, 6, 8, 10]; colInd
[10] = [0, 2, 3, 0, 2, 3, 1, 2, 1, 2]; val
[40] = [0, 2, 0, 3, 0, 7, 0, 2, 3, 0, 8, 0, 0, 2, 0, 4, 0, 2, 0, 1, 1, 0, 4, 0, 1, 0, 5, 0, 3, 0, 1, 0, 2, 0, 0, 0, 2, 0, 0, 0].
[0062] It can be seen that the CSR format requires a total of 44 data type spaces to store array information, the BCSR format requires a total of 55 data type spaces to store array information, and the data storage format of the banded sparse matrix provided by the present invention only requires 31 data type spaces to store array information. Therefore, it is better to use a data storage format of a banded sparse matrix of the method of the present invention for processing, satisfying p=2<(2*7-1) / 4.
[0063] Further, combined with Figure 4 , a sparse-dense matrix multiplication (C=A*B) with a banded sparse matrix data storage format is used, and the specific implementation steps are as follows:
[0064] Step (1): When calculating the jth column of matrix C, the first sparse band D of the banded sparse matrix A is used. 1 First, calculate D based on array b 1 The corresponding height h 1 =b[1]-b[0]=4, that is, D 1 There are 4 rows; according to the array rc, calculate D 1 The number of non-zero elements in each row is T 1 =rc[1]-rc[0]=3;
[0065] Step (2): Traverse the sparse band D 1 , calculate D based on array c and array rc 1 The column subscript of the first non-zero element in the first row: col 1=c[0+rc[0]]=1; Calculate the column subscript of the second non-zero element: col 2 =c[1+rc[0]]=5; Calculate the column subscript of the third non-zero element: col 3 = r[2+rc[0]] = 6, thus obtaining the col of the matrix B multiplied by these non-zero elements respectively. i The value of the row element;
[0066] Step (3): Traverse the sparse band D 1 For each row of the first row, the intermediate result result is initialized first, according to the array rc and T 1 The value of R is used to calculate the total number of non-zero elements in all rows before this row: 1 =rv[0]+0*T 1 = 0. Set the first non-zero element v in the first row of the banded sparse matrix A to 1 =v[R 1 +0]=2 and B[col 1 ][j], and the product is accumulated to result; the second non-zero element v 2 =v[R 1 +1]=7 and B[col 2 ][j] and add the result to result; add the third non-zero element v 3 =v[R 1 +2]=3 and B[col 3 ][j], and the result is added to result, and finally C[0][j] = result is obtained; for D 1 The calculation of the second, third, and fourth rows is similar, and the values of C[1][j], C[2][j], and C[3][j] can be obtained.
[0067] Step (4): Repeat steps (1) to (3) to traverse the remaining sparse bands D of the banded sparse matrix A. 2 , calculate D based on array b 2 The corresponding height h 2 =b[2]-b[1]=3, that is, D 2 There are 3 rows; according to the array rc, calculate D 2 The number of non-zero elements in each row is T 2 =rc[1]-rc[0]=3;
[0068] Step (5): Traverse the sparse band D 2 , calculate D based on array c and array rc 2 The column subscript of the first non-zero element in the first row: col 1 =c[0+rc[1]]=2; Calculate the column subscript of the second non-zero element: col 2=c[1+rc[1]]=4;
[0069] Step (6): Traverse the sparse band D 2 For each row of A, for the first row (i.e. the fifth row of A), first initialize the intermediate result result, according to the array rc and T 2 The value of R is used to calculate the total number of non-zero elements in all rows before this row: 2 =rv[0]+0*T 2 = 12. Replace the first non-zero element v in the fifth row of the banded sparse matrix A 1 =v[R 2 +0]=2 and B[col 1 ][j], and the product is accumulated to result; the second non-zero element v 2 =v[R 2 +1]=7 and B[col 2 ][j], and the result is added to result, and finally C[4][j] = result is obtained; for D 21 The calculation of the second and third rows is similar to that of , and the values of C[5][j] and C[6][j] can be obtained.
[0070] Step (7): j starts from 0 and loops through each column until n-1 to obtain the value of matrix C.
[0071] Example 2: In order to better demonstrate the advantages of the method of the present invention, for large-scale banded sparse matrices, this implementation intends to use banded sparse matrices A of different dimensions (m=k=n=1024, m=k=n=2048) to calculate matrix multiplication C=A*B, where the banded sparse matrix A is calculated according to Figure 6 The format shown is randomly generated. At the same time, considering the influence of sparsity, 2 random numbers are generated in each row of the banded sparse matrix A. 5 ~2 10 non-zero elements, and B is a randomly generated dense matrix. The floating point computing capability comparison test is now conducted on a GPU using the method of the present invention and the prior art method. The prior art methods include: (i) SpMM algorithm based on CSR format, which can be found in reference [2]. This method has good performance in the experimental results ( Figure 7 to Figure 10 ) is denoted as CSR; (ii) the SpMM algorithm implemented by the cuSPARSE library provided by NVIDIA, which can be found in reference [3]. This method is shown in the experimental results ( Figure 7 to Figure 10 ) is denoted as cuSPARSE.
[0072] Combination Figure 6 Since p=m / 16<(2m-1) / 4 is satisfied, it can be predicted that a data storage format of a band sparse matrix using the method of the present invention is better for processing.
[0073] After program code implementation, a floating point computing capability comparison experiment of three multiplication methods (including the method of the present invention) on GPU was completed. The experimental results are as follows: Figure 7 to Figure 10 As shown. The floating point computing capability represents the number of floating point operations to be performed per unit time. It can be seen that the floating point computing capability of the method of the present invention in each dimension is superior to that of the prior art method.
[0074] Next, the advantages of the multiplication acceleration method using a banded sparse matrix data storage format in the method of the present invention are further described from the perspective of GPU implementation.
[0075] In this embodiment, the matrix C is divided into sub-blocks of size 16×32. Similarly, the thread block size is set to 16×32, and one thread block is responsible for one sub-block of C, and one thread is responsible for calculating one element of C. That is, each thread block is responsible for a sub-block of a banded sparse matrix A of size 16×k and a sub-block of a dense matrix B of size k×32. For a sub-block A stored in CSR format, two two-dimensional shared memory spaces of size 16×32 are set to cyclically read the non-zero element values and column indexes of the sub-block A respectively, so as to reduce the time consumption of reading data from the global memory; and for the A matrix stored in the data storage format of the banded sparse matrix, in the calculation of a block of C, since all rows in the banded sparse matrix A sub-block to be read have the same column subscript, compared with the algorithm in CSR format, the method of the present invention can set another shared memory space of size 32×32 to store a sub-block of the dense matrix B that needs to be calculated each time, thereby realizing the row reuse of the dense matrix B.
[0076] Finally, it should be noted that the above preferred embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail through the above preferred embodiments, those skilled in the art should understand that various changes can be made in form and details without departing from the scope defined by the claims of the present invention.
Claims
1. A data storage format for a banded sparse matrix, characterized in that: It consists of five arrays: b, rc, rv, c, v; for p sparse bands {D1,…,D p }, b is the accumulated value of the height of the sparse band, rc is the accumulated value of the number of non-zero elements in the first row of the sparse band, rv is the accumulated value of the total number of all non-zero elements in the sparse band, c is the column subscript of the non-zero elements in the first row of each sparse band, and v is the value of each non-zero element in the band sparse matrix A; the sparse band is a number of rows in the matrix where the number of non-zero elements and the corresponding column subscripts are the same; The storage format is selected by comparing the number of sparse bands p and the dimension m of the sparse matrix A in advance. When p<(2m-1) / 4, a banded sparse matrix data storage format is used for processing, otherwise, the CSR format is used for processing; The data storage format of a banded sparse matrix comprises the following steps: S31: Traverse the banded sparse matrix A and identify p sparse bands {D1,…,D p }, insert an empty sparse band D0 before D1, and form an array sparse band {D0, D1, ..., D p }; S32: Traverse the sparse band of the array and convert D0 to D i The heights are accumulated to obtain the values of b[i] respectively; and then the p+1-dimensional array b={b[i]|0≤i≤p} is obtained; S33: Traverse the sparse band of the array and convert D0 to D i The non-zero numbers of the first row are accumulated to obtain the values of rc[i] respectively; and then the p+1-dimensional array rc={rc[r]|0≤i≤p} is obtained; S34: Traverse the first p array sparse bands and convert the sparse bands D0 to D i Accumulate the total number of non-zero elements in all rows to obtain the value of rv[i], and then obtain a p-dimensional array rv={rv[i]|0≤i≤p-1}; S35: Traverse the sparse bands {D1,…,D p }, extract the column subscripts of all non-zero elements in the first row of each sparse band in turn, and store them in array c in order; S36: traverse the banded sparse matrix A, record the value v[i] of each non-zero element, and obtain an array v={v[i]|1≤i≤nnz}, where nnz is the total number of non-zero elements in the banded sparse matrix; S37: Pack the five arrays b, rc, rv, c, and v as the data storage format of the banded sparse matrix A.
2. A multiplication acceleration method for a data storage format of a banded sparse matrix as claimed in claim 1, for multiplication C=A*B, wherein: B is a k*n dimensional dense matrix, characterized by comprising the following steps: S41: Starting from the first sparse band D1 of the banded sparse matrix A, calculate the i-th sparse band D according to array b. i The corresponding height h i = b[i]-b[i-1]; S42: Calculate the i-th sparse band D according to the array rc i The corresponding number of non-zero elements in each row is T = rc[i]-rc[i-1]; S43: Traverse the i-th sparse band D i , for the T non-zero elements in each row, obtain the value of each non-zero element according to the array v, and calculate its column subscript col according to the array c, thereby obtaining the value of the element on the col-th row corresponding to the matrix B multiplied by the non-zero element; S44: Sparse band D i The corresponding row non-zero element is multiplied by the value of the column element on the col row corresponding to the matrix B, and the resulting products are accumulated to obtain D i The product of each row in and B; S45: Repeat steps S41 to S44 to traverse all sparse bands {D1,…,D p }, and then get the sparse band D1,…,D p The product of A and B is accumulated to get the value of matrix C.
3. The multiplication acceleration method of a banded sparse matrix data storage format according to claim 2, characterized in that: The sparse band D described in step S44 i The multiplication calculations of the corresponding row non-zero elements and the values of the column elements on the col-th row corresponding to the matrix B are independent of each other and can be accelerated by parallel computing.
4. The multiplication acceleration method of a banded sparse matrix data storage format according to claim 2, characterized in that: The process of traversing the multiplication of all sparse bands in the band-shaped sparse matrix A and B described in step S45 is independent of each other and can be accelerated by parallel computing.
5. The multiplication acceleration method of a banded sparse matrix data storage format according to claim 2, characterized in that: In the steps S43 to S45, the i-th sparse band D can be determined by accessing the rc array. i The column subscript of each non-zero element in , thereby determining the calculation of D i The row information of the dense matrix B required for the multiplication of all consecutive rows is read at one time, thereby realizing row reuse of the same matrix B to improve computational efficiency.
Citation Information
Patent Citations
Radar target constant false alarm detection method based on sparse signal processing
CN111796253A
Sparse matrix storage method for Sunway many-core architecture
CN112540718A