Adaptive edge sampling method for sparse-dense matrix multiplication in accelerated graph neural network
By executing adaptive edge sampling in parallel on the GPU side, combined with the CSR format and a suitable sampling strategy, the problem of uneven accuracy and speed of SpMM operations in edge sampling accelerated GNNs is solved, and sparse-dense matrix multiplication in graph neural networks is realized. efficient calculation.
Patent Information
- Application Number
- CN202410713500.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-04
- Publication Date
- 2024-09-24
AI Technical Summary
The sparse-dense matrix multiplication operation in existing edge sampling accelerated graph neural networks cannot take into account both accuracy and speed, and requires preprocessing on the CPU or the use of complex models, resulting in additional overhead that outweighs the reduction in computational complexity.
Using the adaptive edge sampling method, the edge sampling process is executed in parallel on the GPU side. By setting the GPU shared memory width and converting the sparse matrix into CSR format, an appropriate sampling strategy is selected based on the number of non-zero elements in the current row to reduce computational complexity. and increase speed.
In GNN, the time overhead of sampling is significantly reduced, the speed of SpMM operation is improved, ensuring that the accuracy loss is minimized while ensuring the execution speed, and is suitable for different scales of graph data, and is compatible with popular GNN frameworks.
Smart Images

Figure CN118690806A
Abstract
Description
Technical Field
[0001] The present invention mainly relates to the application field of graph neural networks in deep learning, and in particular to an adaptive edge sampling method for accelerating sparse-dense matrix multiplication in graph neural networks. Background Art
[0002] Graph Neural Network (GNN) is developed based on neural network, which applies deep learning principles to graph data in non-Euclidean space, effectively overcoming the limitations of traditional deep learning methods when processing such data. The data objects processed by GNN are graph data with irregular structures. The structure of graph data is very rich. Since its structure can represent many different types of information, this rich structure is also in line with many practical problems to be dealt with in life, so GNN has a wide range of applications.
[0003] Sparse-dense Matrix Multiplication (SpMM) is a frequently used operation in GNN layer feature aggregation. Since graph data is usually sparse, that is, there are few connections between nodes, the adjacency matrix is very sparse. In traditional matrix multiplication algorithms, the multiplication of sparse matrices is computationally complex and requires processing a large number of zero elements, resulting in low computational efficiency. Therefore, the SpMM operation becomes a bottleneck in GNN operations.
[0004] Edge sampling is a technique that includes only a subset of the edges of the original graph and discards the rest. Edge sampling is used to effectively process large-scale graph data. By selecting a portion of the graph data for training or inference, it helps improve computational efficiency and model performance.
[0005] At present, edge sampling has been used to alleviate the overfitting and over-smoothing training problems of GNN. Representatives include Dropedge proposed by Yu Rong et al. from Tencent Artificial Intelligence Laboratory, NeuralSparse proposed by Cheng Zheng et al. from University of California, Los Angeles, and Graph DropConnect proposed by Arman Hasanzadeh et al. from Texas A&M University.
[0006] What they have in common is that the edge sampling method is to randomly discard edges or use a learned neural network to determine which edges need to be discarded, so as to alleviate the overfitting and oversmoothing problems in training and reduce memory and computing overhead. Edge sampling can also be used to accelerate the SpMM operation in GNN, because edge sampling reduces the number of connections in the graph, thereby reducing the number of non-zero elements in the adjacency matrix, further reducing the calculation time of the SpMM operation, so it can be used to accelerate the SpMM operation in GNN.
[0007] However, the current method of using edge sampling to accelerate SpMM operations in GNN still has the problem of imbalance between accuracy and speed. The reason is that the sampling strategy cannot take into account both accuracy and speed at the same time, and the existing methods need to preprocess the graph on the CPU or use complex models to sample the edges. The additional overhead will eventually outweigh the benefits of reducing computational complexity. Summary of the invention
[0008] The purpose of the present invention is to provide an adaptive edge sampling method for accelerating sparse-dense matrix multiplication in graph neural networks, aiming to solve the problem that the SpMM operation in the current edge sampling accelerated GNN cannot take into account both accuracy and speed.
[0009] The present invention is implemented as follows: an adaptive edge sampling method for accelerating sparse-dense matrix multiplication in a graph neural network comprises the following steps: Step 1: Set the GPU shared memory width W; Step 2: Convert the sparse matrix graph data into CSR format; Step 3: Select an appropriate sampling strategy for the current row to perform edge sampling; Step 4: Load the sampled sparse matrix graph data into the shared memory; Step 5: Calculate the elements in the shared memory and the corresponding elements of the dense matrix representing the node features in the global memory to obtain the final result.
[0010] Furthermore, the step 1 sets the shared memory width W according to the complexity of the graph and the scale of the graph data.
[0011] Furthermore, the step 2 converts the sparse adjacency matrix graph data into a compressed sparse row (CSR) format.
[0012] Furthermore, the step three selects a suitable sampling strategy for the current row to perform edge sampling:
[0013] Step 1: Select an appropriate sampling strategy based on the shared memory width and the number of non-zero elements in the current row;
[0014] Step 2: Sampling is performed according to the sampling strategy selected in step 1.
[0015] Furthermore, the step 4 loads all the sparse matrix graph data selected by sampling into the shared memory.
[0016] Furthermore, in step five, the elements in the shared memory are multiplied by the elements corresponding to the dense matrix representing the node features in the global memory and the accumulated calculations are performed to obtain the final result.
[0017] The beneficial effects of the present invention are as follows: (1) The present invention does not require time-consuming edge sampling on the CPU side, but instead adds an edge sampling process to the SpMM operation, which is executed in parallel on the GPU side, greatly reducing the time overhead of sampling and improving the speed of SpMM operations in GNN; (2) The sampling strategy proposed in the present invention is lightweight and can select a suitable sampling strategy according to the shared memory width and the number of non-zero elements in the current row, thereby minimizing the loss of accuracy while ensuring the execution speed; (3) The present invention can perform adaptive edge sampling on graph data of different scales to accelerate the SpMM operation in GNN, and the sparse matrix is stored in CSR format, which is compatible with many popular GNN frameworks and has universality. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 This is a flowchart of an adaptive edge sampling method for accelerating sparse-dense matrix multiplication in a graph neural network provided by an embodiment of the present invention.
[0019] Figure 2 This is an example of the SpMM process in the adaptive edge sampling accelerated GNN provided by an embodiment of the present invention.
[0020] Figure 3 This is an example of an adaptive sampling strategy provided by an embodiment of the present invention.
[0021] Figure 4 This is an example of a sampling starting position provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0022] 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.
[0023] Figure 1 The process of the adaptive edge sampling method for accelerating sparse-dense matrix multiplication in a graph neural network of the present invention is shown. As shown in the figure, the present invention is implemented in this way. An adaptive edge sampling method for accelerating sparse-dense matrix multiplication in a graph neural network includes the following steps: S101: Setting the GPU shared memory width W; S102: Convert the sparse matrix graph data into CSR format; S103: Selecting a suitable sampling strategy for the current row to perform edge sampling; S104: Load the sampled sparse matrix graph data into the shared memory; S105: Calculate the elements in the shared memory and the corresponding elements of the dense matrix representing the node features in the global memory to obtain the final result.
[0024] Furthermore, the step S101 sets the shared memory width W according to the scale of the graph data.
[0025] Furthermore, the step S102 converts the sparse adjacency matrix graph data into a compressed sparse row (CSR) format.
[0026] Furthermore, the step S103 selects a suitable sampling strategy for the current row to perform edge sampling.
[0027] Step 1: Select an appropriate sampling strategy according to the shared memory width W and the number of non-zero elements nnz in the current row;
[0028] Step 2: Sampling is performed according to the selected sampling strategy.
[0029] Furthermore, the step S104 loads all the sparse matrix graph data selected by sampling into the shared memory.
[0030] Furthermore, the step S105 multiplies the elements in the shared memory with the elements corresponding to the dense matrix representing the node features in the global memory and accumulates the calculations to obtain the final result.
[0031] Example: The ogbn-proteins dataset is an undirected, weighted and typed (according to species) graph. The ogbn-proteins dataset contains 132,534 nodes, 39,561,252 edges, and the average degree of the nodes is 597. The node prediction task is to predict the existence of protein function in a multi-label binary classification setting. There are a total of 112 labels that need to be predicted. The graph data of this dataset is relatively complex. If traditional methods are used for calculation, it will bring huge time and space overhead. Using this dataset can effectively verify the performance improvement brought by our proposed method. The steps for implementing the adaptive edge sampling method for accelerating sparse-dense matrix multiplication in graph neural networks on the ogbn-proteins dataset are as follows:
[0032] Step 1: Set the GPU shared memory width W; Since the graph data of the ogbn-proteins dataset is relatively complex and the average degree of the nodes is 597, a larger shared memory width needs to be set. We choose the shared memory width W to be 256. When W is 256, the corresponding sampling rate of the ogbn-proteins dataset is 34.3%.
[0033] Step 2: Convert the sparse matrix graph data into CSR format; The compressed sparse row (CSR) format is a commonly used sparse matrix storage format. The CSR format provides efficient sparse matrix operations by compressing the storage space of non-zero elements. At the same time, many popular GNN frameworks support the CSR format, such as PyTorch Geometric (PyG), Deep Graph Library (DGL), etc., which allows our method to avoid the additional overhead of format conversion and can be well integrated with the current popular GNN framework.
[0034] Step 3: Select an appropriate sampling strategy for the current row to perform edge sampling; Select an appropriate sampling strategy based on the shared memory width W and the number of non-zero elements in the current row nnz. According to the shared memory width W set in step 1 as 256, if the number of non-zero elements in the current row is less than or equal to the shared memory width, all elements in the current row will be selected. For example, if the number of non-zero elements in the current row nnz is 200, then according to Figure 3 , the value of N is also 200, that is, 200 adjacent elements are selected each time. If the number of non-zero elements in the current row is greater than the shared memory width, the number of adjacent elements N sampled each time is calculated based on the ratio R of the current row nnz to W. N actually reflects the sampling granularity. When R is small, coarse-grained sampling is used to ensure sampling speed, and when R is large, fine-grained sampling is used to ensure sampling accuracy. For example, the number of non-zero elements nnz in the current row is 640, and the ratio R is 2.5. According to Figure 3 , the value of N is 256 / 8=32, that is, 32 adjacent elements are selected each time.
[0035] Sampling is performed according to the selected sampling strategy. If the number of non-zero elements in the current row is less than or equal to the shared memory width, all elements in the current row are selected. For example, if N is 200, one sampling is performed and the starting position of the sampling is Figure 4 Calculate and select 200 adjacent elements. If the number of non-zero elements in the current row is greater than the shared memory width, sample the current row in a pseudo-random manner sample_cnt = W / N times, and use the hash function to calculate the starting position of each sampling based on the product of the current index current_ind and the prime number prime_num modulo nnz-N+1. Each sampling selects N adjacent elements. For example, if the current N is 32, 256 / 32 = 8 samples are performed, and the starting position of each sampling is determined by Figure 4 It is calculated that 32 adjacent elements are selected each time.
[0036] Step 4: Load the sampled sparse matrix graph data into the shared memory; All the elements selected in step 3 are loaded into the shared memory. Since the sparse matrix graph data has been edge sampled, the computational complexity of the SpMM operation is reduced. At the same time, the sparse matrix graph data is uniformly stored in the shared memory, which improves data locality and can accelerate the SpMM operation in GNN.
[0037] Step 5: Calculate the elements in the shared memory and the corresponding elements of the dense matrix representing the node features in the global memory to obtain the final result; Read the sampled sparse matrix graph data from the shared memory, load the corresponding dense matrix graph data from the global memory, calculate the product, repeat this process in a loop and accumulate the multiplication results, store the dense matrix obtained by the SpMM operation into the global memory, and get the final result.
[0038] The above proposed adaptive edge sampling accelerates the SpMM process in GNN as follows Figure 2 As shown in the figure, this method adaptively selects a sampling strategy suitable for the current row according to the number of non-zero elements in the current row and the shared memory width, and assigns sampling and SpMM operations to each thread for parallel execution, thus avoiding the problem of unbalanced accuracy and speed when using edge sampling to accelerate SpMM operations in GNNs, and realizing edge sampling schemes for different graph data scales, thereby achieving an effect that is more in line with the characteristics of the GPU architecture and can efficiently accelerate SpMM operations in parallel.
[0039] 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. An adaptive edge sampling method to accelerate sparse-dense matrix multiplication in graph neural networks, It is characterized in that The adaptive edge sampling method for accelerating sparse-dense matrix multiplication in graph neural networks comprises the following steps: Step 1: Set the GPU shared memory width W; Step 2: Convert the sparse matrix graph data into CSR format; Step 3: Select an appropriate sampling strategy for the current row to perform edge sampling; Step 4: Load the sampled sparse matrix graph data into the shared memory; Step 5: Calculate the elements in the shared memory and the corresponding elements of the dense matrix representing the node features in the global memory to obtain the final result.
2. The adaptive edge sampling method for accelerating sparse-dense matrix multiplication in graph neural networks as claimed in claim 1, It is characterized in that The step 1 sets the shared memory width W by analyzing the graph complexity and the graph data scale.
3. The adaptive edge sampling method for accelerating sparse-dense matrix multiplication in graph neural networks as claimed in claim 1, It is characterized in that The step 2 converts the sparse adjacency matrix graph data into a compressed sparse row (CSR) format.
4. The adaptive edge sampling method for accelerating sparse-dense matrix multiplication in graph neural networks as claimed in claim 1, It is characterized in that The step three selects a suitable sampling strategy and performs edge sampling according to the shared memory width W and the number of non-zero elements nnz in the current row, and the specific steps are as follows: Step 1: Select an appropriate sampling strategy based on the shared memory width and the number of non-zero elements in the current row. If the number of non-zero elements in the current row is less than or equal to the shared memory width, all elements in the current row will be selected; otherwise, the number of adjacent elements N for each sampling is calculated based on the ratio R of the number of non-zero elements nnz in the current row to the shared memory width W; Step 2: Sampling is performed according to the selected sampling strategy. If the number of non-zero elements in the current row is less than or equal to the shared memory width, all elements in the current row are selected; otherwise, the current row is sampled in a pseudo-random manner for sample_cnt=W / N times, and the starting position of each sampling is calculated by taking the modulus of nnz-N+1 based on the product of the current index current_ind and the prime number prime_num using the hash function, and each sampling selects N adjacent elements.
5. The adaptive edge sampling method for accelerating sparse-dense matrix multiplication in graph neural networks as claimed in claim 1, It is characterized in that The step 4 loads all the sparse matrix graph data selected by sampling into the shared memory.
6. The adaptive edge sampling method for accelerating sparse-dense matrix multiplication in graph neural networks as claimed in claim 1, It is characterized in that The step five multiplies the elements in the shared memory with the elements corresponding to the dense matrix representing the node features in the global memory and accumulates the calculations to obtain the final result.
Citation Information
Cited By
Multi-agent decision framework and method based on kernel event perception
CN120952040A
