Method for accelerating GNN reasoning through three caches
By introducing a three-cache mechanism into GNN inference and using a lightweight cache search mechanism and pre-sampling to determine the cache capacity, the problem of improper utilization of GPU memory and redundant calculations is solved, and the efficiency and effectiveness of GNN inference are improved.
Patent Information
- Application Number
- CN202410914147.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-10-11
AI Technical Summary
During the inference process of graph neural network (GNN), due to the improper utilization of GPU memory, the actual utilization rate of GPU resources is low, and there are problems of redundant calculation and low data transmission efficiency. Especially when inferring on large graphs, the existing technology is difficult to be effective. Utilize free memory and increase memory bandwidth.
A three-cache acceleration method is adopted, including adjacency array cache, node feature cache and intermediate layer output cache. Reasonable cache capacity is determined through pre-sampling, and the cache is filled during the inference process. A lightweight cache lookup mechanism is used to reduce redundant calculations and Data transfer to improve GPU memory utilization.
It improves the efficiency of the GNN inference process and GPU memory utilization, reduces the amount of data transmission and calculation, improves the overall inference efficiency, and is suitable for graph data sets and GNN parameters of different sizes.
Smart Images

Figure HDA0004934594040000011 
Figure HDA0004934594040000012 
Figure HDA0004934594040000021
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 a method for accelerating GNN reasoning by using three caches. Background Art
[0002] Graph Neural Network (GNN) has made significant progress in various graph data applications in recent years and is widely used in fields such as social network analysis, recommendation systems, and knowledge graphs. The training phase of GNN usually involves operations such as neighborhood aggregation and graph convolution to learn the feature representation of nodes and their neighbors, thereby optimizing the parameters of the model. This process requires processing a large number of nodes and edges, and usually relies on powerful computing resources such as GPUs for acceleration. However, training is only the first step in GNN application. The trained model also needs to be inferred in order to play a role in actual scenarios.
[0003] GNN inference is a key step in applying the trained GNN model to practical scenarios and a necessary stage for testing the quality of GNN training. Although it has not attracted much attention from researchers, accelerating GNN inference is as important as accelerating GNN training. In many downstream tasks, such as social media recommendation, the social network graph maintained by Facebook has nearly 2 billion users, and its input graph is large. It is very challenging to perform GNN inference on such a huge graph because full batch processing will exceed the GPU memory capacity. The CSC (Compressed Sparse Column) format is particularly suitable for sampling workloads because it allows fast access to all neighbors of the target node. Therefore, most modern GNN systems have developed high-performance C++ and CUDA graph sampling kernels based on CSC arrays. For example, DGL (Deep Graph Library) and PyG (PyTorch Geometric) have taken advantage of this advantage to optimize graph sampling and computing performance. Therefore, sampling-based methods are usually selected for small batch inference for reasoning on large graphs. However, this approach is limited by the low efficiency of CPU to GPU data loading, and there is also the problem of redundant calculation in GNN inference.
[0004] Currently in academia, there are two types of inference algorithms for existing graph neural network systems: full batch inference and small batch inference. Full batch inference is suitable for small graphs. Due to the limitation of GPU memory, only sampling-based small batch inference can be used for inference on large graphs. Representative works include PCGraph proposed by Zhang from the National University of Defense Technology and RAIN proposed by Liu et al. from the University of Aizu in Japan.
[0005] The sampling-based small batch reasoning system will have the problem of redundant data transmission, because different nodes may share the same neighbors. The common point of the above works is that they want to reduce the data transmission from CPU to GPU through data reuse, thereby accelerating the reasoning process. Because the main bottleneck of reasoning comes from the overhead generated when loading graph data from host memory to GPU, the data loading time will account for more than 70% of the total time of the entire reasoning process, while the GPU utilization rate is less than 20%, because the GPU spends most of the time waiting for the arrival of small batch data samples. The acceleration of modern machine learning models is often severely limited by insufficient memory bandwidth. In order to provide the highest possible memory bandwidth, data is usually placed in GPU memory. Since real-world graphs usually exceed the capacity of GPU memory, the current GCN training system saves node features in host memory and relies on the CPU to collect sparse features and then send them to the GPU. However, this approach puts tremendous pressure on the host memory bandwidth and CPU. Some works have proposed the use of unified virtual addressing (UVA) technology to quickly access and process irregular graph data. UVA technology can improve the utilization of PCIe bandwidth when graph data is transferred to the GPU, but UVA technology cannot utilize the locality of graph data, thereby wasting time repeatedly transmitting frequently accessed data.
[0006] Currently, most of the graphs in the real world are power-law graphs, and a high cache hit rate can be achieved by storing only a small amount of data. For example, in the ogbn-papers100M dataset, the node feature cache cannot obtain significant benefits in a cache capacity exceeding 2.5GB. The single node feature cache has a boundary effect, and the remaining spare GPU memory is not properly utilized. Using all the free GPU memory to store features will result in a waste of GPU space. Summary of the invention
[0007] The purpose of the present invention is to provide a method for accelerating GNN reasoning with three caches, aiming to solve the problem that in the current graph neural network reasoning process, all the free GPU memory is used to cache node features, and the free memory space is not reasonably divided, resulting in low actual utilization of GPU resources in the GNN reasoning process. By introducing the adjacency array cache and the intermediate layer output cache, the GPU memory is reasonably utilized, solving the problem of the locality of the adjacency matrix and redundant calculation not being utilized in the current GNN reasoning.
[0008] 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: Pre-sampling according to given parameters; Step 2: Determine the average out-degree of the node; Step 3: Determine the reasonable capacity of the adjacency array cache, node feature cache, and middle layer output cache; Step 4: Fill the node feature and adjacency array caches respectively; Step 5: Prepare small batches during formal reasoning; Step 6: After the calculation of the middle layer is completed, the output result is stored in the middle layer output cache. Repeat this operation, reasoning layer by layer, until the second to last layer is processed; Step 7: Perform the calculation of the last layer, output the final result, and the reasoning ends.
[0009] Furthermore, the step 1 determines the size of free memory in the GPU during inference by pre-sampling, determines the total memory capacity available for cache allocation, and counts the out-degree of the node and the number of times the node is selected.
[0010] Furthermore, the step 2 will calculate the average out-degree of the node.
[0011] Furthermore, the step three is to determine the proportion of the neighbor array cache, the node feature cache and the intermediate layer output through the graph neural network parameters and the two arrays maintained in the step one, and allocate their respective cache capacities in proportion to the total capacity.
[0012] Furthermore, step 4 will fill the node feature and adjacency array caches:
[0013] Step a: Fill the node features with out-degree greater than the average value into the feature cache first. If there is still some capacity left in the cache after filling all the nodes with out-degree greater than the average value, select the nodes with out-degree less than the average value to continue filling in sequence, and maintain a hash table to quickly index the location of node feature storage;
[0014] Step b: sort the original CSC array according to the number of times the nodes are selected, and fill the adjacent array cache with the nodes that are selected more times.
[0015] Further, step five will start the formal sampling process:
[0016] Step a: When sampling a node, the sampler will try to access the nth element in the original array. If n is less than the length L of the cache array, the cache hits and the required element is directly obtained from the GPU. Otherwise, the cache misses and the data is obtained from the original CSC array in the host memory through the unified virtual address (UVA) technology.
[0017] Step b: When selecting node features, the feature selector uses the hash table to determine whether the node features are in the feature cache. If the cache hits, it directly obtains the data from the GPU memory. If it does not hit, it uses UVA technology to obtain the node features from the host memory. After the feature selection is completed, the reasoning process begins;
[0018] Furthermore, in step six, after completing the reasoning of the current layer, the hidden state output of the layer is stored in the intermediate layer output cache. When performing the next layer calculation, the model directly reads these hidden states from the cache without recalculating or iteratively accessing the nodes of the distant layer. This operation is repeated for calculation layer by layer.
[0019] Furthermore, the step seven calculates the last layer of the graph neural network, and the output result represents the final processing result of the model on the input graph data, completing the reasoning.
[0020] The beneficial effects of the present invention are as follows: (1) The present invention uses the idle GPU memory in the sampling-based GNN reasoning to cache frequently accessed nodes and node features, which reduces the amount of data transmission during the reasoning process, speeds up the preparation time of small batches during the reasoning process, and improves the effective utilization of GPU memory. (2) The present invention avoids multiple feature aggregations of the same node by caching the output of the hidden layer, significantly reduces the amount of calculation, and improves the efficiency of the reasoning process. (3) Both the adjacency array cache and the node feature cache proposed in the present invention adopt a lightweight cache search mechanism, wherein the adjacency array cache only uses comparison operations to determine whether the cache hits, and the node feature cache uses a hash table for fast judgment. (4) The present invention can implement three-cache allocation for graph data sets and GNN parameters of different sizes. By performing relay optimization in the three links of sampling, feature selection and calculation, the overall efficiency of the graph neural network reasoning process is effectively improved. It is also compatible with the currently popular GNN framework and has universality. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 It is a flow chart of a method for accelerating GNN reasoning with three caches provided by an embodiment of the present invention;
[0022] Figure 2 is a directed graph and its corresponding Compressed Sparse Column (CSC) representation;
[0023] Figure 3 Yes Figure 2 The sorted representation of the compressed sparse column (CSC) array in ;
[0024] Figure 4is an example of an adjacency array that will be populated into the cache;
[0025] Figure 5 This is an example of a process for accelerating GNN reasoning from a three-cache provided by an embodiment of the present invention;
[0026] Figure 6 is an example of the storage volume of an adjacency array provided in an embodiment of the present invention;
[0027] Figure 7 is an example of the storage volume of the node feature provided by the embodiment of the present invention;
[0028] Figure 8 is an example of the storage volume of the intermediate layer output provided by an embodiment of the present invention;
[0029] Fig. 9 is an example of the cache ratio occupied by the adjacent array provided in the embodiment of the present invention;
[0030] Fig.10 is an example of the cache ratio occupied by node features provided in an embodiment of the present invention;
[0031] Fig.11 This is an example of the cache ratio occupied by the middle layer output provided in an embodiment of the present invention; DETAILED DESCRIPTION
[0032] 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.
[0033] Figure 1 The process of the method of three caches plus GNN reasoning of the present invention is shown. As shown in the figure, a method of three caches accelerating GNN reasoning includes the following steps: S101: pre-sampling according to given parameters; S102: Determine the average out-degree of the node; S103: Determine the reasonable capacity of the adjacency array cache, the node feature cache, and the intermediate layer output cache; S104: Fill node feature and adjacency array caches respectively; S105: Prepare small batches during formal reasoning; S106: After the middle layer reasoning is completed, the output result is stored in the middle layer output cache. Repeat this operation, reasoning layer by layer, until the second to last layer is processed; S107: Perform calculations on the last layer, output the final result, and the reasoning ends.
[0034] Furthermore, the step S101 determines the size of free memory in the GPU during inference by pre-sampling, determines the total memory capacity available for cache allocation, and counts the out-degree of the node and the number of times the node is selected.
[0035] Furthermore, the step S102 calculates the average out-degree of the node.
[0036] Furthermore, the step S103 is to determine the proportion of the neighbor matrix cache, the node feature cache and the intermediate layer output through the graph neural network parameters and the two arrays maintained in step one, and allocate their respective cache capacities in proportion to the total capacity.
[0037] Furthermore, the step S104 will fill the node feature and adjacency array cache.
[0038] Step a: First, fill the node features with out-degree greater than the average value into the feature cache. If there is still capacity left in the feature cache after all the node features with out-degree greater than the average value are filled into the cache, select the nodes with out-degree less than the average degree to continue to fill the remaining capacity, and maintain a hash table to quickly index the location of node feature storage;
[0039] Step b: sort the original CSC array according to the number of times the nodes are selected, and fill the adjacent array cache with the nodes that are selected more times.
[0040] Furthermore, the step S105 will start the formal sampling process.
[0041] Step a: When sampling a node, the sampler will try to access the nth element in the original array. If n is less than the length L of the cache array, the cache hits and the required element is directly obtained from the GPU. Otherwise, the cache misses and the data is obtained from the original CSC array in the host memory through the unified virtual address (UVA) technology.
[0042] Step b: When selecting node features, the feature selector selects node features based on the selected node, and quickly confirms whether the node features are in the feature cache by accessing the hash table. If the cache hits, the required features are directly obtained from the GPU. If the cache misses, the node features are obtained from the host memory through the unified virtual address (UVA) technology.
[0043] Furthermore, after completing the reasoning of the current layer, step S106 stores the hidden state output of the layer in the intermediate layer output cache. When performing the calculation of the next layer, the model directly reads these hidden states from the cache without recalculating or iteratively accessing the nodes of the distant layer, and repeats this operation to calculate layer by layer.
[0044] Furthermore, the step S107 calculates the last layer of the graph neural network, and the output result represents the final processing result of the model on the input graph data, completing the reasoning.
[0045] Example: The ogbn-papers100M dataset is a directed citation graph. Nodes represent papers, and edges represent citation relationships between papers. Each node carries a 128-dimensional feature vector, which is obtained by averaging the word embeddings in the paper title and abstract. The citation relationship between nodes is represented by edges. The entire graph contains 111059956 paper nodes and 1615685872 citation edges. The average degree of the nodes is 29.1. The node prediction task is to predict the subject field labels of the papers in a 172-class classification setting. These labels mainly come from the subject classification in the ARXIV database. The graph data of this dataset is extremely large and complex. The size of the adjacency matrix and node features is about 70GB. Traditional computing methods will incur huge overhead in time and space, and full-graph reasoning will become impossible. At this time, sampling is used to sample subgraphs from the original graph for reasoning to reduce the amount of computation for a single small batch. The steps for implementing triple cache plus GNN reasoning on the ogbn-papers100M dataset are as follows:
[0046] Step 1: Perform pre-sampling according to given parameters, determine the total cache capacity available for allocation according to the workload, and count the node out-degree and the number of times the node neighbors are selected; Pre-sample the test set of the ogbn-papers100M dataset. We set the parameters as follows: pre-batches is 10, feat-dim is 128, batch-size is 8000, hidden-dim is 100, and fanout is "15, 10, 5". According to the above parameters, we pre-sample ten times. During the sampling process, we maintain the adjacency count adj_counts and out-degree array out_degree.
[0047] Step 2: Determine the average out-degree of the node based on the out_degree array; Calculate the average out-degree of the nodes sampled in pre-sampling, for example, out_degree = [16, 100, 25, 13, 56], and the average out-degree can be calculated as
[0048] Step 3: Determine the reasonable capacity of the adjacency array cache, node feature cache, and middle layer output cache; Formulas 1 and 2 can be used to determine the memory occupied by the CSC array and node features in pre-sampling. Formula 3 can determine the size of the intermediate layer output by the number of nodes, where N represents the number of nodes after sampling and deduplication, and T represents the size of the data type. Formulas 4, 5, and 6 can be used to calculate the corresponding percentages of the three. The total capacity determined in step 1 can be proportionally distributed to obtain the cache space of the three.
[0049] Step 4: Fill the node feature and adjacency array caches respectively; The out-degree array out_degree = [16, 100, 25, 13, 56]. We first use the 1st and 4th nodes with out-degree greater than 42 to fill the cache. If the node feature cache is not full after filling, fill the nodes that are not filled into the cache from front to back. When filling, maintain a hash table. The key of the hash table is the node number, and the value represents the address of the feature in the cache space, which is used to quickly find the storage location when selecting features. Figure 2 As shown in Figure 1, it is a directed graph and its corresponding compression coefficient column (CSC). First, we sort by the number of visits (here we simply sort by in-degree), and the sorting result is as follows: Figure 3 As shown, we assume that nodes 0, 2, and 3 are cached according to the number of times they are selected ( Figure 3 (shown in red font in the figure), so we Figure 2 Slice the red font part in the Figure 4 The three arrays shown are populated into the contiguous array buffer.
[0050] Step 5: Prepare small batches during formal reasoning; When sampling a node, the cached CSC array and the original CSC array are passed to the sampler. When the sampler tries to access the nth element of the original array, the cache will hit when n is less than L (L represents the length of the cache array). Figure 3 As shown in the figure, if the sampler accesses the 0th element in the original array, and the adjacent array cache has a total of 3 elements cached in the adjacent array cache, the cache hits because 0 is less than 3. For the cache hit element, the sampling kernel will obtain it from the GPU. Otherwise, the sampling kernel uses UVA technology to obtain data from the original CSC array on the host memory. When selecting features, the feature selector uses the hash table to determine whether the node's features are in the feature cache, for example Figure 5 Nodes 3 and 4 in the figure are in the node feature cache, and data can be directly obtained from the node cache, but node 8 is not in the node cache, and UVA technology is needed to obtain the features of node 8 from the host memory. The reasoning process starts after feature selection is completed.
[0051] Step 6: After the calculation of the middle layer is completed, the output result is stored in the middle layer output cache, and this operation is repeated, reasoning layer by layer until the second to last layer is processed; When sampling a node, the cached CSC array and the original CSC array are passed to the sampler. When the sampler tries to access the nth element of the original array, the cache will hit when n is less than L (L represents the length of the cache array). Figure 3 As shown in the figure, if the sampler accesses the 0th element in the original array, and the adjacent array cache has a total of 3 elements cached in the adjacent array cache, the cache hits because 0 is less than 3. For the cache hit element, the sampling kernel will obtain it from the GPU. Otherwise, the sampling kernel uses UVA technology to obtain data from the original CSC array on the host memory. When selecting features, the feature selector uses the hash table to determine whether the node's features are in the feature cache, for example Figure 5 Nodes 3 and 4 in the figure are in the node feature cache, and data can be directly obtained from the node cache, but node 8 is not in the node cache, and UVA technology is needed to obtain the features of node 8 from the host memory. The reasoning process starts after feature selection is completed.
[0052] Step 7: Perform the calculation of the last layer, output the final result, and the reasoning ends; By loading the output of the second-to-last layer from the cache, the output of the last layer can be quickly calculated to obtain the final result and complete the reasoning.
[0053] The flowchart of the three-cache method for accelerating GNN reasoning proposed above is shown in Figure 5. Since this method only requires a few small batch pre-sampling and simple calculations to quickly allocate the respective cache capacities. Before formal reasoning, a lightweight cache filling algorithm is used to quickly fill the feature cache and the adjacent array cache to reduce redundant loading. During the reasoning process, the output of the intermediate layer is cached to reduce redundant calculations, accelerate the three stages of sampling, feature selection and calculation in GNN reasoning, and improve the overall operating efficiency of the system.
[0054] 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 method for accelerating GNN reasoning using three caches, characterized in that: The three-cache method for accelerating GNN reasoning includes the following steps: Step 1: Pre-sampling according to given parameters; Step 2: Determine the average out-degree of the node; Step 3: Determine the reasonable capacity of the adjacency array cache, node feature cache, and intermediate layer output cache; Step 4: Fill the node feature and adjacency array caches respectively; Step 5: Prepare small batches during formal reasoning; Step 6: After the calculation of the middle layer is completed, the output result is stored in the middle layer output cache, and this operation is repeated, reasoning layer by layer until the second to last layer is processed; Step 7: Perform the calculation of the last layer, output the final result, and the reasoning ends.
2. The method for accelerating GNN reasoning using three caches as claimed in claim 1, characterized in that: The step 1 determines the total capacity that can be used for cache allocation through the workload during pre-sampling, and maintains two arrays for counting the node out-degree and the number of times the node neighbor is selected.
3. The method for accelerating GNN reasoning using three caches as claimed in claim 1, characterized in that: The step 2 calculates the average out-degree of the node based on the node out-degree array maintained in the step 1.
4. The method for accelerating GNN reasoning using three caches as claimed in claim 1, characterized in that: The step three determines the proportion of the neighbor array cache, the node feature cache and the intermediate layer output cache through the graph neural network parameters and the two arrays maintained in the step one, and allocates their respective cache capacities in proportion to the total cache capacity.
5. The method for accelerating GNN reasoning using three caches as claimed in claim 1, characterized in that: The step 4 fills the node feature and adjacency array caches respectively. The node feature cache is stored in a hash table, and the adjacency array cache adopts a structure similar to the compressed sparse column (CSC) format. The specific steps are as follows: Step a: Determine whether to fill the feature cache based on whether its out-degree is greater than the average value. If there is still remaining capacity after all nodes with out-degree greater than the average degree are filled, select nodes with out-degree less than the average degree to fill the remaining capacity, and maintain a hash table to quickly index the location of node feature storage; Step b: sort the original CSC array according to the number of times the nodes are selected, fill the adjacent array cache with the nodes with more selected times, and also store them in the CSC format in the cache.
6. The method for accelerating GNN reasoning using three caches as claimed in claim 1, characterized in that: In the process of preparing a small batch for formal reasoning, the step 5 obtains data from the GPU memory and the host memory for reasoning according to whether the cache hits or not. The specific steps are as follows: Step a: When sampling a node, the sampler will try to access the nth element in the original array. If n is less than the length L of the cache array, the cache hits and the required element is directly obtained from the GPU. Otherwise, the cache misses and the data is obtained from the original CSC array in the host memory through the unified virtual address (UVA) technology. Step b: When selecting node features, the feature selector selects node features based on the selected node, and quickly confirms whether the node features are in the feature cache by accessing the hash table. If the cache hits, the required features are directly obtained from the GPU. If the cache misses, the node features are obtained from the host memory through the unified virtual address (UVA) technology.
7. The method for accelerating GNN reasoning using three caches as claimed in claim 1, characterized in that: In step 6, after completing the reasoning of the current layer, the hidden state output of the layer is stored in the intermediate layer output cache. When performing the next layer calculation, the model directly reads these hidden states from the cache without recalculating or iteratively accessing the nodes of the distant layer. This operation is repeated for calculation layer by layer.
8. The method for accelerating GNN reasoning using three caches as claimed in claim 1, characterized in that: The step seven described above calculates the last layer of the graph neural network, and the output result represents the final processing result of the model on the input graph data, completing the reasoning.
