Sparse matrix multiplication design of adaptive row merging and partitioning strategy

Through the adaptive row merging and dividing strategy and the improved CSR storage format, the problem of computational load imbalance in sparse matrix multiplication is solved, the performance of sparse dense matrix multiplication on the GPU is improved, and more efficient memory access and thread utilization are achieved. .

CN118708329APending Publication Date: 2024-09-27SOUTHWEAT UNIV OF SCI & TECH
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202410473777.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-17
Publication Date
2024-09-27

AI Technical Summary

Technical Problem

The existing sparse matrix multiplication algorithm cannot fully utilize the computing resources and memory resources of the GPU when processing large-scale sparse matrices, resulting in an imbalance between computing load and thread mapping, which affects the performance of GNN.

Method used

Adopting an adaptive row merging and dividing strategy, by rearranging the sparse matrix, short rows are merged, long rows are balanced and divided, and an improved CSR storage format is used to transfer the processed matrix to the GPU shared memory to be multiplied with the dense matrix , optimize thread utilization and memory access efficiency.

Benefits of technology

It improves the parallel efficiency on the GPU, reduces the number of idle threads in the thread group, increases instruction-level parallelism, solves the problem of load imbalance, and improves the computing performance of sparse and dense matrix multiplication.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118708329A
    Figure CN118708329A
Patent Text Reader

Abstract

The invention discloses a sparse matrix multiplication design of a self-adaptive row merging and dividing strategy, and the method comprises the following steps: carrying out the rearrangement according to the number of non-zero elements in each row of a sparse matrix, and determining a short row; determining a middle row and a long row; the short rows are combined in pairs in a self-adaptive mode, the long rows are divided in a balanced mode, and the middle rows are kept unchanged; storing the matrix after the adaptive strategy by using the improved CSR; transmitting the'new line 'to a shared GPU memory; and multiplying a new line in the memory of the shared GPU by corresponding elements of the dense matrix to obtain a result. The invention aims to provide a sparse matrix multiplication design of a self-adaptive row merging and partitioning strategy aiming at the problem of load imbalance among parallel threads in sparse matrix multiplication operation in a GNN framework, an SpMM operation algorithm is calculated through a self-adaptive row partitioning and merging mechanism, calculated graph data is loaded into a GPU shared memory, and the GPU shared memory is used for storing the graph data. The problem of GPU on-chip load imbalance is solved, and then the performance of GNN operation is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention mainly relates to the application field of graph neural networks in deep learning, and in particular to a sparse matrix multiplication design with an adaptive row merging and partitioning strategy. Background Art

[0002] In recent years, research on graph neural networks (GNNs) has made significant progress in many areas, including the processing of sparse matrices. Sparse matrices are an important concept in GNNs, especially when dealing with large-scale graph data. A sparse matrix is ​​a matrix in which most elements are zero or have default values. In GNNs, due to the characteristics of graphs, such as the connections between nodes are usually relatively sparse, the adjacency matrix of the graph is often sparse. The calculation of sparsity is achieved by counting the number of zero elements in the matrix and calculating its ratio to the total number of elements in the matrix.

[0003] For GNN, the key to processing sparse matrices is how to effectively utilize the sparsity of matrices to optimize computation and storage. Traditional dense matrix operation methods may waste a lot of computing resources and memory space when processing sparse matrices. Therefore, researchers have proposed a variety of optimization techniques for sparse matrices to improve the performance and efficiency of GNN. SpMM, in the field of deep learning and computer science, usually refers to sparse matrix multiplication. Sparse matrix multiplication is an important problem in computer science and numerical computing, especially when dealing with large-scale data and machine learning applications. The SpMM algorithm aims to improve the efficiency of sparse matrix multiplication by reducing unnecessary calculations and only processing non-zero elements, thereby optimizing the use of computing resources.

[0004] With the rapid development of big data and artificial intelligence, the application demand of sparse matrix multiplication in many fields is growing. Therefore, the research and optimization of SpMM algorithms has become an important research direction. At present, many researchers are committed to proposing more efficient SpMM algorithms to cope with the computational challenges of large-scale sparse matrices. These algorithms usually combine hardware characteristics, parallel computing and optimization techniques to improve computing speed and efficiency. Currently, many independent SpMM computing studies have achieved better performance than cuSPARSE (NVIDIA's official math library), but they are not applicable to the mainstream GNN computing framework. Huang proposed GE-SpMM based on GPU hardware. Based on the row splitting algorithm, it optimized the reuse of sparse row data through shared memory, improved the parallel performance of SpMM by reducing memory transactions, and achieved effective acceleration performance after GE-SpMM replaced cuSPARSE API in the GNN framework. TLPGNN divides GNN computing into two levels and adopts a hybrid dynamic workload distribution method to solve the problem of workload imbalance.

[0005] Although the above work has made some progress in the research of SpMM algorithm, it still cannot make good use of GPU computing resources and memory resources when processing various sparse matrices. The main reason is that the current SpMM row partitioning scheme does not consider adaptability, the mapping between computing load and thread is not reasonable, and there is a lack of a complete adaptive framework. Summary of the invention

[0006] The purpose of the present invention is to address the problem of unbalanced load between parallel threads of sparse and dense matrix multiplication operations in the GNN framework, propose a sparse matrix multiplication design with an adaptive row merging and partitioning strategy, perform calculations through the SpMM operation algorithm with an adaptive row merging and partitioning mechanism, and load the calculated graph data into the GPU shared memory to improve the load imbalance problem on the GPU chip, thereby improving the performance of GNN operations.

[0007] The present invention is implemented in such a way that a sparse matrix multiplication design of an adaptive row merging and partitioning strategy comprises the following steps: Step 1: Rearrange the sparse matrix according to the number of non-zero elements in each row to determine the short rows; Step 2: Determine the middle and long lines; Step 3: Adaptively merge short lines in pairs, divide long lines evenly, and keep the middle lines unchanged; Step 4: Use the improved CSR to store the matrix after the adaptive strategy; Step 5: Transfer the "new row" to the shared GPU memory; Step 6: Multiply the "new row" in the shared GPU memory with the corresponding element of the dense matrix to get the result.

[0008] Furthermore, the step 1 rearranges the sparse matrix to determine the short rows that affect thread utilization. The specific steps are as follows:

[0009] Step 1: According to the size of the thread group in the GPU, the rows that are less than or equal to half the size of a thread group are placed in the front column of the matrix;

[0010] Step 2: Identify the rows in the front column of the matrix (rows less than or equal to half the size of a thread group) as short rows, and use these short rows as candidates for subsequent operations.

[0011] Furthermore, the step 2 determines the middle row and the long row that causes the thread group load to be unbalanced, and the specific steps are as follows:

[0012] Step 1: According to the size of the thread group in the GPU, the rows larger than the size of one thread group are identified as long rows, and these long rows are used as candidates for subsequent operations;

[0013] Step 2: All rows except short rows and long rows are called middle rows.

[0014] Furthermore, in step 3, by analyzing the rearranged sparse matrix, since the short rows are located in the front column of the matrix after rearrangement, the short rows are processed first, and then the medium rows and long rows are processed. The specific steps are as follows:

[0015] Step 1: When processing short lines, merge two adjacent lines into a "new line" and use the "new line" as the parallel granularity. Each "new line" is processed by one thread group.

[0016] Step 2: When processing the middle bank, since the middle bank does not need to be divided and merged, it only needs to use the "new row" as the parallel granularity, and each "new row" is processed by one thread group;

[0017] Step 3: When processing a long line, determine the New_length of the "new line" after the long line is divided according to Formula 1, and divide the long line into "new lines" in a balanced manner. Use the "new line" as the parallel granularity, and each "new line" is processed by a thread group.

[0018] Furthermore, the step 4 uses an improved CSR format to store the merged and divided sparse matrix, and the specific steps are as follows: the storage format uses "new row" as the basic unit, and the improved CSR format is divided into four parts: (1) Row_Ind: records the index of the row before rearrangement; (2) New_Ptr: records the number of non-zero elements in the first i rows of the rearranged matrix; (3) Col_Ind: records the vertical coordinates of all non-zero elements of the rearranged matrix; (4) Value: records the values ​​of all non-zero elements of the rearranged matrix.

[0019] Furthermore, step five is a transfer stage, in which the "new row" is copied from the original location to the newly allocated GPU memory according to the improved CSR format.

[0020] Further, the step six is ​​the calculation stage, and the specific steps are as follows:

[0021] Step 1: multiply the non-zero elements with the elements at the corresponding positions in the dense matrix, and store the product results in the corresponding positions of the result matrix;

[0022] Step 2: After the calculation is completed, the calculation results in each thread group are accumulated to the corresponding position in the global memory, and the results in the global memory are returned to the host side for subsequent processing or output.

[0023] The adaptive row merging and splitting strategy of the present invention has the following significant advantages: (1) The present invention uses "new lines" instead of short lines, medium lines and long lines as the parallel granularity, and controls the size of the "new lines" within a certain range according to hardware resources. This not only ensures that the on-chip memory has sufficient space to ensure data reuse, reduces the number of idle threads in the thread group and the divergence of threads, but also improves the load imbalance problem on the GPU chip, thereby improving the parallel efficiency. (2) The present invention obtains "new rows" with an adaptive row merging and splitting strategy. Short row merging, this step reduces the use of one warp, thereby greatly improving thread utilization and increasing more instruction-level parallelism (ILP) during calculations. Long row splitting, this step eliminates the load imbalance caused by the huge difference between rows in the past. The non-zero elements come from the same row of the sparse matrix, which can ensure the merged memory access to the dense matrix, thereby improving memory access efficiency. (3) The present invention does not require complicated preprocessing, is applicable to different types of matrices, and is universal. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] Figure 1 It is a flow chart of the adaptive row merging and partitioning strategy based on GPU accelerated sparse-dense matrix multiplication of the present invention;

[0025] Figure 2 is an example of a sparse matrix storage format provided by an embodiment of the present invention;

[0026] Figure 3 This is an example of a GPU-based sparse-dense matrix multiplication kernel architecture provided by an embodiment of the present invention;

[0027] Figure 4 This is an example of the effect of using an adaptive row merging and splitting strategy provided by an embodiment of the present invention;

[0028] Figure 5 It is a specific formula of the adaptive long row partitioning strategy in the sparse matrix of the present invention;

[0029] Figure 6 It is a strategy for adaptive row merging and partitioning in the sparse matrix of the present invention. DETAILED DESCRIPTION

[0030] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0031] Figure 1 The process of the adaptive row merging and partitioning strategy for the sparse-dense matrix multiplication in the accelerated graph neural network of the present invention is shown. As shown in the figure, the present invention is implemented in this way. An adaptive row merging and partitioning strategy includes the following steps: S101: Rearrange the sparse matrix according to the number of non-zero elements in each row to determine the short row; S102: Determine the middle line and the long line; S103: Adaptively merge short lines in pairs, divide long lines evenly, and keep the middle lines unchanged; S104: using the improved CSR to store the matrix after the adaptive strategy; S105: transferring the “new row” to the shared GPU memory; S106: Multiply the “new row” in the shared GPU memory by the corresponding element of the dense matrix to obtain a result.

[0032] Furthermore, the step 1 rearranges the sparse matrix to determine the short rows that affect thread utilization. The specific steps are as follows:

[0033] Step 1: According to the size of the thread group in the GPU, the rows that are less than or equal to half the size of a thread group are placed in the front column of the matrix;

[0034] Step 2: Identify the rows in the front column of the matrix (rows less than or equal to half the size of a thread group) as short rows, and use these short rows as candidates for subsequent operations.

[0035] Furthermore, the step 2 determines the middle row and the long row that causes the thread group load to be unbalanced, and the specific steps are as follows:

[0036] Step 1: According to the size of the thread group in the GPU, the rows larger than the size of one thread group are identified as long rows, and these long rows are used as candidates for subsequent operations;

[0037] Step 2: All rows except short rows and long rows are called middle rows.

[0038] Furthermore, in step 3, by analyzing the rearranged sparse matrix, since the short rows are located in the front column of the matrix after rearrangement, the short rows are processed first, and then the medium rows and long rows are processed. The specific steps are as follows:

[0039] Step 1: When processing short lines, merge two adjacent lines into a "new line" and use the "new line" as the parallel granularity. Each "new line" is processed by one thread group.

[0040] Step 2: When processing the middle bank, since the middle bank does not need to be divided and merged, it only needs to use the "new row" as the parallel granularity, and each "new row" is processed by one thread group;

[0041] Step 3: When processing a long line, determine the New_length of the "new line" after the long line is divided according to Formula 1, and divide the long line into "new lines" in a balanced manner. Use the "new line" as the parallel granularity, and each "new line" is processed by a thread group.

[0042] Furthermore, the step 4 uses an improved CSR format to store the merged and divided sparse matrix, and the specific steps are as follows: the storage format uses "new row" as the basic unit, and the improved CSR format is divided into four parts: (1) Row_Ind: records the index of the row before rearrangement; (2) New_Ptr: records the number of non-zero elements in the first i rows of the rearranged matrix; (3) Col_Ind: records the vertical coordinates of all non-zero elements of the rearranged matrix; (4) Value: records the values ​​of all non-zero elements of the rearranged matrix.

[0043] Furthermore, step five is a transfer stage, in which the "new row" is copied from the original location to the newly allocated GPU memory according to the improved CSR format.

[0044] Further, the step six is ​​the calculation stage, and the specific steps are as follows:

[0045] Step 1: multiply the non-zero elements with the elements at the corresponding positions in the dense matrix, and store the product results in the corresponding positions of the result matrix;

[0046] Step 2: After the calculation is completed, the calculation results in each thread group are accumulated to the corresponding position in the global memory, and the results in the global memory are returned to the host side for subsequent processing or output. Example:

[0047] The SNAP dataset is a sparse matrix test benchmark. The SNAP dataset contains 66 sparse matrices. The sparse matrices in the SNAP dataset are formed by valid graphs in many fields, which usually require sparse dense matrix operations in real life. The total number of rows of these 66 sparse matrices is 1005-4847571, and the average number of non-zero elements per row is 1.58-32.53. This dataset was also used for performance testing of previous GPU-accelerated sparse dense matrix operation kernel designs, so this dataset can effectively verify the performance improvement brought by our proposed method. All sparse matrices are calculated with dense matrices with 32, 64, 128, and 256 columns respectively to further illustrate the effectiveness of our method. The steps of the adaptive row partitioning and merging method based on GPU-accelerated sparse dense matrix multiplication implemented on the SNAP dataset are as follows:

[0048] Step 1: Rearrange the sparse matrix according to the number of non-zero elements in each row to determine the short rows; According to the number of threads in the GPU thread group, the rows with less than or equal to half the thread group size are placed in the front column of the matrix, and the rows with non-zero elements less than or equal to half the GPU thread group size are considered short rows. Figure 2 In the "rearrangement" part, assuming that the size of the GPU thread group is 4, put the rows with non-zero elements less than or equal to 2 in the front column of the matrix; Figure 3 In the left part, the number of non-zero elements in the zeroth row and the first row after rearrangement is less than or equal to 2. We consider these two rows to be short rows and need to merge them two by two.

[0049] Step 2: Determine the middle and long lines; According to the number of threads in the thread group of the GPU, the rows larger than the size of a thread group are identified as long rows, and the rows other than short rows and long rows are collectively referred to as medium rows. Figure 3 In the left part, the number of non-zero elements in the second row after rearrangement is greater than 4. We determine that this row is a long row and needs to be divided evenly. Except for the zeroth, first, and second rows, the third row is left, which is a middle row.

[0050] Step 3: Adaptively merge short lines in pairs, divide long lines evenly, and keep the middle lines unchanged; For short lines, we merge every two lines into a "new line", and one "new line" is processed by one thread group. Since the middle line does not need to be processed, we only need to use the "new line" as the parallel granularity for the middle line; for long lines, we divide the long line into "new lines" according to formula 1, and the size of each "new line" is less than or equal to the size of the thread group. Figure 3 In the middle part, the zeroth and first rows are short rows, so we merge them into a "new row"; the second row is a long row, so we divide it into two "new rows" in a balanced way; the third row is a medium row, so we use the "new row" as the parallel granularity.

[0051] Step 4: Use the improved CSR to store the matrix after the adaptive strategy; After the matrix is ​​merged and divided, the “new row” replaces the short row, medium row and long row as the basic unit. The improved CSR format is divided into four parts: (1) Row_Ind: records the index of the row before rearrangement; (2) New_Ptr: records the number of non-zero elements in the first i rows of the rearranged matrix; (3) Col_Ind: records the vertical coordinates of all non-zero elements of the rearranged matrix; (4) Value: records the values ​​of all non-zero elements of the rearranged matrix.

[0052] Step 5: Transfer the "new row" to the shared GPU memory; Copies the "new row" from the original location to the newly allocated GPU memory in modified CSR format.

[0053] Step 6: Multiply the "new row" in the shared GPU memory with the corresponding element of the dense matrix to get the result. Multiply the non-zero elements with the elements at the corresponding positions in the dense matrix, and store the product results in the corresponding positions of the result matrix; after the calculation is completed, accumulate the calculation results in each thread group to the corresponding positions in the global memory, and return the results in the global memory to the host side for subsequent processing or output.

[0054] The above adaptive row merging and partitioning sparse matrix operations are executed on the GPU as follows: Figure 4 As shown. Since this method adaptively uses "new rows" instead of short rows, medium rows and long rows as the parallel granularity, and the size of the "new rows" is controlled within a reasonable range to ensure that the thread group has enough threads to parallelize all non-zero element tasks. For short rows, the algorithm assigns more non-zero elements to a warp, thereby reducing the number of idle threads and thread divergence in a warp, while increasing more instruction-level parallelism (ILP) when consuming data. For long rows, the algorithm avoids the problem of requiring multiple iterations to process all non-zero element tasks when there are too many non-zero elements, as well as the problem of load imbalance between thread groups. Figure 4 A more reasonable allocation of computing tasks and computing resources is achieved, thereby achieving an acceleration effect that is more in line with the characteristics of the GPU architecture and can be efficiently parallelized.

[0055] Although the above describes the specific implementation mode of the present invention in conjunction with the accompanying drawings, it is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art on the basis of the technical solution of the present invention without creative labor are still within the scope of protection of the present invention.

Claims

1. A sparse matrix multiplication design with an adaptive row merging and partitioning strategy, characterized in that: The sparse matrix multiplication design of the adaptive row merging and partitioning strategy includes the following steps: Step 1: Rearrange the sparse matrix according to the number of non-zero elements in each row to determine the short rows; Step 2: Determine the middle and long lines; Step 3: Adaptively merge short lines in pairs, divide long lines evenly, and keep the middle lines unchanged; Step 4: Use the improved CSR to store the matrix after the adaptive strategy; Step 5: Transfer the "new row" to the shared GPU memory; Step 6: Multiply the "new row" in the shared GPU memory with the corresponding element of the dense matrix to obtain the result.

2. The sparse matrix multiplication design of the adaptive row merging and splitting strategy as claimed in claim 1, characterized in that: The step 1 re-arranges the sparse matrix to determine the short rows that affect thread utilization. The specific steps are as follows: Step 1: According to the size of the thread block in the GPU, the rows that are less than or equal to half the size of a thread block are placed in the front column of the matrix; Step 2: Identify the rows in the front column of the matrix (rows less than or equal to half the size of a thread block) as short rows, and use these short rows as candidates for subsequent operations.

3. The sparse matrix multiplication design of the adaptive row merging and splitting strategy as claimed in claim 1, characterized in that: The step 2 determines the middle row and the long row that causes the thread block load to be unbalanced, and the specific steps are as follows: Step 1: According to the size of the thread block in the GPU, the rows larger than the size of a thread block are identified as long rows, and these long rows are used as candidates for subsequent operations; Step 2: All rows except short rows and long rows are called middle rows.

4. The sparse matrix multiplication design of the adaptive row merging and splitting strategy as claimed in claim 1, characterized in that: The step 3 analyzes the rearranged sparse matrix. Since the short rows are located at the front column of the matrix after rearrangement, the short rows are processed first, and then the medium and long rows are processed. The specific steps are as follows: Step 1: When processing short lines, merge two adjacent lines into a "new line" and use the "new line" as the parallel granularity. Each "new line" is processed by one thread block. Step 2: When processing the middle row, since the middle row does not need to be divided and merged, it is only necessary to use the "new row" as the parallel granularity of the middle row, and each "new row" is processed by one thread block; Step 3: When processing a long line, determine the New_length of the "new line" after the long line is divided according to Formula 1, and divide the long line into "new lines" in a balanced manner. Use the "new line" as the parallel granularity, and each "new line" is processed by a thread block.

5. The sparse matrix multiplication design of the adaptive row merging and partitioning strategy as claimed in claim 1, characterized in that: The step 4 uses the improved CSR format to store the merged and divided sparse matrix. The specific steps are as follows: The storage format uses "new row" as the basic unit. The improved CSR format is divided into four parts: (1) Row_Ind: records the index of the row before rearrangement; (2) New_Ptr: records the number of non-zero elements in the first i rows of the rearranged matrix; (3) Col_Ind: records the ordinates of all non-zero elements in the rearranged matrix; (4)Value: records the values ​​of all non-zero elements of the rearranged matrix.

6. The sparse matrix multiplication design of the adaptive row merging and partitioning strategy as claimed in claim 1, characterized in that: The step five is the transfer stage, which copies the "new row" from the original location to the newly allocated GPU memory according to the improved CSR format.

7. The sparse matrix multiplication design of the adaptive row merging and partitioning strategy as claimed in claim 1, characterized in that: The step six is ​​the calculation stage, and the specific steps are as follows: Step 1: multiply the non-zero elements with the elements at the corresponding positions in the dense matrix, and store the product results in the corresponding positions of the result matrix; Step 2: After the calculation is completed, the calculation results in each thread block are accumulated to the corresponding position in the global memory, and the results in the global memory are returned to the host side for subsequent processing or output.

Citation Information

Cited By

  • GPU resource aware matrix multiplication parallel performance analysis model construction method

    CN120429216A

  • Data structure optimization method, cardiac electrophysiology simulation method, device, equipment and medium

    CN120708921A

  • Parallel adaptive matrix lossless compression method

    CN120825184A

  • Matrix data processing method, processor and computer device

    WO2026091597A1