Data processing method, device and equipment
By performing data packaging and inner product operations on the DSP chip, combined with the use of a two-dimensional DMA controller, the storage and operation of convolution kernel parameters are optimized, which solves the problem of low convolution operation efficiency of the DSP chip and achieves more efficient convolution. deal with.
Patent Information
- Application Number
- CN201911143301.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-11-20
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2039-11-20
AI Technical Summary
The DSP chip has low read and write bandwidth when performing convolution operations, resulting in low efficiency. It is necessary to improve the efficiency of convolution operations.
By packaging and inner product operations on the data to be convolved, inner product instructions and accumulation instructions are used for calculations, and data is moved and completed through a two-dimensional DMA controller to optimize the storage and use of convolution kernel parameters and simplify the calculation process.
It improves the efficiency of convolution operations, reduces the number of data moves, and improves the efficiency of convolution processing of target images.
Smart Images

Figure CN112825151B
Abstract
Description
Technical Field
[0001] The present disclosure relates to computer vision technology, and in particular to a data processing method, device and equipment. Background Art
[0002] DSP (digital signal processor) microprocessors can be used as on-end image processing or deep learning chips. However, some DSP chips have low read and write bandwidth when performing convolution operations. How to improve the efficiency of DSP convolution operations is an urgent problem to be solved. Summary of the invention
[0003] The embodiments of the present disclosure provide a data processing method, apparatus and device.
[0004] According to one aspect of the present disclosure, a data processing method is proposed, the method comprising: packing the data to be convolved in units of P columns and M input channels to obtain multiple first data elements; the convolution kernel parameters include S*S first parameter elements, each first parameter element includes M input channels and N output channels, wherein the data to be convolved is obtained based on a target image; performing an inner product operation on each of the first parameter elements and the corresponding first data element in a first data block through an inner product instruction to obtain an inner product result corresponding to each first parameter element, wherein the first data block includes each first data element obtained by performing a first windowing S times on each of S consecutive rows of the data to be convolved with a set step size; accumulating the inner product results corresponding to each of the first parameter elements through an accumulation instruction to obtain a first accumulation result; and obtaining a data processing result based on the first accumulation result.
[0005] In combination with any embodiment provided in the present disclosure, obtaining the data processing result based on the first accumulation result includes: performing a second window on the data to be convolved based on the M input channels of the first data block to obtain each first accumulation result corresponding to the second window on the input channel each time; accumulating the each first accumulation result to obtain a second accumulation result; and obtaining the data processing result based on the second accumulation result.
[0006] In combination with any embodiment provided in the present disclosure, the data processing result is obtained based on the second accumulation result, including: performing a third windowing on the data to be convolved row by row in the column direction in units of a first data block containing all input channels, and obtaining second accumulation results corresponding to each third windowing in the column direction; after offsetting P columns, repeating the third windowing in the column direction row by row until offsetting to Q columns, and obtaining multiple second accumulation results; successively offsetting M output channels on the output channel of the data to be convolved, and obtaining the multiple second accumulation results corresponding to each offset on the output channel; expanding the obtained second accumulation results on the rows, columns, and output channels of the data to be convolved to obtain the data processing result.
[0007] In combination with any embodiment provided by the present disclosure, the obtained second accumulation results are expanded on the rows, columns, and output channels of the data to be convolved to obtain the target expansion result, including: expanding the second accumulation result corresponding to the data to be convolved in the column direction on the column to obtain the first expansion result; expanding the first expansion result corresponding to the Q column on the row to obtain the second expansion result; expanding the second expansion result corresponding to the output channel on the output channel to obtain the data processing result.
[0008] In combination with any embodiment provided by the present disclosure, the convolution kernel parameters are parameters formed by the difference between each element in the initial convolution kernel and the convolution kernel quantization zero point; the inner product instruction is used to perform an inner product operation on each of the first parameter elements and the corresponding first data element in the first data block to obtain the inner product result corresponding to each first parameter element, including: adding the result of the inner product operation to a constant to obtain the inner product result, wherein the constant is obtained according to the product of the quantization zero point of the data to be convolved and the convolution kernel parameters and the bias of the convolution operation.
[0009] In combination with any embodiment provided by the present disclosure, before the convolution kernel parameters are set to include M input channels and N output channels, and S*S first parameter elements are obtained for the convolution kernel parameters of size S*S, the method also includes: moving the convolution kernel parameters to a first storage area, and moving the data to be convolved to a second storage area, wherein the first storage area is a storage area that uses a set step size to control sliding, and the inner product instruction is a multiplication and accumulation instruction with a step size sliding window.
[0010] In combination with any implementation provided in the present disclosure, the method further includes: moving the data to be convolved to the second storage area through a two-dimensional DMA controller.
[0011] In combination with any implementation manner provided in the present disclosure, the method further includes: performing a padding operation on the data to be convolved in the second storage area in a column direction.
[0012] According to one aspect of the present disclosure, a data processing method is proposed, the method comprising: moving data to be convolved to a storage area through a two-dimensional DMA controller, wherein the data to be convolved is obtained based on a target image; performing a padding operation in the column direction on the data to be convolved in the storage area; and performing a convolution operation on the data stored in the storage area by calling a convolution instruction, wherein an instruction for performing a padding operation in the row direction is loaded at a set position in the convolution instruction.
[0013] According to one aspect of the present disclosure, a data processing device is proposed, the device comprising: a packing unit, used to pack the data to be convolved in units of P columns and M input channels to obtain multiple first data elements; a convolution kernel parameter comprising S*S first parameter elements, each first parameter element comprising M input channels and N output channels, wherein the data to be convolved is obtained based on a target image; an inner product unit, used to perform an inner product operation on each of the first parameter elements and a corresponding first data element in a first data block through an inner product instruction to obtain an inner product result corresponding to each first parameter element, wherein the first data block comprises each first data element obtained by performing a first windowing S times on each of S consecutive rows of the data to be convolved with a set step size; an accumulation unit, used to accumulate the inner product results corresponding to each of the first parameter elements through an accumulation instruction to obtain a first accumulation result; an obtaining unit, used to obtain a data processing result according to the first accumulation result.
[0014] In combination with any embodiment provided in the present disclosure, the obtaining unit is specifically used to: perform a second window on the data to be convolved based on the M input channels of the first data block to obtain first cumulative results corresponding to each second window on the input channel; add up the first cumulative results to obtain a second cumulative result; and obtain a data processing result based on the second cumulative result.
[0015] In combination with any embodiment provided in the present disclosure, when the obtaining unit is used to obtain the data processing result according to the second accumulation result, it is specifically used to: perform a third windowing on the data to be convolved row by row in the column direction with the first data block containing all input channels as a unit, and obtain each second accumulation result corresponding to the third windowing in the column direction each time; after shifting P columns, repeat the third windowing in the column direction row by row until it shifts to Q columns, and obtain multiple second accumulation results; shift M output channels successively on the output channel of the data to be convolved, and obtain the multiple second accumulation results corresponding to each shift on the output channel; expand each second accumulation result obtained on the rows, columns, and output channels of the data to be convolved, and obtain the data processing result.
[0016] In combination with any embodiment provided by the present disclosure, when the obtaining unit is used to expand the obtained second accumulation results on the rows, columns, and output channels of the data to be convolved to obtain the data processing result, it is specifically used to: expand the second accumulation results corresponding to the data to be convolved in the column direction on the column to obtain the first expanded result; expand the first expanded result corresponding to the Q column on the row to obtain the second expanded result; expand the second expanded result corresponding to the output channel on the output channel to obtain the data processing result.
[0017] In combination with any embodiment provided by the present disclosure, the convolution kernel parameters are parameters formed by the difference between each element in the initial convolution kernel and the convolution kernel quantization zero point. When the inner product unit is used to perform an inner product operation on each of the first parameter elements and the corresponding first data element in the first data block through an inner product instruction to obtain the inner product result corresponding to each first parameter element, it is specifically used to: add the result of the inner product operation to a constant to obtain the inner product result, wherein the constant is obtained according to the product of the quantization zero point of the data to be convolved and the convolution kernel parameters and the bias of the convolution operation.
[0018] In combination with any embodiment provided by the present disclosure, the device also includes a moving unit for moving the convolution kernel parameters to a first storage area and the data to be convolved to a second storage area before setting the convolution kernel parameters to include M input channels and N output channels and obtaining S*S first parameter elements for the convolution kernel parameters of size S*S, wherein the first storage area is a storage area that uses a set step size to control sliding, and the inner product instruction is a multiplication and accumulation instruction with a step size sliding window.
[0019] In combination with any embodiment provided in the present disclosure, the device further includes a sub-moving unit, which is used to move the data to be convolved to the second storage area through a two-dimensional DMA controller.
[0020] In combination with any embodiment provided in the present disclosure, the device further includes a padding unit for performing a padding operation on the data to be convolved in the second storage area in a column direction.
[0021] According to one aspect of the present disclosure, a data processing device is proposed, comprising: a moving unit, used to move data to be convolved to a storage area through a two-dimensional DMA controller, wherein the data to be convolved is obtained based on a target image; a padding unit, used to perform padding operations on the data to be convolved in the storage area in the direction of columns; and an operation unit, used to perform convolution operations on the data stored in the storage area by calling convolution instructions, wherein instructions for performing padding operations in the direction of rows are loaded at a set position in the convolution instructions.
[0022] According to one aspect of the present disclosure, a data processing device is provided, the device comprising a memory and a processor, the memory being used to store computer instructions executable on the processor, the processor being used to implement the method described in any embodiment of the present disclosure when executing the computer instructions.
[0023] According to one aspect of the present disclosure, a computer-readable storage medium stores a computer program, and when the program is executed by a processor, the method described in any embodiment of the present disclosure is implemented.
[0024] The data processing method, device and equipment provided by the embodiments of the present disclosure pack the data to be convolved in rows, columns and input channels to obtain multiple first data elements, perform inner product operation on the first parameter element contained in the convolution kernel parameter and the corresponding first data element in the first data block, and accumulate each first parameter element, obtain each accumulation result by traversing the first data block in the data to be convolved, and obtain the final convolution result by accumulation and expansion. The entire convolution process can reuse the data to be convolved and the convolution kernel parameters for convolution operation to the greatest extent, simplify the calculation process, and improve the efficiency of convolution operation. In addition, by using a two-dimensional DMA controller to move the data to be convolved to the storage area, and padding in the column direction, the padding operation in the row direction is implemented in the core algorithm, thereby reducing the number of data moves and improving the convolution processing efficiency for the target image.
[0025] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the specification and, together with the description, serve to explain the principles of the specification.
[0027] Figure 1 is a flow chart of a data processing method proposed by at least one embodiment of the present disclosure;
[0028] Figure 2 is a schematic diagram of a first data block in a data processing method provided by at least one embodiment of the present disclosure;
[0029] Figure 3 is a schematic diagram of data grouping in a data processing method proposed in at least one embodiment of the present disclosure;
[0030] Figure 4 is a schematic diagram of the operation process of the data processing method proposed in at least one embodiment of the present disclosure;
[0031] Figure 5is a flowchart of another data processing method proposed by at least one embodiment of the present disclosure;
[0032] Figure 6 is a structural schematic diagram of a data processing device proposed in at least one embodiment of the present disclosure;
[0033] Figure 7 is a structural schematic diagram of another data processing device proposed by at least one embodiment of the present disclosure;
[0034] Figure 8 It is a structural schematic diagram of a convolution operation device proposed in at least one embodiment of the present disclosure. DETAILED DESCRIPTION
[0035] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0036] Figure 1 FIG. 1 is a flow chart showing a data processing method according to some embodiments of the present disclosure. Figure 1 As shown, the method includes steps 101 to 104.
[0037] In step 101, the data to be convolved is packaged in units of P columns and M input channels to obtain a plurality of first data elements, wherein the data to be convolved is obtained based on a target image.
[0038] In the disclosed embodiment, the default input and output data format of the data to be convolved based on the target image is IC×H×W, where IC is the input channel, H is the height, and W is the width. According to the minimum size multiplication supported by the DSP that performs the convolution operation, the data to be convolved can be packed for each row, and the data of the P columns and M input channels corresponding to each row can be packed into a first data element, thereby obtaining multiple first data elements. That is, for the data to be convolved, the number of first data elements included is: (number of input channels / M)*number of rows*(number of columns / P)*number of output channels.
[0039] Those skilled in the art should understand that the target image may be a video image or an image acquired in real time, and the present disclosure does not limit this.
[0040] In the disclosed embodiment, the input and output format of the convolution kernel parameters is OC×IC×H×W, where OC is the output channel, IC is the input channel, H is the height, and W is the width. When the convolution kernel size is S*S, the convolution kernel parameters include S*S first parameter elements, each of which includes M input channels and N output channels, that is, M*N bits of data. Usually, the number of input channels is equal to the number of output channels, that is, M=N.
[0041] In step 102, an inner product operation is performed on each of the first parameter elements and the corresponding first data element in the first data block through an inner product instruction to obtain an inner product result corresponding to each of the first parameter elements.
[0042] Each first parameter element of the convolution kernel parameter includes M input channels and N output channels, that is, includes M*N bits of data. For example, for a convolution kernel of size 3*3, when it includes 4 input channels and 4 output channels, each first parameter element includes 4*4 bits of data, as shown in Table 1, where i represents an input channel and o represents an output channel.
[0043] Table 1
[0044] i0o0 i1o0 i2o0 i3o0 i0o1 i1o1 i2o1 i3o1 i0o2 i1o2 i2o2 i3o2 i0o3 i1o3 i2o3 i3o3
[0045] A first data element of the data to be convolved, as described in step 101, includes P columns and M input channels. For example, in the case of 4 columns and 4 input channels, as shown in Table 2, i represents the input channel and w represents the column.
[0046] Table 2
[0047] w0i1 w1i0 w2i0 w3i0 w0i1 w1i1 wxya w3i1 w0i2 w1i2 w2i2 w3i2 w0i3 w1i3 w2i3 w3i3
[0048] The first data block includes first data elements obtained by performing first windowing S times on each of S consecutive rows of the data to be convolved with a set step size.
[0049] For example, when the convolution kernel size is 3*3, the first data block includes the first elements obtained by performing the first windowing three times with a step size of 1 for three consecutive rows (H0, H1, H2) of the convolution data. Figure 2 Exemplary first data elements are shown. Figure 2As shown, for the H0 row, the first element obtained by each first windowing is W0-3 in the column direction, that is, (0 1 2 3), the first element obtained for the second time is W1-4 (1 2 3 4) in the column direction, and the first element obtained for the third time is W2-5 (2 3 4 5) in the column direction. It should be noted that each first element contains 4 columns and 4 input channels, so W0-3, W1-4, and W2-5 all correspond to 4 input channels. For the H1 row and the H2 row, the first windowing is performed in a similar manner to obtain the corresponding first data elements. Corresponding to the case where the convolution kernel size is 3*3 and the step size is set to 1, the first data block is a data block of 3 rows and 6 columns. Similarly, when the step size is set to 2, the first data block is a data block of 3 rows and 8 columns, and so on.
[0050] The inner product operation is performed on each of the first parameter elements and the corresponding first data element in the first data block through the inner product instruction to obtain the inner product result corresponding to each of the first parameter elements. For example, the inner product result can be stored in an inner product matrix containing M columns and P columns.
[0051] Taking the inner product operation of a first parameter element in Table 1 and a first data element in Table 2 as an example, the inner product result is stored in a 4*4 inner product matrix, where the rows correspond to the output channels of the convolution kernel parameters, as shown in Table 3, where w represents the column and o represents the output channel.
[0052] Table 3
[0053] w0o0 w1o0 w2o0 w3o0 w0o1 w1o1 w2o1 w3o1 w0o2 w1o2 w2o2 w3o2 w0o3 w1o3 w2o3 w3o3
[0054] In step 103, the inner product results corresponding to the first parameter elements are accumulated through an accumulation instruction to obtain a first accumulation result.
[0055] Each first parameter element of the convolution kernel parameter performs an inner product operation with the corresponding first data element in the first data block, and the inner product results corresponding to each first parameter element are accumulated to obtain a first accumulated result. The first accumulated result is also stored in the inner product matrix of M columns and P columns.
[0056] In step 104, a data processing result is obtained according to the first accumulation result.
[0057] For all first data blocks contained in the data to be convolved, the corresponding first accumulation results are obtained, and then the convolution operation on the convolution kernel parameters and the data to be convolved can be implemented to obtain the data processing result.
[0058] The data processing method provided by the embodiment of the present disclosure packs the data to be convolved in rows, columns, and input channels to obtain multiple first data elements, performs an inner product operation on the first parameter elements contained in the convolution kernel parameters and the corresponding first data elements in the first data block, and accumulates each first parameter element, obtains each accumulation result by traversing the first data block in the data to be convolved, and obtains the final data processing result by accumulation and expansion. The entire convolution process can reuse the data to be convolved and the convolution kernel parameters for the convolution operation to the greatest extent, simplifies the calculation process, and improves the convolution processing efficiency for the target image.
[0059] In some embodiments, the following method may be used to obtain a data processing result based on the first accumulation result.
[0060] First, the data to be convolved is second-windowed in units of the M input channels of the first data block to obtain first cumulative results corresponding to each second windowing on the input channel. The first data block itself includes M input channels, and by successively shifting the M channels on the input channels, the second windowing of the data to be convolved can be performed on the input channels in units of the M input channels to obtain first cumulative results corresponding to all first data blocks contained on the input channels.
[0061] For each acquired first data block, by performing steps 102 and 103 as described above, each first accumulation result corresponding to the first data block can be obtained.
[0062] Next, each first accumulation result is accumulated to obtain a second accumulation result. The second accumulation result can also be stored in an inner product matrix with M rows and P columns.
[0063] The second accumulated result obtained above is the accumulated result of the first data block on all input channels. Next, the corresponding second accumulated result is obtained for the first data block (the first data block corresponds to all input channels of the data to be convolved) contained in the rows, columns, and output channels of the data to be convolved, and the convolution operation on the convolution kernel parameters and the data to be convolved can be implemented to obtain the data processing result.
[0064] In some embodiments, the target convolution may be obtained according to the second accumulation result in the following manner.
[0065] First, the data to be convolved is subjected to a third windowing in the column direction row by row, taking the first data block containing all input channels as a unit, to obtain each second cumulative result corresponding to each third windowing in the column direction. That is, the third windowing is performed row by row in the H direction of the data to be convolved, and each third windowing obtains the corresponding data in the corresponding first data block, and the first cumulative result is obtained by performing inner product operations and accumulation operations with multiple first parameter elements contained in the convolution kernel parameters, and then the accumulation is performed on all input channels to obtain the second cumulative result. By completing the third windowing in the H direction, that is, traversing the H direction, all the second cumulative results corresponding to the H direction are obtained.
[0066] Next, windowing is performed in the W direction. Specifically, after shifting P columns, the third windowing is repeated row by row in the column direction. That is, after shifting P columns, windowing is repeated in the H direction at the shifted position to obtain each second accumulation result in the H direction corresponding to the shifted column position. Repeat the shifting until Q columns are shifted to obtain multiple corresponding second accumulation results, where the number of shifted columns is the set step size for the shifting.
[0067] That is, when Q is the number of columns of the data to be convolved, this step can obtain the second accumulated result on the entire column; when Q is a partial number of columns, it is necessary to perform more than one convolution operation to obtain the data processing result. The specific number of bits included in Q can be determined according to the size of the area storing the data to be convolved.
[0068] Then, M output channels are successively shifted on the output channel of the data to be convolved to obtain the multiple second cumulative results corresponding to each shift on the output channel. The first data block itself includes M output channels, and the M channels are successively shifted on the output channel of the data to be convolved, that is, the third windowing on the output channel is implemented to obtain all the first data blocks included in the output channel, so that each second cumulative result corresponding to the first data block on the output channel can be obtained.
[0069] Each second accumulation result obtained in the above process is stored in its corresponding matrix. The matrix includes M output channels, P columns (corresponding to W dimensions), and M input channels. Next, each second accumulation result is expanded on each dimension of the data to be convolved, including rows, input and output channels, that is, the matrices corresponding to each second accumulation result are arranged on each dimension, and the data processing result is obtained by the expansion result.
[0070] Specifically, the second accumulated results corresponding to the data to be convolved in the column direction are expanded in the column to obtain the first expanded results. That is, each second accumulated result is first expanded in the H direction.
[0071] Next, the first expansion result corresponding to the Q column is expanded on the row to obtain the second expansion result. The result that has been expanded in the H direction is further expanded in the W direction.
[0072] Finally, the corresponding second expansion result on the output channel is expanded on the output channel to obtain the target convolution result. That is, for the results expanded in the H direction and the W direction, the final expansion result obtained is the data processing result.
[0073] The following uses an XM4 DSP chip to perform the convolution operation of the embodiment of the present disclosure as an example to describe the data processing method in detail.
[0074] The convolution operation can be expressed by formula (1):
[0075] f(i) = conv(i,w)+bias (1)
[0076] Among them, i is the input data, that is, the data to be convolved, w is the filter data, that is, the convolution kernel parameter, conv is the convolution operator, and bias is the bias of the convolution operation.
[0077] Corresponding to the convolution operation formula (1), the convolution operation formula of int8 quantization is as follows:
[0078] f(i) = conv((i-izero),(w-wzero)) + bias (2)
[0079] Where, izero, wzero are the quantization zero points of i and w respectively, izero, w, wzero are constants, i, izero, w, wzero are all 8 bits, and bias is 32 bits. If a general quantization scheme of 8bit*8bit is used, the convolution is expanded into two convolution calculations and two additions. In the embodiment of the present disclosure, w-wzero is merged into wnew
[0080] (16bit), the convolution formula (2) can be simplified to:
[0081]
[0082] Among them, conv(i,wnew) is obtained through an 8bit*16bit convolution calculation, and -conv(izero,wnew)+bias is a 32bit constant that can be calculated in advance. Therefore, through the above quantization method, the int8 convolution is simplified to a regular convolution and a vector addition.
[0083] In the embodiment of the present disclosure, the core instructions (core functions) of the XM4 DSP are used in combination with the quantization method described above to implement the convolution operation. Specifically, in the data processing method proposed in the embodiment of the present disclosure, the convolution kernel parameter is a parameter formed by the difference between each element in the applied convolution kernel and the convolution kernel quantization zero point. By executing the core instruction, an inner product operation is performed on one of the first parameter elements of the convolution kernel parameter and a first data element, including: adding the result of the inner product operation to a constant to obtain the inner product result, wherein the constant is obtained according to the product of the quantization zero point of the data to be convolved and the convolution kernel parameter and the bias of the convolution operation.
[0084] For XM4 DSP, the word length of the data area is 16 bits, and it is a storage area that can be controlled by step size; while the word length of the filter area is 8 bits, and it is a storage area that selects the starting position by setting the offset. In order to be applicable to the 8bit*16bit quantization scheme described above, the embodiment of the present disclosure proposes a scheme to reverse the positions of the data to be convolved and the convolution kernel parameters in the instruction area.
[0085] The convolution kernel parameters can be moved to the data area, where the data area can be referred to as the first storage area; corresponding to the data to be convolved, they can be moved to the filter area, where the filter area can be referred to as the second storage area.
[0086] For the data stored in the first storage area and the second storage area, a convolution operation is performed on the data in the first storage area and the second storage area by calling the core instruction of the XM4 DSP.
[0087] In one example, for the first storage area with a word length of 16 bits, the data of the convolution kernel parameters placed therein can be set to the format of 4OC (output channel) * 4IC (input channel) during the convolution operation. For one of the first parameter elements of the convolution kernel parameters (a filter factor), by expanding the filter factor to 4OC*4IC*16bit, and when the set step size (step size) of the first storage area is 4, it can be ensured that each instruction processes the multiplication and accumulation of a filter factor of 4IC*4OC. This method makes the instruction insensitive to the size of the convolution kernel and can be applied to convolution kernels of different lengths and steps.
[0088] In one example, for the second storage area with a word length of 8 bits, the data to be convolved is packed during the convolution operation, and the format of each first data element generated is N4CHW, and the corresponding number of bits is 8bit*4IC*8W. Here, the data can be further divided into two groups, each group corresponding to 4 W positions (4 columns), and the convolution multiplication and accumulation calculation of 8 W positions can be processed by two core instructions.
[0089] Taking the convolution kernel size of 3*3 as an example, the convolution kernel parameters can be recorded as filter0 to 8. For each filter factor, the format is 4OC*4IC; for the data to be convolved, IC4 is packed by default, and each first data element after packing includes 4W*IC4.
[0090] For each core instruction, an inner product operation is performed on a filter factor and a packing unit. By executing 9 core instructions, inner product operations are performed on 9 filter factors respectively. That is, by using 9 core instructions, OC4*IC4*4 convolution calculations can be implemented. Since the next instruction reuses the filter factor data, there is no need to read the data again. Therefore, the convolution operation efficiency is 4*4*8*9 / 9*64=100%.
[0091] In one example, for three-dimensional (3D) data to be convolved, the data to be convolved may be moved to the second storage area through two-dimensional DMA (2D-Direct Memory Access).
[0092] For three-dimensional data to be convolved, padding is performed and the data movement includes at least three dimensions. In the embodiment of the present disclosure, the data to be convolved in the second storage area is padded in the column direction. The data grouping method and padding method proposed in the embodiment of the present disclosure enable the convolution operation of three-dimensional data to be realized by using 2D-DMA with one data movement.
[0093] Figure 3 A data grouping method is provided for at least one embodiment of the present disclosure. Figure 3 As shown in , the data to be convolved is represented by a cube, which includes input channel C, H dimension, and W dimension. Figure 3 As shown in FIG. 1 , after the data to be convolved is moved to the second storage area, padding is performed only in the W dimension, that is, only in the column direction. 0 is padded at both ends of the W dimension, but no 0 is padded in the H dimension. That is, by Figure 2The data grouping method shown in the figure can realize the dimensioning method of (w+2*pad,h*4ic) for 4 input channels, where pad represents the number of bits filled with 0. Through the above method, it can be ensured that 2D-DMA will not become the bottleneck of XM4 DSP for convolution operation. Accordingly, it is necessary to add padding operations on unprocessed dimensions in the core instructions, such as processing branches for padding operations in the column direction. For example, by installing a 0 value (zero value) at a specific position in the function, it is equivalent to increasing the code size. In the DSP system, each core instruction downloads a code and concentrates on computing a large amount of data, so the code size will not become a system bottleneck.
[0094] In the disclosed embodiment, the convolution operation can be implemented through two stages: preprocessing and real-time processing. Figure 4 As shown, in the preprocessing stage, the convolution kernel parameter wnew and the constant con are set. The convolution kernel parameter wnew is set according to the difference between the initial convolution kernel w and the convolution kernel quantization zero point wzero, and the constant con is set to the product of the quantization zero point izero of the data to be convolved and the convolution kernel parameter wnew and the bias of the convolution operation, for example, it can be set to bias-izero*wnew.
[0095] In the real-time processing stage, the dimension reduction method (w+2*pad,h*4ic) as described above is used to move the padded data to be convolved to the data storage area through 2D-DMA, and the convolution operation is performed on the convolution data and the convolution kernel parameter wnew by calling the core instruction. In addition to the core instruction, the convolution operation of all data on the W dimension is realized by looping on the W dimension of the data to be convolved, and then the convolution result is quantized and the data processing result is output.
[0096] Through the above data processing method, register data is reused to the greatest extent through data grouping on input channels, H dimensions, and W dimensions. This method is highly versatile and applicable to convolution kernels of all sizes. For XM4 DSP, it can make full use of the 8*16 multiplier width and convert the int 8 quadratic convolution into one convolution operation and one addition operation, which simplifies the convolution operation and improves the operation efficiency. In addition, the 4-way accumulation of XM4 DSP matches the data format of the packed 4 channels, and the input and output are always in 4-channel format without additional conversion.
[0097] Figure 5 A data processing method proposed in at least one embodiment of the present disclosure is shown, and the method includes steps 501 to 503.
[0098] In step 501, the data to be convolved is moved to a storage area through a two-dimensional DMA controller, wherein the data to be convolved is obtained based on a target image.
[0099] In step 502, a padding operation is performed on the to-be-convolved data in the storage area in a column direction.
[0100] In step 503, a convolution operation is performed on the data stored in the storage area by calling a convolution instruction, wherein the convolution instruction loads an instruction for performing a padding operation in a row direction at a set position.
[0101] In the disclosed embodiment, a two-dimensional DMA controller is used to move the data to be convolved to a storage area and pad the data in the column direction. The padding operation in the row direction is implemented in the core algorithm, thereby reducing the number of data moves and improving the efficiency of the convolution operation.
[0102] Figure 6 A data processing device is provided for at least one embodiment of the present disclosure, such as Figure 6 As shown, the device may include:
[0103] A packing unit 601 is used to pack the convolution data in units of P columns and M input channels to obtain multiple first data elements; the convolution kernel parameters include S*S first parameter elements, each of which includes M input channels and N output channels;
[0104] An inner product unit 602 is used to perform an inner product operation on each of the first parameter elements and a corresponding first data element in a first data block through an inner product instruction to obtain an inner product result corresponding to each of the first parameter elements, wherein the first data block includes each of the first data elements obtained by performing a first windowing S times on each of S consecutive rows of the data to be convolved with a set step size;
[0105] An accumulation unit 603, configured to accumulate inner product results corresponding to each of the first parameter elements through an accumulation instruction to obtain a first accumulation result;
[0106] The obtaining unit 604 is used to obtain a data processing result according to the first accumulation result.
[0107] In some embodiments, the acquisition unit 604 is specifically used to: perform a second window on the data to be convolved based on the M input channels of the first data block, and obtain each first cumulative result corresponding to each second window on the input channel; accumulate the each first cumulative result to obtain a second cumulative result; and obtain a data processing result based on the second cumulative result.
[0108] In some embodiments, when the obtaining unit 604 is used to obtain the data processing result according to the second accumulation result, it is specifically used to: perform a third windowing on the data to be convolved row by row in the column direction in units of the first data block containing all input channels, and obtain each second accumulation result corresponding to the third windowing in the column direction each time; after shifting P columns, repeat the third windowing in the column direction row by row until it shifts to Q columns, and obtain multiple second accumulation results; shift M output channels successively on the output channel of the data to be convolved, and obtain the multiple second accumulation results corresponding to each shift on the output channel; expand each second accumulation result obtained on the rows, columns, and output channels of the data to be convolved, and obtain the data processing result.
[0109] In some embodiments, when the obtaining unit 604 is used to expand the obtained second accumulation results on the rows, columns, and output channels of the data to be convolved to obtain the data processing result, it is specifically used to: expand the second accumulation results corresponding to the data to be convolved in the column direction on the column to obtain the first expanded result; expand the first expanded result corresponding to the Q column on the row to obtain the second expanded result; expand the second expanded result corresponding to the output channel on the output channel to obtain the data processing result.
[0110] In some embodiments, when the obtaining unit 604 is used to expand the obtained second accumulation results on the rows, columns, and output channels of the data to be convolved to obtain the data processing result, it is specifically used to: expand the second accumulation results corresponding to the data to be convolved in the column direction on the column to obtain the first expanded result; expand the first expanded result corresponding to the Q column on the row to obtain the second expanded result; expand the second expanded result corresponding to the output channel on the output channel to obtain the data processing result.
[0111] In some embodiments, the device further includes a sub-moving unit, configured to move the data to be convolved to the second storage area via a two-dimensional DMA controller.
[0112] In some embodiments, the device further includes a padding unit for performing padding operations on the to-be-convolved data in the second storage area in a column direction.
[0113] Figure 7 A data processing device is provided for at least one embodiment of the present disclosure, such as Figure 7 As shown, the device may include:
[0114] A moving unit 701 is used to move the data to be convolved to a storage area through a two-dimensional DMA controller;
[0115] A padding unit 702, configured to perform a padding operation on the to-be-convolved data in the storage area in a column direction;
[0116] The operation unit 703 is used to perform a convolution operation on the data stored in the storage area by calling a convolution instruction, wherein the convolution instruction loads an instruction for performing a padding operation in a row direction at a set position.
[0117] Figure 8 A data processing device provided for at least one embodiment of the present disclosure comprises a memory and a processor, wherein the memory is used to store computer instructions executable on the processor, and the processor is used to implement the data processing method described in any embodiment of the present disclosure when executing the computer instructions.
[0118] At least one embodiment of the present disclosure further provides a computer-readable storage medium having a computer program stored thereon, and when the program is executed by a processor, the data processing method described in any embodiment of the present disclosure is implemented.
[0119] It should be understood by those skilled in the art that one or more embodiments of the present specification may be provided as a method, system or computer program product. Therefore, one or more embodiments of the present specification may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, one or more embodiments of the present specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0120] The embodiment of the present specification also provides a computer-readable storage medium, which may store a computer program, and when the program is executed by a processor, the steps of the method for detecting the driver's gaze area described in any embodiment of the present specification are implemented, and / or the steps of the method for training the neural network of the driver's gaze area described in any embodiment of the present specification are implemented. Wherein, the "and / or" means at least one of the two, for example, "A and / or B" includes three solutions: A, B, and "A and B".
[0121] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the data processing device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0122] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0123] The embodiments of the subject matter and functional operations described in this specification may be implemented in the following: digital electronic circuits, tangibly embodied computer software or firmware, computer hardware including the structures disclosed in this specification and their structural equivalents, or a combination of one or more of them. The embodiments of the subject matter described in this specification may be implemented as one or more computer programs, i.e., one or more modules in computer program instructions encoded on a tangible non-temporary program carrier to be executed by a data processing device or to control the operation of the data processing device. Alternatively or additionally, the program instructions may be encoded on an artificially generated propagation signal, such as a machine-generated electrical, optical or electromagnetic signal, which is generated to encode information and transmit it to a suitable receiver device for execution by a data processing device. The computer storage medium may be a machine-readable storage device, a machine-readable storage substrate, a random or serial access memory device, or a combination of one or more of them.
[0124] The processes and logic flows described in this specification can be performed by one or more programmable computers executing one or more computer programs to perform corresponding functions by operating on input data and generating output. The processes and logic flows can also be performed by special purpose logic circuits, such as FPGAs (field programmable gate arrays) or ASICs (application-specific integrated circuits), and the apparatus can also be implemented as special purpose logic circuits.
[0125] Computers suitable for executing computer programs include, for example, general and / or special microprocessors, or any other type of central processing unit. Typically, the central processing unit will receive instructions and data from a read-only memory and / or a random access memory. The basic components of a computer include a central processing unit for implementing or executing instructions and one or more memory devices for storing instructions and data. Typically, the computer will also include one or more large-capacity storage devices for storing data, such as magnetic disks, magneto-optical disks, or optical disks, or the computer will be operably coupled to this large-capacity storage device to receive data from it or to transmit data to it, or both. However, the computer does not necessarily have such a device. In addition, the computer can be embedded in another device, such as a mobile phone, a personal digital assistant (PDA), a mobile audio or video player, a game console, a global positioning system (GPS) receiver, or a portable storage device such as a universal serial bus (USB) flash drive, to name a few.
[0126] Computer readable media suitable for storing computer program instructions and data include all forms of non-volatile memory, media and memory devices, including, for example, semiconductor memory devices (e.g., EPROM, EEPROM and flash memory devices), magnetic disks (e.g., internal hard disks or removable disks), magneto-optical disks, and CD ROM and DVD-ROM disks. The processor and memory may be supplemented by, or incorporated in, special purpose logic circuitry.
[0127] Although this specification includes many specific implementation details, these should not be interpreted as limiting the scope of any invention or the scope of protection claimed, but are mainly used to describe the features of the specific embodiments of specific inventions. Certain features described in multiple embodiments in this specification may also be implemented in combination in a single embodiment. On the other hand, the various features described in a single embodiment may also be implemented separately in multiple embodiments or in any suitable sub-combination. In addition, although features may work in certain combinations as described above and even initially claim protection, one or more features from the claimed combination may be removed from the combination in some cases, and the claimed combination may point to a sub-combination or a variation of a sub-combination.
[0128] Similarly, although operations are depicted in a particular order in the accompanying drawings, this should not be understood as requiring that these operations be performed in the particular order shown or performed sequentially, or requiring that all illustrated operations be performed to achieve the desired results. In some cases, multitasking and parallel processing may be advantageous. In addition, the separation of various system modules and components in the above-described embodiments should not be understood as requiring such separation in all embodiments, and it should be understood that the described program components and systems can generally be integrated together in a single software product, or packaged into multiple software products.
[0129] Thus, specific embodiments of the subject matter have been described. Other embodiments are within the scope of the appended claims. In some cases, the actions recited in the claims can be performed in a different order and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the particular order or sequential order shown to achieve the desired results. In some implementations, multitasking and parallel processing may be advantageous.
[0130] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.
Claims
1. A data processing method, characterized in that: The method comprises: The data to be convolved is packaged in units of P columns and M input channels to obtain a plurality of first data elements; the convolution kernel parameters include S*S first parameter elements, each first parameter element includes M input channels and N output channels, wherein the data to be convolved is obtained based on the target image; Performing an inner product operation on each of the first parameter elements and a corresponding first data element in the first data block through an inner product instruction to obtain an inner product result corresponding to each of the first parameter elements, wherein the first data block includes each of the first data elements obtained by performing a first windowing S times on each of the consecutive S rows of the data to be convolved with a set step size; Accumulate the inner product results corresponding to each of the first parameter elements through an accumulation instruction to obtain a first accumulation result; Performing a second windowing on the data to be convolved based on the M input channels of the first data block as a unit, and obtaining first accumulation results corresponding to each second windowing on the input channel; Accumulating the first accumulation results to obtain a second accumulation result; Taking the first data block containing all input channels as a unit, performing a third windowing on the to-be-convolved data row by row in the column direction, and obtaining respective second accumulated results corresponding to each third windowing in the column direction; After shifting to P columns, repeatedly performing the third windowing row by row in the column direction until shifting to Q columns, to obtain a plurality of second accumulation results; Sequentially shifting M output channels on the output channel of the to-be-convolved data to obtain the plurality of second accumulated results corresponding to each shift on the output channel; The obtained second accumulated results are expanded on the rows, columns and output channels of the data to be convolved to obtain the data processing result.
2. The method according to claim 1, characterized in that Expand each of the second accumulated results obtained on the rows, columns, and output channels of the data to be convolved to obtain a target expansion result, including: Expand the second accumulated result corresponding to the data to be convolved in the column direction on the column to obtain a first expanded result; Expand the first expansion result corresponding to column Q on the row to obtain a second expansion result; The second expansion result corresponding to the output channel is expanded on the output channel to obtain a data processing result.
3. The method according to claim 1, characterized in that The convolution kernel parameter is a parameter formed by the difference between each element in the initial convolution kernel and the convolution kernel quantization zero point; the inner product operation is performed on each of the first parameter elements and the corresponding first data element in the first data block through the inner product instruction to obtain the inner product result corresponding to each of the first parameter elements, including: The result of the inner product operation is added to a constant to obtain the inner product result, wherein the constant is obtained according to the product of the quantization zero point of the data to be convolved and the convolution kernel parameter and the bias of the convolution operation.
4. The method according to any one of claims 1 to 3, characterized in that: Before setting the convolution kernel parameters to include M input channels and N output channels and obtaining S*S first parameter elements for the convolution kernel parameters of size S*S, the method further includes: The convolution kernel parameters are moved to a first storage area, and the to-be-convolved data are moved to a second storage area, The first storage area is a storage area that uses a set step size to control sliding, and the inner product instruction is a multiplication-accumulation instruction with a step size sliding window.
5. The method according to claim 4, characterized in that The method further comprises: The data to be convolved is moved to the second storage area through a two-dimensional DMA controller.
6. The method according to any one of claim 5, characterized in that: The method further comprises: A padding operation is performed on the to-be-convolved data in the second storage area in a column direction.
7. A data processing method, characterized in that: The method comprises: Moving the data to be convolved to a storage area through a two-dimensional DMA controller, wherein the data to be convolved is obtained based on a target image; Performing a padding operation on the to-be-convolved data in the storage area in a column direction; A convolution operation is performed on the data stored in the storage area by calling a convolution instruction, wherein an instruction for performing a padding operation in a row direction is loaded at a set position in the convolution instruction.
8. A data processing device, characterized in that: The device comprises: A packing unit is used to pack the data to be convolved in units of P columns and M input channels to obtain multiple first data elements; the convolution kernel parameters include S*S first parameter elements, each first parameter element includes M input channels and N output channels, wherein the data to be convolved is obtained based on the target image; an inner product unit, configured to perform an inner product operation on each of the first parameter elements and a corresponding first data element in a first data block through an inner product instruction to obtain an inner product result corresponding to each of the first parameter elements, wherein the first data block includes each of the first data elements obtained by performing a first windowing S times on each of S consecutive rows of the data to be convolved with a set step size; an accumulation unit, configured to accumulate inner product results corresponding to each of the first parameter elements through an accumulation instruction to obtain a first accumulation result; Get unit for Performing a second windowing on the data to be convolved based on the M input channels of the first data block as a unit, and obtaining first accumulation results corresponding to each second windowing on the input channel; Accumulating the first accumulation results to obtain a second accumulation result; Taking the first data block containing all input channels as a unit, performing a third windowing on the to-be-convolved data row by row in the column direction, and obtaining respective second accumulated results corresponding to each third windowing in the column direction; After shifting to P columns, repeatedly performing the third windowing row by row in the column direction until shifting to Q columns, to obtain a plurality of second accumulation results; Sequentially shifting M output channels on the output channel of the to-be-convolved data to obtain the plurality of second accumulated results corresponding to each shift on the output channel; The obtained second accumulated results are expanded on the rows, columns and output channels of the data to be convolved to obtain the data processing result.
9. The device according to claim 8, characterized in that The obtaining unit is used to expand each second accumulation result obtained on the row, column, and output channel of the to-be-convolved data to obtain the data processing result, specifically for: Expand the second accumulated result corresponding to the data to be convolved in the column direction on the column to obtain a first expanded result; Expand the first expansion result corresponding to column Q on the row to obtain a second expansion result; The second expansion result corresponding to the output channel is expanded on the output channel to obtain a data processing result.
10. The device according to claim 8, characterized in that The convolution kernel parameter is a parameter formed by the difference between each element in the initial convolution kernel and the convolution kernel quantization zero point; the inner product unit is specifically used for: The result of the inner product operation is added to a constant to obtain the inner product result, wherein the constant is obtained according to the product of the quantization zero point of the data to be convolved and the convolution kernel parameter and the bias of the convolution operation.
11. The device according to any one of claims 8 to 10, characterized in that The device also includes a moving unit, which is used to move the convolution kernel parameters to a first storage area and the data to be convolved to a second storage area before setting the convolution kernel parameters to include M input channels and N output channels and obtaining S*S first parameter elements for the convolution kernel parameters of size S*S, wherein the first storage area is a storage area that uses a set step size to control sliding, and the inner product instruction is a multiplication and accumulation instruction with a step size sliding window.
12. The device according to claim 11, characterized in that The device also includes a sub-moving unit, which is used to move the data to be convolved to the second storage area through a two-dimensional DMA controller.
13. The device according to claim 12, characterized in that The device also includes a padding unit, which is used to perform a padding operation on the to-be-convolved data in the second storage area in a column direction.
14. A data processing device, characterized in that: The device comprises: A moving unit, used for moving the data to be convolved to a storage area through a two-dimensional DMA controller, wherein the data to be convolved is obtained based on a target image; a padding unit, configured to perform a padding operation on the to-be-convolved data in the storage area in a column direction; The operation unit is used to perform a convolution operation on the data stored in the storage area by calling a convolution instruction, wherein the convolution instruction loads an instruction for performing a padding operation in a row direction at a set position.
15. A data processing device, characterized in that: The device comprises a memory and a processor, wherein the memory is used to store computer instructions executable on the processor, and the processor is used to implement the method according to any one of claims 1 to 6 when executing the computer instructions.
16. A data processing device, characterized in that: The device comprises a memory and a processor, wherein the memory is used to store computer instructions executable on the processor, and the processor is used to implement the method of claim 7 when executing the computer instructions.
17. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
18. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to claim 7 is implemented.
