A method for reconstructing architecture in a computing system and a computing system
By switching the architecture mode according to the computing needs in the computing system and using the systolic array to perform convolution operations, the problem of inefficiency caused by data reuse and calculation regularity in convolution calculations is solved, and efficient convolutional neural network calculations are achieved, improving throughput and energy efficiency.
Patent Information
- Application Number
- CN202110616149.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-03
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2041-06-03
AI Technical Summary
It is difficult for existing CPUs to complete convolution calculations with high performance and efficiency. Especially in convolutional neural networks, there is a large amount of data reuse and calculation regularity, resulting in low throughput and energy consumption efficiency, and convolution to matrix calculation Shaping and copying increase bandwidth consumption during the process.
Introduce the reconstruction architecture method into the computing system, switch the architecture mode according to the participation degree of matrix multiplication or convolutional neural network operation in the calculation, select the general graphics processor mode or the convolutional neural network mode, and use the systolic array for data access and operations, supports mixed-precision calculations, and dynamically reorganizes computing resources and bandwidth.
It has significantly improved the throughput rate and energy consumption efficiency of convolutional neural networks, reaching a level no less than that of systolic arrays, while maintaining the flexibility of GPGPU. It is suitable for various application scenarios and supports a variety of mixed-precision neural network calculations.
Smart Images

Figure CN113392959B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computing, and more specifically, to a method for reconstructing architecture in a computing system and a computing system. Background Art
[0002] Deep neural networks (DNNs) are the basis of current artificial intelligence (AI) applications, such as speech recognition, image recognition, video processing, autonomous driving, cancer detection, game confrontation, etc., and in some areas, DNNs have surpassed human accuracy.
[0003] Figure 1 It shows a relatively simple neural network calculation process: the neurons in the input layer pass the received information to the middle layer of the neural network (also called the hidden layer), and the "weight sum" of the hidden layer will eventually be transmitted to the output layer and finally presented to the user. The input or output of a neuron is usually called "activation", and the synapse is called "weight". In the present invention, including the specification and its drawings, activation / weight, activation / weight, input or output / weight will be used later. Those skilled in the art should understand that these terms can be used interchangeably.
[0004] Figure 2 The calculation of each layer is shown:
[0005]
[0006] W ij is the weight, x i is the input activation, y j is the output activation, f(.) is a nonlinear function, and b is the bias.
[0007] A common form of DNN is called a convolutional neural network (CNN), which contains multiple convolutional (CONV) layers. In such a network, each layer produces a high-level abstraction of the input data, called a feature map (fmap or feature map). A typical CNN model is as follows Figure 3 As shown in the figure, there will be 5 to 1000 CONV layers, and 1 to 3 fully connected layers after the CONV layers. The remaining nonlinear layers, normalization layers, pooling layers, etc. are not within the scope of this article because of their extremely low power consumption.
[0008] A 2D convolution input consists of an input feature map (input fmap) and a convolution kernel (filter or weight), and the operation is as follows:
[0009] 1. The input feature map is a H * W matrix, such as a 28x28 image pixel, and the convolution kernel is a R * S matrix, such as a 3x3 kernel. Figure 4 As shown;
[0010] 2. Use the convolution kernel to multiply the corresponding elements of the matrix of the corresponding size in the upper left corner of the input feature map and add them to get the element in the upper left corner of the output feature map. The corresponding multiplication operation is as follows: Figure 5 As shown;
[0011] 3. The sliding convolution kernel continues to multiply the corresponding elements with the corresponding size matrix of the input feature map and obtains the next element of the output feature map, such as Figure 6 shown.
[0012] When the input feature map has multiple channels, a specific example is that the image changes from a black and white image to a color image, so it has three RGB channels, then the convolution operation becomes Figure 7 As shown in the figure, each channel has an independent input feature map and convolution kernel, and different channels are finally added and merged.
[0013] When the input feature map has multiple (for example, N) images and multiple convolution kernels (for example, M), the convolution operation is Figure 8 shown.
[0014] In this way, the final multidimensional convolution operation formula is obtained as follows:
[0015]
[0016] The parameters in the formula are as follows:
[0017] O Output feature map matrix
[0018] I Input feature map matrix
[0019] W convolution kernel matrix
[0020] B Bias Matrix
[0021] N is the batch size of the three-dimensional feature map
[0022] M is the number of three-dimensional convolution kernels / number of output feature map channels
[0023] C Input feature map / Number of convolution kernel channels
[0024] H / W Input feature map plane height / width
[0025] R / S Convolution kernel plane height / width
[0026] E / F Output feature map plane height / width
[0027] U is the step size of the split window
[0028] A typical example is AlexNet, such as Fig. 9 As shown, the corresponding convolution operation parameters are shown below.
[0029] H / WR / SE / FCMU
[0030] CONV1 227 11 55 3 96 4
[0031] CONV2 21 5 27 48 256 1
[0032] CONV3 15 3 13 256 284 1
[0033] CONV4 15 3 13 192 284 1
[0034] CONV5 15 3 13 192 256 1
[0035] Among them, CONV1, CONV2, CONV3, CONV4 and CONV5 represent convolutional layers;
[0036] H / W, R / S, E / F, C, M, and U represent CNN shape parameters.
[0037] It is difficult for existing mainstream CPUs to complete convolution calculations with high performance and efficiency. Compared with general general-purpose computing, the large amount of data reuse and regularity of calculations in convolution calculations have great room for optimization in architecture design and computing optimization, which has given rise to many chips for accelerating convolutional neural networks.
[0038] General-purpose graphics processing unit (GPGPU) accelerators use general matrix multiplication (GEMM) to achieve convolution acceleration. GEMM has been widely used before CNN. Many linear algebra libraries fully combine the data reuse relationship in matrix calculations and the hierarchical design structure of processor cache to fully optimize GEMM multiplication. The matrix multiplication of C = AB + C can be expressed as:
[0039] for i = 1 : m
[0040] for j = 1 : n
[0041] for k = 1 : t
[0042] C (i, j) = A(i,k) * B(k, j) + C(i, j)
[0043] The current mainstream GPGPU will provide special hardware acceleration for matrix multiplication, such as Fig.10 As shown. General matrix multiplication is widely used in convolution operations, and the specific implementation method is as follows Fig.11 As shown. Input matrices M*K and K*N, where M is the number of rows and N is the number of columns, M=H*W, K=R*S*C, N=K. A simple example is Fig.12 As shown in Figure 2. A general GPGPU architecture is shown in Figure 2. Fig.13 shown.
[0044] If the matrix is stored in memory (DDR) and the matrix calculation is performed directly in a three-layer loop, then each cycle needs to access three numbers a, b, and c. In this case, the performance will be limited by the DDR bandwidth. It is a good choice to put the matrix in the on-chip cache, but the capacity of the on-chip cache is often small. The way to solve this contradiction is to divide the large matrix into blocks. In this case, the matrix calculation can be expressed as
[0045] for i = 1 : MR : m / / step MR
[0046] for j = 1 : NR : n / / step NR
[0047] for k = 1 : KC : c / / step KC
[0048] / / block-dot product in cache
[0049] / / Csub_{NR*MR} += Asub_{MR*KC}*B_sub(KC*NR)
[0050] / / opt.mirco kernel
[0051] for ir = 1:MR
[0052] for jr = 1:NR
[0053] for kr = 1: KC
[0054] Csub(ir,jr) += Asub(ir,kr)*Bsub(kr,jr);
[0055] Using this blocking method, assuming that the matrix is stored in DDR, the blocked matrix is stored in the on-chip cache; to complete MR×NR×NC multiplication calculations, only MR×NR+NR×NC+MR×NC data need to be obtained from DDR. Reasonable blocking can reduce the access to DDR.
[0056] For GPGPUs with different storage hierarchies and matrix calculations of different sizes, there are different ways of partitioning to achieve peak performance. This is a simple, efficient and relatively flexible option, and its advantages include:
[0057] 1. Simple. The computing unit can implement the micro kernel of GEMM, which is easy to integrate.
[0058] 2. Flexible, supports all algorithms that can be accelerated by GEMM;
[0059] 3. There are many reference implementations for compiler design and scheduling.
[0060] Convolutional neural networks (CNNs) are widely used in modern AI systems because of their powerful accuracy, but they also bring huge challenges in throughput and energy efficiency. This is because calculations require reading and writing large amounts of data, as well as data movement within and between chips, and the power consumed by these data movements may even exceed the calculations themselves. In CNNs, convolution calculations account for more than 90% of the entire calculation (including reasoning, testing, and training), so for convolution calculations of any size, it becomes crucial to minimize the impact of data movement on throughput and functional performance. Although the above GPU accelerators have optimized matrix calculations very well, they still have the following defects for convolution calculations:
[0061] 1. During the convolution matrix conversion process, the tensor is reshaped and duplicated, which increases bandwidth consumption;
[0062] 2. Time domain execution results in repeated data loading, which is not as energy efficient as space domain execution (e.g. based on systolic array, which will be described in detail below). Summary of the invention
[0063] In view of this, the present invention proposes a method and a computing system for reconstructing the architecture in a computing system, so that it can be applied to convolutional neural network acceleration. Compared with the original GEMM mode, the throughput and energy efficiency are significantly improved, reaching a level not lower than that of the systolic array. But at the same time, the flexibility of GPGPU is maintained, making it flexibly applicable to various application scenarios. The solution of the present invention supports various mixed precision calculations from 8-bit integer to 32-bit floating point, such as FP16, BF16, FP32, etc.
[0064] At the same time, different neural network layers can use different precisions to achieve real-time switching precision. In the specific implementation process, the reconfigurable mode dynamically reorganizes computing resources and bandwidth. According to the precision requirements, the computing resources and bandwidth are calculated at close to full load, efficiently supporting a variety of mixed-precision neural networks.
[0065] According to an embodiment of the present invention, a first aspect of the present invention provides a method for reconstructing architecture in a computing system. The method comprises: selecting an architecture mode according to the degree of participation of matrix multiplication or convolutional neural network operation in the calculation, wherein the architecture mode comprises a general graphics processor mode and a convolutional neural network mode; when the general graphics processor mode is selected, the registers in the computing system are configured to perform data access and operation in a general matrix multiplication manner of the general graphics processor; when the convolutional neural network mode is selected, the registers in the computing system are configured to perform data access and operation in a convolution manner of a systolic array.
[0066] In a preferred implementation, when the selected architecture mode is different from the architecture mode currently adopted by the computing system, the architecture mode is switched.
[0067] In a preferred implementation, after waiting for the previously unexecuted computing tasks to be completed and the cache to be refreshed, the registers in the computing system are reconfigured from the currently used architecture mode to the selected architecture mode; after the mode reconstruction is completed, new computing tasks are accepted.
[0068] In a preferred implementation, the registers in the computing system are configured as a plurality of computing units, and each computing unit is configured to simultaneously perform a plurality of multiplication operations and add the results of the multiplication operations to obtain the calculation result of each computing unit.
[0069] In a preferred implementation, each computing unit is configured to perform a maximum of 8 multiplication operations simultaneously and add the results of the multiplication operations to obtain the calculation result of each computing unit.
[0070] In a preferred implementation, in the general graphics processor mode, the calculation results of each calculation unit are combined or accumulated through instructions.
[0071] In a preferred implementation, in the convolutional neural network mode, a matrix multiplication operation of Y = X *W is completed by a systolic array, where X is an input feature map matrix, W is a weight matrix, and Y is an output feature map matrix: the weight elements in the weight matrix W are fixed in the computing unit; in one direction of the computing unit array, the elements of the input feature map matrix X are propagated sequentially according to the clock cycle; in each computing unit, the element of X propagated to this computing unit is multiplied by the weight element of W fixed in this computing unit, and the partial sum calculation result of the previous cycle propagated from the previous computing unit is accumulated to obtain the partial sum calculation result of the current computing unit in the current clock cycle; in another direction of the computing unit array, the partial sum calculation results of each computing unit are propagated and accumulated according to the clock cycle until the partial sum calculation result propagates out of the computing array, and the elements of the output feature map matrix Y are obtained in sequence.
[0072] In a preferred implementation, in the convolutional neural network mode, a convolution operation is performed by a systolic array: the convolution kernel is expanded into a weight matrix W by cyclic replication in a convolutional circular multiplication manner; the input data is expanded into an input feature map matrix X by cyclic replication corresponding to the weight matrix elements in a convolutional circular multiplication manner; and the matrix multiplication operation of Y = X * W is performed by a systolic array.
[0073] According to an embodiment of the present invention, a second aspect of the present invention provides a computing system, comprising a register. The architecture mode of the register is configured to switch according to the degree of participation of matrix multiplication or convolution operation in the calculation, wherein the architecture mode includes a general graphics processor mode and a convolutional neural network mode; when switching to the general graphics processor mode, the register is configured to access and operate data in a general matrix multiplication manner of the general graphics processor; when switching to the convolutional neural network mode, the register is configured to access and operate data in a convolution manner of a systolic array.
[0074] In a preferred implementation, the register is configured as a plurality of computing units, and each computing unit is configured to simultaneously perform a plurality of multiplication operations and add the results of the multiplication operations to obtain the calculation result of each computing unit.
[0075] In a preferred implementation, each computing unit is configured to perform a maximum of 8 multiplication operations simultaneously and add the results of the multiplication operations to obtain the calculation result of each computing unit.
[0076] In a preferred implementation, in the general graphics processor mode, the register is configured to combine or accumulate the calculation results of each calculation unit through instructions.
[0077] In a preferred implementation, in the convolutional neural network mode, the register is configured to complete the matrix multiplication operation of Y = X * W through a systolic array, where X is the input feature map matrix, W is the weight matrix, and Y is the output feature map matrix: the weight elements in the weight matrix W are fixed in the computing unit; in one direction of the computing unit array, the elements of the input feature map matrix X are propagated sequentially according to the clock cycle; in each computing unit, the element of X propagated to this computing unit is multiplied by the weight element of W fixed in this computing unit, and the partial sum calculation result of the previous cycle propagated from the previous computing unit is accumulated to obtain the partial sum calculation result of the current computing unit in the current clock cycle; in another direction of the computing unit array, the partial sum calculation results of each computing unit are propagated and accumulated according to the clock cycle until the partial sum calculation result is propagated out of the computing array, and the elements of the output feature map matrix Y are obtained in sequence.
[0078] In a preferred implementation, in the convolutional neural network mode, the register is configured to perform a convolution operation through a systolic array: the convolution kernel is expanded into a weight matrix W by circular replication in a convolution manner; the input data is expanded into an input feature map matrix X by circular replication corresponding to the weight matrix elements in a convolution manner; and the matrix multiplication operation of Y = X * W is completed through the systolic array.
[0079] According to an embodiment of the present invention, a third aspect of the present invention provides an apparatus for reconstructing an architecture in a computing system. The apparatus comprises a processor and a memory. A computer program is stored in the memory, and when the computer program is executed by the processor, the processor implements the method provided according to the first aspect of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0080] The present invention includes the accompanying drawings, which should be considered as included in and constituting a part of the specification, and together with the description, illustrate various exemplary embodiments, features, and aspects of the invention and serve to explain the principles of the invention.
[0081] Figure 1 A relatively simple neural network calculation process is shown.
[0082] Figure 2 The calculations for each layer of the neural network are shown.
[0083] Figure 3 A typical CNN model is shown.
[0084] Figure 4 An example of a single-channel two-dimensional convolution operation is shown.
[0085] Figure 5It is shown that the two-dimensional convolution corresponds to a multiplication operation.
[0086] Figure 6 A two-dimensional convolution sliding window operation is shown.
[0087] Figure 7 An example of a multi-channel convolution operation is shown.
[0088] Figure 8 An example of a multi-dimensional convolution operation is shown.
[0089] Fig. 9 An example of a convolution operation in AlexNet is shown.
[0090] Fig.10 The matrix multiplication operation in mainstream GPGPU is shown.
[0091] Fig.11 It shows how the convolution operation is converted into a matrix multiplication operation.
[0092] Fig.12 An example of converting a convolution operation into a matrix multiplication operation is shown.
[0093] Fig.13 The mainstream GPGPU architecture is shown.
[0094] Fig.14 A two-dimensional systolic array architecture is shown.
[0095] Fig.15 The structure of the computing unit (Cell) in the two-dimensional systolic array is shown.
[0096] Fig.16 A comparison of the traditional computing structure and the systolic array structure is shown.
[0097] Fig.17 A TPU systolic array implementation of the Y = X * W matrix multiplication is shown.
[0098] Fig.18 The case of Cycle0 and Cycle1 of a systolic array performing an example matrix multiplication is shown.
[0099] Fig.19 The situation of Cycle2 and Cycle3 of the systolic array performing an example matrix multiplication is shown.
[0100] Fig. 20 Cycle 4 and Cycle 5 of the systolic array performing an example matrix multiplication are shown.
[0101] Fig.21 Cycle 6 and Cycle 7 of the systolic array performing an example matrix multiplication are shown.
[0102] Fig. 22 Cycle 8 and Cycle 9 are shown where the systolic array performs an example matrix multiplication.
[0103] Fig.23 The situation of Cycle 10 and Cycle 11 of the systolic array performing an example matrix multiplication is shown.
[0104] Fig.24 The situation of Cycle 12 and Cycle 13 of the systolic array performing an example matrix multiplication is shown.
[0105] Fig.25 The DOT8 operation in the GPGPU architecture is shown.
[0106] Fig.26 An example of configuration as a GPGPU architecture is shown.
[0107] Fig. 27 An example of how a 5*5 convolution operation is implemented on a GPGPU architecture is shown.
[0108] Fig.28 Shows the connections between computing units in the CNN architecture.
[0109] Fig.29 Shown is the PE array under the CNN architecture.
[0110] Fig.30 An example of convolution operation under the CNN architecture is shown. DETAILED DESCRIPTION
[0111] The technical solution of the present invention is further described in detail below through embodiments and in conjunction with the accompanying drawings, but the present invention is not limited to the following embodiments.
[0112] Various exemplary embodiments, features and aspects of the present invention will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise specified.
[0113] The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.
[0114] In addition, in order to better illustrate the present invention, numerous specific details are provided in the following specific embodiments. It should be understood by those skilled in the art that the present invention can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present invention.
[0115] A method for reconstructing architecture in a computing system will be introduced below according to an embodiment of the present invention.
[0116] The main purpose of the method of the present invention is to be able to select an architecture mode according to the degree of participation of matrix multiplication or convolutional neural network operation in the calculation. In the following text, several examples will be given so that those skilled in the art can understand in what kind of computing target or computing environment, the corresponding architecture mode can be selected. Moreover, those skilled in the art should understand that the selection of the architecture mode can be manually specified or changed, or it can be controlled by a program, or even automatically determined and selected.
[0117] In the example of the present invention, the architecture modes actually only include a general purpose graphics processor mode and a convolutional neural network mode. However, those skilled in the art should understand that under the teachings of the present invention, the number of architecture modes may not be limited to two.
[0118] In an example of the present invention, when the general-purpose graphics processor mode is selected, registers in the computing system are configured to perform data access and calculations in the general-purpose graphics processor (General-Purpose computing on Graphics Processing Units, GPGPU) general matrix multiplication (GEneral Matrix Multiplication, GEMM) manner.
[0119] When the convolutional neural network mode is selected, the registers in the computing system are configured to access and calculate data in a systolic array matrix multiplication manner.
[0120] Those skilled in the art should understand that the convolution or convolution operation mentioned in the present invention actually has the same or similar meaning as the correlation operation or the sliding window filtering operation. In the field of artificial neural networks, those skilled in the art are accustomed to calling such an operation a convolution operation, and the specific operation method can refer to the more detailed examples below.
[0121] The selection of the architecture mode may occur while the computing system is running. Therefore, when the selected architecture mode is different from the architecture mode currently adopted by the computing system, the architecture mode needs to be switched.
[0122] Preferably, it is necessary to wait for the computing tasks that have not been executed by the computing system to be completed and the cache to be refreshed before reconfiguring the registers in the computing system from the currently adopted architecture mode to the selected architecture mode. After the mode reconstruction is completed, new computing tasks are accepted.
[0123] It should be understood by those skilled in the art that, as further described below, in the operation mode of the systolic array, the first arithmetic logic unit (ALU) fetches data, which is passed to the next ALU after processing, while the second data enters the first ALU, and so on. After the first data reaches the last ALU, a result can be obtained in each cycle. In this case, each computing unit includes both an operation unit ALU and a register to temporarily store data in the order of clock cycles, partially sum, and output part or all of the results of the matrix multiplication or convolution operation in a certain clock cycle. Therefore, each computing unit (PE or PE Cell) of the systolic array can be regarded as an operation unit with a register, or a register containing an operation unit.
[0124] According to an embodiment of the present invention, registers in a computing system are configured as multiple PEs, and each PE is configured to simultaneously complete one or more multiplication operations and add the results of the multiplication operations to obtain the calculation result of each computing unit.
[0125] In a preferred implementation, each PE is configured to perform a maximum of 8 multiplication operations simultaneously and add the results of the multiplication operations to obtain the calculation result of each calculation unit. For example, see the DOT8 calculation unit exemplified below.
[0126] In the general graphics processor mode, there is no connection between the various computing units, and there is no need to transfer or propagate the calculation results of one computing unit to adjacent or other computing units. In fact, the various calculation results can be combined or accumulated through instructions.
[0127] The following first introduces the operation method of the systolic array introduced in the present invention.
[0128] Systolic Array
[0129] In addition to GPU, another way to implement matrix multiplication is called systolic array accelerator, a typical example is Google TPU. Its computing core is a 256x256 two-dimensional systolic array, such as Fig.14 As shown, each computing unit (Cell) is as follows Fig.15 The systolic array allows data to flow in the array of computing units, reducing the number of memory accesses, making the structure more regular, the wiring more uniform, and increasing the frequency. Fig.16 A comparison of the traditional computing structure and the systolic array structure is shown. Fig.16On the left is the traditional computing architecture, which can be used for various forms of computing, such as CPU and GPU. Registers are used to store data. A program tells the ALU (arithmetic logic unit) to take data from the register, perform an operation (such as addition, multiplication or logical operation), and then write the result back to the specified register. In the case of a systolic array, the first ALU takes the data, which is passed to the next ALU after processing, while the second data enters the first ALU, and so on. After the first data reaches the last ALU, a result can be obtained in each cycle. In this way, the systolic array can balance IO reading and writing with calculations, improve throughput while consuming less memory bandwidth, and effectively solve the problem of data access speed being much faster than data processing speed. The systolic array itself is just a structure with data flow. Different data will flow and flow in different directions depending on different applications.
[0130] A TPU systolic array implementation of a Y = X * W matrix multiplication is as follows Fig.17 shown.
[0131] exist Fig.17 In the example, the 5-row 5-column input feature map matrix is taken as X, and the 5-row 5-column weight matrix is taken as W. After matrix multiplication, the 5-row 5-column output feature map matrix Y is obtained. As mentioned above, the operation rules of matrix multiplication are:
[0132] Y00 = X00 * W00 + X01 * W10 + X02 * W20 + X03 * W30 + X04 * X40
[0133] Y01 = X00 * W01 + X01 * W11 + X02 * W21 + X03 * W31 + X04 * X41
[0134] …
[0135] Y44 = X40 * W04 + X41 * W14 + X42 * W24 + X43 * W34 + X44 * X44
[0136] The operation process is as follows:
[0137] 1. As Fig.17 As shown below, the weight (weight) is fixed in the computational unit (PE Cell), and the activation element (activation) of the input feature map matrix is propagated vertically and the partial sum (psum) is propagated horizontally.
[0138] 2. If Fig.18As shown, in the clock cycle Cycle0, X00 is input to the first row and first column of the array, and multiplied by W00 to obtain Y00.
[0139] 3. Still Fig.18 As shown, in Cycle1, input X10 to the first row and first column of the array, propagate the partial sum Y00 (=X00*W00) to the first row and second column (W10). Input X01 to the first row and second column of the array, multiply it with W10 and add the propagated partial sum Y00 to get the new Y00 (=X00*W00+X01*W10), and propagate X00 to the second row and first column (W01).
[0140] 4. Such as Fig.19 As shown, in the next clock cycles Cycle2 and Cycle3, X is continuously input, X is propagated vertically, and Y is propagated horizontally.
[0141] 5. Such as Fig. 20 As shown, after Cycle4, in Cycle5, Y00 propagates out of the array, and now we get Y00 = X00 *W00 + X01 * W10 + X02 * W20 + X03 * W30 + X04 * X40.
[0142] 6. Such as Fig.21 As shown, Y10 and Y01 are obtained in Cycle 6, and Y20, Y11 and Y02 are obtained in Cycle 7.
[0143] 7. Such as Fig. 22 As shown, Y30, Y21, Y12, and Y03 are obtained in Cycle 8, and Y40, Y31, Y22, Y13, and Y04 are obtained in Cycle 9.
[0144] 8. As Fig.23 As shown, Y41, Y32, Y23 and Y14 are obtained in Cycle 10, and Y42, Y33 and Y24 are obtained in Cycle 11.
[0145] 9. As Fig.24 As shown, Y43 and Y34 are obtained in Cycle 12, and Y44 is obtained in Cycle 13. So far, all results have been obtained.
[0146] Those skilled in the art will appreciate that the horizontal and vertical directions described above are actually interchangeable. Therefore, they can be referred to as being in one direction and another direction of the computing unit array (systolic array).
[0147] More generally, the matrix multiplication operation Y = X * W is completed by the systolic array, where X is the input feature map matrix, W is the weight matrix, and Y is the output feature map matrix, which can include the following steps:
[0148] 1. Fix the weight elements in the weight matrix W in the computational unit, such as Fig.17 as shown in .
[0149] 2. In one direction of the computing unit array, propagate each element of the input feature map matrix X in sequence according to the clock cycle. Figure 17-24 As shown in , the elements of X are propagated vertically. Specifically, the columns of X (e.g., X00, X10, X20, X30, X40) are aligned with the rows of W (e.g., W00, W01, W02, W03, W04) (vertically in the figure), and propagate sequentially according to the clock cycle, so that the multiplication operation of each two corresponding elements is completed in each clock cycle. On the other hand, the columns of X are staggered by one clock cycle before starting to propagate into the array. For example, the second column of X (X01, X11, X21, X31, X41) is one clock cycle later than the first column of X (X00, X10, X20, X30, X40), the third column of X is one clock cycle later than the second column, and so on, and finally the fifth column of X. Therefore, the first element to enter the array is X00, the first row and first column of X, and the last element to enter the array is X44, the fifth row and fifth column of X.
[0150] 3. In each computing unit, multiply the elements of X propagated to this computing unit with the weight elements of W fixed in this computing unit, and accumulate the partial sum calculation results of the previous cycle propagated from the previous computing unit to obtain the partial sum calculation results of the current computing unit in the current clock cycle. For example, in Cycle1, input X01 to the first row and second column of the array, multiply it with W10 and add the propagated partial sum Y00 to obtain the new Y00 (= X00 * W00 + X01 * W10).
[0151] 4. In the other direction of the computing unit array, propagate and accumulate the partial and calculation results of each computing unit according to the clock cycle. Figure 18-24 Specifically, in each column of W (horizontally in the figure), each computing unit propagates the partial sum horizontally. For example, Y00 propagates from the computing unit where W00 is located to the right through the computing units where W10, W20, W30, and W40 are located, accumulating the multiplication results of each computing unit while propagating, that is, Y00 = X00 * W00 + X01 * W10 + X02 * W20 + X03 * W30 + X04 * X40.
[0152] 5. Until the partial and calculation results are propagated out of the calculation array, the elements of the output feature map matrix Y are obtained in sequence. After Cycle5 obtains the final result of Y00, several elements of Y in the subsequent clock cycles obtain the final result until Cycle13 obtains Y44, and all the results are obtained.
[0153] Although systolic arrays can reduce data duplication and significantly improve the performance of convolution operations compared to GPUs, there are certain problems in completely replacing existing accelerators on GPUs with systolic arrays:
[0154] 1. It loses flexibility. When the neural network model is constantly updated and iterated, it cannot flexibly support all GEMM acceleration algorithms, cannot support general operations other than matrix operations, and the narrow application scenarios lead to a reduction in market demand.
[0155] 2. There are still some limitations, that is, it only uses the accumulation characteristics of the spatial domain, but completely abandons the time domain accumulation characteristics of GPGPU, so that convolution still cannot avoid matrix operations. Once the convolution is converted to a matrix, a large amount of repeated data will be added, making it impossible to further reduce the movement of input / output data to optimize energy efficiency.
[0156] General-Purpose Graphics Processing Unit (GPGPU) Architecture
[0157] The core PE of matrix multiplication (GEMM) implements the function of DOT8: Y00 = X00 * W00 + X01 * W10 + X02 * W20 + X03 * W30 + X04 * W40 + X05 * W50 + X06 * W60 + X07 * W70, such as Fig.25 shown.
[0158] Tensor cores in GPGPU will instantiate a large number of PEs (i.e. DOT8) to complete GEMM, such as Fig.26 There is no connection between PEs, and data accumulation needs to be completed through the execution of instructions in the encoding, that is, accumulation in the time domain. Fig.26 The range of several rows on the left is called a Computing Work Group (CWG). A CWG can complete operations at the granularity of a work group in OpenCL. A 5*5 convolution operation can be performed as follows Fig. 27 The method shown is converted into GEMM and distributed to each CWG for execution.
[0159] Convolutional Neural Network (CNN) Architecture
[0160] In the CNN architecture, each PE (or PE Cell) will be physically connected to the surrounding PE (or PE Cell) to transfer Activation and Psum, such as Fig.28 Specifically, Fig.28 In the example, Psum propagates and accumulates vertically from top to bottom, while Activation propagates horizontally from left to right.
[0161] Under the CNN architecture, a huge PE array will be generated, and each basic unit in the array is DOT8, such as Fig.29 shown.
[0162] The working mode at this time is like a systolic array.
[0163] For the convolution operation, the convolution kernel and the input data need to be converted, that is, repeated data is added and arranged accordingly to form the weight matrix of the matrix multiplication and the input feature map matrix, so as to perform matrix multiplication optimization under the systolic array.
[0164] A specific example of the convolution operation implementation for a 3x3 convolution kernel is as follows Fig.30 shown.
[0165] like Fig.30 As shown in the figure, the 5x5 input data and the 3x3 convolution kernel are expanded to 9x9 matrices respectively.
[0166] Generally, in the convolutional neural network mode, the convolution operation is performed by a systolic array, including the following steps:
[0167] 1. Expand the convolution kernel into a weight matrix W by cyclic replication in the manner of convolution cyclic multiplication. For example, as mentioned above, the 3x3 convolution kernel is expanded into a 9x9 weight matrix. The specific row and column elements can be found in Fig.30 .
[0168] 2. The input data is expanded into an input feature map matrix X by cyclic replication corresponding to the weight matrix elements in a convolutional cyclic multiplication manner. It should be understood by those skilled in the art that the input data is the actual input feature map matrix, which is expanded to become an input feature map matrix suitable for matrix multiplication optimization. Here, as described above, the 5x5 input data is expanded to a 9x9 matrix.
[0169] 3. The matrix multiplication operation Y = X * W is completed through the systolic array.
[0170] For the extended process of converting the convolution operation into the matrix multiplication operation, please refer to the description of the GPGPU accelerator and GEMM optimization in the background technology of the specification of the present invention.
[0171] from Fig.30 It is not difficult to see from the implementation that this architecture minimizes the movement of the convolution kernel (or weight).
[0172] Architecture mode switching
[0173] The user can choose to configure the architecture mode, for example, using the parameter arch_mode, where mode 0 indicates the GPGPU architecture mode and mode 1 indicates the CNN architecture mode. The driver recognizes and passes this parameter (arch_mode) to registers in, for example, the GPU chip. Once the GPU detects the switch of arch_mode (from 0 to 1 or from 1 to 0), it will wait for the previous task to complete and flush the cache, configure the internal registers to accept the new arch_mode, and then start accepting new tasks.
[0174] Therefore, according to an embodiment of the present invention, the technology taught by the present invention can be implemented as a computing system including registers. The architectural mode of the register can be configured, for example, it can be configured to be switched according to the degree of participation of matrix multiplication or convolutional neural network operation in the calculation. The architectural mode includes a general graphics processor mode and a convolutional neural network mode. When switching to the general graphics processor mode, the register is configured to access and operate data in the general matrix multiplication mode of the general graphics processor. When switching to the convolutional neural network mode, the register is configured to access and operate data in the matrix multiplication mode of the systolic array.
[0175] The core of the register may be a plurality of computing units, each of which is configured to simultaneously complete one or more multiplication operations and add the results of the multiplication operations to obtain the calculation result of each computing unit.
[0176] Preferably, each computing unit is configured to simultaneously complete a maximum of 8 multiplication operations and add the results of the multiplication operations to obtain the calculation result of each computing unit. For example, the PE structure of DOT8 as described above.
[0177] In the general graphics processor mode, the register is configured to combine or accumulate the calculation results of each calculation unit through instructions.
[0178] In the convolutional neural network mode, the matrix multiplication operation of Y = X * W is completed through the systolic array, where X is the input feature map matrix, W is the weight matrix, and Y is the output feature map matrix. Its specific operations include: fixing the weight elements in the weight matrix W in the computing unit; in one direction of the computing unit array, propagating the elements of the input feature map matrix X in sequence according to the clock cycle; in each computing unit, multiplying the elements of X propagated to this computing unit with the weight elements of W fixed in this computing unit, and accumulating the partial sum calculation results of the previous cycle propagated from the previous computing unit to obtain the partial sum calculation results of the current computing unit in the current clock cycle; in the other direction of the computing unit array, propagating and accumulating the partial sum calculation results of each computing unit according to the clock cycle until the partial sum calculation results propagate out of the computing array, and obtaining the elements of the output feature map matrix Y in sequence.
[0179] As for the convolution operation, in the convolutional neural network mode, the convolution operation is completed through the systolic array. The specific operations include: expanding the convolution kernel into the weight matrix W through cyclic replication in the manner of convolutional cyclic multiplication; expanding the input data into the input feature map matrix X through cyclic replication corresponding to the weight matrix elements in the manner of convolutional cyclic multiplication; completing the matrix multiplication operation of Y = X * W through the systolic array.
[0180] Let's look at a few examples of choosing architectural patterns.
[0181] Example 1:
[0182] In meteorological simulation, matrix multiplication operations that represent state transitions are the core of simulation calculations. Therefore, users can set the arch_mode parameter to 0, which configures the registers in the computing system to the GPGPU architecture for fast matrix operations and data reading and writing.
[0183] Example 2:
[0184] In DNN, fully connected (FC) operations are equivalent to matrix operations. Therefore, users can set the arch_mode parameter to 0, which configures the registers in the computing system to the GPGPU architecture for fast matrix operations and data reading and writing.
[0185] Example 3:
[0186] In signal processing, convolution (i.e. filtering, sliding window, or so-called correlation or convolution operation) is widely used in image filtering. Users can set the arch_mode parameter to 1 to configure the registers in the computing system into a CNN architecture for fast convolution operations.
[0187] Example 4:
[0188] In the convolutional neural network AlexNet, there are 5 convolutional layers (convolution operations) and 3 fully connected layers (matrix operations). Users can set the mode in programming: for the convolutional layer, set the arch_mode parameter to 1 for fast convolution operations; for the fully connected layer, set the arch_mode parameter to 0 for fast matrix operations and data reading and writing.
[0189] The solution based on the present invention can support:
[0190] 1) Convolution operations of various sizes. When performing convolution operations, the efficiency is much higher than the GEMM method converted to GPGPU;
[0191] 2) Matrix multiplication operations of any size, various general SIMD operations, and memory read and write operations;
[0192] 3) Dynamic variability of hardware architecture and efficient architecture transformation capabilities;
[0193] 4) Software and hardware programmable;
[0194] 5) It has both high computing efficiency and high energy efficiency.
[0195] The content taught by the present invention is applicable to various computing systems and artificial intelligence applications, and is particularly applicable to applications such as CPU, GPU, FPGA, and AI chips.
[0196] In addition, it should be recognized by those skilled in the art that the method of the present invention can be implemented as a computer program. As described above in conjunction with the accompanying drawings, the method of the above-mentioned embodiment is executed by one or more programs, including instructions to enable a computer or processor to execute the algorithm described in conjunction with the accompanying drawings. These programs can be stored and provided to a computer or processor using various types of non-transient computer-readable media. Non-transient computer-readable media include various types of tangible storage media. Examples of non-transient computer-readable media include magnetic recording media (such as floppy disks, tapes, and hard disk drives), magneto-optical recording media (such as magneto-optical disks), CD-ROMs (compact disk read-only memories), CD-Rs, CD-R / Ws, and semiconductor memories (such as ROMs, PROMs (programmable ROMs), EPROMs (erasable PROMs), flash ROMs, and RAMs (random access memories)). Further, these programs can be provided to a computer by using various types of transient computer-readable media. Examples of transient computer-readable media include electrical signals, optical signals, and electromagnetic waves. Transient computer-readable media can be used to provide programs to a computer through a wired communication path or a wireless communication path such as wires and optical fibers.
[0197] For example, according to one embodiment of the present invention, a device for reconstructing architecture in a computing system may be provided. The device includes a processor and a memory. A computer program is stored in the memory, and when the computer program is executed by the processor, the method for reconstructing architecture in a computing system as described above may be implemented.
[0198] Therefore, according to the present invention, a computer program or a computer-readable medium may be proposed, which is used to record instructions executable by a processor. When the instructions are executed by the processor, the method of reconstructing the architecture in a computing system as described above may be implemented.
[0199] The embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable those of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A method for reconfiguring architecture in a computing system, characterized in that: include: Selecting an architecture mode according to the degree of participation of matrix multiplication or convolutional neural network operation in the calculation, wherein the architecture mode includes a general graphics processor mode and a convolutional neural network mode; When the general graphics processor mode is selected, the registers in the computing system are configured to perform data access and operations in a general matrix multiplication manner of the general graphics processor; When the convolutional neural network mode is selected, registers in the computing system are configured to access and operate on data in a matrix multiplication manner using a systolic array.
2. The method according to claim 1, characterized in that The method further comprises: When the selected architecture mode is different from the architecture mode currently adopted by the computing system, the architecture mode is switched.
3. The method according to claim 2, characterized in that The switching of the architecture mode further includes: After waiting for the previously unexecuted computing tasks to be completed and the cache to be refreshed, reconfiguring the registers in the computing system from the currently adopted architecture mode to the selected architecture mode; After the model reconstruction is completed, it starts accepting new computing tasks.
4. The method according to claim 1, characterized in that: The registers in the computing system are configured as a plurality of computing units, and each computing unit is configured to simultaneously complete one or more multiplication operations and add the results of the multiplication operations to obtain the calculation result of each computing unit.
5. The method according to claim 4, characterized in that Each computing unit is configured to perform a maximum of 8 multiplication operations simultaneously and add the results of the multiplication operations to obtain a calculation result of each computing unit.
6. The method according to claim 4, characterized in that In the general graphics processor mode, the calculation results of each calculation unit are combined or accumulated through instructions.
7. The method according to claim 4, characterized in that In the convolutional neural network mode, the matrix multiplication operation Y = X * W is completed by the systolic array, where X is the input feature map matrix, W is the weight matrix, and Y is the output feature map matrix: Fix the weight elements in the weight matrix W in the computation unit; In one direction of the computing unit array, each element of the input feature map matrix X is propagated sequentially according to the clock cycle; In each computing unit, the element of X propagated to this computing unit is multiplied by the weight element of W fixed in this computing unit, and the partial sum calculation result of the previous cycle propagated from the previous computing unit is accumulated to obtain the partial sum calculation result of the current computing unit in the current clock cycle; In the other direction of the computing unit array, the partial and calculation results of each computing unit are propagated and accumulated according to the clock cycle until the partial and calculation results are propagated out of the computing array, and each element of the output feature map matrix Y is obtained in turn.
8. The method according to claim 7, characterized in that In the described convolutional neural network mode, the convolution operation is performed by the systolic array: The convolution kernel is expanded into a weight matrix W by cyclic replication in the manner of convolutional cyclic multiplication; The input data is expanded into the input feature map matrix X by loop replication corresponding to the weight matrix elements in a convolution loop multiplication manner; The matrix multiplication operation Y = X * W is done by the systolic array.
9. A computing system comprising a register, characterized in that: The architecture mode of the register is configured to switch according to the degree of participation of matrix multiplication or convolutional neural network operation in the calculation, wherein the architecture mode includes a general graphics processor mode and a convolutional neural network mode; When switching to the general graphics processor mode, the register is configured to perform data access and operation in a general matrix multiplication manner of the general graphics processor; When switched to the convolutional neural network mode, the registers are configured to perform data access and operations in the matrix multiplication manner of a systolic array.
10. The computing system according to claim 9, characterized in that The register is configured as a plurality of computing units, and each computing unit is configured to simultaneously complete one or more multiplication operations and add the results of the multiplication operations to obtain a calculation result of each computing unit.
11. The computing system according to claim 10, characterized in that: Each computing unit is configured to perform a maximum of 8 multiplication operations simultaneously and add the results of the multiplication operations to obtain a calculation result of each computing unit.
12. The computing system according to claim 10, characterized in that: In the general graphics processor mode, the register is configured to combine or accumulate calculation results of various calculation units through instructions.
13. The computing system according to claim 10, characterized in that: In the convolutional neural network mode, the registers are configured to perform a matrix multiplication operation of Y = X * W through a systolic array, where X is the input feature map matrix, W is the weight matrix, and Y is the output feature map matrix: Fix the weight elements in the weight matrix W in the computation unit; In one direction of the computing unit array, each element of the input feature map matrix X is propagated sequentially according to the clock cycle; In each computing unit, the element of X propagated to this computing unit is multiplied by the weight element of W fixed in this computing unit, and the partial sum calculation result of the previous cycle propagated from the previous computing unit is accumulated to obtain the partial sum calculation result of the current computing unit in the current clock cycle; In the other direction of the computing unit array, the partial and calculation results of each computing unit are propagated and accumulated according to the clock cycle until the partial and calculation results are propagated out of the computing array, and each element of the output feature map matrix Y is obtained in turn.
14. The computing system according to claim 13, characterized in that: In the convolutional neural network mode, the registers are configured to perform convolution operations via a systolic array: The convolution kernel is expanded into a weight matrix W by cyclic replication in a convolution manner; The input data is expanded into the input feature map matrix X by cyclic replication corresponding to the elements of the weight matrix in a convolutional manner; The matrix multiplication operation Y = X * W is done by the systolic array.
15. An apparatus for reconfiguring architecture in a computing system, characterized in that: The device comprises a processor and a memory, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the processor implements the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Reconfigurable single instruction multiple data and systolic array structure, processor and electronic terminal
CN108628799A
An accelerating device and a method for reconfigurable neural network algorithm
CN109472356A
