Graph neural network acceleration method and graph neural network acceleration structure
By adjusting the matrix calculation order and sparse matrix compression technology, the problem of low acceleration efficiency in the graph neural network acceleration method is solved, and more efficient data reading and hardware resource utilization are achieved.
Patent Information
- Application Number
- CN202410693570.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-30
- Publication Date
- 2024-09-24
AI Technical Summary
Existing graph neural network acceleration methods have the problem of low acceleration efficiency, mainly due to the memory wall problem and the inefficiency of sparse-dense matrix multiplication in matrix calculations.
By adjusting the matrix calculation sequence, using the sparsity of the sparse matrix for compressed storage, and reading the data in the external memory in the order of the storage address, and using the sparsity of the sparse matrix for optimization, the storage space requirements and memory wall problems are reduced, and data reading is improved. Get efficiency.
It effectively improves the acceleration efficiency of graph neural networks, alleviates memory wall problems, and improves data reading speed and hardware resource utilization.
Smart Images

Figure CN118690803A
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of deep learning technology, and more specifically, to a graph neural network acceleration method and a graph neural network acceleration structure. Background Art
[0002] The acceleration method of graph neural networks is usually to optimize the matrix operations of two stages in each layer of the network, that is, aggregation and combination update. Aggregation and combination (update) require continuous calculation of three matrices, namely: relationship matrix, feature matrix, and weight matrix. Among them, the relationship matrix and feature matrix are sparse matrices, which means that their non-zero elements only account for a small part of the total number of matrix elements, and most of the rest are zero; the relationship matrix is an extremely sparse matrix, which means that the proportion of non-zero elements in the matrix is less than 1%; the weight matrix is usually a dense matrix.
[0003] The sparsity of the input data, the cache requirements, and the data reusability of the two matrix calculations are very different. In addition, in matrix calculations, data needs to be loaded from the memory to the processor (such as the CPU or GPU) for calculation. Due to the difference in data transmission speed between the memory and the processor, when the processor is waiting for data to be loaded from the memory, the computing task cannot fully utilize the computing power of the processor, resulting in a performance bottleneck, that is, the memory wall problem. At present, the acceleration method of graph neural networks in related technologies has the problem of low acceleration efficiency. Summary of the invention
[0004] The embodiments of the present application provide a graph neural network acceleration method and a graph neural network acceleration structure to at least solve the problem of low acceleration efficiency in the graph neural network acceleration method in the related art.
[0005] According to an embodiment of the present application, a method for accelerating a graph neural network is provided, which is applied to a graph neural network acceleration structure, wherein the graph neural network is used to process graph structure data, the graph neural network includes a hidden layer, the hidden layer is used to perform specified matrix operations, the graph neural network acceleration structure includes a graph neural network accelerator and an external memory of the graph neural network accelerator, and the graph neural network accelerator is used to implement the specified matrix operations; the method includes: sequentially reading a compressed feature matrix from the external memory according to a storage address, wherein the compressed feature matrix is obtained by compressing data of a specified feature matrix corresponding to the graph structure data; performing a first matrix operation on the read compressed feature matrix and a weight matrix to obtain an intermediate matrix, wherein the specified matrix operation includes the first matrix operation; sequentially reading a compressed relationship matrix from the external memory according to a storage address, wherein the compressed relationship matrix is obtained by compressing data of a specified relationship matrix corresponding to the graph structure data, and the specified relationship matrix is used to describe the relationship between nodes in the graph structure data; performing a second matrix operation on the read compressed relationship matrix and the intermediate matrix to obtain a target matrix, wherein the specified matrix operation also includes the second matrix operation.
[0006] According to another embodiment of the present application, a graph neural network acceleration structure is provided, wherein the graph neural network is used to process graph structure data, the graph neural network includes a hidden layer, the hidden layer is used to perform specified matrix operations, the graph neural network acceleration structure includes a graph neural network accelerator, and the graph neural network accelerator is used to implement the specified matrix operations; including: the graph neural network accelerator is used to sequentially read a compressed feature matrix from the external memory according to a storage address, wherein the compressed feature matrix is obtained by data compression of a specified feature matrix corresponding to the graph structure data; perform a first matrix operation on the read compressed feature matrix and a weight matrix to obtain an intermediate matrix, wherein the specified matrix operation includes the first matrix operation; sequentially read a compressed relationship matrix from the external memory according to a storage address, wherein the compressed relationship matrix is obtained by data compression of a specified relationship matrix corresponding to the graph structure data, and the specified relationship matrix is used to describe the relationship between nodes in the graph structure data; perform a second matrix operation on the read compressed relationship matrix and the intermediate matrix to obtain a target matrix, wherein the specified matrix operation also includes the second matrix operation.
[0007] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium includes a stored program, wherein the steps of any of the above method embodiments are executed when the program is run.
[0008] According to another aspect of the embodiments of the present application, an electronic device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute the steps in any one of the above method embodiments through the computer program.
[0009] According to another aspect of the present application, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in any one of the above method embodiments are implemented.
[0010] Through the embodiments of the present application, the matrix calculation order is adjusted, and the data in the external memory is read in address order. Since the two-step matrix operations after adjusting the matrix calculation order are sparse-dense matrix multiplication, the sparsity of the sparse matrix can be used to compress the sparse matrix and store it in the external memory, thereby reducing storage space. Since a sequential reading method is adopted to read the data in the external memory in storage address order, the memory wall problem can be alleviated, the data reading efficiency can be improved, and the problem of low acceleration efficiency in the acceleration method of the graph neural network in the related art can be solved. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Figure 1 It is a flowchart of a method for accelerating a graph neural network according to an embodiment of the present application.
[0012] Figure 2 It is a schematic diagram of an aggregation and combination update according to an embodiment of the present application.
[0013] Figure 3 It is a schematic diagram of a HyGCN (graph convolutional network accelerator with hybrid architecture) according to an embodiment of the present application.
[0014] Figure 4 It is a schematic diagram of COO compression according to an embodiment of the present application.
[0015] Figure 5 It is a schematic diagram of modifying a row address to a valid mark at the end of a row according to an embodiment of the present application.
[0016] Figure 6 It is a schematic diagram of a graph neural network structure according to an embodiment of the present application.
[0017] Figure 7 It is a schematic diagram of two matrix calculations in a single hidden layer according to an embodiment of the present application.
[0018] Figure 8 It is a schematic diagram of two matrix calculations in another single hidden layer according to an embodiment of the present application.
[0019] Fig. 9 It is a schematic diagram of a matrix row multiplication according to an embodiment of the present application.
[0020] Fig.10 It is a schematic diagram of a row convolution calculation according to an embodiment of the present application.
[0021] Fig.11 It is a schematic diagram of a multiplication-addition unit and a cache according to an embodiment of the present application.
[0022] Fig.12 It is a schematic diagram of an XW row multiplication according to an embodiment of the present application.
[0023] Fig.13 It is a schematic diagram of an XW storage and calculation method according to an embodiment of the present application.
[0024] Fig.14 This is a schematic diagram of a graph neural network acceleration structure according to an embodiment of the present application.
[0025] Fig.15 It is a structural block diagram of a computer system of an optional electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] The embodiments of the present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0027] It should be noted that the terms "first", "second", etc. in the description and claims of the embodiments of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0028] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0029] In this embodiment, a method for accelerating a graph neural network is provided. Figure 1 is a flow chart of a method for accelerating a graph neural network according to an embodiment of the present application, such as Figure 1 As shown, the process includes the following steps:
[0030] Step S102, sequentially reading a compressed feature matrix from an external memory according to a storage address, wherein the compressed feature matrix is obtained by performing data compression on a designated feature matrix corresponding to the graph structure data.
[0031] The acceleration method of the graph neural network in this embodiment can be applied to the graph neural network, which is a deep learning model for processing graph structure data. It solves various tasks such as node classification, graph classification, link prediction, etc. by performing information propagation and feature learning on the graph structure. The graph neural network can process various types of graphs, including undirected graphs, directed graphs, weighted graphs, and multi-graphs.
[0032] Graph convolutional neural network is a specific type of graph neural network, which is mainly used in artificial intelligence fields where input data is correlated, such as interpersonal relationships, video recommendations, etc. Compared with other artificial intelligence networks, the unique feature of graph convolutional neural network is that in each layer of the network, two stages of matrix calculation are required, namely aggregation (AX) and combination update (AXW). The sparsity of input data, cache requirements, and data reusability of the two matrix calculations are very different.
[0033] Among them, Figure 2 The feature matrix (i.e., feature raw data) X, depending on the scenario, may be sparse or dense, and the data size may be hundreds of millions of points. Although it can be cut if it is too large, it cannot be cut too small, otherwise the correlation between the data will be lost. The relationship matrix A is an extremely sparse matrix, and the data size can be hundreds of millions × hundreds of millions. The weight matrix W, is a dense matrix, the data size is small, and it can be cached on the chip.
[0034] Since the computational data sparsity and cache requirements of the two stages are extremely different, graph neural network acceleration structures usually adopt the following two structures.
[0035] 1. Single-core acceleration structures such as general-purpose GPUs. The advantage of this is that only a single type of acceleration unit is required. However, since it is aimed at general computing, it cannot fully address the characteristics of graph neural networks and use two computing steps to optimize the overall resource requirements, resulting in serious waste of memory and data bandwidth performance.
[0036] Second, two independent hardware computing units, such as Figure 3 The advantage of HyGCN is that it can perform targeted optimization for different points in the two stages, but the problem with this is that the loads of the two accelerators are uneven, resulting in one accelerator being highly loaded while the other accelerator is waiting, wasting hardware resources.
[0037] In order to reduce hardware resources, in this embodiment, a single accelerator structure is used to be compatible with two-step matrix calculations. In order to utilize the sparsity of the matrix and reduce the data bandwidth requirement of the external memory, the calculation order is adjusted to first calculate XW and then calculate A(XW), that is, the two-step matrix calculations are both multiplications of a sparse matrix and a dense matrix.
[0038] A sparse matrix refers to a matrix in which most of the elements are zero, which usually occupies a large amount of storage space. When processing a sparse matrix, we can compress the sparse matrix. In this embodiment, taking the specified feature matrix X as a sparse matrix as an example, the compressed feature matrix is obtained by compressing the specified feature matrix corresponding to the graph structure data. The data compression method includes but is not limited to at least one of the following methods:
[0039] Coordinate list (COO) format: This format stores the row index, column index, and value of the non-zero elements in the matrix. It is suitable for preliminary compression of sparse matrices because only non-zero elements are stored.
[0040] Compressed Sparse Row (CSR) format: The CSR format represents a sparse matrix as three arrays: an array containing nonzero elements, an array containing the start positions of rows, and an array containing column indices, suitable for fast matrix-vector multiplication and matrix transpose operations.
[0041] Compressed Sparse Column (CSC) format: The CSC format is similar to CSR, but arrays of column indices and column start positions are stored, which makes column-vector multiplication and matrix transpose operations more efficient.
[0042] Triplet format: This format is similar to the COO format, but is usually used during the construction phase of a matrix because new elements can be added at any time.
[0043] Block Compressed Sparse Row (BSR) format: BSR is a variant of CSR, but it divides the matrix into sub-blocks of equal size and stores each sub-block as an element. This format is suitable for multi-core and vector processors and can reduce cache misses.
[0044] Hash table: A hash table can be used to store the non-zero elements of a sparse matrix in a dynamic data structure, which can improve the efficiency of element insertion and search.
[0045] Binary Decision Diagram (BDD): For certain sparse matrices, such as binary matrices, a binary decision diagram can be used to store them. This data structure can efficiently compress and operate sparse matrices.
[0046] Sparse matrix packages: Use mathematical packages such as LAPACK, BLAS, SPARSKIT, etc., which provide a variety of algorithms for sparse matrix storage and manipulation.
[0047] Numerical compression: For some specific sparse matrices, such as matrices with specific patterns, numerical methods can be used for compression, such as reducing the rank of the matrix through singular value decomposition (SVD).
[0048] The compressed feature matrix can be stored in an external memory, which can refer to an off-chip memory, including DDR, etc. Considering that if the external memory is read sequentially according to the address, address (0 / 1 / 2 / 3...), the reading rate can reach the upper limit of the reading speed. If the address jumps to read, the reading rate is halved. If one data jumps one address, the reading rate will be reduced to 10% of the maximum value.
[0049] In order to improve the data reading speed and alleviate the memory wall phenomenon, the compressed feature matrix can be read sequentially from the external memory according to the storage address. Sequential reading allows the memory controller to read data in the order of increasing addresses, and can make greater use of the internal prefetch mechanism of the memory, thereby improving the data transmission rate; during the sequential reading process, the memory can pre-load the data to be accessed into the cache, which can reduce access delays and improve reading efficiency; sequential reading can reduce random jumps within the memory, so that each part of the memory is used more evenly, thereby improving the overall utilization of the memory.
[0050] Step S104, performing a first matrix operation on the read compressed feature matrix and the weight matrix to obtain an intermediate matrix, wherein the specified matrix operation includes the first matrix operation.
[0051] Here, the first matrix operation may refer to multiplying the read compressed feature matrix X with the weight matrix W to obtain an intermediate matrix, that is, calculating XW.
[0052] Step S106, sequentially reading a compressed relationship matrix from an external memory according to a storage address, wherein the compressed relationship matrix is obtained by compressing data of a designated relationship matrix corresponding to the graph structure data, and the designated relationship matrix is used to describe the relationship between nodes in the graph structure data.
[0053] Graph structure data consists of nodes (vertices) and edges (edges), which can represent complex relationships and interactions. In graph convolutional neural networks, the relationship matrix is a key component used to capture the relationship between nodes in the graph. The specified relationship matrix A is very sparse. Similar to the previous embodiment, in order to utilize the sparsity of the sparse matrix, the specified relationship matrix corresponding to the graph structure data can be compressed to obtain a compressed relationship matrix. In order to increase the data reading speed, the compressed relationship matrix can be read sequentially from the external memory according to the storage address.
[0054] Step S108, performing a second matrix operation on the read compressed relation matrix and the intermediate matrix to obtain a target matrix, wherein the specified matrix operation also includes a second matrix operation.
[0055] Here, the second matrix operation may refer to multiplying the read compression relationship matrix A with the intermediate matrix XW to obtain the intermediate matrix, that is, calculating A(XW).
[0056] Through the above steps of the embodiment provided by the present application, a compressed feature matrix is sequentially read from an external memory according to a storage address, wherein the compressed feature matrix is obtained by compressing data on a specified feature matrix corresponding to the graph structure data; a first matrix operation is performed on the read compressed feature matrix and the weight matrix to obtain an intermediate matrix, wherein the specified matrix operation includes a first matrix operation; a compressed relationship matrix is sequentially read from an external memory according to the storage address, wherein the compressed relationship matrix is obtained by compressing data on a specified relationship matrix corresponding to the graph structure data, and the specified relationship matrix is used to describe the relationship between nodes in the graph structure data; a second matrix operation is performed on the read compressed relationship matrix and the intermediate matrix to obtain a target matrix, wherein the specified matrix operation also includes a second matrix operation, which solves the problem of low acceleration efficiency in the acceleration method of the graph neural network in the related art.
[0057] In an exemplary embodiment, the compressed feature matrix and the compressed relationship matrix are both stored in an external memory by row, and the external memory also stores a first row end flag corresponding to the elements in the compressed feature matrix and a second row end flag corresponding to the elements in the compressed feature matrix, wherein the first row end flag is used to identify whether the corresponding element is the end of a row vector, and the second row end flag is used to identify whether the corresponding element is the end of a row vector;
[0058] The compressed feature matrix is sequentially read from the external memory according to the storage address, including:
[0059] S11, sequentially reading elements in the compressed feature matrix from the external memory according to the storage address until the flag value of the corresponding first row end flag is read as the first flag value, and obtaining a first target row vector, wherein the first flag value is used to identify the corresponding element as the end of a row vector, and the first target row vector is a row vector in the compressed feature matrix; sequentially reading the compressed relationship matrix from the external memory according to the storage address, including:
[0060] S12, sequentially read the elements in the compression relationship matrix from the external memory according to the storage address until the flag value of the corresponding second row end flag is read as the second flag value, and obtain the second target row vector, wherein the second flag value is used to identify the corresponding element as the end of a row vector, and the second target row vector is a row vector in the compression relationship matrix.
[0061] In this embodiment, the COO format is used to compress the sparse matrix (Matrix) as an example. The standard COO format is as follows: Figure 4As shown, it is necessary to store non-zero elements (values), row coordinates (row indices) and column coordinates (column indices), so three off-chip storage spaces are required to store data, row coordinates and column coordinates. In order to save storage space in COO format, the data format of recording data row addresses is changed to record whether the data is end-of-row data. Because COO has removed 0-value data, all data and their corresponding row and column addresses are valid. Therefore, in this solution, the row address is modified to the end-of-row valid flag. If it is not the last column (end of row) of a row, it is 0, and if it is the last column of a row, it is 1. This can not only meet the calculation requirements, but also reduce the required row address storage space to 1 / 32 (the address is 32 bits, and the end-of-row valid flag only requires 1 bit), as shown in FIG. Figure 5 As shown, a byte is usually composed of 8 binary digits and is used to store and represent data.
[0062] The compressed feature matrix and the compressed relationship matrix are both stored in the external memory by row, which can mean that the compressed feature matrix and the compressed relationship matrix are both stored in the external memory in sequence according to row coordinates, that is, the elements of the same row are stored in the external memory in sequence, and the flag value of the end-of-row flag is used to identify whether the corresponding element is the last non-zero element of the row.
[0063] For the compressed feature matrix, data (non-zero elements) and the first end-of-row flags corresponding to the non-zero elements can be stored separately based on multiple corresponding off-chip storage spaces, that is, one off-chip storage space is used to store the non-zero elements of the compressed feature matrix, and another off-chip storage space is used to store the first end-of-row flags corresponding to the non-zero elements of the compressed feature matrix.
[0064] The elements in the compressed feature matrix are sequentially read from the external memory according to the storage address until the flag value of the corresponding first row end flag is read as the first flag value, and the first target row vector is obtained, wherein the first flag value is used to identify the corresponding element as the end of a row vector, the first target row vector is a row vector in the compressed feature matrix, and the first target row vector corresponds to a non-zero element in a row vector of the specified feature matrix.
[0065] For a compressed relational matrix, the data (non-zero elements) of the compressed relational matrix and the second row end flags corresponding to the non-zero elements of the compressed relational matrix can be stored separately based on multiple corresponding off-chip storage spaces, that is, one off-chip storage space is used to store the non-zero elements of the compressed relational matrix, and another off-chip storage space is used to store the second row end flags corresponding to the non-zero elements of the compressed relational matrix.
[0066] The elements in the compressed relation matrix are sequentially read from the external memory according to the storage address until the flag value of the corresponding second row end flag is read as the second flag value, and the second target row vector is obtained, wherein the second flag value is used to identify the corresponding element as the end of a row vector, the second target row vector is a row vector in the compressed relation matrix, and the second target row vector corresponds to a non-zero element in a row vector of the specified relation matrix.
[0067] Through this embodiment, the storage space can be reduced by modifying the row coordinates (row index) in the standard COO format into a row end mark for identifying whether the corresponding non-zero element is the last non-zero element of the row.
[0068] In an exemplary embodiment, the compressed feature matrix and the compressed relationship matrix are both stored in an external memory by row and read by row, the row vector of the compressed feature matrix read is the first target row vector, and the row vector of the compressed relationship matrix read is the second target row vector;
[0069] The first matrix operation is performed on the read compressed feature matrix and the weight matrix to obtain an intermediate matrix, including:
[0070] S21, using the read first target row vector as the first current row vector to perform the following first operation to obtain a row vector in the intermediate matrix corresponding to the first target row vector: respectively multiplying the m-th element of the first current row vector with the m-th row vector of the weight matrix to obtain n first reference row vectors, where m is less than or equal to the total number of columns of the specified feature matrix, and n is the number of elements contained in the first current row vector; performing a column-wise addition operation on the elements of the n first reference row vectors to obtain a row vector in the intermediate matrix corresponding to the first current row vector, where the column-wise addition operation is an operation of respectively adding elements on the same column;
[0071] The second matrix operation is performed on the compressed relation matrix and the intermediate matrix to obtain the target matrix, including:
[0072] S22, uses the read second target row vector as the second current row vector to perform the following second operation to obtain a row vector in the target matrix corresponding to the second target row vector: multiply the p-th element of the second current row vector by the p-th row vector of the intermediate matrix respectively to obtain q second reference row vectors, where p≤the total number of columns of the specified relationship matrix, and q is the number of elements contained in the second current row vector; perform a column-wise addition operation on the elements of the q second reference row vectors to obtain a row vector in the target matrix corresponding to the second current row vector, where the column-wise addition operation is an operation of adding elements on the same column respectively.
[0073] In this embodiment, combined with Figure 6For example, a graph neural network has four hidden layers, and each hidden layer needs to perform two matrix calculations, aggregation and combination update. The two matrix calculations in a single hidden layer can be as follows: Figure 7 As shown in the figure. For the sake of explanation, we make an assumption about the size of all data: Assuming that there are 370,000 points after the feature segmentation, and each point has 128 features, the size of the original feature X is 370,000 × 128. The weights W of the four layers are 128 × 256, 256 × 512, 512 × 1024, and 1024 × 176 respectively. The relationship matrix A is the square of the number of points, that is, 370,000 × 370,000.
[0074] Matrix calculation XW or A(XW), taking A(XW), W size 128×256 (first layer) as an example, the two matrices of the hidden layer of the first layer are calculated as follows Figure 8 shown.
[0075] If column multiplication is used, that is, the dot product of the rows of A and the columns of (XW), when parallel calculation is performed, 370,000 multiplication and addition PE units are required, and each row of data in the A matrix needs to be read 256 times to complete the calculation of one row. The memory bandwidth requirement is too large, and data reuse is not considered. If serial calculation is used, it will take too long.
[0076] If the column-row multiplication method is used, that is, the column of A is multiplied by the row matrix of (XW), the intermediate calculation results that need to be cached are 370,000×256 in size, which cannot be cached on the chip, and additional external memory read and write overhead needs to be added.
[0077] Based on this, the present embodiment adopts the row multiplication method, that is, the points in one row of A are multiplied and accumulated with the corresponding rows of (XW). The two matrices of the hidden layer are calculated as follows: Fig. 9 shown.
[0078] Since most of the data in A is sparse, very little data is needed for calculation, such as Fig. 9 As shown, to calculate the intermediate result of the matrix calculation of the first row of the output result, you only need to calculate the multiplication and addition of the data a in the A matrix and the corresponding row in the weight W, and accumulate the multiplication and addition results of the data b and the corresponding row of the weight, and you can calculate the first row of data of the final data result, as shown in Fig.10 shown.
[0079] Based on this, all multiplication and addition units will not perform invalid zero value calculations due to data sparsity, and the required cache size only needs to be the size of one row of the calculation result (256), which can be completed completely on-chip without the need for off-chip storage units. In addition, the calculation process only needs to read the A matrix data once, which can reduce the read and write bandwidth requirements of the entire model. In this embodiment, since the maximum weight column is 1024 columns, the acceleration PE unit and cache unit design need 1024 respectively to cover the maximum parallel computing requirements. The multiplication and addition unit and cache are as follows: Fig.11 shown.
[0080] Specifically, combined Fig.12 , the XW calculation step can be performed by row multiplication, and the row multiplication of XW can include the following steps:
[0081] The read first target row vector is used as the first current row vector to perform the following first operation to obtain a row vector in the intermediate matrix corresponding to the first target row vector: the m-th element of the first current row vector is multiplied by the m-th row vector of the weight matrix to obtain n first reference row vectors, where m is less than or equal to the total number of columns of the specified feature matrix, and n is the number of elements contained in the first current row vector; a column-wise addition operation is performed on the elements of the n first reference row vectors to obtain a row vector in the intermediate matrix corresponding to the first current row vector, where the column-wise addition operation is an operation of adding elements on the same column respectively.
[0082] Specifically, the row multiplication of A(XW) may include the following steps:
[0083] The read second target row vector is used as the second current row vector to perform the following second operation to obtain a row vector in the target matrix corresponding to the second target row vector: the p-th element of the second current row vector is multiplied by the p-th row vector of the intermediate matrix to obtain q second reference row vectors, where p≤the total number of columns of the specified relationship matrix, and q is the number of elements contained in the second current row vector; a column-wise addition operation is performed on the elements of the q second reference row vectors to obtain a row vector in the target matrix corresponding to the second current row vector, where the column-wise addition operation is an operation of adding elements on the same column respectively.
[0084] Through this embodiment, the matrix product is obtained by adopting the row multiplication method, the non-zero elements of a row of the left matrix are read in parallel and multiplied with the corresponding row of the right matrix, and the products are accumulated column by column. This can be completed completely on the chip without the need for off-chip storage units, which can reduce the read and write bandwidth requirements in the entire model.
[0085] In an exemplary embodiment, before performing the following first operation on the read first target row vector as the first current row vector, the method further includes: caching the read first target row vector, wherein the first operation is performed on the cached first target row vector;
[0086] After performing the following first operation on the read first target row vector as the first current row vector, the method further includes:
[0087] S31, storing the row vector corresponding to the first target row vector in the obtained intermediate matrix into a first memory, wherein the first memory is used to store the row vector of the intermediate matrix, and the first memory is an on-chip memory of the processing chip in which the graph neural network accelerator is integrated; clearing the cached first target row vector;
[0088] Before performing the following second operation using the read second target row vector as the second current row vector, the method further includes:
[0089] S32, caching the second target row vector read, wherein the second operation is performed on the cached second target row vector;
[0090] S33, after performing the following second operation on the read second target row vector as the second current row vector, the method further includes: storing the row vector corresponding to the second target row vector in the obtained target matrix into a second memory, wherein the second memory is used to store the row vectors of the target matrix, and the second memory is an on-chip memory of the processing chip in which the graph neural network accelerator is integrated; clearing the cached second target row vector.
[0091] Before the read first target row vector is used as the first current row vector to perform the following first operation, the read first target row vector is read and cached row by row, and the first operation is performed on the cached first target row vector, that is, each element in the first target row vector is multiplied by the corresponding row vector of the weight matrix, where the column coordinates of the elements of the multiplied first target row vector are the same as the row coordinates of the corresponding row vector of the weight matrix, and the column coordinates of the elements of the first target row vector are the same as the column coordinates of the non-zero element in the specified feature matrix.
[0092] After performing the following first operation on the read first target row vector as the first current row vector, the row vector corresponding to the first target row vector in the obtained intermediate matrix is stored in a first memory, wherein the first memory is used to store the row vectors of the intermediate matrix, and the first memory is an on-chip memory of a processing chip in which the graph neural network accelerator is integrated;
[0093] After completing the calculation of the current row vector of the compressed feature matrix, in order to facilitate the loop execution of the calculation of the next row vector of the compressed feature matrix, the first target row vector of the cache is cleared to store the next row vector of the compressed feature matrix in the cache, and the first operation is performed on the next row vector of the compressed feature matrix in the cache.
[0094] Similar to the above embodiment, before performing the following second operation on the read second target row vector as the second current row vector, the read second target row vector is cached, wherein the second operation is performed on the cached second target row vector;
[0095] After performing the following second operation on the read second target row vector as the second current row vector, the row vector corresponding to the second target row vector in the obtained target matrix is stored in a second memory, wherein the second memory is used to store row vectors of the target matrix, and the second memory is an on-chip memory of the processing chip in which the graph neural network accelerator is integrated; clear the cached second target row vector.
[0096] Through this embodiment, the row vectors read and cached are read row by row based on the row end mark of the sparse matrix, matrix row multiplication is performed row by row, and after the calculation of the row is completed, the cache is cleared to read and cache the next row vector, which can speed up the data reading and further improve the reasoning acceleration efficiency.
[0097] In an exemplary embodiment, before performing the first matrix operation on the read compressed feature matrix and the weight matrix, the method further includes:
[0098] S41, storing the weight matrix in R third memories by column, where R is the total number of columns of the weight matrix, the third memory is used to store the column vectors of the weight matrix, and the third memory is an on-chip memory of the processing chip in which the graph neural network accelerator is integrated;
[0099] S42, before multiplying the mth element of the first current row vector and the mth row vector of the weight matrix respectively, the method further includes: reading in parallel the element at the mth position in the column vectors stored in O third memories to obtain the mth row vector of the weight matrix.
[0100] Since the W matrix is very small, it is suitable for storage in the on-chip memory. In order to meet the parallel computing requirements, a row of W can be output in parallel without calculation. W can be stored in multiple RAM caches according to columns. The storage and calculation method is as follows: Fig.13 shown.
[0101] When a graph neural network includes multiple hidden layers and different hidden layers correspond to weight matrices of different sizes, in order to meet computing requirements, the number of on-chip memories used to store weight matrices can be designed to be consistent with the number of columns of the weight matrix with the largest number of columns among the multiple weight matrices of the graph neural network.
[0102] For example, in this embodiment, taking the graph neural network having 4 hidden layers, the weights W of the 4 layers are 128×256, 256×512, 512×1024, and 1024×176 respectively, and the largest weight column is 1024 columns, 1024 on-chip memories can be designed to store the weight matrix by column.
[0103] Optionally, after determining the weight matrix corresponding to the current hidden layer, before respectively multiplying the mth element of the first current row vector with the mth row vector of the weight matrix, the elements at the mth position in the column vectors stored in O third memories are read in parallel to obtain the mth row vector of the weight matrix. Here, O is the number of columns of the weight matrix corresponding to the current hidden layer, O can be less than or equal to R, and the element at the mth position in the column vectors stored in the O third memories is the mth row vector of the weight matrix, where m can be 1 to the number of rows of the weight matrix corresponding to the current hidden layer.
[0104] Since on-chip memory is integrated with the processor chip, its access speed is usually faster than that of off-chip memory. Off-chip memory needs to communicate with the processor through a bus, which increases access latency.
[0105] Through this embodiment, by storing the dense weight matrix by column and storing it in the on-chip memory, the data reading speed can be improved, and a larger sparse matrix only needs to be read once, and the dense matrix is reused to reduce the data reading bandwidth requirement.
[0106] In an exemplary embodiment, performing a column-wise addition operation on elements of the n first reference row vectors to obtain a row vector corresponding to the first current row vector in the intermediate matrix includes:
[0107] S51, after each first reference row vector is obtained, performing a column-wise addition operation on the currently obtained first reference row vector and the cached first intermediate row vector to obtain a first vector addition result, wherein the first intermediate row vector is used to record a row vector obtained by performing the column-wise addition operation on the obtained first reference row vector;
[0108] S52, using the first vector addition result to update the cached first intermediate row vector to obtain an updated first intermediate row vector, wherein the row vector corresponding to the first current row vector in the intermediate matrix is the first intermediate row vector after the last update;
[0109] Performing a column-wise addition operation on the elements of the q second reference row vectors to obtain a row vector corresponding to the second current row vector in the target matrix, including:
[0110] S53, after each second reference row vector is obtained, performing a column-wise addition operation on the currently obtained second reference row vector and the cached second intermediate row vector to obtain a second vector addition result, wherein the second intermediate row vector is used to record a row vector obtained by performing the column-wise addition operation on the obtained second reference row vector;
[0111] S54, using the second vector addition result to update the cached second intermediate row vector to obtain an updated second intermediate row vector, wherein the row vector corresponding to the second current row vector in the target matrix is the second intermediate row vector after the last update.
[0112] The m-th element of the first current row vector is multiplied by the m-th row vector of the weight matrix to obtain n first reference row vectors, and the column-wise addition operation is performed on the elements of the n first reference row vectors to obtain the row vectors in the intermediate matrix corresponding to the first current row vector, which can be gradually accumulated.
[0113] For example, in this embodiment, the first current row vector includes two non-zero elements a and b, and the corresponding row vectors in the weight matrix are (a 1 ,......,a t )、(b 1 ,......,b t ) as an example, in each case a first reference row vector b(b 1 , ....., b t ) then, for the first reference row vector b(b 1 , ....., b t ) and the first intermediate row vector a(a 1,. ....., a t ) performs column-wise addition to obtain the first vector addition result:
[0114] a(a 1 ,......,a t )+b(b 1 ,......,b t )=(a*a 1 +b*b 1 ,......,a*a t +b*b t ),
[0115] The first intermediate row vector is used to record a row vector obtained by performing a column-wise addition operation on the obtained first reference row vector;
[0116] Use the first vector addition result (a*a 1 +b*b 1 ,......,a*a t +b*b t ) updates the first intermediate row vector a(a) of the cache 1 ,......,a t ), and get the updated first intermediate row vector (a*a 1 +b*b 1 ,......,a*a t +b*b t ), wherein the row vector in the intermediate matrix corresponding to the first current row vector is the first intermediate row vector after the last update;
[0117] Similar to performing a column-wise addition operation on the elements of the n first reference row vectors to obtain a row vector in the intermediate matrix corresponding to the first current row vector, performing a column-wise addition operation on the elements of the q second reference row vectors to obtain a row vector in the target matrix corresponding to the second current row vector can also be gradually accumulated.
[0118] After each second reference row vector is obtained, a column-wise addition operation is performed on the currently obtained second reference row vector and the cached second intermediate row vector to obtain a second vector addition result, wherein the second intermediate row vector is used to record the row vector obtained by performing the column-wise addition operation on the obtained second reference row vector; the second vector addition result is used to update the cached second intermediate row vector to obtain an updated second intermediate row vector, wherein the row vector in the target matrix corresponding to the second current row vector is the second intermediate row vector after the last update.
[0119] Optionally, in this embodiment, the number of cache units may be designed to be greater than or equal to the maximum number of weight columns, that is, the maximum number of weight matrix columns.
[0120] Through this embodiment, by gradually accumulating and updating the cached intermediate results (i.e., the first intermediate row vector and the second intermediate row vector), the storage space occupied by the intermediate results can be reduced, and it is avoided that all non-zero elements of a row of the left matrix are added after calculation, resulting in the product of each non-zero element multiplied by the corresponding row vector of the right matrix corresponding to it taking up a certain amount of storage space.
[0121] In an exemplary embodiment, the number of weight matrices is multiple, and the graph neural network accelerator includes a computing engine PE array, the PE array includes S PE units arranged in a one-dimensional direction, and S ≥ the number of columns included in the weight matrix with the largest number of columns;
[0122] Performing a column-wise addition operation on the elements of the n first reference row vectors to obtain a row vector corresponding to the first current row vector in the intermediate matrix, including:
[0123] S61, using at least some of the S PE units to perform column-wise addition operations on the elements of the n first reference row vectors, respectively, to obtain a row vector corresponding to the first current row vector in the intermediate matrix;
[0124] Performing a column-wise addition operation on the elements of the q second reference row vectors to obtain a row vector corresponding to the second current row vector in the target matrix, including:
[0125] S62, use at least some of the S PE units to perform column-wise addition operations on the elements of the q second reference row vectors, to obtain a row vector corresponding to the second current row vector in the target matrix.
[0126] A graph neural network is a deep learning model for processing graph-structured data. It can capture the relationship between nodes in graph-structured data and learn the representation of nodes. The hidden layer is the middle layer in the graph neural network, which is used to represent and process node features in graph-structured data. A graph neural network usually contains one or more hidden layers, each of which is responsible for processing and transforming node features so that higher-level abstraction and learning can be performed in subsequent layers; the weight matrix is a key parameter in the graph neural network, which is used to define the transformation relationship between node features. Each hidden layer has a corresponding weight matrix, which is used to map input node features to output node features. The size of the weight matrix is usually related to the dimension of the node features. In each hidden layer of the graph neural network, the node features are linearly transformed by the weight matrix, and then a nonlinear activation function is usually applied. Such a transformation helps capture the complex relationship between nodes and extract useful feature representations. Information transfer in the graph neural network is achieved through the adjacency matrix (also called the relationship matrix) and the weight matrix. The adjacency matrix represents the connection relationship between nodes in the graph-structured data, while the weight matrix defines the transformation relationship between node features. By multiplying the adjacency matrix with the weight matrix, message passing and feature aggregation between nodes can be achieved. During the training process of graph neural networks, the parameters of the weight matrix need to be adjusted through optimization algorithms such as gradient descent. This process aims to minimize the prediction error so that the model can learn the node representation in the graph structure data more accurately.
[0127] That is, in the graph neural network, the hidden layer is responsible for processing and converting node features, while the weight matrix defines the conversion relationship between node features. Similar to the aforementioned embodiment, the graph neural network can have multiple hidden layers, each hidden layer corresponds to a weight matrix, that is, the number of weight matrices in the graph neural network can be multiple, and the graph neural network accelerator includes a computing engine PE array, and the PE array includes S PE units arranged in a one-dimensional direction, and S ≥ the number of columns contained in the weight matrix with the largest number of columns. In order to prevent the computing array from waiting as much as possible, a hardware architecture solution with weak single-core computing performance but a large number of PEs is adopted (similar to the DSP array of FPGA, with more than 9,000 computing arrays on a single chip). The PE array is arranged in a one-dimensional direction, and the number of PE computing units is greater than the row length of the weight matrix of the graph neural network in the extreme case.
[0128] The number of PE units used to perform column-by-column addition operations on the elements of the n first reference row vectors is consistent with the number of columns of the weight matrix corresponding to the current hidden layer. Correspondingly, the number of PE units used to perform column-by-column addition operations on the elements of the q second reference row vectors is also consistent with the number of columns of the weight matrix corresponding to the current hidden layer.
[0129] Through this embodiment, by designing a PE unit that matches the number of columns of the weight matrix of the graph neural network, it is possible to read the non-zero elements of the sparse matrix by row and multiply and accumulate them with the corresponding rows of the dense matrix (right matrix), thereby improving the data reading speed without affecting the calculation speed of the PE array.
[0130] Although the implementation methods described in this application are as above, the above descriptions and definitions are only for the purpose of facilitating the understanding of the implementation methods of this application, and are not intended to limit this application. Any modifications and changes made without departing from the spirit and scope of this application, especially any software and hardware implementation solutions based on this algorithm, are within the scope of protection of the present invention.
[0131] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0132] According to another aspect of the embodiments of the present application, an acceleration structure of a graph neural network is also provided, and the system is used to implement the acceleration method of the graph neural network provided in the above-mentioned embodiments, which has been described and will not be repeated here. As used below, the term "module" can implement a combination of software and / or hardware for a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, implementation in hardware, or a combination of software and hardware, is also possible and conceivable.
[0133] In this embodiment, the graph neural network is used to process graph structure data, the graph neural network includes a hidden layer, the hidden layer is used to perform specified matrix operations, and the graph neural network acceleration structure includes a graph neural network accelerator, and the graph neural network accelerator is used to implement specified matrix operations;
[0134] It includes: a graph neural network accelerator, which is used to sequentially read a compressed feature matrix from an external memory according to a storage address, wherein the compressed feature matrix is obtained by compressing a specified feature matrix corresponding to graph structure data; perform a first matrix operation on the read compressed feature matrix and a weight matrix to obtain an intermediate matrix, wherein the specified matrix operation includes a first matrix operation; sequentially read a compressed relationship matrix from an external memory according to a storage address, wherein the compressed relationship matrix is obtained by compressing a specified relationship matrix corresponding to the graph structure data, and the specified relationship matrix is used to describe the relationship between nodes in the graph structure data; perform a second matrix operation on the read compressed relationship matrix and the intermediate matrix to obtain a target matrix, wherein the specified matrix operation also includes a second matrix operation.
[0135] Optionally, each method step S202 to step S208 in the above embodiment can be executed by a graph neural network accelerator in the acceleration structure of the graph neural network, which has been explained and will not be repeated here.
[0136] In an exemplary embodiment, taking the example of designing 1024 acceleration PE units and 1024 cache units respectively, the graph neural network acceleration structure proposed in this embodiment is explained.
[0137] The graph neural network acceleration structure in this embodiment can be as follows Fig.14 As shown, Fig.14 The technical terms included in the text are explained as follows:
[0138] PCIe-core: PCI Express (PCIe) core is a hardware interface that allows devices inside a computer to be connected via a high-speed serial communication link. In the field of GNN, a GPU or other accelerator may be connected to the system's CPU via a PCIe core to facilitate data transfer and processing.
[0139] PCIe BUS: PCIe bus (BUS) is a point-to-point serial expansion bus standard for high-bandwidth connections of computer hardware. It is mainly used to connect central processing units (CPUs) and peripheral devices such as graphics processing units (GPUs).
[0140] Local Bus: A local bus is a communication line that connects components within a computer. It is usually used to connect the CPU, memory, and other peripherals such as input / output controllers. The speed of a local bus is usually lower than that of a PCIe bus.
[0141] DMA: Direct memory access (DMA) is a technology that allows hardware subsystems to directly read and write system memory without CPU intervention. In the field of GNN, DMA can be used to accelerate data transfer, especially when processing large amounts of graph data.
[0142] PE array: Processing Element (PE) array is a hardware architecture for parallel computing. In the field of GNN, PE array can be used to process multiple graph nodes at the same time, thereby improving the computational efficiency of graph neural networks.
[0143] HBM2: High Bandwidth Memory 2 (HBM2) is a high-performance 3D stacked DRAM technology used to provide high-speed, high-bandwidth memory solutions. HBM2 can be used to increase the memory access speed of GNNs, thereby improving overall computing performance. HBM technology stacks multiple layers of DRAM chips vertically and uses TSV (Through Silicon Via) and μbumps technology to connect to logic chips. This stacking and connection method enables high bandwidth and high transmission speed in a small package, which is very suitable for GPU memory requirements in high-performance artificial intelligence servers. The advantages of HBM technology include high bandwidth, low latency and high density, which can provide higher performance than traditional DRAM. Using HBM technology, the time the processor waits for data to load can be effectively reduced, and the utilization and computing efficiency of artificial intelligence computing power can be improved.
[0144] Bit width BRAM group: Bit width refers to the number of data bits that can be transmitted at one time during data transmission. Block Random Access Memory (BRAM) is a memory resource used in Field Programmable Gate Arrays (FPGAs). Bit width BRAM group refers to a collection of BRAM resources with a specific bit width, which can be used to store intermediate data or weights of GNNs.
[0145] reg: "reg" is the abbreviation of "register", which refers to a register. A register is a high-speed memory used to store instructions, data, or addresses. In the field of GNN, registers can be used to store features, weights, or other intermediate calculation results of graph nodes.
[0146] Bias HBM2 (High Bandwidth Memory 2): HBM2 is a high-performance 3D stacked DRAM (dynamic random access memory) technology commonly used in high-performance computing systems. Bias HBM2 may refer to a certain bias technology applied in HBM2 memory to improve performance or power consumption. However, this term is not a standard industry term and may be a concept in a specific application or design.
[0147] Data HBM2: This may refer to data stored in HBM2 memory, a high-speed memory technology suitable for applications that require large amounts of data transfer, such as high-performance computing, graphics processing units (GPUs), and AI accelerators.
[0148] BRAM (Block RAM): In FPGA, BRAM is a built-in memory resource that can be used as on-chip memory. BRAM blocks can be configured as different memory types, such as single-port or dual-port RAM, FIFOs, etc. BRAM is a key component in FPGA design for fast data storage and access.
[0149] Pong BRAM: Often used to describe a special BRAM configuration in FPGAs. In some FPGA architectures, two BRAM blocks can be paired to form a larger memory, where one BRAM block is called a "Pong". This configuration can increase memory capacity and performance.
[0150] Ping BRAM: The counterpart of Pong BRAM, Ping BRAM is the other in a paired BRAM block. In some FPGA architectures, Ping and Pong BRAM can be used to achieve more efficient data transfer, such as in data pipeline or double buffer systems.
[0151] In this embodiment, a single computing unit is used to be compatible with the two-step matrix calculation of the graph neural network. The method of first calculating XW and then calculating A(XW) is adopted to retain the data sparsity of the graph neural network; the two-step matrix calculation adopts the row multiplication calculation method, which can minimize the read and write requirements of the maximum data of the graph neural network; the hardware structure of the row multiplication calculation of the multiplication-addition cache; the column-by-column storage structure of the weight data; the parallel reading structure of the weight data; the 1-bit storage method of the end-of-row flag after the relationship matrix COO is compressed to reduce the storage requirement; the data transfer and cache clearing control method according to the end-of-row flag; for sparse matrices, there is no time interval for continuous Continued valid data calculation method; multi-row parallel calculation PE structure; pipeline sparse matrix valid number calculation without clear control requirements; calculation result ping-pong cache structure (dual HBM); feature matrix cache size, only the size of one row of data; the relationship matrix cache only needs no more than 32; the largest relationship matrix A only needs to be read once; the intermediate calculation result cache of the first step matrix calculation only needs the size of one row of data; the intermediate result of the second step matrix calculation only needs to read one row of data; the pipeline automatically masks 0 value results; reuse on-chip weight data (minimum data volume); clear the on-chip calculation cache according to the end of line flag.
[0152] Through this embodiment, a graph neural network accelerator compatible with two-step matrix calculations is designed in view of the calculation characteristics of the graph neural network, namely the sparsity of the two-step matrix calculations, cache requirements, and different calculation densities. By adjusting the calculation order, adjusting the matrix calculation method to row multiplication, and adjusting the storage structure, there is no invalid 0 value calculation when performing sparse matrix calculations, and ensuring that the matrix with the largest data volume only needs to be read once, reducing the data bandwidth requirements for reading and writing external memory, and realizing a high-density computing structure with no idle computing cycles, improving the hardware resource utilization rate of graph neural network calculations, and because it is a single accelerator structure, it also reduces the design difficulty of related chips. Effectively improve the acceleration capability of graph neural network reasoning calculations.
[0153] In an exemplary embodiment, the compressed feature matrix and the compressed relationship matrix are both stored in an external memory by row, and the external memory also stores a first row end flag corresponding to the elements in the compressed feature matrix and a second row end flag corresponding to the elements in the compressed feature matrix, wherein the first row end flag is used to identify whether the corresponding element is the end of a row vector, and the second row end flag is used to identify whether the corresponding element is the end of a row vector;
[0154] A graph neural network accelerator is used to sequentially read elements in a compressed feature matrix from an external memory according to a storage address until a flag value of a corresponding first row end flag is read as a first flag value, thereby obtaining a first target row vector, wherein the first flag value is used to identify that the corresponding element is the end of a row vector, and the first target row vector is a row vector in the compressed feature matrix;
[0155] A graph neural network accelerator is used to sequentially read elements in a compressed relationship matrix from an external memory according to a storage address until a flag value of a corresponding second row end flag is read as a second flag value, thereby obtaining a second target row vector, wherein the second flag value is used to identify the corresponding element as the end of a row vector, and the second target row vector is a row vector in the compressed relationship matrix.
[0156] In an exemplary embodiment, the compressed feature matrix and the compressed relationship matrix are both stored in an external memory by row and read by row, the row vector of the compressed feature matrix read is the first target row vector, and the row vector of the compressed relationship matrix read is the second target row vector;
[0157] A neural network accelerator is used to perform the following first operation on the read first target row vector as the first current row vector to obtain a row vector in the intermediate matrix corresponding to the first target row vector: respectively multiplying the mth element of the first current row vector with the mth row vector of the weight matrix to obtain n first reference row vectors, wherein m is less than or equal to the total number of columns of the specified feature matrix, and n is the number of elements contained in the first current row vector; performing a column-by-column addition operation on the elements of the n first reference row vectors to obtain a row vector in the intermediate matrix corresponding to the first current row vector, wherein the column-by-column addition operation is an operation of respectively adding elements on the same column;
[0158] A graph neural network accelerator is used to perform the following second operation on the read second target row vector as the second current row vector to obtain a row vector in the target matrix corresponding to the second target row vector: multiply the p-th element of the second current row vector by the p-th row vector of the intermediate matrix respectively to obtain q second reference row vectors, wherein p≤the total number of columns of the specified relationship matrix, and q is the number of elements contained in the second current row vector; perform a column-wise addition operation on the elements of the q second reference row vectors to obtain a row vector in the target matrix corresponding to the second current row vector, wherein the column-wise addition operation is an operation of adding elements on the same column respectively.
[0159] In an exemplary embodiment, a graph neural network accelerator is used to cache the read first target row vector before performing the following first operation on the read first target row vector as a first current row vector, wherein the first operation is performed on the cached first target row vector;
[0160] A graph neural network accelerator, configured to store the row vector corresponding to the first target row vector in the intermediate matrix obtained into a first memory after performing the following first operation on the first target row vector read as the first current row vector, wherein the first memory is used to store the row vectors of the intermediate matrix, and the first memory is an on-chip memory of a processing chip in which the graph neural network accelerator is integrated; clear the cached first target row vector;
[0161] A neural network accelerator, configured to cache the read second target row vector before performing the following second operation on the read second target row vector as a second current row vector, wherein the second operation is performed on the cached second target row vector;
[0162] A graph neural network accelerator is used to store the row vector corresponding to the second target row vector in the obtained target matrix into a second memory after performing the following second operation on the read second target row vector as the second current row vector, wherein the second memory is used to store the row vectors of the target matrix, and the second memory is an on-chip memory of the processing chip in which the graph neural network accelerator is integrated; and clear the cached second target row vector.
[0163] In an exemplary embodiment, a graph neural network accelerator is used to store the weight matrix by column in R third memories before performing a first matrix operation on the read compressed feature matrix and the weight matrix, wherein R is the total number of columns of the weight matrix, the third memory is used to store the column vector of the weight matrix, and the third memory is an on-chip memory of a processing chip in which the graph neural network accelerator is integrated;
[0164] A graph neural network accelerator is used to read in parallel the elements at the m-th position in the column vectors stored in O third memories before multiplying the m-th element of the first current row vector with the m-th row vector of the weight matrix respectively, so as to obtain the m-th row vector of the weight matrix.
[0165] In an exemplary embodiment, a graph neural network accelerator is used to perform a column-by-column addition operation on the currently obtained first reference row vector and the cached first intermediate row vector after each first reference row vector is obtained to obtain a first vector addition result, wherein the first intermediate row vector is used to record the row vector obtained by performing the column-by-column addition operation on the obtained first reference row vector; and use the first vector addition result to update the cached first intermediate row vector to obtain an updated first intermediate row vector, wherein the row vector in the intermediate matrix corresponding to the first current row vector is the first intermediate row vector after the last update;
[0166] A graph neural network accelerator is used to perform a column-by-column addition operation on the currently obtained second reference row vector and the cached second intermediate row vector after obtaining each second reference row vector, to obtain a second vector addition result, wherein the second intermediate row vector is used to record the row vector obtained by performing the column-by-column addition operation on the obtained second reference row vector; and use the second vector addition result to update the cached second intermediate row vector to obtain an updated second intermediate row vector, wherein the row vector in the target matrix corresponding to the second current row vector is the second intermediate row vector after the last update.
[0167] In an exemplary embodiment, the number of weight matrices is multiple, and the graph neural network accelerator includes a computing engine PE array, the PE array includes S PE units arranged in a one-dimensional direction, and S ≥ the number of columns included in the weight matrix with the largest number of columns;
[0168] A graph neural network accelerator is used to use at least some of the S PE units to perform column-by-column addition operations on the elements of n first reference row vectors, respectively, to obtain a row vector in an intermediate matrix corresponding to the first current row vector; and use at least some of the S PE units to perform column-by-column addition operations on the elements of q second reference row vectors, respectively, to obtain a row vector in a target matrix corresponding to the second current row vector.
[0169] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when run.
[0170] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory, a random access memory, a mobile hard disk, a magnetic disk, or an optical disk.
[0171] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0172] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0173] The embodiments of the present application also provide another computer program, which includes computer instructions stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the steps in any one of the above method embodiments.
[0174] According to one aspect of the present application, a computer program product is provided, the computer program product comprising a computer program / instruction, the computer program / instruction comprising a program code for executing the method shown in the flowchart. Fig.15 , the computer program can be downloaded and installed from the network through the communication part 1509, and / or installed from the removable medium 1511. When the computer program is executed by the central processor 1501, various functions provided by the embodiments of the present application are executed. The serial numbers of the embodiments of the present application are only for description and do not represent the advantages and disadvantages of the embodiments.
[0175] refer to Fig.15 , Fig.15 It is a structural block diagram of a computer system of an optional electronic device provided in an embodiment of the present application.
[0176] Fig.15 The computer system structure block diagram of the electronic device used to implement the embodiment of the present application is schematically shown. Fig.15 As shown, the computer system 1500 includes a central processing unit 1501 (CPU), which can perform various appropriate actions and processes according to the program stored in the read-only memory 1502 (ROM) or the program loaded from the storage part 1508 to the random access memory 1503 (RAM). Various programs and data required for system operation are also stored in the random access memory 1503. The central processing unit 1501, the read-only memory 1502 and the random access memory 1503 are connected to each other through a bus 1504. The input / output interface 1505 (Input / Output interface, referred to as I / O interface) is also connected to the bus 1504.
[0177] The following components are connected to the input / output interface 1505: an input section 1506 including a keyboard, a mouse, etc.; an output section 1507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1508 including a hard disk, etc.; and a communication section 1509 including a network interface card such as a LAN card, a modem, etc. The communication section 1509 performs communication processing via a network such as the Internet. A drive 1510 is also connected to the input / output interface 1505 as needed. A removable medium 1511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1510 as needed so that a computer program read therefrom is installed into the storage section 1508 as needed.
[0178] In particular, according to an embodiment of the present application, the process described in each method flow chart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer readable medium, and the computer program contains a program code for executing the method shown in the flow chart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 1509, and / or installed from the removable medium 1511. When the computer program is executed by the central processor 1501, various functions defined in the system of the present application are executed.
[0179] It should be noted that Fig.15 The computer system 1500 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0180] According to another aspect of the embodiments of the present application, there is also provided an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0181] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0182] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0183] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of the present application are not limited to any specific combination of hardware and software.
[0184] The above are only preferred embodiments of the present application and are not intended to limit the embodiments of the present application. For those skilled in the art, the embodiments of the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principles of the embodiments of the present application shall be included in the protection scope of the embodiments of the present application.
Claims
1. A method for accelerating graph neural networks, It is characterized in that Applied to a graph neural network acceleration structure, wherein the graph neural network is used to process graph structure data, the graph neural network includes a hidden layer, the hidden layer is used to perform a specified matrix operation, the graph neural network acceleration structure includes a graph neural network accelerator and an external memory of the graph neural network accelerator, and the graph neural network accelerator is used to implement the specified matrix operation; The method comprises: sequentially reading a compressed feature matrix from the external memory according to a storage address, wherein the compressed feature matrix is obtained by performing data compression on a designated feature matrix corresponding to the graph structure data; Performing a first matrix operation on the read compressed feature matrix and weight matrix to obtain an intermediate matrix, wherein the specified matrix operation includes the first matrix operation; Sequentially reading a compressed relationship matrix from the external memory according to a storage address, wherein the compressed relationship matrix is obtained by compressing a specified relationship matrix corresponding to the graph structure data, and the specified relationship matrix is used to describe the relationship between nodes in the graph structure data; A second matrix operation is performed on the read compressed relation matrix and the intermediate matrix to obtain a target matrix, wherein the specified matrix operation also includes the second matrix operation.
2. The method according to claim 1, It is characterized in that The compressed feature matrix and the compressed relationship matrix are both stored in the external memory in rows, and the external memory also stores a first row end flag corresponding to the elements in the compressed feature matrix and a second row end flag corresponding to the elements in the compressed feature matrix, wherein the first row end flag is used to identify whether the corresponding element is the end of a row vector, and the second row end flag is used to identify whether the corresponding element is the end of a row vector; The sequentially reading the compressed feature matrix from the external memory according to the storage address includes: sequentially reading elements in the compressed feature matrix from the external memory according to the storage address until the flag value of the corresponding first row end flag is read as a first flag value, and a first target row vector is obtained, wherein the first flag value is used to identify that the corresponding element is the end of a row vector, and the first target row vector is a row vector in the compressed feature matrix; The sequentially reading the compressed relationship matrix from the external memory according to the storage address includes: sequentially reading the elements in the compressed relationship matrix from the external memory according to the storage address until the flag value of the corresponding second row end flag is read as the second flag value, and a second target row vector is obtained, wherein the second flag value is used to identify the corresponding element as the end of a row vector, and the second target row vector is a row vector in the compressed relationship matrix.
3. The method according to claim 1, It is characterized in that The compressed feature matrix and the compressed relationship matrix are both stored in the external memory in rows and read in rows, the row vector of the compressed feature matrix read is the first target row vector, and the row vector of the compressed relationship matrix read is the second target row vector; The step of performing a first matrix operation on the compressed feature matrix and the weight matrix to obtain an intermediate matrix includes: performing the following first operation on the first target row vector as the first current row vector to obtain a row vector in the intermediate matrix corresponding to the first target row vector: multiplying the mth element of the first current row vector by the mth row vector of the weight matrix to obtain n first reference row vectors, wherein m is less than or equal to the total number of columns of the specified feature matrix, and n is the number of elements included in the first current row vector; performing a column-wise addition operation on the elements of the n first reference row vectors to obtain a row vector in the intermediate matrix corresponding to the first current row vector, wherein the column-wise addition operation is an operation of adding elements on the same column respectively; The second matrix operation is performed on the compressed relationship matrix and the intermediate matrix to obtain the target matrix, including: taking the second target row vector read as the second current row vector, the following second operation is performed to obtain the row vector corresponding to the second target row vector in the target matrix: the p-th element of the second current row vector is multiplied by the p-th row vector of the intermediate matrix to obtain q second reference row vectors, wherein p≤the total number of columns of the specified relationship matrix, and q is the number of elements contained in the second current row vector; the column-wise addition operation is performed on the elements of the q second reference row vectors to obtain the row vector corresponding to the second current row vector in the target matrix, wherein the column-wise addition operation is an operation of adding the elements on the same column respectively.
4. The method according to claim 3, It is characterized in that Before performing the following first operation on the read first target row vector as the first current row vector, the method further includes: caching the read first target row vector, wherein the first operation is performed on the cached first target row vector; After performing the following first operation on the read first target row vector as the first current row vector, the method further includes: storing the obtained row vector corresponding to the first target row vector in the intermediate matrix into a first memory, wherein the first memory is used to store the row vectors of the intermediate matrix, and the first memory is an on-chip memory of the processing chip in which the graph neural network accelerator is integrated; clearing the cached first target row vector; Before performing the following second operation on the read second target row vector as the second current row vector, the method further includes: caching the read second target row vector, wherein the second operation is performed on the cached second target row vector; After performing the following second operation on the read second target row vector as the second current row vector, the method further includes: storing the obtained row vector corresponding to the second target row vector in the target matrix into a second memory, wherein the second memory is used to store the row vectors of the target matrix, and the second memory is an on-chip memory of the processing chip in which the graph neural network accelerator is integrated; clearing the cached second target row vector.
5. The method according to claim 3, It is characterized in that Before performing the first matrix operation on the read compressed feature matrix and the weight matrix, the method further includes: The weight matrix is stored in R third memories by column, where R is the total number of columns of the weight matrix, the third memory is used to store the column vectors of the weight matrix, and the third memory is an on-chip memory of the processing chip in which the graph neural network accelerator is integrated; Before multiplying the mth element of the first current row vector with the mth row vector of the weight matrix, the method also includes: reading in parallel the elements at the mth position in the column vectors stored in O third memories to obtain the mth row vector of the weight matrix.
6. The method according to claim 3, It is characterized in that The performing a column-wise addition operation on the elements of the n first reference row vectors to obtain a row vector corresponding to the first current row vector in the intermediate matrix includes: after each first reference row vector is obtained, performing a column-wise addition operation on the currently obtained first reference row vector and a cached first intermediate row vector to obtain a first vector addition result, wherein the first intermediate row vector is used to record a row vector obtained by performing the column-wise addition operation on the obtained first reference row vector; and using the first vector addition result to update the cached first intermediate row vector to obtain an updated first intermediate row vector, wherein the row vector corresponding to the first current row vector in the intermediate matrix is the first intermediate row vector after the last update; The method of performing a column-wise addition operation on the elements of the q second reference row vectors to obtain a row vector in the target matrix corresponding to the second current row vector includes: after each second reference row vector is obtained, performing a column-wise addition operation on the currently obtained second reference row vector and a cached second intermediate row vector to obtain a second vector addition result, wherein the second intermediate row vector is used to record the row vector obtained by performing the column-wise addition operation on the obtained second reference row vectors; and using the second vector addition result to update the cached second intermediate row vector to obtain an updated second intermediate row vector, wherein the row vector in the target matrix corresponding to the second current row vector is the second intermediate row vector after the last update.
7. The method according to any one of claims 3 to 6, It is characterized in that There are multiple weight matrices, and the graph neural network accelerator includes a computing engine PE array, and the PE array includes S PE units arranged in a one-dimensional direction, and S ≥ the number of columns included in the weight matrix with the largest number of columns; The performing a column-wise addition operation on the elements of the n first reference row vectors to obtain a row vector in the intermediate matrix corresponding to the first current row vector comprises: using at least some of the S PE units to respectively perform a column-wise addition operation on the elements of the n first reference row vectors to obtain a row vector in the intermediate matrix corresponding to the first current row vector; The step of performing a column-wise addition operation on the elements of the q second reference row vectors to obtain a row vector in the target matrix corresponding to the second current row vector includes: using at least some of the S PE units to perform a column-wise addition operation on the elements of the q second reference row vectors to obtain a row vector in the target matrix corresponding to the second current row vector.
8. A graph neural network acceleration structure, It is characterized in that The graph neural network is used to process graph structure data, the graph neural network includes a hidden layer, the hidden layer is used to perform a specified matrix operation, the graph neural network acceleration structure includes a graph neural network accelerator, and the graph neural network accelerator is used to implement the specified matrix operation; include: The graph neural network accelerator is used to sequentially read a compressed feature matrix from the external memory according to a storage address, wherein the compressed feature matrix is obtained by compressing a specified feature matrix corresponding to the graph structure data; perform a first matrix operation on the read compressed feature matrix and a weight matrix to obtain an intermediate matrix, wherein the specified matrix operation includes the first matrix operation; sequentially read a compressed relationship matrix from the external memory according to a storage address, wherein the compressed relationship matrix is obtained by compressing a specified relationship matrix corresponding to the graph structure data, and the specified relationship matrix is used to describe the relationship between nodes in the graph structure data; perform a second matrix operation on the read compressed relationship matrix and the intermediate matrix to obtain a target matrix, wherein the specified matrix operation also includes the second matrix operation.
9. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, wherein the computer program implements the method according to any one of claims 1 to 7 when executed by a processor.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Matrix multiplication rapid calculation method and device, equipment and storage medium
CN119557552A
Graph structure data processing method, accelerator, storage medium and program product
CN119721119A
Graph Structure Data Processing Method, Accelerator, Storage Medium, and Program Product
CN119721119B
Sub-graph GNN acceleration system and electronic chip
CN121436063A
