System for accelerated processing of LSTM neural network data based on RTL level
By designing an RTL-level data processing system in the LSTM neural network and using data accelerators for parallel computing, the problem of low LSTM computing performance and efficiency in the existing technology is solved, achieving faster processing speed and lower latency. And improve the parallelism and stability of the system.
Patent Information
- Application Number
- CN202410274731.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-11
- Publication Date
- 2024-10-11
AI Technical Summary
The existing technology has low computing performance and efficiency when processing LSTM neural networks, resulting in slow inference speed and large delay, making it difficult to meet the needs of complex sequence data processing.
Design an LSTM neural network data processing system based on RTL level, by mapping the computing tasks of the LSTM neural network to the data accelerator, using parallel computing capabilities and high-speed memory, including DDR data storage chips and data acceleration processing chips, using forward Components such as the inference module, matrix-vector multiplication module, activation function module, and memory vector update module realize efficient operations on matrices and vectors.
Significantly improve the computing performance and efficiency of LSTM neural network, achieve faster processing speed and lower latency, the inference clock frequency reaches 100M, the computing power is increased to 1.7TFLOPS, and the data throughput is improved through double buffering technology, reducing data Conflicts, improve system stability and parallelism.
Smart Images

Figure CN118761450A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of artificial intelligence acceleration, and in particular relates to an LSTM neural network data processing system based on RTL level acceleration. Background Art
[0002] RNN (Recurrent Neural Network) is a classic algorithm in deep learning and a neural network used to process sequences. LSTM (Long Short-Term Memory Network) is a variant of RNN. When processing long sequence data, the LSTM neural network structure has been proven to have a more obvious advantage than RNN in learning and memorizing long-term sequence information. It has been successfully applied to a series of fields that require sequence processing, such as natural language processing, speech recognition, etc.
[0003] LSTM cell structure is as follows Figure 1 As shown, where x t is the input vector of the input layer, h t and c t-1 is the memory vector of the hidden layer input from the previous LSTM cell, h t and c t is the memory vector of the hidden layer output to the next LSTM cell. The forward reasoning formula of LSTM cells is shown in formulas (1)-(6), which represent the three gate structures of LSTM cells. Formula (1) is the input gate structure, which determines the updated value; formula (2) is the forget gate structure, which determines to discard information from the LSTM cell state; formula (3) creates a vector to update the state of LSTM cells; formulas (4) and (5) are output gate structures, which output the hidden state of the current cell; formula (6) updates the state of the current cell.
[0004] i t =σ(x t W i +h t-1 x t W i +b i ) (1)
[0005] f t =σ(x t W f +h t-1 W f +b f ) (2)
[0006]
[0007] o t =σ(x t W o +h t-1 W o +bo ) (4)
[0008] h t =o t *tanh(c t ) (5)
[0009] Summary of the invention
[0010] In view of the technical problems existing in the prior art, the present invention provides a data processing system for accelerating an LSTM neural network based on the RTL level. The present invention maps the computing tasks of the LSTM neural network to an accelerator in the data processing system to utilize the parallel computing capabilities and high-speed memory of the data accelerator, thereby improving the computing performance and efficiency of the LSTM neural network on the one hand; on the other hand, it can accelerate the reasoning process of the LSTM neural network to achieve faster processing speed and lower latency.
[0011] In order to solve the problems of the prior art, the present invention adopts the following technical solutions:
[0012] A system for accelerating the processing of LSTM neural network data based on RTL level, the system comprising a DDR data storage chip and a data acceleration processing chip; the DDR data storage chip is used to input matrix and vector data to the data acceleration processing chip; the data acceleration processing chip accelerates the processing of LSTM neural network data through forward reasoning operation; the data acceleration processing chip is composed of a read control module, a data storage module, a forward reasoning module and a write control module; the forward reasoning module is composed of a control unit and a computing unit; the computing unit comprises a vector replication module, a matrix-vector multiplication module, a bias addition module, an activation function module and a memory vector update module, wherein: the forward reasoning module is connected to the data storage module through four groups of signals to realize the accelerated processing of LSTM neural network data:
[0013] Matrix-vector multiplication read signal controls all matrices and vectors h t-1 and x t The operation block reads from the data storage module, including:
[0014] The address signal m_addr of the read matrix is an output signal with a bit length of X bits; it is connected to the read address of the BRAM of each storage matrix in the data storage module;
[0015] The address signal v_addr of the read vector is an output signal with a bit length of X bits, which is connected to the data storage module to store h t-1 and x t The read address port of the BRAM;
[0016] Read enable signal ram_en, output signal, bit length is 1 bit, connected to the data storage module to store all matrices and vectors h t-1 and c t-1 The read enable port of the BRAM;
[0017] 8 matrix read data signals, input signals, corresponding to the W and U type data read from the BRAM of the data storage module, with a data length of M*N*WS bits, connected to the matrix input ports of the 8 matrix-vector multiplication modules;
[0018] 2 vector data refers to h t-1 and x t , input signal, the read data output port of the BRAM storing this type of data in the data storage module is connected to the vector input port of the vector copy module respectively, and the bit length is M*WS bits;
[0019] The bias vector read signal includes:
[0020] The biased address signal b_addr is read, and the output signal has a bit length of X bits and is connected to the read address port of each BRAM storing the biased vector in the data storage module.
[0021] The read bias enable signal b_r_en is an output signal with a bit length of 1 bit, which is connected to the read enable port of each BRAM storing the bias vector in the data storage module.
[0022] 4 bias data signals, input signals, are connected from the data output port of the BRAM storing the bias in the data storage module to the bias input port of the bias addition module, and the bit length is N*WS bits;
[0023] c t-1 Reading signals include:
[0024] Read c t-1 The address signal c_addr, output signal, bit length is X bits, connected to the data storage module (storage c t-1 The read address port of the BRAM.
[0025] Read c t-1 The read enable signal c_r_en is an output signal with a bit length of 1 bit, which is connected to the data storage module to store c t-1 The read enable port of the BRAM;
[0026] Read c t-1 The data, input signal, bit length is N*WS bits, stored in the data storage module c t-1 The data output port of the BRAM is connected to the memory vector update module.
[0027] Other control signals include:
[0028] The number of operation blocks in the current data storage module is mat_block_num, the input signal, the bit length is Y bits, connected from the start signal control module to the control unit in the forward reasoning module;
[0029] Control signal start, input signal, controls the first start of reasoning, bit length is 1 bit, connected from the start signal control module to the control unit in the forward reasoning module;
[0030] Control signal conti, input signal, controls the continuation of reasoning, bit length is 1 bit, connected from the start signal control module to the control unit in the forward reasoning module;
[0031] The control signal req, input signal, forward reasoning stop, has a bit length of 1 bit, and is connected from the control unit in the forward reasoning module to the data storage module;
[0032] The row block number row_block_num of the matrix, the input signal, the bit length is Y bits, as the input of the forward reasoning module, connected to the control unit;
[0033] The number of column blocks of the matrix col_block_num, the input signal, the bit length is Y bits, as the input of the forward reasoning module, connected to the control unit.
[0034] Furthermore, the control unit outputs the read matrix address, vector address and read enable to the outside, initiates the reading of the specified block of the matrix, and the storage module performs the operation process on the corresponding matrix and vector data:
[0035] The control unit outputs a cd signal, which is connected to an accumulation module in a matrix-vector multiplication module and is used for clearing the accumulation, and the bit length is 1 bit;
[0036] The control unit outputs an intr signal, which is connected to the accumulation module in the matrix-vector multiplication module and is used for the register after the accumulation module to stop receiving the accumulated value, and the bit length is 1 bit.
[0037] The control unit outputs a vec_ofs_o signal, which passes through a multi-level register and is finally used as the output of the forward reasoning module, as an output valid offset signal, marking the offset position of the current operation result in the final result, with a bit length of Y bits;
[0038] The control unit outputs a we_o signal, which passes through a multi-level register and is finally used as the output of the forward reasoning module as an output valid signal, marking that the current operation result is valid, and the bit length is 1 bit;
[0039] The control signal outputs the done_o signal, which passes through a multi-level register and finally serves as the output of the forward reasoning module, as a reasoning end signal, marking the end of the current forward reasoning, and has a bit length of 1 bit.
[0040] Furthermore, the computing unit performs an acceleration process on the LSTM neural network, including:
[0041] The vector replication module receives a vector with a length of M*WS bits, outputs it after replication, and outputs it as a matrix with a length of M*N*WS bits, which is output to the matrix-vector multiplication module;
[0042] The data connection of the matrix-vector multiplication module includes:
[0043] Matrix data mat, input, bit length is M*N*WS bits, input from the data storage module;
[0044] Vector data vec, input, bit length is M*N*WS bits, input from the vector copy module;
[0045] The calculation result mv_res is output, with a bit length of N*WS bits, and is output to a bias addition module; its internal connection is:
[0046] The matrix mat and vector res data are divided into M*N parts, each with a length of WS. Each matrix element and each vector element are sent to the M*N multipliers in the dot multiplication module respectively, and all the results are spliced into a matrix mv_tmp with a length of M*N*WS. The result mv_tmp is sent to N addition trees; N addition trees receive the data input mv_tmp of the dot multiplication module, and each addition tree receives a column of matrix data with a bit length of M*WS; the output result is a number with a bit length of WS, and the outputs of N addition trees are spliced into a vector col_sum_res with a length of N*WS, which is output to the vector accumulation module; the vector accumulation module (vec add) has two inputs, one is the output col_sum_res of the addition tree, and the other is the output mv_res of the vector addition after beating. Both bit lengths are N*WS, and the output result mv_res is also N*WS bits long;
[0047] Data connection of the bias addition module:
[0048] Each of the bias addition modules receives inputs from two matrix-vector multiplication modules and a bias vector b;
[0049] There are 4 bias addition modules in the forward reasoning module. The results of every 2 matrix-vector multiplication modules are input to 1 bias addition module. The outputs (x t W i+h t-1 U i +b i 、x t W f +h t-1 U f +b f and x t W o +h t-1 U o +b o ) are connected to three activation function modules (sigmoid), the output of a bias addition module (x t W j +h t-1 U j +b j ) is connected to the input of the activation function module (tanh);
[0050] Each bias addition module receives the results of two matrix-vector multiplication modules and a bias vector b; first inputs the results of the two matrix-vector multiplication modules into the vector addition module and outputs the result of the vector addition to the register, and the bias vector b is tapped by the register FF. The two vectors are input into the vector addition module, and the result of the vector addition (xW+hU+b) is tapped by the register and then output.
[0051] The bit length of the input, intermediate result, and output of the bias addition module is N*WS bits;
[0052] The data connection between the activation function module and the memory vector update module:
[0053] Each activation function module (sigmoid or tanh) receives the output from the bias addition, performs activation operation and outputs the result to the memory vector update module. The bit length of input and output is N*WS.
[0054] The values after the activation function module operation are f t (sigmoid(x t W f +h t-1 U f +b f )),o t (sigmoid(x t W o +h t-1 U o +b o )) and i t (sigmoid(x t W i +h t-1 Ui +b i ));
[0055] The memory vector update module receives the output f from three activation function modules (sigmoid) t , o t and i t and the output of an activation function tanh module At the same time, it receives data from the data storage module BRAM data Inside the memory vector update module, f t and c t-1 Input to the vector multiplication module, i t and Input to the vector multiplication module; connect the outputs of the two vector multiplication modules to the vector addition module; the vector addition module adds the two values and outputs the result to the register for storage; the data result calculated at this time is the memory vector c t , register will c t Output to the activation function module (tanh) and convert the result tanh(c t ) is output to the vector multiplication module; another input of the vector multiplication module is o t The data output after multiple register taps; the output of the vector multiplication o t *tanh(c t ) is another memory vector h t .c t After multiple levels of registers are played, and h t Output simultaneously.
[0056] Furthermore, the DDR data storage chip is used to input the laid-out matrix and vector data to the data acceleration processing chip, including:
[0057] Use zero padding to pad matrices and vectors twice to reach the specified size;
[0058] Divide the zero-filled matrix W or U and vector into several identical two-dimensional operation blocks, where the size of the block is M*N, then the vector h t-1 and x t is divided into multiple one-dimensional vector blocks, the length of the block is M, all bias vectors b and memory vectors c t-1 It is divided into multiple one-dimensional vector operation blocks, and the length of the block is N;
[0059] The matrix and vector data after the above operations are stored in a certain address area in DDR in order. The data arrangement inside each type of matrix on DDR needs to be stored in a block manner. The data is stored between blocks in the order of column priority, and the data is stored in the order of row priority within the block. If it is a vector, the storage method is sequential storage;
[0060] The arranged data is read from the off-chip memory DDR through the read control module and stored in the on-chip memory BRAM in the data storage module; the data arrangement on the on-chip memory BRAM is that each address in the BRAM stores the data of one operation block.
[0061] Beneficial Effects
[0062] The present invention realizes hardware acceleration of the LSTM forward reasoning process; by optimizing the design and hardware structure, the calculation clock frequency of the reasoning is increased to 100M, and the scale of the matrix vector multiplication 32×32 blocks is realized in the forward reasoning process, which improves the parallelism of the calculation; accelerates the reasoning speed of LSTM and improves the speed of the entire calculation. When the calculation clock frequency is 100M and the read and write clock frequency is 125M, the peak computing power of LSTM is increased to 1.7TFLOPS.
[0063] In terms of data storage, double buffering is used for data storage, which improves data throughput. By reading and writing two address spaces in parallel, read and write operations can be performed simultaneously, thereby improving data throughput. This can more effectively utilize the bandwidth of BRAM, speed up data transmission, and improve system performance. Reduced data conflicts, dividing the address space into two blocks can avoid data conflicts between read and write operations. When read and write operations occur in the same address space at the same time, data conflicts and race conditions may occur. By reading and writing two address spaces in parallel, such conflicts can be reduced and the stability and reliability of the system can be improved. Improved parallelism, by reading and writing two address spaces in parallel, the parallelism of the system can be increased. In the LSTM accelerator, read and write operations are independent of each other. By processing these two operations in parallel, system resources can be fully utilized and the parallel computing capability of the system can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] Figure 1 The present invention relates to LSTM neural network;
[0065] Figure 2 FPGA-based LSTM neural network accelerator functional module;
[0066] Figure 3 Matrix data zero filling method;
[0067] Figure 4 How data is stored on DDR;
[0068] Figure 5 Matrix block-storage order between blocks;
[0069] Figure 6 Matrix block-storage order within the block;
[0070] Figure 7 W i How data of the type is stored on the chip;
[0071] Figure 8 Forward reasoning module;
[0072] Fig. 9 Matrix-vector multiplication module;
[0073] Fig.10 Block matrix-vector multiplication algorithm;
[0074] Fig.11 Addition tree module;
[0075] Fig.12 Operation stop request data and operation resumption;
[0076] Fig.13 Bias addition module diagram;
[0077] Fig.14 Update module structure diagram;
[0078] Fig.15 Data is read into on-chip storage via the AXI data bus;
[0079] Fig.16 Read the state transition diagram of the state machine in the control module;
[0080] Fig.17 Double buffer area in data storage module
[0081] Fig.18 Writing back inference results
[0082] Fig.19 LSTM Accelerator Connection Example DETAILED DESCRIPTION
[0083] The following is combined with Figure 1-19 The present invention is described as follows:
[0084] The present invention provides a data processing system based on RTL-level accelerated LSTM neural network, the system comprising a DDR data storage chip and a data acceleration processing chip; the DDR data storage chip is used to input the laid-out matrix and vector data to the data acceleration processing chip;
[0085] In the design of the accelerator, in order to facilitate the calculation and storage of the accelerator, the data needs to be preprocessed to meet the requirements of the operation.
[0086] In the forward reasoning process of LSTM, a total of 15 data types are required, as shown in Table 1.
[0087] Table 1 Data symbols and types involved in forward reasoning
[0088]
[0089] Before entering DDR, these data need to be zero-filled to meet the calculation format and layout. Zero filling is divided into two steps, such as Figure 3 shown.
[0090] The first time, the matrix is padded to an integer multiple of the block size. Let the size of the matrix W be (R, C), where R is the dimension of the input and C is the dimension of the hidden layer. Then the size of U is (C, C). After the first zero padding, the sizes of W and U are (R ext ,C ext ) and (C ext ,R ext ). Where R ext and C ext The calculation method of is shown in formulas (7) and (8), where M and N are the number of rows and columns of blocks in the accelerator's operation, and the ceil function is a round-up function.
[0091]
[0092]
[0093] The second filling is to align the scales of W and U, fill the smaller matrix with 0, and fill it to the size of the other matrix. The scales of W and U are both (R pad ,C pad ), and the calculation method is shown in formulas (9) and (10).
[0094]
[0095] C pad =C ext (10)
[0096] In addition to the matrix, the input x and the hidden layer vector h t-1 Zero padding is also required until the length of the vector is R. pad . All bias vectors b i 、b f 、b j 、b oand the hidden layer vector c t-1 Fill to vector length C pad .
[0097] After zero padding, the data is stored in the off-chip DDR. The storage method is as follows: Figure 4 As shown. i , W f , W j and W o After merging, the data is stored in an address space starting at w_addr. i , U f , U j , U o After merging, they are stored in an address space starting at u_addr.
[0098] All types of W and U matrices are stored after the matrices are divided into blocks, and the divided block data is stored in a column-first manner, that is, all block data in one column block is stored first, and then all block data in the next column block is stored, and so on. Figure 5 The record is a size that divides the matrix into two blocks in the row and column directions, storing matrix block 0, matrix block 1, matrix block 2, and matrix block 3 in sequence. The data in the block is stored in a row-first manner. Figure 6 What is recorded is a matrix block of size 32×32 after block division, and the data of the elements in the matrix block are stored according to the method in the figure.
[0099] b i 、b f 、b j and b o After merging, the data is stored in an address space starting at b_addr. t Stored in an address space starting at x0_addr, n t-1 It is stored in an address space starting from h0_addr. All vectors are stored sequentially.
[0100] During the inference process of the accelerator, the accelerator reads the data from the off-chip DDR and stores it on multiple BRAMs on the chip. According to the size of the matrix block, multiple BRAMs are used to splice into a read port with a data bit width equal to the data bit length of a block. The matrix data and vector data in the DDR are written from the write ports of these BRAMs. After the writing is completed, the data at one address is exactly the data of one operation block. When reading, only one read address needs to be given to complete the reading of all the data of one operation block. Figure 7 The following shows that the matrix type is W iThe data storage method of a matrix of size (R, C) after zero padding is divided into M×N blocks. In the figure, each row is a read address.
[0101] The data acceleration processing chip accelerates the processing of LSTM neural network data through forward reasoning operation; the data acceleration processing chip is composed of a read control module, a data storage module, a forward reasoning module and a write control module; the forward reasoning module is composed of a control unit and a calculation unit; the control unit outputs the read matrix address, vector address and read enable to the outside, initiates the reading of the specified block of the matrix, and the data storage module performs the operation process on the corresponding matrix and vector data:
[0102] The control unit outputs a cd signal, which is connected to an accumulation module in a matrix-vector multiplication module and is used for clearing the accumulation, and the bit length is 1 bit;
[0103] The control unit outputs an intr signal, which is connected to the accumulation module in the matrix-vector multiplication module and is used for the register after the accumulation module to stop receiving the accumulated value, and the bit length is 1 bit.
[0104] The control unit outputs a vec_ofs_o signal, which passes through a multi-level register and is finally used as the output of the forward reasoning module, as an output valid offset signal, marking the offset position of the current operation result in the final result, with a bit length of Y bits;
[0105] The control unit outputs a we_o signal, which passes through a multi-level register and is finally used as the output of the forward reasoning module (, as an output valid signal, marking that the current operation result is valid, and the bit length is 1 bit;
[0106] The control signal outputs the done_o signal, which passes through a multi-level register and finally serves as the output of the forward reasoning module, as a reasoning end signal, marking the end of the current forward reasoning, and has a bit length of 1 bit.
[0107] The computing unit includes a vector replication module, a matrix vector multiplication module, a bias addition module, an activation function module and a memory vector update module, wherein: the forward reasoning module is connected to the data storage module through four groups of signals to realize the accelerated processing of LSTM neural network data: the computing unit accelerates the processing process of LSTM neural network,
[0108] include:
[0109] The vector replication module receives a vector with a length of M*WS bits, outputs it after replication, and outputs it as a matrix with a length of M*N*WS bits, which is output to the matrix-vector multiplication module;
[0110] The data connection of the matrix-vector multiplication module includes:
[0111] Matrix data mat, input, bit length is M*N*WS bits, input from the data storage module;
[0112] Vector data vec, input, bit length is M*N*WS bits, input from the vector copy module;
[0113] The calculation result mv_res is output, with a bit length of N*WS bits, and is output to a bias addition module; its internal connection is:
[0114] The matrix mat and vector res data are divided into M*N parts, each with a length of WS. Each matrix element and each vector element are sent to the M*N multipliers in the dot multiplication module respectively, and all the results are spliced into a matrix mv_tmp with a length of M*N*WS. The result mv_tmp is sent to N addition trees; N addition trees receive the data input mv_tmp of the dot multiplication module, and each addition tree receives a column of matrix data with a bit length of M*WS; the output result is a number with a bit length of WS, and the outputs of N addition trees are spliced into a vector col_sum_res with a length of N*WS, which is output to the vector accumulation module; the vector accumulation module (vec add) has two inputs, one is the output col_sum_res of the addition tree, and the other is the output mv_res of the vector addition after beating. Both bit lengths are N*WS, and the output result mv_res is also N*WS bits long;
[0115] Data connection of the bias addition module:
[0116] Each of the bias addition modules receives inputs from two matrix-vector multiplication modules and a bias vector b;
[0117] There are 4 bias addition modules in the forward reasoning module. The results of every 2 matrix-vector multiplication modules are input to 1 bias addition module. The outputs (x t W i +h t-1 U i +b i 、x t W f +h t-1 U f +b f and x t W o +h t-1 U o +b o ) are connected to the input of three activation function modules (sigmoid), and the output of a bias addition (x t W j +h t-1 Uj +b j ) is connected to the input of the activation function module (tanh);
[0118] Each of the bias addition modules receives the results of the two matrix vector multiplication modules and a bias vector b; first inputs the results of the two matrix vector multiplication modules into the vector addition module and outputs the result of the vector addition to the register, and the bias vector b is tapped by the register FF. The two vectors are input into the vector addition module, and the result of the vector addition (xW+hU+b) is tapped by the register and then output;
[0119] The bit length of the input, intermediate result, and output of the bias addition module is N*WS bits;
[0120] The data connection between the activation function module and the memory vector update module:
[0121] Each activation function module (sigmoid or tanh) receives the output from the bias addition, performs activation operation and outputs the result to the memory vector update module. The bit length of input and output is N*WS.
[0122] The values after the activation function module operation are f t (sigmoid(x t W f +h t-1 U f +b f )),o t (sigmoid(x t W o +h t-1 U o +b o )) and i t (sigmoid(x t W i +h t-1 U i +b i ));
[0123] The memory vector update module receives the output f from three activation function modules (sigmoid) t , o t and i t and the output of an activation function tanh module At the same time, it receives data from the data storage module BRAM data Inside the memory vector update module, f t and c t-1 Input to vector multiplication module it and Input to the vector multiplication module; connect the outputs of the two vector multiplication modules to the vector addition module; the vector addition module adds the two values and outputs the result to the register for storage; the data result calculated at this time is the memory vector c t , register will c t Output to the activation function module and convert the result tanh(c t ) is output to the vector multiplication module; another input of the vector multiplication module is through o t The data output after multiple register taps; the output of the vector multiplication o t *tanh(c t ) is another memory vector h t c t After multiple levels of registers are played, and h t Output simultaneously.
[0124] Matrix-vector multiplication read signal controls all matrices and vectors h t-1 and x t The operation block reads from the data storage module, including:
[0125] The address signal m_addr of the read matrix is an output signal with a bit length of X bits; it is connected to the read address of the BRAM of each storage matrix in the data storage module;
[0126] The address signal v_addr of the read vector is an output signal with a bit length of X bits, which is connected to the data storage module to store h t-1 and x t The read address port of the BRAM;
[0127] Read enable signal ram_en, output signal, bit length is 1 bit, connected to the data storage module to store all matrices and vectors h t-1 and c t-1 The read enable port of the BRAM;
[0128] 8 matrix read data signals, input signals, corresponding to the W and U type data read from the BRAM of the data storage module, with a data length of M*N*WS bits, connected to the matrix input ports of the 8 matrix-vector multiplication modules;
[0129] 2 vector data refers to h t-1 and x t , input signal, the read data output port of the BRAM storing this type of data in the data storage module is connected to the vector input port of the vector copy module respectively, and the bit length is M*WS bits;
[0130] The bias vector read signal includes:
[0131] The biased address signal b_addr is read, and the output signal has a bit length of X bits and is connected to the read address port of each BRAM storing the biased vector in the data storage module.
[0132] The read bias enable signal b_r_en is an output signal with a bit length of 1 bit, which is connected to the read enable port of each BRAM storing the bias vector in the data storage module.
[0133] 4 bias data signals, input signals, are connected from the data output port of the BRAM storing the bias in the data storage module to the bias input port of the bias addition module, and the bit length is N*WS bits;
[0134] c t-1 Reading signals include:
[0135] Read c t-1 The address signal c_addr, output signal, bit length is X bits, connected to the data storage module (storage c t-1 The read address port of the BRAM.
[0136] Read c t-1 The read enable signal c_r_en is an output signal with a bit length of 1 bit, which is connected to the data storage module to store c t-1 The read enable port of the BRAM;
[0137] Read c t-1 The data, input signal, bit length is N*WS bits, stored in the data storage module c t-1 The data output port of the BRAM is connected to the memory vector update module.
[0138] Other control signals include:
[0139] The number of operation blocks in the current data storage module is mat_block_num, the input signal, the bit length is Y bits, connected from the start signal control module to the control unit in the forward reasoning module;
[0140] Control signal start, input signal, controls the first start of reasoning, bit length is 1 bit, connected from the start signal control module to the control unit in the forward reasoning module;
[0141] Control signal conti, input signal, controls the continuation of reasoning, bit length is 1 bit, connected from the start signal control module to the control unit in the forward reasoning module;
[0142] The control signal req, input signal, forward reasoning stops, has a bit length of 1 bit, and is connected from the control module in the forward reasoning module to the data storage module;
[0143] The row block number row_block_num of the matrix, the input signal, the bit length is Y bits, as the input of the forward reasoning module, connected to the control unit;
[0144] The number of column blocks of the matrix col_block_num, the input signal, the bit length is Y bits, as the input of the forward reasoning module, connected to the control unit.
[0145] The neural network data processing system includes: a read control module (LSTM read channel), a data storage module (SDP buf), a forward reasoning module (LSTM cell unit), and a write control module (LSTM write channel). The functional modules of the FPGA-based LSTM neural network accelerator are as follows: Figure 2 As shown. The read control module reads the data required for the LSTM forward reasoning operation from the DDR data storage chip and stores it in the data storage module. The forward reasoning module obtains the data required for the operation from the data storage module, performs forward reasoning, and waits for new data from the data storage module when the data is insufficient. The write control module receives the calculation results from the forward reasoning module and transmits the results to the DDR data storage chip.
[0146] After receiving the start signal, the control unit of the forward reasoning module (LSTM cell unit) sends a control signal to read the parameter matrix block and input vector block that need to be calculated in a certain order. These data are sequentially processed according to the forward reasoning part of the LSTM unit, and the module reuse and parallel operation are realized through the pipeline.
[0147] The forward reasoning module consists of two parts: the control unit and the computing unit. Figure 8 shown.
[0148] The control unit (ctrl_unit) is a state machine that outputs the read matrix address (m_addr), vector address (v_addr) and read enable (ram_en) to initiate the reading of the specified block of the matrix. The data storage module inputs the corresponding matrix and vector data (w, u, x and h) into the accelerator module for calculation. The control unit also sends out the data valid signal we and the data offset signal vec_ofs as the effective signal and bias of the calculation, and the hidden layer long-term memory vector c t-1 The read control signal.
[0149] The calculation unit includes a vector duplication module (wor_dup), a matrix vector multiplication module (mat_vec_mul), a bias addition module (bias_add), an activation function module (sigmoid, tanh) and a memory vector update module (vec_mul, vec_add, tanh, etc.). Figure 8 As shown, the matrix and vector data are respectively input into the matrix-vector multiplication plus bias module (xwhub), and then pass through two of the matrix-vector multiplication modules in turn, and then add the two multiplication results, add the bias vector, and then pass through the activation function module, and finally calculate the new hidden layer vector according to the output of the activation function.
[0150] Matrix-vector multiplication module (mat_vec_mul): The matrix-vector multiplication module receives matrix block and vector block data from bram, and passes the data through the dot multiplication module, addition tree module and accumulation module in sequence to complete the matrix-vector multiplication. Fig. 9 The figure below shows the structure diagram of a matrix-vector multiplication with a block size of 4×4. Fig.10 It is an algorithm for block matrix-vector multiplication, that is, after the matrix vector is divided into blocks, the result of the matrix-vector multiplication of each block is calculated in sequence within the column block, and these results in the column block are accumulated to obtain the final result of the matrix-vector multiplication of this column block, and then each column block is calculated backward in turn to obtain the results of all matrix-vector multiplications.
[0151] like Fig. 9 As shown in the figure, before entering the matrix-vector multiplication operation, the vector needs to be input into the word_dup module, the vector is copied to the same size as the matrix, and then input into the dot multiplication module mul_units. The dot multiplication module mul_units implements the dot multiplication of matrix elements and vector elements. The dot multiplication module includes multiple multipliers; the total number of multipliers is the same as the size of the input matrix and the copied vector. Each multiplier will perform overflow processing after multiplication. If positive or negative overflow occurs, it will be replaced by the maximum or minimum value. The accumulation module consists of a vector addition module (vec add) and a register (FF). Vector addition will add the value of the register output after vector addition and the output of the current multi-group addition tree, and output it to the input of the register. If the data input to the accumulation module is the calculated value of the data of the first row block of the current column block, 0 is added to the value and the result is output to the input of the register. If the input of the accumulation module is the calculated value of the last row block data of the current column block, the sum of this value and the output of the register is the result of the matrix-vector multiplication completed by all the row blocks of the current column block.
[0152] After multiplication, the data in the same column of the multiplication result is input into an addition tree, and the data in this column is evenly divided into 2 groups. Each group of data is sent to the recursive subtree for calculation. After the two subtrees calculate the sum of the two groups of data, the two sums are added and then beat. After beating at the root node of the addition tree, overflow judgment is performed. The structure of the addition tree is as follows: Fig.11 shown.
[0153] The accelerator supports stopping calculation when data is insufficient, requesting data, and resuming calculation after obtaining sufficient data. The control method is as follows Fig.12 As shown. The read control module inputs the number of blocks currently read in (mat_block_num) and the valid data signal of the data (mat_block_num_we) into the start signal generation module (cal start gen), and transmits the transmission completion signal (axi_done) to the data storage module after all parameters are written. After the data storage module (sdp buf) completes the selection of the corresponding read area according to the transmission completion signal (axi_done), it sends a recovery calculation signal (conti) to the start signal generation module (cal start gen), which generates a start or recovery signal (the first calculation generates a start signal start2ctrl; the subsequent calculation is a recovery signal conti2ctrl), and sends the corresponding total number of blocks that can be calculated (mat_block_num2ctrl) to the control unit (ctrl_unit) in the forward reasoning module. After receiving the start or resume signal, the control unit starts the state machine and starts counting the operation blocks. When the count reaches the total number of blocks, it sends a stop operation signal (intr) to act on the register (FF) after the vector addition module (vec add) in the matrix vector multiplication module (mat vec mul) in the forward reasoning module (lstm cell unit), and sends a request data signal to the data storage module (sdp buf) to request new data. When intr is pulled high, the register stops receiving the output of the vector addition module; when intr becomes low, the register continues to receive the result of the vector addition module.
[0154] Bias addition, the output and bias of the matrix-vector multiplication module are input into this module at the same time. First, the results of the two matrix-vector multiplications are added, and the result of the addition and the bias are temporarily stored in a register, and then input into the next vector addition module. After the result is output, it is stored again, and the result obtained is the result of the bias addition module. Fig.13 Block diagram for bias addition.
[0155] The activation function is fitted using a piecewise second-order function, and shiftable parameters are used during the fitting process to replace the multiplication operation in the fitting process, thereby consuming fewer multipliers and reducing the resource consumption of the activation function. The function expressions of sigmoid and tanh are shown in formulas (11) and (12); the second-order expressions after fitting are shown in formulas (13) and (14). The calculation of the entire activation function module consumes a total of 5 calculation cycles.
[0156]
[0157]
[0158]
[0159]
[0160] The memory vector update module calculates the new memory vector according to the obtained structure after completing the output of the gate structure. The calculation module is shown in the figure below. Fig.14 As shown. While completing the vector multiplication, o which is not involved in the operation t Because the multiplication operation requires 3 cycles to calculate the result, 3 levels of storage are used to store o in sequence. t Then the result of the two vector multiplications is input into the vector addition, and after the vector addition, a register is used to store the addition result. t Register again. Then input the data into the vector activation module. This calculation process consumes a total of 5 cycles, so here is o t Store 5 times; the result of the addition is the long-term memory vector c in the new hidden layer vector t , in order to output it simultaneously with the short-term memory vector ht, here c t Continue to deposit until and h t Output at the same time. The value after passing the activation function and the value after multiple storage t Input into the vector multiplication module, the result is the short-term memory vector ct in the new hidden layer.
[0161] The present invention is based on double buffering data interaction interface
[0162] Fig.15The data is read in as shown in the figure. The AXI master interface (AXI master controller) receives the read data request initiated by the read control module (LSTM read channel) and converts it into an AXI read request to send out. The read control module (LSTM read channel) is responsible for initiating data requests for different matrices and vectors, and outputs the requested data to the data storage module (SDP buf).
[0163] The Master interface reads data from DDR through the read channel of AXI.
[0164] The read control module initiates a read request of a certain data type, which is implemented by a state machine. After receiving the start signal bus_start, the state machine starts and initiates a request from the matrix type WI to CT. After receiving the done signal indicating the end of this transmission, it jumps to the next sending state. The state transition of this state machine is as follows Fig.16 As shown. After receiving the start signal bus_start, it jumps to the TYPE_WI state. The TYPE_WI state is to initiate the reading of the specified scale of the WI type parameters. When the read control module completes the reading of the WI type parameters once, it receives the transmission completion signal done and jumps to the next type of parameter reading state. In the TYPE_CT state, if all the data has been read in, it jumps to the DONE state, indicating that all the data reading is completed, and automatically jumps back to the initial state IDLE in the next cycle; if all the data has not been read in, it jumps to the TYPE_WI state and repeats a new round of data reading.
[0165] The data storage module (sdp buf) is used to store matrix parameters and vectors for LSTM forward reasoning. In the data transmission phase, data is written from the control unit to the BRAM; in the calculation phase, data is output to the calculation module according to the read signal for forward reasoning. Inside the data storage module, data reading and writing are achieved through double buffering. The data storage module consists of 15 groups of on-chip brams. The address space of these brams is divided into two buffers according to the highest bit of the address bit: high address buffer and low address buffer, such as Fig.17As shown in the figure. Data is written to a buffer under the write clock (wr_clk). After writing, this part randomly enters the readable state. Data can be read from this part under the read clock (rd_clk) for forward reasoning; at this time, data is written to another buffer. This operation realizes parallel processing of read and write data, improves data throughput, and reduces data waiting time during calculation. The control of read and write buffers is implemented by the storage control module (mem ctrl) in the data storage module. This module outputs a wr_en0 and a rd_en0 signal as the highest bit of the write and read addresses to control which buffer the read and write are applied to.
[0166] like Fig.18 After the inference is completed, the write control module (lstm write channel) temporarily stores the two memory vectors. When the temporarily stored vectors reach the default transmission length specified by the parameters, a data transmission is initiated, and the data is sent to the MASTER interface through communication with the MASTER interface, and the result is sent to the DDR through the write channel of the MASTER interface.
[0167] like Fig.19 , the LSTM accelerator is connected to the AXI interconnect via the AXI bus. The AXI interconnect enables bus communication between multiple hosts and one slave, or one host and multiple slaves via the AXI bus. The AXIinterconnect connects the MIG IP core to manage the reading and writing of data to the off-chip DDR. The AXI interconnect connects the processor soft core microblaze, which is responsible for the execution of instructions. In this way, microblaze writes data to the DDR, and then executes the instructions required to calculate the LSTM, reading data from the off-chip DDR to the accelerator module via the AXI bus. The accelerator module performs forward reasoning and writes the reasoning results back to the DDR via the AXI bus.
[0168] For all the above modules, add physical constraints to the input and output pins of the top-level module, add master clock constraints to the clock module, generate a bitstream file after synthesis and implementation, and burn it into the FPGA device. Although the present invention is described above, the present invention is not limited to the above specific implementation methods. The above specific implementation methods are only illustrative and not restrictive. Under the enlightenment of the present invention, ordinary technicians in this field can make many variations without departing from the purpose of the present invention, which are all within the protection of the present invention.
Claims
1. A system for accelerating the processing of LSTM neural network data based on RTL level, the system comprising a DDR data storage chip and a data acceleration processing chip; the DDR data storage chip is used to input the laid-out matrix and vector data to the data acceleration processing chip; the data acceleration processing chip accelerates the processing of LSTM neural network data through forward reasoning operations; characterized in that The data acceleration processing chip is composed of a read control module, a data storage module, a forward reasoning module and a write control module; the forward reasoning module is composed of a control unit and a calculation unit; the calculation unit includes a vector replication module, a matrix vector multiplication module, a bias addition module, an activation function module and a memory vector update module, wherein: the forward reasoning module reads the signal through the matrix vector multiplication, the bias vector reads the signal, c t-1 Data read signals and other control signals are connected to the data storage module to accelerate the processing of LSTM neural network data: The matrix-vector multiplication read signal controls all matrices and vectors h t-1 and x t The operation block reads from the data storage module, including: The address signal m_addr of the read matrix is an output signal with a bit length of X bits; it is connected to the read address of the BRAM of each storage matrix in the data storage module; The address signal v_addr of the read vector is an output signal with a bit length of X bits, which is connected to the data storage module to store h t-1 and x t The read address port of the BRAM; Read enable signal ram_en, output signal, bit length is 1 bit, connected to the data storage module to store all matrices and vectors h t-1 and c t-1 The read enable port of the BRAM; 8 matrix read data signals, input signals, corresponding to the W and U type data read from the BRAM of the data storage module, with a data length of M*N*WS bits, connected to the matrix input ports of the 8 matrix-vector multiplication modules; 2 vector data refers to h t-1 and x t , input signal, the read data output port of the BRAM storing this type of data in the data storage module is connected to the vector input port of the vector copy module respectively, and the bit length is M*WS bits; The bias vector reading signal includes: Read the biased address signal b_addr, output signal, bit length is X bits, connected to the read address port of each BRAM storing the bias vector in the data storage module; Read bias enable signal b_r_en, output signal, bit length is 1 bit, connected to the read enable port of each BRAM storing bias vector in the data storage module; 4 bias data signals, input signals, are connected from the data output port of the BRAM storing the bias in the data storage module to the bias input port of the bias addition module, and the bit length is N*WS bits; The c t-1 Reading signals include: Read c t-1 The address signal c_addr, output signal, bit length is X bits, connected to the data storage module to store c t-1 The read address port of the BRAM; Read c t-1 The read enable signal c_r_en is an output signal with a bit length of 1 bit, which is connected to the data storage module to store c t-1 The read enable port of the BRAM; Read c t-1 The data, input signal, bit length is N*WS bits, stored in the data storage module c t-1 The data output port of the BRAM is connected to the memory vector update module; The other control signals include: The number of operation blocks in the current data storage module is mat_block_num, the input signal, the bit length is Y bits, connected from the start signal control module to the control unit in the forward reasoning module; Control signal start, input signal, controls the first start of reasoning, bit length is 1 bit, connected from the start signal control module to the control unit in the forward reasoning module; Control signal conti, input signal, controls the continuation of reasoning, bit length is 1 bit, connected from the start signal control module to the control unit in the forward reasoning module; The control signal req, input signal, forward reasoning stop, has a bit length of 1 bit, and is connected from the control unit in the forward reasoning module to the data storage module; The row block number row_block_num of the matrix, the input signal, the bit length is Y bits, as the input of the forward reasoning module, connected to the control unit; The number of column blocks of the matrix col_block_num, the input signal, the bit length is Y bits, as the input of the forward reasoning module, connected to the control unit.
2. A system for accelerating the processing of LSTM neural network data based on RTL level according to claim 1, characterized in that: The control unit outputs the read matrix address, vector address and read enable to initiate the reading of the specified matrix block, and the data storage module performs the operation process on the corresponding matrix and vector data: The control unit outputs a cd signal, which is connected to an accumulation module in a matrix-vector multiplication module and is used for clearing the accumulation, and the bit length is 1 bit; The control unit outputs an intr signal, which is connected to the accumulation module in the matrix-vector multiplication module and is used for the register after the accumulation module to stop receiving the accumulated value, and the bit length is 1 bit; The control unit outputs a vec_ofs_o signal, which passes through a multi-level register and is finally used as the output of the forward reasoning module, as an output valid offset signal, marking the offset position of the current operation result in the final result, with a bit length of Y bits; The control unit outputs a we_o signal, which passes through a multi-level register and is finally used as the output of the forward reasoning module as an output valid signal, marking that the current operation result is valid, and the bit length is 1 bit; The control signal outputs the done_o signal, which passes through a multi-level register and finally serves as the output of the forward reasoning module, as a reasoning end signal, marking the end of the current forward reasoning, and has a bit length of 1 bit.
3. A system for accelerating the processing of LSTM neural network data based on RTL level according to claim 1, characterized in that: The computing unit accelerates the LSTM neural network, including: The vector replication module receives a vector with a length of M*WS bits, outputs it after replication, and outputs it as a matrix with a length of M*N*WS bits, which is output to the matrix-vector multiplication module; The data connection of the matrix-vector multiplication module includes: Matrix data mat, input, bit length is M*N*WS bits, input from the data storage module; Vector data vec, input, bit length is M*N*WS bits, input from the vector copy module; The calculation result mv_res is output, with a bit length of N*WS bits, and is output to a bias addition module; its internal connection is: The matrix mat and vector res data are divided into M*N parts, each with a length of WS. Each matrix element and each vector element are sent to the M*N multipliers in the dot multiplication module respectively, and all the results are spliced into a matrix mv_tmp with a length of M*N*WS. The result mv_tmp is sent to N addition trees; N addition trees receive the data input mv_tmp of the dot multiplication module, and each addition tree receives a column of matrix data with a bit length of M*WS; the output result is a number with a bit length of WS, and the outputs of N addition trees are spliced into a vector col_sum_res with a length of N*WS, which is output to the vector accumulation module; the vector accumulation module (vec add) has two inputs, one is the output col_sum_res of the addition tree, and the other is the output mv_res of the vector addition after beating. Both bit lengths are N*WS, and the output result mv_res is also N*WS bits long; Data connection of the bias addition module: Each of the bias addition modules receives inputs from two matrix-vector multiplication modules and a bias vector b; There are 4 bias addition modules in the forward reasoning module. The results of every 2 matrix-vector multiplication modules are input to 1 bias addition module. The output x of the 3 bias addition modules is t W i +h t-1 U i +b i 、x t W f +h t-1 U f +b f and x t W o +h t-1 U o +b o Connected to the input of three sigmoid activation function modules respectively, and the output x of a bias addition t W j +h t-1 U j +b j Connect to the input of the tanh activation function module; Each of the bias addition modules receives the results of the two matrix-vector multiplication modules and a bias vector b; firstly inputs the results of the two matrix-vector multiplication modules into the vector addition module and outputs the result of the vector addition to the register, and the bias vector b is beat by the register FF; the two vectors are input into the vector addition module, and the result of the vector addition (xW+hU+b) is output after being beat by the register; The bit length of the input, intermediate result, and output of the bias addition module is N*WS bits; The data connection between the activation function module and the memory vector update module: Each activation function module (sigmoid or tanh) receives the output from the bias addition, performs activation operation and outputs the result to the memory vector update module. The bit length of input and output is N*WS. The values after the activation function module operation are f t , o t and i t ; The memory vector update module receives the output f from three sigmoid activation function modules t , o t and i t and the output of a tanh activation module At the same time, it receives data from the data storage module BRAM data Inside the memory vector update module, f t and c t-1 Input to the vector multiplication module, i t and Input to the vector multiplication module; connect the outputs of the two vector multiplication modules to the vector addition module; the vector addition module adds the two values and outputs the result to the register for storage; the data result calculated at this time is the memory vector c t , register will c t Output to the tanh activation function module, and output the result to the vector multiplication module; another input of the vector multiplication module is o t The data output after multiple register taps; the output of the vector multiplication is another memory vector h t ;c t After multiple levels of registers are played, and h t Output simultaneously.
4. A system for accelerating the processing of LSTM neural network data based on RTL level according to any one of claims 1 to 3, characterized in that: The DDR data storage chip is used to input the laid-out matrix and vector data to the data acceleration processing chip, including: Use zero padding to pad matrices and vectors twice to reach the specified size; Divide the zero-filled matrix W or U and vector into several identical two-dimensional operation blocks, where the size of the block is M*N, then the vector h t-1 and x t is divided into multiple one-dimensional vector blocks, the length of the block is M, all bias vectors b and memory vectors c t-1 It is divided into multiple one-dimensional vector operation blocks, and the length of the block is N; The matrix and vector data after the above operations are stored in a certain address area in DDR in order. The data arrangement inside each type of matrix on DDR needs to be stored in a block manner. The data is stored between blocks in the order of column priority, and the data is stored in the order of row priority within the block. If it is a vector, the storage method is sequential storage; The arranged data is read from the off-chip memory DDR through the read control module and stored in the on-chip memory BRAM in the data storage module; the data arrangement on the on-chip memory BRAM is that each address in the BRAM stores the data of one operation block.
Citation Information
Patent Citations
Design method of hardware accelerator based on LSTM recursive neural network algorithm on FPGA platform
CN108090560A
LSTM (Long Short-Term Memory) forward direction operation accelerator based on FPGA (Field Programmable Gate Array)
CN108763159A
Inference engine acceleration for video analytics in computing environments
CN110866859A
Efficient LSTM accelerator based on FPGA
CN113191494A
Hardware Accelerator for Compressed LSTM
US20180174036A1
Cited By
Long and short time memory network computing chip and method for MIMO time sequence signals
CN121072631A
