Calculating device
The arithmetic device optimizes matrix calculations by using output matrices from previous calculations and a zero check unit to skip unnecessary data reads, addressing inefficiencies in CNN convolution operations and reducing overall calculation time.
Patent Information
- Application Number
- PCT/JP2024/009203
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-30
- Filing Date
- 2024-03-09
- Publication Date
- 2024-10-03
AI Technical Summary
Conventional methods for matrix calculations in machine learning, such as convolution operations in CNNs, waste time by reading and processing zero data, leading to inefficiencies in memory usage and calculation time.
An arithmetic device that uses an output matrix from a previous calculation as data for subsequent calculations, incorporating a zero check unit to determine if data needs to be read, thereby skipping unnecessary calculations and reducing data read time.
This approach significantly reduces wasted time and overall calculation time by skipping unnecessary data reads and optimizing matrix calculation processes.
Smart Images

Figure JP2024009203_03102024_PF_FP_ABST
Abstract
Description
computing device
[0001] The present invention relates to an arithmetic device that performs matrix calculations such as convolution operations.
[0002] Traditionally, in the field of machine learning, convolutional neural networks (CNNs) are used to recognize images and videos. For example, in image recognition, the input image is transformed using convolutional layers and pooling layers, gradually reducing the amount of data, and finally outputting the probability value for each classification.
[0003] Here, in the convolutional layer of a CNN, a filter operation is performed on each coordinate region (e.g., a 3x3 cell region) in the input data. The operation result is then used as input for the operation in the next layer, and the convolution operation is repeated. Therefore, machine learning using a CNN requires many matrix calculations and memory bandwidth. As a method for alleviating this condition, a configuration is used that skips calculations when the operation target is zero (e.g., Patent Documents 1 and 2, etc.).
[0004] JP 2020-184309 A JP 2018-028908 A
[0005] The techniques disclosed in Patent Documents 1 and 2 do not require calculations, thereby reducing calculation time. As a result, the time required for the entire convolution operation can also be reduced. However, in these techniques, data used as input for the operation target is loaded into a calculation memory, and the data loaded into the calculation memory is checked to see if it is zero. In other words, if the calculation is skipped as a result, the time and memory space required to read the data will be used for data not used in the calculation.
[0006] The present invention has been made in consideration of the above-mentioned circumstances, and aims to provide a calculation device that can further reduce the time that is ultimately wasted when performing matrix calculations such as convolution operations, and can further shorten the time required for the entire calculation compared to conventional methods.
[0007] To achieve the above-mentioned object, the present invention employs the following technical means. First, the present invention is premised on a calculation device in which, in a series of matrix calculations, the output matrix of a previous matrix calculation is used as the data to be calculated for the subsequent matrix calculation. The calculation device according to the present invention comprises a data memory, a matrix calculation unit, a zero check unit, a submap memory, and a map check unit. The data memory stores the data to be calculated. The matrix calculation unit reads data from the data memory, performs a matrix calculation, and stores the output matrix in the data memory. The zero check unit determines whether each element of the output matrix falls within a pre-specified range. The submap memory stores the determination result of the zero check unit as status information. Based on the status information stored in the submap memory, the map check unit determines whether the output matrix corresponding to the status information should be read by the matrix calculation unit as the data to be calculated.
[0008] According to this calculation device, when the map check unit determines that the data to be calculated should not be read, the calculation is skipped without the data to be calculated being read by the matrix calculation unit, thereby reducing unnecessary data read time and, as a result, shortening the time required for the entire calculation.
[0009] In the above configuration, the matrix calculation unit may simultaneously read out a plurality of data items for successively calculating the same output matrix. In this case, the zero check unit uses one of the plurality of pieces of status information corresponding to the plurality of data items successively read out to the matrix calculation unit.
[0010] The above-described configuration can also be applied to cases where the matrix calculation is, for example, a convolution operation in a convolutional neural network. In this case, the matrix calculation unit stores the output matrix in the data memory as data to be calculated in the next layer of the convolution operation. Furthermore, the map check unit determines, based on the state information stored in the submap memory, whether to cause the matrix calculation unit to read the output matrix corresponding to the state information as data to be calculated in the next layer of the convolution operation. This configuration can also be configured such that the matrix calculation unit reads the same coordinate region constituting a part of each input channel as data to be calculated in all input channels belonging to the same layer of the convolution operation, and performs matrix calculation. This configuration can also be configured such that the matrix calculation unit simultaneously reads multiple data items to be continuously subjected to matrix calculation in the same layer of the convolution operation. In this case, the zero check unit uses one of multiple state information items corresponding to the multiple data items continuously read to the matrix calculation unit as state information for the multiple data items.
[0011] The above-described arithmetic device may further include a table creation unit and a read control unit. The table creation unit creates a table that specifies an output matrix to be read by the matrix calculation unit based on the determination result of the map check unit. The read control unit causes the matrix calculation unit to read data based on the created table.
[0012] In the above-described arithmetic device, the zero check unit may further determine whether each element of the output matrix by the matrix calculation unit falls within a predetermined range for each memory access. In this case, the submap memory stores the determination result of the zero check unit as second state information.
[0013] In addition, in the above-mentioned calculation device, a configuration can be adopted in which the map check unit executes matrix calculations for the first layer and thereafter based on state information stored in the submap memory as a result of the initial matrix calculation for the first layer in the convolution calculation.
[0014] The above-described computing device may further include a submap memory buffer that stores, in association with each other, information for identifying an output matrix corresponding to state information, information indicating a storage location of the state information in the submap memory, and information indicating whether the state information has been used in the convolution calculation of the next layer. In this configuration, a storage location in the submap memory associated with usage information indicating use of the state information in the convolution calculation of the next layer is selected as the storage location for newly generated state information.
[0015] In addition, the above-mentioned calculation device may be configured such that the submap memory stores in advance kernel state information that determines whether each element of the kernel used in the matrix calculation falls within a predetermined range. In this case, the map check unit determines, based on the state information stored in the submap memory and the kernel state information, whether to cause the matrix calculation unit to read the output matrix corresponding to the state information as data to be calculated.
[0016] In addition, in the above-mentioned calculation device, a configuration can be adopted in which the zero check unit compares each element of the output matrix with multiple thresholds and determines which of multiple ranges defined by the multiple thresholds all elements of the output matrix belong to.
[0017] In addition, in the above-mentioned calculation device, a configuration can be adopted in which the zero check unit further determines whether or not a negative value exists in each element of the output matrix, or the number of elements that belong to any one of a plurality of ranges.
[0018] In addition, in the above-mentioned calculation device, a configuration can be adopted in which the zero check unit creates status information during matrix calculation for the input channel that is the last to be matrix calculated among input channels belonging to the same layer, and stores the information in the submap memory.
[0019] According to the present invention, it is possible to reduce wasted time and further shorten the time required for the entire calculation compared to the conventional method.
[0020] FIG. 1 is a schematic diagram showing an example of a calculation device according to an embodiment of the present invention. FIG. 2 is a flow diagram showing the procedure for a convolution calculation performed by a calculation device according to an embodiment of the present invention. FIG. 3 is a flow diagram showing the procedure for a convolution calculation performed by a calculation device according to an embodiment of the present invention. FIG. 4 is a schematic diagram showing an example of a zero check unit provided in a calculation device according to an embodiment of the present invention. FIG. 5 is a schematic diagram showing an example of a submap provided in a calculation device according to an embodiment of the present invention. FIG. 6 is a schematic diagram showing an example of a calculation device according to an embodiment of the present invention. FIG. 7 is a schematic diagram showing an example of a submap address table provided in a calculation device according to an embodiment of the present invention. FIG. 8 is a flow diagram showing the procedure for a convolution calculation performed by a calculation device according to an embodiment of the present invention. FIG. 9 is a flow diagram showing the procedure for a convolution calculation performed by a calculation device according to an embodiment of the present invention. FIG. 10 is an explanatory diagram schematically showing the concept of a convolution calculation method performed by a calculation device according to an embodiment of the present invention. FIG. 11 is a flow diagram showing the procedure for a convolution calculation performed by a calculation device according to an embodiment of the present invention. FIG. 12 is a flow diagram showing the procedure for a convolution calculation performed by a calculation device according to an embodiment of the present invention. Fig. 13 is an explanatory diagram schematically illustrating the concept of a convolution calculation method by a calculation device according to an embodiment of the present invention. Fig. 14 is a schematic configuration diagram showing an example of a calculation device according to an embodiment of the present invention. Fig. 15 is a flow diagram showing the procedure of a convolution calculation by a calculation device according to an embodiment of the present invention. Figs. 16(a) and 16(b) are explanatory diagrams schematically illustrating the concept of a convolution calculation method by a calculation device according to an embodiment of the present invention.
[0021] Hereinafter, an embodiment of the present invention will be described in more detail with reference to the drawings. In the following, a computing device according to the present invention, which uses an output matrix of a previous matrix calculation as data to be calculated for a subsequent matrix calculation in a series of matrix calculations, is embodied as a computing device that realizes processing of a convolutional layer of a convolutional neural network (CNN).
[0022] As is well known, a convolutional neural network (CNN) includes a convolutional layer and a pooling layer. Input data, such as an image to be recognized, is processed through a series of processes in the convolutional layer and the pooling layer repeatedly, gradually reducing the amount of data. The convolutional neural network then outputs a classification probability value that indicates the type of object the input image is.
[0023] When the recognition target is an image, for example, data in which pixel values are arranged two-dimensionally for each R, G, and B input channel of each pixel of the image is input as input data to the convolution layer. In the convolution layer, for each input channel of the input image, a kernel (filter) is multiplied to a coordinate region (e.g., a 3×3 region) constituting a portion of the input data. Then, for example, the results calculated for each input channel are summed to calculate the output value of that coordinate region. This multiplication with the kernel is performed on the entire input image by sequentially moving the coordinate region for each input channel while partially overlapping the coordinate region. At this time, multiple sets of kernels are prepared for each input channel according to the number of output channels output by the convolution operation. For example, if the input data has three channels and the output data has three channels, three kernel sets, each consisting of three kernels, are prepared to be multiplied to the coordinate region of each input channel.
[0024] In addition, in the pooling layer, output values are calculated by processing data for each coordinate region of the two-dimensional data (output matrix) output as the calculation result in the convolution layer. For example, in the pooling layer, the average or maximum value in a 2x2 coordinate region is output as the output value of that coordinate region. Note that the pooling layer may be omitted. When the pooling layer is omitted, the data output by the convolution calculation in the first layer is used as input data to perform the convolution calculation in the second layer.
[0025] FIG. 1 is a schematic diagram showing the configuration of a calculation device according to one embodiment of the present invention. As shown in FIG. 1, the calculation device 100 of this embodiment includes a data memory 111, a matrix calculation unit 112, a zero check unit 113, a submap memory 114, a map check unit 115, and a controller 116. The calculation device 100 creates a submap separate from the output matrix (main map) obtained as a calculation result in a conventional convolution calculation, and uses the submap to reduce the time required for the entire convolution calculation. A submap is created for each input channel used as input data for the convolution calculation of the next layer.
[0026] The data memory 111 stores data to be calculated. As described above, when an image is the object of calculation, for example, pixel values of each pixel constituting the image are stored as input data in the data memory 111. In this embodiment, the data memory 111 also stores kernels and biases (described later) that are used for matrix calculation in the matrix calculation unit 112.
[0027] The matrix calculation unit 112 reads data from the data memory 111 and performs matrix calculations. As described above, the matrix calculation unit 112 performs matrix calculations for each of the R, G, and B input channels, including multiplying pixel values of a coordinate region formed by a 3×3 region by a kernel. In this embodiment, the matrix calculation unit 112 performs a matrix calculation of Q = A * P + B, where P is coordinate region data, A is kernel, B is bias, and Q is calculation matrix. The matrix calculation unit 112 stores an output matrix (output channel) that is the matrix calculation result for all of the input data in the data memory 111 as data to be calculated in the next layer of the convolution calculation. Although not particularly limited, in this embodiment, the matrix calculation unit 112 outputs, as an output value, the sum of the elements of the calculation matrix Q that is the result of performing the matrix calculation for the coordinate region of each input channel. As described above, the matrix calculation unit 112 performs the matrix calculation for all of the input data, and stores the output value for each coordinate region in the data memory 111 together with information indicating the coordinate region. Therefore, when the matrix calculation for the input data is completed, the data memory 111 stores an output matrix that is the result of the matrix calculation (convolution operation) performed on the entire input data.
[0028] Although not particularly limited, in this embodiment, the matrix calculation unit 112 first performs matrix calculations for each coordinate region for one of the three input channels. Upon completion of the matrix calculations for each coordinate region, the data memory 111 stores an output matrix resulting from the matrix calculations for that one input channel. Next, the matrix calculation unit 112 performs matrix calculations for each coordinate region for one of the remaining two input channels. At this time, a matrix in which elements other than those corresponding to the coordinate region being calculated are set to zero in the output matrix for the first input channel stored in the data memory 111 is used as a bias. In this case, upon completion of the matrix calculations for each coordinate region for the second input channel, the data memory 111 stores an output matrix resulting from the sum of the results of the matrix calculations for the first input channel and the second input channel. Next, the matrix calculation unit 112 performs matrix calculations for each coordinate region for the remaining input channel. At this time, a matrix in which elements other than those corresponding to the coordinate region being calculated are set to zero is used as the bias in the output matrices for the first and second input channels stored in the data memory 111. In this case, when the matrix calculation for each coordinate region of the third input channel is completed, the data memory 111 stores an output matrix in which the results of the matrix calculation for the three input channels are added together.
[0029] The zero check unit 113 determines whether each element of the output matrix output by the matrix calculation unit 112, i.e., the output value of the matrix calculation for each coordinate region, falls within a predetermined range. Although not particularly limited, in this embodiment, the zero check unit 113 determines which of a plurality of ranges defined by a plurality of preset thresholds the element falls within. As will be described later, in this embodiment, the zero check unit 113 is configured to make the above-mentioned determination based on the state information stored in the submap memory 114 at that time and the output value from the matrix calculation unit 112 each time an output value is output from the matrix calculation unit 112.
[0030] The submap memory 114 stores the determination result of the zero check unit 113 as state information. The state information is stored corresponding to the output matrix described above. The state information is one of the pieces of information constituting the submap described above. For example, if three thresholds are preset in the zero check unit 113, the state information indicates which of four states the zero check unit 113 belongs to. That is, the state information indicates which of the four states the zero check unit 113 belongs to: "State 1" where all elements of the output matrix are equal to or less than the first threshold; "State 2" where all elements of the output matrix are equal to or less than the second threshold; "State 3" where all elements of the output matrix are equal to or less than the third threshold; or "State 4" where the zero check unit 113 does not fall under State 1, State 2, or State 3. Although not particularly limited, in this embodiment, the values "0," "1," "2," and "3" are stored as information indicating State 1, State 2, State 3, and State 4, respectively. The state information is updated each time the zero check unit 113 makes a determination. The submap memory 114 may be configured as a part of the memory device that constitutes the data memory 111, or may be configured as a separate memory device.
[0031] Based on the state information stored in the submap memory 114, the map check unit 115 determines whether to have the matrix calculation unit 112 read the output matrix corresponding to the state information as input data (data to be calculated) for the next layer in the convolution calculation. For example, in the above example, the following determination is made: If the state information is state 1, the map check unit 115 determines not to have the matrix calculation unit 112 read the corresponding data (output matrix). If the state information is state 2 or state 3, the map check unit 115 determines not to have the matrix calculation unit 112 read the corresponding data (output matrix) if the value of kernel A satisfies a preset condition. The preset condition is, for example, state 2 when more than half of the kernel elements are zero, state 3 when more than three-quarters of the kernel elements are zero, etc. Furthermore, if the state information is state 4, the map check unit 115 determines to have the matrix calculation unit 112 read the corresponding data (output matrix).
[0032] The arithmetic unit 100 also includes a controller 116 that controls the operation timing of the data memory 111, the matrix calculation unit 112, the zero check unit 113, the submap memory 114, and the map check unit 115, etc.
[0033] In the arithmetic device 100, the matrix calculation unit 112 can be realized by a processor such as a GPU (Graphic Processing Unit) specialized for image processing. Furthermore, each element that performs signal processing or data processing, such as the zero check unit 113, the map check unit 115, and the controller 116, can be realized by, for example, a dedicated arithmetic circuit, or hardware including a processor and memory such as a RAM (Random Access Memory) or a ROM (Read Only Memory), and software that is stored in the memory and runs on the processor.
[0034] Next, the operation of the arithmetic device 100 having the above configuration will be described. As described above, when a convolution operation is performed on input data, a submap containing state information is created for each output matrix used as an input channel for the convolution operation of the next layer. That is, the submap created during the convolution operation of the first layer is used during the convolution operation of the second layer, and the submap created during the convolution operation of the second layer is used during the convolution operation of the third layer. Therefore, in the convolution operation of the first layer, there are no submaps corresponding to each input channel. Below, the operation during the convolution operation of the first layer and the convolution operations of the second layer and beyond will be described.
[0035] 2 is a flow diagram showing a procedure performed during the first layer convolution calculation of the arithmetic device 100 of this embodiment. Note that FIG. 2 shows an example in which the number of input channels is n and the number of output channels is m. Although not particularly limited, this procedure is started, for example, when data to be calculated is stored in the data memory 111 from outside the arithmetic device 100.
[0036] When this procedure is started, the matrix calculation unit 112 starts matrix calculation for the first input channel. The matrix calculation unit 112 first reads a kernel to be used for matrix calculation for the first input channel from the data memory 111 (step S201). At this time, the matrix calculation unit 112 also reads data belonging to the coordinate region to be used for matrix calculation from the input data belonging to the first input channel, and the bias described above, from the data memory 111 (step S202). As described above, the bias for the first input channel is a zero matrix.
[0037] Next, the matrix calculation unit 112 performs a matrix calculation and stores the output value, which is the calculation result, in the data memory 111 together with information indicating the coordinate region (steps S203 and S204). At this time, the matrix calculation unit 112 inputs the output value to the zero check unit 113. In response to this input, the zero check unit 113 determines which of multiple ranges defined by multiple preset thresholds the value belongs to. The zero check unit 113 then stores the determination result in the submap memory 114 and updates the previously stored state information (step S205).
[0038] The calculation device 100 repeats the above process until it is completed for all coordinate regions belonging to the first input channel (No in step S206). At this time, the data memory 111 stores the output matrix calculated for the first input channel.
[0039] When the calculation for the first input channel is completed, the matrix calculation unit 112 starts the matrix calculation for the second input channel (step S206: Yes, S207: No). The matrix calculation unit 112 reads the kernel to be used for the matrix calculation for the second input channel from the data memory 111 (step S201). At this time, the matrix calculation unit 112 also reads, from the data memory 111, data belonging to the coordinate region to be used for the matrix calculation from the input data belonging to the second input channel, and a bias (step S202). As described above, the bias for the second input channel is a matrix in which all elements of the output matrix currently being calculated, stored in the data memory 111 at that time, except for elements corresponding to the coordinate region to be calculated, are set to zero.
[0040] Next, the matrix calculation unit 112 performs a matrix calculation and stores the output value, which is the calculation result, in the data memory 111 together with information indicating the coordinate region (steps S203 and S204). At this time, the matrix calculation unit 112 inputs the output value to the zero check unit 113. In response to this input, the zero check unit 113 determines which of multiple ranges defined by multiple preset thresholds the value belongs to. The zero check unit 113 then stores the determination result in the submap memory 114 and updates the previously stored state information (step S205).
[0041] The calculation device 100 repeats the above process until it is completed for all coordinate regions belonging to the second input channel (No in step S206). At this time, the data memory 111 stores an output matrix obtained by adding together the results of the matrix calculation for the first input channel and the results of the matrix calculation for the second input channel.
[0042] Thereafter, the same process as that for the second input channel is repeatedly performed until the process for the nth input channel (n=3 in this example) is completed (step S206: Yes, S207: No). When the process for the nth input channel is completed, the data memory 111 stores an output matrix that is the result of matrix calculation for all input data (all input channels).
[0043] The calculation device 100 repeats the above process for the n input channels until a predetermined number m of output matrices (m=3 in this example) is obtained (step S207: Yes, S208: No). As a result, m output matrices are stored in the data memory 111, and m submaps corresponding to the output matrices are stored in the submap memory 114. These m output matrices are used as input channels for the convolution calculation of the next layer.
[0044] 3 is a flow diagram showing a procedure performed by the arithmetic device 100 of this embodiment when performing convolution operations on the second and subsequent layers. Note that FIG. 3 illustrates an example in which the number of input channels is n and the number of output channels is m. Furthermore, the number of input channels n is equal to the number m of output matrices (output channels) calculated by the convolution operation of the immediately preceding layer. This procedure is initiated, for example, when the convolution operation of the immediately preceding layer is completed.
[0045] When this procedure starts, the map check unit 115 reads the submap corresponding to the first input channel from the submap memory 114 and checks the status information included in this submap (step S301).
[0046] If the status information indicates the above-mentioned status 1, the map check unit 115 reads the submap corresponding to the second input channel from the submap memory 114 and checks the status information contained in the submap (step S302 Yes, S310 No, S301).
[0047] If the state information indicates the above-described state 2 or state 3, the map check unit 115 causes the matrix calculation unit 112 to read a kernel to be used for matrix calculation for the first input channel from the data memory 111. Then, it is confirmed whether the kernel satisfies the above-described conditions (step S302: No, S303). If the kernel satisfies the above-described conditions, the map check unit 115 reads a submap corresponding to the second input channel from the submap memory 114 and checks the state information included in the submap (step S304: Yes, S310: No, S301).
[0048] Furthermore, if the state information indicates the above-described state 4, the map check unit 115 causes the matrix calculation unit 112 to execute a matrix calculation (step S302: No). In this case, the matrix calculation unit 112 reads, from the data memory 111, a kernel to be used for the matrix calculation for the first input channel (steps S302: No, S303). At this time, the matrix calculation unit 112 also reads, from the data memory 111, data belonging to the coordinate region to be used for the matrix calculation from the input data belonging to the first input channel, and the above-described bias (steps S304: No, S305). As described above, in the case of the convolution calculation for the kth layer, each of the multiple output matrices calculated in the convolution calculation for the k-1th layer is used as an input channel.
[0049] Next, the matrix calculation unit 112 performs a matrix calculation and stores the calculated output value together with information indicating the coordinate region in the data memory 111 (steps S306 and S307). At this time, the matrix calculation unit 112 inputs the output value to the zero check unit 113. In response to this input, the zero check unit 113 determines which of multiple ranges defined by multiple preset thresholds the value belongs to. The zero check unit 113 then stores the determination result in the submap memory 114 and updates the previously stored state information (step S308).
[0050] The arithmetic device 100 repeats the above process until it is completed for all coordinate regions belonging to the first input channel (step S309: No).
[0051] When the calculation for the first input channel is completed, the map check unit 115 reads the submap corresponding to the second input channel from the submap memory 114 and checks the status information contained in the submap (steps S309: Yes, S310: No, S301). Subsequent processing, similar to the processing for the first input channel described above, is repeated until processing for the nth input channel (n=3 in this example) is completed (steps S309: Yes, S310: No). When processing for the nth input channel is completed, the data memory 111 stores an output matrix, which is the result of matrix calculation for all input data (all input channels).
[0052] The calculation device 100 also repeatedly performs the above processing on the n input channels until a predetermined number m of output matrices (m = 3 in this example) is obtained (Yes in step S310, No in step S311). As a result, m output matrices are stored in the data memory 111, and m submaps corresponding to each output matrix are stored in the submap memory 114. These m output matrices are used as input channels for the convolution calculation of the next layer. The calculation device 100 then repeatedly performs the procedures performed in the convolution calculation of the second layer and subsequent layers until all convolution calculations for the specified number of layers are completed.
[0053] As described above, in the arithmetic device 100 of this embodiment, state information is created based on each element of the output matrix of the convolution operation in the immediately preceding layer, and if the state information satisfies a pre-specified condition, the matrix calculation using the input channel corresponding to the state information is skipped. At this time, data belonging to the input channel is not read from the data memory 111 to the matrix calculation unit 112. In other words, since unnecessary data is not read, the wasted data read time can be further reduced, and the time required for the entire calculation can be further shortened compared to conventional methods.
[0054] Here, an example of the configuration of the zero check unit 113 will be described. Fig. 4 is a schematic configuration diagram showing an example of the zero check unit 113 provided in the arithmetic device 100. As shown in Fig. 4, the zero check unit 113 has an input terminal 31, a comparison terminal 32, and an output terminal 33. The input terminal 31 receives an output value from the matrix calculation unit 112. The comparison terminal 32 receives state information and the like stored in the submap memory 114. The output terminal 33 outputs data to be stored in the submap memory 114.
[0055] The output value from the matrix calculation unit 112 input through the input terminal 31 is input to the comparison unit 34, which has a plurality of comparators. The comparison unit 34 includes a number of comparators equal to or greater than the number of preset thresholds. As described above, in this embodiment, three thresholds are set, and therefore the comparison unit 34 includes three comparators 34a, 34b, and 34c. The output value from the matrix calculation unit 112 is input to one input terminal of each of the comparators 34a, 34b, and 34c, and the threshold is input to the other input terminal. Note that, although not particularly limited, in this example, when the output value input to each of the comparators 34a, 34b, and 34c from the matrix calculation unit 112 is greater than the threshold, the comparators 34a, 34b, and 34c output the value "1."
[0056] The outputs of the comparators 34a, 34b, and 34c are input to the checker 35. The status information currently stored in the submap memory 114 is also input to the checker 35 via the comparison terminal 32. As described above, the status information stored in the submap memory 114 is a numeric value between "0" and "3."
[0057] When the output of each of the comparators 34a, 34b, and 34c contains the value "1" and the status information stored in the submap memory 114 needs to be updated, the checker 35 outputs an output corresponding to the updated status information to the output terminal 33. For example, when the stored status information is "0," the checker 35 updates the status information to one of the values "1," "2," or "3" depending on the outputs of the comparators 34b and 34c when at least the output of the comparator 34a is the value "1." When the stored status information is "1," the checker 35 updates the status information to one of the values "2" or "3" depending on the output of the comparator 34c when at least the output of the comparator 34b is the value "1." When the stored status information is "2," the checker 35 updates the status information to the value "3" when the output of the comparator 34c is the value "1." When the stored status information is "3," the checker 35 does not update the status information.
[0058] With the zero check unit 113 having the above configuration, when a convolution operation for obtaining one output matrix is completed, status information corresponding to that output matrix is stored in the submap memory 114. The zero check unit 113 can also be realized with other configurations. For example, a configuration in which the zero check unit 113 holds a cumulative value of the number of output values belonging to each range can be adopted. In this case, each time an output value is output from the matrix calculation unit 112, the zero check unit 113 can determine which of the above-mentioned multiple ranges the output value belongs to based on the held cumulative value.
[0059] Although not particularly limited, in this example, the zero check unit 113 is configured to be able to make the above-mentioned judgments as well as to make a negative judgment as to whether or not the elements of the output matrix contain negative values, and to count the number of elements in the output matrix that exceed any of the above-mentioned thresholds. Note that negative judgment information indicating the result of the negative judgment and count information indicating the coefficient result are stored in the submap memory 114. The negative judgment information and count information, together with the above-mentioned state information, are information that constitute the above-mentioned submap.
[0060] That is, the zero check unit 113 includes a comparator 34d in the comparison unit 34, one input terminal of which receives the output value from the matrix calculation unit 112 and the other input terminal of which receives the numerical value "0." The comparator 34d is configured to output the numerical value "1" if the input output value from the matrix calculation unit 112 is smaller than "0." The output of the comparator 34d is input to an OR circuit 36. The OR circuit 36 also receives the negative determination information currently stored in the submap memory 114 via a comparison terminal 32. If either the output of the comparator 34d or the negative determination information stored in the submap memory 114 is the numerical value "1," the OR circuit 36 outputs the numerical value "1" to the output terminal 33. That is, when the convolution operation to obtain one output matrix is completed, if an element of the output matrix contains a negative value, the numerical value "1" is stored in the submap memory 114 as negative determination information. If the elements of the output matrix do not contain negative values, the value "0" is stored in the submap memory 114 as negative determination information.
[0061] The zero check unit 113 also includes a selector 37 to which the outputs of the comparators 34a, 34b, and 34c are input. The selector 37 inputs a preset output from the comparators 34a, 34b, and 34c to a counter 38. The counter 38 also receives the count information currently stored in the submap memory 114 via a comparison terminal 32. When the counter 38 receives the value "1," it outputs a value obtained by adding "1" to the stored count information to an output terminal 33. For example, when counting the number of elements in the output matrix that are greater than the third threshold, the selector 36 is set to a state that outputs the output value of the comparator 34c. According to this configuration, when the convolution operation to obtain one output matrix is completed, the count values of the elements in the output matrix that are greater than the third threshold are stored in the submap memory 114 as count information.
[0062] The negative determination information can be used as a flag to determine which process to implement when different processes are required depending on whether or not a negative value is present. Furthermore, the count information can be used to skip the corresponding output matrix (input channel) without reading it if the total number of elements exceeds a predetermined threshold, even if the count information contains elements exceeding a predetermined threshold.
[0063] FIG. 5 is a diagram showing an example of a submap. While not particularly limited, the submap shown here is a 1-byte (8-bit) submap. As described above, in this embodiment, the submap 40 includes status information, negative determination information, and count information. In this example, the submap 40 is configured with 2 bits of status information, 1 bit of negative determination information, and 5 bits of count information. It is preferable that the address information of the submap 40 in the submap memory 114 and the address information of the output matrix (input channel of the next layer) corresponding to the submap 40 stored in the data memory 111 are correlated with each other. This correlation may be achieved, for example, by adding a predetermined offset to the top address of the output matrix corresponding to the submap 40.
[0064] 2 and 3, the zero check unit 113 is configured to update the state information in step S205 or step S308 each time the matrix calculation unit 112 outputs a calculation result. However, the state information can also be updated at other times. For example, a configuration can be adopted in which the zero check unit 113 creates state information and stores it in the submap memory 114 only when performing matrix calculation for the last input channel to perform matrix calculation among input channels belonging to the same layer, that is, when performing matrix calculation to determine the values of the elements of the output matrix.
[0065] In the configuration of the arithmetic device 100 described above, the submap memory 114 stores submaps corresponding to all output matrices calculated by the matrix calculation. Therefore, if the number of layers of the convolution operation and the number of output matrices in each layer are large, a large storage area must be prepared for the submap memory 114. Here, a configuration that can reduce the storage area required for the submap memory 114 will be described. Figure 6 is a schematic diagram showing the configuration of a modified example of the arithmetic device according to one embodiment of the present invention. Note that in Figure 6, components that achieve the same effects as those of the arithmetic device 100 are designated by the same reference numerals as in Figure 1, and detailed description thereof will be omitted below.
[0066] As shown in FIG. 6 , the arithmetic device 300 of this embodiment further includes a submap address buffer 120. The arithmetic device 300 creates a submap address table in addition to the submap created by the arithmetic device 100 described above. The submap address table is stored in the submap address buffer 120. As shown in FIG. 7 , the submap address table 41 is a table in which ID numbers, address information, and usage information are recorded in a linked state. The submap address buffer 120 may be configured as part of the memory device that constitutes the submap memory 114 or the memory device that constitutes the data memory 111, or may be configured as a separate memory device.
[0067] The ID number functions as information for identifying a submap. As described above, a submap is created for each input channel used as input data for the convolution operation of the next layer, i.e., for each output channel in the layer where the convolution operation is performed. Therefore, the number of ID numbers is the same as the number of output channels. Although not particularly limited, in this embodiment, a unique ID number is assigned that combines a number indicating which layer of the convolution operation and a number indicating which output channel. For example, if three output channels are operated in the (k-1)th layer, the ID numbers assigned are "k1," "k2," and "k3." More specifically, the ID numbers assigned to the three output channels in the second layer are "31," "32," and "33." Since these output channels become input channels in the operation of the third layer, address information associated with the ID numbers "31," "32," and "33," respectively, is referenced when reading a submap.
[0068] The address information indicates the storage location of a submap in the submap memory 114. More specifically, it is, for example, the starting address of the storage location of the submap. As described with reference to FIG. 5, the data length (number of bits) of a submap is constant. Therefore, the storage location of a submap in the submap memory 114 can be specified by a single address.
[0069] The usage information indicates whether the associated submap has been used in the convolution calculation of the next layer. In FIG. 7 , the usage information is displayed as "valid." As described above, a submap is created for each input channel used as input data for the convolution calculation of the next layer. Therefore, a submap read and used in the convolution calculation of the next layer is not used in subsequent convolution calculations. In this embodiment, the values "0" and "1" are used to indicate that a submap has been used and that it has not been used, respectively. In this case, a new ID number, address information, and usage information can be associated and stored in a record in the submap address table whose usage information is "0."
[0070] In this embodiment, the controller 116 generates the ID number, address information, and usage information and records them in the submap address table of the submap address buffer 120, but other configurations are also possible. For example, a submap address management unit having the function of performing these processes may be provided separately from the controller 116.
[0071] Next, the operation of the arithmetic device 300 having the above configuration will be described. FIG. 8 is a flow diagram showing a procedure for implementing a technique for acquiring data in the same coordinate region for all input channels in the first-layer convolution calculation by the arithmetic device 300. FIG. 8 illustrates an example in which the number of input channels is n and the number of output channels is m. Although not particularly limited, this procedure may be initiated, for example, when data to be calculated is stored in the data memory 111 from outside the arithmetic device 300. As described above, the arithmetic device 300 differs from the arithmetic device 100 only in that the arithmetic device 300 creates a submap address table. Therefore, in the procedure shown in FIG. 8, steps that perform the same operations as those of the arithmetic device 100 are assigned the same reference numerals as those in FIG. 2, and detailed description thereof will be omitted below.
[0072] When this procedure starts, the matrix calculation unit 112 starts matrix calculation of the first output matrix (output channel). At this time, the controller 116 generates data for the submap address table (step S220). That is, the controller 116 generates the above-mentioned ID number, address information, and usage information, and records them in the submap address table 41 of the submap address buffer 120. The controller 116 records the generated information in the submap address table 41 in a record whose usage information is "0."
[0073] According to the above-mentioned ID number generation rules, the ID number "21" will be generated in this case. As address information, an address in the submap memory 114 is appropriately selected. For example, a configuration can be adopted in which all selectable addresses in the submap memory 114 are recorded in the submap address table 41, and the controller 116 selects the address information recorded in the record into which information is to be written as the address information to be linked to the generated ID number. Note that since the linked submap has not yet been read, the usage information recorded is "1."
[0074] When the generation of the data for the submap address table is completed, the matrix calculation unit 112 starts matrix calculation for the first input channel. The procedure for matrix calculation for the first input channel is generally the same as the procedure described in FIG. 2. That is, the kernel reading (step S201), data reading (step S202), matrix calculation (step S203), and calculation result storage (step S204) are as described above. In addition, in storing the determination result by the zero check unit 113 (step S205), the zero check unit 113 stores the determination result in a storage location in the submap memory 114 specified by the address information generated by the controller 116.
[0075] The calculation device 300 repeats the above process until it is completed for all coordinate regions belonging to the first input channel (No in step S206). At this time, the data memory 111 stores the output matrix calculated for the first input channel.
[0076] When the calculation for the first input channel is completed, the matrix calculation unit 112 starts matrix calculation for the second input channel (step S206: Yes, S207: No). The procedure for matrix calculation for the second input channel is also generally the same as the procedure described in FIG. 2. That is, the kernel reading (step S201), data reading (step S202), matrix calculation (step S203), and calculation result storage (step S204) are as described above. In addition, in storing the determination result by the zero check unit 113 (step S205), the zero check unit 113 stores the determination result in a storage location in the submap memory 114 specified by the address information generated by the controller 116.
[0077] The arithmetic device 300 repeats the above process until it is completed for all coordinate regions belonging to the second input channel (No in step S206). Thereafter, the same process as the process for the second input channel is repeated until it is completed for the nth input channel (n=3 in this example) (Yes in step S206, No in step S207). When the process for the nth input channel is completed, the data memory 111 stores an output matrix that is the result of matrix calculation for all input data (all input channels).
[0078] The arithmetic unit 300 repeatedly performs the above process on the n input channels until a predetermined number m of output matrices (m = 3 in this example) is obtained (step S207: Yes, S208: No). When the matrix calculation unit 112 starts matrix calculation for the second output matrix (output channel), the controller 116 generates submap address table data corresponding to the output matrix (step S220). That is, the controller 116 generates an ID number, address information, and usage information, and records them in the submap address table 41 of the submap address buffer 120. The controller 116 records the generated information in a record in the submap address table 41 whose usage information is "0." According to the ID number generation rules described above, the generated ID number at this time is "22." Because the associated submap has not yet been read, the recorded usage information is "1."
[0079] When all calculations to obtain a predetermined number m of output matrices are completed, m output matrices will be stored in data memory 111, m submaps corresponding to the respective output matrices will be stored in submap memory 114, and address information and usage information corresponding to each of the m output matrices will be recorded in submap address buffer 120. These m output matrices will be used as input channels for the convolution operation of the next layer.
[0080] In the above description, the submap address table data is generated at the start of the output matrix calculation. However, the table data may be generated at any other timing as long as it is generated before the zero check unit 113 first stores the determination result (status information) in the submap memory 114 in the matrix calculation for one output channel.
[0081] FIG. 9 is a flow diagram showing the procedure performed by the arithmetic device 300 of this embodiment when performing convolution operations on the second and subsequent layers. Note that FIG. 9 illustrates an example in which the number of input channels is n and the number of output channels is m. The number of input channels n is equal to the number m of output matrices (output channels) calculated by the convolution operation of the immediately preceding layer. This procedure is initiated, for example, when the convolution operation of the immediately preceding layer is completed. Note that, as described above, the arithmetic device 300 differs from the arithmetic device 100 only in that the arithmetic device 300 creates a submap address table. Therefore, in the procedure shown in FIG. 9 , steps that perform the same operations as those of the arithmetic device 100 are denoted by the same reference numerals as those in FIG. 3 , and detailed description thereof will be omitted below.
[0082] When this procedure starts, the matrix calculation unit 112 starts matrix calculation of the first output matrix (output channel). At this time, the controller 116 generates data for the submap address table (step S320). That is, the controller 116 generates the above-mentioned ID number, address information, and usage information, and records them in the submap address table 41 of the submap address buffer 120. The controller 116 records the generated information in a record in the submap address table 41 whose usage information is "0." According to the above-mentioned ID number generation rules, the ID number generated at this time is "31." Furthermore, because the associated submap has not yet been read, the recorded usage information is "1."
[0083] Once the generation of the submap address table data is complete, the matrix calculation unit 112 begins matrix calculation for the first input channel. At this time, the map check unit 115 reads address information for the submap corresponding to the first input channel from the submap address buffer 120 (step S321). Based on the address information, the map check unit 115 then reads the submap corresponding to the first input channel from the submap memory 114 and checks the status information included in the submap (step S301). For example, if the calculation is for the first input channel of the second layer, the map check unit 115 reads address information associated with ID number "21." The map check unit 115 also notifies the controller 116 of the ID number associated with the address information read from the submap address buffer 120. Upon receiving this notification, the controller 116 rewrites the usage information associated with the ID number in the submap address buffer 120 from "1" to "0." Note that the usage information can be rewritten at any time, not just at the specified timing. However, from the viewpoint of efficient use of the storage area of the submap memory 114, it is preferable that this be performed after the address information is read and before a new submap is stored in the submap memory 114.
[0084] 3, the zero check unit 113 stores the result of the determination in a storage location in the submap memory 114 specified by the address information generated by the controller 116 (step S308). The calculation device 300 repeats the above process until it is completed for all coordinate regions belonging to the first input channel (step S309: No).
[0085] When the calculation for the first input channel is completed, the map check unit 115 reads address information of the submap corresponding to the second input channel from the submap address buffer 120 (steps S309: Yes, S310: No, S321). Then, based on the address information, the map check unit 115 reads the submap corresponding to the second input channel from the submap memory 114 and checks the status information included in the submap (step S301). Subsequent processing, similar to the processing for the first input channel described above, is repeated until processing for the nth input channel (n=3 in this example) is completed (steps S309: Yes, S310: No). When processing for the nth input channel is completed, the data memory 111 stores the output matrix, which is the result of matrix calculation for all input data (all input channels).
[0086] The arithmetic unit 300 repeatedly performs the above process on the n input channels until a predetermined number m of output matrices (m = 3 in this example) is obtained (step S310: Yes, S311: No). When the matrix calculation unit 112 starts matrix calculation for the second output matrix (output channel), the controller 116 generates submap address table data corresponding to the output matrix (step S320). That is, the controller 116 generates an ID number, address information, and usage information, and records them in the submap address table 41 of the submap address buffer 120. The controller 116 records the generated information in a record in the submap address table 41 whose usage information is "0." According to the ID number generation rules described above, the generated ID number at this time is "32." Because the associated submap has not yet been read, the usage information recorded is "1."
[0087] When all calculations to obtain the predetermined number m of output matrices are completed, data memory 111 will store m output matrices, submap memory 114 will store m submaps corresponding to the output matrices, and submap address buffer 120 will record address information and usage information corresponding to each of the m output matrices. These m output matrices will be used as input channels for the convolution operation of the next layer. The arithmetic unit 300 then repeatedly performs the procedures performed for the convolution operations of the second and subsequent layers until all convolution operations for the specified number of layers are completed.
[0088] As described above, in the arithmetic unit 300 of this embodiment, by using the submap address table, it becomes possible to overwrite a new submap in an area of the submap memory 114 where a submap that will not be used in the future is stored. As a result, the submap memory 114 can be realized using a memory with a limited size, such as a ring buffer.
[0089] The above-described arithmetic units 100 and 300 are configured to generate submaps only for input channel data used in convolution calculations and determine whether to read the input channel data based on the status information included in the submaps. However, such status information can also be applied to kernels used in matrix calculations of input data. That is, a configuration can also be adopted in which status information is created based on each element of the kernel, and if the status information satisfies a predetermined condition, the matrix calculation using the kernel corresponding to the status information is skipped without reading the input channel data. In this case, since the kernel is a matrix whose element values are predetermined, the status information of the kernel can be acquired in advance. For example, the status information of the kernel can be stored in the submap memory 114, and the map check unit 115 can determine whether to read the input channel data in step S302 of FIG. 3 or FIG. 9 by taking into account the status information of the kernel in addition to the status information of the input channel.
[0090] In the above-described arithmetic device 100, the matrix calculation unit 112 performs matrix calculations for the entirety of one input channel, and then performs matrix calculations for the entirety of the next input channel after completion. However, matrix calculations do not need to be performed continuously for the entirety of the input channels. Here, a configuration is described in which matrix calculations are performed for each element of the output matrix. In such a configuration, matrix calculations are performed for each coordinate region that constitutes a portion of the input channel. FIG. 10 is a diagram for explaining the concept of this technique. FIG. 10 illustrates an example in which three output matrices (output channels) are obtained from three input channels. In addition, this technique only changes the order in which data is read by the matrix calculation unit 112, etc., and the configuration of the arithmetic device is the same as the configuration shown in FIG. 1.
[0091] As shown in Fig. 10 , data in the same coordinate region in the three input channels is used to calculate an element located at a specific coordinate in each of the three output matrices. For example, in Fig. 10 , the matrix calculation to calculate element 61a located at coordinates (2, 3) in first output matrix 61 uses data belonging to a 3 x 3 coordinate region 51a centered at coordinates (2, 3) in the first input channel 51, data belonging to a 3 x 3 coordinate region 52a centered at coordinates (2, 3) in the second input channel 52, and data belonging to a 3 x 3 coordinate region 53a centered at coordinates (2, 3) in the third input channel 53. Similarly, the matrix calculation to calculate element 62a located at coordinates (2, 3) in the second output matrix 62 and element 63a located at coordinates (2, 3) in the third output matrix 63 also uses data belonging to the coordinate region 51a in the first input channel 51, data belonging to the coordinate region 52a in the second input channel 52, and data belonging to the coordinate region 53a in the third input channel 53, with only different kernels.
[0092] Therefore, an output matrix identical to the output matrix calculated in the above-described embodiment can also be calculated by sequentially reading out the data in the coordinate region 51a of the first input channel 51, the data in the coordinate region 52a of the second input channel 52, and the data in the coordinate region 53a of the third input channel 53, and then sequentially reading out the data in the coordinate regions whose positions have been changed in each of the input channels 51, 52, and 53, and performing matrix calculations.
[0093] 11 is a flow diagram showing a procedure for implementing a technique for acquiring data in the same coordinate region for all input channels in the first-layer convolution calculation by the calculation device 100. Fig. 11 shows an example in which the number of input channels is n and the number of output channels is m. While not particularly limited, this procedure is initiated, for example, when data to be calculated is stored in the data memory 111 from outside the calculation device 100.
[0094] When this procedure is started, first, the coordinates of the elements of the output matrix to be calculated are determined (step S701). Then, based on the determined coordinates, the coordinate region of the input channel required for the matrix calculation is identified (step S702). Note that in this embodiment, the controller 116 determines the coordinates of the elements in the output matrix and identifies the coordinate region of the input channel.
[0095] The matrix calculation unit 112 reads, from the data memory 111, a kernel used for matrix calculation for the first input channel with respect to the first output matrix (step S703). The matrix calculation unit 112 also reads, from the data memory 111, data belonging to the coordinate region of the first input channel and the bias described above (step S704). As described above, the bias for the first input channel is a zero matrix.
[0096] The matrix calculation unit 112 executes the matrix calculation and stores the output value, which is the calculation result, in the data memory 111 together with information indicating the coordinate region (steps S705 and S706). At this time, the matrix calculation unit 112 inputs the output value to the zero check unit 113. In response to this input, the zero check unit 113 performs the above-described state determination. Then, the zero check unit 113 stores the determination result in the submap memory 114 (step S707).
[0097] Next, the matrix calculation unit 112 reads from the data memory 111 a kernel to be used for matrix calculation of the first output matrix for the second input channel (step S708: No, S703). The matrix calculation unit 112 also reads from the data memory 111 data belonging to the coordinate region of the second input channel and the bias (step S704). At this time, the bias is a matrix in which elements of the output matrix currently being calculated that are stored in the data memory 111 at that time, other than the element to be calculated, are set to zero.
[0098] The matrix calculation unit 112 executes the matrix calculation and stores the output value, which is the calculation result, in the data memory 111 together with information indicating the coordinate region (steps S705 and S706). At this time, the matrix calculation unit 112 inputs the output value to the zero check unit 113. In response to this input, the zero check unit 113 performs the above-described state determination. Then, the zero check unit 113 stores the determination result in the submap memory 114 (step S707).
[0099] The calculation device 100 repeats the above process for the first output matrix until the process for the nth input channel (n=3 in this example) is completed (No in step S708). When the process for the nth input channel is completed, the data memory 111 stores the elements of the output matrix that are the results of matrix calculations performed for all input channels.
[0100] Furthermore, when processing for one element of the output matrix is completed, the controller 116 determines the coordinates of the next element of the output matrix to be calculated, and identifies the coordinate region of the input channel corresponding to the determined coordinates (steps S708: Yes, S709: No, S701, S702). The calculation device 100 then repeats the above processing until it has been completed for all elements of the output matrix (step S709: No).
[0101] The arithmetic device 100 repeats the above process until the process for the mth (m=3 in this example) output matrix is completed (step S709: Yes, S710: No).
[0102] 12 is a flow diagram showing a procedure for implementing a technique for acquiring data in the same coordinate region for all input channels in the convolution calculation of the second layer and subsequent layers by the calculation device 100. Fig. 12 shows an example in which the number of input channels is n and the number of output channels is m. While not particularly limited, this procedure is initiated, for example, when the convolution calculation of the immediately preceding layer is completed.
[0103] When this procedure starts, the controller 116 first determines the coordinates of the elements of the output matrix to be calculated, and then identifies the coordinate region of the input channel required for the matrix calculation based on the determined coordinates (steps S801 and S802).
[0104] The map check unit 115 reads out the submap corresponding to the first input channel for the first output matrix from the submap memory 114 and checks the status information included in the submap (step S803). If the result of the check indicates that matrix calculation is not to be performed, the map check unit 115 reads out the submap corresponding to the second input channel for the first output matrix from the submap memory 114 and checks the status information included in the submap (step S804: Yes, S811: No, S803).
[0105] If the result of the check indicates that the matrix calculation should proceed, the map check unit 115 causes the matrix calculation unit 112 to read a kernel to be used for the matrix calculation for the first input channel from the data memory 111. Then, it is checked whether the kernel satisfies the above-mentioned conditions (step S804: No, S805). If the result of the check indicates that the matrix calculation should not be performed, the map check unit 115 reads a submap corresponding to the second input channel for the first output matrix from the submap memory 114 and checks the status information included in the submap (step S806: Yes, S811: No, S803).
[0106] Furthermore, if the kernel check result indicates that the matrix calculation should proceed, the map check unit 115 causes the matrix calculation unit 112 to execute the matrix calculation (step S806: No). In this case, the matrix calculation unit 112 reads data belonging to the coordinate region to be used for the matrix calculation and the bias described above from the input data belonging to the first input channel stored in the data memory 111 (step S807). As described above, in the case of the kth layer convolution calculation, each of the multiple output matrices calculated in the k-1th layer convolution calculation is used as an input channel.
[0107] Next, the matrix calculation unit 112 executes the matrix calculation and stores the output value, which is the calculation result, in the data memory 111 together with information indicating the coordinate region (steps S808 and S809). At this time, the matrix calculation unit 112 inputs the output value to the zero check unit 113. In response to this input, the zero check unit 113 performs the above-described state determination. Then, the zero check unit 113 stores the determination result in the submap memory 114 (step S810).
[0108] The calculation device 100 repeats the above process for the first output matrix until the process for the nth input channel (n=3 in this example) is completed (step S811 No). When the process for the nth input channel is completed, the data memory 111 stores the elements of the output matrix, which are the results of matrix calculations performed for all input channels.
[0109] Furthermore, when processing for one element of the output matrix is completed, the controller 116 determines the coordinates of the next element of the output matrix to be calculated, and identifies the coordinate region of the input channel corresponding to the determined coordinates (steps S811: yes, S812: no, S801, S802). The calculation device 100 then repeats the above processing until it has been completed for all elements of the output matrix (step S812: no).
[0110] The calculation device 100 repeats the above process until the process for the mth (m=3 in this example) output matrix is completed (step S812: Yes, S813: No).
[0111] As explained above, the present technique can also achieve the above-mentioned effects. In the calculation device 100, state information is created based on each element of the output matrix of the convolution calculation in the immediately preceding layer, and if the state information satisfies a pre-specified condition, the matrix calculation using the input channel corresponding to the state information is skipped. At this time, the matrix calculation unit 112 skips the data belonging to the input channel without reading it from the data memory 111. In other words, since unnecessary data is not read, the wasted data read time can be further reduced, and the time required for the entire calculation can be further shortened compared to the conventional method.
[0112] 11 and 12, the zero check unit 113 is configured to update the state information in step S707 or step S810 each time the matrix calculation unit 112 outputs a calculation result. However, the state information can also be updated at other times. For example, a configuration can be adopted in which the zero check unit 113 creates state information and stores it in the submap memory 114 only when performing matrix calculation for the last input channel to perform matrix calculation among input channels belonging to the same layer, that is, when performing matrix calculation to determine the values of the elements of the output matrix.
[0113] Furthermore, in step S804 or S806 of the flow diagram shown in FIG. 12 , if reading of input data for all input channels for the same element of the output matrix is skipped, a zero check is not performed on that element. That is, the state information corresponding to that output matrix remains at its initial value and is not updated. Therefore, it is preferable to configure the initial value of the state information to be set to, for example, "0," which indicates state 1. With this configuration, if reading of input data for all input channels is skipped, that output matrix can be skipped without being read as input data in the next layer of the convolution calculation. That is, even if an element of the output matrix is not calculated, a zero-clear operation (access to the data memory 111) to set the value of that element to zero is not required.
[0114] In the above description, the matrix calculation unit 112 is configured to read one piece of coordinate domain data for each input channel. However, it is also possible to adopt a configuration in which the matrix calculation unit 112 reads multiple consecutive pieces of coordinate domain data for each input channel and writes the results of multiple matrix calculations to the data memory 111. This enables parallelization of matrix calculations. As can be seen from FIG. 10 , reading consecutive coordinate domain data for each input channel and performing matrix calculations is equivalent to performing matrix calculations on consecutive elements in the output matrix.
[0115] When the matrix calculation unit 112 performs multiple matrix calculations in parallel, for example, the output values of each matrix calculation are output at the same timing, which complicates the storage of output matrix status information by the zero check unit 113 in the submap memory 114. Therefore, when reading consecutive coordinate area data in each input channel to perform matrix calculation, the zero check unit 113 stores status information based on any one of the multiple calculated output values in the submap memory 114 as status information of all elements corresponding to the multiple output values.
[0116] FIG. 13 is a diagram illustrating the concept of this technique. FIG. 13 illustrates only one output matrix. For example, in FIG. 13 , when the matrix calculations for calculating element 71a located at coordinates (2, 3), element 71b located at coordinates (3, 3), and element 71c located at coordinates (4, 3) of output matrix 71 are parallelized, the zero check unit 113 registers the determination result for one of the elements (e.g., element 71c) in the submap memory 114 as the determination result for all elements 71a, 71b, and 71c. This facilitates parallelization of matrix calculations. Note that, while the example illustrated here uses three consecutive data as one unit, this technique can also be applied to consecutive data in units of output matrices, rows of output matrices, or input ranges of input channels.
[0117] In the configuration described above in which data of the same coordinate region is acquired for all input channels, the map check unit 115 checks the status information included in the submap and selects whether or not to read the data of the input channel into the matrix calculation unit 113. From the viewpoint of further reducing the time required for the entire calculation, it is preferable to check as few times as possible.
[0118] Fig. 14 is a schematic diagram showing the configuration of a computing device that can further reduce the number of checks. As shown in Fig. 14, computing device 200 includes a table creation unit 117 and a read control unit 118 in addition to the configuration of computing device 100 described above. Note that components in Fig. 14 that have the same functions and effects as computing device 100 are assigned the same reference numerals as in Fig. 1, and detailed description thereof will be omitted below.
[0119] Based on the determination result of the map check unit 115, the table creation unit 117 creates a table that specifies the output matrices to be read as input data by the matrix calculation unit 112. That is, when starting a convolution operation, the table creation unit 117 first causes the map check unit 115 to read state information corresponding to all input channels used in the convolution operation (all output matrices calculated in the convolution operation in the previous layer) and determines, using the method described above, whether to cause the matrix calculation unit 112 to read the state information as input data. Based on the determination result, the table creation unit 117 then creates a table that specifies the input channels to be read as input data by the matrix calculation unit 112. For example, if there are three input channels and the map check unit 115 determines that the first and third input channels should be read as input data by the matrix calculation unit 112, the table creation unit 117 creates a table indicating this. Although not particularly limited, in this embodiment, the table creation unit 117 is configured to store the created table itself.
[0120] The read control unit 118 causes the matrix calculation unit 112 to read data to be calculated based on the table created by the table creation unit 117. As described above, when a table indicating that the first input channel and the third input channel are to be read as input data by the matrix calculation unit 112 is created, the read control unit 118 causes the matrix calculation unit 112 to perform matrix calculation using only the first input channel and the third input channel in the convolution operation.
[0121] In the computing device 200, the table creation unit 117 and the read control unit can be realized, for example, by hardware including a processor and memory such as RAM or ROM, and software stored in the memory and running on the processor.
[0122] Next, the operation of the arithmetic unit 200 having the above configuration will be described. The arithmetic unit 200 also operates differently between the convolution operation for the first layer, which does not have a submap, and the convolution operation for the second layer and subsequent layers, which do have submaps. However, the operation of the convolution operation for the first layer is the same as the operation shown in FIG. 11 , and therefore a description thereof will be omitted here.
[0123] 15 is a flow diagram showing a procedure for implementing a technique for acquiring data in the same coordinate region for all input channels in the convolution calculations of the second layer and subsequent layers by the calculation device 200. Fig. 15 shows an example in which the number of input channels is n and the number of output channels is m. While not particularly limited, this procedure is initiated, for example, when the convolution calculation of the immediately preceding layer is completed.
[0124] When this procedure starts, first, the table creation unit 117 causes the map check unit 115 to read out state information corresponding to all input channels and determines, using the above-described method, whether or not to read the state information as input data to the matrix calculation unit 112. Then, the table creation unit 117 creates the above-described table based on the result of this determination (step S1101).
[0125] When the table creation is complete, the controller 116 determines the coordinates of the elements of the output matrix to be calculated, and specifies the coordinate region of the input channel required for the matrix calculation based on the determined coordinates (steps 1102 and S1103).
[0126] Based on the table created by the table creation unit 117, the read control unit 118 instructs the matrix calculation unit 112 to perform matrix calculation for the input channel listed first in the table. Based on this instruction, the matrix calculation unit 112 reads, from the data memory 111, a kernel to be used for matrix calculation for the input channel listed first in the table for the first output matrix (step S1104). At this time, the matrix calculation unit 112 also reads, from the data memory 111, data belonging to the coordinate region to be used for matrix calculation from the input data belonging to the input channel listed first in the table, and the bias described above (step S1105). As described above, in the case of the kth layer convolution calculation, each of the multiple output matrices calculated in the k-1th layer convolution calculation is used as an input channel.
[0127] Next, the matrix calculation unit 112 executes the matrix calculation and stores the output value, which is the calculation result, in the data memory 111 together with information indicating the coordinate region (steps S1106 and S1107). At this time, the matrix calculation unit 112 inputs the output value to the zero check unit 113. In response to this input, the zero check unit 113 performs the above-described state determination. Then, the zero check unit 113 stores the determination result in the submap memory 114 (step S1108).
[0128] The calculation device 200 repeats the above process for the first output matrix until it has completed the process for all input channels listed in the table (step S1109: No). When the process for all input channels in the table has been completed, the data memory 111 stores the elements of the output matrix that are the results of matrix calculation for all input channels.
[0129] Furthermore, when processing for one element of the output matrix is completed, the controller 116 determines the coordinates of the next element of the output matrix to be calculated, and identifies the coordinate region of the input channel corresponding to the determined coordinates (step S1109: Yes, S1110: No, S1102, S1103).The arithmetic device 100 then repeats the above processing until it has been completed for all elements of the output matrix (step S1110: No).
[0130] The arithmetic device 100 repeats the above process until the process for the mth (m=3 in this example) output matrix is completed (step S1110: Yes, S1111: No).
[0131] As described above, in the arithmetic device 200, state information is created based on each element of the output matrix of the convolution operation in the immediately preceding layer, and if the state information satisfies a pre-specified condition, the matrix calculation using the input channel corresponding to the state information is skipped. At this time, the matrix calculation unit 112 skips the data belonging to the input channel without reading it from the data memory 111. In other words, since unnecessary data is not read, the wasted data read time can be reduced, and the time required for the entire calculation can be further shortened compared to the conventional method. Furthermore, in the arithmetic device 200, the input channels used for the calculation are listed in a table, so there is no need to determine whether or not to read data belonging to the input channel each time a matrix calculation is performed. As a result, the time required for the entire calculation can be further shortened.
[0132] 15, the zero check unit 113 is configured to update the state information in step S1108 each time the matrix calculation unit 112 outputs a calculation result. However, the state information can also be updated at other times. For example, a configuration can be adopted in which the zero check unit 113 creates state information and stores it in the submap memory 114 only when performing matrix calculation for the last input channel to perform matrix calculation among input channels belonging to the same layer, that is, when performing matrix calculation to determine the values of the elements of the output matrix.
[0133] The above describes a configuration in which a submap containing status information is created for each output matrix. However, submaps can also be created in physical memory access units. Here, a physical memory access unit refers to the amount of data that can be obtained in a single memory access.
[0134] 16(a) and 16(b) are diagrams for explaining the concept of this technique. Fig. 16(a) corresponds to the case where the amount of data in one input channel is smaller than the memory access unit. Fig. 16(b) corresponds to the case where the amount of data in one input channel is larger than the memory access unit.
[0135] As shown in Figure 16(a), when the amount of data in one input channel is smaller than the memory access unit, the memory access unit will contain data from multiple input channels. In the example shown in Figure 16(a), memory access unit 81 contains data from three input channels, Ch0, Ch1, and Ch2. Memory access unit 82 contains data from two input channels, Ch2 and Ch3. In this example, creating submaps in input channel units would result in four submaps: 83a, 83b, 83c, and 83d, while creating submaps in memory access units would result in two submaps: 84a and 84b.
[0136] In this case, if the state information of the submap 84a of the memory access unit 81 is, for example, the above-mentioned state 1, it is possible to skip the matrix calculations for the three input channels Ch0, Ch1, and Ch2 simply by checking the state information. Furthermore, if the state information of the submap 84a of the memory access unit 81 is, for example, the above-mentioned state 4, it is possible to skip the matrix calculations for specific input channels by further checking the state information of the submaps 82a, 82b, and 82c of the three input channels Ch0, Ch1, and Ch2. In other words, compared to the above-mentioned configuration, it is possible to reduce the number of times the map check unit 115 checks the submaps.
[0137] 1, the zero check unit 113 may be configured to further determine, for each memory access, whether or not each element of the output matrix by the matrix calculation unit 112 falls within a predetermined range. In this case, the zero check unit 113 may be configured to store the determination result of the zero check unit 113 in the submap memory 114 as second state information.
[0138] On the other hand, as shown in Figure 16(b), when the amount of data in one input channel is larger than the memory access unit, the data for one input channel will be composed of multiple memory access units. In the example shown in Figure 16(b), the data for one input channel 95 is composed of four memory access units 91, 92, 93, and 94. In this example, creating submaps in input channel units will result in one submap 96a, while creating submaps in memory access units will result in four submaps 97a, 97b, 97c, and 97d.
[0139] In this case, if the state information of the input channel unit submap 96a is, for example, state 4 described above, it may be possible to skip matrix calculations for a portion of the input channel by further checking the state information of the four memory access unit submaps 97a, 97b, 97c, and 97d.
[0140] Such a technique can also be realized by configuring the zero check unit 113 in the configuration shown in FIG. 1 to further determine, on a memory access basis, whether each element of the output matrix by the matrix calculation unit falls within a pre-specified range.
[0141] Next, the operation when implementing this method will be described. In this method, too, the operation differs between the convolution operation in the first layer, where no submap exists, and the convolution operation in the second layer and thereafter, where submaps exist. However, the operation of the convolution operation in the first layer is the same as the operation shown in FIG. 2 except that the zero check unit 113 further stores the above-mentioned second state information in the submap memory 114, so a description thereof will be omitted here.
[0142] In addition, in the operation of the convolution operation for the second layer and beyond, in the flowchart shown in Figure 3, a step in which the map check unit 115 reads a submap corresponding to a memory access and checks the second state information included in the submap is added before and after the step in which the map check unit 115 reads a submap corresponding to an input channel and checks the state information included in the submap. That is, as shown in Figure 16(a), when the data amount of one input channel is smaller than the memory access unit, a step in which the submap corresponding to the memory access and checks the second state information included in the submap is added before the step in which the state information included in the submap is checked. Also, as shown in Figure 16(b), when the data amount of one input channel is larger than the memory access unit, a step in which the submap corresponding to the memory access and checks the second state information included in the submap is added after the step in which the state information included in the submap is checked.
[0143] As described above, the present method can also achieve the above-mentioned effects. In addition, the present method may enable the matrix calculation unit 112 to increase the number of times that data belonging to an input channel is skipped without being read out.
[0144] Although the above describes a configuration in which state information is not used in the convolution calculation of the first layer, it is not impossible to use state information in the convolution calculation of the first layer. As described with reference to FIG. 10 , in the convolution calculation, multiple output matrices are calculated using the same input channel in the matrix calculation of the same layer. Therefore, it is possible to use the state information registered in the submap memory 114 in the matrix calculation for calculating the first output matrix in the matrix calculation for calculating the second or subsequent output matrices in the convolution calculation of the same layer.
[0145] In this configuration, the operation when calculating the first output matrix of the same layer is the same as the part of calculating one output matrix in the flow chart shown in Fig. 2 and the operation shown in Fig. 11. Furthermore, the operation when calculating the second and subsequent output matrices of the same layer is the same as the case in which the state information read out by the map check unit 115 is the state information corresponding to the first output matrix of the same layer in the flow chart shown in Fig. 3 and the operation shown in Fig. 12.
[0146] As described above, according to the present invention, it is possible to reduce wasted time and further shorten the time required for the entire calculation compared to the conventional method.
[0147] It should be noted that the above-described embodiments do not limit the technical scope of the present invention, and various modifications and applications other than those already described are possible. For example, although the above embodiments do not mention a pooling layer, a pooling layer may exist between the convolution operation of the k-1th layer and the convolution operation of the kth layer. Even if pooling is performed on the output matrix, the characteristics of the output matrix before pooling are inherited in the data after pooling, so the information in the submap can be used without any problems. Furthermore, in the above-described embodiments, a case has been described in which the submap includes negative determination information and count information, but it is sufficient that the submap includes at least status information, and it is not necessary for it to include other information.
[0148] In addition, the various configurations mentioned in the embodiments can be used in any combination. Furthermore, the flow charts shown in Figures 2, 3, 8, 9, 11, 12, and 15 are examples, and the order of each step can be changed as appropriate within the scope of achieving equivalent effects.
[0149] Although the matrix calculation performed by the arithmetic device according to the present invention has been described above as a case where the matrix calculation is performed in a convolutional layer of a convolutional neural network, the present invention is not limited to the convolutional layer of a convolutional neural network and can be applied to any matrix calculation in which the output matrix of a previous matrix calculation is used as the data to be calculated in the subsequent matrix calculation.
[0150] According to the present invention, it is possible to reduce wasted time, and as a result, it is possible to further reduce the time required for the entire calculation compared to the conventional art, and it is useful as a calculation device.
[0151] 100, 200, 300 arithmetic unit 111 data memory 112 matrix calculation unit 113 zero check unit 114 submap memory 115 map check unit 116 controller 117 table creation unit 118 read control unit 120 submap address buffer
Claims
1. A calculation device in which an output matrix of a previous matrix calculation is used as target data for a subsequent matrix calculation in a series of matrix calculations, the calculation device comprising: a data memory for storing target data; a matrix calculation unit for reading the data from the data memory, performing matrix calculations, and storing an output matrix in the data memory; a zero check unit for determining whether each element of the output matrix falls within a pre-specified range; a sub-map memory for storing the results of the determination by the zero check unit as status information; and a map check unit for determining, based on the status information stored in the sub-map memory, whether to cause the matrix calculation unit to read out an output matrix corresponding to the status information as target data for calculation.
2. The arithmetic device according to claim 1, wherein the matrix calculation is a convolution operation in a convolutional neural network, the matrix calculation unit stores an output matrix in the data memory as data to be calculated in a next layer in the convolution operation, and the map check unit determines, based on the status information stored in the submap memory, whether or not to cause the matrix calculation unit to read out the output matrix corresponding to the status information as data to be calculated in the next layer in the convolution operation.
3. The arithmetic device according to claim 2, wherein the matrix calculation unit reads out the same coordinate region constituting a part of each input channel as the data for all input channels belonging to the same layer in the convolution calculation, and performs matrix calculation.
4. The arithmetic device according to claim 1, wherein the matrix calculation unit simultaneously reads out a plurality of pieces of data for successively calculating the same output matrix, and the zero check unit uses one of the plurality of pieces of status information corresponding to the plurality of pieces of data as status information for the plurality of pieces of data successively read out to the matrix calculation unit.
5. The arithmetic device according to claim 3, wherein the matrix calculation unit simultaneously reads out a plurality of pieces of data for which matrix calculation is to be performed successively in the same layer in the convolution calculation, and the zero check unit uses one of the plurality of pieces of state information corresponding to the plurality of pieces of data as state information for the plurality of pieces of data successively read out to the matrix calculation unit.
6. The arithmetic device according to claim 2, further comprising: a table creation unit that creates a table specifying the output matrix to be read by the matrix calculation unit based on the judgment result of the map check unit; and a read control unit that causes the matrix calculation unit to read the data based on the table.
7. The arithmetic device according to claim 1, wherein the zero check unit further determines whether each element of the output matrix by the matrix calculation unit falls within a pre-specified range in units of memory access, and the submap memory stores the determination result of the zero check unit as second state information.
8. The arithmetic device according to claim 2, wherein the zero check unit further determines whether each element of the output matrix by the matrix calculation unit falls within a pre-specified range in units of memory access, and the submap memory stores the determination result of the zero check unit as second state information.
9. The arithmetic device according to claim 2, wherein said map check unit executes matrix calculations after the first layer based on said state information stored in said submap memory as a result of an initial matrix calculation of a first layer in a convolution operation.
10. The arithmetic device of claim 2, further comprising a submap memory buffer that stores, in association with each other, information for identifying an output matrix corresponding to the status information, information indicating a storage location of the status information in the submap memory, and information indicating whether the status information has been used in a convolution operation of a next layer, and wherein a storage location in the submap memory associated with the usage information indicating use in a convolution operation of a next layer is selected as the storage location in the submap memory for the newly generated status information.
11. The arithmetic device according to claim 2, wherein the submap memory prestores kernel state information that determines whether each element of the kernel used in the matrix calculation falls within a prespecified range, and the map check unit determines, based on the state information stored in the submap memory and the kernel state information, whether to cause the matrix calculation unit to read out an output matrix corresponding to the state information as data to be calculated.
12. A calculation device according to any one of claims 1 to 11, wherein the zero check unit compares each element of the output matrix with a plurality of thresholds and determines which of a plurality of ranges defined by the plurality of thresholds all elements of the output matrix belong to.
13. The arithmetic device according to any one of claims 1 to 11, wherein the zero check unit further determines whether or not a negative value exists in each element of the output matrix, or the number of elements that belong to any one of the multiple ranges.
14. An arithmetic device according to any one of claims 1 to 11, wherein the zero check unit creates status information during matrix calculation for an input channel that is the last to be matrix-calculated among input channels belonging to the same layer, and stores the status information in a submap memory.
Citation Information
Patent Citations
Sparse Optimization for Matrix Accelerator Architectures
JP2022523762A
Technologies for providing error correction for row direction and column direction in a cross point memory
US20190317857A1
Calculation circuit, calculation method, and program
WO2022123687A1
