Data processing method, system and equipment for sparse matrix multiplication and storage medium
By selecting a hybrid accumulator based on the number of non-zero elements and a preset strategy in sparse matrix multiplication, and utilizing the ordered nature of the matrix structure for accumulation and summation, the problems of redundant computation and inefficient memory access in existing technologies are solved, and efficient sparse matrix multiplication operations are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-26
- Publication Date
- 2026-04-03
AI Technical Summary
Existing accumulation strategies for sparse matrix multiplication fail to fully utilize the ordered nature of the matrix structure, resulting in redundant computations and inefficient memory access, making it difficult to achieve optimal performance under various sparse matrix structures.
The target accumulator is determined based on the number of non-zero elements in the sparse matrix and a preset selection strategy. A hybrid accumulator set (including merge, dense and hash accumulators) is used to perform efficient accumulation and summation by taking advantage of the ordered nature of the matrix structure and allocate precise memory space.
It achieves low sorting overhead, high accumulation efficiency, and reasonable memory allocation, significantly improving the performance of sparse matrix multiplication.
Smart Images

Figure CN121786313A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of high-performance computing, and in particular to a data processing method, system, device and storage medium for sparse matrix multiplication. Background Technology
[0002] Sparse general matrix-matrix multiplication (SpGEMM) is a core computational task in many scientific and engineering computing applications, such as graph neural networks (GNNs), large-scale graph analysis, and finite element analysis. The performance bottleneck of SpGEMM lies primarily in its "accumulation" step: when calculating a row of the output matrix, a large number of intermediate calculation results (i.e., intermediate product terms) that need to be merged are generated. How to efficiently collect and merge these intermediate product terms with the same column index is the key to determining the performance of the SpGEMM algorithm.
[0003] To reduce the storage overhead of sparse matrices, the industry commonly uses Compressed Sparse Row (CSR) or Compressed Sparse Column (CSC) formats to store sparse matrices. In the standard CSR / CSC storage format, the column / row indices of the non-zero elements in each row / column of the input matrix are inherently ordered. However, existing technologies fail to fully utilize this ordering, leading to a large amount of redundant computation (such as repeated sorting) or inefficient memory access.
[0004] Existing accumulation strategies suffer from the following problems: Collection-then-sorting strategies, such as the Expand-Sort-Compress (ESC) method, store all intermediate results in a buffer and perform global sorting after computation. While simple, this method fails to utilize the ordered nature of the matrix structure, incurring huge sorting overhead, and its performance degrades sharply as the number of intermediate product terms increases. Real-time order-preserving strategies, such as heap-based algorithms, maintain data order during insertion, avoiding final sorting. While theoretically optimal, these methods suffer from extremely low cache hit rates on modern processors due to irregular memory access patterns (pointer chasing), resulting in poor practical performance. Fixed accumulation strategies, with their "one-size-fits-all" approach, cannot adapt to the diversity of matrix structures. Real-world sparse matrix structures vary greatly; some conform to power-law distributions, while others have locally dense regions. One row of the output matrix may be very sparse, while another may be very dense; no single fixed accumulation strategy can perform optimally in all cases.
[0005] Therefore, how to provide a sparse matrix multiplication data processing method and system with high accumulation efficiency, reasonable memory allocation, and the ability to adjust the accumulation strategy according to the matrix structure is a technical problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0006] To address the aforementioned technical problems, the present invention aims to provide a data processing method for sparse matrix multiplication. This application first performs simulated matrix multiplication based on a first target accumulator to determine the number of non-zero elements in the corresponding output unit of the output matrix, thereby accurately allocating memory space for the output matrix. Then, based on the number of non-zero elements in the corresponding output unit of the output matrix and intermediate calculation results, a second target accumulator is refined to obtain the output matrix. The accumulator in this application includes a merge accumulator that can utilize the ordered nature of the matrix structure for summation, thus achieving low sorting overhead, high accumulation efficiency, and reasonable memory allocation, thereby improving the computational performance of sparse matrix multiplication.
[0007] The purpose of this invention is to provide a data processing method for sparse matrix multiplication; The technical solution provided by this invention is as follows: A data processing method for sparse matrix multiplication includes the following steps: The first target accumulator is determined based on the number of non-zero elements of the processing unit in the first sparse matrix, the number of non-zero elements of the corresponding processing unit in the second sparse matrix, and the first preset selection strategy, wherein the first sparse matrix and the second sparse matrix are sparse matrices with intrinsically ordered values. The first target accumulator is used to perform simulated matrix multiplication on the non-zero elements in the processing unit of the first sparse matrix and the non-zero elements in the corresponding processing unit of the second sparse matrix to obtain the number of non-zero elements in the corresponding output unit of the output matrix. The second target accumulator is determined based on the number of non-zero elements in the processing unit of the first sparse matrix, the number of non-zero elements in the corresponding output unit of the output matrix, and the second preset selection strategy; the first target accumulator and the second target accumulator are a set of mixed accumulators that include at least a merge accumulator. The corresponding output unit of the output matrix is obtained by summing the products of the non-zero elements in the processing unit of the first sparse matrix and the non-zero elements in the corresponding processing unit of the second sparse matrix using the second target accumulator.
[0008] Preferably, the processing unit and the output unit include a single row, a single column, multiple rows, or multiple columns; The determination of the first target accumulator based on the number of non-zero elements of the processing unit in the first sparse matrix, the number of non-zero elements of the corresponding processing unit in the second sparse matrix, and the first preset selection strategy includes the following steps: The product of the number of non-zero elements in the processing unit of the first sparse matrix and the number of non-zero elements in the corresponding processing unit of the second sparse matrix is determined based on the number of non-zero elements in the current row of the first sparse matrix. Obtain the number of columns in the second sparse matrix; The first target accumulator is determined based on the number of products, the number of columns in the second sparse matrix, and the first preset selection strategy.
[0009] Preferably, the first target accumulator and the second target accumulator further include: a dense accumulator and a hash accumulator; The first target accumulator is determined based on the number of products, the number of columns in the second sparse matrix, and the first preset accumulator selection strategy, including the following steps: The ratio of the number of products to the number of columns in the second sparse matrix is used to obtain the estimated density; When the estimated density is greater than the first threshold, the first target accumulator is determined to be the dense accumulator. When the number of non-zero elements in the current row of the first sparse matrix is greater than the second threshold, and the number of products is greater than the third threshold, the first target accumulator is determined to be the hash accumulator; Otherwise, the first target accumulator is determined to be the merge accumulator.
[0010] Preferably, determining the second target accumulator based on the number of non-zero elements in the processing unit of the first sparse matrix, the number of non-zero elements in the corresponding output unit of the output matrix, and the second preset selection strategy includes the following steps: The actual density is obtained by calculating the ratio of the number of non-zero elements in the corresponding output unit of the output matrix to the number of columns in the second sparse matrix; When the actual density is greater than the first threshold, the second target accumulator is determined to be the dense accumulator. When the number of non-zero elements in the current row of the first sparse matrix is greater than the second threshold, and the number of products is greater than the third threshold, and the number of products is greater than the fourth threshold, the second target accumulator is determined to be the hash accumulator. Otherwise, the second target accumulator is determined to be the merge accumulator.
[0011] Preferably, when performing accumulation and summation based on the merge accumulator, the following steps are included: The product is stored as multiple ordered linked lists; The multiple ordered linked lists are merged in pairs in multiple rounds until they are merged into a single ordered linked list.
[0012] Preferably, the pairwise merging process, which stitches two input linked lists into one output linked list by directly manipulating pointers of linked list nodes, includes the following steps: Compare the column indices of nodes in two linked lists; When the column numbers of the two linked list nodes are different, the linked list node with the smaller column number is linked to the end of the output linked list; When the column numbers of the two linked list nodes are the same, the values of the two linked list nodes are added together and the result is stored in one of the linked list nodes. This linked list node is then linked to the end of the output linked list, while the other linked list node that has not been stored is discarded.
[0013] Preferably, after performing simulated matrix multiplication on the number of non-zero elements in the processing unit of the first sparse matrix and the number of non-zero elements in the corresponding processing unit of the second sparse matrix using the first target accumulator to obtain the number of non-zero elements in the corresponding output unit of the output matrix, the method further includes: Memory space is allocated to the output matrix based on the number of non-zero elements in the corresponding output unit of the output matrix; After summing the products of the number of non-zero elements in the processing unit of the first sparse matrix and the number of non-zero elements in the corresponding processing unit of the second sparse matrix using the second target accumulator to obtain the corresponding output unit of the output matrix, the method further includes: The corresponding output units of the output matrix are stored in the memory space.
[0014] The second objective of this invention is to provide a data processing system for sparse matrix multiplication; The technical solution provided by this invention is as follows: A data processing system for sparse matrix multiplication includes: The first selection module is used to determine the first target accumulator based on the number of non-zero elements of the processing unit in the first sparse matrix, the number of non-zero elements of the corresponding processing unit in the second sparse matrix, and the first preset selection strategy, wherein the first sparse matrix and the second sparse matrix are sparse matrices with intrinsically ordered values. The simulation calculation module is used to perform simulated matrix multiplication on the non-zero elements in the processing unit of the first sparse matrix and the non-zero elements in the corresponding processing unit of the second sparse matrix using the first target accumulator, so as to obtain the number of non-zero elements in the corresponding output unit of the output matrix. The second selection module is used to determine a second target accumulator based on the number of non-zero elements in the processing unit of the first sparse matrix, the number of non-zero elements in the corresponding output unit of the output matrix, and a second preset selection strategy, wherein the first target accumulator and the second target accumulator are a set of mixed accumulators that include at least a merge accumulator. The actual calculation module uses the second target accumulator to accumulate and sum the products of the non-zero elements in the processing unit of the first sparse matrix and the non-zero elements in the corresponding processing unit of the second sparse matrix to obtain the corresponding output unit of the output matrix.
[0015] The third objective of this invention is to provide a computer device; The technical solution provided by this invention is as follows: A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the steps of any one of the data processing methods for sparse matrix multiplication.
[0016] A fourth objective of this invention is to provide a computer-readable storage medium; The technical solution provided by this invention is as follows: A computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of any of the data processing methods for sparse matrix multiplication described above.
[0017] This invention provides a data processing method for sparse matrix multiplication, comprising the following steps: determining a first target accumulator based on the number of non-zero elements in the processing units of a first sparse matrix, the number of non-zero elements in the corresponding processing units of a second sparse matrix, and a first preset selection strategy; performing simulated matrix multiplication based on the first target accumulator to obtain the number of non-zero elements in the corresponding output units of the output matrix; determining a second target accumulator based on the number of non-zero elements in the processing units of the first sparse matrix, the number of non-zero elements in the corresponding output units of the output matrix, and a second preset selection strategy; the target accumulator is a set of mixed accumulators including at least a merge accumulator; and summing the products of the non-zero elements in the processing units of the first sparse matrix and the non-zero elements in the corresponding processing units of the second sparse matrix using the second target accumulator to obtain the corresponding output units of the output matrix. This application first performs simulated matrix multiplication based on the first target accumulator to determine the number of non-zero elements in the corresponding output unit of the output matrix, thereby accurately allocating memory space for the output matrix. Then, based on the number of non-zero elements in the corresponding output unit of the output matrix, the second target accumulator is determined in a more refined manner to obtain the output matrix. The accumulator of this application includes a merge accumulator that can use the ordered nature of the matrix structure for summation, thereby achieving the effects of low sorting overhead, high accumulation efficiency, and reasonable memory allocation, thus significantly improving the computational performance of sparse matrix multiplication.
[0018] The present invention also provides a data processing system for sparse matrix multiplication. Since this system and the data processing method for sparse matrix multiplication solve the same technical problem and belong to the same technical concept, they should have the same beneficial effects, and will not be described in detail here. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a flowchart of a data processing method for sparse matrix multiplication in an embodiment of the present invention; Figure 2 This is a schematic diagram of the summation process of the merge accumulator in an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of a data processing system for sparse matrix multiplication according to an embodiment of the present invention; Figure 4 This is an internal structural diagram of a computer device according to an embodiment of the present invention. Detailed Implementation
[0021] To enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this application will be clearly and completely described below. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0022] like Figure 1 As shown, this embodiment of the invention provides a data processing method for sparse matrix multiplication, including the following steps: S1. Determine the first target accumulator based on the number of non-zero elements of the processing unit in the first sparse matrix, the number of non-zero elements of the corresponding processing unit in the second sparse matrix, and the first preset selection strategy, wherein the first sparse matrix and the second sparse matrix are sparse matrices with intrinsically ordered values. It should be noted that the first and second sparse matrices can be sparse matrices in CSR or CSC format. The CSR format includes three one-dimensional arrays to represent a sparse matrix: a value array (stores all non-zero element values in row-major order); a column indices array (stores the column indices corresponding to each non-zero element, in ordered order); and a row pointer array (rowPtr[]) with a length of (number of rows + 1). rowPtr[i] represents the starting index of the first non-zero element in the i-th row within the value array and column indices array, and rowPtr[i+1] - rowPtr[i] is the number of non-zero elements in the i-th row.
[0023] As one implementation, the first target accumulator includes: a merge accumulator, a dense accumulator, and a hash accumulator.
[0024] Preferably, the processing unit includes a single row, a single column, multiple rows, or multiple columns; As one implementation method, step S1 includes the following steps: A1. Determine the product of the number of non-zero elements in the processing unit of the first sparse matrix and the number of non-zero elements in the corresponding processing unit of the second sparse matrix based on the number of non-zero elements in the current row of the first sparse matrix. As one implementation method, steps S1-S4 are based on row-matrix multiplication. The following example uses the row-matrix SpGEMM computation paradigm to calculate sparse matrix multiplication. , where A, B, and C are all sparse matrices in CSR format.
[0025] Calculate the output matrix of each row of the output matrix C independently. . The calculation formula is:
[0026] in, It is the first sparse matrix A. Line 1 The non-zero elements of the column, It is the first sparse matrix B (the second sparse matrix). This calculation process will produce the number of non-zero elements in the i-th row of matrix A (denoted by nnz(A_i)) product terms. These product terms are then combined and summed to obtain the final product. Therefore, in step A1, the number of non-zero elements in the current row of the first sparse matrix can be used to determine the number of products. The product is the intermediate product term obtained when the current row of matrix A and the corresponding row of matrix B are multiplied.
[0027] A2. Obtain the number of columns in the second sparse matrix; A3. Determine the first target accumulator based on the number of products and the number of columns of the second sparse matrix and the first preset selection strategy.
[0028] Step A3 includes the following steps: A3.1 Calculate the ratio of the number of products to the number of columns in the second sparse matrix to obtain the estimated density; A3.2 When the estimated density is greater than the first threshold, the first target accumulator is determined to be a dense accumulator; A3.3 When the number of non-zero elements in the current row of the first sparse matrix is greater than the second threshold and the number of products is greater than the third threshold, the first target accumulator is determined to be a hash accumulator. A3.4 Otherwise, determine the first target accumulator as the merge accumulator.
[0029] It should be noted that the dense accumulator, implemented based on an array, is used to handle output rows with extremely dense computation results; the hash accumulator, implemented based on a hash table, is used to handle output rows with a huge number of intermediate product terms but a small number of final non-zero elements (i.e., high computational redundancy); and the merge accumulator, implemented based on an ordered linked list, is the default accumulator and is used to handle the summation of intermediate results with inherent order.
[0030] In practical applications, when the estimated density is greater than the first threshold, it indicates that the estimated output row density is very high. At this time, the overhead of creating a dense array of size B with the number of columns of the matrix and directly accumulating through index access (O(1) time complexity) is less than the management overhead of any dynamic data structure (such as a linked list or hash table). Therefore, a dense accumulator is used for the calculation of this output row. Preferably, the first threshold can be 0.1, 0.15, 0.2, etc. When the number of non-zero elements in the current row of the first sparse matrix is greater than the second threshold and the number of products is greater than the third threshold, it indicates that when The computational redundancy is very high, and a large number of intermediate result items need to be merged into a few non-zero elements. At this time, based on the fast unordered accumulation speed of hash tables, the calculation of the output row uses a hash accumulator. Preferably, to avoid the overhead of creating a hash table for overly simple rows, the second threshold can be 16, 17, 18, etc., and the third threshold can be 3-6 times the number of non-zero elements in the current row of matrix A, indicating that the number of intermediate results is much greater than the number of non-zero elements in the current row of matrix A. Under other conditions, especially when the ordered nature of the matrix data is the main feature, the calculation of the output row uses a merge accumulator.
[0031] like Figure 3 As shown, the steps for summation based on a merge accumulator are as follows: B1. Store the multiple products as multiple ordered linked lists; In practical applications, step B1 generates an ordered linked list: for the current row of the calculated output matrix... The process involves iterating through each non-zero element in the i-th row of matrix A. .Will With the k-th row of matrix B ( Multiplying these terms together yields a product term. Because In CSR format, column indices are naturally ordered, so the product terms are also ordered. Each such product term is stored as an ordered linked list. Therefore, the calculation for the i-th row of matrix A will result in k_i = nnz(A_i) ordered linked lists.
[0032] B2. Merge multiple ordered linked lists in pairs multiple times until they are merged into a single ordered linked list.
[0033] In one implementation, step B2 performs divide-and-conquer merging: the k_i linked lists are merged in a tree-like manner.
[0034] a) First round: Merge linked list 1 with linked list 2, linked list 3 with linked list 4, and so on.
[0035] b) Second round: Merge the new linked lists generated in the previous round in pairs again.
[0036] c) Repeat this process until all linked lists are merged into a single, ultimately ordered linked list. This process takes [time period]. The cycle is merged.
[0037] Preferably, pairwise merging stitches two input linked lists into one output linked list by directly manipulating pointers to the linked list nodes includes the following steps: Compare the column indices of nodes in two linked lists; When the column indices of two linked list nodes are different, the linked list node with the smaller column indice is linked to the end of the output linked list; When two linked list nodes have the same column index, add the values of the two linked list nodes and store the result in one of the linked list nodes. Link that linked list node to the end of the output linked list and discard the other linked list node that has not been stored.
[0038] In actual operation, pairwise merge is the key to the merge accumulator. This scheme does not copy the data in the linked list nodes, but directly modifies the next pointer of the linked list nodes, using a "pointer stitching" technique to "stitch" the nodes of two input linked lists into one output linked list. The specific steps are as follows: a) When merging two input list nodes, compare their column indices and link the list node with the smaller column indices to the end of the result list.
[0039] b) Integration of accumulation operations: If two linked list nodes have the same column index, add their values together, store the result in one of the nodes, link that node to the result linked list, and discard the other node. In this way, merging and numerical accumulation are completed in one operation.
[0040] Compared to existing technologies, the merge accumulator-based approach merges multiple naturally ordered intermediate product lists generated by row or column multiplication in a balanced, tree-like manner (merging them pairwise in sequence). By using a "pointer stitching" technique that directly manipulates the pointers of the linked list nodes, rather than copying the data itself, it greatly reduces memory access overhead, achieves cache friendliness, and the accumulation method based on the merge accumulator completely avoids sorting and can be seamlessly integrated with the value accumulation process.
[0041] S2. Using the first target accumulator, perform simulated matrix multiplication on the number of non-zero elements in the processing unit of the first sparse matrix and the number of non-zero elements in the corresponding processing unit of the second sparse matrix to obtain the number of non-zero elements in the corresponding output unit of the output matrix. It should be noted that in step S2, the structural information (row offset and column index array) of matrices A and B is traversed, and simulated matrix multiplication is performed on the current row of A and the corresponding column of B. The simulated matrix multiplication does not perform any floating-point calculations, but is only used to find the unique column index and count it.
[0042] Preferably, after performing simulated matrix multiplication on the number of non-zero elements in the processing unit of the first sparse matrix and the corresponding number of non-zero elements in the second sparse matrix using the first target accumulator to obtain the number of non-zero elements in the corresponding output unit of the output matrix, the method further includes: Memory space is allocated to the output matrix based on the number of non-zero elements in the corresponding output unit.
[0043] In practical applications, steps S1 and S2 are defined as the symbolic computation stage, and steps S3 and S4 are defined as the numerical computation stage.
[0044] Compared to existing technologies, the symbolic computation stage allocates memory space for the output matrix based on the number of non-zero elements in the corresponding output unit of the output matrix, avoiding the huge overhead of dynamic memory management. At the same time, the number of non-zero elements in the corresponding output unit of the output matrix provides a more accurate decision basis for the selection of accumulators in the numerical computation stage.
[0045] S3. The second target accumulator is determined based on the number of non-zero elements of the processing unit of the first sparse matrix, the number of non-zero elements of the corresponding output unit of the output matrix, and the second preset selection strategy; the first target accumulator and the second target accumulator are a set of mixed accumulators that include at least a merge accumulator. Preferably, determining the second target accumulator based on the number of products, the number of non-zero elements in the corresponding output unit of the output matrix, and a second preset selection strategy includes the following steps: The actual density is obtained by calculating the ratio of the number of non-zero elements in the corresponding output unit of the output matrix to the number of columns in the second sparse matrix. When the actual density is greater than the first threshold, the second target accumulator is determined to be a dense accumulator. If the number of non-zero elements in the current row of the first sparse matrix is greater than the second threshold, the number of products is greater than the third threshold, and the number of products is greater than the fourth threshold, then the second target accumulator is determined to be a hash accumulator. Otherwise, the second target accumulator is determined to be a merge accumulator.
[0046] In practical applications, the selection strategy for the second target accumulator is further combined with the number of non-zero elements in the corresponding output unit of the symbolic computation node's output matrix. When the actual density is greater than the first threshold, it indicates that the actual output row density is very high, so a dense accumulator is used for the calculation of that output row. When the number of non-zero elements in the current row of the first sparse matrix is greater than the second threshold, and the number of products is greater than the third threshold, and the number of products is greater than the fourth threshold, it indicates that the current computational redundancy is very high, so a hash accumulator is used for the calculation of that output row. Preferably, the fourth threshold can be 2 times, 4 times, etc., of the number of non-zero elements in the current row of the output matrix, indicating that the product terms have a high reduction rate. Under other conditions, especially when the ordered nature of the matrix data is the main feature, a merge accumulator is used for the calculation of the output row.
[0047] S4. Using the second target accumulator, the products of the non-zero elements in the processing unit of the first sparse matrix and the non-zero elements in the corresponding processing unit of the second sparse matrix are accumulated and summed to obtain the corresponding output unit of the output matrix.
[0048] After summing the products of the non-zero elements in the processing units of the first sparse matrix and the corresponding non-zero elements in the processing units of the second sparse matrix using the second target accumulator to obtain the corresponding output unit of the output matrix, the process further includes: Store the corresponding output cells of the output matrix in memory.
[0049] It should be noted that after the symbol calculation stage (steps S1-S2), a reserved memory space is allocated for the output matrix based on the number of non-zero elements in the corresponding output unit of the output matrix. At this time, the number of non-zero elements in the corresponding output unit of the output matrix is directly stored in the reserved memory space, thereby avoiding the huge overhead of dynamic memory management.
[0050] In practical applications, steps S1-S4 can also be implemented by formulating multiplication. The specific implementation method is consistent with the principle of the above embodiment, and will not be repeated here.
[0051] Compared with existing technologies, this invention proposes a merge-accumulator algorithm that utilizes the inherent orderliness of the input matrix structure, transforming the traditional "sorting" problem into an efficient "merging" problem, thereby improving the computational efficiency of SpGEMM. The merge algorithm based on linked list pointer operations in this invention has a time complexity comparable to the theoretically optimal heap method. However, by minimizing data movement and promoting sequential access, it achieves excellent caching performance and data locality, solving the problem of the disconnect between theory and practice. This invention includes a hybrid accumulator set of merge accumulator, hash accumulator, and dense accumulator. Through a dynamic selection mechanism, it can independently select the optimal strategy for each row / column at runtime, exhibiting strong adaptability and robust high performance for various sparse matrices with different structures. This invention achieves one-time precise pre-allocation of memory for the output matrix by separating the computation into two stages: a symbolic computation stage (steps S1-S2) and a numerical computation stage (steps S3-S4). This avoids the huge overhead of dynamic memory management and provides a more accurate decision basis for accumulator selection in the numerical computation stage, improving the overall execution efficiency.
[0052] In one embodiment, such as Figure 3 As shown, a data processing system for sparse matrix multiplication includes: The first selection module is used to determine the first target accumulator based on the number of non-zero elements of the processing unit in the first sparse matrix, the number of non-zero elements of the corresponding processing unit in the second sparse matrix, and the first preset selection strategy, wherein the first sparse matrix and the second sparse matrix are sparse matrices with intrinsically ordered values. The simulation calculation module is used to perform simulated matrix multiplication on the non-zero elements in the processing unit of the first sparse matrix and the non-zero elements in the corresponding processing unit of the second sparse matrix using the first target accumulator, so as to obtain the number of non-zero elements in the corresponding output unit of the output matrix. The second selection module is used to determine the second target accumulator based on the number of non-zero elements in the processing unit of the first sparse matrix, the number of non-zero elements in the corresponding output unit of the output matrix, and the second preset selection strategy, wherein the first target accumulator and the second target accumulator are a set of mixed accumulators that include at least a merge accumulator. The actual calculation module uses the second target accumulator to accumulate and sum the products of the non-zero elements in the processing unit of the first sparse matrix and the non-zero elements in the corresponding processing unit of the second sparse matrix to obtain the corresponding output unit of the output matrix.
[0053] For specific limitations regarding a data processing system for sparse matrix multiplication, please refer to the limitations regarding a data processing method for sparse matrix multiplication described above, which will not be repeated here. The modules in the aforementioned data processing system for sparse matrix multiplication can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0054] like Figure 4 As shown, in one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it performs the following steps: The first target accumulator is determined based on the number of non-zero elements of the processing unit in the first sparse matrix, the number of non-zero elements of the corresponding processing unit in the second sparse matrix, and the first preset selection strategy, wherein the first sparse matrix and the second sparse matrix are sparse matrices with intrinsically ordered values. The number of non-zero elements in the corresponding output unit of the output matrix is obtained by performing simulated matrix multiplication on the non-zero elements in the processing unit of the first sparse matrix and the corresponding non-zero elements in the second sparse matrix using the first target accumulator. The second target accumulator is determined based on the number of non-zero elements in the processing unit of the first sparse matrix, the number of non-zero elements in the corresponding output unit of the output matrix, and the second preset selection strategy; the first target accumulator and the second target accumulator are a set of mixed accumulators that include at least a merge accumulator. The product of the non-zero elements in the processing unit of the first sparse matrix and the non-zero elements in the corresponding processing unit of the second sparse matrix is accumulated and summed using the second target accumulator to obtain the corresponding output unit of the output matrix.
[0055] Those skilled in the art will understand that Figure 4The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0056] In one embodiment, a computer-readable storage medium is provided, storing a computer program that, when executed by a processor, performs the following steps: The first target accumulator is determined based on the number of non-zero elements of the processing unit in the first sparse matrix, the number of non-zero elements of the corresponding processing unit in the second sparse matrix, and the first preset selection strategy, wherein the first sparse matrix and the second sparse matrix are sparse matrices with intrinsically ordered values. The number of non-zero elements in the corresponding output unit of the output matrix is obtained by performing simulated matrix multiplication on the non-zero elements in the processing unit of the first sparse matrix and the corresponding non-zero elements in the second sparse matrix using the first target accumulator. The second target accumulator is determined based on the number of non-zero elements in the processing unit of the first sparse matrix, the number of non-zero elements in the corresponding output unit of the output matrix, and the second preset selection strategy; the first target accumulator and the second target accumulator are a set of mixed accumulators that include at least a merge accumulator. The product of the non-zero elements in the processing unit of the first sparse matrix and the non-zero elements in the corresponding processing unit of the second sparse matrix is accumulated and summed using the second target accumulator to obtain the corresponding output unit of the output matrix.
[0057] In the embodiments provided in this application, it should be understood that the disclosed methods and systems can be implemented in other ways. The system embodiments described above are merely illustrative. For example, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple modules or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, and can be electrical, mechanical, or other forms.
[0058] Furthermore, in the various embodiments of the present invention, each functional module can be fully integrated into a processor, or each module can be a separate device, or two or more modules can be integrated into a device; each functional module in the various embodiments of the present invention can be implemented in hardware or in the form of hardware plus software functional units.
[0059] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by program instructions and related hardware. The aforementioned program instructions can be stored in a computer-readable storage medium. When the program instructions are executed, they perform the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as mobile storage devices, read-only memory (ROM), magnetic disks, or optical disks.
[0060] It should be understood that the use of terms such as "system," "apparatus," "unit," and / or "module" in this application is only applicable to distinguishing different components, elements, parts, sections, or assemblies at different levels. However, if other terms can achieve the same purpose, they may be replaced by other expressions.
[0061] As indicated in this application and claims, unless the context clearly indicates otherwise, the words "a," "an," "a," and / or "the" are not specifically singular and may include the plural. Generally, the terms "comprising" and "including" only indicate the inclusion of expressly identified steps and elements, which do not constitute an exclusive list, and the method or apparatus may also include other steps or elements. An element defined by the phrase "comprising an..." does not exclude the presence of other identical elements in the process, method, product, or apparatus that includes the element.
[0062] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this application, "a plurality of" or "several" means two or more, unless otherwise explicitly specified.
[0063] If a flowchart is used in this application, it is used to illustrate the operations performed by the system according to embodiments of this application. It should be understood that the preceding or following operations are not necessarily performed in exact order. Instead, the steps can be processed in reverse order or simultaneously. Furthermore, other operations can be added to these processes, or one or more steps can be removed from them.
[0064] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A data processing method for sparse matrix multiplication, characterized in that, Includes the following steps: The first target accumulator is determined based on the number of non-zero elements of the processing unit in the first sparse matrix, the number of non-zero elements of the corresponding processing unit in the second sparse matrix, and the first preset selection strategy, wherein the first sparse matrix and the second sparse matrix are sparse matrices with intrinsically ordered values. The first target accumulator is used to perform simulated matrix multiplication on the non-zero elements in the processing unit of the first sparse matrix and the non-zero elements in the corresponding processing unit of the second sparse matrix to obtain the number of non-zero elements in the corresponding output unit of the output matrix. The second target accumulator is determined based on the number of non-zero elements in the processing unit of the first sparse matrix, the number of non-zero elements in the corresponding output unit of the output matrix, and the second preset selection strategy; the first target accumulator and the second target accumulator are a set of mixed accumulators that include at least a merge accumulator. The corresponding output unit of the output matrix is obtained by summing the products of the non-zero elements in the processing unit of the first sparse matrix and the non-zero elements in the corresponding processing unit of the second sparse matrix using the second target accumulator.
2. The data processing method according to claim 1, characterized in that, The processing unit and the output unit include a single row, a single column, multiple rows, or multiple columns; The determination of the first target accumulator based on the number of non-zero elements of the processing unit in the first sparse matrix, the number of non-zero elements of the corresponding processing unit in the second sparse matrix, and the first preset selection strategy includes the following steps: The product of the number of non-zero elements in the processing unit of the first sparse matrix and the number of non-zero elements in the corresponding processing unit of the second sparse matrix is determined based on the number of non-zero elements in the current row of the first sparse matrix. Obtain the number of columns in the second sparse matrix; The first target accumulator is determined based on the number of products, the number of columns in the second sparse matrix, and the first preset selection strategy.
3. The data processing method according to claim 2, characterized in that, The first target accumulator and the second target accumulator further include: a dense accumulator and a hash accumulator; The first target accumulator is determined based on the number of products, the number of columns in the second sparse matrix, and the first preset accumulator selection strategy, including the following steps: The ratio of the number of products to the number of columns in the second sparse matrix is used to obtain the estimated density; When the estimated density is greater than the first threshold, the first target accumulator is determined to be the dense accumulator. When the number of non-zero elements in the current row of the first sparse matrix is greater than the second threshold, and the number of products is greater than the third threshold, the first target accumulator is determined to be the hash accumulator; Otherwise, the first target accumulator is determined to be the merge accumulator.
4. The data processing method according to claim 3, characterized in that, The determination of the second target accumulator based on the number of non-zero elements in the processing unit of the first sparse matrix, the number of non-zero elements in the corresponding output unit of the output matrix, and the second preset selection strategy includes the following steps: The actual density is obtained by calculating the ratio of the number of non-zero elements in the corresponding output unit of the output matrix to the number of columns in the second sparse matrix; When the actual density is greater than the first threshold, the second target accumulator is determined to be the dense accumulator. When the number of non-zero elements in the current row of the first sparse matrix is greater than the second threshold, and the number of products is greater than the third threshold, and the number of products is greater than the fourth threshold, the second target accumulator is determined to be the hash accumulator. Otherwise, the second target accumulator is determined to be the merge accumulator.
5. The data processing method according to claim 4, characterized in that, When performing accumulation and summation based on the merge accumulator, the following steps are included: The product is stored as multiple ordered linked lists; The multiple ordered linked lists are merged in pairs in multiple rounds until they are merged into a single ordered linked list.
6. The data processing method according to claim 5, characterized in that, The pairwise regression, which stitches two input linked lists into one output linked list by directly manipulating pointers of linked list nodes, includes the following steps: Compare the column indices of nodes in two linked lists; When the column numbers of the two linked list nodes are different, the linked list node with the smaller column number is linked to the end of the output linked list; When the column numbers of the two linked list nodes are the same, the values of the two linked list nodes are added together and the result is stored in one of the linked list nodes. This linked list node is then linked to the end of the output linked list, while the other linked list node that has not been stored is discarded.
7. The data processing method according to claim 1, characterized in that, After performing simulated matrix multiplication on the number of non-zero elements in the processing unit of the first sparse matrix and the number of non-zero elements in the corresponding processing unit of the second sparse matrix using the first target accumulator to obtain the number of non-zero elements in the corresponding output unit of the output matrix, the method further includes: Memory space is allocated to the output matrix based on the number of non-zero elements in the corresponding output unit of the output matrix; After summing the products of the number of non-zero elements in the processing unit of the first sparse matrix and the number of non-zero elements in the corresponding processing unit of the second sparse matrix using the second target accumulator to obtain the corresponding output unit of the output matrix, the method further includes: The corresponding output units of the output matrix are stored in the memory space.
8. A data processing system for sparse matrix multiplication, characterized in that, include: The first selection module is used to determine the first target accumulator based on the number of non-zero elements of the processing unit in the first sparse matrix, the number of non-zero elements of the corresponding processing unit in the second sparse matrix, and the first preset selection strategy, wherein the first sparse matrix and the second sparse matrix are sparse matrices with intrinsically ordered values. The simulation calculation module is used to perform simulated matrix multiplication on the non-zero elements in the processing unit of the first sparse matrix and the non-zero elements in the corresponding processing unit of the second sparse matrix using the first target accumulator, so as to obtain the number of non-zero elements in the corresponding output unit of the output matrix. The second selection module is used to determine a second target accumulator based on the number of non-zero elements in the processing unit of the first sparse matrix, the number of non-zero elements in the corresponding output unit of the output matrix, and a second preset selection strategy, wherein the first target accumulator and the second target accumulator are a set of mixed accumulators that include at least a merge accumulator. The actual calculation module uses the second target accumulator to accumulate and sum the products of the non-zero elements in the processing unit of the first sparse matrix and the non-zero elements in the corresponding processing unit of the second sparse matrix to obtain the corresponding output unit of the output matrix.
9. A computer device, characterized in that, The method includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the steps of the data processing method as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the data processing method as described in any one of claims 1-7.