Neural network processing device, neural network processing method, and neural network processing program
The neural network processing device addresses the challenge of reducing CNN calculation complexity by using winograd transformation with bit width adjustments based on input channels and kernel size, enhancing throughput and power efficiency in dedicated hardware.
Patent Information
- Application Number
- PCT/JP2023/016553
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-04-26
- Publication Date
- 2024-10-31
AI Technical Summary
Convolutional neural networks (CNNs) face challenges in reducing calculation complexity while maintaining inference accuracy, particularly with the winograd transformation method, which increases bit width and affects throughput and power consumption in dedicated hardware.
A neural network processing device and method that applies winograd transformation with a bit width adjustment mechanism, determining the step width based on the number of input channels, kernel size, and clipping occurrence rate to optimize bit width and prevent overflow, thereby reducing calculations without compromising accuracy.
The solution effectively reduces the amount of calculation in CNNs while maintaining inference accuracy, improving throughput and power efficiency in dedicated hardware by dynamically adjusting bit width and preventing clipping.
Smart Images

Figure JP2023016553_31102024_PF_FP_ABST
Abstract
Description
Neural network processing device, neural network processing method, and neural network processing program
[0001] The disclosed technology relates to a neural network processing device, a neural network processing method, and a neural network processing program.
[0002] A convolutional neural network (CNN) has been known as a technique used in artificial intelligence (AI) inference. In a CNN, a network model is composed of multiple layers, such as an input layer, a convolutional layer, a pooling layer, a fully connected layer, and an output layer, and convolution processing is performed in the convolutional layer.
[0003] A convolutional layer receives input feature maps for input channels and kernels, which are weighting coefficients, as inputs, and outputs output feature maps for output channels. In the convolution process, a two-dimensional multiply-and-accumulate operation is repeatedly performed for each input channel using the input feature map and kernel, and the results of the multiply-and-accumulate operation for all input channels are cumulatively added to generate a convolutional result for one output channel. Then, a bias value is added to the convolutional result for one output channel, followed by activation function processing, to obtain an output feature map for that output channel. By performing these processes for all output channels, an output feature map for one convolutional layer (for all output channels) is obtained. The obtained output feature map becomes the input feature map input to the subsequent convolutional layer. The operations related to this convolutional process account for the largest proportion of the operations related to the entire inference process performed by a CNN.
[0004] In recent years, there has been an increasing demand for implementing CNN inference processing using dedicated hardware such as LSIs (Large Scale Integration) and FPGAs (Field Programmable Gate Arrays). Generally, the greater the amount of calculation, the greater the circuit area and power consumption required for the dedicated hardware. Therefore, it is desirable to reduce the amount of calculation as much as possible. If the amount of calculation can be reduced while maintaining inference accuracy, the throughput (inference processing performance) per circuit area and power consumption can be improved.
[0005] One example of a method for reducing the amount of computation in CNN inference processing is to reduce the bit width of each piece of data used in convolution processing (e.g., reducing 16 bits to 8 bits). In this case, if the step width per bit (decimal point position) after bit width reduction is not appropriately set, the inference accuracy will decrease.
[0006] Also, as another example of a method for reducing the amount of computation in inference processing using a CNN, the Winograd transform is known (see, for example, Non-Patent Document 1). The Winograd transform performs a matrix transform on each of the input feature map and the kernel in advance, multiplies the transformed input feature map (matrix) by the transformed kernel (matrix) using the Hadamard product, and then performs a post-transformation matrix transform. This allows for obtaining results similar to those of the above-mentioned convolution processing. The number of multiplications required for the Hadamard product is fewer than the number of multiplications required for a product-sum operation that directly uses the input feature map and the kernel, thereby reducing the overall amount of computation.
[0007] Andrew Lavin, Scott Gray: Fast Algorithms for Convolutional Neural Networks, 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), Pages: 4013-4021.
[0008] However, in the Winograd transform, matrix transformation of the input feature map and the kernel may result in an increase in bit width compared to the input feature map itself and the kernel itself. Even if the number of multiplications can be reduced by the Winograd transform, the effect of reducing the amount of computation is lost if the bit width of the converted input feature map (matrix) and the converted kernel (matrix) increases. In other words, it is not possible to sufficiently improve the throughput (inference processing performance) per circuit area and power consumption of the dedicated hardware.
[0009] The disclosed technology has been made in consideration of the above points, and aims to provide a neural network processing device, a neural network processing method, and a neural network processing program that can reduce the amount of calculation while suppressing a decrease in inference accuracy when applying Winograd transformation to a convolutional neural network.
[0010] a multiplication unit that calculates a Hadamard product of the first matrix and the second matrix for each input channel; a third transformation unit that performs matrix transformation on the Hadamard product for each input channel to obtain a third matrix; an addition unit that calculates a cumulative sum of the third matrix for each input channel; and an adjustment unit that determines a step width per bit when adjusting a bit width of the cumulative sum of the third matrix based on at least one of the number of input channels, the size of the kernel, and a clipping occurrence rate occurring in the process of calculating the cumulative sum of the third matrix, and adjusts the bit width of the cumulative sum of the third matrix in accordance with the determined step width.
[0011] A second aspect of the present disclosure is a neural network processing method, in which a neural network processing device including a convolutional neural network using a Winograd transform performs matrix transformation on a kernel for each input channel to obtain a first matrix, performs matrix transformation on an input feature map for each input channel to obtain a second matrix, calculates a Hadamard product of the first matrix and the second matrix for each input channel, performs matrix transformation on the Hadamard product for each input channel to obtain a third matrix, calculates a cumulative sum of the third matrix for each input channel, determines a step width per bit when adjusting a bit width of the cumulative sum of the third matrix based on at least one of the number of input channels, the size of the kernel, and a clipping incidence rate occurring in the process of calculating the cumulative sum of the third matrix, and adjusts the bit width of the cumulative sum of the third matrix according to the determined step width.
[0012] A third aspect of the present disclosure is a neural network processing program for causing a computer to function as the neural network processing device of the first aspect.
[0013] According to the above aspects, the neural network processing device, neural network processing method, and neural network processing program of the present disclosure can reduce the amount of calculation while suppressing a decrease in inference accuracy when applying the Winograd transform to a convolutional neural network.
[0014] FIG. 1 is a diagram for explaining a bit width reduction method. FIG. 2 is a diagram for explaining Winograd transformation. FIG. 3 is a diagram for explaining Winograd transformation. FIG. 4 is a block diagram showing an example of the hardware configuration of a neural network processing device. FIG. 5 is a block diagram showing an example of the functional configuration of a neural network processing device. FIG. 6 is a diagram for explaining functions of a neural network processing device. FIG. 7 is a flowchart showing the flow of step width determination processing. FIG. 8 is a flowchart showing the flow of neural network processing.
[0015] An example of an embodiment of the disclosed technology will be described below with reference to the drawings. Note that the same or equivalent components and parts in each drawing are given the same reference numerals. Also, the dimensional proportions in the drawings are exaggerated for the convenience of explanation and may differ from the actual proportions.
[0016] [Overview of Convolutional Neural Network] The disclosed technology relates to a convolutional neural network (CNN) used for AI inference. In a CNN, a network model is composed of multiple layers, such as an input layer, a convolutional layer, a pooling layer, a fully connected layer, and an output layer, and convolution processing is performed in the convolutional layer. Note that the convolutional neural network (CNN) according to this embodiment may include multiple convolutional layers.
[0017] The convolutional layer receives input feature maps (also referred to as input fmap and ifmap) for input channels (also referred to as ich) and kernels that are weighting coefficients as input, and outputs output feature maps (also referred to as output fmap and ofmap) for output channels (also referred to as och). In the convolution process, a two-dimensional planar product-sum operation is repeatedly performed using the input feature map and kernel for each input channel, and the results of the product-sum operation for all input channels are cumulatively added to generate a convolution result for one output channel. Then, a bias value is added to the convolution result for one output channel, followed by activation function processing, to obtain an output feature map for that output channel. By performing these processes for all output channels, output feature maps for one convolutional layer (for all output channels) are obtained. The obtained output feature map becomes the input feature map input to the subsequent convolutional layer. The operations related to this convolutional process account for the largest proportion of the operations related to the entire inference process performed by a CNN. Therefore, the technology of the present disclosure aims to reduce the amount of calculation, particularly in the convolutional layer, while suppressing a decrease in the inference accuracy of CNN.
[0018] [Bit Width Reduction] First, a method of reducing the bit width of each piece of data used in convolution processing will be described as an example of a method of reducing the amount of computation in inference processing using a CNN, with reference to Fig. 1. Fig. 1 is a diagram showing an example of the flow of data processing in one convolution layer, and also shows the bit width of each piece of data.
[0019] Conventionally, when convolution calculations are performed by software using a general-purpose CPU (Central Processing Unit), the calculations are often performed using 32-bit floating-point numbers. On the other hand, when CNN inference processing is implemented using dedicated hardware such as an LSI or FPGA, the calculations are performed using 8-bit fixed-point numbers.
[0020] Specifically, as shown in FIG. 1 , data input to a convolution layer, such as a kernel, an input feature map, and a bias value, is represented by 8 bits. Furthermore, in a product-sum operation performed during the convolution operation, an 8-bit kernel is multiplied by an 8-bit input feature map to obtain a 16-bit operation result. Subsequent operations for accumulating product sums in the input channel (ich) direction also perform sequential accumulating while maintaining the product sums in 16 bits. After that, once the accumulating sums for all input channels are completed, the 16-bit accumulating sum is converted to 8 bits, and an 8-bit bias value is added. The bit width is adjusted from 16 bits to 8 bits, and activation function processing is performed on the accumulating sum to which the bias value has been added, ultimately obtaining an 8-bit output feature map.
[0021] When reducing the bit width, the lower bits are truncated (or truncated after rounding off). For example, if the step width after conversion is 8 bits, it is 32 times (i.e., 2 times) the step width before conversion is 16 bits. 5If it is decided to convert the bit width to 1 / 2 times, the lowest 5 bits of the original 16 bits are discarded, as shown in the speech bubble in Figure 1. In other words, the decimal point position of the data expressed in binary is shifted 5 places to the left. In this way, the step width (decimal point position) per bit of the output feature map can be determined arbitrarily when converting the bit width. If this step width is too large, the calculation will be performed with a low accuracy overall, which will cause a decrease in inference accuracy.
[0022] Furthermore, if an overflow occurs in the value after the bit width is reduced, clipping is also performed. In Figures 1, 2, and 6, points where clipping due to overflow may occur are marked with an asterisk. Overflow is more likely to occur if the step size is too small. This is because the converted value is equivalent to the pre-conversion value divided by the number of steps after conversion, and if the step size is too small, the converted value will be too large.
[0023] For example, suppose the value obtained by converting a 16-bit value to an 8-bit signed integer (int type) is 130. Since the range that can be represented by an 8-bit signed integer type is from -128 to 127, the signed integer type value of 130 is clipped to 127. When clipping occurs, the value used in the calculation becomes completely different from the original value, which can cause a decrease in inference accuracy.
[0024] Furthermore, if the step width is too small, an overflow occurs, especially in the calculation of the cumulative sum in the input channel direction, and the possibility of clipping increases. This is because the value increases as the cumulative sum increases in the input channel direction. For example, if the number of input channels is 1024, in addition to the 16 bits required to multiply two 8-bit values, log 2(1024) bits (10 bits), which means that a total of 26 bits of temporary storage is required. Due to constraints such as hardware size and cost, it is not realistic to provide a memory that can hold calculation results with such a large bit width, so it is expected that the calculation will be stopped at a certain bit width (for example, 16 bits as shown in Figure 1) and then continued. In this case, if cumulative addition is performed in the input channel direction, an overflow may occur.
[0025] Furthermore, since the output feature map of a given convolutional layer becomes the input feature map of the next convolutional layer, the step size of the output feature map affects the frequency of clipping in the calculation of the next convolutional layer.
[0026] Thus, if the step size during bit width reduction is too large, the estimation accuracy will decrease, and if it is too small, it will cause overflow during the convolution operation in the current convolution layer and the cumulative addition in the input channel direction in the next convolution layer. Therefore, it is desirable to determine the step size after bit width reduction to be large enough to prevent overflow, but as small as possible.
[0027] For example, to prevent clipping when the cumulative sum is large, the step size can be determined in proportion to the number of input channels. For example, if no clipping occurs when the number of input channels is 256, then to prevent clipping when the number of input channels is 1024 (4 times), the step size can be set to four times the step size when the number of input channels is 256.
[0028] Furthermore, for example, to prevent clipping when the kernel size is large, the step width can be determined in proportion to the kernel size. This is because in a convolution operation, the sum of products of the input feature map and the kernel is accumulated, and the larger the kernel size, the larger the accumulated sum is likely to be, making clipping more likely to occur. For example, if clipping does not occur when the average kernel size is 30 in 8 bits, to prevent clipping when the average kernel size is 120 (4 times) in 8 bits, the step width can be set to four times the step width when the average kernel size is 30.
[0029] [Winograd Transform] Next, the Winograd Transform related to the technology of the present disclosure will be described. The Winograd Transform is known as a method for reducing the amount of computation required for convolution operations in CNN inference processing. Figure 2 shows the Winograd Transform process for one input channel of one output channel. The portion of Figure 1 corresponding to the convolution operation for one input channel can be replaced with the entirety of Figure 2.
[0030] As shown in Figure 2, the Winograd transform performs matrix transformation on each of the input feature map and the kernel, takes the Hadamard product of the transformed input feature map (matrix) and the transformed kernel (matrix), and then performs another matrix transformation. This produces results similar to those of a conventional convolution operation, i.e., a product-sum operation using the input feature map and the kernel. In this case, the number of multiplications required for the Hadamard product is less than that required for a conventional convolution operation, thereby reducing the overall amount of calculation. When using dedicated hardware such as an LSI or FPGA, fewer multiplication circuits need to be implemented, improving throughput per circuit area or power.
[0031] The transformation formula for the winograd transformation shown in Figure 2 is expressed by the following formula (1). Here, K is the kernel, K' is the first matrix (transformed kernel), I is the input feature map, I' is the second matrix (transformed input feature map), O' is the Hadamard product result, and O is the third matrix (convolution result). Also, A, B, and C are transformation matrices, and T is the transposed matrix.
[0032] (1)
[0033] For example, a case where the size of the input feature map I is 4×4, the size of the kernel K is 3×3, and the size of the convolution result O is 2×2 is shown in Fig. 3. In the case of the size configuration shown in Fig. 3, the transformation matrices A, B, and C used for the winograd transformation are determined as shown in the following formula (2).
[0034] (2)
[0035] The size of the second matrix (transformed input feature map) I' is 4x4, and the size of the first matrix (transformed kernel) K' is 3x3. These Hadamard products require 16 multiplications. The transformation matrix A after the Hadamard product multiplication turns the 4x4 Hadamard product result O' into a 2x2 third matrix (convolution result) O.
[0036] While a normal convolution operation requires (3 x 3) x (2 x 2) = 36 multiplications, using the Winograd transform requires only 16 multiplications, a multiplication rate of 4 / 9. Similarly, for a 5 x 5 kernel, if the size of the convolution result is 2 x 2, the multiplication rate is 9 / 25.
[0037] [Bit Width Reduction in Winograd Transform] By combining the above two techniques to reduce the bit width of the values used in the convolution operation to an 8-bit fixed-point number or the like and then reducing the number of multiplications in the convolution operation by Winograd transform, it is possible to significantly reduce the overall computational load of the convolution operation. However, by performing matrix transformation on the input feature map and kernel in the Winograd transform, the bit width may increase more than that of the input feature map itself and the kernel itself.
[0038] 2 and 3 and equation (2), 4 bits are added to the first matrix (transformed kernel) K' compared to before the matrix transformation, and 2 bits are added to the second matrix (transformed input feature map) I' compared to before the matrix transformation. Even if the number of multiplications can be reduced by the Winograd transformation, if the bit widths of the first matrix (transformed kernel) K' and the second matrix (transformed input feature map) I' increase in this way, the effect of reducing the amount of calculation is lost.
[0039] In other words, simply combining the above two techniques cannot sufficiently improve the throughput (inference processing performance) per circuit area and power consumption of the dedicated hardware. Therefore, it is conceivable to reduce the bit width of the first matrix and the second matrix used in the Winograd transform, and to perform clipping if an overflow occurs, thereby suppressing the bit width related to the Hadamard product calculation.
[0040] However, the step size determination policy in the above-described bit width reduction method is not suitable when the Winograd transform is applied. In the above-described bit width reduction method, the step size is determined based on the number of input channels, the kernel size, etc., from the viewpoint of preventing clipping during the convolution operation in the current convolution layer and the cumulative addition in the input channel direction in the next convolution layer.
[0041] On the other hand, in the method of applying the Winograd transform, the calculation of transforming the input feature map into the second matrix is performed for each input channel, so the number of input channels does not affect the occurrence of clipping that may occur when reducing the bit width of the second matrix. Also, the calculation of transforming the input feature map into the second matrix is performed using the input feature map and the transformation matrix C, so the size of the kernel does not affect the occurrence of clipping that may occur when reducing the bit width of the second matrix. When reducing the bit width of the second matrix, if the step size is too small, the possibility of clipping increases.
[0042] [Configuration of the Neural Network Processing Device According to the Present Embodiment] Therefore, when applying the Winograd transform to a convolutional neural network, the neural network processing device according to the present embodiment determines an appropriate step size that can reduce the amount of calculation while suppressing a decrease in inference accuracy, thereby suppressing a decrease in inference accuracy. The neural network processing device 10 according to the present embodiment will be described below.
[0043] First, the hardware configuration of the neural network processing device 10 according to this embodiment will be described with reference to Fig. 4. Fig. 4 is a block diagram showing the hardware configuration of the neural network processing device 10. As shown in Fig. 4, the neural network processing device 10 includes a CNN arithmetic circuit 50, a CPU 91, a ROM (Read Only Memory) 92, a RAM (Random Access Memory) 93, a storage 94, an input unit 95, a display unit 96, and a communication I / F (Interface) 97. Each component is connected to each other via a bus 99 so as to be able to communicate with each other.
[0044] The CPU 91 is a central processing unit that executes various programs and controls each part. That is, the CPU 91 reads programs from the ROM 92 or the storage 94 and executes the programs using the RAM 93 as a work area. The CPU 91 controls each of the above components and performs various arithmetic processing in accordance with the programs stored in the ROM 92 or the storage 94.
[0045] The ROM 92 stores various data and programs. The RAM 93 temporarily stores programs or data as a working area. The storage 94 is configured with a storage device such as a hard disk drive (HDD) or a solid state drive (SSD), and stores various programs including an operating system and various data. The ROM 92 or the storage 94 stores input / output data used in inference processing by the CNN, such as an input feature map, an output feature map, a kernel, and a bias value (details will be described later).
[0046] The input unit 95 includes, for example, a pointing device such as a mouse, a keyboard, etc., and is used to input various types of information. The display unit 96 is, for example, a liquid crystal display, and displays various types of information. The display unit 96 may also function as the input unit 95 by employing a touch panel system.
[0047] The communication I / F 97 is an interface for communicating with other devices, for example, using a wired communication standard such as Ethernet (registered trademark) or FDDI (Fiber Distributed Data Interface), or a wireless communication standard such as 4G, 5G, or Wi-Fi (registered trademark).
[0048] The CNN arithmetic circuit 50 performs CNN processing such as convolution processing and activation function processing using input feature maps, kernels, bias values, etc. transferred from the ROM 92 or the storage 94. The CNN arithmetic circuit 50 according to this embodiment is configured as hardware designed specifically for CNN. The CNN arithmetic circuit 50 is configured as a dedicated electrical circuit that is a processor having a circuit configuration designed specifically for executing specific processing, such as a programmable logic device (PLD) whose circuit configuration can be changed after manufacturing, such as an FPGA, or an application specific integrated circuit (ASIC).
[0049] Next, the functional configuration of the neural network processing device 10 will be described with reference to Figures 5 and 6. Figure 5 is a block diagram showing an example of the functional configuration of the neural network processing device 10. As shown in Figure 5, the neural network processing device 10 includes a CNN arithmetic circuit 50. Figure 6 is a diagram showing an example of the flow of data processing in one convolution layer in the CNN arithmetic circuit 50, and also shows an example of the bit width of each piece of data.
[0050] As shown in Fig. 5, the CNN arithmetic circuit 50 includes a circuit for performing convolution operations including the Winograd transform. Specifically, the CNN arithmetic circuit 50 includes, as functional components, a convolution unit 40 and an activation function processing unit 51. The convolution unit 40 includes a Winograd transform unit 30, an adder unit 41, and an adjustment unit 42. The Winograd transform unit 30 includes a first transform unit 31, a second transform unit 32, a multiplier unit 33, and a third transform unit 34. Each of these components is realized, for example, by an FPGA or ASIC designed specifically for CNN.
[0051] The convolution unit 40 is configured to be able to switch between performing a convolution operation with or without applying the Winograd transform for each convolution layer. Whether or not to perform the Winograd transform may be determined, for example, by receiving an instruction from the CPU 91, or the adjustment unit 42 may determine whether or not to perform the Winograd transform in the next convolution layer (details will be described later).
[0052] [Convolution Operation Applying Winograd Transform] First, the convolution operation when the winograd transform is applied will be described.
[0053] The first conversion unit 31 performs matrix transformation on the kernel for each input channel to obtain a first matrix. Specifically, the first conversion unit 31 acquires the kernel stored in the ROM 92 or the like, and performs matrix transformation on the kernel using the transformation matrix B shown in the above equation (2). At this time, if the value of the obtained first matrix exceeds the upper limit of the representable bit width (overflows), the first conversion unit 31 performs clipping and saturation processing so that the upper limit is not exceeded.
[0054] For example, if the kernel is 8 bits and the transformation matrix B shown in the above formula (2) is used, 12 bits are required to accurately represent the first matrix. On the other hand, when the first matrix is converted to 8 bits to reduce the amount of calculation, if the transformation result is −128 or less, it is clipped to −128, and if the transformation result is 127 or more, it is clipped to 127, so that the size of the first matrix fits within 8 bits.
[0055] The kernel is weight data and is determined in advance through learning. That is, before the inference process by the CNN begins, the kernel value, including the decimal point position (step size), is already determined. Therefore, the first conversion unit 31 does not need to determine the decimal point position (step size) or calculate the first matrix in real time during the inference process. For example, the first conversion unit 31 may perform matrix transformation on the kernel for each input channel in advance to obtain the first matrix and store the obtained first matrix in the ROM 92, storage 94, or the like. In this case, the amount of calculation required for the matrix transformation can be reduced, thereby improving the throughput (inference processing performance) per circuit area and power consumption of the CNN arithmetic circuit 50. On the other hand, since the data size of the kernel is smaller than the first matrix, it is preferable to perform matrix transformation on the kernel in real time during the inference process in order to reduce the amount of data transfer between the CNN arithmetic circuit 50 and an external memory, such as the ROM 92, in which the kernel or the first matrix is stored. Therefore, whether to perform matrix transformation on the kernel in advance or perform matrix transformation in real time during the inference process may be selected as appropriate.
[0056] Alternatively, for example, the inference process by the CNN arithmetic circuit 50 may be performed several times in advance with the Winograd transform applied, and the decimal point position with the best inference accuracy may be set as the decimal point position of the kernel when the Winograd transform is applied. Alternatively, for example, a kernel (e.g., 8 bits) corresponding to a predetermined decimal point position may be created by an external computer or the like, and the kernel may be stored in advance in the ROM 92, storage 94, or the like. In this case, the first conversion unit 31 may read and use the kernel stored in the ROM 92, storage 94, or the like as appropriate when the inference process is started.
[0057] The second conversion unit 32 performs matrix transformation on the input feature map for each input channel to obtain a second matrix. Specifically, the second conversion unit 32 acquires the input feature map stored in the ROM 92, the storage 94, or the like, and performs matrix transformation on the input feature map using the transformation matrix C shown in the above equation (2). At this time, if the value of the obtained second matrix exceeds the upper limit of the representable bit width (overflows), the second conversion unit 32 performs clipping and saturation processing so that the upper limit is not exceeded.
[0058] For example, if the input feature map is 8 bits and the transformation matrix C shown in the above formula (2) is used, 10 bits are required to correctly represent the second matrix. On the other hand, when the second matrix is converted to 8 bits to reduce the amount of calculation, if the transformation result is −128 or less, it is clipped to −128, and if the transformation result is 127 or more, it is clipped to 127, so that the size of the second matrix fits within 8 bits.
[0059] Note that since the input feature map is generated in real time during inference processing by the CNN based on input data such as images, it is difficult to determine the decimal point position and second matrix in advance, as with the kernel.
[0060] The multiplication unit 33 calculates the Hadamard product of the first matrix and the second matrix for each input channel. Specifically, the multiplication unit 33 acquires the first matrix obtained by the first conversion unit 31 and the second matrix obtained by the second conversion unit 32, and calculates the Hadamard product using the above formula (1).
[0061] The third transformation unit 34 performs matrix transformation on the Hadamard product for each input channel to obtain a third matrix. Specifically, the third transformation unit 34 obtains the Hadamard product calculated by the multiplication unit 33, and performs matrix transformation on the Hadamard product using the transformation matrix A shown in the above equation (2).
[0062] The adder 41 calculates the cumulative sum of the third matrix for each input channel. Specifically, the adder 41 obtains the third matrix for each input channel obtained by the third conversion unit 34 and performs cumulative addition for all input channels to obtain the cumulative sum. For example, the adder 41 stores the cumulative sum during the cumulative addition in the RAM 93 or the like, and when the adder 41 obtains the third matrix for another input channel, it reads the cumulative sum during the cumulative addition from the RAM 93 or the like, adds it, updates it, and stores the updated cumulative sum again in the RAM 93 or the like. Furthermore, when the adder 41 completes the cumulative addition for all channels, it reads the cumulative sum from the RAM 93 or the like and outputs it to the adjustment unit 42.
[0063] At this time, if the cumulative sum during the cumulative addition exceeds the upper limit of the expressible bit width (if it overflows), the adder 41 performs clipping and saturation processing so that the upper limit is not exceeded. For example, if a 16-bit temporary storage area for cumulative addition is provided, if the cumulative sum during the cumulative addition is −32768 or less, it is clipped to −32768, and if the conversion result is 32767 or more, it is clipped to 32767, so that the size of the cumulative sum fits within 16 bits.
[0064] The adjustment unit 42 determines a step width per bit when adjusting the bit width of the cumulative sum of the third matrix based on at least one of the number of input channels, the kernel size, and the clipping incidence rate occurring in the process of calculating the cumulative sum of the third matrix. The adjustment unit 42 also adjusts the bit width of the cumulative sum of the third matrix according to the determined step width. The adjustment unit 42 also adds a bias value to the cumulative sum of the third matrix after the bit width has been adjusted. The kernel size is, for example, the average of the absolute values of each element of the kernel (so-called SAD: Sum of Absolute Difference). For example, in the case of a 3×3 kernel, nine values are included per channel, and the average of the absolute values of these nine values is the kernel size. When there are multiple input channels, the kernel size may be determined by averaging the values in the channel direction. For example, when there are three 3×3 kernels for three channels, the average of the absolute values of the 27 values may be determined as the kernel size. Instead of the average, various representative values such as the median and the mode may be used. The method for determining the step width will be described in detail in each embodiment below.
[0065] As an example, suppose that the cumulative sum (convolution result) accumulated for all input channels is 16 bits, and the final convolution result and output feature map are converted to 8 bits. The adjustment unit 42 sets the step width for 8 bits after conversion to 32 times (i.e., 2 times) the step width for 16 bits before conversion. 5 If it is decided to multiply the number by 16, the lowest 5 bits of the original 16 bits are discarded. In other words, the decimal point position of the data expressed in binary is shifted 5 places to the left.
[0066] Furthermore, the adjustment unit 42 also clips the value if an overflow occurs in the value after adjusting the bit width. For example, suppose the value obtained by converting a 16-bit value to an 8-bit value is 130 in signed integer type (int type). Since the range that can be expressed in an 8-bit signed integer type is from -128 to 127, the signed integer type value of 130 is clipped to 127.
[0067] In addition, the adjustment unit 42 may add the bias value before adjusting the bit width and then adjust the bit width, rather than adding the bias value to the cumulative sum of the third matrix after adjusting the bit width.
[0068] The clipping occurrence rate may be determined by measuring the number of times that the value exceeds the original number of bits (e.g., 16 bits) and is clipped and saturated during the cumulative sum calculation process by the adder 41. The clipping occurrence rate can be determined by measuring the total number of clippings for one layer.
[0069] The activation function processing unit 51 generates an output feature map by performing predetermined nonlinear processing on the final convolution operation result output from the adjustment unit 42 (i.e., the cumulative sum of the third matrix whose bit width has been adjusted and to which a bias value has been added). The output feature map is stored in the ROM 92, RAM 93, storage 94, etc., and serves as an input feature map for the next layer (convolutional layer, pooling layer, fully connected layer, etc.). As the nonlinear processing, processing using a known activation function can be appropriately applied.
[0070] As described above, the step size (decimal point position) can be appropriately adjusted taking the Winograd transformation into consideration. This makes it possible to reduce the frequency of clipping (saturation processing) that may occur in each calculation in the convolution unit 40 while reducing the amount of calculation using the Winograd transformation. Therefore, it is possible to maintain the calculation accuracy of the convolution calculation and the inference processing.
[0071] [Convolution Operation Without Applying Winograd Transform] Next, a convolution operation without applying Winograd transform will be described. As described above, by adjusting the step size suitable for the Winograd transform, it is possible to reduce the amount of calculation while suppressing a decrease in inference accuracy. However, when adjusting the step size does not maintain sufficient calculation accuracy, or when it is estimated that the amount of calculation is sufficiently small even without performing the Winograd transform, it may be preferable to perform the convolution operation without applying the Winograd transform.
[0072] Therefore, the CNN arithmetic circuit 50 according to this embodiment also has the function of performing a convolution operation without performing a Winograd transform. In Fig. 5, the dotted lines indicate the data flow when a convolution operation is performed without performing a Winograd transform. As shown in Fig. 5, when a Winograd transform is not performed, the first conversion unit 31, the second conversion unit 32, and the third conversion unit 34 are not used. Some of the explanations overlapping with the case when a Winograd transform is performed will be omitted.
[0073] First, the adjustment unit 42 may determine not to perform the Winograd transform in the next convolutional layer when the number of input channels, the kernel size, the product of the number of input channels and the kernel size, and the clipping incidence rate occurring in the process of calculating the cumulative sum of the third matrix satisfy predetermined conditions. The cases in which the Winograd transform is not performed will be described in detail in the following examples. Below, the function of each functional unit when the adjustment unit 42 has determined not to perform the Winograd transform in the previous convolutional layer will be described.
[0074] The multiplication unit 33 calculates the sum of products between the kernel and the input feature map for each input channel instead of the Hadamard product. The addition unit 41 calculates the cumulative sum of products between the kernel and the input feature map for each input channel calculated by the multiplication unit 33 instead of the cumulative sum of the third matrix. That is, the multiplication unit 33 and the addition unit 41 calculate the sum of products between the kernel and the input feature map and perform cumulative addition, similar to a general CNN.
[0075] The adjustment unit 42 adjusts the bit width of the cumulative sum of products of the kernel and the input feature map instead of the cumulative sum of the third matrix. The adjustment unit 42 also adds a bias value to the cumulative sum of products of the kernel and the input feature map after the bit width has been adjusted. The adjustment unit 42 also performs clipping if an overflow occurs in the value after the bit width has been adjusted.
[0076] The activation function processing unit 51 creates an output feature map by performing a predetermined nonlinear processing on the final convolution operation result output from the adjustment unit 42 (i.e., the cumulative sum of the products of the kernel with its bit width adjusted and bias value added and the input feature map).
[0077] [Example 1-1] Next, an example of the step size determination process by the adjustment unit 42 will be described with reference to Fig. 7. The step size determination process shown in Fig. 7 is a process for determining the step size per bit when adjusting the bit size of the cumulative sum of the third matrix, and corresponds to Examples 1-1 to 1-4. The step size determination process shown in Fig. 7 is realized by the CNN arithmetic circuit 50 of the neural network processing device 10.
[0078] In this embodiment, when the number of input channels Nich is equal to or greater than a predetermined first threshold and less than a predetermined second threshold that is greater than the first threshold, the adjustment unit 42 increases the step size compared to when the number of input channels Nich is less than the first threshold or equal to or greater than the second threshold. Specifically, the adjustment unit 42 determines the step size by comparing the number of input channels Nich with thresholds X0, X1, and X2 (where X0<X1<X2) that are set in stages. Here, it is assumed that the initial value W0 of the step size is predetermined. The threshold X0 is an example of a first threshold in the present disclosure, and the threshold X2 is an example of a second threshold in the present disclosure.
[0079] In step S51, the adjustment unit 42 checks whether or not the Winograd transform is to be applied to the next layer (i.e., the next convolutional layer). If the process of step S53 (described later) has been executed in the previous convolutional layer, the Winograd transform will not be applied, and the process proceeds to step S54. In step S54, the adjustment unit 42 ends this step size determination process without changing the step size.
[0080] On the other hand, if it is determined in step S51 that the Winograd transform is to be applied to the next layer, the process proceeds to step S52. In step S52, the adjustment unit 42 determines whether the number of input channels Nich is less than the minimum threshold X0. If the number of input channels Nich is less than the minimum threshold X0, the process proceeds to step S53, where the adjustment unit 42 determines not to apply the Winograd transform to the next layer. In step S54, the adjustment unit 42 ends this step size determination process without particularly changing the step size.
[0081] This is because it is believed that when the number of input channels Nich is so small as to be less than the minimum threshold X0, it is impossible to suppress deterioration in calculation accuracy. The smaller the number of input channels Nich, the smaller the cumulative sum in the input channel direction is likely to be, and overflow is less likely to occur, so a fine step width is more likely to be selected in the convolution calculation of the previous layer. On the other hand, since the number of input channels Nich does not have an effect on the matrix transformation of the input feature map, a step width selected by considering only the cumulative sum in the input channel direction is too fine, and overflow is more likely to occur during matrix transformation.
[0082] On the other hand, if it is determined in step S52 that the number of input channels Nich is equal to or greater than the minimum threshold X0, the process proceeds to step S55. In step S55, the adjustment unit 42 determines whether the number of input channels Nich is equal to or greater than the minimum threshold X0 and less than the threshold X1. If the number of input channels Nich is less than the threshold X1, it is estimated that when the input feature map is matrix-transformed in the next layer, the calculation result may overflow and be clipped, possibly resulting in a deterioration in calculation accuracy, although this is not enough to stop the Winograd transformation. Therefore, the process proceeds to step S56, where the adjustment unit 42 determines to increase the step size to four times the predetermined initial value W0, and ends this step size determination process.
[0083] On the other hand, if it is determined in step S55 that the number of input channels Nich is equal to or greater than the threshold X1, the process proceeds to step S57. In step S57, the adjustment unit 42 determines whether the number of input channels Nich is equal to or greater than the threshold X1 and less than the maximum threshold X2. If the number of input channels Nich is less than the threshold X2, it is estimated that, although the possibility of clipping is lower than in the cases of steps S55 and S56 when the input feature map is subjected to matrix transformation in the next layer, there is still a possibility of degradation in calculation accuracy. Therefore, the process proceeds to step S58, where the adjustment unit 42 determines to increase the step size to twice the predetermined initial value W0, and ends this step size determination process.
[0084] On the other hand, if it is determined in step S57 that the number of input channels Nich is equal to or greater than the maximum threshold X2, the process proceeds to step S60. If it is determined that the number of input channels Nich is equal to or greater than the maximum threshold X2, it is estimated that there is no problem in applying the Winograd transformation even if the step size remains at its initial value W0. Therefore, in step S60, the adjustment unit 42 determines not to change the step size (to leave it at its initial value W0), and ends this step size determination process.
[0085] 7, the number of input channels Nich is compared with three thresholds X0, X1, and X2 that are set in stages, but the number of thresholds is not limited to this. For example, two thresholds or four or more thresholds may be set.
[0086] [Example 1-2] In this example, when the kernel size |K| is equal to or greater than a predetermined third threshold and less than a predetermined fourth threshold that is greater than the third threshold, the adjustment unit 42 increases the step size compared to when the kernel size |K| is less than the third threshold or equal to or greater than the fourth threshold. Specifically, the adjustment unit 42 determines the step size by comparing the kernel size |K| with thresholds Y0, Y1, and Y2 (where Y0<Y1<Y2) that are set in stages. The threshold Y0 is an example of the third threshold of the present disclosure, and the threshold Y2 is an example of the fourth threshold of the present disclosure.
[0087] The processing according to this embodiment corresponds to replacing the number of input channels Nich in the above-described first embodiment with the kernel size |K|, and replacing the thresholds X0, X1, and X2 in the above-described first embodiment with thresholds Y0, Y1, and Y2, respectively, and therefore will not be described again. As with the number of input channels Nich, it is considered that the smaller the kernel size |K| is, the more difficult it is to suppress deterioration in calculation accuracy.
[0088] [Example 1-3] The above-described Example 1-1 and Example 1-2 may be combined. For example, the adjustment unit 42 may increase the step size when at least one of the following conditions is satisfied: the number of input channels Nich is equal to or greater than a first threshold value and less than a second threshold value; and the kernel size |K| is equal to or greater than a third threshold value and less than a fourth threshold value. Furthermore, for example, the adjustment unit 42 may increase the step size only when both of the above-described two conditions are satisfied.
[0089] [Examples 1-4] In the present example, when the product of the number of input channels Nich and the kernel size |K| is equal to or greater than a predetermined fifth threshold and less than a predetermined sixth threshold that is greater than the fifth threshold, the adjustment unit 42 increases the step size compared to when the product of the number of input channels Nich and the kernel size |K| is less than the fifth threshold or equal to or greater than the sixth threshold. Specifically, the adjustment unit 42 determines the step size by comparing the product (Nich × |K|) of the number of input channels Nich and the kernel size |K| with thresholds Z0, Z1, and Z2 (where Z0 < Z1 < Z2) that are set in stages. The threshold Z0 is an example of a fifth threshold in the present disclosure, and the threshold Z2 is an example of a sixth threshold in the present disclosure.
[0090] The processing according to this embodiment is equivalent to replacing the number of input channels Nich in the above-described first embodiment with the product (Nich × |K|) of the number of input channels Nich and the kernel size |K|, and replacing the thresholds X0, X1, and X2 in the above-described first embodiment with thresholds Z0, Z1, and Z2, respectively, and therefore will not be described again. As with the number of input channels Nich, it is considered that the smaller the product of the number of input channels Nich and the kernel size |K|, the more difficult it is to suppress deterioration in calculation accuracy.
[0091] Second Example Next, another example of the step size determination process by the adjustment unit 42 will be described with reference to Fig. 8. The step size determination process shown in Fig. 8 is a process for determining a step size per bit when adjusting the bit width of the cumulative sum of the third matrix. The step size determination process shown in Fig. 8 is realized by the CNN arithmetic circuit 50 of the neural network processing device 10.
[0092] In this embodiment, when the clipping incidence rate p occurring in the process of calculating the cumulative sum of the third matrix is equal to or greater than a predetermined seventh threshold and less than a predetermined eighth threshold that is greater than the seventh threshold, the adjustment unit 42 increases the step size in the next convolutional layer compared to the step size Wr in the current convolutional layer. When the clipping incidence rate p is equal to or greater than a certain value, the current step size Wr is too small, causing an overflow, and therefore the step size is increased from the current step size Wr in the calculation of the next layer to suppress clipping.
[0093] Specifically, when a CNN performs object detection on a video, for example, the CNN performs inference processing on each frame that makes up the video. If the clipping incidence rate p in a certain frame is equal to or greater than a certain value, clipping may also occur in the next frame, and it is desirable to increase the step size. Note that when the clipping incidence rate p is measured during the cumulative sum calculation process, calculations such as bit width adjustment using the step size have already been completed for the current frame, so the change in step size is reflected from the next frame onwards.
[0094] Specifically, the adjustment unit 42 determines the step width of the next layer by comparing the clipping incidence rate p with thresholds D0, D1, and D2 (where D0<D1<D2) that are set in stages. The threshold D0 is an example of a seventh threshold in the present disclosure, and the threshold D2 is an example of an eighth threshold in the present disclosure.
[0095] Furthermore, the adjustment unit 42 may prepare two types of thresholds to be compared with the clipping incidence rate p: one for applying the Winograd transform and one for not applying the Winograd transform. For example, if the cumulative sum in the input channel direction is clipped to fit within 8 bits in the current convolutional layer, a large amount of overflow may occur when the input feature map is matrix-transformed for the Winograd transform in the next convolutional layer. Therefore, by setting the threshold for applying the Winograd transform to be stricter than the threshold for not applying the Winograd transform, the occurrence of clipping can be suppressed overall.
[0096] In Figure 8, thresholds D0, D1, and D2 (where D0<D1<D2) are set in stages when the Winograd transformation is applied, and thresholds E0 and E1 (where E0<E1, D0<E0, D1<E1) are set in stages when the Winograd transformation is not applied.
[0097] 8, the adder 41 calculates the clipping incidence rate p. In step S71, the adjuster 42 checks whether or not the Winograd transform is to be applied to the next layer (i.e., the next convolutional layer). If the process of step S73 (described later) has been executed in the previous convolutional layer, the Winograd transform will not be applied, and the process proceeds to step S81.
[0098] On the other hand, if it is determined in step S71 that the Winograd transform should be applied to the next layer, the process proceeds to step S72. In step S72, the adjustment unit 42 determines whether the clipping incidence rate p is equal to or greater than the maximum threshold D2. If the clipping incidence rate p is equal to or greater than the maximum threshold D2, it is estimated that the clipping incidence rate p is too high. Therefore, the process proceeds to step S73, where the adjustment unit 42 determines not to apply the Winograd transform to the next layer. In step S74, the adjustment unit 42 ends this step size determination process without changing the step size.
[0099] On the other hand, if it is determined in step S72 that the clipping incidence rate p is less than the maximum threshold D2, the process proceeds to step S75. In step S75, the adjustment unit 42 determines whether the clipping incidence rate p is equal to or greater than the threshold D1 and less than the maximum threshold D2. If the clipping incidence rate p is within this range, it is estimated that the calculation result may overflow and be clipped, resulting in a deterioration in calculation accuracy, although this is not enough to stop the Winograd transformation in the next layer. Therefore, the process proceeds to step S76, where the adjustment unit 42 determines to increase the step size to four times the current step size Wr, and ends this step size determination process.
[0100] On the other hand, if it is determined in step S75 that the clipping incidence rate p is less than the threshold value D1, the process proceeds to step S77. In step S77, the adjustment unit 42 determines whether the clipping incidence rate p is equal to or greater than the minimum threshold value D0 and less than the threshold value D1. If the clipping incidence rate p is within this range, the possibility of clipping is lower than in the cases of steps S75 and S76, but it is estimated that there is still a possibility that the accuracy of the calculation will deteriorate. Therefore, the process proceeds to step S78, where the adjustment unit 42 determines to increase the step size to twice the current step size Wr, and ends this step size determination process.
[0101] On the other hand, if it is determined in step S77 that the clipping incidence rate p is less than the minimum threshold value D0, the process proceeds to step S80. If it is determined that the clipping incidence rate p is less than the minimum threshold value D0, it is estimated that there is no problem in applying the winograd transformation even if the current step size Wr is left unchanged. Therefore, in step S80, the adjustment unit 42 determines not to change the step size (to leave the current step size Wr), and ends this step size determination process.
[0102] On the other hand, if it is determined in step S71 that the Winograd transformation is not to be applied to the next layer, the process proceeds to step S81. In step S81, the adjustment unit 42 determines whether the clipping incidence rate p is equal to or greater than the maximum threshold E1 for not applying the Winograd transformation. If the clipping incidence rate p is equal to or greater than the maximum threshold E1, it is estimated that the clipping incidence rate p is too high. Therefore, the process proceeds to step S76, where it is determined to increase the step size to four times the current step size Wr, and the step size determination process ends.
[0103] On the other hand, if it is determined in step S81 that the clipping incidence rate p is less than the threshold value E1, the process proceeds to step S82. In step S82, the adjustment unit 42 determines whether the clipping incidence rate p is equal to or greater than the threshold value E0 and less than the threshold value E1. If the clipping incidence rate p is within this range, the possibility of clipping is lower than in the case of step S81, but it is estimated that there is still a possibility that the accuracy of the calculation will deteriorate. Therefore, the process proceeds to step S78, where the adjustment unit 42 determines to increase the step size to twice the current step size Wr, and ends this step size determination process.
[0104] On the other hand, if it is determined in step S82 that the clipping incidence rate p is less than the threshold value E0, the process proceeds to step S80. If it is determined that the clipping incidence rate p is less than the threshold value E0, it is presumed that there is no problem even if the current step width Wr is left unchanged. Therefore, in step S80, the adjustment unit 42 determines not to change the step width (to leave the current step width Wr), and ends this step width determination process.
[0105] In a CNN having multiple convolutional layers, the effect of clipping may vary depending on the layer position. Therefore, in each of the above embodiments, thresholds X0, X1, and X2, thresholds Y0, Y1, and Y2, thresholds Z0, Z1, and Z2, thresholds D0, D1, and D2, and thresholds E0 and E1 may be set for each layer.
[0106] For example, since the output feature map of one layer becomes the input feature map of the next layer, if there is an error in the feature map in the early layers, it may be magnified into a large error in the feature map in the last layer. Therefore, the earlier the layer, the more attention is needed to the error in the feature map. The error in the feature map caused by increasing the step size tends to result in a lower accuracy overall, but the error in the feature map caused by decreasing the step size requires more attention because clipping results in completely different values locally.
[0107] Therefore, for example, it is conceivable to set a threshold value so that saturation processing due to clipping does not occur in the earlier layers. For example, the larger the threshold value X0 in Figure 7 is, the more likely it is that step S52 will result in a positive determination, making it less likely that winograd processing will be applied. Therefore, if the threshold value X0 is set larger in the earlier layers, it becomes less likely that winograd processing will be applied in the earlier layers, making it less likely that clipping will occur.
[0108] Next, the operation of the neural network processing device 10 of this embodiment will be described. Fig. 9 is a flowchart showing the flow of neural network processing by the neural network processing device 10. The processing by the neural network processing device 10 is realized by the CNN arithmetic circuit 50 of the neural network processing device 10.
[0109] In step S10, the convolution unit 40 checks whether or not the Winograd transform is to be applied to the current convolution layer. If the determination in step S10 is affirmative, the process proceeds to step S12, where the first transformation unit 31 performs matrix transformation on the kernel to obtain a first matrix. In step S14, the second transformation unit 32 performs matrix transformation on the input feature map to obtain a second matrix. In step S16, the multiplication unit 33 calculates the Hadamard product of the first matrix obtained in step S12 and the second matrix obtained in step S14. In step S18, the third transformation unit 34 performs matrix transformation on the Hadamard product calculated in step S16 to obtain a third matrix.
[0110] On the other hand, if the determination in step S10 is negative, the process proceeds to step S20, where the multiplication unit 33 calculates the sum of products of the kernel and the input feature map. In step S22, the convolution unit 40 determines whether or not the matrix transformation (third matrix) of the Hadamard product in step S18 or the calculation of the sum of products of the kernel and the input feature map in step S20 has been completed for all input channels. If the processing for all input channels has not been completed, the process returns to step S10 and is repeated until the processing for all input channels is completed.
[0111] On the other hand, if the result of step S22 is a positive judgment, in step S24, the adder 41 calculates the cumulative sum of the third matrix obtained in step S18 or the cumulative sum of the products of the kernel and the input feature map obtained in step S20.
[0112] In step S50, the adjustment unit 42 performs the step width determination process described above (see FIGS. 7 and 8). In step S26, the adjustment unit 42 adjusts the bit width of the cumulative sum of the third matrix obtained in step S24 or the cumulative sum of the products of the kernel and the input feature map obtained in step S20, according to the step width determined in step S50. In step S28, the adjustment unit 42 adds a bias value to the cumulative sum whose bit width has been adjusted in step S26.
[0113] In step S30, the activation function processing unit 51 generates an output feature map by performing a predetermined nonlinear process on the final convolution operation result (the cumulative sum with the bit width adjusted and the bias value added) obtained in step S28. In step S32, the activation function processing unit 51 outputs the output feature map generated in step S30 to the next convolution layer, thereby completing the neural network process.
[0114] As described above, the neural network processing device 10 of this embodiment is a neural network processing device including a convolutional neural network using the Winograd transform, and includes a first transformation unit 31 that performs matrix transformation on a kernel for each input channel to obtain a first matrix, a second transformation unit 32 that performs matrix transformation on an input feature map for each input channel to obtain a second matrix, a multiplication unit 33 that calculates a Hadamard product of the first matrix and the second matrix for each input channel, and a third transformation unit 34 that performs matrix transformation on the Hadamard product for each input channel to obtain a third matrix, an addition unit 41 that calculates a cumulative sum of the third matrix for each input channel, and an adjustment unit 42 that determines a step size per bit when adjusting the bit width of the cumulative sum of the third matrix based on at least one of the number of input channels, the kernel size, and the clipping incidence rate that occurs in the process of calculating the cumulative sum of the third matrix, and adjusts the bit width of the cumulative sum of the third matrix in accordance with the determined step size.
[0115] According to the neural network processing device 10 of this embodiment, when the Winograd transformation is applied to a convolutional neural network, the amount of calculation can be reduced while suppressing a decrease in inference accuracy.
[0116] The neural network processing performed by the CNN arithmetic circuit 50 in the above embodiment may be realized by a processor such as a CPU executing a neural network processing program. For example, the neural network processing program may be pre-stored (also referred to as "installed") in the ROM 92 or the storage 94. The neural network processing program may be provided in a form stored in a non-transitory storage medium such as a CD-ROM (Compact Disk Read Only Memory), a DVD-ROM (Digital Versatile Disk Read Only Memory), or a USB (Universal Serial Bus) memory. The neural network processing program may also be downloaded from an external device via a network.
[0117] Furthermore, neural network processing may be performed by one of these various processors, or by a combination of two or more processors of the same or different types (e.g., a plurality of FPGAs, or a combination of a CPU and an FPGA, etc.).More specifically, the hardware structure of these various processors is an electric circuit that combines circuit elements such as semiconductor elements.
[0118] All publications, patent applications, and technical standards mentioned in this specification are herein incorporated by reference to the same extent as if each individual publication, patent application, or technical standard was specifically and individually indicated to be incorporated by reference.
[0119] The following additional notes are provided regarding the above-described embodiments.
[0120] (Supplementary Item 1) A neural network processing device including a convolutional neural network using a Winograd transform, comprising: a memory; and at least one processor connected to the memory, wherein the processor: performs matrix transformation on a kernel for each input channel to obtain a first matrix; performs matrix transformation on an input feature map for each input channel to obtain a second matrix; calculates a Hadamard product of the first matrix and the second matrix for each input channel; performs matrix transformation on the Hadamard product for each input channel to obtain a third matrix; calculates a cumulative sum of the third matrix for each input channel; determines a step width per bit when adjusting a bit width of the cumulative sum of the third matrix based on at least one of the number of input channels, the size of the kernel, and a clipping occurrence rate occurring in the process of calculating the cumulative sum of the third matrix; and adjusts the bit width of the cumulative sum of the third matrix according to the determined step width.
[0121] (Supplementary Item 2) A non-transitory storage medium storing a program executable by a computer to perform neural network processing including a convolutional neural network using a Winograd transform, wherein the neural network processing comprises: performing matrix transformation on a kernel for each input channel to obtain a first matrix; performing matrix transformation on an input feature map for each input channel to obtain a second matrix; calculating a Hadamard product of the first matrix and the second matrix for each input channel; performing matrix transformation on the Hadamard product for each input channel to obtain a third matrix; calculating a cumulative sum of the third matrix for each input channel; determining a step width per bit when adjusting a bit width of the cumulative sum of the third matrix based on at least one of the number of input channels, the size of the kernel, and a clipping occurrence rate occurring in the process of calculating the cumulative sum of the third matrix; and adjusting the bit width of the cumulative sum of the third matrix according to the determined step width.
[0122] 10 Neural network processing device 30 Winograd conversion unit 31 First conversion unit 32 Second conversion unit 33 Multiplication unit 34 Third conversion unit 40 Convolution unit 41 Addition unit 42 Adjustment unit 50 CNN arithmetic circuit 51 Activation function processing unit 91 CPU 92 ROM 93 RAM 94 Storage 95 Input unit 96 Display unit 97 Communication I / F 99 Bus
Claims
1. A neural network processing device including a convolutional neural network using a Winograd transform, comprising: a first transformation unit that performs matrix transformation on a kernel for each input channel to obtain a first matrix; a second transformation unit that performs matrix transformation on an input feature map for each input channel to obtain a second matrix; a multiplication unit that calculates a Hadamard product of the first matrix and the second matrix for each input channel; a third transformation unit that performs matrix transformation on the Hadamard product for each input channel to obtain a third matrix; an addition unit that calculates a cumulative sum of the third matrix for each input channel; and an adjustment unit that determines a step width per bit when adjusting the bit width of the cumulative sum of the third matrix based on at least one of the number of input channels, the size of the kernel, and a clipping occurrence rate occurring in the process of calculating the cumulative sum of the third matrix, and adjusts the bit width of the cumulative sum of the third matrix in accordance with the determined step width.
2. The neural network processing device according to claim 1, wherein the adjustment unit increases the step width when the number of input channels is equal to or greater than a predetermined first threshold and less than a predetermined second threshold that is greater than the first threshold, compared to when the number of input channels is less than the first threshold or equal to or greater than the second threshold.
3. The neural network processing device according to claim 1, wherein the adjustment unit increases the step width when the size of the kernel is equal to or greater than a predetermined third threshold and less than a predetermined fourth threshold that is greater than the third threshold, compared to when the size of the kernel is less than the third threshold or equal to or greater than the fourth threshold.
4. The neural network processing device of claim 1, wherein the adjustment unit increases the step width when the product of the number of input channels and the size of the kernel is equal to or greater than a predetermined fifth threshold and less than a predetermined sixth threshold that is greater than the fifth threshold, compared to when the product of the number of input channels and the size of the kernel is less than the fifth threshold or equal to or greater than the sixth threshold.
5. The neural network processing device according to claim 1, wherein the convolutional neural network includes a plurality of convolutional layers, and the adjustment unit makes the step size in the next convolutional layer larger than the step size in the current convolutional layer when the clipping occurrence rate is equal to or greater than a predetermined seventh threshold and less than a predetermined eighth threshold that is greater than the seventh threshold.
6. The neural network processing device according to claim 1, wherein the convolutional neural network includes a plurality of convolutional layers, and the adjustment unit determines not to perform a Winograd transform in the next convolutional layer when the number of input channels, the size of the kernel, the product of the number of input channels and the size of the kernel, and the clipping incidence rate satisfy predetermined conditions, and the multiplication unit calculates a sum of products between the kernel and the input feature map for each input channel instead of the Hadamard product when it has been determined that a Winograd transform is not to be performed in the previous convolutional layer, and the addition unit calculates a cumulative sum of products between the kernel and the input feature map for each input channel instead of the cumulative sum of the third matrix, and the adjustment unit adjusts a bit width of the cumulative sum of products between the kernel and the input feature map instead of the cumulative sum of the third matrix.
7. A neural network processing method in which a neural network processing device including a convolutional neural network using a Winograd transform: performs matrix transformation on a kernel for each input channel to obtain a first matrix; performs matrix transformation on an input feature map for each input channel to obtain a second matrix; calculates a Hadamard product of the first matrix and the second matrix for each input channel; performs matrix transformation on the Hadamard product for each input channel to obtain a third matrix; calculates a cumulative sum of the third matrix for each input channel; determines a step width per bit when adjusting the bit width of the cumulative sum of the third matrix based on at least one of the number of input channels, the size of the kernel, and a clipping occurrence rate occurring in the process of calculating the cumulative sum of the third matrix, and adjusts the bit width of the cumulative sum of the third matrix in accordance with the determined step width.
8. A neural network processing program for causing a computer to function as the neural network processing device according to any one of claims 1 to 6.
Citation Information
Patent Citations
Convolutional neural network accelerator
CN113361695A
Arithmetic processing device, information processing device, information processing method, and program
JP2019148896A
Operation method and apparatus for network layer in deep neural network
US20210271973A1
