A sequential optimization graph attention network algorithm and hardware accelerator thereof

By optimizing the computation order of the graph attention network algorithm and the design of the hardware accelerator, the problems of high computational complexity and large storage resource consumption of the graph attention network algorithm are solved, and more efficient hardware accelerator computing is achieved.

CN118333116BActive Publication Date: 2026-11-27SUN YAT SEN UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410507421.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-25
Publication Date
2026-11-27
Estimated Expiration
2044-04-25

AI Technical Summary

Technical Problem

Existing graph attention network algorithms suffer from high computational complexity, high computational latency, and high storage resource consumption, making it impossible for hardware accelerators to execute graph attention network algorithms efficiently.

Method used

By optimizing the computation order of the graph attention network algorithm, the attention stage and the aggregation stage are split and recombined, and the division operation is moved to the final embedding expression computation. Combined with a distributed fine-grained storage scheme, a hardware accelerator is designed to achieve parallel computing and storage optimization.

Benefits of technology

It reduces computational complexity, decreases the number of division operations, improves computational parallelism, reduces storage resource consumption, and enhances the computational efficiency of hardware accelerators.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118333116B_ABST
    Figure CN118333116B_ABST
Patent Text Reader

Abstract

The application discloses a kind of computing sequential optimization graph attention network algorithm and its hardware accelerator, and optimization method includes: the attention stage and aggregation stage in the computing stage of graph attention network algorithm are split and reorganized into one aggregation stage;In aggregation stage, when the calculation of attention weight is carried out, the division operation in attention weight is moved backward, and the final embedding expression z i Of node is calculated again, and the multiplication-addition operation in the final embedding expression of node is moved forward;According to the data obtained in combination stage, the final embedding expression of node is calculated according to the above steps.The application reduces the number of operations by optimizing the computing sequence of graph attention network algorithm, and reduces the computational complexity.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of machine learning technology, and in particular to a graph attention network algorithm with optimized computational order and its hardware accelerator. Background Technology

[0002] Graph Neural Networks (GNNs) have become an effective method for processing graph data, a non-Euclidean domain data structure, demonstrating advantages that traditional neural networks cannot match in various application scenarios such as social networks, transportation networks, and chemical molecular structures. GNNs introduce an attention mechanism, using attention coefficients to distinguish the importance of different neighbors of a node, focusing on the most prominent and important parts of the data, and using weighted summation for feature aggregation, resulting in better representation capabilities.

[0003] Graph Attention Networks (GAT) algorithms consist of three main stages: the combination stage, the attention stage, and the aggregation stage. Like other GNN algorithms, GAT exhibits hybrid computational characteristics. In the combination stage, feature transformations and similarity constant calculations are regular and intensive. However, the attention and aggregation stages heavily rely on the adjacency information of the graph data, involving numerous irregular and sparse memory access operations. Furthermore, the attention stage includes complex computations such as softmax.

[0004] The algorithmic characteristics of Graph Attention Networks (GATs) make it difficult for the two most commonly used computing architectures, CPUs and GPUs, to efficiently perform the forward inference process of GATs. CPUs lack sufficient computing power and suffer from significant latency when faced with the intensive computations of the combination phase; while GPUs are inefficient and consume a lot of power when faced with the irregular and sparse memory accesses and operations of the attention and aggregation phases. Advanced FPGAs, on the other hand, integrate abundant storage, computation, logic, and bus resources, and possess both powerful parallel computing capabilities and flexibility, making them suitable as a platform for GAT hardware accelerator architectures.

[0005] Existing hardware accelerators still suffer from high inference latency and high storage resource consumption, failing to address the problems of high computational complexity, computational parallelism, high inference latency, and high storage resource consumption caused by the characteristics of the GAT algorithm. Summary of the Invention

[0006] To address the high computational complexity caused by the characteristics of GAT algorithms in existing technologies, a graph attention network algorithm with optimized computation order and its hardware accelerator are proposed. By optimizing the computation order of the graph attention network algorithm, the number of operations is reduced, thereby lowering the computational complexity.

[0007] The technical solution of the present invention is as follows:

[0008] A graph attention network algorithm with optimized computational order, comprising:

[0009] The computational phases of the graph attention network algorithm include the combination phase, the attention phase, and the aggregation phase.

[0010] The attention phase and the convergence phase are separated and reorganized into a single convergence phase;

[0011] In the aggregation stage after splitting and recombining, when calculating attention weights, the division operation in the attention weights is moved to the end, and it is performed in the final embedding expression z of the computation node. i Then perform the calculation again, and move the multiply-accumulate operation in the final embedded expression of the node to the front;

[0012] Based on the data calculated in the combination phase, the final embedded representation of the node is calculated according to the steps of the aggregation phase after splitting and recombining.

[0013] Furthermore, the computation process of the graph attention network algorithm after splitting and recombining under a single attention head includes the following:

[0014] First, the features of different types of nodes are projected onto the same feature space, i.e., a combination operation is performed; then, the original feature vectors h of the nodes are weighted by the corresponding weight matrix W. i Perform the conversion:

[0015] h′ i =Wh i (1)

[0016] Then, attention weight a is calculated. ij Calculation;

[0017]

[0018] Finally, the final embedding representation z of the node is computed. i ;

[0019] Where e ij a is the attention coefficient. T represents the attention kernel weight matrix, ij represents the node pair of source node-neighbor target node, i represents the source node, j represents the neighbor node of the source node, i.e. the neighbor target node; || represents the concatenation operation, and LeakyReLU represents a non-linear activation function;

[0020] If we decompose equation (2) for the calculation of attention weights, extract the dense computation part, and use matrix form to represent the combination operation, then the algorithm process under a single attention head can be represented by equations (3) to (7) below.

[0021] H′=HW (3)

[0022] H′(a1||a2)=H′a1||H′a2=p||q (4)

[0023] e ij =σ(p i +q j (5)

[0024]

[0025]

[0026] Where H represents the feature matrix, H′ represents the combined result of all nodes, p represents the left similarity constant, q represents the right similarity constant, W is the weight matrix, and a1 represents the attention kernel matrix. The left attention kernel matrix in the diagram, where a2 represents the attention kernel matrix. The right attention kernel matrix in the diagram, where σ represents the activation operation, and z i This represents the final embedded representation of the node;

[0027] Because in the calculation of attention weights in equation (6), the denominator needs to accumulate the attention coefficients e of all node pairs. ij After traversing all the neighboring nodes of the source node i, the calculation of equation (6) is completed. Therefore, the aggregation calculation of equation (7) needs to wait for the calculation result of equation (6).

[0028] Substitute equation (6) into equation (7), and then use the distributive property of multiplication to convert the fractions. Extracting this makes the division operation in equation (14) shift to the end, so that it is calculated only when the node is embedded in the final calculation, and makes the multiplication and addition operations in equation (6) a prerequisite, resulting in the following equations (8)(9)(10):

[0029] e′ ij =exp(e ij (8)

[0030]

[0031]

[0032] Among them, e′ ij For e ij The intermediate result obtained after performing exponentiation, a′ iThis represents information about all neighboring target nodes of the source node in the aggregation;

[0033] Equations (3) and (4) above represent the combination stage of the graph attention network algorithm, while equations (8), (9), (10) and (18) above represent the aggregation stage.

[0034] Furthermore, in the graph attention network algorithm, the combination operation of each attention head yields a corresponding combination result, left similarity constant, and right similarity constant;

[0035] When the number of attention heads is k, there are k different combinations of results H′, left similarity constant p, and right similarity constant q.

[0036] Furthermore, under multiple attention heads, the final embedding representation of a node is calculated as follows:

[0037] The calculation results of K attention heads are concatenated in the intermediate layer, and then... This indicates that the calculation results of the K attention heads are averaged at the output layer.

[0038] Intermediate layer:

[0039] Output layer:

[0040] The graph attention network algorithm has a multi-layer structure, which can be viewed as multiple computation processes. The output layer is the last computation process, while the intermediate layers are each computation process except for the output layer.

[0041] A hardware accelerator for a computationally optimized graph attention network algorithm, employing the aforementioned computationally optimized graph attention network algorithm, includes:

[0042] External storage, main controller, combination module, aggregation module;

[0043] The external memory is used to store graph data and calculation results output by the aggregation module;

[0044] The main controller is used to load slices of graph data from external memory into the on-chip memory of the FPGA and control the switching of computing tasks.

[0045] The combination module is used to complete the combination stage operation of the graph attention network algorithm and pass the result to the aggregation module;

[0046] The aggregation module is used to complete the aggregation stage operation of the graph attention network algorithm and obtain the final embedding representation of the node as the output calculation result.

[0047] Furthermore, the aggregation module includes several aggregation calculation modules and an aggregation result synchronization module;

[0048] The aggregation calculation module is used to index the on-chip cache and complete the aggregation calculation task;

[0049] The aggregation result synchronization module is used to receive the final embedded expression z of the computing node after receiving the calculation results from each aggregation calculation module. i And store it in the on-chip cache.

[0050] Furthermore, the aggregation calculation module includes an index submodule and a calculation submodule;

[0051] The index submodule includes an index controller, a left similarity constant cache block, a right similarity constant cache block, a combination result cache block, and an adjacency information cache block;

[0052] The computation submodule includes a first computation array, a coefficient register, and a product register;

[0053] The index controller is used to read the data of each on-chip cache according to the input source node number and transmit the data to the computing submodule;

[0054] The left similarity constant cache block, right similarity constant cache block, combination result cache block, and adjacency information cache block are all used to cache their corresponding data;

[0055] The first computing array includes a first computing unit; the first computing array is used to receive data output by the index controller;

[0056] The first calculation unit includes a vector processing unit; the vector processing unit is used to receive data output by the index controller and calculate attention coefficients and products;

[0057] The coefficient register is used to cache attention coefficients; the product register is used to cache product registers;

[0058] The computation unit accumulates the attention coefficients and products calculated by the vector processing unit through the coefficient register and product register.

[0059] After the calculation of all neighbor nodes in the adjacency information cache in the index submodule is completed, the calculation submodule outputs the data stored in the coefficient register and product register to the aggregation result synchronization module.

[0060] Furthermore, the aggregation result synchronization module includes a second computing array, a splicing computing unit, and an aggregation result cache block;

[0061] The second computing array includes a second computing unit; the second computing unit is used to receive and superimpose partial sums from various aggregation computing modules, and then compute the embedded representation of the nodes;

[0062] The splicing calculation unit is used to splice or average the results of each second calculation unit to obtain the final embedded expression of the node;

[0063] The aggregation result cache block is used to store the final embedded representation of a set of source nodes.

[0064] Furthermore, for k different combination results H′, left similarity constant p and right similarity constant q, there are k corresponding caches and k corresponding index controllers, and a computing array composed of k computing units is used for parallel operation. The splicing operation unit is responsible for splicing or averaging the computing results under k attention heads to obtain the final embedding expression of the node.

[0065] Each aggregation computing module is configured with several on-chip caches, and the on-chip caches are split according to different attention heads, so that each on-chip cache corresponds to an attention head.

[0066] Furthermore, the aggregation computing module adopts a pipelined design.

[0067] The index submodule serves as the first pipeline stage;

[0068] The first computing unit includes a second pipeline stage, a third pipeline stage, and a fourth pipeline stage;

[0069] The second pipeline stage includes an adder and a non-linear arithmetic unit;

[0070] The third stage includes an exponentiation calculator;

[0071] The fourth pipeline stage includes one multiplier and two accumulators;

[0072] Each of the second, third, and fourth pipeline stages has a register to store the number i of the source node being processed by the corresponding pipeline stage, enabling each pipeline stage to process the computations of different source nodes in parallel.

[0073] The beneficial effects of this invention are:

[0074] 1. By changing the computation order of the graph attention network, the proposed computation order optimization algorithm reduces the number of division operations in the corresponding hardware accelerator, thereby reducing the computational complexity.

[0075] 2. Through the aggregation module of the hardware accelerator, each aggregation computing module can aggregate tasks in parallel, solving the problem of low computational parallelism. Attached Figure Description

[0076] Figure 1 A schematic diagram illustrating the steps of the graph attention network algorithm with optimized computation order provided in this embodiment.

[0077] Figure 2 The block diagram shows the structure of a hardware accelerator for a graph attention network algorithm with optimized computation order provided in the embodiment.

[0078] Figure 3 The structural block diagram of the aggregation module provided in the embodiment.

[0079] Figure 4 The structural block diagram of the aggregation result synchronization module provided in the embodiment.

[0080] Figure 5 This is a schematic diagram illustrating the division and sequence of computational tasks provided in this embodiment.

[0081] Figure 6 This is a schematic diagram of the calculation process in the aggregation calculation module provided in the embodiment.

[0082] Figure 7 This is a schematic diagram of an aggregation computing task provided for an embodiment.

[0083] Figure 8 This is a schematic diagram of the pipeline for the aggregation computing module provided in the embodiment. Detailed Implementation

[0084] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments.

[0085] Example 1

[0086] In this embodiment, as Figure 1 As shown, a graph attention network algorithm with optimized computation order includes the following: the computation stages of the graph attention network algorithm include a combination stage, an attention stage, and an aggregation stage;

[0087] The attention phase and the convergence phase are separated and reorganized into a single convergence phase;

[0088] In the aggregation stage after splitting and recombining, when calculating attention weights, the division operation in the attention weights is moved to the end, and it is performed in the final embedding expression z of the computation node. i Then perform the calculation again, and move the multiply-accumulate operation in the final embedded expression of the node to the front;

[0089] Based on the data calculated in the combination phase, the final embedded representation of the node is calculated according to the steps of the aggregation phase after splitting and recombining.

[0090] In this embodiment, the combination stage includes: performing intensive calculations on weight data, feature data, and attention kernel values ​​to obtain the combination result H′ of all nodes, the left similarity constant p, and the right similarity constant q.

[0091] Intensive computation refers to the fact that since the weight matrix and attention kernel are dense (i.e., there are no zero values ​​in the matrix), and the feature matrix data is also denser than the adjacent matrix data, the combination stage requires a large number of calculations, making it a computationally intensive operation stage.

[0092] More specifically, the computation process of the graph attention network algorithm after splitting and recombining under a single attention head includes the following:

[0093] First, the features of different types of nodes are projected onto the same feature space, i.e., a combination operation is performed; then, the original feature vectors h of the nodes are weighted by the corresponding weight matrix W. i Perform the conversion:

[0094] h′ i =Wh i (1)

[0095] Then, attention weight a is calculated. ij Calculation;

[0096]

[0097] Finally, the final embedding representation z of the node is computed. i ;

[0098] Where e ij a is the attention coefficient. T represents the attention kernel weight matrix, ij represents the node pair of source node-neighbor target node, i represents the source node, j represents the neighbor node of the source node, i.e. the neighbor target node; || represents the concatenation operation, and LeakyReLU represents a non-linear activation function;

[0099] If we decompose equation (2) for the calculation of attention weights, extract the dense computation part, and use matrix form to represent the combination operation, then the algorithm process under a single attention head can be represented by equations (3) to (7) below.

[0100] H′=HW (3)

[0101] h′(a1||a2)=H′a1||H′a2=p||q (4)

[0102] e ij =σ(p i +q j (5)

[0103]

[0104]

[0105] Where H represents the feature matrix, H′ represents the combined result of all nodes, p represents the left similarity constant, q represents the right similarity constant, W is the weight matrix, and a1 represents the attention kernel matrix. The left attention kernel matrix in the diagram, where a2 represents the attention kernel matrix. The right attention kernel matrix in the diagram, where σ represents the activation operation, and z i This represents the final embedded representation of the node;

[0106] Because in the attention weight calculation of equation (6), the denominator needs to accumulate the attention coefficients e of all node pairs. ij After traversing all the neighboring nodes of the source node i, the calculation of equation (6) is completed. Therefore, the aggregation calculation of equation (7) needs to wait for the calculation result of equation (6).

[0107] Under the original computation sequence, the hardware design can only form a stage-level pipeline between the attention weight calculation stage and the aggregation stage, and cannot perform node-pair-level pipeline design, resulting in large latency. Furthermore, since a division needs to be calculated for each node pair, the corresponding hardware design will contain a large number of division operations.

[0108] To solve the above problem, substitute equation (6) into equation (7), and then use the distributive property of multiplication to convert the fractions... Extracting the division operation in equation (14) shifts it to the end and is calculated only when the node embedding expression is finally calculated. This also makes the multiplication and addition operation in equation (6) a prerequisite, resulting in equations (8)(9)(10) below. This calculation process no longer requires division for each node pair and enables the hardware circuit to form a node pair-level pipeline, which helps to reduce computational latency.

[0109] e′ ij =exp(e ij (8)

[0110]

[0111]

[0112] Among them, e′ ij For e ij The intermediate result obtained after performing exponentiation, a′ i This represents information about all neighboring target nodes of the source node in the aggregation;

[0113] Equations (3) and (4) above represent the combination stage of the graph attention network algorithm, while equations (8), (9), (10) and (18) above represent the aggregation stage.

[0114] More specifically, in the graph attention network algorithm, the combination operation of each attention head yields a corresponding combination result, left similarity constant, and right similarity constant;

[0115] When the number of attention heads is k, there are k different combinations of results H′, left similarity constant p, and right similarity constant q.

[0116] Under multiple attention heads, the final embedding representation of a node is calculated as follows:

[0117] The calculation results of K attention heads are concatenated in the intermediate layer, and then... This indicates that the calculation results of the K attention heads are averaged at the output layer.

[0118] Intermediate layer:

[0119] Output layer:

[0120] The graph attention network algorithm has a multi-layer structure, which can be viewed as multiple computation processes. The output layer is the last computation process, while the intermediate layers are each computation process except for the output layer.

[0121] Example 2

[0122] In this embodiment, a hardware accelerator for a graph attention network algorithm with optimized computation order employs the graph attention network algorithm with optimized computation order as described in Embodiment 1, comprising:

[0123] External storage, main controller, combination module, aggregation module;

[0124] The external memory is used to store graph data and calculation results output by the aggregation module;

[0125] The main controller is used to load slices of graph data from external memory into the on-chip memory of the FPGA and control the switching of computing tasks.

[0126] The combination module is used to complete the combination stage operation of the graph attention network algorithm and pass the result to the aggregation module;

[0127] The aggregation module is used to complete the aggregation stage operation of the graph attention network algorithm, and obtain the final embedding representation z of the node. i The calculation results are output.

[0128] The aggregation module includes several aggregation calculation modules and an aggregation result synchronization module;

[0129] The aggregation calculation module is used to index the on-chip cache and complete the aggregation calculation task;

[0130] The aggregation result synchronization module is used to receive the final embedded expression z of the computing node after receiving the calculation results from each aggregation calculation module. i And store it in the on-chip cache.

[0131] Because graph data is typically large, the on-chip memory of an FPGA can only store a portion of the graph data, i.e., slices of the graph data. Therefore, external memory is needed to store a complete graph. The main controller loads slices of graph data from external memory into the FPGA's on-chip memory. After the accelerator completes its calculation on a slice, the main controller sends the calculation result obtained by the accelerator back to the external memory and loads a new slice into the FPGA's on-chip memory. Furthermore, the main controller controls the switching of computational tasks within the hardware circuitry.

[0132] The aggregation calculation module includes an index submodule and a calculation submodule;

[0133] The index submodule includes an index controller, a left similarity constant cache block, a right similarity constant cache block, a combination result cache block, and an adjacency information cache block;

[0134] The computation submodule includes a first computation array, a coefficient register, and a product register;

[0135] The index controller is used to read the data of each on-chip cache according to the input source node number and transmit the data to the computing submodule;

[0136] The left similarity constant cache block, right similarity constant cache block, combination result cache block, and adjacency information cache block are all used to cache their corresponding data;

[0137] The first computing array includes a first computing unit; the first computing array is used to receive data output by the index controller;

[0138] The first computing unit includes a vector processing unit; the vector processing unit is used to receive the data output by the index controller and calculate the attention coefficients and products; Vector Processing Unit, abbreviated as VPU.

[0139] The coefficient register is used to cache attention coefficients; the product register is used to cache product registers;

[0140] The first calculation unit accumulates the attention coefficients and products obtained by the vector processing unit through the coefficient register and product register.

[0141] After the calculation of all neighbor nodes in the adjacency information cache in the index submodule is completed, the calculation submodule outputs the data stored in the coefficient register and product register to the aggregation result synchronization module.

[0142] The aggregation result synchronization module includes a second computing array, a splicing computing unit, and an aggregation result cache block;

[0143] The second computing array includes a second computing unit; the second computing unit is used to receive and superimpose partial sums from various aggregation computing modules, and then compute the embedded representation of the nodes;

[0144] The splicing calculation unit is used to splice or average the results of each second calculation unit to obtain the final embedded expression of the node;

[0145] The aggregation result cache block is used to store the final embedded representation of a set of source nodes, i.e., the aggregation result. The aggregation result cache stores the aggregation result of a set of source nodes.

[0146] More specifically, for k different combination results H′, left similarity constant p and right similarity constant q, there are k corresponding caches and k corresponding index controllers, and a computing array composed of k computing units is used for parallel operation. The splicing operation unit is responsible for splicing or averaging the computing results under k attention heads to obtain the final embedding expression of the node.

[0147] Each aggregation computing module is configured with several on-chip caches, and the on-chip caches are split according to different attention heads, so that each on-chip cache corresponds to an attention head.

[0148] This hardware accelerator architecture employs a distributed, fine-grained storage scheme, which eliminates memory access conflicts, thereby ensuring computational parallelism while limiting the exponential growth of on-chip storage resource consumption.

[0149] The aggregation phase of a graph attention network (GAT) requires four types of data: left similarity constant, right similarity constant, adjacency information, and combination results. If four coarse-grained on-chip caches are used to store these four types of data from a single graph slice, each aggregation module would need to share these caches. This results in high bandwidth requirements for data transmission, and memory access conflicts occur when different aggregation modules access data at the same address in storage, preventing parallel operation. While copying these four on-chip caches multiple times, with each cache corresponding to one aggregation module, can eliminate memory access conflicts, the large amount of data required for aggregation due to the characteristics of the GAT algorithm means this approach would consume significant on-chip storage resources.

[0150] Therefore, a distributed, fine-grained storage scheme is adopted. Each aggregation computing module has an on-chip cache for the four types of data. The data is split according to the different computing tasks of each aggregation computing module. Specifically, the data is divided into multiple groups based on the target nodes, with each group corresponding to the computing task of one aggregation computing module. The split data is stored in the on-chip cache of each aggregation computing module, enabling each module to process aggregation tasks of the same group of source nodes and different groups of neighboring target nodes in parallel. Furthermore, the on-chip cache is further split according to different attention heads, so that each on-chip cache block corresponds to one attention head. This allows aggregation operations under different attention heads to be executed in parallel without memory access conflicts. This storage scheme allocates on-chip storage based on the computing tasks of each aggregation computing module, rather than simply copying the data. Therefore, it can control the consumption of on-chip storage resources while ensuring computational parallelism, preventing it from increasing exponentially with the number of aggregation computing modules.

[0151] More specifically, the aggregation computing module adopts a pipelined design approach;

[0152] The index submodule serves as the first pipeline stage;

[0153] The first computing unit includes a second pipeline stage, a third pipeline stage, and a fourth pipeline stage;

[0154] The second pipeline stage includes an adder and a non-linear arithmetic unit;

[0155] The third stage includes an exponentiation calculator;

[0156] The fourth pipeline stage includes one multiplier and two accumulators;

[0157] The hardware circuits of each pipeline stage can work simultaneously and perform indexing or computational tasks at different node pairs in parallel.

[0158] Each of the second, third, and fourth pipeline stages has a register to store the number i of the source node being processed by the corresponding pipeline stage. This allows each pipeline stage to process computations from different source nodes in parallel, and the pipeline will not be blocked when switching between computation tasks from different source nodes.

[0159] When the number of node pairs is M and the number of nodes is N, the number of divisions in the algorithm process under the original calculation order is M, while the number of divisions in the algorithm process under the optimized calculation order is N, which is reduced by a factor of M / N.

[0160] Example 3

[0161] In this embodiment, according to the hardware accelerator of the graph attention network algorithm with optimized computation order described in Embodiment 2, the main controller loads a slice of graph data from external memory into the on-chip storage of the FPGA and controls the accelerator to start computation. The combination module completes the intensive computation of the combination stage in equations (3) and (4) of the algorithm using the input weight data, feature data, and attention kernel value, and calculates the combination result H′ of all nodes, the left similarity constant p, and the right similarity constant q. The main controller then transmits these data to the aggregation module. The aggregation module completes equations (8) to (10) of the aggregation stage according to the GAT algorithm with optimized computation order, and obtains the final embedding expression of the node. After the accelerator completes the computation of the slice, the main controller transmits the computation result obtained by the accelerator back to the external memory and loads a new slice into the on-chip storage of the FPGA.

[0162] like Figure 3 As shown, the workflow of the aggregation module is explained in detail, taking the calculation process of a source node as an example, combined with the optimized algorithm process of the calculation order.

[0163] The main controller transmits the calculation results of the combination module to the aggregation module for storage, as shown in the combination result cache, left similarity constant cache and right similarity constant cache in the figure, and transmits the adjacency information from the external memory to the aggregation module for storage, as shown in the adjacency information cache in the figure.

[0164] Once all the necessary data for the operation is ready, the indexing operation is performed. The index controller first retrieves the left similarity constant p of a source node from the left similarity constant cache. i The second step involves the index controller retrieving a neighboring target node number j from the adjacency information cache based on the source node number i. Then, based on the number j, the controller retrieves the combination result g′ of its neighboring nodes from the combination result cache and the right similarity constant cache, respectively. j and its right similarity constant q j After completing the above steps, the index controller will obtain i and p. i h′ j and q j Pass it to the calculation part.

[0165] Then, the computation operation is performed. The VPU in one of the computational units in the computation array first executes equations (5) and (8) to complete the attention coefficient e′ of the node pair. ij The calculation unit also accumulates the attention coefficient e′ obtained from the VPU through the coefficient register. ij , as the denominator in the division of equation (10). Then, the VPU executes equation (9) to convert the attention coefficient e′. ij Combined result h′ j Multiply, and accumulate the product e′ through a product register. ijh′ j This completes the main aggregation phase operation between the source node i and one of its neighboring target nodes j. The process then returns to the second step of the indexing phase to perform the operation between the source node i and its next neighboring target node.

[0166] Once all neighboring target nodes of source node i in the adjacency information cache have completed the above operations, the coefficient sum and product sum belonging to the aggregation calculation module are obtained. These two partial sums and the corresponding source node number i are input into the aggregation result synchronization module, and the coefficient register and product register are cleared.

[0167] The aggregation result synchronization module receives the partial sums from all aggregation calculation modules, completes the remaining calculations, and obtains the aggregation result. Specifically, for example... Figure 4 As shown, by superimposing the coefficients from each aggregation calculation module, the denominator of the fraction in equation (10) is obtained. The sum of the superimposed products gives the numerator a′ of the fraction in equation (10). i Dividing the sum of the coefficients obtained after superposition by the sum of the products, and then performing an ELU nonlinear activation operation on the division result, yields the node embedding representation of source node i under a certain attention head. The subsequent concatenation unit performs concatenation or averaging operations on the node embeddings of different attention heads to obtain the final aggregation result z. i Finally, the aggregation result synchronization module stores the result in the aggregation result cache using the source node number i as the address.

[0168] like Figure 5 The diagram shows the method for dividing the computational tasks of each aggregation computation module, as well as the computational order of the aggregation modules.

[0169] Figure 5 The leftmost matrix represents the adjacency matrix of a complete graph, with the vertical axis representing the source node number i, the horizontal axis representing the target node number j, and the arrows indicating the calculation order of each slice.

[0170] Figure 5 The rectangle in the middle represents a slice of graph data. When the number of aggregation computing modules is N, a slice is divided into N sub-slices. Each sub-slice corresponds to a computing task of an aggregation computing module. These sub-slices are computed in parallel in different aggregation computing modules. The computing tasks in the sub-slices are also divided into multiple source node groups, and the arrows indicate the computing order of each group.

[0171] Specifically, the main controller, based on the computational tasks of each aggregation module, divides the combination results, right similarity constants, and adjacency information into sub-slices according to the target node numbers, and stores them in separate on-chip storage for each aggregation module; the target node number is represented by the horizontal coordinate of the adjacency matrix. Within one sub-slice, the main controller divides the left similarity constants calculated by the combination module into groups based on the source nodes, and each time transfers one group to the left similarity constant cache of a different aggregation module; the source node is represented by the column coordinate of the adjacency matrix. For example... Figure 5 As indicated by the arrow in the middle rectangle, after an aggregation calculation module completes the calculation of a group of source nodes in a sub-slice, the main controller sequentially transmits the left similarity constant of the next group of source nodes in the sub-slice to the aggregation module and begins to execute the calculation of the next group of source nodes.

[0172] Figure 5 The rectangle on the right represents a set of computational tasks within a sub-slice. White squares indicate nodes without connections, while dark squares represent nodes with connections, specifically a source node and its neighboring target node. The computation order is shown by the arrows in the diagram. Solid arrows indicate the sequential computation of all node pairs for a source node within the sub-slice. When a solid arrow reaches the end of a row in the matrix, it means all neighboring target nodes of the source node in the current sub-slice have completed their computations in the aggregation module. Subsequently, dashed arrows point to the beginning of the next row, indicating that the index controller retrieves the left similarity constant and node number of the next source node from the left similarity constant cache and begins executing the computation for that next source node.

[0173] like Figure 6 The diagram shown is a detailed block diagram of the computation section in the aggregation computation module. The computation section is divided into three pipeline stages: stage 1 is the second pipeline stage, stage 2 is the third pipeline stage, and stage 3 is the fourth pipeline stage.

[0174] Stage 1 receives the input left and right similarity constants and performs the addition and nonlinear activation operations in algorithm (5); nonlinear activation operation: LeakyReLU; Stage 2 performs the exponential operation in algorithm (8) to obtain the attention coefficient e′. ij Pass to the next stage; Exponential operation: exp; Stage 3 executes formula (9), and the combined result h′ of the input is passed to the next stage. j and attention coefficient e′ ij Multiply and convert the product e′ ij h′ j Attention coefficient e′ of the input ijThe results are accumulated into the corresponding positions of source node i in the product register and coefficient register, respectively. A register is set up in the hardware circuit of each stage to store the source node number i being processed in each stage, so that the partial sum calculated in stage 3 can be accumulated into the correct positions in the registers.

[0175] like Figure 7 The diagram shows an example of a set of computation tasks in the aggregation computation module. White squares represent two nodes that are not connected, while squares with letters represent two nodes that are connected, indicating that the corresponding node pairs have aggregated computation tasks. Squares of the same shade represent computation tasks originating from the same source node.

[0176] like Figure 8 The diagram illustrates the pipelined execution process of the aggregation computing module. The horizontal axis represents the computation time, and the vertical axis represents each pipeline stage. In each pipeline stage, a square represents the corresponding hardware circuit in operation, and the letters within the square correspond to... Figure 8 The letters within the squares correspond to the node pairs to which the square belongs. Due to the possible differences in execution time between pipeline stages, the length of the squares may vary. Stages with shorter execution times must wait for the pipeline stage with the longest execution time to finish before they can begin executing the task of the next node pair. Therefore, there may be gaps between squares, indicating that the hardware circuitry of the corresponding pipeline stage is in an idle state.

[0177] Combination Figure 6 , 7 Section 8 describes the pipeline execution process of the aggregation calculation module. Figure 7 The computational tasks shown are performed in alphabetical order.

[0178] First, the indexing part indexes based on the node number of the source node 1 to obtain the relevant data of the neighboring target node 1, thus completing the indexing task of node a.

[0179] The execution of Phase 1 depends on the indexing results; therefore, Phase 1 can only begin calculating 'a' after the indexing of 'a' is complete. While Phase 1 is calculating 'a', the indexing part simultaneously performs the indexing task for the next node pair. Here, the next node pair refers to node pair 'b'.

[0180] The execution of Phase 2 depends on the result of Phase 1. Therefore, Phase 2 can only begin calculating 'a' after Phase 1's calculation of 'a' is completed. While Phase 2 is calculating 'a', Phase 1 simultaneously performs the calculation task for the next node pair. Here, the next node pair refers to node pair 'b'.

[0181] Similarly, only after the calculation of stage 2 of node a is completed can the calculation of node a begin in stage 3. Simultaneously, the hardware circuitry of stage 2 begins the calculation task for the next node pair. Here, the next node pair refers to node pair b. The execution process of tasks after node a follows the same logic as described above.

[0182] like Figure 8 As shown, at time 4, stage 3 completes the calculation of task 'a', at which point the pipeline of the aggregation calculation module is full. From this time until time 11, the aggregation calculation module outputs the calculation result of one node pair at each time. The time between time 0 and 4 is the pipeline throughput time, corresponding to the time from when the first task 'a' enters the pipeline to when it completes its calculation. The time between time 4 and 7 is the pipeline steady-state operating time. During this period, the hardware circuits of all four pipeline stages are in operation, processing different stage tasks of different node pairs in parallel. The time between time 7 and 11 is the pipeline drain time, corresponding to the time from when the last task 'h' enters the pipeline to when it completes its calculation.

[0183] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the present invention, and are not intended to limit the implementation of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the claims of the present invention.

Claims

1. A method for optimizing the computation order of a graph attention network algorithm, characterized in that, The algorithm used by the graph attention network hardware accelerator for forward inference computation of graph data includes the following: The computational phases of the graph attention network algorithm include the combination phase, the attention phase, and the aggregation phase. The attention phase and the convergence phase are separated and reorganized into a single convergence phase; In the aggregation stage after splitting and reorganizing, when calculating attention weights, the division operation in the attention weight calculation is moved to the end, in the final embedding expression of the computation node. Then perform the calculation again, and move the multiply-accumulate operation in the final embedded expression of the node to the front; Based on the data calculated in the combination phase, the final embedding representation of the nodes is calculated according to the steps of the aggregation phase after splitting and recombination. The combination phase performs intensive calculations on weight data, feature data, and attention kernel values ​​to obtain the combination results of all nodes, left similarity constant, and right similarity constant. The aggregation phase after splitting and recombination performs aggregation calculations based on the adjacency information of the graph data. Through the optimization of the calculation order, the number of division operations in the aggregation phase of the hardware accelerator is reduced from the number of node pairs to the number of nodes, and the operations in the aggregation phase after splitting and recombination form a node pair-level pipeline to reduce the inference latency of the hardware accelerator.

2. The method for optimizing the computation order of a graph attention network algorithm according to claim 1, characterized in that, The computation process of the graph attention network algorithm after splitting and recombining under a single attention head includes the following: First, the features of different types of nodes are projected onto the same feature space, i.e., a combination operation is performed; then, the corresponding weight matrix is ​​used... For the original feature vector of the node Perform the conversion: (1) Then attention weights are calculated. Calculation; (2) Finally, compute the final embedded representation of the node. ; in Attention coefficient This represents the attention kernel weight matrix. This represents the feature vector obtained after transforming the original feature vector of a node using the weight matrix. This represents a node pair representing the source node and its neighbor, the target node. Represents the source node, The neighboring nodes of the source node, i.e., the target neighboring node; Represents concatenation operation. This represents a non-linear activation function, where k is the number of attention heads in the graph attention network algorithm; If we decompose equation (2) for the calculation of attention weights, extract the dense computation part, and use matrix form to represent the combination operation, then the algorithm process under a single attention head can be represented by equations (3) to (7) below. (3) (4) (5) (6) (7) in, Represents the characteristic matrix, This represents the combined result of all nodes. Represents the left similarity constant. Represents the right similarity constant. This is the weight matrix. Represents the attention kernel matrix The left attention kernel matrix in Represents the attention kernel matrix The right attention kernel matrix in the middle, Indicates activation operation, This represents the final embedded representation of the node; Because in the attention weight calculation of equation (6), the denominator needs to accumulate the attention coefficients of all node pairs. After traversing the source node The calculation of equation (6) is completed after all neighboring nodes are reached. Therefore, the aggregation calculation of equation (7) needs to wait for the calculation result of equation (6). Substitute equation (6) into equation (7), and then use the distributive property of multiplication to convert the fractions. Extracting the fraction shifts the division operation to the end, calculating it only when the final node is embedded in the expression, and makes the multiplication and addition operations in equation (6) a prerequisite, resulting in equations (8)(9)(10): (8) (9) (10) in, To Intermediate result obtained after performing exponentiation. This represents information about all neighboring target nodes of the source node in the aggregation; Equations (3) and (4) above represent the combination stage of the graph attention network algorithm, while equations (8), (9), and (10) above represent the aggregation stage.

3. The method for optimizing the computation order of a graph attention network algorithm according to claim 2, characterized in that, In the graph attention network algorithm, the combination operation of each attention head yields a corresponding combination result, left similarity constant, and right similarity constant; When the number of attention points is At that time, there exists Different combinations of results Left similarity constant And right similarity constant .

4. The method for optimizing the computation order of a graph attention network algorithm according to claim 3, characterized in that, Under multiple attention heads, the final embedding representation of a node is calculated as follows: splicing in the middle layer The calculation results of each attention head are used This indicates that; while in the output layer... The average of the calculation results of each attention head; Intermediate layer: (11) Output layer: (12) The graph attention network algorithm has a multi-layer structure, which can be viewed as multiple computation processes. The output layer is the last computation process, while the intermediate layers are each computation process except for the output layer.

5. A hardware accelerator for a graph attention network algorithm with optimized computation order, employing the graph attention network algorithm with optimized computation order as described in claims 1-4, characterized in that, include: External storage, main controller, combination module, aggregation module; The external memory is used to store graph data and calculation results output by the aggregation module; The main controller is used to load slices of graph data from external memory into the on-chip memory of the FPGA and control the switching of computing tasks. The combination module is used to complete the combination stage operation of the graph attention network algorithm and pass the result to the aggregation module; The aggregation module is used to complete the aggregation stage operation of the graph attention network algorithm and obtain the final embedding representation of the node as the output calculation result.

6. The hardware accelerator for a graph attention network algorithm with optimized computational order according to claim 5, characterized in that, The aggregation module includes several aggregation calculation modules and an aggregation result synchronization module; The aggregation calculation module is used to index the on-chip cache and complete the aggregation calculation task; The aggregation result synchronization module is used to receive the final embedded representation of the computing node after receiving the calculation results from each aggregation calculation module. And store it in the on-chip cache.

7. A hardware accelerator for a graph attention network algorithm with optimized computational order as described in claim 6, characterized in that, The aggregation calculation module includes an index submodule and a calculation submodule; The index submodule includes an index controller, a left similarity constant cache block, a right similarity constant cache block, a combination result cache block, and an adjacency information cache block; The computation submodule includes a first computation array, a coefficient register, and a product register; The index controller is used to read the data of the left similarity constant cache block, the right similarity constant cache block, the combination result cache block, and the adjacency information cache block according to the input source node number, and transmit the data to the calculation submodule; The left similarity constant cache block, right similarity constant cache block, combination result cache block, and adjacency information cache block are all used to cache their corresponding data; The first computing array includes a first computing unit; the first computing array is used to receive data output by the index controller; The first calculation unit includes a vector processing unit; the vector processing unit is used to receive data output by the index controller and calculate attention coefficients and products; The coefficient register is used to cache attention coefficients; the product register is used to cache product registers; The first calculation unit accumulates the attention coefficients and products obtained by the vector processing unit through the coefficient register and product register. After the calculation of all neighbor nodes in the adjacency information cache in the index submodule is completed, the calculation submodule outputs the data stored in the coefficient register and product register to the aggregation result synchronization module.

8. The hardware accelerator for a graph attention network algorithm with optimized computational order according to claim 7, characterized in that, The aggregation result synchronization module includes a second computing array, a splicing computing unit, and an aggregation result cache block; The second computing array includes a second computing unit; the second computing unit is used to receive and superimpose partial sums from various aggregation computing modules, and then compute the embedded representation of the nodes; The splicing calculation unit is used to splice or average the results of each second calculation unit to obtain the final embedded expression of the node; The aggregation result cache block is used to store the final embedded representation of a set of source nodes.

9. A hardware accelerator for a graph attention network algorithm with optimized computational order as described in claim 8, characterized in that, against Different combinations of results Left similarity constant And right similarity constant , respectively corresponding Each corresponding cache A corresponding index controller, and use The computing array, composed of multiple computing units, performs parallel operations, while the splicing computing unit is responsible for splicing or averaging. The computation results under each attention head yield the final embedded representation of the node; Each aggregation computing module is configured with several on-chip caches, and the on-chip caches are split according to different attention heads, so that each on-chip cache corresponds to an attention head.

10. A hardware accelerator for a graph attention network algorithm with optimized computational order according to claim 7, characterized in that, The aggregation calculation module adopts a pipelined design. The index submodule serves as the first pipeline stage; The first computing unit includes a second pipeline stage, a third pipeline stage, and a fourth pipeline stage; The second pipeline stage includes an adder and a non-linear arithmetic unit; The third stage includes an exponentiation calculator; The fourth pipeline stage includes one multiplier and two accumulators; Each of the second, third, and fourth pipeline stages has a register to store the number of the source node being processed in the corresponding pipeline stage. This allows each pipeline stage to process the computations of different source nodes in parallel.

Citation Information

Patent Citations

  • Urban scene-oriented pedestrian trajectory prediction method, model and storage medium

    CN115071762A

  • Human motion prediction method based on time sequence grading and recombination mechanism

    CN115170613A