Method and system for carrying out matrix multiplication by using unit supporting convolution, device, and medium
By converting the matrix multiplication operator into a convolution operator and using units that support the convolution operator for calculation, the problem of insufficient computing performance of the matrix multiplication operator in the existing technology is solved, and efficient acceleration of the matrix multiplication operator is achieved.
Patent Information
- Application Number
- PCT/CN2024/089122
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-04-24
- Filing Date
- 2024-04-22
- Publication Date
- 2024-10-31
AI Technical Summary
Existing artificial intelligence tasks such as accelerating CNN only support convolution operators and cannot effectively accelerate matrix multiplication operators that also have a large number of multiplication and accumulation operations, resulting in insufficient computing performance in scenarios such as AI inference training, computer vision, and scientific computing.
The matrix multiplication operator is implemented by converting the first matrix and the second matrix of the matrix multiplication operator into the input data matrix and weight matrix of the convolution operator, and using a unit that supports the convolution operator operation to perform the convolution operation. Compute, thereby reusing and improving mature CNN accelerators.
It saves hardware and software overhead, improves computing performance, and achieves efficient acceleration of matrix multiplication operators.
Smart Images

Figure CN2024089122_31102024_PF_FP_ABST
Abstract
Description
Method, system, device and medium for performing matrix multiplication using a unit supporting convolution
[0001] This disclosure claims priority to Chinese Patent Application No. 202310457070.9 filed on April 24, 2023, and the contents of the above-mentioned Chinese patent application disclosure are hereby incorporated by reference in their entirety as part of this disclosure. Technical Field
[0002] The present disclosure relates to a method, system, electronic device, and non-transitory storage medium for performing a matrix multiplication operator using a unit supporting a convolution operator operation. Background Art
[0003] Convolutional Neural Networks (CNN) are a type of feedforward neural network that includes convolution calculations and has a deep structure. It is one of the representative algorithms of deep learning.
[0004] Existing artificial intelligence (AI) tasks, such as accelerated CNNs, implement multiply-accumulate (MAC) arrays to provide high computational power for convolution operators (Conv operators). A multiply-accumulate operation adds the product of a multiplication to the value in an accumulator and stores the result in the accumulator.
[0005] Summary of the Invention
[0006] According to one aspect of the present disclosure, a method for performing a matrix multiplication operator using a unit supporting convolution operator operations is provided, comprising: converting a first matrix of the matrix multiplication operator into an input data matrix of the convolution operator; converting a second matrix of the matrix multiplication operator into a weight matrix of the convolution operator, wherein the first matrix and the second matrix are to be matrix multiplied; and using a unit supporting convolution operator operations to perform a convolution operation on the converted input data matrix and the weight matrix of the convolution operator to obtain an operation result of the matrix multiplication operator.
[0007] According to another aspect of the present disclosure, a system for performing a matrix multiplication operator using a unit supporting a convolution operator operation is provided, comprising: a first conversion device configured to convert a first matrix of the matrix multiplication operator into an input data matrix of the convolution operator; a second conversion device configured to convert a second matrix of the matrix multiplication operator into a weight matrix of the convolution operator, wherein the first matrix and the second matrix are to be matrix multiplied; and a convolution operation device configured to perform a convolution operation on the converted input data matrix and the weight matrix of the convolution operator using the unit supporting the convolution operator operation to obtain an operation result of the matrix multiplication operator.
[0008] According to another aspect of the present disclosure, an electronic device is provided, including: a memory for storing instructions; and a processor for reading the instructions in the memory and executing a method according to an embodiment of the present disclosure.
[0009] According to another aspect of the present disclosure, a non-transitory storage medium is provided, on which instructions are stored, wherein when the instructions are read by a processor, the processor is caused to execute a method according to an embodiment of the present disclosure.
[0010] In this way, since the matrix multiplication operator has a large number of multiplication and accumulation calculations like the convolution operator, and the multiplication and accumulation of the convolution operator is mainly reflected in the multiplication and accumulation between the input data matrix and the weight matrix of the convolution operator, the first matrix of the matrix multiplication operator is converted into the input data matrix of the convolution operator and the second matrix of the matrix multiplication operator is converted into the weight matrix of the convolution operator. The unit that supports the convolution operator operation can be used to perform convolution operations on the converted input data matrix and weight matrix of the convolution operator to obtain the operation result of the matrix multiplication operator, thereby saving hardware and software overhead and improving operation performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0012] 1A-1B are schematic diagrams showing the convolution process of a convolutional neural network in the prior art.
[0013] FIG2A shows a schematic process of performing a convolution operation on an input data cube and a weight cube to obtain an output data cube.
[0014] FIG2B shows an intuitive schematic diagram of an atomic operation of performing a convolution operation on an input data cube and a weight cube in hardware using a unit supporting the Conv operator operation.
[0015] FIG2C shows an intuitive schematic diagram of a stripe operation of performing a convolution operation on an input data cube and a weight cube on hardware using a unit supporting the Conv operator operation.
[0016] FIG2D shows an intuitive schematic diagram of a block operation of performing a convolution operation on an input data cube and a weight cube on hardware using a unit supporting Conv operator operation.
[0017] FIG2E shows an intuitive schematic diagram of a channel operation of performing a convolution operation on an input data cube and a weight cube in hardware using a unit supporting the Conv operator operation.
[0018] FIG2F shows a schematic diagram of the output cube after convolution and its output order.
[0019] FIG3 is a schematic diagram showing an example matrix multiplication process of matrix A and matrix B. In FIG3 , a matrix multiplication process is shown.
[0020] FIG4 shows a flowchart of a method 400 for performing a matrix multiplication operator using a unit supporting a convolution operator operation according to an embodiment of the present disclosure.
[0021] FIG5A shows a flowchart of a method for performing a matrix multiplication operator using a unit supporting a convolution operator operation according to another embodiment of the present disclosure.
[0022] Figure 5B shows a schematic diagram of the parameter mapping relationship between the matrix multiplication and convolution operators when the number of rows of the first matrix of the matrix multiplication operator is mapped to the width parameter of the input matrix of the convolution operator according to another embodiment of the present disclosure as shown in Figure 5A.
[0023] FIG6A shows another flowchart of a method for performing a matrix multiplication operator using a unit supporting convolution operator operations according to another embodiment of the present disclosure.
[0024] FIG6B shows a schematic diagram of mapping the first matrix and the second matrix of the matrix multiplication operator to the input data matrix and the weight matrix of the convolution operator.
[0025] FIG6C is a schematic diagram showing a convolution performed by a matrix multiplication (MAC) unit in a unit supporting Conv operator operations.
[0026] FIG7 shows a flowchart of a matrix data format that directly supports matrix multiplication on deep learning accelerator DLA hardware by using a unit that supports convolution operator operations according to another embodiment of the present disclosure.
[0027] FIG8 is a schematic diagram showing the order of fetching the first matrix and memory mapping of a matrix multiplication operator according to an embodiment of the present disclosure.
[0028] FIG9 is a schematic diagram showing the order of fetching the second matrix and memory mapping of the matrix multiplication operator according to an embodiment of the present disclosure.
[0029] FIG10 is a schematic diagram showing a storage order and memory mapping of a result matrix of a matrix multiplication operator according to an embodiment of the present disclosure.
[0030] FIG11 shows a block diagram of a system for performing a matrix multiplication operator using a unit supporting a convolution operator operation according to an embodiment of the present disclosure.
[0031] FIG12 illustrates a block diagram of an exemplary electronic device suitable for implementing embodiments of the present disclosure.
[0032] as well as
[0033] FIG13 shows a schematic diagram of a non-transitory computer-readable storage medium according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0034] Reference will now be made in detail to specific embodiments of the present disclosure, examples of which are illustrated in the accompanying drawings. Although the present disclosure will be described in conjunction with specific embodiments, it will be understood that the disclosure is not intended to be limited to the described embodiments. On the contrary, it is intended to cover variations, modifications, and equivalents within the spirit and scope of the present disclosure as defined by the appended claims. It should be noted that the method steps described herein can be implemented by any functional block or functional arrangement, and any functional block or functional arrangement can be implemented as a physical entity or a logical entity, or a combination of the two.
[0035] 1A-1B are schematic diagrams showing the convolution process of a convolutional neural network in the prior art.
[0036] As shown in Figure 1A, assume that the input data is a 7×7×3 three-dimensional matrix (input data cube, Datain Cube) (Height (Datain Height) = 7, Width (Datain Width) = 7, Channel (Datain Channel) = 3). The first channel of the input data is the 7×7 two-dimensional matrix x[:,:,0] in the upper left corner of Figure 1A, the second channel of the input data is the 7×7 two-dimensional matrix x[:,:,1] in the middle left corner of Figure 1A, and the third channel of the input data is the 7×7 two-dimensional matrix x[:,:,2] in the lower left corner of Figure 1A.
[0037] The weight matrix (weight cube) to be convolved with the input data consists of two convolution kernel matrices (also called filters), w0 and w1, with Weight Kernel = 2. Each convolution kernel matrix is a 3×3×3 three-dimensional matrix (Height = 3, Width = 3, Channel = 3). The first channel of the first convolution kernel matrix is a 3×3 two-dimensional matrix w0[:,:,0], the second channel is a 3×3 two-dimensional matrix w0[:,:,1], and the third channel is a 3×3 two-dimensional matrix w0[:,:,2]. Note that the number of channels in the weight matrix, 3, must be equal to the number of channels in the input data, because the first channel multiplication is performed, then the second channel multiplication, then the third channel multiplication, and finally the three channel products are accumulated. The first channel of the second convolution kernel matrix is a 3×3 two-dimensional matrix w1[:,:,0], the second channel is a 3×3 two-dimensional matrix w1[:,:,1], and the third channel is a 3×3 two-dimensional matrix w1[:,:,2].
[0038] Note that, as shown in Figure 1A, each convolution kernel also includes a bias: b0 and b1. The role of this bias is to add this bias after the three channel products are accumulated.
[0039] The output matrix is a 3×3×2 three-dimensional matrix (dataout cube) (height = 3, width = 3, channels = 2). The number of channels corresponds to the number of kernels in the weight matrix (weight kernel), both of which are 2. The 3×3 matrix of the first channel of the output matrix is o[:,:,0], and the 3×3 matrix of the second channel of the output matrix is o[:,:,1].
[0040] Next, the specific convolution process shown in Figure 1A is as follows:
[0041] When the convolution window size is 3×3, first, the 3×3 matrix in the two-dimensional matrix of the first channel of the input data is multiplied and accumulated with the corresponding number of the 3×3 matrix of the convolution kernel of the first channel, that is, 0×1+0×1+0×1+0×(-1)+1×(-1)+1×0+0×(-1)+1×1+1×0=0, and then the 3×3 matrix in the two-dimensional matrix of the second channel of the input data is multiplied with the corresponding number of the 3×3 matrix of the convolution kernel of the second channel. And accumulate, that is, 0×(-1)+0×(-1)+0×1+0×(-1)+0×1+1×0+0×(-1)+2×1+2×0=2, and then the 3×3 matrix in the two-dimensional matrix of the second channel of the input data is multiplied by the corresponding number of the 3×3 matrix of the convolution kernel of the second channel and accumulated (that is, the inner product of the two matrices), that is, 0×1+0×0+0×(-1)+0×0+2×0+2×0+0×1+0×(-1)+0×(-1)=0.
[0042] Then, the results of the three channel multiplications are accumulated (i.e., multiplication and accumulation are performed), that is, 0+2+0=2, and then the bias b0=1 is added, that is, 2+1=3. Therefore, the first value of the 3×3 matrix o[:,:,0] of the first channel of the output matrix is [0,0,0]=3.
[0043] Then, as shown in Figure 1B, the window is shifted right by the sliding step size (e.g., 2) elements. The second 3×3 matrix is taken from each channel of the input data cube and multiplied by the corresponding weight matrix of the first kernel (i.e., the inner product of the two matrices). This yields the second value [0,1,0] = -5 of the 3×3 matrix o[:,:,0] of the first channel of the output matrix. This continues in this manner, yielding all the values of the 3×3 matrix o[:,:,0] of the first channel of the output matrix.
[0044] Then, all the values of the 3×3 matrix o[:,:,1] of the second channel of the output matrix of the convolution of the input matrix and the weight matrix w1 of the second kernel can be calculated in the same way.
[0045] 2A-2F show intuitive schematic diagrams of performing convolution operations on input data cubes and weight cubes on hardware using units supporting Conv operator operations.
[0046] FIG2A shows a schematic process of performing a convolution operation on an input data cube and a weight cube to obtain an output data cube.
[0047] As shown in Figure 2A, the convolution operator inputs: input data and weight data. The size of the input data cube is W × H × C. Where W represents the width, H represents the height, and C represents the number of channels, and they are all positive integers.
[0048] The size of a weight kernel is R×S×C, where R represents the height, S represents the width, and C represents the number of channels, and they are all positive integers.
[0049] The total number of kernel weights is K, which is a positive integer.
[0050] After convolution of the input data cube and the weight cube, the size of the output data cube is W'×H'×C'. Where W' represents the width, H' represents the height, and C' represents the number of channels, and they are all positive integers.
[0051] To perform the above convolution operations, the convolution pipeline uses a method called direct convolution. The key idea of direct convolution is to divide the multiplication operations from each convolution kernel into groups so that each group contains 64 multiplication operations. The basic rules are:
[0052] 1. All multiply-accumulate MAC hardware is divided into 16 subunits. Each subunit, called a MAC unit, has hardware for 64 int16 / fp16 MACs or 128 int8 MACs. Int16, fp16, and int8 are different data formats. Note that since this is a hardware implementation, considerations must be made regarding the stored data format, the method and order in which data is stored in and retrieved from memory, and so on.
[0053] 2. A collection of MAC units is called a MAC unit array.
[0054] 3. For int16, fp16, and int8, split all input data cubes into 1×1×64 cubes. This means that each cube has 64 channels and a width and height of 11. If each number in the cube is in int16 or fp16 format, the size is 2 bytes, resulting in a channel-wise length of 128 bytes. If each number in the cube is in int8 format, the size is 1 byte, resulting in a channel-wise length of 64 bytes.
[0055] 4. Divide all weight data cubes into small cubes of 1×1×64 elements, each int16, fp16, and int8. Specifically, within each core's weight data cube, a small cube with 64 channels and a width and height of 1 is constructed. If each number in this cube is int16 or fp16 format, the size is 2 bytes, resulting in a channel-wise length of 128 bytes. If each number in this cube is int8 format, the size is 1 byte, resulting in a channel-wise length of 64 bytes.
[0056] 5. Multiply a small input data cube by a small weight data cube and add the products (i.e., multiply-accumulate). These multiplications and additions are performed within a MAC unit.
[0057] 6. These computing operations are combined into four operation levels, namely atomic operations, stripe operations, block operations, and channel operations.
[0058] The following describes these four operations using the precision mode of the int16 data format as an example.
[0059] FIG2B shows an intuitive schematic diagram of an atomic operation of performing a convolution operation on an input data cube and a weight cube in hardware using a unit supporting the Conv operator operation.
[0060] Atomic operations are the fundamental steps of direct convolution. In an atomic operation, each MAC unit caches a 1×1×64 weight cube from a single weight kernel. Therefore, 16 MAC units cache weights from 16 int16 / fp16 kernels or 32 int8 kernels. All MAC units share a 1×1×64 atomic cube of feature data.
[0061] As shown in FIG2B , if the format of each number in the cube is int16, the size is 2 bytes, and thus the length in the channel direction is 128 bytes.
[0062] The MAC unit performs the calculation mentioned in Rule 5 above. As shown in Figure 2B, one MAC unit multiplies a small input data cube 0 by a small weight data cube K0_00, one MAC unit multiplies a small input data cube 0 by a small weight data cube K1_00, ... one MAC unit multiplies a small input data cube 0 by a small weight data cube K14_00, and one MAC unit multiplies a small input data cube 0 by a small weight data cube K15_00. The output of each MAC unit is called a partial sum. This operation requires one cycle to complete, resulting in 16 partial sums per cycle. The partial sums are sent to the convolution adder module for further calculation.
[0063] FIG2C shows an intuitive schematic diagram of a stripe operation of performing a convolution operation on an input data cube and a weight cube on hardware using a unit supporting the Conv operator operation.
[0064] Strip operations combine a set of atomic operations from several convolutions. During a strip operation, the weight data in the MAC unit array remains unchanged. The input data slides along the input data cube. That is, small input data cube 0 is multiplied by a small weight data cube K0_00, small input data cube 1 is multiplied by a small weight data cube K0_00, small input data cube 2 is multiplied by a small weight data cube K0_00, small input data cube 3 is multiplied by a small weight data cube K0_00, small input data cube 6 is multiplied by a small weight data cube K0_00, small input data cube 7 is multiplied by a small weight data cube K0_00, and so on. Small input data cube 20 is multiplied by a small weight data cube K0_00, and small input data cube 21 is multiplied by a small weight data cube K0_00. Here, a sliding window of 4×4 is assumed.
[0065] Note that the partial sums within a strip operation cannot be added together since they correspond to different points in the output cube.
[0066] There are limits on the length of a strip operation. The lower limit of 16 is due to the internal bandwidth required to extract weights for the next strip operation. The upper limit is 32 due to the buffer size in the accumulator. In some extreme cases, the length may be less than the lower limit.
[0067] Figure 2C shows an example of a stripe operation with 16 atomic operations. In this case, the padding size is 0. Note that this is not a progressive scan of the input data cube. Although, in general, the stripe is indeed first scanned along the W dimension. Figure 2C shows an example without padding, so the last two columns are not part of the first stripe (using a 3×3 kernel, no padding, input data W=6, output data W=4).
[0068] FIG2D shows an intuitive schematic diagram of a block operation of performing a convolution operation on an input data cube and a weight cube on hardware using a unit supporting Conv operator operation.
[0069] Block operations are higher-level operations composed of multiple strip operations. During a block operation, each kernel in the kernel group uses R×S×64 weight elements and a small cube of input feature data, sized appropriately to ensure that the results can be added across the strip operations and accumulated into a 16-by-32 element accumulator.
[0070] All stripe operations in a block have the same atomic operation number. In the convolution accumulator, each stripe operation adds together the partial sums from the same block. These results are called cumulative sums.
[0071] FIG2E shows an intuitive schematic diagram of a channel operation of performing a convolution operation on an input data cube and a weight cube in hardware using a unit supporting the Conv operator operation.
[0072] Channel operations are higher-level operations. They include (C+63) / 64 block operations. The block operations in a channel operation are similar, except that the coordinates of the channel direction are different.
[0073] All partial sums of a channel operation can be added together through stripe operation. After a channel operation, the result in the convolution accumulator is the convolution result.
[0074] After one channel operation is completed, the accumulator is unloaded and sent to the post-processor to make room for the next channel operation.
[0075] After channel operations, group operations are performed. This is a more advanced operation than channel operations, completing the entire computation for a group of kernels. This includes channel operations. After group operations, the output data forms an output matrix of W × H × K'. Here, K' refers to the kernel size in the kernel group. A kernel group is the number of kernels processed at a time, one per MAC unit.
[0076] Typically, there are 16 identical multiplication arrays used to calculate the multiplication of 16 different cores; and each multiplication array has 64 multiplications and a 64-input addition tree for multiplication and accumulation.
[0077] When calculating direct convolution, each cycle requires 128 bytes of feature / pixel data (i.e., the data of the elements of the input data matrix), or 64 channels of data (because each data point occupies 2 bytes in the case of int16 / fp16). Therefore, when storing, only 64 channels of data need to be stored in each memory bank. When using, the data in a specific memory bank is selected through a multiplexer (MUX). When writing back the results, 16 feature data points need to be written back per cycle.
[0078] FIG2F shows a schematic diagram of the output cube after convolution and its output order.
[0079] The order mentioned in each operation refers primarily to the input feature data and weight data, not the output order. The output data sequence is very simple. It follows the order C'(K') -> W -> H -> C(K). Here, C' or K' refers to the kernel group size, which is 16 for int16 / fp16 and 32 for int8.
[0080] Existing acceleration for AI tasks like CNNs implements a multiply-accumulate MAC array, providing high computational power for convolutional operators (Conv operators). However, this only supports Conv operators and cannot accelerate matrix multiplication operators, which also require a large number of MAC operations. Matrix multiplication operators are widely used in data center and high-performance computing (HPC) scenarios, such as AI inference training, Basic Linear Algebra Subprograms (BLAS), computer vision, and scientific computing, and therefore require accelerated processing.
[0081] This disclosure aims to reuse and improve mature CNN accelerators to process a large number of matrix multiplication operators in various application scenarios, so as to better offload and accelerate the tasks of the host central processing unit (CPU).
[0082] As mentioned above, during the calculation process of the Conv operator, there is a multiplication-accumulation MAC calculation between each channel of the input matrix and each channel of the weight matrix, that is, the inner product of each channel of the input matrix and the corresponding channel of the weight matrix is summed.
[0083] Matrix multiplication involves a large amount of data reuse and multiply-accumulate (MAC) operations. Therefore, the present disclosure hopes to utilize the similarity between matrix multiplication and Conv operators to map matrix multiplication to Conv operators, thereby accelerating matrix multiplication using a CNN accelerator that only processes Conv operators.
[0084] The following describes in detail how to use the CNN accelerator that only processes Conv operators to accelerate matrix multiplication:
[0085] FIG3 is a schematic diagram showing an example matrix multiplication process of matrix A and matrix B. In FIG3 , a matrix multiplication process is shown.
[0086] Assume that the two matrices to be multiplied are Matrix A and Matrix B, where Matrix A is an M×K two-dimensional matrix and Matrix B is a K×N two-dimensional matrix, where M, K, and N are positive integers. The resultant matrix C obtained by performing the matrix multiplication operation on Matrix A and Matrix B is an M×N two-dimensional matrix. As is well known, to multiply two matrices, the number of columns in Matrix A must be equal to the number of rows in Matrix B.
[0087] As shown in FIG3 , taking M=5, K=4, N=6 as an example, that is, the matrix A is a 5×4 two-dimensional matrix Matrix A is a 4×6 two-dimensional matrix The resulting matrix C is a 5×6 two-dimensional matrix
[0088] Where C11 = A11 × B11 + A12 × B21 + A13 × B31 + A14 × B41. C12 = A11 × B12 + A12 × B22 + A13 × B32 + A14 × B42, and so on. C21 = A21 × B11 + A22 × B21 + A23 × B31 + A24 × B41, C22 = A21 × B12 + A22 × B22 + A23 × B32 + A24 × B42, and so on. I won't go into detail here about all the calculations for matrix multiplication.
[0089] In short, matrix multiplication also has a large number of multiply-accumulate MAC calculations.
[0090] Therefore, it is hoped that the similarity between matrix multiplication and Conv operators can be exploited to map matrix multiplication to Conv operators, thereby accelerating matrix multiplication using a CNN accelerator that only processes Conv operators.
[0091] FIG4 shows a flowchart of a method 400 for performing a matrix multiplication operator using a unit supporting a convolution operator operation according to an embodiment of the present disclosure.
[0092] As shown in FIG. 4 , a method 400 for performing a matrix multiplication operator using a unit supporting a convolution operator operation includes the following steps.
[0093] Step 410: Convert the first matrix of the matrix multiplication operator into an input data matrix of the convolution operator.
[0094] The matrix multiplication operator usually multiplies two matrices, for example, the first matrix and the second matrix.
[0095] Step 420: Convert the second matrix of the matrix multiplication operator into a weight matrix of the convolution operator.
[0096] The first matrix and the second matrix are to be matrix multiplied.
[0097] Step 430: Use a unit that supports convolution operator operations to perform a convolution operation on the converted input data matrix and weight matrix of the convolution operator to obtain an operation result of the matrix multiplication operator.
[0098] In this way, since the matrix multiplication operator has a large number of multiplication-accumulation MAC calculations like the convolution operator, and the multiplication-accumulation of the convolution operator is mainly reflected in the multiplication-accumulation between the input data matrix and the weight matrix of the convolution operator, the first matrix of the matrix multiplication operator is converted into the input data matrix of the convolution operator and the second matrix of the matrix multiplication operator is converted into the weight matrix of the convolution operator. The unit that supports the convolution operator operation can be used to perform convolution operations on the converted input data matrix and weight matrix of the convolution operator to obtain the operation result of the matrix multiplication operator, thereby saving hardware and software overhead and improving operation performance.
[0099] FIG5A shows a flowchart of a method 400 for performing a matrix multiplication operator using a unit supporting a convolution operator operation according to another embodiment of the present disclosure.
[0100] For the convolution operator, the input data includes the input data cube (or matrix) (Datain Cube) and the weight cube (or matrix) (Weight Cube).
[0101] The parameters of the data cube are Datain Width (i.e., width parameter), Datain Height (i.e., height parameter), and Datain Channel (i.e., channel parameter). Note that the parameters refer to size. For example, the width parameter refers to the width of the matrix, that is, the number of elements in the width dimension; the height parameter refers to the height of the matrix, that is, the number of elements in the height dimension; and the channel parameter refers to the size of the channel of the matrix, that is, the number of elements in the channel dimension, that is, the number of channels.
[0102] The parameters of the weight cube are Weight Width, Weight Height, Weight Channel, and Weight Kernel.
[0103] The parameters of the output data cube (Dataout Cube) of the convolution operator are data output width (Dataout Width), data output height (Dataout Height) and data output channel (Dataout Channel).
[0104] Assume that the number of rows of the first matrix for which the matrix multiplication operator is to be calculated is M, the number of columns of the first matrix for which the matrix multiplication operator is to be calculated is K, the number of rows of the second matrix for which the matrix multiplication operator is to be calculated is K, and the number of columns of the second matrix for which the matrix multiplication operator is to be calculated is N, where M, K, and N are positive integers.
[0105] In FIG5A , step 410 of converting the first matrix of the matrix multiplication operator into the input data matrix of the convolution operator includes the following steps.
[0106] Step 411: Map the number of rows M of the first matrix of the matrix multiplication operator to one of the width parameter or the height parameter of the input data matrix of the convolution operator.
[0107] In step 412, the other parameter of the width parameter or the height parameter of the input data matrix of the convolution operator is set to 1.
[0108] In general, since the first matrix of the matrix multiplication operator is two-dimensional, and the input data matrix of the convolution operator is three-dimensional, the two-dimensional matrix must be mapped to a three-dimensional matrix first. Then, the parameter of one dimension of the input data matrix of the convolution operator (that is, the number of elements) must be set to 1. Since the multiplication and accumulation operation must include the calculation of the channel dimension, the input data matrix of the convolution operator can be converted to a two-dimensional matrix by taking one of the width and height dimensions and setting the number of elements in the other dimension to 1. This is equivalent to removing the other dimension and converting it to a two-dimensional matrix.
[0109] Note that if the number of rows M of the first matrix of the matrix multiplication operator is mapped to the width parameter of the input data matrix of the convolution operator, the height parameter of the input data matrix of the convolution operator is set to 1. On the other hand, if the number of rows M of the first matrix of the matrix multiplication operator is mapped to the height parameter of the input data matrix of the convolution operator, the width parameter of the input data matrix of the convolution operator is set to 1.
[0110] There are two mapping methods for mapping the number of rows M of the first matrix of the matrix multiplication operator to the width parameter or height parameter of the input data matrix of the convolution operator, which can provide equivalent hardware execution efficiency and performance. One mapping scheme can be selected based on the design and implementation logic of hardware units such as data organization and process control of the reused Conv operator.
[0111] Step 413: Map the number of columns K of the first matrix of the matrix multiplication operator to the number of channels of the input data matrix of the convolution operator.
[0112] Thus, after setting the parameters in this way, the first matrix of the matrix multiplication operator will be mapped to a two-dimensional matrix of the input data of the convolution operator, with only the width or height dimension and the channel dimension of the input data of the convolution operator.
[0113] The step 420 of converting the second matrix of the matrix multiplication operator into the weight matrix of the convolution operator includes the following steps.
[0114] Step 421 : Map the number of rows K of the second matrix of the matrix multiplication operator to the number of channels of the weight matrix of the convolution operator.
[0115] Step 422: Set the width parameter and height parameter of the weight matrix of the convolution operator to 1.
[0116] Step 423: Map the number of columns N of the second matrix of the matrix multiplication operator to the number of cores of the weight matrix of the convolution operator.
[0117] That is to say, the two dimensions of the second matrix of the matrix multiplication operator are mapped to the channel dimension and kernel dimension of the weight matrix of the convolution operator respectively, that is, the weight matrix of the convolution operator becomes a two-dimensional matrix, and the width dimension and height dimension of the weight matrix of the convolution operator are removed, because the width or height dimension and channel dimension of the input data of the convolution operator are multiplied and accumulated with the channel dimension and kernel dimension of the weight operator, that is, the multiplication and accumulation of the convolution operator can be used to calculate the multiplication and accumulation in the matrix multiplication to obtain the result of the matrix multiplication.
[0118] Figure 5B shows a schematic diagram of the parameter mapping relationship between the matrix multiplication and convolution operators when the number of rows of the first matrix of the matrix multiplication operator is mapped to the width parameter of the input matrix of the convolution operator according to another embodiment of the present disclosure as shown in Figure 5A.
[0119] As shown in FIG5B , the number of rows M of the first matrix of the matrix multiplication operator is mapped to the width parameter of the input data matrix of the convolution operator. The other parameter of the height parameter of the input data matrix of the convolution operator is set to 1. The number of rows K of the second matrix of the matrix multiplication operator is mapped to the number of channels of the weight matrix of the convolution operator. The width parameter and the height parameter of the weight matrix of the convolution operator are both set to 1. The number of columns N of the second matrix of the matrix multiplication operator is mapped to the number of cores of the weight matrix of the convolution operator.
[0120] In this way, the first matrix of the matrix multiplication operator is changed to the input data matrix of the convolution operator of M×1×K (i.e., an M×K two-dimensional matrix), and the second matrix of the matrix multiplication operator is changed to the weight matrix of the convolution operator of 1×1×K×N (i.e., a K×N two-dimensional matrix). Then the output matrix after convolution is M×1×N (i.e., an M×N two-dimensional matrix), which is the calculation result of the matrix multiplication operator.
[0121] Therefore, as shown in FIG5B , the data output width parameter of the output data matrix (or result matrix) is M, the data output height parameter is 1, and the data output channel parameter is N.
[0122] The parameter settings are introduced above. According to the parameter settings, the first matrix and the second matrix of the matrix multiplication operator can be actually converted into the input data matrix and the weight matrix of the convolution operator.
[0123] FIG6A shows another flow chart of a method 400 for performing a matrix multiplication operator using a unit supporting a convolution operator operation according to another embodiment of the present disclosure.
[0124] In addition to the steps shown in FIG. 5A , step 410 of converting the first matrix of the matrix multiplication operator into the input data matrix of the convolution operator further includes the following steps.
[0125] In step 414, if the number of rows M of the first matrix of the matrix multiplication operator is mapped to the height parameter of the input data matrix of the convolution operator, each row of the first matrix of the matrix multiplication operator is mapped to each row of the input data matrix of the convolution operator; if the number of rows M of the first matrix of the matrix multiplication operator is mapped to the width parameter of the input data matrix of the convolution operator, each row of the first matrix of the matrix multiplication operator is mapped to each column of the input data matrix of the convolution operator.
[0126] Step 415 : Map each column of the first matrix of the matrix multiplication operator to each channel of the input data matrix of the convolution operator.
[0127] In this way, the first matrix of the matrix multiplication operator is actually changed into an input data matrix of the convolution operator of M×1×K (ie, an M×K two-dimensional matrix).
[0128] In addition to the steps shown in FIG. 5A , converting the second matrix of the matrix multiplication operator into the weight matrix 420 of the convolution operator also includes the following steps.
[0129] Step 424 : Map each row of the second matrix of the matrix multiplication operator to each channel of the weight matrix of the convolution operator.
[0130] Step 425 : Map each column of the second matrix of the matrix multiplication operator to each kernel of the weight matrix of the convolution operator.
[0131] FIG6B shows a schematic diagram of mapping the first matrix and the second matrix of the matrix multiplication operator to the input data matrix and the weight matrix of the convolution operator.
[0132] The left side of FIG6B shows the first matrix of the matrix multiplication operator mapped to the input data matrix of the convolution operator, where width W = M, height H = 1, and channel C = K. It can be seen that this is a two-dimensional matrix.
[0133] The right side of FIG6B shows the weight matrix of the convolution operator mapped to the second matrix of the matrix multiplication operator, where width W = 1, height H = 1, channel C = K, and kernel Kernel = N. It can be seen that this is also a two-dimensional matrix.
[0134] Of course, note that this is merely an example and not a limitation.
[0135] In this way, the second matrix of the matrix multiplication operator is actually changed into a weight matrix of the convolution operator of 1×1×K×N (ie, a two-dimensional matrix of K×N).
[0136] Then the output matrix after convolution is M×1×N (that is, an M×N two-dimensional matrix), which is the calculation result of the matrix multiplication operator.
[0137] In this way, the unit of the convolution operator can be used to apply the first matrix and the second matrix of the matrix multiplication operator to obtain the result of the matrix multiplication operator through the convolution process.
[0138] The following describes how to actually implement the above mapping of the matrix multiplication operator to the convolution operator and perform convolution calculations on the Deep Learning Accelerator (DLA) hardware.
[0139] The data format of the matrices for matrix multiplication (hereinafter referred to as the two matrices of the matrix multiplication operator) can be directly supported on the deep learning accelerator DLA hardware, thereby avoiding the overhead of converting from the matrix format to the Conv data format and then loading it as the input data cube and weight cube of the convolution operator, thereby improving performance. In other words, using the deep learning accelerator DLA hardware that supports the convolution operator, the elements of the two matrices of the matrix multiplication operator stored in the memory are directly retrieved and loaded as the input data cube and weight cube of the convolution operator, which can save hardware and software overhead and improve computing performance.
[0140] Support for matrix formats requires consideration of both row-major and column-major matrices. The starting address of the matrix data in memory may not align with the hardware's memory access interface. Hardware-implemented modules can be used to convert and process the matrix order and alignment to meet the processing requirements of the data loading and data storage modules. This can be processed inline within the Convolution Direct Memory Access (CDMA) module that loads the input data and the Write Direct Memory Access (WDMA) module that stores the result data, or it can be processed using a dedicated independent format conversion module that can operate in parallel with the CDMA and / or WDMA modules.
[0141] After loading data, DLA will first store it in an on-chip buffer for processing by the operation unit. The size of each data item in the buffer is usually determined by the scale of the MAC operation array, which will also affect the processing logic of the matrix data loading module.
[0142] The following lists the order / alignment requirements of the CDMA and WDMA modules for the matrix format and the processing logic for matrix data loading / storage.
[0143] As before, only 64 channel data need to be stored on each memory block (bank) during storage. Assuming that the data format of the channel data is int16 (i.e., it occupies 2 bytes), each data item of the internal buffer for storing the loaded data is 128 bytes.
[0144] The CDMA input data matrix loading module supports row-major matrices and requires that the matrix's starting address and column parameters be 32-byte aligned. This ensures that the starting address of each row is 32-byte aligned. The upstream module can pre-process the input data matrix to meet this requirement. The 32-byte format is determined by the structure of the multiply-accumulate unit that supports the convolution operator.
[0145] FIG6C is a schematic diagram showing a convolution performed by a matrix multiplication (MAC) unit in a unit supporting Conv operator operations.
[0146] The structure of the multiplication and accumulation unit has 32 MAC units (not shown) when the data format is int8, and 16 MAC units when the data format is int16 (as shown in Figure 6C). Each multiplication and accumulation unit multiplies the input weights and features and inputs the multiplication results into the convolution accumulation accumulator for accumulation. As shown in Figure 6C, the features and weights output from the convolution sequence controller (CSC) can be calculated in parallel by 16 MAC units at a time to produce 16 accumulation results, which are ultimately written into the convolution accumulation accumulator (CACC). Each accumulation result is in the original precision size, i.e., 1 byte when the data format is int8 and 2 bytes when the data format is int16. Therefore, the structure of the multiplication and accumulation unit enables calculation of 32 words at a time.
[0147] In other words, the structure of the multiply-accumulate unit allows each multiply-accumulate operation to process 32 bytes of data. Therefore, the matrix start address and column parameters must be 32-byte aligned so that 32 bytes of data can be processed at a time. Of course, the 32-byte size is just an example; other byte sizes are also possible.
[0148] FIG7 shows a flowchart of a matrix data format that directly supports matrix multiplication on deep learning accelerator DLA hardware by using a unit that supports convolution operator operations according to another embodiment of the present disclosure.
[0149] As shown in FIG7 , step 410 of converting the first matrix of the matrix multiplication operator into the input data matrix of the convolution operator further includes: step 416 of loading the first matrix of the matrix multiplication operator using the input data matrix loading module of the unit supporting the convolution operator operation.
[0150] The step 420 of converting the second matrix of the matrix multiplication operator into the weight matrix of the convolution operator further includes: step 426, using the weight matrix loading module of the unit supporting the convolution operator operation to load the second matrix of the matrix multiplication operator.
[0151] Step 430 of using a unit that supports convolution operator operations to perform a convolution operation on the converted input data matrix and weight matrix of the convolution operator to obtain the operation result of the matrix multiplication operator also includes: step 431, using a result matrix storage module of the unit that supports convolution operator operations to store the result matrix of the matrix multiplication operator.
[0152] Next, with reference to Figures 8-10, the process of directly supporting the matrix data format for matrix multiplication on the deep learning accelerator DLA hardware will be described in detail.
[0153] FIG8 is a schematic diagram showing the order of fetching the first matrix and memory mapping of a matrix multiplication operator according to an embodiment of the present disclosure.
[0154] Step 416 of loading the first matrix of the matrix multiplication operator using the input data matrix loading module of the unit supporting the convolution operator operation includes: aligning the starting address of each row of the first matrix of the matrix multiplication operator according to a first predetermined size, the first predetermined size being associated with the structure of the multiplication-accumulation unit supporting the convolution operator operation; dividing the data of each row of the first matrix of the matrix multiplication operator into small cubes of a second predetermined size, wherein the second predetermined size is a predetermined multiple of the first predetermined size; and loading the first matrix of the matrix multiplication operator according to a nested loop order of small cubes, rows, and columns of the first matrix of the matrix multiplication operator from an inner loop to an outer loop.
[0155] Specifically, the first predetermined size is 32 bytes. Here, the structure of the multiply-accumulate unit enables each multiply-accumulate operation to process 32 bytes of data. Therefore, the first predetermined size is associated with the structure of the multiply-accumulate unit that supports the convolution operator operation.
[0156] As shown in Figure 8, taking the data precision of int16 as an example, each row of the first matrix of the matrix multiplication operator (corresponding to the channel parameters of the input data matrix of the convolution operator, a total of 4 channels) is divided into small cubes of 128 bytes (regardless of the number of elements in the first matrix, the data sizes of these are concatenated together, and the overall data is divided into multiple small cubes of 128 bytes). If the column parameters of the original input data matrix before formatting are not 32-byte aligned, the CDMA module will align the last data with 32 bytes and append 0 to store it in the buffer, and finally update the write pointer of the buffer with 128-byte alignment.
[0157] As shown on the left side of Figure 8, taking the data precision of int16 as an example, since the size of each of the elements 0, 1, 2...18, 19 in the first matrix is 32 bytes, when each row of the first matrix of the matrix multiplication operator is divided into small cubes of 128 bytes, the first cube in the first row is composed of elements 0, 1, 2, 3, the second cube in the first row is composed of element 4, the first cube in the second row is composed of elements 5, 6, 7, 8, the second cube in the second row is composed of element 9, the first cube in the third row is composed of elements 10, 11, 12, 13, the second cube in the third row is composed of element 14, the first cube in the fourth row is composed of elements 15, 16, 17, 18, and the second cube in the fourth row is composed of element 19.
[0158] The order of taking out the input data matrix is small cube -> row -> column, that is, the first matrix of the matrix multiplication operator is loaded as the input data matrix according to the nested loop order of small cube, row, and column of the first matrix of the matrix multiplication operator from the inner loop to the outer loop.
[0159] The nested loop order of cubes, rows, and columns from the inner loop to the outer loop is that the outermost loop is for columns, the middle loop is for rows, and the innermost loop is for cubes. That is, taking the data precision of int16 as an example, as shown in Figure 8, first take the first cube (consisting of elements 0, 1, 2, and 3) in the first row of the first column (the first column here is based on 128-byte cubes), then take the small cube (consisting of elements 5, 6, 7, and 8) in the second row of the first column, then take the small cube (consisting of elements 10, 11, 12, and 13) in the third row of the first column, then take the small cube (consisting of elements 15, 16, 17, and 18) in the fourth row of the first column, then take the small cube (consisting of elements 4) in the first row of the second column, then take the small cube (consisting of element 9) in the second row of the second column, then take the small cube (consisting of element 14) in the third row of the second column, and finally take the small cube (consisting of element 19) in the fourth row of the second column.
[0160] Therefore, originally, the first matrix of the matrix multiplication operator is stored in the memory from low memory address to high memory address in the order of 0, 1, 2, 3, 4, 5, 6, 7...16, 17, 18, 19. And the data retrieval order from the inner loop to the outer loop in the nested loop order of small cubes, rows, and columns is: 0->1->2->3->5->6->7->8->10->11->12->13->15->16->17->18->4->9->14->19.
[0161] In this way, the first matrix of the matrix multiplication operator is loaded using the input data matrix loading module of the unit supporting the convolution operator operation.
[0162] FIG9 is a schematic diagram showing the order of fetching the second matrix and memory mapping of the matrix multiplication operator according to an embodiment of the present disclosure.
[0163] Using the weight matrix loading module of the unit supporting the convolution operator operation to load the second matrix 426 of the matrix multiplication operator includes: aligning the starting address of each column of the second matrix of the matrix multiplication operator according to a first predetermined size, and the first predetermined size is associated with the structure of the multiplication-accumulation unit supporting the convolution operator operation; dividing all columns of the second matrix of the matrix multiplication operator into multiple extraction groups, wherein each extraction group includes a third predetermined number of columns; dividing the data of each column of the second matrix of the matrix multiplication operator into small cubes of a second predetermined size, wherein the second predetermined size is a predetermined multiple of the first predetermined size; and loading the second matrix of the matrix multiplication operator according to the nested loop order from inner loop to outer loop of the small cubes of the second matrix of the matrix multiplication operator, the columns of one extraction group, the rows, and the columns of all extraction groups.
[0164] Here, since the hardware interface used for loading the weight matrix is consistent with the hardware interface used for loading the data matrix, the first predetermined size is also 32 bytes. This is because the structure of the multiplication and accumulation unit enables each multiplication and accumulation operation to process 32 bytes of data. Therefore, the first predetermined size is associated with the structure of the multiplication and accumulation unit that supports the convolution operator operation. The weight matrix loading module of CDMA supports column-major order matrices, requiring the starting address and row parameters of the second matrix to be 32-byte aligned, that is, to ensure that the starting address of each column is 32-byte aligned. The weight matrix can be processed by the upstream module into a format that meets the above requirements. The order of weight matrix retrieval, memory mapping, and retrieval requirements of different precisions are shown in Figure 9.
[0165] All columns of the second matrix (corresponding to kernel parameters) are divided into extraction groups. For the int8 data format, each group consists of 32 columns (i.e., the third predetermined number), and for other precision int16 / fp16, each group consists of 16 columns (i.e., the third predetermined number). The last group may contain fewer columns; each row of the second matrix (corresponding to channel parameters, a total of 4 channels) is divided into small cubes. The size of the int8 small cube is 64 bytes (i.e., the second predetermined size), and the size of the small cube of other precision int16 / fp16 / fp32 is 128 bytes (i.e., the second predetermined size). If the row parameters of the original weight matrix before formatting are not 32-byte aligned, the CDMA module will align the last small cube with 32 bytes and append 0 to store it in the buffer.
[0166] Note that, unlike FIG8 , in order to simplify the description, 0, 1, 2, 3, 4, ... 31 shown in FIG9 are small cubes after division, rather than the elements themselves shown in FIG8 .
[0167] The order of extracting the weight matrix is cube -> column (one extracted group) -> row -> column (all extracted groups). There is no alignment requirement between groups. For example, using the data precision of int16, CDMA appends zeros after the last group to align to 128 bytes.
[0168] The nested loop order from inner loop to outer loop of the small cube, the columns of a removed group, the rows, and the columns of all removed groups means that the outermost loop is for the columns of all removed groups, the inner loop is for the rows, the inner loop is for the columns in a removed group, and the innermost loop is for the small cube.
[0169] As shown in Figure 9, taking the data precision of int16 as an example, one retrieval group has 16 columns (Figure 9 shows the case of exactly one retrieval group. If there are other columns, the retrieval groups are divided into 16 columns as one retrieval group). Each row of the second matrix is divided into small cubes of 128 bytes. Then, the first small cube of the first row of the second matrix (equivalent to the first column in units of small cubes) is 0, the second small cube of the first row of the second matrix (equivalent to the second column in units of small cubes) is 2, the third small cube of the first row of the second matrix is 4, the fourth small cube of the first row of the second matrix is 6,... The first small cube of the second row of the second matrix is 1, the second small cube of the second row of the second matrix is 3, and so on. The 16th small cube of the second row of the second matrix is 31.
[0170] Then, the nested loop sequence from the inner loop to the outer loop, where the extraction order is small cube -> column (one extraction group) -> row -> column (all extraction groups), is: 0 -> 2 -> 4 -> 6 -> 8 -> 10 -> 12 -> 14 ... -> 30 -> 1 -> 3 -> 5 -> 7 ... -> 25 -> 27 -> 29 -> 31. If there is a second extraction group (not shown), the above nested loop sequence is continued for the second extraction group.
[0171] In this way, the second matrix of the matrix multiplication operator is loaded using the data weight matrix loading module of the unit that supports the convolution operator operation.
[0172] In this way, the deep learning accelerator DLA hardware that supports the convolution operator can directly extract the elements of the two matrices of the matrix multiplication operator stored in the memory and load them as the input data cube and weight cube of the convolution operator, which can save hardware and software overhead and improve computing performance.
[0173] FIG10 is a schematic diagram showing a storage order and memory mapping of a result matrix of a matrix multiplication operator according to an embodiment of the present disclosure.
[0174] During a convolution calculation process of a deep learning accelerator DLA hardware supporting a convolution operator, result data of a result matrix of a matrix multiplication operator is a plurality of atomic cubes generated with a first predetermined size as a granularity, wherein the first predetermined size is associated with a structure of a multiplication-accumulation unit supporting the convolution operator operation, wherein the result matrix storage module of the unit supporting the convolution operator operation is used to store the result matrix of the matrix multiplication operator, including: storing the result matrix of the matrix multiplication operator in a nested loop order from an inner loop to an outer loop of atomic cubes, rows, and columns of the result matrix of the matrix multiplication operator.
[0175] The WDMA result matrix storage module supports storing the result matrix of matrix multiplication in memory in row-major order. The result matrix generation sequence and memory mapping are shown in Figure 10. The arithmetic unit generates result data at the atomic cube granularity. The atomic cube size for fp32 data precision is 64 bytes (i.e., the first predetermined size), while the atomic cube size for other precisions, such as int16, is 32 bytes. If the column parameter is not aligned with the atomic cube size, the arithmetic unit appends zeros to align it with the atomic cube size. The result matrix generation sequence is atomic cube -> row -> column.
[0176] The nested loop order for atomic cubes, rows, and columns, from inner loop to outer loop, means the outermost loop is the column, the innermost loop is the row, and the innermost loop is the atomic cube. As shown in Figure 10, unlike Figure 8, the numbers 0, 1, 2, 3, etc. represent individual atomic cubes, not the elements themselves. Therefore, the result generation sequence is atomic cube 0 in the first row of the first column, followed by atomic cube 5 in the second row of the first column, atomic cube 10 in the third row of the first column, atomic cube 15 in the fourth row of the first column, atomic cube 1 in the first row of the second column, atomic cube 6 in the second row of the second column, ... atomic cube 4 in the first row of the fifth column, atomic cube 9 in the second row of the fifth column, atomic cube 14 in the third row of the fifth column, and atomic cube 19 in the fourth row of the fifth column. In other words, the result generation order is 0 -> 5 -> 10 -> 15 -> 1 -> 6 -> 11 -> 16 ... -> 4 -> 9 -> 14 -> 19.
[0177] In this way, the result matrix is stored using the deep learning accelerator DLA hardware that supports the convolution operator, which can save hardware and software overhead and improve computing performance.
[0178] In summary, the deep learning accelerator DLA hardware that supports the convolution operator is used to directly extract the elements of the two matrices of the matrix multiplication operator stored in the memory and load them as the input data cube and weight cube of the convolution operator and store the result matrix, thereby saving hardware and software overhead and improving computing performance.
[0179] FIG11 shows a block diagram of a system 1100 for performing a matrix multiplication operator using a unit supporting a convolution operator operation according to an embodiment of the present disclosure.
[0180] As shown in Figure 11, a system 1100 for performing a matrix multiplication operator using a unit supporting convolution operator operations includes: a first conversion device 1110, configured to convert the first matrix of the matrix multiplication operator into an input data matrix of the convolution operator; a second conversion device 1120, configured to convert the second matrix of the matrix multiplication operator into a weight matrix of the convolution operator, wherein the first matrix and the second matrix are to be matrix multiplied; a convolution operation device 1130, configured to use the unit supporting convolution operator operations to perform a convolution operation on the converted input data matrix and weight matrix of the convolution operator to obtain the operation result of the matrix multiplication operator.
[0181] In this way, since the matrix multiplication operator has a large number of multiplication-accumulation MAC calculations like the convolution operator, and the multiplication-accumulation of the convolution operator is mainly reflected in the multiplication-accumulation between the input data matrix and the weight matrix of the convolution operator, the first matrix of the matrix multiplication operator is converted into the input data matrix of the convolution operator and the second matrix of the matrix multiplication operator is converted into the weight matrix of the convolution operator. The unit that supports the convolution operator operation can be used to perform convolution operations on the converted input data matrix and weight matrix of the convolution operator to obtain the operation result of the matrix multiplication operator, thereby saving hardware and software overhead and improving operation performance.
[0182] In one embodiment, the first conversion device 1110 is configured to: map the number of rows M of the first matrix of the matrix multiplication operator to one of the width parameter or the height parameter of the input data matrix of the convolution operator, and set the other parameter of the width parameter or the height parameter of the input data matrix of the convolution operator to 1; map the number of columns K of the first matrix of the matrix multiplication operator to the number of channels of the input data matrix of the convolution operator.
[0183] Thus, after setting the parameters in this way, the first matrix of the matrix multiplication operator will be mapped to a two-dimensional matrix of the input data of the convolution operator, with only the width or height dimension and the channel dimension of the input data of the convolution operator.
[0184] In one embodiment, the first conversion device 1110 is further configured to: if the number of rows M of the first matrix of the matrix multiplication operator is mapped to the height parameter of the input data matrix of the convolution operator, then each row of the first matrix of the matrix multiplication operator is mapped to each row of the input data matrix of the convolution operator; if the number of rows M of the first matrix of the matrix multiplication operator is mapped to the width parameter of the input data matrix of the convolution operator, then each row of the first matrix of the matrix multiplication operator is mapped to each column of the input data matrix of the convolution operator; and each column of the first matrix of the matrix multiplication operator is mapped to each channel of the input data matrix of the convolution operator.
[0185] In this way, the first matrix of the matrix multiplication operator is actually changed into an input data matrix of the convolution operator of M×1×K (ie, an M×K two-dimensional matrix).
[0186] In one embodiment, the second conversion device 1120 is configured to: map the number of rows K of the second matrix of the matrix multiplication operator to the number of channels of the weight matrix of the convolution operator, and set the width parameter and height parameter of the weight matrix of the convolution operator to 1; map the number of columns N of the second matrix of the matrix multiplication operator to the number of cores of the weight matrix of the convolution operator.
[0187] That is to say, the two dimensions of the second matrix of the matrix multiplication operator are mapped to the channel dimension and kernel dimension of the weight matrix of the convolution operator respectively, that is, the weight matrix of the convolution operator becomes a two-dimensional matrix, and the width dimension and height dimension of the weight matrix of the convolution operator are removed, because the width or height dimension and channel dimension of the input data of the convolution operator are multiplied and accumulated with the channel dimension and kernel dimension of the weight operator, that is, the multiplication and accumulation of the convolution operator can be used to calculate the multiplication and accumulation in the matrix multiplication to obtain the result of the matrix multiplication.
[0188] In one embodiment, the second conversion device 1120 is further configured to: map each row of the second matrix of the matrix multiplication operator to each channel of the weight matrix of the convolution operator; and map each column of the second matrix of the matrix multiplication operator to each kernel of the weight matrix of the convolution operator.
[0189] In this way, the first matrix of the matrix multiplication operator becomes the input data matrix of the convolution operator, which is M×1×K (i.e., an M×K two-dimensional matrix), and the second matrix of the matrix multiplication operator becomes the weight matrix of the convolution operator, which is 1×1×K×N (i.e., a K×N two-dimensional matrix). Then, the output matrix after convolution is M×1×N (i.e., an M×N two-dimensional matrix), which is the calculation result of the matrix multiplication operator. In this way, the unit of the convolution operator can be applied to the first and second matrices of the matrix multiplication operator to obtain the result of the matrix multiplication operator through the convolution process.
[0190] In one embodiment, the first conversion device 1110 further includes: an input data matrix loading module (not shown) of a unit supporting convolution operator operation, configured to load the first matrix of the matrix multiplication operator.
[0191] The second conversion device 1120 further includes: a weight matrix loading module (not shown) of a unit supporting convolution operator operation, configured to load the second matrix of the matrix multiplication operator.
[0192] The convolution operation device 1130 also includes: a result matrix storage module (not shown) of a unit supporting convolution operator operation, which is configured to store the result matrix of the matrix multiplication operator.
[0193] In one embodiment, the input data matrix loading module is configured to: align the starting address of each row of the first matrix of the matrix multiplication operator to a first predetermined size, the first predetermined size being associated with the structure of the multiplication-accumulation unit supporting the convolution operator operation; divide the data of each row of the first matrix of the matrix multiplication operator into small cubes of a second predetermined size, wherein the second predetermined size is a predetermined multiple of the first predetermined size; and load the first matrix of the matrix multiplication operator in a nested loop order of small cubes, rows, and columns of the first matrix of the matrix multiplication operator from an inner loop to an outer loop.
[0194] In this way, the first matrix of the matrix multiplication operator is loaded using the input data matrix loading module of the unit supporting the convolution operator operation.
[0195] In one embodiment, the weight matrix loading module is configured to: align the starting address of each column of the second matrix of the matrix multiplication operator to a first predetermined size, where the first predetermined size is associated with the structure of the multiplication-accumulation unit supporting the convolution operator operation; divide all columns of the second matrix of the matrix multiplication operator into multiple take-out groups, where each take-out group includes a third predetermined number of columns; divide the data of each column of the second matrix of the matrix multiplication operator into small cubes of a second predetermined size, where the second predetermined size is a predetermined multiple of the first predetermined size; and load the second matrix of the matrix multiplication operator in a nested loop order from inner loop to outer loop of small cubes of the second matrix of the matrix multiplication operator, columns of one take-out group, rows, and columns of all take-out groups.
[0196] In this way, the second matrix of the matrix multiplication operator is loaded using the data weight matrix loading module of the unit that supports the convolution operator operation.
[0197] In this way, the deep learning accelerator DLA hardware that supports the convolution operator can directly extract the elements of the two matrices of the matrix multiplication operator stored in the memory and load them as the input data cube and weight cube of the convolution operator, which can save hardware and software overhead and improve computing performance.
[0198] In one embodiment, the result data of the result matrix of the matrix multiplication operator is a plurality of atomic cubes generated with a first predetermined size as a granularity, wherein the first predetermined size is associated with the structure of the multiplication-accumulation unit supporting the convolution operator operation, wherein the result matrix storage module is configured to: store the result matrix of the matrix multiplication operator in a nested loop order of atomic cubes, rows, and columns from an inner loop to an outer loop of the result matrix of the matrix multiplication operator.
[0199] In this way, the result matrix is stored using the deep learning accelerator DLA hardware that supports the convolution operator, which can save hardware and software overhead and improve computing performance.
[0200] In summary, the deep learning accelerator DLA hardware that supports the convolution operator is used to directly extract the elements of the two matrices of the matrix multiplication operator stored in the memory and load them as the input data cube and weight cube of the convolution operator and store the result matrix, thereby saving hardware and software overhead and improving computing performance.
[0201] FIG12 illustrates a block diagram of an exemplary electronic device suitable for implementing embodiments of the present disclosure.
[0202] The electronic device may include a processor (H1); a storage medium (H2) coupled to the processor (H1) and storing computer-executable instructions therein for performing the steps of various methods of the embodiments of the present disclosure when executed by the processor.
[0203] The processor (H1) may include, but is not limited to, one or more processors or microprocessors, etc.
[0204] The storage medium (H2) may include, but is not limited to, for example, random access memory (RAM), read-only memory (ROM), flash memory, EPROM memory, EEPROM memory, registers, computer storage media (such as hard disk, floppy disk, solid-state drive, removable disk, CD-ROM, DVD-ROM, Blu-ray disc, etc.).
[0205] In addition, the electronic device may also include (but not limited to) a data bus (H3), an input / output (I / O) bus (H4), a display (H5) and input / output devices (H6) (for example, a keyboard, a mouse, a speaker, etc.).
[0206] The processor (H1) can communicate with external devices (H5, H6, etc.) through an I / O bus (H4) via a wired or wireless network (not shown).
[0207] The storage medium (H2) may also store at least one computer-executable instruction for executing various functions and / or steps of methods in the embodiments described in the present technology when the processor (H1) executes the instruction.
[0208] In one embodiment, the at least one computer executable instruction may also be compiled into or constitute a software product, wherein one or more computer executable instructions are executed by a processor to perform the various functions and / or method steps in the embodiments described in the present technology.
[0209] FIG13 shows a schematic diagram of a non-transitory computer-readable storage medium according to an embodiment of the present disclosure.
[0210] As shown in Figure 13, computer-readable storage medium 1320 stores instructions, such as computer-readable instructions 1310. When computer-readable instructions 1310 are executed by a processor, the various methods described above can be executed. Computer-readable storage media include, but are not limited to, volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and / or cache memory. Non-volatile memory may include, for example, read-only memory (ROM), a hard disk, flash memory, etc. For example, computer-readable storage medium 1320 can be connected to a computing device such as a computer, and then, when the computing device executes the computer-readable instructions 1310 stored on computer-readable storage medium 1320, the various methods described above can be performed.
[0211] Of course, the above-mentioned specific embodiments are merely examples and not limitations, and those skilled in the art can, based on the concept of the present disclosure, merge and combine some steps and devices from the various embodiments described separately above to achieve the effects of the present disclosure. Such merged and combined embodiments are also included in the present disclosure, and such merges and combinations are not described one by one here.
[0212] Note that the advantages, strengths, and effects mentioned in this disclosure are merely examples and not limitations, and should not be construed as necessarily possessed by each embodiment of this disclosure. Furthermore, the specific details disclosed above are provided for illustrative purposes and to facilitate understanding, not limitations, and the aforementioned details do not necessarily limit this disclosure to the use of these specific details.
[0213] The block diagrams of the devices, devices, equipment, and systems involved in this disclosure are merely illustrative examples and are not intended to require or imply that they must be connected, arranged, or configured in the manner shown in the block diagrams. As will be appreciated by those skilled in the art, these devices, devices, equipment, and systems can be connected, arranged, or configured in any manner. Words such as "include," "comprise," "have," and the like are open-ended words, meaning "including but not limited to," and can be used interchangeably therewith. The words "or" and "and" used herein refer to the words "and / or" and can be used interchangeably therewith, unless the context clearly indicates otherwise. The word "such as" used herein refers to the phrase "such as but not limited to," and can be used interchangeably therewith.
[0214] The step flow charts and the above method descriptions in this disclosure are merely illustrative examples and are not intended to require or imply that the steps of the various embodiments must be performed in the order given. As will be appreciated by those skilled in the art, the order of the steps in the above embodiments can be performed in any order. Words such as "thereafter," "then," "next," and the like are not intended to limit the order of the steps; these words are only used to guide the reader through the description of these methods. In addition, any reference to an element in the singular, such as using the articles "a," "an," or "the," is not to be construed as limiting the element to the singular.
[0215] In addition, the steps and devices in the various embodiments of this document are not limited to being implemented in a certain embodiment. In fact, according to the concepts of this disclosure, relevant partial steps and partial devices in the various embodiments of this document can be combined to conceive new embodiments, and these new embodiments are also included in the scope of this disclosure.
[0216] Each operation of the method described above may be performed by any suitable means capable of performing the corresponding functions. The means may include various hardware and / or software components and / or modules, including but not limited to hardware circuits, application specific integrated circuits (ASICs) or processors.
[0217] The various illustrated logic blocks, modules, and circuits may be implemented or described using a general-purpose processor, a digital signal processor (DSP), an ASIC, a field programmable gate array signal (FPGA) or other programmable logic device (PLD), discrete gate or transistor logic, discrete hardware components, or any combination thereof designed to perform the functions described herein. A general-purpose processor may be a microprocessor, but as an alternative, the processor may be any commercially available processor, controller, microcontroller, or state machine. A processor may also be implemented as a combination of computing devices, such as a combination of a DSP and a microprocessor, multiple microprocessors, a microprocessor cooperating with a DSP core, or any other such configuration.
[0218] The steps of the method or algorithm described in conjunction with the present disclosure can be directly embedded in hardware, in a software module executed by a processor, or in a combination of the two. The software module can exist in any form of tangible storage medium. Some examples of storage media that can be used include random access memory (RAM), read-only memory (ROM), flash memory, EPROM memory, EEPROM memory, registers, hard disks, removable disks, CD-ROMs, etc. A storage medium can be coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. In an alternative embodiment, the storage medium can be integral to the processor. A software module can be a single instruction or many instructions and can be distributed over several different code segments, between different programs, and across multiple storage media.
[0219] The methods disclosed herein include actions for implementing the described methods. Methods and / or actions may be interchangeable with one another without departing from the scope of the claims. In other words, unless a specific order of actions is specified, the order and / or use of specific actions may be modified without departing from the scope of the claims.
[0220] The above functions can be implemented by hardware, software, firmware or any combination thereof. If implemented in software, the functions can be stored as instructions on a tangible computer-readable medium. The storage medium can be any available tangible medium that can be accessed by a computer. By way of example and not limitation, such computer-readable media can include RAM, ROM, EEPROM, CD-ROM or other optical disk storage, magnetic disk storage or other magnetic storage devices or any other tangible medium that can be used to carry or store desired program codes in the form of instructions or data structures and can be accessed by a computer. As used herein, disk and disc include compact discs (CDs), laser discs, optical discs, digital versatile discs (DVDs), floppy discs and Blu-ray discs, wherein disks usually reproduce data magnetically, while discs reproduce data optically using lasers.
[0221] Therefore, the present disclosure may also include computer program products, wherein the computer program products can perform the methods, steps, and operations presented herein. For example, such computer program products can be computer software packages, computer code instructions, or computer-readable tangible media having computer instructions tangibly stored (and / or encoded) thereon, the instructions being executable by a processor to perform the operations described herein. The computer program product can include packaging materials.
[0222] Software or instructions may also be transmitted via a transmission medium. For example, software may be transmitted from a website, server, or other remote source using a transmission medium such as coaxial cable, fiber optic cable, twisted pair, digital subscriber line (DSL), or wireless technologies such as infrared, radio, or microwave.
[0223] In addition, the modules and / or other appropriate means for carrying out the methods and techniques described herein can be downloaded and / or otherwise obtained by the user terminal and / or base station when appropriate. For example, such a device can be coupled to a server to facilitate the transmission of the means for carrying out the methods described herein. Alternatively, the various methods described herein can be provided via a storage component (e.g., RAM, ROM, a physical storage medium such as a CD or a floppy disk) so that the user terminal and / or base station can obtain the various methods when being coupled to the device or providing a storage component to the device. In addition, any other appropriate technology for providing the methods and techniques described herein to a device can be utilized.
[0224] Other examples and implementations are within the scope and spirit of this disclosure and the appended claims. For example, due to the nature of software, the functions described above can be implemented using software performed by a processor, hardware, firmware, hardwiring, or any combination of these. Features that implement the functions can also be physically located in various locations, including being distributed so that parts of the functions are implemented at different physical locations. Moreover, as used herein, including as used in the claims, "or" used in a list of items that begin with "at least one" indicates a separate list, so that, for example, a list of "at least one of A, B, or C" means A or B or C, or AB or AC or BC, or ABC (i.e., A and B and C). In addition, the wording "exemplary" does not mean that the example described is preferred or better than other examples.
[0225] Various changes, substitutions, and modifications of the technology described herein may be made without departing from the teachings of the appended claims. Moreover, the scope of the claims of this disclosure is not limited to the specific aspects of the processes, machines, manufactures, compositions of things, means, methods, and actions described above. Currently existing or later developed processes, machines, manufactures, compositions of things, means, methods, or actions that perform substantially the same function or achieve substantially the same results as the corresponding aspects described herein may be utilized. Accordingly, the appended claims include within their scope such processes, machines, manufactures, compositions of things, means, methods, or actions.
[0226] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the aspects shown herein, but rather to be accorded the widest scope consistent with the principles and novel features disclosed herein.
[0227] The above description has been provided for the purpose of illustration and description. In addition, this description is not intended to limit the embodiments of the present disclosure to the forms disclosed herein. Although a number of example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations thereof.
Claims
1. A method for performing a matrix multiplication operator using a unit supporting a convolution operator operation, comprising: Convert the first matrix of the matrix multiplication operator to the input data matrix of the convolution operator; Converting a second matrix of a matrix multiplication operator into a weight matrix of a convolution operator, wherein the first matrix and the second matrix are to be matrix multiplied; The unit supporting the convolution operator operation is used to perform a convolution operation on the converted input data matrix and the weight matrix of the convolution operator to obtain the operation result of the matrix multiplication operator.
2. The method according to claim 1, wherein: The step of converting the first matrix of the matrix multiplication operator into an input data matrix of the convolution operator comprises: Mapping the number of rows M of the first matrix of the matrix multiplication operator to one of a width parameter or a height parameter of the input data matrix of the convolution operator, and setting the other of the width parameter or the height parameter of the input data matrix of the convolution operator to 1; The number of columns K of the first matrix of the matrix multiplication operator is mapped to the number of channels of the input data matrix of the convolution operator, where M and K are positive integers.
3. The method according to claim 2, wherein: The step of converting the first matrix of the matrix multiplication operator into an input data matrix of the convolution operator further comprises: If the number of rows M of the first matrix of the matrix multiplication operator is mapped to the height parameter of the input data matrix of the convolution operator, then each row of the first matrix of the matrix multiplication operator is mapped to each row of the input data matrix of the convolution operator; if the number of rows M of the first matrix of the matrix multiplication operator is mapped to the width parameter of the input data matrix of the convolution operator, then each row of the first matrix of the matrix multiplication operator is mapped to each column of the input data matrix of the convolution operator; Each column of the first matrix of the matrix multiplication operator is mapped to each channel of the input data matrix of the convolution operator.
4. The method according to claim 3, wherein: The step of converting the second matrix of the matrix multiplication operator into a weight matrix of the convolution operator comprises: The number of rows K of the second matrix of the matrix multiplication operator is mapped to the number of channels of the weight matrix of the convolution operator, and the width parameter and the height parameter of the weight matrix of the convolution operator are both set to 1; The number of columns N of the second matrix of the matrix multiplication operator is mapped to the number of cores of the weight matrix of the convolution operator, where N is a positive integer.
5. The method according to claim 4, wherein: The step of converting the second matrix of the matrix multiplication operator into a weight matrix of the convolution operator further comprises: Map each row of the second matrix of the matrix multiplication operator to each channel of the weight matrix of the convolution operator; Each column of the second matrix of the matrix multiplication operator is mapped to each kernel of the weight matrix of the convolution operator.
6. The method according to claim 5, in, The step of converting the first matrix of the matrix multiplication operator into an input data matrix of the convolution operator further comprises: Using the input data matrix loading module of the unit supporting the convolution operator operation to load the first matrix of the matrix multiplication operator; Wherein, converting the second matrix of the matrix multiplication operator into the weight matrix of the convolution operator also includes: Using a weight matrix loading module of a unit supporting convolution operator operation to load a second matrix of the matrix multiplication operator; Wherein, the using a unit supporting convolution operator operation to perform convolution operation on the converted input data matrix and weight matrix of the convolution operator to obtain the operation result of the matrix multiplication operator also includes: The result matrix storage module of the unit supporting the convolution operator operation is used to store the result matrix of the matrix multiplication operator.
7. The method according to claim 6, wherein: The step of using the input data matrix loading module of the unit supporting the convolution operator operation to load the first matrix of the matrix multiplication operator comprises: Aligning the start address of each row of the first matrix of the matrix multiplication operator to a first predetermined size, wherein the first predetermined size is associated with the structure of a multiply-accumulate unit supporting convolution operator operations; Dividing the data of each row of the first matrix of the matrix multiplication operator into small cubes of a second predetermined size, wherein the second predetermined size is a predetermined multiple of the first predetermined size; The first matrix of the matrix multiplication operator is loaded in a nested loop order of small cubes, rows, and columns of the first matrix of the matrix multiplication operator from an inner loop to an outer loop.
8. The method according to claim 6, wherein: The method of using a weight matrix loading module of a unit supporting convolution operator operation to load the second matrix of the matrix multiplication operator includes: Aligning the start address of each column of the second matrix of the matrix multiplication operator to a first predetermined size, wherein the first predetermined size is associated with the structure of a multiply-accumulate unit supporting convolution operator operations; dividing all columns of the second matrix of the matrix multiplication operator into a plurality of fetch groups, wherein each fetch group includes a third predetermined number of columns; Dividing the data of each column of the second matrix of the matrix multiplication operator into small cubes of a second predetermined size, wherein the second predetermined size is a predetermined multiple of the first predetermined size; The second matrix of the matrix multiplication operator is loaded in a nested loop order from inner loop to outer loop of a small cube of the second matrix of the matrix multiplication operator, columns of one extracted group, rows, and columns of all extracted groups.
9. The method according to claim 6, wherein: The result data of the result matrix of the matrix multiplication operator is a plurality of atomic cubes generated with a first predetermined size as a granularity, wherein the first predetermined size is associated with the structure of the multiplication-accumulation unit supporting the convolution operator operation, wherein the result matrix storage module of the unit supporting the convolution operator operation is used to store the result matrix of the matrix multiplication operator, comprising: The result matrix of the matrix multiplication operator is stored in a nested loop order of atomic cubes, rows, and columns of the result matrix of the matrix multiplication operator from inner loop to outer loop.
10. A system for performing a matrix multiplication operator using a unit supporting convolution operator operations, comprising: A first conversion device configured to convert a first matrix of a matrix multiplication operator into an input data matrix of a convolution operator; A second conversion device is configured to convert a second matrix of the matrix multiplication operator into a weight matrix of the convolution operator, wherein the first matrix and the second matrix are to be matrix multiplied; and The convolution operation device is configured to use a unit supporting the convolution operator operation to perform a convolution operation on the converted input data matrix and weight matrix of the convolution operator to obtain the operation result of the matrix multiplication operator.
11. The system according to claim 10, wherein: The first conversion device is configured to: Mapping the number of rows M of the first matrix of the matrix multiplication operator to one of a width parameter or a height parameter of the input data matrix of the convolution operator, and setting the other of the width parameter or the height parameter of the input data matrix of the convolution operator to 1; The number of columns K of the first matrix of the matrix multiplication operator is mapped to the number of channels of the input data matrix of the convolution operator, where M and K are positive integers.
12. The system according to claim 11, wherein: The first conversion device is further configured to: If the number of rows M of the first matrix of the matrix multiplication operator is mapped to the height parameter of the input data matrix of the convolution operator, then each row of the first matrix of the matrix multiplication operator is mapped to each row of the input data matrix of the convolution operator; if the number of rows M of the first matrix of the matrix multiplication operator is mapped to the width parameter of the input data matrix of the convolution operator, then each row of the first matrix of the matrix multiplication operator is mapped to each column of the input data matrix of the convolution operator; Each column of the first matrix of the matrix multiplication operator is mapped to each channel of the input data matrix of the convolution operator.
13. The system according to claim 12, wherein: The second conversion device is configured to: The number of rows K of the second matrix of the matrix multiplication operator is mapped to the number of channels of the weight matrix of the convolution operator, and the width parameter and the height parameter of the weight matrix of the convolution operator are both set to 1; The number of columns N of the second matrix of the matrix multiplication operator is mapped to the number of cores of the weight matrix of the convolution operator, where N is a positive integer.
14. The system according to claim 13, wherein: The second conversion device is further configured to: Map each row of the second matrix of the matrix multiplication operator to each channel of the weight matrix of the convolution operator; Each column of the second matrix of the matrix multiplication operator is mapped to each kernel of the weight matrix of the convolution operator.
15. The system according to claim 14, in, The first conversion device also includes: An input data matrix loading module of a unit supporting convolution operator operation, configured to load a first matrix of the matrix multiplication operator; Wherein, the second conversion device further includes: A weight matrix loading module of a unit supporting convolution operator operation, configured to load a second matrix of the matrix multiplication operator; Wherein, the convolution operation device also includes: The result matrix storage module of the unit supporting the convolution operator operation is configured to store the result matrix of the matrix multiplication operator.
16. The system of claim 15, wherein: The input data matrix loading module is configured as follows: Aligning the start address of each row of the first matrix of the matrix multiplication operator to a first predetermined size, wherein the first predetermined size is associated with the structure of a multiply-accumulate unit supporting convolution operator operations; Dividing the data of each row of the first matrix of the matrix multiplication operator into small cubes of a second predetermined size, wherein the second predetermined size is a predetermined multiple of the first predetermined size; The first matrix of the matrix multiplication operator is loaded in a nested loop order of small cubes, rows, and columns of the first matrix of the matrix multiplication operator from an inner loop to an outer loop.
17. The system of claim 15, wherein: The weight matrix loading module is configured as follows: Aligning the start address of each column of the second matrix of the matrix multiplication operator to a first predetermined size, wherein the first predetermined size is associated with the structure of a multiply-accumulate unit supporting convolution operator operations; dividing all columns of the second matrix of the matrix multiplication operator into a plurality of fetch groups, wherein each fetch group includes a third predetermined number of columns; Dividing the data of each column of the second matrix of the matrix multiplication operator into small cubes of a second predetermined size, wherein the second predetermined size is a predetermined multiple of the first predetermined size; The second matrix of the matrix multiplication operator is loaded in a nested loop order from inner loop to outer loop of a small cube of the second matrix of the matrix multiplication operator, columns of one extracted group, rows, and columns of all extracted groups.
18. The system of claim 15, wherein: The result data of the result matrix of the matrix multiplication operator is a plurality of atomic cubes generated with a first predetermined size as a granularity, wherein the first predetermined size is associated with the structure of the multiplication-accumulation unit supporting the convolution operator operation, wherein the result matrix storage module is configured as follows: The result matrix of the matrix multiplication operator is stored in a nested loop order of atomic cubes, rows, and columns of the result matrix of the matrix multiplication operator from inner loop to outer loop.
19. An electronic device comprising: a memory configured to store instructions; as well as A processor is configured to read instructions in the memory and execute the method according to any one of claims 1 to 9.
20. A non-transitory storage medium having stored thereon instructions, in, When the instructions are read by a processor, the processor is caused to execute the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Matrix operation method and device, computer equipment and storage medium
CN110580324A
Image data processing method and device
CN114283314A
Computing device, method for implementing convolution operation by using computing device and related product
CN115470176A
Programmable matrix multiplication engine
US20230115542A1
