Data processing method, matrix transposition system and chip
By setting up a matrix transposition system in the AI processor and using cyclic right and left shift control units and dynamic cache areas to perform matrix transposition, the problem of matrix transposition operations occupying cache space and computing power is solved, and efficiency and caching are improved. Utilization.
Patent Information
- Application Number
- CN202310372542.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-30
- Publication Date
- 2024-10-01
AI Technical Summary
In the existing technology, the matrix transposition operation occupies a large cache space, wastes computing power, and takes a long time. It cannot match the computing performance of the AI processor and becomes a performance bottleneck.
By setting up a matrix transposition system in direct memory access, using circular right shift and circular left shift control units, the dynamic buffer area performs matrix transposition, reducing dependence on arithmetic logic units, dynamically allocating cache space, and improving cache utilization.
The online matrix transposition task is implemented, saving cache space and computing power, improving operating efficiency, improving cache space utilization, and reducing the time consumption of matrix transposition.
Smart Images

Figure CN118733501A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of data processing technology, and specifically relates to a data processing method, a matrix transposition system for executing the data processing method, and a chip including the matrix transposition system. Background Art
[0002] AI processors, also known as artificial intelligence units (AIU), require a large number of transposition operations during operation to achieve row-column transformation of input matrices. Since AI processing involves the operation of a large number of neural network layers, neural networks are matrix operations on input matrices, and transposition is the basic operation of matrix operations, if the performance of transposition cannot match the computing performance of the AI processor, transposition will become the performance bottleneck of the AI processor.
[0003] Currently, matrix transposition is usually performed by moving the matrix to the L1 memory cache of the AI processor through direct memory access (DMA), and then calling a large number of load / store instructions through the arithmetic and logic unit (ALU) to complete the transposition operation. This takes up a large amount of cache space, wastes computing power, and takes a long time. Summary of the invention
[0004] The purpose of the present application is to provide a data processing method, a data processing device, a computer-readable storage medium and an electronic device, which can overcome the problems existing in the related art of occupying a large cache space, wasting computing power and taking a long time when transposing a matrix.
[0005] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by the practice of the present application.
[0006] According to one aspect of an embodiment of the present application, a data processing method is provided, which is applied to a matrix transposition system set in direct memory access, the method comprising: obtaining configuration information corresponding to a target matrix, determining a right shift amount corresponding to a current input row vector according to the configuration information, and generating a right shift control instruction according to the right shift amount, wherein the current input row vector is a row vector in the target matrix; in response to the right shift control instruction, circularly right-shifting the current input row vector according to the right shift amount to obtain a right-shifted row vector corresponding to the current input row vector; determining a target cache area corresponding to the target matrix in a dynamic cache area according to the configuration information, and writing the right-shifted row vector into the target cache area; after completing the caching of the target matrix, step-reading the column vector in the target cache area, and circularly left-shifting the column vector read each time to form a left-shifted column vector, so as to determine a transposed matrix corresponding to the target matrix according to the left-shifted column vector.
[0007] According to one aspect of an embodiment of the present application, a matrix transposition system is provided, which is arranged in direct memory access, and the system includes: a circular right shift control unit, which is used to obtain configuration information of a target matrix, determine a right shift amount corresponding to a current input row vector according to the configuration information, and generate a right shift control instruction according to the right shift amount, wherein the current input row vector is a row vector in the target matrix; a circular right shift unit, which is connected to the second input port and the circular right shift control unit, and is used to respond to the right shift control instruction and circularly right shift the current input row vector according to the right shift amount in the right shift control instruction to generate a right shifted row vector; a cache control unit, which is connected to the circular right shift control unit, and is used to store the right shifted row vector in a dynamic cache area according to the configuration information. Determine a target cache area corresponding to the target matrix to write the right-shifted row vector into the target cache area, and after completing the caching of the target matrix, perform a step-by-step reading of the data in the target cache area to obtain a column vector; a circular left shift control unit, connected to the cache control unit, for determining a left shift amount corresponding to a currently read column vector according to configuration information of the target matrix and a current reading time, and generating a left shift control instruction according to the left shift amount; a circular left shift unit, connected to the dynamic cache area and the circular left shift control unit, for responding to the left shift control instruction, circularly shifting the currently read column vector according to the left shift amount to generate a left-shifted column vector for constructing a transposed matrix corresponding to the target matrix.
[0008] In one embodiment of the present application, based on the above scheme, the matrix transposition system also includes: a first input port, connected to the circular right shift control unit, for inputting a command to the circular right shift control unit, wherein the command is used to indicate configuration information corresponding to the target matrix; a second input port, connected to the circular right shift unit, for inputting a row vector in the target matrix to the circular right shift unit.
[0009] In one embodiment of the present application, based on the above scheme, the matrix transposition system also includes: an output network control unit, connected to the circular left shift control unit, for determining the number of output column vectors based on a preset output data amount and the amount of data contained in the left-shifted column vector, and generating an output control instruction based on the number of output column vectors; an output network unit, connected to the circular left shift unit and the output network control unit, for responding to the output control instruction, outputting and reorganizing the left-shifted column vector according to the number of output column vectors, so as to generate a transposed matrix corresponding to the target matrix.
[0010] In one embodiment of the present application, based on the above solution, the matrix transposition system further includes: a command queue cache unit, connected to the circular right shift control unit and the cache control unit, for caching command sequences corresponding to multiple transposition tasks.
[0011] In one embodiment of the present application, based on the above solution, the matrix transposition system further includes: a beater for performing beat processing to control the timing of commands and data in the matrix transposition system.
[0012] In one embodiment of the present application, based on the above scheme, the matrix transposition system includes: a first beater, a second beater, a third beater, a fourth beater, a fifth beater, a sixth beater and a seventh beater; wherein the first beater is located between the first input port and the circular right shift control unit, and is used to beat the command input by the first input port; the second beater is located between the circular right shift unit and the cache control unit, and is used to beat the command after being beat by the first beater; the third beater is located between the circular left shift control unit and the output network control unit, and is used to beat the command processed by the second beater; the fourth beater is located between the second input port and the circular right shift unit, and is used to beat the command after being beat by the first beater. The row vector input by the second input port is beat processed; the fifth beater is located between the circular right shift unit and the dynamic buffer area, and is used to beat the right-shifted row vector; the sixth beater is located between the circular left shift unit and the output network unit, and is used to beat the left-shifted column vector; the seventh beater is located after the output network unit, and is used to beat the left-shifted column vector output according to the output column vector number; and, the command after the first beater is beat and the row vector after the fourth beater is beat are output synchronously, the command after the second beater is beat and the right-shifted row vector after the fifth beater is output synchronously, and the command after the third beater is beat and the left-shifted column vector after the sixth beater is output synchronously.
[0013] In one embodiment of the present application, based on the above scheme, the first input port, the first beater, the circular right shift control unit, the second beater, the cache control unit, the command queue cache unit, the circular left shift control unit, the third beater and the output network control unit constitute a control instruction path in the matrix transposition system, and the second input port, the fourth beater, the circular right shift unit, the fifth beater, the dynamic cache area, the circular left shift unit, the sixth beater, the output network unit and the seventh beater constitute a data path in the matrix transposition system.
[0014] In one embodiment of the present application, based on the above scheme, the cache control unit includes a back pressure generating unit, a write address generating unit and a read address vector generating unit connected in sequence, wherein the back pressure generating unit is connected to the circular right shift control unit, and is used to determine whether to generate a back pressure signal or a write signal according to the occupancy of the dynamic cache area and the configuration information of the target matrix, the write address generating unit is used to receive the write signal sent by the back pressure generating unit, and allocate the target cache area to the target matrix according to the configuration information of the target matrix, and the read address vector generating unit is used to perform a step-by-step read of the data in the target cache area to obtain the column vector.
[0015] In one embodiment of the present application, based on the above scheme, the read address vector generation unit includes multiple address generation components, each of the address generation components is a saturated subtraction unit, and each of the address generation components corresponds one-to-one to each cache unit in the target cache area, and is used to determine the read address corresponding to each cache unit according to the serial number of each cache unit and the current read time, and generate a read signal according to the read address.
[0016] In one embodiment of the present application, the configuration information includes the matrix specification of the target matrix; based on the above scheme, the row vector sequence number corresponding to the current input row vector is determined by the circular right shift control unit according to the matrix specification of the target matrix, wherein the row vector sequence number is a sequence number that increases starting from 0; the row vector sequence number corresponding to the current input row vector is used as the right shift amount corresponding to the current input row vector.
[0017] In one embodiment of the present application, based on the above solution, the circular right shift unit responds to the right shift control instruction and circularly right shifts the current input row vector according to the right shift amount.
[0018] In one embodiment of the present application, the configuration information includes a matrix specification of the target matrix; the matrix transposition system includes a back pressure generating unit and a write address generating unit; the cache area includes a plurality of cache units, and each of the cache units includes a plurality of cache bits; based on the above scheme, the number of target cache units containing unwritten cache bits in the dynamic cache area and the number of unwritten cache bits in each of the target cache units are obtained through the back pressure generating unit; when the number of columns of the matrix specification is less than or equal to the number of target cache units, and the number of rows of the matrix specification is less than or equal to the number of unwritten cache bits, the target cache area is determined by the write address generating unit among the target cache units and the unwritten cache bits, so as to write each data in the right-shifted row vector into the unwritten cache bits of the target cache area in sequence.
[0019] In one embodiment of the present application, based on the above scheme, when the number of rows of the matrix specification is greater than the number of unwritten cache bits in each of the target cache units, or the number of columns of the matrix specification is greater than the number of the target cache units, the back pressure generating unit generates a back pressure signal to refuse to write the right-shifted row vector into the dynamic cache area.
[0020] In one embodiment of the present application, the matrix transposition system includes a read address vector generation unit, the read address vector generation unit includes multiple read address generation components, and each of the read address generation components corresponds one-to-one to each cache unit in the dynamic cache area; based on the above scheme, the difference between the serial number of the Nth cache unit in the target cache area and the current read time is obtained; when the difference exceeds the address representation range, the target cache bit address located in the Nth cache unit is determined based on saturated subtraction; the data in the target cache bit is read, and the column vector is constructed based on the data read from all cache units in the target cache area; wherein N and the current read time are both non-negative integers, and the address representation range is the range constructed by the first cache bit address and the last cache bit address in the cache unit.
[0021] In one embodiment of the present application, based on the above scheme, the circular left shift control unit determines the left shift amount corresponding to the current reading moment according to the matrix specification of the target matrix, and generates a left shift control instruction according to the left shift amount; the circular left shift unit responds to the left shift control instruction, and circularly shifts the column vector left according to the left shift amount to obtain the left-shifted column vector.
[0022] In one embodiment of the present application, based on the above scheme, after obtaining all the left-shifted column vectors corresponding to the target matrix, the output network control unit determines the number of output column vectors according to the preset output data amount and the amount of data contained in each of the left-shifted column vectors, and generates an output control instruction according to the number of output column vectors; the output network unit responds to the output control instruction and outputs the left-shifted column vector according to the number of output column vectors, so as to obtain the transposed matrix by reorganizing according to the left-shifted column vectors.
[0023] In one embodiment of the present application, based on the above solution, commands corresponding to different transposition tasks are cached in order in a command queue unit, so that corresponding tasks are executed according to the order in which the commands are stored in the command queue unit.
[0024] According to one aspect of an embodiment of the present application, a chip is provided, which includes the matrix transposition system described in the above embodiment.
[0025] The data processing method provided by the embodiment of the present application is applied to a matrix transposition system set in direct memory access. After obtaining the configuration information corresponding to the target matrix, the right shift corresponding to the current input row vector is determined according to the configuration information, and the current input row vector is a row vector in the target matrix; then the current input row vector is right-shifted according to the right shift to obtain the right-shifted row vector corresponding to the current input row vector; then the target cache area corresponding to the target matrix is determined in the dynamic cache area according to the configuration information, and the right-shifted row vector is written into the target cache area; after the cache of the target matrix is completed, the column vector in the target cache area is read in a step-by-step manner, and the column vector read each time is cyclically shifted to the left to form a left-shifted column vector, so as to determine the transposed matrix corresponding to the target matrix according to the left-shifted column vector. On the one hand, the present application can process the matrix transposition task online, without calling a large number of load / store instructions through the arithmetic logic unit to read the matrix data from the first-level cache for transposition, saving cache space and computing power, and improving the operation efficiency; on the other hand, the cache space can be dynamically allocated to different matrices through the dynamic cache area, further improving the utilization of the cache space.
[0026] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the specification are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0028] Figure 1 The flowchart of implementing matrix transposition in the related art is schematically shown.
[0029] Figure 2 The structural diagram of the system architecture of the matrix transposition system in the embodiment of the present application is schematically shown.
[0030] Figure 3 The following is a schematic diagram of the steps of the data processing method in the embodiment of the present application.
[0031] Figure 4 The interface diagram of parallel reading and writing of the dynamic cache area in the embodiment of the present application is schematically shown.
[0032] Figure 5 A schematic diagram of an interface for dynamically allocating cache space in an embodiment of the present application is schematically shown.
[0033] Figure 6 The interface diagram for writing row vectors of each row of the target matrix in an embodiment of the present application is schematically shown.
[0034] Figure 7 The interface diagram for filling a matrix and writing it into a target cache area in an embodiment of the present application is schematically shown.
[0035] Figure 8 The flowchart of the step-by-step reading of column vectors in an embodiment of the present application is schematically shown.
[0036] Fig. 9 The following is a schematic diagram of an interface for obtaining a left-shifted column vector corresponding to a target matrix in an embodiment of the present application.
[0037] Fig.10 A schematic diagram of an interface for outputting a left-shifted column vector in an embodiment of the present application is schematically shown.
[0038] Fig.11 A schematic diagram of an interface for outputting a left-shifted column vector in an embodiment of the present application is schematically shown.
[0039] Fig.12 The flowchart of transposing a 5×5 matrix in an embodiment of the present application is schematically shown. DETAILED DESCRIPTION
[0040] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this application will be more comprehensive and complete and fully convey the concept of the example embodiments to those skilled in the art.
[0041] In addition, described feature, structure or characteristic can be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present application. However, those skilled in the art will appreciate that the technical scheme of the present application can be put into practice without one or more of the specific details, or other methods, components, devices, steps, etc. can be adopted. In other cases, known methods, devices, realizations or operations are not shown or described in detail to avoid blurring the various aspects of the application.
[0042] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0043] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0044] In the related art of the present application, direct memory access DMA, a first-level cache L1 memory cache and an arithmetic logic unit ALU are usually used to implement the matrix transposition operation in the AI processor. Figure 1 The schematic diagram of the process of implementing matrix transposition in the related art is shown as follows: Figure 1 As shown, in step S101, the matrix is moved to the L1 memory cache inside the AI processor through DMA; in step S102, based on the complex addressing mode of the L1 memory cache, the matrix data is read out from the L1 memory cache through the ALU calling the load instruction; in step S103, through the row-column transformation addressing mode, the matrix data after the row-column transformation is written into the L1 memory cache through the ALU calling the store instruction, and finally the matrix in the L1 memory cache is the transposed matrix.
[0045] Although the related technology can realize the matrix transposition processing in the AI processor, it has corresponding defects: first, DMA needs to move the matrix to be transposed to the L1 memory cache, and then the ALU calls a large number of load / store instructions to complete the transposition operation, which occupies the precious L1 memory cache resources and the computing power of the ALU, and cannot process the transposition task online; secondly, calling the load / store instructions by software consumes a lot of running time and has low performance; finally, the L1 memory cache needs to have a row-column change addressing mode, which has high design requirements for the L1 memory cache; for AI processors that do not have a row-column change addressing mode, implementing the transposition operation will consume more running time.
[0046] In response to the problems existing in the related technologies in this field, an embodiment of the present application proposes a data processing method for transposing a matrix in an AI processor to perform matrix transposition tasks online, improve the utilization of cache space, and improve transposition efficiency.
[0047] Before describing the data processing method in the present application in detail, the technical terms that may be involved in the present application are first described.
[0048] 1. Matrix transpose: permute the row and column dimensions of the matrix, converting row vectors to column vectors and column vectors to row vectors.
[0049] 2.RAM: Random Access Memory, also called main memory, is the internal memory that directly exchanges data with the CPU.
[0050] 3.DMA: Direct Memory Access is a function provided by some computer bus architectures that enables data to be sent directly from an attached device (such as a disk drive) to the memory of the computer motherboard.
[0051] 4. Circular shift: put the low bit shifted out to the high bit of the number (circular right shift) or put the high bit shifted out to the low bit of the number (circular left shift).
[0052] Next, an exemplary system architecture applying the technical solution of the present application is described.
[0053] Figure 2 The following schematically shows an architecture block diagram of a matrix transposition system using the technical solution of the present application.
[0054] like Figure 2 As shown, the architecture of the matrix transposition system 200 may include a first input port 201, a second input port 202, a circular right shift control unit 203, a circular right shift unit 204, a cache control unit 205, a dynamic cache area 206 including multiple cache units, a command queue cache unit 207, a circular left shift control unit 208, a circular left shift unit 209, an output network control unit 210, an output network unit 211 and multiple beaters 212.
[0055] The matrix transposition system includes a control instruction path and a data path. Specifically, the first input port 201, the cyclic right shift control unit 203, the cache control unit 205, the command queue cache unit 207, the cyclic left shift control unit 208, the output network control unit 210 and the beater 212 constitute the control instruction path, and the second input port 202, the cyclic right shift unit 204, the dynamic cache area 206 including multiple cache units, the cyclic left shift unit 209, the output network unit 211 and the beater 212 constitute the data path. The control instruction path and the data path are beat synchronously, and the data path performs data processing in response to the control instruction issued by the control instruction path to realize the transposition of the target matrix.
[0056] Specifically, the first input port 201 is used to input a command, which is used to indicate configuration information corresponding to the target matrix, such as the data type, matrix specifications, etc. in the target matrix; the second input port 202 is used to input different row vectors that constitute the target matrix in different clock cycles; a circular right shift control unit 203 is connected to the first input port 201, and is used to determine the right shift amount corresponding to the current input row vector according to the specifications of the target matrix, and generate a right shift control instruction according to the right shift amount; a circular right shift unit 204 is connected to the second input port 202 and the circular right shift control unit 203, and is used to respond to the right shift control instruction and perform right shift processing on the current input row vector according to the right shift amount to obtain a right shifted row vector; a cache control unit 205 is connected to the circular right shift control unit 203, and is used to determine a target cache area in the dynamic cache area 206 according to the specifications of the target matrix, and write the right shifted row vector into the target cache area, and perform step-by-step reading of the data in the target cache area to obtain a column vector; a command queue cache unit 207 is connected to the circular right shift control unit 203 and the cache control unit 205, and is used to cache and multiple transposition tasks The corresponding command sequence is used to enable the data path to orderly transpose the corresponding matrix according to the command sequence; the circular left shift control unit 208 is connected to the command queue buffer unit, and is used to determine the left shift amount corresponding to the currently read column vector according to the specification of the target matrix and the current reading time, and generate a left shift control instruction according to the left shift amount; the circular left shift unit 209 is connected to the dynamic buffer area 206 and the circular left shift control unit 208, and is used to respond to the left shift control instruction, and circularly shift the currently read column vector according to the left shift amount to generate a left shift column vector; the output network control The control unit 210 is connected to the circular left shift control unit 208, and is used to determine the number of output column vectors according to the preset output data amount and the amount of data contained in the left-shifted column vector, and generate an output control instruction according to the number of output column vectors; the output network unit 211 is connected to the circular left shift unit 209 and the output network control unit 210, and is used to respond to the output control instruction and output the left-shifted column vector according to the number of output column vectors, so as to obtain the transposed matrix by reorganization according to the output left-shifted column vector; the beater 212 is used to perform beat processing to control the timing of commands and data in the entire matrix transposition system.
[0057] Among them, the dynamic cache area includes multiple cache units, and each cache unit contains multiple cache bits, that is, each cache unit has a certain depth. In the embodiment of the present application, the cache unit can be implemented by a read-and-write random access memory RAM. While reading the column vector of the previous transposition task, the vector of the next transposition task can be written to realize stream processing, which improves the efficiency of matrix transposition in the AI processor, and when the number of cache units remains unchanged, the depth of each cache unit can be increased to increase the cache space, improve the RAM surface efficiency, and reduce area consumption.
[0058] The cache control unit 205 includes a back pressure generating unit 205-1, a write address generating unit 205-2 and a read address vector generating unit 205-3 connected in sequence. After the input configuration information of the target matrix enters the cache control unit 205, it first enters the back pressure generating unit 205-1. The back pressure generating unit 205-1 determines whether there is enough cache space in the dynamic cache area to write the target matrix according to the occupancy status in the current dynamic cache area and the configuration information of the target matrix. If so, it accepts the task of writing the target matrix. If not, it generates a back pressure signal, stops receiving the task of writing the target matrix, and monitors the occupancy status of the dynamic cache space until there is enough cache space in the dynamic cache space to write the target matrix, and then releases the back pressure signal; then, the back pressure generating unit 205-1 sends the write signal to the write address generating unit 205-2, and the write address generating unit 205-2 allocates the corresponding target cache area for the target matrix in the available cache space in the dynamic cache space according to the specifications of the target matrix. , and determine a write address in the target cache area for each data in the received right-shifted row vector, that is, the address of the cache unit corresponding to each data and the cache bit in the cache unit, and send a control instruction containing the write address to the data path, so that the data path responds to the control instruction to write the relevant data into the corresponding cache unit and cache bit; after completing the data cache of the target matrix, the data in the target cache area can be read out by column through the read address vector generation unit 205-3, and the read address vector generation unit 205-3 includes multiple address generation components, which are saturated subtraction units. Saturated subtraction means that when the data exceeds the address representation range, the data is looped back to the boundary address. The boundary address varies according to the reading time. The address generation component corresponds to the cache unit one by one. Each address generation unit determines the read address according to the sequence number of the cache unit and the current reading time, and generates a read signal according to the read address. The data path responds to the read signal to read the corresponding data from each cache unit to form a column vector. It is worth noting that, since the write address of each cache unit is the same, the write address generation unit 205-2 only needs one address generation component. After determining the write address of the right-shifted row vector, the write address can be broadcast to each cache unit; when reading the column vector, the read address of each cache unit is different, and a vector needs to be generated, so an address generation component needs to be instantiated for each cache unit; after determining the target cache area, the cache units in the target cache area can be numbered in sequence according to the writing direction of the vector data, and the numbers increase in sequence from 0, corresponding to the reading time, so as to ensure the accuracy of the read address and the accuracy of the read column vector.
[0059] In one embodiment of the present application, the command queue cache unit 207 is used to sequentially store commands corresponding to different transposition tasks so that other units in the system execute commands according to the order of the commands in the command queue unit. In the embodiment of the present application, a first-in-first-out queue is used for caching. For example, if task0 enters the matrix transposition system before task1, task0 is executed first and the transposed matrix corresponding to task0 is output.
[0060] In one embodiment of the present application, the control instruction path and the data path respectively include a plurality of beaters, and the beaters are arranged correspondingly, so that the command input from the first input port can be synchronized with the input of the vector, and the command stream will be input into different control units along the path to generate control instructions for the data path. Figure 2 As shown in , three beaters are respectively arranged in the control instruction path and the data path. Specifically, a first beater R1 is arranged between the first input port 201 and the cyclic right shift control unit 203, and is used to beat the command input from the first input port. A second beater R2 is arranged between the cyclic right shift control unit 203 and the cache control unit 205, and is used to beat the command after being beaten by the first beater. A third beater R3 is arranged between the cyclic left shift control unit 208 and the output network control unit 210, and is used to beat the command processed by the second beater. Accordingly, a fourth beater R4 is provided between the second input port 202 and the circular right shift unit 204 for beating the row vector inputted from the second input port, a fifth beater R5 is provided between the circular right shift unit 204 and the dynamic buffer area 206 for beating the right-shifted row vector, a sixth beater R6 is provided between the circular left shift unit 209 and the output network unit 211 for beating the left-shifted column vector, and further, a seventh beater R7 is provided after the output network unit for beating the left-shifted column vector outputted according to the output column vector number.
[0061] The beater is also called a beat register (register). For the processing of asynchronous signals, the register beat is generally performed to prevent the generation of metastable states. Usually, one beat, two beats or three beats can be performed. One beat refers to delaying the signal by one clock cycle, and n beats means delaying n clock cycles. In the present application, the command after the first beater beats and the row vector after the fourth beater beats are synchronously output to ensure that the command and the row vector are synchronously input into the circular right shift control unit and the circular right shift unit, the command after the second beater beats and the right shift row vector after the fifth beater beats are synchronously output, and the command and the right shift row vector are synchronously input into the cache control unit and the dynamic buffer area, and the command after the third beater beats and the left shift column vector after the sixth beater beats are synchronously output, and the command and the left shift column vector can be synchronously input into the output network control unit and the output network unit, thereby ensuring that each control unit generates corresponding control instructions according to the command, and sends the control instructions to the corresponding data processing unit, and then the corresponding data is processed by the data processing unit, ensuring the timing of the entire matrix transposition system.
[0062] In one embodiment of the present application, DMA is an important technology for offloading CPU load. The introduction of DMA makes the original data exchange between device memory and system memory must be participated by CPU, and it is changed to DMA control for data transmission, which is a working mode in which I / O exchange is completely performed by hardware. In view of this, the matrix transposition system 200 can be integrated into DMA. After obtaining the matrix to be transposed through DMA, the matrix to be transposed can be directly transposed through the matrix transposition system set thereon to realize online processing of transposition tasks, thereby improving data processing efficiency, without the need to move the matrix data to be transposed to L1 memory cache through DMA, and realize the matrix transposition task by calling load / store instructions through ALU.
[0063] The following is a detailed description of the technical solutions such as the data processing method, data processing device, computer-readable medium, and electronic device provided by the present application in conjunction with specific implementation methods.
[0064] Figure 3 A schematic diagram of a data processing method in an embodiment of the present application is shown. The data processing method is executed by a matrix transposition system. The server may be specifically as follows: Figure 2 The matrix transposition system 200 shown in FIG. Figure 3 As shown, the data processing method in the embodiment of the present application may mainly include the following steps S310 to S340.
[0065] Step S310: acquiring configuration information corresponding to a target matrix, determining a right shift amount corresponding to a current input row vector according to the configuration information, and generating a right shift control instruction according to the right shift amount, wherein the current input row vector is a row vector in the target matrix;
[0066] Step S320: responding to the right-shift control instruction, performing right-shift processing on the current input row vector according to the right-shift amount to obtain a right-shifted row vector corresponding to the current input row vector;
[0067] Step S330: determining a target buffer area corresponding to the target matrix in the dynamic buffer area according to the configuration information, and writing the right-shifted row vector into the target buffer area;
[0068] Step S340: After the target matrix is cached, the column vectors in the target cache area are read in a stepwise manner, and the column vectors read each time are circularly left-shifted to form a left-shifted column vector, so as to determine a transposed matrix corresponding to the target matrix according to the left-shifted column vector.
[0069] The data processing method provided in the embodiment of the present application is applied to a matrix transposition system set in direct memory access. After obtaining the configuration information corresponding to the target matrix, the right shift amount corresponding to the current input row vector is determined according to the configuration information, and a right shift control instruction is generated according to the right shift amount, and the current input row vector is a row vector in the target matrix; then, in response to the right shift control instruction, the current input row vector is right-shifted according to the right shift amount to obtain a right-shifted row vector corresponding to the current input row vector; then, a target cache area corresponding to the target matrix is determined in the dynamic cache area according to the configuration information, and the right-shifted row vector is written into the target cache area; when the cache of the target matrix is completed, the column vector in the target cache area is step-read, and the column vector read each time is cyclically left-shifted to form a left-shifted column vector, so as to determine the transposed matrix corresponding to the target matrix according to the left-shifted column vector. On the one hand, the present application can process matrix transposition tasks online without calling a large number of load / store instructions through the arithmetic logic unit to read matrix data from the first-level cache for transposition, saving cache space and computing power and improving operating efficiency; on the other hand, it can dynamically allocate cache space for different matrices through the dynamic cache area, further improving the utilization of the cache space.
[0070] The following is based on Figure 2 The architecture of the matrix transposition system 200 is shown, and the specific implementation of each method step of the data processing method in the embodiment of the present application is described in detail.
[0071] In step S310, configuration information corresponding to the target matrix is obtained, a right shift amount corresponding to a current input row vector is determined according to the configuration information, and a right shift control instruction is generated according to the right shift amount, wherein the current input row vector is a row vector in the target matrix.
[0072] In one embodiment of the present application, in an AI processor, when a matrix is transposed, different matrices correspond to different transposition parameters, and the transposition parameters are determined by the configuration information of the matrix. Therefore, in order to transpose the matrix, it is necessary to synchronously obtain the configuration information of the matrix and generate corresponding control instructions according to the configuration information of the matrix. In an embodiment of the present application, the matrix to be transposed is defined as a target matrix, and the configuration information of the target matrix includes a data type, a matrix specification, etc. The data type can specifically be an integer type, a floating point type, a character type, etc. The matrix specification is the number of row vectors and the number of column vectors of the matrix. For example, the specification of a 4×2 matrix is 4 row vectors and 2 column vectors.
[0073] In one embodiment of the present application, the configuration information of the target matrix can be input through the first input port of the matrix transposition system. After being beat by the first beater, the configuration information enters the circular right shift control unit. The circular right shift control unit can determine the right shift amount that the vector input at the current moment needs to be circularly shifted according to the matrix specifications in the configuration information, and generate a right shift control instruction corresponding to the current input row vector according to the right shift amount.
[0074] When inputting the target matrix, the amount of data that can be input by the matrix transposition system in one clock cycle can be set, and then according to the specifications of the target matrix and the preset amount of input data, the number of clock cycles required to complete the input of the target matrix can be determined. For example, four sets of data can be input in one clock cycle, so for a 4×4 matrix, one row vector can be input in one clock cycle, and the input of the matrix can be completed in four clock cycles. For a 4×2 matrix, two row vectors can be input in one clock cycle, and the input of the matrix can be completed in two clock cycles. In other words, the input vector of the matrix transposition system is one or more rows of data in the input target matrix.
[0075] In one embodiment of the present application, for different row vectors in the target matrix, the corresponding right shifts are different. In an embodiment of the present application, the different row vectors of the target matrix are marked in sequence starting from 0, that is, the target matrix is composed of row vectors of the 0th, 1st, ..., Nth rows, and the right shifts of different row vectors are the same as the row vector sequence numbers of the row vectors, that is, the right shift of the row vector of the 0th row is 0, the right shift of the row vector of the 1st row is 1, and so on. When the number of row vectors input in one clock cycle is one, the circular right shift control unit can determine a right shift, and when the number of row vectors input in one clock cycle is multiple, the circular right shift control unit can determine multiple right shifts corresponding to different row vectors. Further, the circular right shift control unit can generate a right shift control instruction according to one right shift or multiple right shifts, and send it to the circular right shift control instruction.
[0076] In step S320, in response to the right shift control instruction, the current input row vector is circularly right shifted according to the right shift amount to obtain a right shifted row vector corresponding to the current input row vector.
[0077] In one embodiment of the present application, the circular right shift control unit sends a right shift control instruction to the circular right shift unit, and the circular right shift unit can respond to the right shift control instruction and perform right shift processing on the current input row vector according to the right shift amount therein to obtain a right shifted row vector corresponding to the current input row vector. If the current input row vector is a row vector, the row vector is circularly right shifted according to the right shift amount in the right shift control instruction; if the current input row vector is a plurality of row vectors, different row vectors are circularly right shifted according to the right shift amounts corresponding to different row vectors in the right shift control instruction.
[0078] Take a 4×4 matrix A as an example. When the input vector at time T1 is the row vector [1,0][1,1][1,2][1,3] of the first row, the corresponding right shift is 1. By cyclically right shifting the row vector by 1 bit, we can obtain the right-shifted row vector [1,3][1,0][1,1][1,2]; when the input vector at time T1 is the row vector [1,0][1,1][1,2][1,3] of the first row and the row vector [2,0][2,1][2,2][2,3] of the second row, the right shift corresponding to the row vector of the first row is 1, and the right shift corresponding to the row vector of the second row is 2. Then, by cyclically right shifting the row vector of the first row by 1 bit, we can obtain the right-shifted row vector [1,3][1,0][1,1][1,2], and by cyclically right shifting the row vector of the second row by 2 bits, we can obtain the right-shifted row vector [2,2][2,3][2,0][2,1].
[0079] Further, after all row vectors in matrix A are circularly shifted to the right, the matrix after the right shift can be obtained as follows:
[0080] The above embodiments only illustrate the right shift operation of the N×N matrix. Next, the right shift operation of the N×M matrix will be described.
[0081] When N>M, it is necessary to convert the N×M matrix into an N×N matrix, that is, fill the (M + 1)-th column to the N-th column, and then circularly shift each row vector to ensure the correctness of the transposed result. Any symbol can be used for filling, and the embodiments of the present application do not make specific limitations on this.
[0082] For example, for a 4×2 matrix Before performing the right shift, it is first converted into a 4×4 matrix according to the matrix specification. For example, it is converted into Then, the right shift operation is performed based on the row vectors of the converted matrix. Specifically, the row vector of the 0-th row does not need to be right shifted and remains {[0,0][0,1][*][*]}, the row vector of the 1-st row needs to be right shifted by 1 bit, and the corresponding right-shifted row vector is {[*][1,0][1,1][*]}, the row vector of the 2-nd row needs to be right shifted by 2 bits, and the corresponding right-shifted row vector is {[*][*][2,0][2,1]}, the row vector of the 3-rd row needs to be right shifted by 3 bits, and the corresponding right-shifted row vector is {[3,1][*][*][3,0]}.
[0083] When N<M, there is no need to fill, and the rows can be directly read by row and the row vectors can be circularly shifted for processing.
[0084] In step S330, a target buffer area corresponding to the target matrix is determined in the dynamic buffer area according to the configuration information, and the right-shifted row vector is written into the target buffer area.
[0085] In one embodiment of the present application, after the target matrix is circularly right-shifted, it can be written into a cache area so that other processing units can process the target matrix after the circular right-shift process and obtain a transposed matrix corresponding to the target matrix. In an embodiment of the present application, the cache area is a dynamic cache area, in which different matrices can be dynamically and cyclically stored. The dynamic cache area includes multiple cache unit banks, and each cache unit has a different depth, that is, it contains multiple cache bits, each cache bit can write a data in the matrix, and further, the depth of the cache unit can be a multiple of the number of row vectors in the maximum specification matrix, for example, it can be twice, three times, etc., but in order to avoid wasting cache space resources, the depth of the cache unit will not be set too large in the embodiment of the present application. Since the depth of the cache unit is greater than the number of row vectors of the maximum specification matrix, multiple matrices can be cached in the dynamic cache area, and while the matrix of the previous task is being output, the matrix of the next task can be input, thereby realizing the pipeline of the matrix transposition system and improving the transposition efficiency. Accordingly, in order to ensure that the dynamic cache area can input a new matrix while outputting a matrix, the cache unit bank in the embodiment of the present application is implemented using a read-one-write RAM. By increasing the depth of the RAM, the area efficiency of the RAM can be improved, which can reduce the consumed area while improving the efficiency of data processing.
[0086] Figure 4 The following schematic diagram shows the interface diagram of the dynamic cache area reading and writing in parallel. Figure 4 As shown, the dynamic cache area includes 4 cache units: bank0, bank1, bank2 and bank3. The depth of each cache unit is 8, which is twice the number of row vectors of the maximum specification matrix 4×4. The dynamic cache area is reading the matrix corresponding to task0 and writing the matrix corresponding to task1. As shown in the figure, the vector being read is the 0th column vector in the matrix, and the vector being written is the 1st row vector in the matrix.
[0087] In one embodiment of the present application, since the cache area is a dynamic cache area, rather than multiple cache areas instantiated for a matrix, before writing the row vector after the circular right shift into the dynamic cache area, it is necessary to determine whether there is enough cache space in the dynamic cache area to write the target matrix. In an embodiment of the present application, the size of the available cache space can be determined by the back pressure generation unit in the matrix transposition system. When there are target cache units with unwritten cache bits in the dynamic cache area, the number of target cache units and the number of unwritten cache bits in each target cache unit are obtained. If the number of columns in the matrix specification of the target matrix is less than or equal to the number of target cache units, and the number of rows of the target matrix is less than or equal to the minimum number of unwritten cache units in the target cache unit, then the unwritten cache bits in the target cache unit can be used as the target cache area, and the data in the right-shifted row vector is sequentially written into the unwritten cache bits of the target cache area through the write address generation unit in the matrix transposition system.
[0088] In one embodiment of the present application, the back pressure generation module may also generate a back pressure signal when it is determined that the number of columns in the matrix specification of the target matrix is greater than the number of target cache units, or the number of rows of the target matrix is greater than the maximum number of unwritten cache units in the target cache unit. In response to the back pressure signal, the data path may stop writing the target matrix into the dynamic cache area until sufficient cache space is released in the dynamic cache area, and then release the back pressure on the target matrix write task.
[0089] Figure 5 The following schematic diagram shows the interface diagram of dynamically allocating cache space. Figure 5 As shown, the dynamic cache space includes a bank, which contains 16 rows of cache bits. When task0 needs to occupy 4 rows of cache bits, task1 and task2 need to occupy 2 rows of cache bits respectively, and task3 needs to occupy 8 rows of cache bits.
[0090] When a new task task4 is received that requires 2 rows of cache bits, the back pressure generation module detects that there are no unwritten cache bits in the bank, and then forms a back pressure signal and suspends receiving task4 until task0 releases the corresponding cache space, and then releases the back pressure on task4.
[0091] In one embodiment of the present application, since the row vector input to the matrix transposition system within one clock cycle may be one or more of the target matrix, after completing the circular right shift of the current input row vector, the right-shifted row vector can be written into the dynamic cache area by row. That is to say, even if there are multiple row vectors input within one clock cycle, when writing to the dynamic cache area, the unwritten cache bits of different rows are written.
[0092] Figure 6 The following schematic diagram shows the interface for writing row vectors of the target matrix row by row. Figure 6 As shown, the target matrix is A, and one row vector is input in one clock cycle. The row vector input in the first clock cycle is {[0,0][0,1][0,2][0,3]}, and its corresponding row number is 0. There is no need to perform a circular right shift. Just write each group of data directly into the unwritten cache bit of row 0 of the target cache unit bank1, bank2, bank3, and bank4. The row vector input in the second clock cycle is {[1,0][1,1][1,2][1,3]}, and its corresponding row number is 1. It needs to be circularly shifted right by 1 bit to form a right-shifted row vector {[1,3][1,0][1,1][1,2]}
[0093] After that, each group of data in the right-shifted row vector is written into the first row of unwritten cache bits of the target cache units bank1, bank2, bank3 and bank4 in turn. The row vector input in the third clock cycle is {[2,0][2,1][2,2][2,3]}, and its corresponding row number is 2. It needs to be cyclically shifted right by 2 bits to form the right-shifted row vector {[2,2][2,3][2,0][2,1]}, and then each group of data in the right-shifted row vector is written into the target cache units bank1, bank2, bank3 and bank4 in turn. In the unwritten cache bits of the second row of ank3 and bank4, the row vector input in the fourth clock cycle is {[3,0][3,1][3,2][3,3]}, and its corresponding row number is 3. It needs to be cyclically right-shifted by 3 bits to form the right-shifted row vector {[3,1][3,2][3,3][3,0]}, and then each group of data in the right-shifted row vector is written into the unwritten cache bits of the third row of the target cache units bank1, bank2, bank3 and bank4 in turn, thus completing the caching of the right-shifted target matrix.
[0094] It is worth noting that when the row vector is circularly shifted right, if the number of row vectors is greater than the number of column vectors, the matrix needs to be filled. Therefore, when the right-shifted row vector is written to the target buffer, the data is written according to the right-shifted row vector obtained by right shifting after filling, but only the data is written at the corresponding address without writing the mark symbol used for filling. For example, the matrix obtained after filling and circular right shift is When writing the matrix A' into the target buffer, only the specific value is written into the buffer bit of the corresponding address without writing *, but the corresponding position is left blank, such as Figure 7 When the number of row vectors is less than the number of column vectors, there is no need to fill the matrix when the row vectors are circularly shifted right.
[0095] Of course, when writing the matrix A' into the target cache area, the * in the matrix can also be written into the corresponding cache bit to indicate that there is no data at that position. This identifier is involved in the subsequent reading of the column vector and circular left shift, but when the column vector is finally output, there is no need to output the identifier and the corresponding cache bit.
[0096] In step S340, after the target matrix is cached, the vectors in the target cache area are read in a stepwise manner, and each read vector is left-shifted to form a column vector, so as to determine a transposed matrix corresponding to the target matrix according to the column vector.
[0097] In one embodiment of the present application, after each row vector of the target matrix is right-shifted and written into the dynamic cache area, the data of the target matrix cached in the dynamic cache area can be read out column by column, and the column vectors read out column by column can be left-shifted to form column vectors for constructing a transposed matrix. Finally, all the left-shifted column vectors can be reorganized to obtain the transposed matrix of the target matrix.
[0098] Among them, the data of the target matrix can be read out by column by column using a step-by-step reading method. Figure 8 The schematic diagram of the process of step-by-step reading of column vectors is shown as follows: Figure 8 As shown, in step S801, the difference between the serial number of the Nth cache unit in the target cache area and the current read time is obtained; in step S802, when the difference exceeds the address representation range, the target cache bit address located in the Nth cache unit is determined based on saturated subtraction; in step S803, the data in the target cache bit is read, and the column vector is constructed according to the data read from all cache units in the target cache area; wherein N and the current read time are both non-negative integers, and the address representation range is the range constructed by the first cache bit address and the last cache bit address in the cache unit.
[0099] In one embodiment of the present application, the data of the target matrix can be read out by columns through a read address vector generation unit in the matrix transposition system. Since the read address of each cache unit bank is different, it is necessary to instantiate an address generation component for each cache unit, such as Figure 2 The sat_sub module shown in the figure is a saturated subtraction unit. Each address generation component can determine the target cache bit address in the corresponding cache unit through saturated subtraction, so as to read the corresponding data from the target cache bit address. Saturated subtraction means that when the data exceeds the address representation range, the data is looped back to the boundary address. The boundary address varies according to the reading time. Specifically, the boundary address can be calculated based on the number of row vectors of the target matrix and the difference between the current reading time and the sequence number of each cache unit. Figure 6Taking the matrix of write target cache area shown as an example, the address corresponding to each bank represents the range of 0 to 3. For the data in bank0, at time T0, the target cache bit address is 0, and the data of bit 0 in bank0 needs to be read [0,0]. At time T1, 0-1=-1, which exceeds the range of 0 to 3. At this time, according to the row vector number 4 and -1, the boundary address can be determined to be 3, that is, the target cache bit address loops back to 3, and the data of bit 3 in bank0 needs to be read [3,1]. At time T2, 0-2=-2, which exceeds the range of 0 to 3. At this time, according to the row vector number 4 and -2, the boundary address can be determined to be 2, that is, the target cache bit address loops back to 2, and the data of bit 2 in bank0 needs to be read [2,2]. At time T3, 0-3=-3, which exceeds the range of 0 to 3. At this time, according to the row vector number 4 and -3, the boundary address can be determined to be 1, that is, the target cache bit address loops back to 1, and the data of bit 1 in bank0 needs to be read [1,3].
[0100] Furthermore, after step-wise reading to obtain column vectors at different reading times, the read column vectors need to be circularly shifted left. Specifically, the circular left shift control unit can determine the left shift amount corresponding to the current reading time according to the matrix specification of the target matrix, and generate left shift control information according to the left shift amount, so that the circular left shift unit can respond to the left shift control instruction and circularly shift the read column vectors left according to the left shift amount to form a left-shifted column vector. The left-shifted column vector can be used to construct a transposed matrix.
[0101] In order to make the technical solution of this application clearer, Figure 6 Taking the matrix in the dynamic buffer area shown as an example, the method of reading column vectors by column and circularly shifting left in the present application is explained.
[0102] Fig. 9 The following schematic diagram shows an interface diagram for obtaining the left-shifted column vector corresponding to the target matrix. Fig. 9As shown, the data to be read are stored in bank0, bank1, bank2 and bank3 respectively. According to the matrix specification of 4×4, it is known that four readings are required to complete the reading of the column vector. According to the saturated subtraction, at time T0, the 0th bit in bank0, the 1st bit in bank1, the 2nd bit in bank2 and the 3rd bit in bank3 are read to obtain the first column vector {[0,0][1,0][2,0][3,0]}. At time T1, the 3rd bit in bank0, the 0th bit in bank1, the 1st bit in bank2 and the 2nd bit in bank3 are read to obtain the second column vector {[3,1][0,1][1,1][2,1]}. At time T2, the 2nd bit in bank0, the 3rd bit in bank1, the 2nd bit in bank2 At time T3, the 1st bit in bank0, the 2nd bit in bank1, the 3rd bit in bank2 and the 0th bit in bank3 are read to obtain the third column vector {[2,2][3,2][0,2][1,2]}. At time T3, the 1st bit in bank0, the 2nd bit in bank1, the 3rd bit in bank2 and the 0th bit in bank3 are read to obtain the fourth column vector {[1,3][2,3][3,3][0,3]}. Furthermore, the first column vector does not need to be shifted left, the second column vector needs to be shifted left by 1 bit, the third column vector needs to be shifted left by 2 bits, and the fourth column vector needs to be shifted left by 3 bits. By cyclically shifting left according to the left shift amount, four left-shifted column vectors can be obtained: {[0,0][1,0][2,0][3,0]}, {[0,1][1,1][2,1][3,1]}, {[0,2][1,2][2,2]}
[0103] [3,2]}, {[0,3][1,3][2,3][3,3]}, the transposed matrix of the target matrix can be obtained based on these four left-shifted column vectors.
[0104] If the target buffer is not fully written and there are empty spaces, when reading by column, the position where there is no data is still read, occupying the space and performing a circular left shift. In other words, there may be empty spaces in the column vector obtained by reading by column. For the convenience of explanation, the empty spaces are still represented by *. Figure 7 Taking the cache matrix shown in the figure as an example, when reading by column, the column vector read at time T0 is {[0,0][1,0][2,0][3,0]}, and the column vector read at time T1 is {[3,1][0,1][1,1]}
[0105] [2,1]}, the column vector read at time T2 is {[*][*][*][*]}, and the column vector read at time T3 is {[*][*][*][*]}. Correspondingly, after circularly shifting left according to the current reading time corresponding to each column vector, the obtained left-shifted column vectors are {[0,0][1,0][2,0][3,0]}, {[0,1][1,1][2,1][3,1]}, {[*][*][*][*]}, and {[*][*][*][*]}. It can be seen from this that a 4×2 matrix forms a 2×4 matrix after transposition.
[0106] In an embodiment of the present application, when the target matrix is an N×M matrix (N<M), although no padding is required during right shifting and caching, when reading column vectors by column, it is necessary to pad the matrix cached in the dynamic buffer to generate an M×M matrix, and perform column-by-column reading and circular left shifting based on the padded matrix. However, when outputting, there is no need to consider the padded part, and only the matrix part with specific data needs to be output. For example, the target matrix The matrix after circular right shifting When reading the data written into the dynamic buffer, it is necessary to pad A' to generate a 4×4 matrix containing padding identifiers, that is, Then, column-by-column reading is performed based on the padded matrix, and the read column vectors are {1, 5, *, *}, {*, 2, 6, *}, {*, *, 3, 7}, and {8, *, *, 4} respectively. Circular left shifting is performed on each column vector to obtain left-shifted column vectors {1, 5, *, *}, {2, 6, *, *}, {3, 7, *, *}, and {4, 8, *, *}. Output can be performed based on these left-shifted column vectors, and the finally obtained transposed matrix is
[0107] In an embodiment of the present application, after obtaining the left-shifted column vectors, it is necessary to output according to the specified output form. For matrices of different specifications, the output form may be different. For example, 4 data can be output per clock cycle. If the specification of the target matrix is 4×4, then one column of data in the target matrix can be output per clock cycle. If the specification of the target matrix is 2×4, then two columns of data in the target matrix can be output per clock cycle, and these two columns of data are located in the same row vector. Taking the above embodiment as an example, since two column vectors are read in one clock cycle, the finally output transposed matrix is
[0108] In the present application, the output network control unit in the matrix transposition system can determine the number of output column vectors based on the preset output data volume and the amount of data contained in each column vector, and generate an output control instruction based on the number of output column vectors. Then, the output network unit responds to the output control instruction and outputs the left-shifted column vectors in sequence according to the number of output column vectors, so as to obtain the transposed matrix by reorganizing the left-shifted column vectors.
[0109] Fig.10 A schematic diagram of an interface for outputting a left-shifted column vector is shown schematically, such as Fig.10 As shown, the target matrix is a 4×4 matrix A. When 4 data are output in one clock cycle, the first clock cycle outputs the first column vector of the target matrix A as the first row vector of the transposed matrix, and the second clock cycle outputs the second column vector of the target matrix A as the second row vector of the transposed matrix, and so on, until the fourth clock cycle outputs the fourth column vector of the target matrix A as the fourth row vector of the transposed matrix, thereby obtaining the transposed matrix A of the matrix A. T .
[0110] Fig.11 A schematic diagram of an interface for outputting a left-shifted column vector is shown schematically, such as Fig.11 As shown, the target matrix is a 2×4 matrix B. When 4 data are output in one clock cycle, the first clock cycle outputs the first column vector and the second column vector of the target matrix B as the first row vector of the transposed matrix, and the second clock cycle outputs the third column vector and the fourth column vector of the target matrix B as the second row vector of the transposed matrix, thereby obtaining the transposed matrix B of the matrix B. T .
[0111] The data processing method in the embodiment of the present application can be applied to an AI processor for online matrix transposition. Of course, the data processing method in the embodiment of the present application can also be installed as a plug-in in other storage media for transposing the matrix to be transposed. In order to make the technical solution of the present application clearer, next, it is assumed that there is sufficient cache space in the dynamic cache area, and a row / column vector is input / output for each clock cycle to illustrate the technical solution of the present application by transposing a specific matrix.
[0112] Fig.12 The schematic diagram of the process of transposing a 5×5 matrix is shown schematically, as shown in FIG. Fig.12As shown, in step S1201, a command containing matrix configuration information is input through the first input port, and each row vector in the matrix is input through the second input port in different clock cycles. In five time cycles, the 0th to 4th row vectors are input in sequence; in step S1202, each time a row vector is input, the circular right shift control unit sends a right shift control instruction to the circular right shift unit, and the circular right shift unit responds to the right shift control instruction to circularly right shift the current input row vector to generate a right shift row vector, and writes the right shift row vector into the dynamic buffer area in sequence. Specifically, the data written in bank0 is written from the 0th bit to the 4th bit in sequence. The data written in bank1 are 2, 6, 15, 19, 23 from bit 0 to bit 4, the data written in bank2 are 3, 7, 11, 20, 24 from bit 0 to bit 4, the data written in bank3 are 4, 8, 12, 16, 25 from bit 0 to bit 4, the data written in bank4 are 5, 9, 13, 17, 21 from bit 0 to bit 4; in step S1203, the data in the dynamic cache are read in steps, one column vector is read in each clock cycle, and different time cycles are The column vectors read in the period are: {1, 6, 11, 16, 21}, {22, 2, 7, 12, 17}, {18, 23, 3, 8, 13}, {14, 19, 24, 4, 9}, {10, 15, 20, 25, 5}; in step S1204, the read column vectors are respectively input to the circular left shift unit, and the circular left shift control unit generates a left shift control instruction according to the left shift amount corresponding to the current reading time, and sends it to the circular left shift unit, so that the circular left shift unit shifts the current read column vector left according to the left shift amount to generate a left shift column vector; each column vector is input to the circular left shift unit according to the left shift amount. The left-shifted column vectors generated after the corresponding left-shift amount is circularly shifted left are: {1, 6, 11, 16, 21}, {2, 7, 12, 17, 22}, {3, 8, 13, 18, 23}, {4, 9, 14, 19, 24}, {5, 10, 15, 20, 25}; in step S1205, the output network control unit generates an output control instruction according to the preset output data amount corresponding to one clock cycle and the data amount contained in a column vector, and sends the control instruction to the output network unit, so that the output network unit outputs the left-shifted column vector within five clock cycles and reorganizes to generate a transposed matrix.
[0113] It is worth noting that for a row vector input within a clock cycle, vector input-right shift-write can be executed continuously or discontinuously. For example, the input row vector can be directly written to the target cache after the circular right shift, or it can be written to the target cache in sequence after all row vectors have completed the circular right shift. Similarly, the data in the target cache is read to generate a column vector, and the left shift and output of the column vector can also be executed continuously or discontinuously with the reading of the column vector. That is, after reading a column vector, the column vector is immediately input into the circular left shift unit for circular left shift, and then the left-shifted column vector is input into the output network unit for output. It can also be that after completing the reading of the entire matrix, the column vectors are sequentially input into the circular left shift unit for circular left shift, and after completing the circular left shift of all column vectors, the left-shifted column vectors are sequentially input into the output network unit for output. It can also be that after reading a column vector, the column vector is immediately input into the circular left shift unit for circular left shift, and after completing the reading and left shift of all column vectors, the left-shifted column vectors are sequentially input into the output network unit for output.
[0114] The procedure for transposing a matrix with different numbers of row vectors and column vectors is the same as Fig.12 The processes shown are basically the same, the only difference is that the matrix needs to be filled during circular right shift, and blank bits need to be considered when reading column vectors and circularly shifting left. Taking a 4×2 matrix as an example, before inputting the row vector into the circular right shift unit, the row vector is filled to four bits, and then a circular right shift is performed to generate a right-shifted row vector. When the right-shifted row vector is written to the cache area, the filled symbol identifier is not written to the cache bit, but the corresponding cache position is empty, and when reading the column vector by column, the empty cache bit also needs to be read, that is, the corresponding position in the column vector is set to empty, and a circular left shift is performed based on the column vector containing the empty value. When outputting, the actual value is output, and the column vector that is completely empty is not considered.
[0115] The data processing method in the present application is applied to a matrix transposition system set in direct memory access. After obtaining the configuration information corresponding to the target matrix, the right shift amount corresponding to the current input row vector is determined according to the configuration information, and a right shift control instruction is generated according to the right shift amount, and the current input row vector is a row vector in the target matrix; then, in response to the right shift control instruction, the current input row vector is circularly right-shifted according to the right shift amount to obtain the right-shifted row vector corresponding to the current input row vector; then, the target cache area corresponding to the target matrix is determined in the dynamic cache area according to the configuration information, and the right-shifted row vector is written into the target cache area; when the cache of the target matrix is completed, the vector in the target cache area is step-read, and the vector read each time is circularly left-shifted to form a left-shifted column vector, so as to determine the transposed matrix corresponding to the target matrix according to the left-shifted column vector. On the one hand, the present application can process matrix transposition tasks online without calling a large number of load / store instructions through the arithmetic logic unit to read matrix data from the first-level cache for transposition, saving cache space and computing power and improving operating efficiency; on the other hand, it can dynamically allocate cache space for different matrices through the dynamic cache area, further improving the utilization of the cache space; on the other hand, according to the physical characteristics of RAM, the depth of RAM is increased as much as possible, thereby improving the surface efficiency of RAM and consuming less area.
[0116] It should be noted that although the steps of the method in the present application are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0117] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer program instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer program instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired or wireless means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integration. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a digital video disc (digital video disc, DVD)), or a semiconductor medium (e.g., a solid-state hard disk), etc.
[0118] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0119] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
[0120] A chip is also provided in an embodiment of the present application, which chip can specifically be an AI chip. The AI chip can be a dedicated computing acceleration chip (or accelerator) designed to undertake heavy computing tasks, such as a graphics processing unit (GPU), a tensor processing unit (TPU), etc. Of course, it can also be other homogeneous or heterogeneous processors.
[0121] Optionally, an AI chip may include multiple hardware devices, any of which can be used as a target hardware device according to actual needs. A hardware device may include multiple hardware execution units, such as a hardware device in an AI chip may include but is not limited to: a first unit (CU, Compute engine Unit) for general computing, a second unit (TU, Tensor Unit) for AI accelerated computing, a third unit (DMA, Direct Memory Access) for data handling, etc. Among them, a matrix transposition system is integrated in DMA, and the matrix transposition system includes: a first input port constituting a control instruction path, a first beater, a circular right shift control unit, a second beater, a cache control unit, a command queue cache unit, a circular left shift control unit, a third beater and an output network control unit, and a second input port constituting a data path, a fourth beater, a circular right shift unit, a fifth beater, a dynamic cache area containing multiple cache units, a circular left shift unit, a sixth beater, an output network unit and a seventh beater. Based on the matrix transposition system, the transposed matrix can be transposed accordingly. A hardware device in an AI chip can also be regarded as a computing cluster containing multiple hardware execution units. Different types of hardware devices may include different numbers and types of hardware execution units. The specific hardware architecture should not be construed as a limitation on the embodiments of the method of the present application.
[0122] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary technical means in the art that are not disclosed in the present application.
[0123] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A data processing method, It is characterized in that Applies to matrix transposition systems set up in direct memory access, including: Acquire configuration information corresponding to a target matrix, determine a right shift amount corresponding to a current input row vector according to the configuration information, and generate a right shift control instruction according to the right shift amount, wherein the current input row vector is a row vector in the target matrix; In response to the right shift control instruction, circularly right shift the current input row vector according to the right shift amount to obtain a right shifted row vector corresponding to the current input row vector; Determine a target buffer area corresponding to the target matrix in a dynamic buffer area according to the configuration information, and write the right-shifted row vector into the target buffer area; After the target matrix is cached, the column vectors in the target cache area are read in a step-by-step manner, and the column vectors read each time are circularly left-shifted to form left-shifted column vectors, so as to determine a transposed matrix corresponding to the target matrix according to the left-shifted column vectors.
2. The method according to claim 1, It is characterized in that The configuration information includes a matrix specification of the target matrix; the matrix transposition system includes a circular right shift control unit; The determining, by the matrix transposition system, a right shift amount corresponding to the current input row vector according to the configuration information, and generating a right shift control instruction according to the right shift amount includes: Determining, by the circular right shift control unit, a row vector sequence number corresponding to the current input row vector according to a matrix specification of the target matrix, wherein the row vector sequence number is a sequence number that increases from 0; The row vector sequence number corresponding to the current input row vector is used as the right shift amount corresponding to the current input row vector, and a right shift control instruction is generated according to the right shift amount.
3. The method according to claim 2, It is characterized in that The matrix transposition system also includes a cyclic right shift unit; The step of responding to the right shift control instruction and circularly right shifting the current input row vector according to the right shift amount includes: The circular right shift unit responds to the right shift control instruction and circularly right shifts the current input row vector according to the right shift amount.
4. The method according to claim 1, It is characterized in that The configuration information includes a matrix specification of the target matrix; the matrix transposition system includes a back pressure generating unit and a write address generating unit; the cache area includes a plurality of cache units, and each of the cache units includes a plurality of cache bits; The step of determining a target buffer area corresponding to the target matrix in a dynamic buffer area according to the configuration information, and writing the right-shifted row vector into the target buffer area comprises: Acquire, by the back pressure generating unit, the number of target cache units in the dynamic cache area that contain unwritten cache bits and the number of unwritten cache bits in each of the target cache units; When the number of columns of the matrix specification is less than or equal to the number of the target cache units, and the number of rows of the matrix specification is less than or equal to the number of unwritten cache bits, the target cache area is determined by the write address generation unit in the target cache unit and the unwritten cache bits, so as to write the data in the right-shifted row vector into the unwritten cache bits of the target cache area in sequence.
5. The method according to claim 4, It is characterized in that The method further comprises: When the number of rows of the matrix specification is greater than the number of unwritten cache bits in each of the target cache units, or the number of columns of the matrix specification is greater than the number of the target cache units, the backpressure generating unit generates a backpressure signal to refuse to write the right-shifted row vector into the dynamic cache area.
6. The method according to claim 1, It is characterized in that The matrix transposition system comprises a read address vector generating unit, wherein the read address vector generating unit comprises a plurality of read address generating components, and each of the read address generating components corresponds one-to-one to each cache unit in the dynamic cache area; The stepwise reading of the column vector in the target buffer area includes: Obtaining the difference between the sequence number of the Nth cache unit in the target cache area and the current reading time; When the difference exceeds the address representation range, determining the target cache bit address located at the Nth cache unit based on saturation subtraction; Reading data in the target cache bit, and constructing the column vector according to the data read from all cache units in the target cache area; Wherein, N and the current reading time are both non-negative integers, and the address representation range is a range constructed by the first cache bit address and the last cache bit address in the cache unit.
7. The method according to claim 1 or 6, It is characterized in that The configuration information includes a matrix specification of the target matrix; the matrix transposition system includes a circular left shift control unit and a circular left shift unit; The step of circularly left-shifting the column vector read each time to form a left-shifted column vector includes: Determine, by the circular left shift control unit, a left shift amount corresponding to a current reading moment according to a matrix specification of the target matrix, and generate a left shift control instruction according to the left shift amount; The circular left shift unit responds to the left shift control instruction and circularly left shifts the column vector according to the left shift amount to obtain the left shifted column vector.
8. The method according to claim 7, It is characterized in that The matrix transposition system comprises an output network control unit and an output network unit; The determining a transposed matrix corresponding to the target matrix according to the left-shifted column vector comprises: After all left-shifted column vectors corresponding to the target matrix are acquired, the output network control unit determines the number of output column vectors according to a preset output data amount and the amount of data contained in each left-shifted column vector, and generates an output control instruction according to the number of output column vectors; The output network unit responds to the output control instruction and outputs the left-shifted column vector according to the output column vector number, so as to obtain the transposed matrix by reorganization according to the left-shifted column vector.
9. The method according to claim 1, It is characterized in that The method further comprises: The commands corresponding to different transposition tasks are cached in order in the command queue unit, so that the corresponding tasks are executed according to the order in which the commands are stored in the command queue unit.
10. The method according to claim 1, It is characterized in that The method further comprises: The timing of control instructions and data in the matrix transposition system is controlled by multiple beaters.
11. A matrix transposition system, It is characterized in that Set in direct memory access, including: A circular right shift control unit, used to obtain configuration information of a target matrix, determine a right shift amount corresponding to a current input row vector according to the configuration information, and generate a right shift control instruction according to the right shift amount, wherein the current input row vector is a row vector in the target matrix; a circular right shift unit, connected to the circular right shift control unit, for responding to the right shift control instruction and circularly shifting the current input row vector right according to the right shift amount in the right shift control instruction to generate a right shift row vector; a cache control unit connected to the circular right shift control unit, configured to determine a target cache area corresponding to the target matrix in a dynamic cache area according to the configuration information, so as to write the right-shifted row vector into the target cache area, and after completing the caching of the target matrix, perform step-wise reading on the data in the target cache area to obtain a column vector; A circular left shift control unit, connected to the cache control unit, for determining a left shift amount corresponding to a currently read column vector according to the configuration information of the target matrix and the current reading time, and generating a left shift control instruction according to the left shift amount; A circular left shift unit is connected to the dynamic cache area and the circular left shift control unit, and is used to respond to the left shift control instruction and circularly left shift the currently read column vector according to the left shift amount to generate a left shift column vector for constructing a transposed matrix corresponding to the target matrix.
12. The matrix transposition system according to claim 11, It is characterized in that The matrix transposition system also includes: A first input port, connected to the circular right shift control unit, for inputting a command to the circular right shift control unit, wherein the command is used to indicate configuration information corresponding to the target matrix; The second input port is connected to the circular right shift unit and is used to input the row vector in the target matrix into the circular right shift unit.
13. The matrix transposition system according to claim 12, It is characterized in that The matrix transposition system also includes: an output network control unit connected to the cyclic left shift control unit, configured to determine the number of output column vectors according to a preset output data amount and the amount of data contained in the left shift column vector, and to generate an output control instruction according to the number of output column vectors; An output network unit is connected to the cyclic left shift unit and the output network control unit, and is used to respond to the output control instruction, output and reorganize the left-shifted column vector according to the number of output column vectors to generate a transposed matrix corresponding to the target matrix.
14. The matrix transposition system according to claim 13, It is characterized in that The matrix transposition system also includes: A command queue cache unit is connected to the circular right shift control unit and the cache control unit, and is used to cache command sequences corresponding to a plurality of transposition tasks.
15. The matrix transposition system according to claim 13 or 14, It is characterized in that The matrix transposition system also includes: A beater is used for performing beat processing to control the timing of commands and data in the matrix transposition system.
16. The matrix transposition system according to claim 15, It is characterized in that The matrix transposition system includes: a first beater, a second beater, a third beater, a fourth beater, a fifth beater, a sixth beater and a seventh beater; wherein the first beater is located between the first input port and the cyclic right shift control unit, and is used to beat the command input from the first input port; the second beater is located between the cyclic right shift unit and the cache control unit, and is used to beat the command after being beat by the first beater; the third beater is located between the cyclic left shift control unit and the output network control unit, and is used to beat the command processed by the second beater; the fourth beater is located between the second input port and the cyclic right shift unit, and is used to beat the command input from the second input port. The row vector is beat processed; the fifth beater is located between the cyclic right shift unit and the dynamic buffer area, and is used for beating the right-shifted row vector; the sixth beater is located between the cyclic left shift unit and the output network unit, and is used for beating the left-shifted column vector; the seventh beater is located after the output network unit, and is used for beating the left-shifted column vector output according to the output column vector number; and, the command after the first beater is beat and the row vector after the fourth beater is beat are output synchronously, the command after the second beater is beat and the right-shifted row vector after the fifth beater is output synchronously, and the command after the third beater is beat and the left-shifted column vector after the sixth beater is output synchronously.
17. The matrix transposition system according to claim 16, It is characterized in that The first input port, the first beater, the circular right shift control unit, the second beater, the cache control unit, the command queue cache unit, the circular left shift control unit, the third beater and the output network control unit constitute a control instruction path in the matrix transposition system, and the second input port, the fourth beater, the circular right shift unit, the fifth beater, the dynamic cache area, the circular left shift unit, the sixth beater, the output network unit and the seventh beater constitute a data path in the matrix transposition system.
18. The matrix transposition system according to claim 11, It is characterized in that The cache control unit includes a back pressure generating unit, a write address generating unit and a read address vector generating unit which are connected in sequence, wherein the back pressure generating unit is connected to the circular right shift control unit and is used to determine whether to generate a back pressure signal or a write signal according to the occupancy of the dynamic cache area and the configuration information of the target matrix, the write address generating unit is used to receive the write signal sent by the back pressure generating unit and allocate the target cache area to the target matrix according to the configuration information of the target matrix, and the read address vector generating unit is used to perform step-by-step reading of data in the target cache area to obtain the column vector.
19. The matrix transposition system according to claim 18, It is characterized in that The read address vector generation unit includes multiple address generation components, each of which is a saturated subtraction unit, and each of the address generation components corresponds one-to-one to each cache unit in the target cache area, and is used to determine the read address corresponding to each cache unit according to the sequence number of each cache unit and the current read time, and generate a read signal according to the read address.
20. A chip, It is characterized in that include: A matrix transposition system as claimed in any one of claims 11 to 19.
Citation Information
Cited By
Data access method and device, electronic equipment and storage medium
CN120447837A
A data access method and device, electronic equipment and storage medium
CN120447837B
