A method for transposing, transposed multiplication and multiplication in matrix operation

By dividing and processing sub-matrices, the problems of large hardware resource consumption and wasted bus bandwidth in matrix operations are solved, achieving more efficient matrix operations.

CN116070072BActive Publication Date: 2026-05-19HANGZHOU NATCHIP SCI & TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HANGZHOU NATCHIP SCI & TECH CO LTD
Filing Date
2023-02-03
Publication Date
2026-05-19

AI Technical Summary

Technical Problem

Existing matrix operation hardware consumes a lot of resources and wastes a lot of bus bandwidth, which limits the area and performance of artificial intelligence chips.

Method used

The system employs a matrix transpose processing unit, a matrix transpose multiplication processing unit, an output unit, and an intermediate buffer. By dividing the matrix into sub-matrices and grandchildren matrices for processing, it reduces the number of times data is repeatedly accessed and the area of ​​the intermediate buffer, thereby saving bus bandwidth.

Benefits of technology

It reduces hardware resource consumption and bus bandwidth, and improves the efficiency and speed of matrix operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure QLYQS_1
    Figure QLYQS_1
  • Figure QLYQS_4
    Figure QLYQS_4
  • Figure QLYQS_5
    Figure QLYQS_5
Patent Text Reader

Abstract

The application discloses a method for transposing, transposing multiplication and multiplication in matrix operation. The method is realized by a matrix transposing processing unit, a matrix transposing multiplication processing unit, an output unit and two intermediate caches. The matrix transposing processing unit performs transposing processing on input data; the matrix transposing multiplication processing unit acquires data of two input matrices and performs transposing multiplication processing of one matrix on another matrix; the output unit takes out data from the intermediate caches and writes the data into an external memory; the matrix transposing processing unit and the matrix transposing multiplication processing unit share one output unit; the intermediate caches store data in a processing process; when the output unit uses one intermediate cache for output, the processing unit uses another intermediate cache for data caching. The method uses the matrix transposing multiplication mode, two matrix multiplication adopts a column data operation method, reduces the number of repeated data taking and the area of the intermediate cache, and saves the bus bandwidth and operation time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of integrated circuit design technology, especially the field of artificial intelligence technology, and specifically relates to a method for transpose, transpose multiplication and multiplication in matrix operations. Background Technology

[0002] With the development of artificial intelligence (AI) technology, more and more AI chips are being used in daily life and production. Matrix operations, as a foundation of AI technology, are also widely used. In many small AI chip applications, matrix operations, as one component, limit the overall size and performance of the AI ​​chip in terms of hardware resources and processing speed. Existing matrix operation hardware performs operations on entire rows and columns, resulting in a significant waste of intermediate cache resources or bus bandwidth. Summary of the Invention

[0003] The purpose of this invention is to provide a method for transpose, transpose multiplication, and multiplication in matrix operations, so that the entire matrix operation device can occupy less hardware resources and save more bus bandwidth.

[0004] This invention is implemented through a matrix transpose processing unit, a matrix transpose multiplication processing unit, an output unit, and two intermediate buffers. Wherein:

[0005] The matrix transpose processing unit is used to obtain the input data to be transposed from the external storage unit via the bus and perform transpose processing.

[0006] The matrix transpose multiplication processing unit is used to obtain data of two input matrices from an external storage unit via a bus and perform the transpose multiplication of one matrix by the other.

[0007] The output unit is used to retrieve data from the intermediate buffer and write it to the external storage unit via the bus; the matrix transpose processing unit and the matrix transpose multiplication processing unit share one output unit.

[0008] Intermediate buffers are used to store data during processing. Two intermediate buffers are used: when the output unit uses one intermediate buffer for output, the processing unit uses the other intermediate buffer for data caching.

[0009] The methods of this invention include matrix transpose method, matrix transpose multiplication method, and matrix multiplication method.

[0010] The matrix transpose method is as follows:

[0011] Step (1) Transpose N that needs to be transposed a Line M a column matrix Divide into P sub-matrices according to columns. This indicates rounding up, where L is the division length.

[0012] Step (2) divides each submatrix into Q grandchild matrices according to their rows. For a submatrix A′1, its grandchild matrix

[0013]

[0014]

[0015] thus

[0016] Step (3) The matrix transpose processing unit first reads the grandson matrix A″ from the external storage unit via the bus. 1,1 The first row is written to the first column of the first intermediate buffer, then the second row is written to the second column of the first intermediate buffer, and so on, until the Lth row is written to the Lth column of the first intermediate buffer, thus completing the Sun matrix A″. 1,1 The input processing unit will output the processed grandchild matrix. Write to external storage units via bus.

[0017] Step (4) The matrix transpose processing unit reads the grandson matrix A1′ from the external storage unit via the bus. , The first row of matrix A1' is written to the first column of the second intermediate buffer, then the second row is written to the second column of the second intermediate buffer, and so on. The Lth row is written to the Lth column of the second intermediate buffer, thus completing the grandson matrix A1'. , The input processing of '2' will result in the output unit processing the grandchild matrix. Write to external storage units via bus.

[0018] Step (5) continues in this manner. After processing all the grandchild matrices of submatrix A1′, the grandchild matrices of submatrix A2′ are processed to finally obtain the transpose matrix.

[0019] The matrix transpose multiplication method is H = B T ×C, the number of rows N of matrix B b With the number of rows N of matrix C c Equal, N b =N c =N; The specific method is as follows:

[0020] Step (A) will transform the matrix Divide into K sub-matrices according to the method in step (1).

[0021]

[0022] matrix Divide into G sub-matrices according to the method in step (1).

[0023]

[0024] Step (B) involves processing submatrix B1′ and submatrix C1′ as follows:

[0025] (B-1) The matrix transpose multiplication processing unit first reads the data of the first row of submatrix B1′ and the first row of submatrix C1′ from the external storage unit via the bus; then it multiplies the data of the first row and first column of submatrix B1′ by... 1,1 The data c in the first row and first column of submatrix C1′ 1,1 Multiply, as the first intermediate matrix D 1 Store the data in the first row and first column of the first intermediate buffer; store the data in the first row and first column of the submatrix B1′. 1,1 The data c in the first row and second column of submatrix C1′ 1,2 Multiply, as the first intermediate matrix D 1 The data in the first row and second column is stored in the first intermediate cache; and so on, to obtain the first intermediate matrix D. 1 The first row of data;

[0026] The data b in the first row and second column of submatrix B1' 1,2 The data c in the first row and first column of submatrix C1′ 1,1 Multiply, as the first intermediate matrix D 1 The data in the second row and first column of submatrix B1' is stored in the first intermediate buffer; the data in the first row and second column of submatrix B1' is stored in the first intermediate buffer. 1,2 The data c in the first row and second column of submatrix C1′ 1,2 Multiply, as the first intermediate matrix D 1 The data in the second row and second column is stored in the first intermediate cache; and so on, to obtain the first intermediate matrix D. 1 The second row of data;

[0027] By analogy, the intermediate matrix is ​​obtained. in

[0028] (B-2) The matrix transpose multiplication processing unit reads the data from the second row of submatrix B1′ and the second row of submatrix C1′ from the external storage unit via the bus; it then multiplies the data in the first column of the second row of submatrix B1′ by... 2,1 The data c in the second row and first column of submatrix C1′ 2,1 Multiply and add the first intermediate matrix D. 1 Data in the first row and first column As the second intermediate matrix D 2 Store the data in the first row and first column of submatrix B1′ into the first intermediate buffer; store the data in the second row and first column of submatrix B1′ into the first intermediate buffer. 2,1 The data c in the second row and second column of submatrix C1′ 2,2 Multiply and add the first intermediate matrix D. 1 Data in the first row and second column As the second intermediate matrix D 2 The data in the first row and second column is stored in the first intermediate cache; and so on, to obtain the second intermediate matrix D. 2 The first row of data;

[0029] The data b in the second row and second column of submatrix B1' 2,2 The data c in the second row and first column of submatrix C1′ 2,1 Multiply and add the first intermediate matrix D. 1 Data in the second row and first column As the second intermediate matrix D 2 The data in the second row and first column of submatrix B1' is stored in the first intermediate cache; the data in the second row and second column of submatrix B1' is... The data c in the second row and second column of submatrix C1′ 2,2 Multiply and add the first intermediate matrix D. 1 Data in the second row and second column As the second intermediate matrix D 2 The data in the second row and second column is stored in the first intermediate cache; and so on, to obtain the second intermediate matrix D. 2 The second row of data;

[0030] By analogy, the second intermediate matrix is ​​obtained.

[0031] (B-3) The matrix transpose multiplication processing unit reads the data from the third row of submatrix B1' and the third row of submatrix C1' from the external storage unit via the bus; and multiplies the data in the first column of the third row of submatrix B1' by... 3,1 The data c in the third row and first column of submatrix C1′ 3,1 Multiply and add the second intermediate matrix D. 2 Data in the first row and first column As the third intermediate matrix D 3 The data in the first row and first column of submatrix B1' is stored in the first intermediate buffer; the data in the third row and first column of submatrix B1' is stored in the first intermediate buffer. 3,1 The data c in the third row and second column of submatrix C1′ 3,2 Multiply and add the second intermediate matrix D. 2 Data in the first row and second column As the third intermediate matrix D 3The data in the first row and second column is stored in the first intermediate cache; and so on, to obtain the second intermediate matrix D. 3 The first row of data;

[0032] The data b in the third row and second column of submatrix B1' 3,2 The data c in the third row and first column of submatrix C1′ 3,1 Multiply and add the second intermediate matrix D. 2 Data in the second row and first column As the third intermediate matrix D 3 The data in the second row and first column of submatrix B1' is stored in the first intermediate buffer; the data in the third row and second column of submatrix B1' is stored in the first intermediate buffer. 3,2 The data c in the third row and second column of submatrix C1′ 3,2 Multiply and add the second intermediate matrix D. 2 Data in the second row and second column As the third intermediate matrix D 3 The data in the second row and second column is stored in the first intermediate cache; and so on, to obtain the third intermediate matrix D. 3 The second row of data;

[0033] By analogy, the third intermediate matrix is ​​obtained.

[0034] (B-4) and so on, to obtain the Nth intermediate matrix. D is a submatrix of the transpose multiplication result matrix H. 1,1 Store it in the first intermediate buffer; the output unit will store the submatrix D. 1,1 Write to external storage units via bus.

[0035] Step (C) performs the same processing on submatrix B′1 and submatrix C′2 to obtain submatrix D of the transpose multiplication result matrix H. 1,2 Store it in the second intermediate buffer; the output unit will store the submatrix D. 1,2 Write to external memory via the bus; and so on, link submatrix B′1 and submatrix C′1. G The same process is performed to obtain submatrix D. 1,G The data is stored sequentially in the first or second intermediate buffer; the output unit will store the submatrix D. 1,G Write to external storage units via bus.

[0036] Step (D) replaces submatrix B′1 with submatrix B′2, and repeats steps (B) and (C) to obtain submatrix D of the transpose multiplication result matrix H. 2,1 D 2,2 ,…,D 2,G ; and so on, to obtain the submatrix D of the transpose multiplication result matrix H. K,1 D K,2,…,D K,G Thus, the external storage unit obtains the transpose multiplication result matrix.

[0037] The matrix multiplication method is S = E × F, where the number of columns in matrix E is equal to the number of rows in matrix F. First, using the matrix transpose method, we obtain the transpose matrix E of matrix E. T Then, the matrix transpose multiplication processing unit reads the transpose matrix E from the external storage unit via the bus. T Given matrix F, multiply by matrix transpose to obtain matrix S = (E T ) T ×F=E×F.

[0038] This invention achieves matrix transposition, transpose multiplication, and multiplication through a combination of transpose and multiplication. Using matrix transpose multiplication, the operation between row data of one matrix and column data of another matrix is ​​transformed into an operation between the column data of the two matrices. This method reduces the number of repeated data retrievals and the area of ​​intermediate buffers, while also saving bus bandwidth and computation time. Detailed Implementation

[0039] A method for transpose, transpose multiplication, and multiplication in matrix operations is implemented through a matrix transpose processing unit, a matrix transpose multiplication processing unit, an output unit, and two intermediate buffers. Wherein:

[0040] The matrix transpose processing unit is used to obtain the input data to be transposed from the external storage unit via the bus and perform transpose processing.

[0041] The matrix transpose multiplication processing unit is used to obtain data of two input matrices from an external storage unit via a bus and perform the transpose multiplication of one matrix by the other.

[0042] The output unit is used to retrieve data from the intermediate buffer and write it to the external storage unit via the bus; the matrix transpose processing unit and the matrix transpose multiplication processing unit share one output unit.

[0043] Intermediate buffers are used to store data during processing. Two intermediate buffers are used: when the output unit uses one intermediate buffer for output, the processing unit uses the other intermediate buffer for data caching.

[0044] The methods of this invention include matrix transpose method, matrix transpose multiplication method, and matrix multiplication method.

[0045] The matrix transpose method is as follows:

[0046] Step (1) Transpose N that needs to be transposed a Line M a column matrix Divide into P sub-matrices according to columns.

[0047] This indicates rounding up, where L is the division length.

[0048] Step (2) divides each submatrix into Q grandchild matrices according to their rows. For a submatrix A1′, its grandchild matrix

[0049]

[0050]

[0051] thus

[0052] Step (3) The matrix transpose processing unit first reads the grandson matrix A″ from the external storage unit via the bus. 1,1 The first row is written to the first column of the first intermediate buffer, then the second row is written to the second column of the first intermediate buffer, and so on, until the Lth row is written to the Lth column of the first intermediate buffer, thus completing the Sun matrix A″. 1,1 The input processing unit will output the processed grandchild matrix. Write to external storage units via bus.

[0053] Step (4) The matrix transpose processing unit reads the grandson matrix A″ from the external storage unit via the bus. 1,2 The first row is written to the first column of the second intermediate buffer, then the second row is written to the second column of the second intermediate buffer, and so on, until the Lth row is written to the Lth column of the second intermediate buffer, thus completing the Sun matrix A″. 1,2 The input processing unit will output the processed grandchild matrix. Write to external storage units via bus.

[0054] Step (5) continues in this manner. After processing all the grandchild matrices of submatrix A′1, the grandchild matrices of submatrix A′2 are processed to finally obtain the transpose matrix.

[0055] The matrix transpose multiplication method is H = B T ×C, the number of rows N of matrix B b With the number of rows N of matrix C c Equal, N b =N c =N; The specific method is as follows:

[0056] Step (A) will transform the matrix Divide into K sub-matrices according to the method in step (1).

[0057]

[0058] matrix Divide into G sub-matrices according to the method in step (1).

[0059]

[0060] Step (B) involves processing submatrix B1′ and submatrix C1′ as follows:

[0061] (B-1) The matrix transpose multiplication processing unit first reads the data of the first row of submatrix B1′ and the first row of submatrix C1′ from the external storage unit via the bus; then it multiplies the data of the first row and first column of submatrix B1′ by... 1,1 The data c in the first row and first column of submatrix C1′ 1,1 Multiply, as the first intermediate matrix D 1 Store the data in the first row and first column of the first intermediate buffer; store the data in the first row and first column of the submatrix B1′. 1,1 The data c in the first row and second column of submatrix C1′ 1,2 Multiply, as the first intermediate matrix D 1 The data in the first row and second column is stored in the first intermediate cache; and so on, to obtain the first intermediate matrix D. 1 The first row of data;

[0062] The data b in the first row and second column of submatrix B1' 1,2 The data c in the first row and first column of submatrix C1′ 1,1 Multiply, as the first intermediate matrix D 1 The data in the second row and first column of submatrix B1' is stored in the first intermediate buffer; the data in the first row and second column of submatrix B1' is stored in the first intermediate buffer. 1,2 The data c in the first row and second column of submatrix C1′ 1,2 Multiply, as the first intermediate matrix D 1 The data in the second row and second column is stored in the first intermediate cache; and so on, to obtain the first intermediate matrix D. 1 The second row of data;

[0063] By analogy, the intermediate matrix is ​​obtained. in

[0064] (B-2) The matrix transpose multiplication processing unit reads the data from the second row of submatrix B1′ and the second row of submatrix C1′ from the external storage unit via the bus; it then multiplies the data in the first column of the second row of submatrix B1′ by... 2,1The data c in the second row and first column of submatrix C1′ 2,1 Multiply and add the first intermediate matrix D. 1 Data in the first row and first column As the second intermediate matrix D 2 Store the data in the first row and first column of submatrix B1′ into the first intermediate buffer; store the data in the second row and first column of submatrix B1′ into the first intermediate buffer. 2,1 The data c in the second row and second column of submatrix C1′ 2,2 Multiply and add the first intermediate matrix D. 1 Data in the first row and second column As the second intermediate matrix D 2 The data in the first row and second column is stored in the first intermediate cache; and so on, to obtain the second intermediate matrix D. 2 The first row of data;

[0065] The data b in the second row and second column of submatrix B1' 2,2 The data c in the second row and first column of submatrix C1′ 2,1 Multiply and add the first intermediate matrix D. 1 Data in the second row and first column As the second intermediate matrix D 2 The data in the second row and first column of submatrix B1' is stored in the first intermediate cache; the data in the second row and second column of submatrix B1' is... The data c in the second row and second column of submatrix C1′ 2,2 Multiply and add the first intermediate matrix D. 1 Data in the second row and second column As the second intermediate matrix D 2 The data in the second row and second column is stored in the first intermediate cache; and so on, to obtain the second intermediate matrix D. 2 The second row of data;

[0066] By analogy, the second intermediate matrix is ​​obtained.

[0067] (B-3) The matrix transpose multiplication processing unit reads the data from the third row of submatrix B1′ and the third row of submatrix C′1 from the external storage unit via the bus; it then multiplies the data in the first column of the third row of submatrix B′1 by... 3,1 The data c in the third row and first column of submatrix C′1 3,1 Multiply and add the second intermediate matrix D. 2 Data in the first row and first column As the third intermediate matrix D 3 The data in the first row and first column of submatrix B′1 is stored in the first intermediate buffer; the data in the third row and first column of submatrix B′1 is stored in the first intermediate buffer. 3,1 The data c in the third row and second column of submatrix C′13,2 Multiply and add the second intermediate matrix D. 2 Data in the first row and second column As the third intermediate matrix D 3 The data in the first row and second column is stored in the first intermediate cache; and so on, to obtain the second intermediate matrix D. 3 The first row of data;

[0068] Take the data b from the third row and second column of submatrix B′1 3,2 The data c in the third row and first column of submatrix C′1 3,1 Multiply and add the second intermediate matrix D. 2 Data in the second row and first column As the third intermediate matrix D 3 The data in the second row and first column of submatrix B′1 is stored in the first intermediate buffer; the data in the third row and second column of submatrix B′1 is stored in the first intermediate buffer. 3,2 The data c in the third row and second column of submatrix C′1 3,2 Multiply and add the second intermediate matrix D. 2 Data in the second row and second column As the third intermediate matrix D 3 The data in the second row and second column is stored in the first intermediate cache; and so on, to obtain the third intermediate matrix D. 3 The second row of data;

[0069] By analogy, the third intermediate matrix is ​​obtained.

[0070] (B-4) and so on, to obtain the Nth intermediate matrix. D is a submatrix of the transpose multiplication result matrix H. 1,1 Store it in the first intermediate buffer; the output unit will store the submatrix D. 1,1 Write to external storage units via bus.

[0071] Step (C) performs the same processing on submatrix B′1 and submatrix C′2 to obtain submatrix D of the transpose multiplication result matrix H. 1,2 Store it in the second intermediate buffer; the output unit will store the submatrix D. 1,2 Write to external memory via the bus; and so on, link submatrix B′1 and submatrix C′1. G The same process is performed to obtain submatrix D. 1,G The data is stored sequentially in the first or second intermediate buffer; the output unit will store the submatrix D. 1,G Write to external storage units via bus.

[0072] Step (D) replaces submatrix B′1 with submatrix B′2, and repeats steps (B) and (C) to obtain submatrix D of the transpose multiplication result matrix H. 2,1 D2,2 ,…,D 2,G ; and so on, to obtain the submatrix D of the transpose multiplication result matrix H. K,1 D K,2 ,…,D K,G Thus, the external storage unit obtains the transpose multiplication result matrix.

[0073] The matrix multiplication method is S = E × F, where the number of columns in matrix E is equal to the number of rows in matrix F. First, using the matrix transpose method, we obtain the transpose matrix E of matrix E. T Then, the matrix transpose multiplication processing unit reads the transpose matrix E from the external storage unit via the bus. T Given matrix F, multiply by matrix transpose to obtain matrix S = (E T ) T ×F=E×F.

[0074] The following is a specific example, and the execution steps are as follows:

[0075] The method for matrix transpose consists of the following steps:

[0076] S100. Transpose the large block of data in the matrix with column numbers 1 to L and row numbers 1 to Ha. L is the maximum length of data to be processed at one time, and Ha is the number of rows in the matrix. If L is greater than the number of columns Wa of the matrix, then the column number range for this step is 1 to Wa, and the matrix transposition ends after the operation is completed.

[0077] S200. Add L to the column index from the previous step to obtain the transpose of the next large block of data. If the rightmost column index of the large block is greater than or equal to Wa, take Wa, and end the matrix transpose operation after completion.

[0078] S300. Repeat step S200.

[0079] The transposition of large blocks of data consists of the following steps:

[0080] S010. Transpose the data in the large block with row numbers from 1 to L. If L is greater than or equal to the number of rows Ha in the large block, then the column number range for this step is 1 to Ha, and the transposition of the large block ends after the operation is completed.

[0081] S020. Add L to the row number from the previous step to obtain the transpose of the next block of data. If the bottom row number of the block is greater than or equal to Ha, take Ha, and end the transpose of the large block after the operation is complete.

[0082] S030. Repeat step S020.

[0083] The transposition of block data consists of the following steps:

[0084] S001. Read data with row number 1 and column number 1 to L from the external memory unit via the bus and store it in the intermediate cache at the address with column number 1 and row number 1 to L. If L is greater than or equal to the number of rows in the block, the block transpose is terminated after the operation.

[0085] S002. Increment the row number from the previous step by 1 to obtain the transpose of the data in the next row. If the row number equals the number of rows in the block, the transpose of the block ends after the operation is complete.

[0086] S003. Repeat step S002.

[0087] In one feasible embodiment, the matrix transpose operation is performed on a block-by-block basis. The matrix transpose processing unit reads each row of data in the block sequentially from top to bottom from the external storage unit via the bus. Then, each row of data is written into a column of the intermediate cache, with the columns ordered from left to right.

[0088] After the matrix transpose processing unit processes the entire block of data, the output unit reads the data from the intermediate cache row by row from top to bottom and writes it to the external storage unit.

[0089] The method of matrix transpose multiplication consists of the following steps:

[0090] T100. Perform calculations on the large blocks of data in matrix A (column numbers 1 to L, row numbers 1 to H) and matrix B. H is the number of rows in matrix A. Due to the constraint of matrix outer product, the number of rows in matrix B is equal to the number of rows in matrix A. If L is greater than the number of columns in matrix A, the column number range for this step is 1 to Wa, and the calculation ends after the operation is completed.

[0091] T200. Add L to the column index of the large block of data in matrix A from the previous step to obtain the next large block of data and perform calculations with matrix B. If the rightmost column index of the large block is greater than or equal to Wa, take Wa, and end the matrix transpose multiplication calculation after the operation is completed.

[0092] T300. Repeat step T200.

[0093] The calculation of large blocks of data and matrices to be transposed consists of the following steps:

[0094] T010. Perform calculations on the large block of data A to be transposed and the large block of data in matrix B with column numbers 1 to L and row numbers 1 to H. If L is greater than or equal to the number of columns in matrix B, then the column number for this step is 1 to Wb, and the calculation ends after the operation is completed.

[0095] T020. Calculate the data of the large block A to be transposed and the data of the next large block obtained by adding L to the column index of the large block in matrix B from the previous step. If the rightmost column index of the large block in matrix B is greater than or equal to Wb, take Wb, and end the calculation after the operation.

[0096] T030. Repeat step T020.

[0097] The large chunks of data to be transposed and the calculation of the large chunks of data consist of the following steps:

[0098] T001. Multiply the data with row number 1 in the large block A to be transposed by the data with row number 1 in the large block B to obtain a block of data. The number of rows in the block is equal to the number of columns in the large block A, and the number of columns in the block is equal to the number of columns in the large block B. The data in the x-th row and y-th column of the block is equal to the x-th data in the large block A multiplied by the y-th data in the large block B. The number of rows in the two large blocks is equal. If the number of rows is 1, the calculation ends, and the block of data is the result.

[0099] T002. Increment the row numbers of both large blocks from the previous step by 1, then add the data in the block obtained by multiplying them to the data in the corresponding position of the block from the previous step. If the current row number equals the row number, end the calculation, and the block data in this step is the result.

[0100] T003. Repeat step T020.

[0101] In one feasible embodiment, the matrix transpose multiplication operation is performed in large blocks. The matrix transpose multiplication processing unit reads one row of data from the large block to be transposed and one row of data from another large block sequentially from top to bottom in the external storage unit via the bus. Then, following the order of the output block data from left to right and top to bottom, the result of multiplying the two rows of data is written into the intermediate storage unit. For subsequent processing, the result of the previous multiplication is read from the intermediate buffer and added to the result of the current multiplication, which is then written into the intermediate buffer.

[0102] After the matrix transpose and multiplication processing unit processes the complete large block of data, the output unit reads the data from the intermediate cache row by row from top to bottom and writes it to the external storage unit.

Claims

1. A method for transpose, transpose multiplication, and multiplication in matrix operations, characterized in that: This is implemented through a matrix transpose processing unit, a matrix transpose multiplication processing unit, an output unit, and two intermediate buffers; where: The matrix transpose processing unit is used to obtain the input data to be transposed from the external storage unit via the bus and perform transpose processing. The matrix transpose multiplication processing unit is used to obtain data of two input matrices from an external storage unit via a bus and perform the transpose multiplication of one matrix by the other. The output unit is used to retrieve data from the intermediate buffer and write it to the external storage unit via the bus; the matrix transpose processing unit and the matrix transpose multiplication processing unit share one output unit. Intermediate buffers are used to store data during processing; two intermediate buffers are used, and when the output unit uses one intermediate buffer for output, the processing unit uses the other intermediate buffer for data caching. The matrix transpose method is as follows: Step (1) Transpose the data that needs to be transposed. OK column matrix Divided into columns Submatrices, , ... , , , Indicates rounding up. L To divide the length; Step (2) divides each submatrix into rows. A matrix of grandchildren, For submatrix Its grandchild matrix , ... , ; thus ; Step (3) The matrix transpose processing unit first reads the first row of the matrix from the external storage unit via the bus and writes it to the first column of the first intermediate cache. Then, it writes the second row to the second column of the first intermediate cache, and so on, until the matrix is ​​transposed. The first line written to the first intermediate cache Column, complete the Sun matrix The input processing unit will output the processed grandchild matrix. Write to external storage unit via bus; Step (4): The matrix transpose processing unit reads the grandson matrix from the external storage unit via the bus. The first row is written to the first column of the second intermediate cache, then the second row is written to the second column of the second intermediate cache, and so on, until the first row is written to the second column of the second intermediate cache. The line written to the second intermediate cache Column, complete the Sun matrix The input processing unit will output the processed grandchild matrix. Write to external storage unit via bus; Step (5) continues in this manner to complete the submatrix. After processing all the grandchild matrices, continue processing the grandchild matrices of the submatrices to finally obtain the transpose matrix; The matrix transpose multiplication method is, i.e., matrix... number of rows Equal to the number of rows in the matrix. The specific method is as follows: Step (A) will transform the matrix Divide into according to step (1) Submatrices, , …… , ; matrix Divide into according to step (1) Submatrices, , …… , ; Step (B) will submatrix AND submatrix Perform the following processing: (B-1) The matrix transpose multiplication processing unit first reads the submatrix from the external storage unit via the bus. The first row and submatrix The first row of data; submatrix The data in the first row and first column AND submatrix The data in the first row and first column Multiplication, as the first intermediate matrix The data in the first row and first column is stored in the first intermediate cache; the submatrix is... The data in the first row and first column AND submatrix Data in the first row and second column Multiplication, as the first intermediate matrix The data in the first row and second column is stored in the first intermediate cache; and so on, to obtain the first intermediate matrix. The first row of data; Submatrix Data in the first row and second column AND submatrix The data in the first row and first column Multiplication, as the first intermediate matrix The data in the second row and first column is stored in the first intermediate cache; the submatrix is... Data in the first row and second column AND submatrix Data in the first row and second column Multiplication, as the first intermediate matrix The data in the second row and second column is stored in the first intermediate cache; and so on, to obtain the first intermediate matrix. The second row of data; By analogy, the intermediate matrix is ​​obtained. ,in ; (B-2) The matrix transpose multiplication processing unit reads the submatrix from the external storage unit via the bus. The second row and submatrix The data in the second row; submatrix Data in the second row and first column AND submatrix Data in the second row and first column Multiply and add the first intermediate matrix. Data in the first row and first column As the second intermediate matrix The data in the first row and first column is stored in the first intermediate cache; the submatrix is... Data in the second row and first column AND submatrix Data in the second row and second column Multiply and add the first intermediate matrix. Data in the first row and second column As the second intermediate matrix The data in the first row and second column is stored in the first intermediate cache; and so on, to obtain the second intermediate matrix. The first row of data; Submatrix Data in the second row and second column AND submatrix Data in the second row and first column Multiply and add the first intermediate matrix. Data in the second row and first column As the second intermediate matrix The data in the second row and first column is stored in the first intermediate cache; the submatrix is... Data in the second row and second column AND submatrix Data in the second row and second column Multiply and add the first intermediate matrix. Data in the second row and second column As the second intermediate matrix The data in the second row and second column is stored in the first intermediate cache; and so on, to obtain the second intermediate matrix. The second row of data; By analogy, the second intermediate matrix is ​​obtained. , ; (B-3) The matrix transpose multiplication processing unit reads the submatrix from the external storage unit via the bus. The third row and submatrix The data in the third row; submatrix The data in the third row and first column AND submatrix The data in the third row and first column Multiply, and add the second intermediate matrix. Data in the first row and first column As the third intermediate matrix The data in the first row and first column is stored in the first intermediate cache; the submatrix is... The data in the third row and first column AND submatrix The data in the third row and second column Multiply, and add the second intermediate matrix. Data in the first row and second column As the third intermediate matrix The data in the first row and second column is stored in the first intermediate cache; and so on, to obtain the second intermediate matrix. The first row of data; Submatrix The data in the third row and second column AND submatrix The data in the third row and first column Multiply, and add the second intermediate matrix. Data in the second row and first column As the third intermediate matrix The data in the second row and first column is stored in the first intermediate cache; the submatrix is... The data in the third row and second column AND submatrix The data in the third row and second column Multiply, and add the second intermediate matrix. Data in the second row and second column As the third intermediate matrix The data in the second row and second column is stored in the first intermediate cache; and so on, to obtain the third intermediate matrix. The second row of data; By analogy, the third intermediate matrix is ​​obtained. , ; (B-4) and so on, to obtain the Nth intermediate matrix. As the matrix resulting from the transpose multiplication submatrix Store the submatrix in the first intermediate buffer; the output unit will then store the submatrix. Write to external storage unit via bus; Step (C) will submatrix AND submatrix Perform the same processing to obtain the transpose multiplication result matrix. submatrix Store the submatrix in the second intermediate buffer; the output unit will then store the submatrix. Write to external storage units via the bus; and so on, write submatrices. AND submatrix The same process is performed to obtain the submatrix. The submatrix is ​​stored sequentially in the first or second intermediate buffer; the output unit will then store the submatrix. Write to external storage unit via bus; Step (D) will submatrix Replace with submatrix Repeat steps (B) and (C) to obtain the transpose multiplication result matrix. submatrix ; and so on, to obtain the transpose multiplication result matrix. submatrix Thus, the external storage unit obtains the transpose multiplication result matrix. ; Matrix multiplication method ,matrix Column number and matrix The number of rows is equal; first, according to the matrix transpose method, obtain the matrix. transpose matrix Then, the matrix transpose multiplication processing unit reads the transpose matrix from the external storage unit via the bus. sum matrix The result matrix is ​​obtained by multiplying the matrix by its transpose. .