Matrix operation method, processor and computing device

By using a combination of matrix registers and vector registers, the efficiency of matrix transposition operations is achieved, and the problem of low matrix transposition efficiency in the prior art is solved, reducing the number of instructions and hardware costs.

WO2024244837A1PCT designated stage expired Publication Date: 2024-12-05HUAWEI TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/089650
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-08-16
Filing Date
2024-04-24
Publication Date
2024-12-05

AI Technical Summary

Technical Problem

In the field of high-performance computing, matrix transposition operation efficiency is low. The existing technology relies on scalar registers or vector registers, and the number of instructions is large, resulting in inefficiency.

Method used

Matrix registers are used to perform matrix transposition operations, by storing matrix data and changing the reading method, reducing the number of instructions and improving transposition efficiency.

Benefits of technology

Reduces the number of instructions required for matrix transposition, improves the efficiency of matrix transposition, and reduces the data channel between memory and matrix registers through vector registers, reducing processor hardware costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024089650_05122024_PF_FP_ABST
    Figure CN2024089650_05122024_PF_FP_ABST
Patent Text Reader

Abstract

A matrix operation method, a processor and a computing device. The matrix operation method is executed by a processor, the processor comprises a matrix register, and the matrix operation method comprises: storing first matrix data into the matrix register, wherein the first matrix comprises N rows and M columns, and the matrix register stores the first matrix data in a two-dimensional form of N rows and M columns; and reading the first matrix data from the matrix register in a row-by-row or column-by-column manner to obtain second matrix data after the first matrix data is transposed, wherein the second matrix comprises M rows and N columns.
Need to check novelty before this filing date? Find Prior Art

Description

Matrix operation method, processor and computing device

[0001] This application claims priority to Chinese patent application No. 202310644474.9 filed on May 31, 2023, with invention name “A computing device”, and priority to Chinese patent application No. 202311036871.4 filed on August 16, 2023, with invention name “Matrix operation method, processor and computing device”, all contents of which are incorporated by reference into this application. Technical Field

[0002] The present application relates to the field of computing technology, and in particular to a matrix operation method, a processor, and a computing device. Background Art

[0003] Matrix operations are frequently used in high-performance computing (HPC) applications, including matrix transposition, addition, subtraction, and multiplication.

[0004] Currently, when matrices in HPC applications need to be transposed, the processor can use scalar registers or vector registers to complete the matrix transposition, which is inefficient.

[0005] Summary of the Invention

[0006] The embodiments of the present application provide a matrix operation method, a processor, and a computing device, which can perform matrix transposition using a matrix register, thereby improving the efficiency of matrix transposition. The corresponding technical solutions are as follows:

[0007] In a first aspect, a matrix operation method is provided, which is executed by a processor including a matrix register. The matrix operation method includes:

[0008] The processor stores first matrix data in a matrix register. The first matrix includes N rows and M columns, and the matrix register stores the first matrix data in a two-dimensional format with N rows and M columns. The processor then reads the first matrix data from the matrix register row by row or column by column to obtain second matrix data including M rows and N columns, which is a transposition of the first matrix data. M and N are positive integers, and the values ​​of M and N may be equal or different.

[0009] A matrix register is a register that can store matrix data in a two-dimensional form. The processor can provide read instructions for reading the matrix data stored in the matrix register by column or row. The processor can also provide store instructions for storing vector data (such as a column in the matrix data) in the matrix register in the form of rows or columns. When the processor reads and stores data in the matrix register in the form of rows or columns, the corresponding differences in read performance and store performance are negligible.

[0010] In the solution shown in the present application, for the first matrix data corresponding to the first matrix to be transposed, the processor may store the first matrix data in a matrix register. When each row of data stored in the matrix register is each row of data of the first matrix, the processor may read out the first matrix data stored in the matrix register in a column-by-column manner, and thus obtain the second matrix data of the second matrix after the first matrix is ​​transposed. When each row of data stored in the matrix register is each column of data of the first matrix, the processor may read out the first matrix data stored in the matrix register in a row-by-row manner, and thus obtain the second matrix data of the second matrix after the first matrix is ​​transposed.

[0011] It can be seen that the solution shown in this application only needs to store the matrix data to be transposed into the matrix register, and then change the reading method and read the matrix data stored in the matrix register to achieve the transposition of the matrix. In this way, for a matrix with N rows and M columns, only N store instructions plus M read instructions (or M store instructions plus N read instructions) are needed to achieve the matrix transposition operation, which can reduce the number of instructions required to transpose the matrix and improve the efficiency of matrix transposition.

[0012] In one achievable manner, storing the first matrix data into the matrix register includes: storing the first matrix data stored in the memory into the matrix register row by row or column by column.

[0013] In the solution shown in the present application, the first matrix data can be stored in the memory in the form of an array. Depending on the storage method, the processor can read a row of data or a column of data of the first matrix from the memory each time. For each row of data that can be read from the memory, the processor can store it in the matrix register in a row or column manner. That is, each row of data of the first matrix read by the processor can be stored in the matrix register by row, or by column. For each column of data that can be read from the memory each time, the processor can store it in the matrix register in a row or column manner. That is, each column of data of the first matrix read out can be stored in the matrix register by row, or by column.

[0014] Among them, after storing a row of data or a column of data of the first matrix read out each time into the matrix register in a row-by-row manner, the processor can read out the first matrix data stored in the matrix register in a column-by-column manner to obtain the second matrix data after transposition. After storing a row of data or a column of data of the first matrix read out each time into the matrix register in a column-by-column manner, the processor can read out the first matrix data stored in the matrix register in a row-by-row manner to obtain the second matrix data after transposition. It can be seen that in the solution shown in the present application, the processor only needs to store the matrix data to be transposed into the matrix register, and then change the reading method and read out the matrix data stored in the matrix register, so as to realize the transposition of the matrix, thereby reducing the number of instructions required to transpose the matrix and improving the efficiency of the matrix transposition.

[0015] In one conceivable embodiment, the processor further includes a vector register. Accordingly, storing the first matrix data in the matrix register includes: storing the first matrix data in the vector register in the form of vector data; and storing the vector data corresponding to the first matrix data stored in the vector register in the matrix register in a row or column manner.

[0016] In the solution shown in this application, the processor also includes a vector register, and the processor can use the vector register to store matrix data in the matrix register. Among them, for each time a row of data or a column of data of the first matrix is ​​read from the memory, the processor can first store it in the vector register in the form of a vector, and then read the row of data or the column of data of the first matrix stored in the vector register into the matrix register, thereby realizing the storage of the first matrix data into the matrix register. In this way, the memory stores the matrix data in the matrix register through the vector register, which can reduce the number of data channels established between the memory and the matrix register, and can reduce the hardware cost of the processor.

[0017] In one achievable manner, reading first matrix data from a matrix register row by row or column by column to obtain second matrix data that is a transposition of the first matrix data includes: reading the first matrix data from the matrix register row by row or column by column, and storing vector data read each time into the vector register; and reading the vector data stored in the vector register into a memory to obtain second matrix data that is a transposition of the first matrix data.

[0018] In the solution shown in the present application, the processor can store matrix data in the matrix register with the help of a vector register, and can also read matrix data from the matrix register with the help of a vector register. Among them, for each row of data or column of data read from the matrix register, the processor can first store it in the vector register in the form of a vector, and then read the row of data or column of data stored in the vector register into the memory, thereby realizing the reading of the first matrix data from the matrix register in a row-by-row or column-by-column manner. In this way, the memory stores the matrix data in the matrix register through the vector register, and reads the matrix data from the matrix register through the vector register, which can avoid establishing a data channel between the memory and the matrix register, and can further reduce the hardware cost of the processor.

[0019] In one achievable embodiment, the processor further includes a vector register. Accordingly, reading the first matrix data from the matrix register row by row or column by column to obtain the second matrix data that is the result of transposing the first matrix data includes: reading the first matrix data from the matrix register row by row or column by column, and storing each read vector data into the vector register. Reading the vector data stored in the vector register into a memory to obtain the second matrix data that is the result of transposing the first matrix data.

[0020] In the solution shown in the present application, the processor also includes a vector register, and the processor can use the vector register to read the matrix data stored in the matrix register into the memory. Among them, for each row of data or column of data read from the matrix register, it can be first stored in the vector register in the form of a vector, and then the row of data or column of data stored in the vector register can be read into the memory, thereby realizing the first matrix data being read from the matrix register in a row-by-row or column-by-column manner. In this way, the memory reads the matrix data from the matrix register through the vector register, which can reduce the number of data channels established between the memory and the matrix register, thereby reducing the hardware cost of the processor.

[0021] In one achievable manner, the processor further includes a calculation unit. Accordingly, after obtaining the second matrix data obtained by transposing the first matrix data, the method further includes: inputting the second matrix data into the calculation unit, and the calculation unit performing a specified calculation on the second data matrix.

[0022] In the solution shown in the present application, the processor further includes a computing unit, such as a matrix computing unit, a vector computing unit, etc. After reading the matrix data stored in the matrix register to obtain the transposed second matrix data, the read second matrix data can be directly input into the computing unit for subsequent calculations, without having to store the read second matrix data in the memory, thereby improving the efficiency of matrix operations.

[0023] According to a second aspect, a processor is provided, the processor including a matrix register, the processor being configured to: store first matrix data in the matrix register, the first matrix including N rows and M columns, the matrix register storing the first matrix data in a two-dimensional format of N rows and M columns; and read the first matrix data from the matrix register row by row or column by column to obtain second matrix data that is a transposition of the first matrix data, the second matrix including M rows and N columns.

[0024] In one achievable manner, the processor is configured to store the first matrix data stored in the memory into the matrix register in a row-by-row or column-by-column manner.

[0025] In one achievable manner, the processor further includes a vector register, and the processor is configured to: store the first matrix data in the vector register in the form of vector data, and store the vector data corresponding to the first matrix data stored in the vector register in the matrix register in a row or column manner.

[0026] In one achievable embodiment, the processor is configured to: read first matrix data from a matrix register row by row or column by column, and store vector data read each time into the vector register, and read the vector data stored in the vector register into a memory to obtain second matrix data that is a transposition of the first matrix data.

[0027] In one possible implementation, the processor further includes a vector register, and the processor is configured to: read the first matrix data from the matrix register row by row or column by column, and store each vector data read into the vector register; and read the vector data stored in the vector register into a memory to obtain second matrix data that is a transposition of the first matrix data.

[0028] In one achievable manner, the processor further includes a calculation unit, and the processor is further configured to: input the second matrix data into the calculation unit, and the calculation unit performs a specified calculation on the second data matrix.

[0029] In a third aspect, a computing device is provided, which includes a memory and a processor, wherein the processor is used to execute instructions stored in the memory so that the processor performs the matrix operation method described in the first aspect above.

[0030] In a fourth aspect, a computer program product comprising instructions is provided. When the instructions are executed by the computing device described in the third aspect, the computing device executes the matrix operation method described in the first aspect.

[0031] In a fifth aspect, a computer-readable storage medium is provided, comprising computer program instructions. When the computer program instructions are executed by the computing device described in the third aspect, the computing device can perform the matrix operation method described in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] FIG1 is a schematic diagram of a method for implementing matrix transposition with the aid of a scalar register in the related art;

[0033] FIG2 is a schematic diagram of a method for implementing matrix transposition with the help of a vector register in the related art;

[0034] FIG3 is a schematic diagram of the structure of a computing device provided in an embodiment of the present application;

[0035] FIG4 is a flow chart of a matrix operation method provided in an embodiment of the present application;

[0036] FIG5 is a schematic diagram of a matrix transposition provided in an embodiment of the present application;

[0037] FIG6 is a schematic diagram of the structure of a computing device provided in an embodiment of the present application;

[0038] FIG7 is a schematic diagram of a matrix transposition provided in an embodiment of the present application;

[0039] FIG8 is a schematic diagram of the structure of a computing device provided in an embodiment of the present application;

[0040] FIG9 is a schematic diagram of a matrix transposition provided in an embodiment of the present application;

[0041] FIG10 is a schematic diagram of the structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0042] In order to make the objectives, technical solutions and advantages of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.

[0043] Matrix operations are commonly used in computers, particularly in high-performance computing (HPC) and artificial intelligence (AI). These operations include transposition, addition, subtraction, and multiplication. In related technologies, matrix operations are typically implemented using scalar processors or vector memories.

[0044] Figure 1 is a schematic diagram of a method for implementing matrix transposition with the help of a scalar register in the related art. In internal memory such as memory and cache, matrices can be stored in the form of arrays. For example, the matrix If matrix A is stored in memory by row, the actual matrix stored in memory is [1, 2, 3, 4, 5, 6, 7, 8, 9]. If matrix A is stored in memory by column, the actual matrix stored in memory is [1, 4, 7, 2, 5, 8, 3, 6, 9]. As shown in Figure 1, in one example, if matrix A is transposed using a scalar register and the matrix is ​​stored in memory by row, that is, matrix A stored in memory is [1, 2, 3, 4, 5, 6, 7, 8, 9], then each element "1", "4", "7", "2", "5", "8", "3", "6", and "9" of matrix A stored in memory can be read sequentially. After each element is read, the read element can be stored in the scalar register, and then the element stored in the scalar register can be stored back in memory. In this way, the elements "1", "4", "7", "2", "5", "8", "3", "6", and "9" can be stored in memory in sequence, obtaining matrix B after the transposition of matrix A. The matrix B is stored in memory by row, that is, the matrix B[1,4,7,2,5,8,3,6,9], that is, the matrix To transpose the matrix A in this way, 9 scalar Load instructions are required to store the elements of the matrix A in the memory into the scalar registers one by one, and 9 scalar Store instructions are required to store the elements in the scalar registers back to the memory one by one. Similarly, if an n×n matrix is ​​transposed with the help of a scalar register, n 2 scalar Load instruction and n 2 Subscalar Store instruction.

[0045] Figure 2 is a schematic diagram of a method for implementing matrix transposition with the help of a vector register in the related art. As shown in Figure 2, in an example, if the matrix A is transposed with the help of a vector register, and the matrix is ​​stored in memory by rows, that is, the matrix A stored in the memory is [1,2,3,4,5,6,7,8,9], then each column element "1,4,7", "2,5,8", "3,6,9" of the matrix A stored in the memory can be read in sequence. Each time a column of elements is read, it can be stored in the vector register, and then the elements stored in the vector register are stored back to the memory, so that the elements "1,4,7", "2,5,8", "3,6,9" can be stored in the memory in sequence to obtain the matrix B after the matrix A is transposed. The matrix B is stored in memory by rows, that is, the matrix B[1,4,7,2,5,8,3,6,9], that is, the matrix To transpose matrix A in this way, three Gather Load instructions are required to store each column element of matrix A in memory into the vector register in turn, and three vector Store instructions are required to store the elements in the vector register back to the memory in turn. However, since matrix A is stored in memory by rows, that is, each column element of matrix A is not stored continuously in memory, Gather Load is actually split into three scalar Load instructions to obtain a column of elements in matrix A. Therefore, with the help of vector registers, 9 scalar Load instructions and 3 vector Store instructions are required. Similarly, if an n×n matrix is ​​transposed with the help of vector registers, n scalar Load instructions and 3 vector Store instructions are required. 2 times scalar Load instructions and n times vector Store instructions.

[0046] An embodiment of the present application provides a method for matrix operation, which can complete the matrix transposition with the help of a matrix register in a processor, can reduce the number of instructions required to transpose the matrix, and improve the efficiency of transposing the matrix. Among them, the matrix register is a register that can store matrix data in a two-dimensional form that distinguishes rows and columns. The processor can provide corresponding read instructions, which can read the matrix data stored in the matrix register by column. The processor also provides corresponding storage instructions, which can store each column of matrix data in the form of rows or columns to the matrix register, or store each row of matrix data in the form of rows or columns to the matrix register. When the processor reads or stores the matrix data in the matrix register in the form of rows or columns, the difference in corresponding reading performance and storage performance can be ignored. In one example, the matrix register can be a matrix register corresponding to a scalable matrix unit (SME).

[0047] Figure 3 is a schematic diagram of the structure of a computing device provided by an embodiment of the present application, in which the computing device includes at least a memory and a processor. The memory may be an external memory (such as a hard disk) or a memory memory (such as a memory, a cache). The processor includes at least a matrix register, and the processor may also include vector registers and scalar registers (not shown in Figure 3). If the processor only includes a matrix register, the matrix register and the memory can access each other, such as data stored in the memory or cache can be directly written to the matrix register, and data stored in the matrix register can be directly written to the memory or cache. The processor may be any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP) or a digital signal processor (DSP).

[0048] FIG4 is a flow chart of a matrix operation method provided by an embodiment of the present application. The method can be executed by the processor of the computing device in FIG3 to implement matrix transposition using matrix registers, reduce the number of instructions required for matrix transposition, and improve the efficiency of matrix transposition. Referring to FIG4, the method includes:

[0049] Step 401: The processor stores first matrix data into the matrix register, wherein the first matrix includes N rows and M columns, and the matrix register stores the first matrix data in a two-dimensional form of N rows and M columns.

[0050] In implementation, applications involving matrix operations, such as HPC applications, applications involving artificial intelligence, etc., may be run in the computing device. During the operation of the computer device, when a matrix needs to be transposed, a matrix transposition request may be sent to the processor so that the processor can transpose the corresponding matrix. The matrix operation method provided in the embodiment of the present application can form a function for implementing matrix transposition through assembly / intrinsic / high-level language, as a dynamic / static / high-level language acceleration library for matrix operations. When the processor needs to perform matrix transposition, the function for implementing matrix transposition can be called and executed in the function library to implement the matrix operation method provided in the embodiment of the present application, such as implementing the processing of steps 401-402.

[0051] In an embodiment of the present application, the matrix to be transposed may be referred to as a first matrix, and the matrix data corresponding to the first matrix may be referred to as first matrix data. Before the first matrix data is transposed, it may be stored in an external memory or an internal memory. The first matrix may include N rows and M columns, where M and N are both positive integers, and the values ​​of M and N may be equal or unequal. In this application, the method of matrix operation is described in detail by taking the first matrix data stored in the memory and the first matrix data being a two-dimensional matrix as an example. Other cases are similar and will not be described in detail.

[0052] The first matrix data can be stored in memory by row or by column. When the first matrix data is stored in memory by row, the processor can read the target matrix from the memory by row and store each row of elements read into the matrix register by row or column. When the target matrix is ​​stored in memory by column, the processor can read the target matrix from the memory by column and store each column of elements read into the matrix register by row or column.

[0053] As shown in Figure 5, the first matrix is ​​a matrix including 8 rows and 8 columns. Accordingly, the first matrix data can be stored in the memory as [00, 01, 02, 03, 04, 05, 06, 07, 10, 11, 12, ..., 75, 76, 77] by row. The processor can read a row of data of the first matrix data from the memory each time, such as [00, 01, 02, 03, 04, 05, 06, 07], [10, 11, 12, 13, 14, 15, 16, 17], etc., and can store a row of data of the first matrix data read each time in the matrix register in the form of rows.

[0054] In one example, the first matrix may also be matrices obtained by dividing a large matrix to be transposed. When reading data from any of the first matrices, the data may be read from the stored matrix data corresponding to the large matrix. The specific reading process is known from the prior art and will not be described in detail in this application. Accordingly, after transposing each first matrix, a matrix transposed from the large matrix can be formed based on the transposed second matrices.

[0055] Step 402: Read the first matrix data from the matrix register in a row-by-row or column-by-column manner to obtain second matrix data obtained by transposing the first matrix data, wherein the second matrix includes M rows and N columns.

[0056] After the first matrix data is stored in the matrix register, the first matrix data can be read from the matrix register row by row or column by column. If a row or column of the first matrix data is stored in the matrix register row by row, the first matrix data can be read out from the matrix register column by column, thereby completing the row-column conversion of the first matrix data. If a row or column of the first matrix data is stored in the matrix register column by column, the first matrix data can be read out from the matrix register row by row, thereby completing the row-column conversion of the first matrix data, and obtaining the second matrix data after the first matrix data is transposed.

[0057] As shown in Figure 5, for the first matrix data stored in the matrix register, the first matrix data can be read column by column, that is, [00, 10, 20, 30, 40, 50, 60, 70], [01, 11, 21, 31, 41, 51, 61, 71], ..., [07, 17, 27, 37, 47, 57, 67, 77] are read in sequence to obtain the second matrix data after the first matrix data is transposed.

[0058] Thus, for a first matrix with N rows and M columns, if the corresponding first matrix data is stored by row in the memory, N storage instructions are required to store the first matrix data in the matrix register, and then M read instructions are required to read the first matrix data from the matrix register to obtain the transposed second matrix data. If the corresponding first matrix data is stored by column in the memory, M storage instructions are required to store the first matrix data in the matrix register, and then N read instructions are required to read the first matrix data from the matrix register to obtain the transposed second matrix data. It can be seen that by using the matrix operation method provided by the present application, only M+N instructions are required to complete the matrix transposition, which can improve the efficiency of matrix transposition.

[0059] FIG5 is a schematic diagram of a matrix transposition provided by an embodiment of the present application. As shown in FIG5, the first matrix is ​​an 8×8 matrix, such as The first matrix data can be stored in memory by row, that is, the first matrix data is stored in memory as [00,01,02,03,04,05,06,07,10,11,12,…,75,76,77]. When the first matrix data is transposed, each row element of the first matrix data in the memory can be stored in the matrix register through 8 storage instructions. Then, each column element of the first matrix data stored in the matrix register is read out through 8 read instructions. For example, each column element read can be stored in the memory in the form of a matrix. In this way, the second matrix data after the first matrix data is transposed can be obtained in the memory, and the second matrix data is stored in the memory as [00,10,20,30,40,50,60,70,01,11,21,…,57,67,77]. That is, the

[0060] In one example, when reading the first matrix data from the matrix register row by row or column by column, the data read each time can be stored in a memory, and the second matrix data obtained in the memory is obtained by transposing the first matrix data. The transposed second matrix data in the memory is then input into a computing unit in the processor for further calculation. In another example, when reading the first matrix data from the matrix register row by row or column by column, the data read each time can be directly input into a corresponding computing unit in the processor for further calculation to improve computing efficiency.

[0061] FIG6 is a schematic diagram of the structure of a computing device provided by an embodiment of the present application. The processor of the computing device may also include a vector register. A bidirectional data path exists between the vector register and the memory, enabling mutual access to data. A bidirectional data path exists between the vector register and the matrix register, also enabling mutual access to data. A unidirectional data path exists between the matrix register and the memory, meaning that data in the matrix register can be stored in the memory, while data in the memory requires the help of a vector register to be stored in the matrix register.

[0062] For the computing device shown in Figure 6, the processing of the above step 401 can be replaced by: the processor stores the first matrix data in the form of vector data to the vector register, and then stores the vector data corresponding to the first matrix data stored in the vector register to the matrix register in rows or columns.

[0063] When the first matrix data is stored in memory by row, the processor can read the target matrix from the memory by row and store each row of data read as a row vector corresponding to the first matrix into the vector register. In this way, multiple vector memories can respectively store the row vectors corresponding to the first matrix. The row vectors stored in each vector register can then be stored in the matrix register by row or by column.

[0064] FIG7 is a schematic diagram of a matrix transposition provided by an embodiment of the present application. As shown in FIG7, the first matrix is ​​an 8×8 matrix, such as The first matrix data can be stored in memory by row, that is, the first matrix data is stored in memory as [00,01,02,03,04,05,06,07,10,11,12,…,75,76,77]. When transposing the first matrix data, 8 vector Load instructions can be used to store each row element of the target matrix in the memory into the vector register. Then, 8 storage instructions are used to store the vector stored in the vector register into the matrix register by row. Finally, 8 read instructions can be used to read out each column of the matrix stored in the matrix register. For example, each column of data read can be stored in the memory in the form of a matrix. In this way, the second matrix data after the first matrix data is transposed can be obtained in the memory. The second matrix data is stored in the memory as [00,10,20,30,40,50,60,70,01,11,21,…,57,67,77]. That is, the

[0065] In the embodiment of the present application, the memory can use vector memory to store data in the matrix register. This can reduce the number of data channels between the matrix register and the memory, reduce the hardware cost of the processor, and do not excessively increase the number of instructions required to transpose the matrix, thereby improving the efficiency of the matrix transposition.

[0066] FIG8 is a schematic diagram of the structure of a computing device provided by an embodiment of the present application. Similar to the computing device shown in FIG6 , the processor of this computing device also includes vector registers. A bidirectional data path exists between the vector registers and the memory, enabling mutual data access. The vector registers and the matrix registers also have a bidirectional data path, also enabling mutual data access. Unlike the computing device shown in FIG6 , a unidirectional data path exists between the matrix registers and the memory, meaning that data in the matrix registers can be stored in the memory, while data in the memory requires the help of vector registers to be stored in the matrix registers.

[0067] For the computing device shown in FIG8 , the process of step 402 can be replaced by: reading the first matrix data from the matrix register row by row or column by column, and storing the vector data read each time into the vector register. Then, the vector data stored in the vector register is read into the memory to obtain the second matrix data that is the transposed result of the first matrix data.

[0068] If each row of data or each column of data in the first matrix data read is stored in the matrix register unit by row, the first matrix data stored in the matrix register can be read column by column, and each column of data (column vector) read each time can be stored in the vector register. Then, the column vectors stored in each vector register can be stored in the memory in sequence. If each row of data or each column of data in the first matrix data read is stored in the matrix register unit by column, the first matrix data stored in the matrix register can be read row by row, and each row of data (row vector) read each time can be stored in the vector register. Then, the column vectors stored in each vector register can be stored in the memory in sequence.

[0069] FIG9 is a schematic diagram of a matrix transposition provided by an embodiment of the present application. As shown in FIG9 , the first matrix is ​​an 8×8 matrix, such as The first matrix data can be stored in memory by row, that is, the target matrix is ​​stored in memory as [00,01,02,03,04,05,06,07,10,11,12,…,75,76,77]. When transposing the target matrix, each row of the first matrix data in the memory can be stored in the matrix register through 8 storage instructions. Then, the first matrix data stored in the matrix register is read column by column into the vector register through 8 read instructions. Finally, the vector stored in the vector register is read into the memory through 8 vector Load instructions. In this way, the second matrix data after the first matrix data is transposed can be obtained in the memory. The second matrix data is stored in the memory as [00,10,20,30,40,50,60,70,01,11,21,…,57,67,77]. That is, the

[0070] In the embodiment of the present application, the matrix register can use vector memory to store data in the memory. This can reduce the number of data channels between the matrix register and the memory, reduce the hardware cost of the processor, and do not excessively increase the number of instructions required to transpose the matrix, thereby improving the efficiency of the matrix transposition.

[0071] Figure 10 is a schematic diagram of the structure of a computing device provided by an embodiment of the present application. The same as the computing devices shown in Figures 6 and 8 is that the processor of the computing device also includes a vector register, and the vector register and the memory can access each other, and the vector register and the matrix register can access each other. Unlike the computing device shown in Figure 6, the matrix register and the memory cannot access each other, that is, if it is necessary to store data stored in the memory into the matrix register, the data in the memory can be first stored into the vector register, and then the data stored in the vector register can be stored into the matrix register. Similarly, if it is necessary to store data stored in the memory into the matrix register, the data in the memory can be first stored into the vector register, and then the data stored in the vector register can be stored into the matrix register.

[0072] For the computing device shown in FIG10 , the processing of step 401 can be replaced by: the processor stores the first matrix data in the form of vector data into a vector register, and then stores the vector data corresponding to the first matrix data stored in the vector register into the matrix register in a row or column manner. Further processing is the same as that in the embodiment corresponding to FIG6 above and is not further described here.

[0073] The process of step 402 can be replaced by: reading the first matrix data from the matrix register row by row or column by column, and storing the vector data read each time into the vector register. Then, the vector data stored in the vector register is read into the memory to obtain the second matrix data obtained by transposing the first matrix data. The further processing can be the same as that of the embodiment corresponding to FIG. 6 above, and will not be repeated here.

[0074] In the embodiment of the present application, vector memory can be used to store data between the matrix register and the memory. This avoids establishing a data channel between the matrix register and the memory, reduces the hardware cost of the processor, and does not excessively increase the number of instructions required to transpose the matrix, thereby improving the efficiency of the matrix transposition.

[0075] The present application also provides a processor that includes a matrix register and a vector register. For example, the processor may be the processor shown in Figures 3, 6, 8, and 10 above. The processor may be used to:

[0076] First matrix data is stored in a matrix register, the first matrix including N rows and M columns. The matrix register stores the first matrix data in a two-dimensional format with N rows and M columns. The first matrix data is read from the matrix register row by row or column by column to obtain second matrix data that is a transposition of the first matrix data, the second matrix including M rows and N columns.

[0077] In one achievable manner, the processor is configured to store the first matrix data stored in the memory into the matrix register in a row-by-row or column-by-column manner.

[0078] In one achievable manner, the processor further includes a vector register, and the processor is configured to: store the first matrix data in the vector register in the form of vector data, and store the vector data corresponding to the first matrix data stored in the vector register in the matrix register in a row or column manner.

[0079] In one achievable embodiment, the processor is configured to: read first matrix data from a matrix register row by row or column by column, and store vector data read each time into the vector register, and read the vector data stored in the vector register into a memory to obtain second matrix data that is a transposition of the first matrix data.

[0080] In one possible implementation, the processor further includes a vector register, and the processor is configured to: read the first matrix data from the matrix register row by row or column by column, and store each vector data read into the vector register; and read the vector data stored in the vector register into a memory to obtain second matrix data that is a transposition of the first matrix data.

[0081] In one achievable manner, the processor further includes a calculation unit, and the processor is further configured to: input the second matrix data into the calculation unit, and the calculation unit performs a specified calculation on the second data matrix.

[0082] The processor provided in the embodiment of the present application can execute the matrix operation method described in the above embodiment to implement matrix transposition. The specific implementation method can be found in the content of the above embodiment and will not be described in detail here. The processor provided in the embodiment of the present application implements matrix transposition through matrix registers, which can reduce the number of instructions required to transpose the matrix and improve the efficiency of matrix transposition.

[0083] The present application also provides a computer program product including instructions. The computer program product may be software or a program product including instructions that can be run on a computing device or stored in any available medium. When the computer program product is run on the computing device provided in the above embodiment, the computing device executes the matrix operation method provided in the above embodiment.

[0084] The present application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that can be stored by a computing device or a data storage device such as a data center that contains one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to perform the matrix operation method provided in the above embodiment.

[0085] In this application, the terms "first", "second", etc. are used to distinguish between identical or similar items with substantially the same effects and functions. It should be understood that there is no logical or temporal dependency between "first" and "second", nor is there a limit on quantity and execution order. It should also be understood that although the following description uses the terms "first", "second", etc. to describe various elements, these elements should not be limited by the terms. These terms are only used to distinguish one element from another. In this application, the term "at least one" means one or more, and the term "plurality" means two or more.

[0086] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and such modifications or substitutions should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.

Claims

1. A matrix operation method, It is characterized in that Executed by a processor, the processor comprising a matrix register, the method comprising: Storing first matrix data in the matrix register, wherein the first matrix includes N rows and M columns, and the matrix register stores the first matrix data in a two-dimensional form of N rows and M columns; The first matrix data is read from the matrix register in a row-by-row or column-by-column manner to obtain second matrix data after transposing the first matrix data, wherein the second matrix includes M rows and N columns.

2. The method according to claim 1, It is characterized in that The storing the first matrix data into the matrix register comprises: The first matrix data stored in the memory is stored in the matrix register in a row-by-row or column-by-column manner.

3. The method according to claim 1, It is characterized in that The processor also includes a vector register; The storing the first matrix data into the matrix register comprises: Storing the first matrix data in the form of vector data into the vector register; The vector data corresponding to the first matrix data stored in the vector register is stored in the matrix register in a row or column manner.

4. The method according to claim 3, It is characterized in that The step of reading the first matrix data from the matrix register row by row or column by column to obtain second matrix data after transposing the first matrix data includes: Reading the first matrix data from the matrix register in a row-by-row or column-by-column manner, and storing the vector data read each time in the vector register; The vector data stored in the vector register is read into the memory to obtain the second matrix data obtained by transposing the first matrix data.

5. The method according to claim 1, It is characterized in that The processor also includes a vector register; The step of reading the first matrix data from the matrix register row by row or column by column to obtain second matrix data after transposing the first matrix data includes: Reading the first matrix data from the matrix register in a row-by-row or column-by-column manner, and storing the vector data read each time in the vector register; The vector data stored in the vector register is read into the memory to obtain the second matrix data obtained by transposing the first matrix data.

6. The method according to any one of claims 1 to 5, It is characterized in that The processor further includes a calculation unit, and after obtaining the second matrix data obtained by transposing the first matrix data, the method further includes: The second matrix data is input into the calculation unit, and the calculation unit performs a specified calculation on the second data matrix.

7. A processor, It is characterized in that The processor comprises a matrix register, and the processor is used for: Storing first matrix data in the matrix register, wherein the first matrix includes N rows and M columns, and the matrix register stores the first matrix data in a two-dimensional form of N rows and M columns; The first matrix data is read from the matrix register in a row-by-row or column-by-column manner to obtain second matrix data after transposing the first matrix data, wherein the second matrix includes M rows and N columns.

8. The processor according to claim 7, It is characterized in that The processor is used to: The first matrix data stored in the memory is stored in the matrix register in a row-by-row or column-by-column manner.

9. The processor according to claim 7, It is characterized in that The processor further comprises a vector register, and the processor is configured to: Storing the first matrix data in the form of vector data into the vector register; The vector data corresponding to the first matrix data stored in the vector register is stored in the matrix register in a row or column manner. device.

10. The processor according to claim 9, It is characterized in that The processor is used to: Reading the first matrix data from the matrix register in a row-by-row or column-by-column manner, and storing the vector data read each time in the vector register; The vector data stored in the vector register is read into the memory to obtain the second matrix data obtained by transposing the first matrix data.

11. The processor according to claim 7, It is characterized in that The processor further comprises a vector register, and the processor is configured to: Reading the first matrix data from the matrix register in a row-by-row or column-by-column manner, and storing the vector data read each time in the vector register; The vector data stored in the vector register is read into the memory to obtain the second matrix data obtained by transposing the first matrix data.

12. A processor according to any one of claims 7 to 11, It is characterized in that The processor further comprises a computing unit, and the processor is further configured to: The second matrix data is input into the calculation unit, and the calculation unit performs a specified calculation on the second data matrix.

13. A computing device, It is characterized in that The computing device comprises a memory and a processor, the processor comprises a matrix register, and the processor is configured to execute instructions stored in the memory, so that the processor executes the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Matrix operation method, processor and computing device

    CN119066317A

  • Method for implementing matrix transpose by using vector processor, and processing system

    CN101093474A

  • Matrix transposition method

    CN102253925A

  • DMA (direct memory access) matrix transposition transmission method based on ping-pong mechanism supporting data out-of-order feedback for GPDSP (general purpose digital signal processor)

    CN104679690A

  • Acceleration method and device for matrix product transposition and processor

    CN109522125A