Computing method and device for realizing Depth-wise convolution by completely multiplexing GEMM and ALU architecture

By multiplexing multiplication accumulator and channel parallelism in GEMM and ALU architectures, the problem of low execution efficiency of Depth-wise convolutional layer is solved, and efficient computing resource utilization and cost-saving effects are achieved.

CN119047526AActive Publication Date: 2024-11-29ZHEJIANG UNIV

Patent Information

Application Number
CN202410994000.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-24
Publication Date
2024-11-29
Estimated Expiration
2044-07-24

AI Technical Summary

Technical Problem

In the prior art, in mobile and edge scenarios, the execution efficiency of the Depth-wise convolutional layer is low, and additional accelerators are required to increase area and cost, so it is impossible to effectively reuse GEMM and ALU architectures, resulting in low computing resource utilization.

Method used

By determining the number and arrangement of multiplication accumulators in the GEMM and ALU architecture, obtaining and dividing the input feature map and weight data blocks, convolution calculation is performed using channel parallel method, multiplexing single-channel computing unit and multiplication accumulator to achieve Depth -Efficient calculation of wise convolution.

Benefits of technology

It saves the area and cost of the additional accelerator, improves the utilization rate of the calculation unit, improves the calculation efficiency of Depth-wise convolution, and supports parallel computing of standard convolution and Depth-wise convolution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119047526A_ABST
    Figure CN119047526A_ABST
Patent Text Reader

Abstract

The invention discloses a calculation method and device for realizing Depth-wise convolution by completely multiplexing GEMM and ALU architectures. The calculation method comprises the following steps: determining the GEMM and ALU architectures, obtaining input feature map data and weight data of a convolution layer, dividing the input feature map data and the weight data into a plurality of data blocks and sub-data blocks, and obtaining a calculation sequence of the data blocks; according to a calculation sequence, inputting data of different channels of each input feature map data block and each weight sub-data block into a corresponding single-channel calculation unit; performing convolution calculation on each input feature map data matrix and each weight sub-data matrix by each single-channel calculation unit to obtain an output feature map data block; and writing the output feature map data blocks back to the corresponding addresses of the memory according to the sequence. According to the method, the utilization rate of GEMM computing resources in the Depth-wise convolution operation process is improved, and the throughput and the processing performance of data are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of deep learning technology, and in particular to a calculation method and device for implementing depth-wise convolution by fully multiplexing GEMM and ALU architecture. Background Art

[0002] Convolutional neural networks (CNNs) extract features from input data through convolution operations, thereby achieving data recognition and classification, and have achieved excellent results in application fields such as image classification and target detection. In CNN, the standard convolution layer is mainly responsible for the important task of extracting features. The input data of the standard convolution layer are two, namely, feature map data with multiple channels and multiple convolution kernels with multiple channels. As the application scope of deep learning in the industry expands, the application of CNN in mobile terminals and edge scenarios is gradually popularized. However, due to the limitations of storage bandwidth and computing resources in mobile terminals and edge scenarios, the role of CNN is not obvious. Therefore, some neural network models have proposed depth-wise convolution layers with smaller parameters and computational complexity. The input data of the depth-wise convolution layer is multi-channel feature map data and a multi-channel convolution kernel. The feature map data and the channels of the convolution kernel correspond to each other, and one channel of the convolution kernel is responsible for the data of one channel of the feature map.

[0003] Standard convolution requires the accumulation of convolution results of all channels. The general implementation method is to use GEMM (general matrix-vector multiplication) acceleration to perform convolution calculations on three-dimensional inputs in a channel-parallel and convolution kernel-parallel manner. The accelerator for convolution calculations, which uses multipliers and accumulators as the smallest unit, achieves channel parallelism and convolution kernel parallelism at the same time by regularly combining and arranging multipliers and accumulators. The number of convolution kernels in the depth-wise convolution layer is equal to 1, and the calculation method is channel-by-channel calculation. Therefore, there is no possibility of convolution kernel parallelism in depth-wise convolution. The depth-wise convolution layer has only n / (n*m) utilization on GEMM, where n is the number of parallel channels, m is the number of parallel convolution kernels, and n*m is the number of multipliers and accumulators in GEMM.

[0004] In existing products, Arm Ethos supports standard convolution and depth-wise convolution. When calculating standard convolution, ArmEthos iterates the output feature map in the order of dimension, horizontal, and vertical directions, and reuses the input feature map in the dimension direction; when calculating the depth-wise convolution layer, it iterates the input feature map and output feature map of the depth-wise convolution in the order of dimension, horizontal, and vertical directions, but does not reuse the input feature map. Therefore, Arm Ethos only performs channel parallelism when implementing depth-wise convolution. Before each convolution calculation, it needs to read the input feature map and convolution kernel data of the number of parallel channels from the memory. Compared with the acceleration effect of ordinary convolution, the execution efficiency of depth-wise convolution is low.

[0005] Some accelerators for depth-wise convolution layers are designed only based on the characteristics of depth-wise convolution, and lose support for standard convolution layers. When implementing, two additional accelerators are required, one for standard convolution and the other for depth-wise convolution, which increases the area and is not conducive to implementation on mobile and edge devices. Some accelerators for depth-wise convolution layers use the img2col operation to convert the input feature map data and weight data into a matrix suitable for GEMM operations, and then perform convolution calculations. This method increases the overhead of matrix conversion caused by img2col and cannot meet the low power consumption requirements of mobile and edge devices. Summary of the invention

[0006] The purpose of the present invention is to provide a calculation method and device for implementing Depth-wise convolution by fully multiplexing GEMM and ALU architecture to solve the above-mentioned technical problems.

[0007] In order to solve the above technical problems, the specific technical solutions of the calculation method and device of the present invention for fully multiplexing GEMM and ALU architecture to realize Depth-wise convolution are as follows: A method for calculating depth-wise convolution by fully multiplexing GEMM and ALU architecture, the method comprising: Step 1: Determine the GEMM and ALU architecture, determine the number and arrangement of multipliers and accumulators in the GEMM architecture, and determine the number of multipliers and accumulators in the ALU architecture; Step 2: Obtain the input feature map data and weight data of the convolutional layer, divide the input feature map data and weight data into several data blocks and sub-data blocks, and obtain the calculation order of each data block; Step 3: In accordance with the calculation order, the data of different channels of each input feature map data block and each weight sub-data block are input into the corresponding single-channel calculation unit; each single-channel calculation unit performs convolution calculation on each input feature map data matrix and each weight sub-data matrix to obtain an output feature map data block; Step 4: The output feature map data block is written back to the corresponding address of the memory in the order of calculation.

[0008] Furthermore, the step 1 includes the following specific steps: Analyze the number of channels of the input feature map of the standard convolution layer, the number of convolution kernels and the requirements of application scenarios, determine the preset number of channel parallelism and the preset number of convolution kernels respectively, determine the number of single-channel computing units in the GEMM architecture according to the preset number of channel parallelism, determine the number of multipliers and accumulators in each single-channel computing unit in the GEMM architecture and the number of multipliers and accumulators in the ALU architecture according to the preset number of convolution kernels parallelism, reuse the single-channel computing unit of GEMM as the input channel parallel of depth-wise convolution, and at the same time, reuse the multipliers and accumulators in each single-channel computing unit as the convolution computing unit for the input feature map data and weight data in each channel of depth-wise convolution.

[0009] Furthermore, for the standard convolution layer using GEMM, the acceleration method of step 1 is that 8 convolution kernels are processed in parallel, each convolution kernel performs convolution calculation in parallel on 8 channels, and GEMM outputs the calculation result according to the output channel in each calculation cycle, with a total of 8 output feature map data; for the Depth-wise convolution layer that reuses the GEMM architecture, the acceleration method is that 8 channels are processed in parallel, and the 8 multiplier accumulators of each single-channel calculation unit perform convolution calculation on the 8 input feature map data and 8 weight data of each channel, and GEMM outputs the calculation result according to the output channel in each calculation cycle, with a total of 8 output feature map data.

[0010] Furthermore, the step 2 includes the following specific steps: The input feature map data of the standard convolution layer and the Depth-wise convolution layer are divided into channel dimensions, and the number of divisions is the preset number of channel parallelism. The input feature map data blocks are divided, and the channel dimension of each input feature map data block is the same, which is equal to the preset number of channel parallelism. The weight data of the standard convolution layer and the Depth-wise convolution layer are also divided into channel dimensions, and the number of divisions is the preset number of channel parallelism. The weight data blocks are divided, and the channel dimension of each weight data block is the same, which is equal to the preset number of channel parallelism. If the channel dimension of the input feature map data and the weight data is less than an integer multiple of the preset number, the number of channels of the input feature map and the weight data is adjusted to an integer multiple of the preset number by channel zero padding, and then the adjusted input feature map data and weight data are divided into data blocks according to the same steps. According to the division method, the position index of the input feature map data block in the input feature map and the position index of the weight data block in the convolution kernel are determined respectively.

[0011] Furthermore, in step 2, the weight data block of the depth-wise convolutional layer is further divided into sub-weight data blocks of a preset size in the row and column dimensions, wherein the preset size is determined according to the number of multipliers and accumulators in each single-channel computing unit of the GEMM. When the weight data block is less than an integer multiple of the preset size, the row and column sizes of the weight data block are adjusted to integer multiples of the preset size by padding rows and columns with zeros, and then the adjusted weight data block is divided into sub-weight data blocks according to the same steps; According to the convolution calculation cycle mode of the standard convolution layer and the depth-wise convolution layer, as well as the position index of each input feature map data block in the input feature map and the position index of each sub-weight data block in the convolution kernel, the convolution calculation order of the input feature map data block and each sub-weight data block of each convolution layer is determined.

[0012] Furthermore, the step 3 includes the following specific steps: GEMM performs convolution calculations on the input feature map data blocks and sub-weight data blocks of each calculation cycle in turn to obtain the corresponding output feature map data blocks. The standard convolution adopts channel parallelism and convolution kernel parallelism on GEMM, wherein the single-channel calculation unit of GEMM implements the convolution kernel parallelism of the standard convolution, and the multiplier-accumulator in each single-channel calculation unit implements channel parallelism; Depth-wise convolution adopts channel parallelism on GEMM, and each channel performs Depth-wise convolution calculation independently. The single-channel calculation unit of GEMM implements the channel parallelism of Depth-wise convolution, and the multiplier-accumulator of each single-channel calculation unit obtains the independent convolution sum of each channel. If the size of the sub-weight data block of the Depth-wise convolution layer is larger than the number of multiplier-accumulators in the single-channel calculation unit, it is necessary to split the sub-weight data block when reusing GEMM to implement Depth-wise convolution, and divide the convolution calculation of the input feature map data and weight data into two calculation cycles.

[0013] Furthermore, in step 3, when processing the standard convolution layer, the input of the GEMM architecture of the present application is the input feature map data block and the weight data block, the data in each weight data block comes from the convolution kernels processed in parallel, the number of convolution kernels processed in parallel is equal to the preset number of single-channel computing units, the number of channels of each input feature map data block and sub-weight data block processed by GEMM each time is equal to the number of multipliers and accumulators of the single-channel computing unit, and when processing the Depth-wise convolution layer, the input of the GEMM and ALU architecture is the input feature map data block and the sub-weight data block, the number of channels of each input feature map data block and each sub-weight data block is equal to the number of single-channel computing units, and the number of input feature map data and weight data processed by each single-channel computing unit in each computing cycle of GEMM is less than or equal to the number of multipliers and accumulators in the single-channel computing unit.

[0014] Furthermore, in step 3, the GEMM and ALU architecture calculation uses a four-layer loop to complete the Depth-wise convolution. During the Depth-wise convolution process, the first layer is the number of groups into which the input feature map is divided according to the preset number of channel parallelism, that is, the number of input feature map data blocks, and the output feature map data is also output in a channel parallel manner; the second layer of the loop is the number of groups obtained by dividing the weight data block according to the preset size, that is, the number of sub-weight data blocks in each weight data block. Therefore, for the next three layers of loops, the Depth-wise convolution is implemented by weight reuse, and each sub-weight data block corresponds to a partial sum of an output feature map data block; the third and fourth layers are the length and width of the output feature map data block, respectively. GEMM obtains the intermediate result of the output feature map row by row and writes it into a dedicated storage In the on-chip memory that stores the intermediate results of the output feature map, while calculating the output feature map results, the intermediate result with the same position as the current output feature map data is read from the on-chip buffer, and the convolution and addition are obtained with the current calculation cycle. After obtaining the new intermediate result, it is written back to the on-chip memory, and the address is the same as the address when reading. If the size of the sub-weight data block of the Depth-wise convolution layer is larger than the number of multipliers and accumulators in the single-channel computing unit, the sub-weight data block is split into two parts. The number of weight data in the first part is equal to the number of multipliers and accumulators, and the second part is the remaining weight data. The convolution calculation of the input feature map data and the weight data is completed on the GEMM architecture and the ALU architecture respectively. When the second layer loop is executed to the last one, the result obtained by addition is the final data of the output feature map data.

[0015] Furthermore, step 4 includes the following specific steps: according to the description of the four-layer loop body in step 3, an output feature data block is obtained after the last three layers of loops. The size of the output feature map data block is equal to the parameters in the third and fourth layers of loops. There are two cases for calculating the output feature map data. The first case is that the size of the weight data block is less than or equal to the preset size, and the other case is that the size of the weight data block is greater than the preset size. If the size of the weight data block is less than or equal to the preset size, there is only one weight sub-data block, and the second layer loop will only be executed once. When the third and fourth layers of loops are completed, the result is the final output feature map data block. According to the position index of the current output data block in the entire output feature map data and the base address of the output data in the on-chip buffer, the starting address of the output feature map data block in the on-chip buffer is determined, and then the output feature map data block is written to the on-chip buffer; if the size of the weight data block is greater than the preset size, Assume that the size is , there will be multiple weighted sub-data blocks, the second layer loop will be executed multiple times, and the inner two layers of loops, namely the third and fourth layers, obtain the intermediate results of the output feature map. This part of the data is written into the register and participates in the accumulation in subsequent loops. After the second layer loop ends, all intermediate results with the same index are accumulated to obtain the final output feature map data. The number of channels of the output feature map of the Depth-wise convolution layer is the same as the number of channels of the input feature map. Therefore, the index of the input channel number of the first layer loop is also the index of the output channel number. According to the index of the current output feature map data block and the base address of the output data in the on-chip buffer, the starting address of the output feature map data block in the on-chip buffer is determined, and the output feature map data block is written back to the on-chip buffer. After the first layer loop ends, all the output feature map data are obtained, and they are written into the off-chip memory in sequence according to the storage format of the output feature map data in the off-chip memory.

[0016] The present invention also discloses a computing device for fully multiplexing GEMM and ALU architectures to implement Depth-wise convolution, comprising: an off-chip memory and an on-chip buffer related to data storage, a data handling module and a Depth-wise computing module related to data computing, wherein the Depth-wise computing module comprises a GEMM architecture and an ALU architecture; The GEMM architecture and ALU architecture determine the four-layer loop sequence of the Depth-wise convolution, the first layer is the number of groups into which the input feature map is divided according to the preset number of channel parallelism, that is, the number of input feature map data blocks, and the output feature map data is also output in a channel parallel manner; the second layer loop is the number of groups obtained by dividing the weight data block according to the preset size, that is, the number of sub-weight data blocks in each weight data block, so for the next three layers of loops, the Depth-wise convolution is implemented by weight reuse, and each sub-weight data block corresponds to a partial sum of an output feature map data block; the third and fourth layers are the length and width of the output feature map data block, respectively, and the GEMM obtains the intermediate result of the output feature map row by row, and writes it into an on-chip memory specifically storing the intermediate result of the output feature map. According to these four layers of loops, the transport order and calculation order of the input image data and the weight data are determined, and according to the transport order, the data transport module transports the input image data and the weight data from the off-chip memory to the on-chip buffer; The computing module has a selector controlled by the computing mode field in the instruction, which distinguishes between standard convolution and depth-wise convolution. For the standard convolution mode, GEMM calculation and ALU calculation will independently perform channel parallel calculation, which is determined according to the calculation type field in the instruction, and the data that needs to be read from the on-chip buffer during the calculation process is determined at the same time. For the depth-wise convolution mode, GEMM calculation and ALU calculation are performed simultaneously. Both GEMM and ALU adopt a channel parallel mode. The intermediate results of the corresponding channels in the GEMM architecture and the ALU architecture are accumulated in the ALU, and finally the output result of the number of parallel channels is obtained. According to the calculation order of the depth-wise convolution, the computing module determines the data address in the on-chip buffer, reads it into the GEMM architecture and the ALU architecture through the data interface, calculates and accumulates the intermediate results in the GEMM architecture, and the intermediate results are used as the input data of the ALU architecture, and are accumulated with the convolution result in the ALU to obtain the convolution sum of the number of parallel channels, and written into the on-chip buffer. The device has a selector controlled by the mode field in the instruction. Under the control of the first-layer loop body, the output results in the on-chip buffer are transferred to the off-chip memory through the data transfer module, and the next round of depth-wise convolution calculation of the input image data and weight data is started at the same time.

[0017] The present invention provides a method and device for calculating depth-wise convolution by fully multiplexing GEMM and ALU architecture, which has the following advantages: The present invention uses the GEMM and ALU architecture originally used to accelerate standard convolution to accelerate Depth-wise convolution. There is no need to add an additional accelerator to specifically optimize the Depth-wise convolution layer, saving a lot of area and cost.

[0018] The GEMM and ALU architecture of the present invention is completely based on the optimized acceleration of standard convolution, and improves the utilization rate of all computing units when accelerating Depth-wise convolution, ensuring that the computing units of GEMM can be efficiently utilized in each computing cycle when performing standard convolution and Depth-wise convolution. At the same time, the present invention adopts the method of simultaneously accelerating Depth-wise convolution by using GEMM and ALU architecture, which saves a large number of computing cycles and improves computing efficiency.

[0019] The present invention proposes a device that fully reuses GEMM and ALU architectures, supports a standard convolution calculation mode and a Depth-wise convolution calculation mode, and distinguishes between the two calculation modes, thereby improving the parallelism and utilization of the GEMM architecture and the ALU architecture in the Depth-wise convolution calculation mode. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 A schematic diagram of the flow chart structure of the present invention's fully multiplexed GEMM and ALU architecture to implement the Depth-wise convolution method; Figure 2 This is a schematic diagram of the weight data cutting principle of the Depth-wise convolution of the present invention; Figure 3 It is a schematic diagram of the calculation process of the Depth-wise convolution of the present invention; Figure 4 Device module diagram for fully reusing GEMM and ALU architecture to implement Depth-wise convolution. DETAILED DESCRIPTION

[0021] In order to better understand the purpose, structure and function of the present invention, the following is a further detailed description of a calculation method and device for implementing Depth-wise convolution by fully multiplexing GEMM and ALU architecture in the present invention in conjunction with the accompanying drawings.

[0022] The application embodiment provides a method and device for calculating depth-wise convolution by fully reusing GEMM and ALU architecture. For mobile terminals and edge devices, under the premise of supporting standard convolution calculation acceleration, depth-wise convolution calculation can be accelerated without adding additional accelerators, thereby improving the utilization rate of GEMM computing resources during depth-wise convolution operations and improving data throughput and processing performance. The main solution of the embodiment of the present application is: determine the GEMM and ALU architecture, determine the number and arrangement of multipliers and accumulators in the GEMM architecture, and determine the number of multipliers and accumulators in the ALU architecture; obtain the input feature map data and weight data of the convolution layer, divide the input feature map data and weight data into several data blocks and sub-data blocks, and obtain the calculation order of each data block; according to the calculation order, input the data of different channels of each input feature map data block and each weight sub-data block into the corresponding single-channel calculation unit; each single-channel calculation unit performs convolution calculation on each input feature map data matrix and each weight sub-data matrix to obtain an output feature map data block; write the output feature map data block back to the corresponding address of the memory in sequence.

[0023] The following is a further explanation of the application content through the description of the embodiments of the present application in conjunction with the accompanying drawings.

[0024] The present application embodiment provides a method for calculating depth-wise convolution by fully multiplexing GEMM and ALU architecture, such as Figure 1 As shown, the method includes: Step 1: Determine the GEMM and ALU architectures, determine the number and arrangement of multiplier accumulators in the GEMM architecture, and determine the number of multiplier accumulators in the ALU architecture.

[0025] Specifically, the number of channels of the input feature map of the standard convolution layer, the number of convolution kernels and the requirements of the application scenario are analyzed, and the preset number of parallel channels and the preset number of parallel convolution kernels are determined respectively. The number of single-channel computing units in the GEMM architecture is determined according to the preset number of parallel channels, and the number of multiplication and accumulation devices in each single-channel computing unit in the GEMM architecture and the number of multiplication and accumulation devices in the ALU architecture are determined according to the preset number of parallel convolution kernels. Since the Depth-wise convolution layer is a channel-by-channel convolution, the calculation results of each channel do not need to be accumulated, and the single-channel computing unit of the GEMM can be reused as the input channel parallel of the Depth-wise convolution. At the same time, the multiplication and accumulation devices in each single-channel computing unit are reused as the convolution computing unit for the input feature map data and weight data in each channel of the Depth-wise convolution. In one implementation, the number of single-channel computing units in the GEMM architecture is equal to 8, and the number of multiplication and accumulation devices in each single-channel computing unit is equal to 8. In practical applications, the preset number of single-channel computing units and the preset number of multiplication and accumulation devices in each single-channel computing unit can be set according to application requirements, such as 16, 32, etc. For the standard convolution layer using GEMM, the acceleration method is to process 8 convolution kernels in parallel, and each convolution kernel performs convolution calculation on 8 channels in parallel. GEMM outputs the calculation results according to the output channel in each calculation cycle, with a total of 8 output feature map data; for the Depth-wise convolution layer that reuses the GEMM architecture, the acceleration method is to process 8 channels in parallel. The 8 multipliers and accumulators of each single-channel calculation unit perform convolution calculation on the 8 input feature map data and 8 weight data of each channel. GEMM outputs the calculation results according to the output channel in each calculation cycle, with a total of 8 output feature map data.

[0026] Step 2: Obtain the input feature map data and weight data of the convolutional layer, divide the input feature map data and weight data into several data blocks and sub-data blocks, and obtain the calculation order of each data block.

[0027] Specifically, the input feature map data of the standard convolution layer and the depth-wise convolution layer are divided into channel dimensions, the number of divisions is the preset number of channel parallelism, and the input feature map data blocks are obtained by division, and the channel dimensions of each input feature map data block are the same, which are equal to the preset number of channel parallelism. The weight data of the standard convolution layer and the depth-wise convolution layer are also divided into channel dimensions, the number of divisions is the preset number of channel parallelism, and the weight data blocks are obtained by division, and the channel dimensions of each weight data block are the same, which are equal to the preset number of channel parallelism. If the channel dimensions of the input feature map data and the weight data are less than an integer multiple of the preset number, the number of channels of the input feature map and the weight data are adjusted to an integer multiple of the preset number by channel zero padding, and then the adjusted input feature map data and weight data are divided into data blocks according to the same steps. According to the division method, the position index of the input feature map data block in the input feature map and the position index of the weight data block in the convolution kernel are determined respectively.

[0028] The weight data block of the depth-wise convolutional layer is further divided into sub-weight data blocks of a preset size in the row and column dimensions, where the preset size is determined according to the number of multipliers and accumulators in each single-channel computing unit of the GEMM. When the weight data block is less than an integer multiple of the preset size, the row and column sizes of the weight data block are adjusted to integer multiples of the preset size by padding the rows and columns with zeros, and then the adjusted weight data block is divided into sub-weight data blocks in the same steps. In one implementation, Figure 2 As shown, the single-channel computing unit of the GEMM architecture uses 8 multipliers and accumulators, so the preset size is determined to be 3*3. In practical applications, the preset size can be set according to application requirements, such as 4*4, 6*6, etc., to adapt to the number of multipliers and accumulators in the single-channel computing unit. According to the division method of the weight data block, the position index of each sub-weight data block in the weight data block is obtained. The position index of each sub-weight data block in the weight data block and the position index of each weight data block in the convolution kernel are combined to obtain the position index of each sub-weight data block in the convolution kernel.

[0029] According to the convolution calculation cycle mode of the standard convolution layer and the depth-wise convolution layer, as well as the position index of each input feature map data block in the input feature map and the position index of each sub-weight data block in the convolution kernel, the convolution calculation order of the input feature map data block and each sub-weight data block of each convolution layer is determined.

[0030] Step 3: In accordance with the calculation order, the data of different channels of each input feature map data block and each weight sub-data block are input into the corresponding single-channel calculation unit; each single-channel calculation unit performs convolution calculation on each input feature map data matrix and each weight sub-data matrix to obtain the output feature map data block.

[0031] Specifically, GEMM performs convolution calculations on the input feature map data blocks and sub-weight data blocks of each calculation cycle in turn to obtain the corresponding output feature map data blocks. Standard convolution uses channel parallelism and convolution kernel parallelism on GEMM, wherein the single-channel calculation unit of GEMM implements the convolution kernel parallelism of standard convolution, and the multiplier-accumulator in each single-channel calculation unit implements channel parallelism; Depth-wise convolution uses channel parallelism on GEMM, and each channel performs Depth-wise convolution calculation independently. The single-channel calculation unit of GEMM implements the channel parallelism of Depth-wise convolution, and the multiplier-accumulator of each single-channel calculation unit obtains the independent convolution sum of each channel. If the size of the sub-weight data block of the Depth-wise convolution layer is larger than the number of multipliers and accumulators in the single-channel calculation unit, it is necessary to split the sub-weight data block when reusing GEMM to implement Depth-wise convolution, and divide the convolution calculation of the input feature map data and weight data into two calculation cycles. In one implementation, Figure 3 As shown, the size of the sub-weight data block is 3*3, and the number of multipliers and accumulators in a single-channel computing unit is equal to 8. Therefore, the sub-weight data block needs to be split into two parts according to the number of multipliers and accumulators. The first part is the first 8 sub-weight data blocks, and the second part is the last 1 sub-weight data block. In the first part, the weight data of each channel and the corresponding 8 input feature map data are input into the GEMM architecture according to the channel and the convolution calculation is completed. The calculation result is saved in a register specifically used to store the output result. The weight data and the corresponding input feature map data of the second part are input into the multiplier and accumulator in the ALU architecture according to the channel sequence in the next cycle, and are accumulated with the data in the register at the same time to obtain the convolution result of the sub-weight data block and the input feature map data block. In the convolution calculation of the first part, the utilization rate of the computing unit of the GEMM is 100%, and in the convolution calculation of the second part, the utilization rate of the computing unit of the ALU is 100%. When performing the ALU calculation of the second part, the GEMM architecture simultaneously performs the convolution calculation of the sub-weight data block and the first part of the next set of input feature map data, and the GEMM computing units are fully utilized in each calculation cycle. (The first part of the weight data and the corresponding 8 input feature map data complete the convolution calculation in the first calculation cycle to obtain the intermediate result. In the second calculation cycle, the second part of the weight data and the corresponding 1 input feature map data complete the convolution calculation, and add it to the intermediate result of the first calculation cycle to obtain a sub-weight data block and the corresponding input feature map data convolution calculation to obtain the output feature map data result. In the convolution calculation of the first part, the utilization rate of the GEMM computing unit is 100%. In the convolution calculation of the second part, some computing units in the GEMM are idle, but overall, it is better than the solution in which most computing units of the GEMM are idle in each calculation cycle.) When processing a standard convolutional layer, the input of the GEMM architecture of the present application is an input feature map data block and a weight data block. The data in each weight data block comes from convolution kernels processed in parallel, and the number of convolution kernels processed in parallel is equal to the preset number of single-channel computing units. The number of channels of each input feature map data block and sub-weight data block processed by GEMM each time is equal to the number of multipliers and accumulators of a single-channel computing unit. When processing a Depth-wise convolutional layer, the input of the GEMM and ALU architecture of the present application is an input feature map data block and a sub-weight data block. The number of channels of each input feature map data block and each sub-weight data block is equal to the number of single-channel computing units. The number of input feature map data and weight data processed by each single-channel computing unit in each computing cycle of GEMM is less than or equal to the number of multipliers and accumulators in a single-channel computing unit.

[0032] The GEMM and ALU architecture calculation of the present application uses four layers of loops to complete Depth-wise convolution. In the process of executing Depth-wise convolution, the first layer is the number of groups divided by the preset number of channel parallel input feature maps, that is, the number of input feature map data blocks, and the output feature map data is also output in a channel parallel manner; the second layer of loops is the number of groups obtained by dividing the weight data blocks according to the preset size, that is, the number of sub-weight data blocks in each weight data block, so for the next three layers of loops, the present application uses the weight reuse method to implement Depth-wise convolution, and each sub-weight data block corresponds to a partial sum of an output feature map data block; the third and fourth layers are the length and width of the output feature map data block, respectively, and GEMM obtains the intermediate results of the output feature map row by row, and writes them into the on-chip memory dedicated to storing the intermediate results of the output feature map. While calculating the output feature map results, read the intermediate results with the same position as the current output feature map data from the on-chip buffer, add the convolution sum obtained in the current calculation cycle, and write the new intermediate results back to the on-chip memory after obtaining them. The address is the same as the address when reading. If the size of the sub-weight data block of the depth-wise convolution layer is larger than the number of multipliers and accumulators in the single-channel computing unit, the sub-weight data block is split into two parts. The number of weight data in the first part is equal to the number of multipliers and accumulators, and the second part is the remaining weight data. The convolution calculation of the input feature map data and weight data is completed on the GEMM architecture and the ALU architecture respectively. When the second layer loop is executed to the last one, the result of the addition is the final data of the output feature map data.

[0033] Step 4: The output feature map data block is written back to the corresponding address of the memory in the order of calculation.

[0034] Specifically, according to the description of the above four-layer loop body, after the last three layers of loops, an output feature data block is obtained, and the size of the output feature map data block is equal to the parameters in the third and fourth layers of loops. There are two cases for calculating the output feature map data, the first case is that the size of the weight data block is less than or equal to the preset size, and the other case is that the size of the weight data block is greater than the preset size.

[0035] If the size of the weight data block is less than or equal to the preset size, there is only one weight sub-data block, and the second layer loop will only be executed once. When the third and fourth layers of loops are completed, the result is the final output feature map data block. According to the position index of the current output data block in the entire output feature map data and the base address of the output data in the on-chip buffer, determine the starting address of the output feature map data block in the on-chip buffer, and then write the output feature map data block to the on-chip buffer.

[0036] If the size of the weight data block is larger than the preset size, there will be multiple weight sub-data blocks, and the second layer loop will be executed multiple times. The inner two layers of loops, namely the third and fourth layers, obtain the intermediate results of the output feature map. This part of the data is written into the register and participates in the accumulation in the subsequent loops. After the second layer loop ends, all the intermediate results with the same index are accumulated to obtain the final output feature map data. The number of channels of the output feature map of the depth-wise convolution layer is the same as the number of channels of the input feature map. Therefore, the index of the input channel number of the first layer loop is also the index of the output channel number. According to the index of the current output feature map data block and the base address of the output data in the on-chip buffer, the starting address of the output feature map data block in the on-chip buffer is determined, and the output feature map data block is written back to the on-chip buffer. After the first layer loop ends, all the output feature map data are obtained, and they are written into the off-chip memory in sequence according to the storage format of the output feature map data in the off-chip memory.

[0037] The present application embodiment provides a computing device that fully reuses GEMM and ALU architecture to implement Depth-wise convolution, such as Figure 4 As shown, the device comprises: The off-chip memory and on-chip cache related to data storage, the data handling module and Depth-wise computing module related to data computing, wherein the Depth-wise computing module includes the GEMM architecture and the ALU architecture.

[0038] The calculation method of fully reusing GEMM and ALU architecture to implement Depth-wise convolution determines the four-layer loop sequence of Depth-wise convolution. The first layer is the number of groups divided by the preset number of channel parallel input feature maps, that is, the number of input feature map data blocks, and the output feature map data is also output in a channel parallel manner; the second layer loop is the number of groups obtained by dividing the weight data block according to the preset size, that is, the number of sub-weight data blocks in each weight data block. Therefore, for the next three layers of loops, this application uses the weight reuse method to implement Depth-wise convolution, and each sub-weight data block corresponds to the partial sum of an output feature map data block; the third and fourth layers are the length and width of the output feature map data block, respectively, and GEMM obtains the intermediate results of the output feature map row by row, and writes them into the on-chip memory dedicated to storing the intermediate results of the output feature map. According to these four layers of loops, the transport order and calculation order of the input image data and weight data are determined. According to the transport order, the data transport module transports the input image data and weight data from the off-chip memory to the on-chip buffer.

[0039] There is a selector in the calculation module, which is controlled by the calculation mode field in the instruction. This field distinguishes between standard convolution and depth-wise convolution. For the standard convolution mode, GEMM calculation and ALU calculation will independently perform channel parallel calculation, which is determined by the calculation type field in the instruction, and at the same time determines the data that needs to be read from the on-chip buffer during the calculation process. For the depth-wise convolution mode, GEMM calculation and ALU calculation are performed simultaneously. Both GEMM and ALU adopt channel parallel mode. The intermediate results of the corresponding channels in the GEMM architecture and the ALU architecture are accumulated in the ALU, and finally the output result of the number of parallel channels is obtained. According to the calculation order of the depth-wise convolution, the calculation module determines the data address in the on-chip buffer, reads it into the GEMM architecture and the ALU architecture through the data interface, calculates and accumulates the intermediate results in the GEMM architecture, and the intermediate results are used as the input data of the ALU architecture. The convolution sum of the number of parallel channels is accumulated with the convolution result in the ALU and written into the on-chip buffer. There is a selector in the device, which is controlled by the mode field in the instruction. Under the control of the first-layer loop body, the output results in the on-chip buffer are transferred to the off-chip memory through the data transfer module, and the next round of depth-wise convolution calculation of the input image data and weight data is started at the same time.

[0040] It is to be understood that the present invention is described by some embodiments, and it is known to those skilled in the art that various changes or equivalent substitutions may be made to these features and embodiments without departing from the spirit and scope of the present invention. In addition, under the teachings of the present invention, these features and embodiments may be modified to adapt to specific circumstances and materials without departing from the spirit and scope of the present invention. Therefore, the present invention is not limited by the specific embodiments disclosed herein, and all embodiments falling within the scope of the claims of this application are within the scope of protection of the present invention.

Claims

1. A method for implementing depth-wise convolution by fully multiplexing GEMM and ALU architecture, characterized in that: The method comprises: Step 1: Determine the GEMM and ALU architecture, determine the number and arrangement of multipliers and accumulators in the GEMM architecture, and determine the number of multipliers and accumulators in the ALU architecture; Step 2: Obtain the input feature map data and weight data of the convolutional layer, divide the input feature map data and weight data into several data blocks and sub-data blocks, and obtain the calculation order of each data block; Step 3: In accordance with the calculation order, the data of different channels of each input feature map data block and each weight sub-data block are input into the corresponding single-channel calculation unit; each single-channel calculation unit performs convolution calculation on each input feature map data matrix and each weight sub-data matrix to obtain an output feature map data block; Step 4: The output feature map data block is written back to the corresponding address of the memory in the order of calculation.

2. The method for calculating depth-wise convolution by fully multiplexing GEMM and ALU architecture according to claim 1, characterized in that: The step 1 comprises the following specific steps: Analyze the number of channels of the input feature map of the standard convolution layer, the number of convolution kernels and the requirements of application scenarios, determine the preset number of channel parallelism and the preset number of convolution kernels respectively, determine the number of single-channel computing units in the GEMM architecture according to the preset number of channel parallelism, determine the number of multipliers and accumulators in each single-channel computing unit in the GEMM architecture and the number of multipliers and accumulators in the ALU architecture according to the preset number of convolution kernels parallelism, reuse the single-channel computing unit of GEMM as the input channel parallel of depth-wise convolution, and at the same time, reuse the multipliers and accumulators in each single-channel computing unit as the convolution computing unit for the input feature map data and weight data in each channel of depth-wise convolution.

3. The method for calculating depth-wise convolution by fully multiplexing GEMM and ALU architecture according to claim 1, characterized in that: In step 1, for the standard convolution layer using GEMM, the acceleration method is that 8 convolution kernels are processed in parallel, each convolution kernel performs convolution calculation in parallel according to 8 channels, and GEMM outputs the calculation result according to the output channel in each calculation cycle, with a total of 8 output feature map data; for the Depth-wise convolution layer that reuses the GEMM architecture, the acceleration method is that 8 channels are processed in parallel, and the 8 multiplier accumulators of each single-channel calculation unit perform convolution calculation on the 8 input feature map data and 8 weight data of each channel, and GEMM outputs the calculation result according to the output channel in each calculation cycle, with a total of 8 output feature map data.

4. The method for calculating depth-wise convolution by fully multiplexing GEMM and ALU architecture according to claim 1, characterized in that: The step 2 comprises the following specific steps: The input feature map data of the standard convolution layer and the Depth-wise convolution layer are divided into channel dimensions, and the number of divisions is the preset number of channel parallelism. The input feature map data blocks are divided, and the channel dimension of each input feature map data block is the same, which is equal to the preset number of channel parallelism. The weight data of the standard convolution layer and the Depth-wise convolution layer are also divided into channel dimensions, and the number of divisions is the preset number of channel parallelism. The weight data blocks are divided, and the channel dimension of each weight data block is the same, which is equal to the preset number of channel parallelism. If the channel dimension of the input feature map data and the weight data is less than an integer multiple of the preset number, the number of channels of the input feature map and the weight data is adjusted to an integer multiple of the preset number by channel zero padding, and then the adjusted input feature map data and weight data are divided into data blocks according to the same steps. According to the division method, the position index of the input feature map data block in the input feature map and the position index of the weight data block in the convolution kernel are determined respectively.

5. The method for calculating depth-wise convolution by fully multiplexing GEMM and ALU architecture according to claim 1, characterized in that: In step 2, the weight data block of the depth-wise convolutional layer is further divided into sub-weight data blocks of a preset size in the row and column dimensions, wherein the preset size is determined according to the number of multipliers and accumulators in each single-channel computing unit of the GEMM. When the weight data block is less than an integer multiple of the preset size, the row and column sizes of the weight data block are adjusted to integer multiples of the preset size by padding rows and columns with zeros, and then the adjusted weight data block is divided into sub-weight data blocks according to the same steps; According to the convolution calculation cycle mode of the standard convolution layer and the depth-wise convolution layer, as well as the position index of each input feature map data block in the input feature map and the position index of each sub-weight data block in the convolution kernel, the convolution calculation order of the input feature map data block and each sub-weight data block of each convolution layer is determined.

6. The method for calculating depth-wise convolution by fully multiplexing GEMM and ALU architecture according to claim 1, characterized in that: The step 3 comprises the following specific steps: GEMM performs convolution calculations on the input feature map data blocks and sub-weight data blocks of each calculation cycle in turn to obtain the corresponding output feature map data blocks. The standard convolution adopts channel parallelism and convolution kernel parallelism on GEMM, wherein the single-channel calculation unit of GEMM implements the convolution kernel parallelism of the standard convolution, and the multiplier-accumulator in each single-channel calculation unit implements channel parallelism; Depth-wise convolution adopts channel parallelism on GEMM, and each channel performs Depth-wise convolution calculation independently. The single-channel calculation unit of GEMM implements the channel parallelism of Depth-wise convolution, and the multiplier-accumulator of each single-channel calculation unit obtains the independent convolution sum of each channel. If the size of the sub-weight data block of the Depth-wise convolution layer is larger than the number of multiplier-accumulators in the single-channel calculation unit, it is necessary to split the sub-weight data block when reusing GEMM to implement Depth-wise convolution, and divide the convolution calculation of the input feature map data and weight data into two calculation cycles.

7. The method for calculating depth-wise convolution by fully multiplexing GEMM and ALU architecture according to claim 1, characterized in that: In step 3, when processing the standard convolution layer, the input of the GEMM architecture of the present application is the input feature map data block and the weight data block, the data in each weight data block comes from the convolution kernels processed in parallel, the number of convolution kernels processed in parallel is equal to the preset number of single-channel computing units, the number of channels of each input feature map data block and sub-weight data block processed by GEMM each time is equal to the number of multipliers and accumulators of the single-channel computing unit, and when processing the Depth-wise convolution layer, the input of the GEMM and ALU architecture is the input feature map data block and sub-weight data block, the number of channels of each input feature map data block and each sub-weight data block is equal to the number of single-channel computing units, and the number of input feature map data and weight data processed by each single-channel computing unit in each computing cycle of GEMM is less than or equal to the number of multipliers and accumulators in the single-channel computing unit.

8. The method for calculating depth-wise convolution by fully multiplexing GEMM and ALU architecture according to claim 1, characterized in that: In step 3, the GEMM and ALU architecture calculation uses a four-layer loop to complete the Depth-wise convolution. During the Depth-wise convolution process, the first layer is the number of groups in which the input feature map is divided according to the preset number of channel parallelism, that is, the number of input feature map data blocks, and the output feature map data is also output in a channel parallel manner; the second layer of loop is the number of groups obtained by dividing the weight data block according to the preset size, that is, the number of sub-weight data blocks in each weight data block. Therefore, for the next three layers of loops, the Depth-wise convolution is implemented by weight reuse, and each sub-weight data block corresponds to a partial sum of an output feature map data block; the third and fourth layers are the length and width of the output feature map data block, respectively. GEMM obtains the intermediate results of the output feature map row by row and writes them into a dedicated storage output In the on-chip memory of the feature map intermediate result, while calculating the output feature map result, the intermediate result with the same position as the current output feature map data is read from the on-chip buffer, and the convolution and addition are obtained with the current calculation cycle. After obtaining the new intermediate result, it is written back to the on-chip memory, and the address is the same as the address when reading. If the size of the sub-weight data block of the Depth-wise convolution layer is larger than the number of multipliers and accumulators in the single-channel computing unit, the sub-weight data block is split into two parts. The number of weight data in the first part is equal to the number of multipliers and accumulators, and the second part is the remaining weight data. The convolution calculation of the input feature map data and the weight data is completed on the GEMM architecture and the ALU architecture respectively. When the second layer loop is executed to the last one, the result obtained by addition is the final data of the output feature map data.

9. The method for calculating depth-wise convolution by fully multiplexing GEMM and ALU architecture according to claim 1, characterized in that: The step 4 includes the following specific steps: according to the description of the four-layer loop body in step 3, an output feature data block is obtained after the last three layers of loops. The size of the output feature map data block is equal to the parameters in the third and fourth layers of loops. There are two cases for calculating the output feature map data. The first case is that the size of the weight data block is less than or equal to the preset size, and the other case is that the size of the weight data block is greater than the preset size. If the size of the weight data block is less than or equal to the preset size, there is only one weight sub-data block, and the second layer loop will only be executed once. When the third and fourth layers of loops are completed, the result is the final output feature map data block. According to the position index of the current output data block in the entire output feature map data and the base address of the output data in the on-chip buffer, the starting address of the output feature map data block in the on-chip buffer is determined, and then the output feature map data block is written to the on-chip buffer; if the size of the weight data block is greater than the preset size Inch, there will be multiple weight sub-data blocks, the second layer loop will be executed multiple times, the inner two layers of loops, namely the third and fourth layers, get the intermediate results of the output feature map, this part of the data is written into the register, and participates in the accumulation in the subsequent loops. After the second layer loop ends, all the intermediate results with the same index are accumulated to get the final output feature map data. The number of channels of the output feature map of the Depth-wise convolution layer is the same as the number of channels of the input feature map. Therefore, the index of the input channel number of the first layer loop is also the index of the output channel number. According to the index of the current output feature map data block and the base address of the output data in the on-chip buffer, the starting address of the output feature map data block in the on-chip buffer is determined, and the output feature map data block is written back to the on-chip buffer. After the first layer loop ends, all the output feature map data are obtained, and they are written into the off-chip memory in sequence according to the storage format of the output feature map data in the off-chip memory.

10. A computing device that fully multiplexes GEMM and ALU architecture to implement Depth-wise convolution, characterized in that: include: The off-chip memory and on-chip cache related to data storage, the data handling module and depth-wise computing module related to data computing, where the depth-wise computing module includes the GEMM architecture and the ALU architecture; The GEMM architecture and ALU architecture determine the four-layer loop sequence of the Depth-wise convolution, the first layer is the number of groups into which the input feature map is divided according to the preset number of channel parallelism, that is, the number of input feature map data blocks, and the output feature map data is also output in a channel parallel manner; the second layer loop is the number of groups obtained by dividing the weight data block according to the preset size, that is, the number of sub-weight data blocks in each weight data block, so for the next three layers of loops, the Depth-wise convolution is implemented by weight reuse, and each sub-weight data block corresponds to a partial sum of an output feature map data block; the third and fourth layers are the length and width of the output feature map data block, respectively, and the GEMM obtains the intermediate result of the output feature map row by row, and writes it into an on-chip memory specifically storing the intermediate result of the output feature map. According to these four layers of loops, the transport order and calculation order of the input image data and the weight data are determined, and according to the transport order, the data transport module transports the input image data and the weight data from the off-chip memory to the on-chip buffer; The computing module has a selector controlled by the computing mode field in the instruction, which distinguishes between standard convolution and depth-wise convolution. For the standard convolution mode, GEMM calculation and ALU calculation will independently perform channel parallel calculation, which is determined according to the calculation type field in the instruction, and the data that needs to be read from the on-chip buffer during the calculation process is determined at the same time. For the depth-wise convolution mode, GEMM calculation and ALU calculation are performed simultaneously. Both GEMM and ALU adopt a channel parallel mode. The intermediate results of the corresponding channels in the GEMM architecture and the ALU architecture are accumulated in the ALU, and finally the output result of the number of parallel channels is obtained. According to the calculation order of the depth-wise convolution, the computing module determines the data address in the on-chip buffer, reads it into the GEMM architecture and the ALU architecture through the data interface, calculates and accumulates the intermediate results in the GEMM architecture, and the intermediate results are used as the input data of the ALU architecture, and are accumulated with the convolution result in the ALU to obtain the convolution sum of the number of parallel channels, and written into the on-chip buffer. The device has a selector controlled by the mode field in the instruction. Under the control of the first-layer loop body, the output results in the on-chip buffer are transferred to the off-chip memory through the data transfer module, and the next round of depth-wise convolution calculation of the input image data and weight data is started at the same time.

Citation Information

Patent Citations

  • FPGA implementation method of sparse weight Fused-Layer convolution accelerator structure

    CN115688892A

  • Convolution calculation method and device

    CN116258171A

  • Dethwise convolution calculation device and method based on deconvolution mapping

    CN116933851A

  • Exploiting shared dimensions in matrix computations

    US20230252106A1

  • Streaming-based compute unit and method, and artificial intelligence chip

    US20240220203A1

Cited By

  • Neural network hardware acceleration device and method

    CN121351906A

  • A neural network hardware acceleration apparatus and method

    CN121351906B

  • FPGA-based YOLO detection network and implementation method thereof

    CN121960615A