Control method for a neural network circuit
By designing a ring-shaped convolution and quantization operation circuit in an embedded device and using semaphores to control data flow, the problem of insufficient computational performance of convolutional neural networks in IoT devices is solved, and efficient and low-power neural network circuit operation is achieved.
Patent Information
- Application Number
- CN202180027773.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2020-04-13
- Filing Date
- 2021-04-12
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2041-04-12
AI Technical Summary
In embedded devices, especially IoT devices, it is difficult to efficiently achieve the computational performance of convolutional neural networks. Existing technologies cannot fully utilize the computing power of convolutional neural networks in devices with limited hardware resources.
A neural network circuit was designed. Through a ring-structured convolution and quantization circuit, data flow is controlled by semaphores. Combined with memory and DMA controller, the efficient alternation of convolution and quantization operations is achieved, reducing the number of memory accesses and power consumption.
It enables high-performance neural network circuit operations in embedded devices, improving computational efficiency and reducing power consumption, and is suitable for environments with limited hardware resources.
Smart Images

Figure CN115398447B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a control method for neural network circuits. This application claims priority based on Japanese Patent Application No. 2020-071933, filed on April 13, 2020, the contents of which are incorporated herein by reference. Background Technology
[0002] In recent years, Convolutional Neural Networks (CNNs) have been used as models for image recognition and other applications. CNNs are multi-layered structures with convolutional and pooling layers, requiring a large number of computations such as convolution operations. Various computational methods have been designed to speed up CNN-based operations (Patent Document 1, etc.).
[0003] Existing technical documents
[0004] Patent documents
[0005] Patent Document 1: Japanese Patent Application Publication No. 2018-077829 Summary of the Invention
[0006] The technical problem that the invention aims to solve
[0007] On the other hand, there is a desire to implement image recognition and other functions using convolutional neural networks in embedded devices such as IoT (Internet of Things) devices. However, it is difficult to embed the large-scale dedicated circuits described in Patent Document 1, etc., into embedded devices. Furthermore, in embedded devices with limited hardware resources such as CPU and memory, it is difficult to fully realize the computational performance of convolutional neural networks using only software.
[0008] In view of the above, the object of the present invention is to provide a control method for neural network circuits that enable neural network circuits that can be embedded in IoT devices and other embedded devices to operate with high performance.
[0009] Technical solutions for solving technical problems
[0010] To address the aforementioned technical challenges, the present invention proposes the following solutions.
[0011] Regarding the control method of the neural network circuit of the first aspect of the present invention, the neural network circuit includes: a first memory for storing input data; a convolution operation circuit for performing convolution operation on the input data stored in the first memory; a second memory for storing convolution operation output data of the convolution operation circuit; a quantization operation circuit for performing quantization operation on the convolution operation output data stored in the second memory; a second write semaphore for restricting writing to the second memory by the convolution operation circuit; a second read semaphore for restricting reading from the second memory by the quantization operation circuit; a third write semaphore for restricting writing to the first memory by the quantization operation circuit; and a third read semaphore for restricting reading from the first memory by the convolution operation circuit. In the control method of the neural network circuit, the convolution operation circuit performs the convolution operation based on the third read semaphore and the second write semaphore.
[0012] Invention Effects
[0013] The control method for neural network circuits of the present invention enables neural network circuits that can be embedded in IoT devices and other embedded devices to operate at high performance. Attached Figure Description
[0014] Figure 1 A diagram illustrating a convolutional neural network.
[0015] Figure 2 A diagram illustrating the convolution operation performed by a convolutional layer.
[0016] Figure 3 A diagram illustrating the unfolding of data in a convolution operation.
[0017] Figure 4 A diagram illustrating the overall structure of the neural network circuit according to the first embodiment.
[0018] Figure 5 A timing diagram illustrating an example of the operation of this neural network circuit.
[0019] Figure 6 Timing diagrams are shown to illustrate other working examples of this neural network circuit.
[0020] Figure 7 This is an internal block diagram of the DMAC of this neural network circuit.
[0021] Figure 8 This is a state transition diagram of the control circuit for the DMAC.
[0022] Figure 9 This is an internal block diagram of the convolution operation circuit of the neural network.
[0023] Figure 10 This is an internal block diagram of the multiplier unit of the convolution operation circuit.
[0024] Figure 11 This is an internal block diagram of the product sum operation unit of this multiplication operator.
[0025] Figure 12 This is an internal block diagram of the accumulator circuit of the convolution operation circuit.
[0026] Figure 13 This is an internal block diagram of the accumulator unit of the accumulator circuit.
[0027] Figure 14 This is an internal block diagram of the quantization operation circuit of the neural network circuit.
[0028] Figure 15 This is a block diagram of the vector operation circuit and the internal block diagram of the quantization circuit.
[0029] Figure 16 This is a block diagram of the arithmetic unit.
[0030] Figure 17 This is an internal block diagram of the vector quantization unit of the quantization circuit.
[0031] Figure 18 A diagram illustrating the control of this neural network circuit based on semaphores.
[0032] Figure 19 This is the timing diagram for the first data stream.
[0033] Figure 20 This is the timing diagram for the second data stream.
[0034] Figure 21 A diagram illustrating the commands executed during convolution operations.
[0035] Figure 22 A diagram illustrating a specific example of the convolution operation command.
[0036] Figure 23 A diagram illustrating the commands executed during quantization operations.
[0037] Figure 24 A diagram illustrating the commands executed during DMA forwarding.
[0038] Figure Labels
[0039] 200: Convolutional Neural Network; 100: Neural Network Circuit (NN Circuit); 1: First Memory; 2: Second Memory; 3: DMA Controller (DMAC); 4: Convolution Operation Circuit; 42: Multiplier; 43: Accumulator Circuit; 5: Quantization Operation Circuit; 52: Vector Operation Circuit; 53: Quantization Circuit; 6: Controller; 61: Register; S: Semaphore; F1: First Data Stream; F2: Second Data Stream; F3: Third Data Stream Detailed Implementation
[0040] (First Implementation)
[0041] Reference Figures 1 to 24 The first embodiment of the present invention will be described.
[0042] Figure 1 A diagram illustrating a convolutional neural network 200 (hereinafter referred to as "CNN 200"). The operations performed by the neural network circuit 100 (hereinafter referred to as "NN circuit 100") of the first embodiment are at least a portion of the learned CNN 200 used during inference.
[0043] [CNN 200]
[0044] CNN 200 is a multi-layered network comprising convolutional layers 210 for performing convolution operations, quantization layers 220 for performing quantization operations, and an output layer 230. In at least a portion of CNN 200, convolutional layers 210 and quantization layers 220 are alternately connected. CNN 200 is a widely used model for image recognition and motion image recognition. CNN 200 may also have fully connected layers or other layers with other functionalities.
[0045] Figure 2 A diagram illustrating the convolution operation performed by convolutional layer 210.
[0046] Convolutional layer 210 performs a convolution operation on the input data a using weights w. Convolutional layer 210 performs a product sum operation on the input data a and the weights w as inputs.
[0047] The input data 'a' (also called activation data or feature map) to the convolutional layer 210 is multidimensional data such as image data. In this embodiment, the input data 'a' is a three-dimensional tensor composed of elements (x, y, c). The convolutional layer 210 of the CNN 200 performs convolution operations on the lower-order input data 'a'. In this embodiment, the elements of the input data 'a' are 2-bit unsigned integers (0, 1, 2, 3). The elements of the input data 'a' can also be, for example, 4-bit or 8-bit unsigned integers.
[0048] If the input data to the CNN 200 is in a form such as 32-bit floating-point type, which is different from the input data a to the convolutional layer 210, the CNN 200 may also have an input layer that performs type transformation and quantization before the convolutional layer 210.
[0049] The weights w (also called filters or convolution kernels) of convolutional layer 210 are multidimensional data with elements that serve as learnable parameters. In this embodiment, the weights w are 4-dimensional tensors consisting of elements (i, j, c, d). The weights w have d three-dimensional tensors consisting of elements (i, j, c) (hereinafter referred to as "weights w0"). The weights w in the learned CNN 200 are the learned data. The convolutional layer 210 of CNN 200 uses the low-order weights w for convolution operations. In this embodiment, the elements of weights w are 1-bit signed integers (0, 1), where a value "0" represents +1 and a value "1" represents -1.
[0050] Convolutional layer 210 performs the convolution operation shown in Equation 1, outputting the output data f. In Equation 1, s represents the stride. Figure 2 The area shown by the dashed line in the middle represents one of the regions ao (hereinafter referred to as the "application region ao") where weight wo is applied to the input data a. The elements of the application region ao are represented by (x+i, y+j, c).
[0051] [Mathematical Expression 1]
[0052]
[0053] The quantization layer 220 performs quantization on the output of the convolution operation of the convolution layer 210. The quantization layer 220 has a pooling layer 221, a batch normalization layer 222, an activation function layer 223, and a quantization layer 224.
[0054] Pooling layer 221 performs average pooling (Equation 2) and max pooling (Equation 3) operations on the output data f of the convolution operation from convolutional layer 210, compressing the output data f of convolutional layer 210. In Equations 2 and 3, u represents the input tensor, v represents the output tensor, and T represents the size of the pooling region. In Equation 3, max is a function of the maximum value of the output u with respect to the combination of i and j contained in T.
[0055] [Mathematical Expression 2]
[0056]
[0057] [Mathematical Expression 3]
[0058] v (x, y, c) = max (u (T·x+i, T·y+j, c)), i∈T, j∈T... (Formula 3)
[0059] Batch normalization layer 222 normalizes the data distribution of the output data of quantization layer 220 and pooling layer 221 using operations such as those shown in Equation 4. In Equation 4, u represents the input tensor, v represents the output tensor, α represents the scale, and β represents the bias. In the learned CNN 200, α and β are learned constant vectors.
[0060] [Mathematical Expression 4]
[0061] v(x,y,c)=α(c)·(u(x,y,c)-β(c))......(Formula 4)
[0062] Activation function layer 223 performs ReLU (Equation 5) and other activation function operations on the outputs of quantization layer 220, pooling layer 221, and batch normalization layer 222. In Equation 5, u is the input tensor, and v is the output tensor. In Equation 5, max is a function of the maximum value among the output independent variables.
[0063] [Mathematical Expression 5]
[0064] v(x,y,c)=max(0,u(x,y,c))......(Formula 5)
[0065] Quantization layer 224 performs quantization on the outputs of pooling layer 221 and activation function layer 223 based on quantization parameters, as shown in Equation 6. The quantization shown in Equation 6 reduces the input tensor u to 2 bits. In Equation 6, q(c) is a vector of quantization parameters. In the learned CNN 200, q(c) is a learned constant vector. The inequality sign “≤” in Equation 6 can also be “<”.
[0066] [Mathematical Expression 6]
[0067]
[0068] Output layer 230 is the layer that outputs the result of CNN 200 using the identity function, the normalized exponential function (Softmax function), etc. The preceding layers of output layer 230 can be convolutional layers 210 or quantization operation layers 220.
[0069] In CNN 200, the output data of the quantized layer 224 is input to the convolutional layer 210. Therefore, compared with other convolutional neural networks that do not perform quantization, the convolutional operation of the convolutional layer 210 has a smaller load.
[0070] [Segmentation in Convolution Operations]
[0071] The NN circuit 100 performs the operation by dividing the input data of the convolution operation (Equation 1) of the convolutional layer 210 into partial tensors. There are no particular restrictions on the method or number of divisions into partial tensors. For example, a partial tensor can be formed by dividing the input data a(x+i, y+j, c) into a(x+i, y+j, co). Alternatively, the NN circuit 100 can also perform the operation without dividing the input data of the convolution operation (Equation 1) of the convolutional layer 210.
[0072] In the input data segmentation for convolution operations, as shown in Equation 7, the variable c in Equation 1 is segmented according to blocks of size Bc. Similarly, as shown in Equation 8, the variable d in Equation 1 is segmented according to blocks of size Bd. In Equation 7, co is the offset, and ci is the index from 0 to (Bc-1). In Equation 8, do is the offset, and di is the index from 0 to (Bd-1). Furthermore, the dimensions Bc and Bd can be the same.
[0073] [Mathematical Expression 7]
[0074] c = co·Bc + ci......(Equation 7)
[0075] [Mathematical Expression 8]
[0076] d = do·Bd + di......(Equation 8)
[0077] The input data a(x+i, y+j, c) in Equation 1 is divided along the c-axis by a dimension Bc, and is represented by the divided input data a(x+i, y+j, c). In the following explanation, the divided input data a will also be referred to as "divided input data a".
[0078] In Equation 1, the weights w(i, j, c, d) are divided along the c-axis by dimension Bc and along the d-axis by dimension Bd, and are represented by the divided weights w(i, j, co, do). In the following explanation, the divided weights w will also be referred to as "divided weights w".
[0079] The output data f(x, y, do) after being segmented according to size Bd is obtained using Equation 9. The final output data f(x, y, d) can be calculated by combining the segmented output data f(x, y, do).
[0080] [Mathematical Expression 9]
[0081]
[0082] [Unfolding data in convolution operations]
[0083] The NN circuit 100 expands the input data a and weight w in the convolution operation of the convolutional layer 210 to perform the convolution operation.
[0084] Figure 3 A diagram illustrating the unfolding of data in a convolution operation.
[0085] The segmented input data a(x+i, y+j, co) is expanded into vector data with Bc elements. The elements of the segmented input data a are indexed by ci (0 ≤ ci < Bc). In the following explanation, the segmented input data a expanded into vector data for each i and j is also referred to as "input vector A". With respect to input vector A, the elements are segmented input data a(x+i, y+j, co×Bc) to segmented input data a(x+i, y+j, co×Bc + (Bc - 1)).
[0086] The segmentation weights w(i, j, co, do) are expanded into a matrix of Bc × Bd elements. The elements of the expanded matrix segmentation weights w are indexed by ci and di (0 ≤ di < Bd). In the following explanation, the segmentation weights w expanded into a matrix for each i and j are also referred to as the "weight matrix W". The weight matrix W consists of segmentation weights w(i, j, co × Bc, do × Bd) to segmentation weights w(i, j, co × Bc + (Bc - 1), do × Bd + (Bd - 1)).
[0087] Vector data is computed by multiplying the input vector A by the weight matrix W. The output data f(x, y, do) is obtained by shaping the computed vector data for each i, j, co into a three-dimensional tensor. This data unfolding allows the convolution operation of convolutional layer 210 to be performed using multiplication of vector and matrix data.
[0088] [NN Circuit 100]
[0089] Figure 4 This diagram illustrates the overall structure of the NN circuit 100 in this embodiment.
[0090] The NN circuit 100 includes a first memory 1, a second memory 2, a DMA controller 3 (hereinafter also referred to as "DMAC 3"), a convolution operation circuit 4, a quantization operation circuit 5, and a controller 6. The NN circuit 100 is characterized in that the convolution operation circuit 4 and the quantization operation circuit 5 are formed in a ring through the first memory 1 and the second memory 2.
[0091] The first memory (first memory unit) 1 is a rewritable memory, such as a volatile memory composed of SRAM (Static RAM). Data is written to and read from the first memory 1 via the DMAC 3 and the controller 6. The first memory 1 is connected to the input port of the convolution operation circuit 4, which can read data from the first memory 1. Furthermore, the first memory 1 is connected to the output port of the quantization operation circuit 5, which can write data to the first memory 1. The external host CPU can input and output data to the NN circuit 100 by writing and reading data from the first memory 1.
[0092] The second memory (second memory unit) 2 is a rewritable memory, such as a volatile memory composed of SRAM (Static RAM). Data is written to and read from the second memory 2 via the DMAC 3 and the controller 6. The second memory 2 is connected to the input port of the quantization circuit 5, which can read data from the second memory 2. Furthermore, the second memory 2 is connected to the output port of the convolution circuit 4, which can write data to the second memory 2. The external host CPU can perform data input / output to the NN circuit 100 by writing and reading data from the second memory 2.
[0093] DMAC 3 is connected to the external bus EB and performs data forwarding between external memory such as DRAM and the first memory 1. Additionally, DMAC 3 performs data forwarding between external memory such as DRAM and the second memory 2. Furthermore, DMAC 3 performs data forwarding between external memory such as DRAM and the convolution operation circuit 4. Additionally, DMAC 3 performs data forwarding between external memory such as DRAM and the quantization operation circuit 5.
[0094] The convolution operation circuit 4 is a circuit that performs convolution operations in the convolutional layer 210 of the learned CNN 200. The convolution operation circuit 4 reads the input data a stored in the first memory 1 and performs a convolution operation on the input data a. The convolution operation circuit 4 writes the output data f of the convolution operation (hereinafter also referred to as "convolution operation output data") into the second memory 2.
[0095] The quantization circuit 5 is a circuit that performs at least a portion of the quantization operation in the quantization layer 220 of the learned CNN 200. The quantization circuit 5 reads the output data f of the convolution operation stored in the second memory 2, and performs quantization operations on the output data f of the convolution operation (including pooling, batch normalization, activation function, and at least the quantization operation). The quantization circuit 5 writes the output data of the quantization operation (hereinafter also referred to as "quantization output data") into the first memory 1.
[0096] Controller 6 is connected to the external bus EB and operates as a slave device of the external host CPU. Controller 6 has a register 61 that includes a parameter register and a status register. The parameter register controls the operation of the NN circuit 100. The status register includes a semaphore S indicating the status of the NN circuit 100. The external host CPU can access register 61 via controller 6.
[0097] Controller 6 is connected to the first memory 1, the second memory 2, the DMAC 3, the convolution operation circuit 4, and the quantization operation circuit 5 via the internal bus IB. An external host CPU can access each module via controller 6. For example, the external host CPU can issue commands to the DMAC 3, the convolution operation circuit 4, and the quantization operation circuit 5 via controller 6. Furthermore, the DMAC 3, the convolution operation circuit 4, and the quantization operation circuit 5 can update the status registers (including semaphores S) of controller 6 via the internal bus IB. The status registers (including semaphores S) can be configured to be updated via dedicated wiring connected to the DMAC 3, the convolution operation circuit 4, and the quantization operation circuit 5.
[0098] The NN circuit 100 includes a first memory 1, a second memory 2, etc., thus reducing the number of times duplicate data is forwarded during data forwarding from external memories such as DRAM by the DMAC 3. Consequently, power consumption due to memory access can be significantly reduced.
[0099] [Example 1 of NN circuit 100 operation]
[0100] Figure 5 A timing diagram is provided to illustrate an example of the operation of the NN circuit 100.
[0101] DMAC 3 stores the input data a of layer 1 in the first memory 1. DMAC 3 can segment the input data a of layer 1 and forward it to the first memory 1 in accordance with the order of convolution operations performed by the convolution operation circuit 4.
[0102] The convolution operation circuit 4 reads the input data a of layer 1 stored in the first memory 1. The convolution operation circuit 4 performs operations on the input data a of layer 1. Figure 1The convolution operation of layer 1 is shown. The output data f of the convolution operation of layer 1 is stored in the second memory 2.
[0103] The quantization circuit 5 reads the layer 1 output data f stored in the second memory 2. The quantization circuit 5 performs layer 2 quantization on the layer 1 output data f. The output data of the layer 2 quantization operation is stored in the first memory 1.
[0104] The convolution operation circuit 4 reads the output data of the quantization operation of layer 2 stored in the first memory 1. The convolution operation circuit 4 uses the output data of the quantization operation of layer 2 as input data a to perform the convolution operation of layer 3. The output data f of the convolution operation of layer 3 is stored in the second memory 2.
[0105] The convolution operation circuit 4 reads the output data of the quantization operation of layer 2M-2 (M is a natural number) stored in the first memory 1. The convolution operation circuit 4 uses the output data of the quantization operation of layer 2M-2 as input data a to perform a convolution operation of layer 2M-1. The output data f of the convolution operation of layer 2M-1 is stored in the second memory 2.
[0106] The quantization circuit 5 reads the output data f of layer 2M-1 stored in the second memory 2. The quantization circuit 5 performs layer 2M quantization on the output data f of layer 2M-1. The output data of the layer 2M quantization operation is stored in the first memory 1.
[0107] The convolution operation circuit 4 reads the output data of the quantization operation of layer 2M stored in the first memory 1. The convolution operation circuit 4 uses the output data of the quantization operation of layer 2M as input data a to perform a convolution operation of layer 2M+1. The output data f of the convolution operation of layer 2M+1 is stored in the second memory 2.
[0108] The convolution circuit 4 and the quantization circuit 5 perform operations alternately to advance... Figure 1 The CNN 200 shown illustrates the operation. In the NN circuit 100, the convolution operation circuit 4 performs convolution operations on layers 2M-1 and 2M+1 in a time-division manner. Additionally, in the NN circuit 100, the quantization operation circuit 5 performs quantization operations on layers 2M-2 and 2M in a time-division manner. Therefore, compared to the case where separate convolution operation circuits 4 and quantization operation circuits 5 are installed for each layer, the circuit size of the NN circuit 100 is much smaller.
[0109] The NN circuit 100 performs computations on a multi-layered CNN 200 by forming a ring-shaped circuit. The ring-shaped circuit structure of the NN circuit 100 allows for efficient utilization of hardware resources. Furthermore, in the NN circuit 100, to form a ring-shaped circuit, the parameters in the convolution operation circuit 4 and the quantization operation circuit 5, which vary in each layer, are appropriately updated.
[0110] When the computation in CNN 200 includes operations that cannot be performed by NN circuit 100, NN circuit 100 forwards intermediate data to an external computing device such as an external host CPU. After the external computing device performs the computation on the intermediate data, the result of the computation is input into the first memory 1 and the second memory 2. NN circuit 100 then re-performs the computation based on the result from the external computing device.
[0111] [Example 2 of NN circuit 100 operation]
[0112] Figure 6 Timing diagrams are shown to illustrate other operating examples of the NN circuit 100.
[0113] The NN circuit 100 can partition the input data 'a' into partial tensors and perform operations on these partial tensors in a time-division manner. There are no particular restrictions on the method or number of partitions.
[0114] Figure 6 This illustrates a working example of decomposing input data 'a' into two partial tensors. The decomposed partial tensors are designated as "first partial tensor a1" and "second partial tensor a2". For example, the convolution operation of layer 2M-1 is decomposed into a convolution operation corresponding to the first partial tensor a1 (in... Figure 6 The text describes the process as "layer 2M-1(a1)" and the convolution operation corresponding to the second tensor a2. Figure 6 It is recorded as “layer 2M-1(a2)”.
[0115] like Figure 6 As shown, the convolution and quantization operations corresponding to the first tensor a1 and the convolution and quantization operations corresponding to the second tensor a2 can be performed independently.
[0116] Convolution circuit 4 performs convolution operation on layer 2M-1 corresponding to the first tensor a1 (in Figure 6 The operation is represented by layer 2M-1 (a1). Then, convolution circuit 4 performs a convolution operation with layer 2M-1 corresponding to the second tensor a2 (in...). Figure 6 The operation is represented by layer 2M-1 (a2). Additionally, the quantization circuit 5 performs quantization operations on layer 2M corresponding to the first tensor a1 (in...). Figure 6 (The operation is represented by layer 2M(a1)). In this way, the NN circuit 100 can perform the convolution operation of layer 2M-1 corresponding to the second tensor a2 and the quantization operation of layer 2M corresponding to the first tensor a1 in parallel.
[0117] Next, convolution circuit 4 performs a convolution operation on layer 2M+1 corresponding to the first tensor a1 (in... Figure 6 The operation is represented by layer 2M+1(a1). Additionally, the quantization circuit 5 performs quantization operations on layer 2M corresponding to the second tensor a2 (in...). Figure 6 (The operation is represented by layer 2M(a2)). In this way, the NN circuit 100 can perform the convolution operation of layer 2M+1 corresponding to the first tensor a1 and the quantization operation of layer 2M corresponding to the second tensor a2 in parallel.
[0118] The convolution and quantization operations corresponding to the first tensor a1 and the second tensor a2 can be performed independently. Therefore, the NN circuit 100 can, for example, perform the convolution operation of layer 2M-1 corresponding to the first tensor a1 and the quantization operation of layer 2M+2 corresponding to the second tensor a2 in parallel. That is, the convolution and quantization operations performed in parallel by the NN circuit 100 are not limited to operations of consecutive layers.
[0119] By segmenting the input data 'a' into partial tensors, the NN circuit 100 enables the convolution operation circuit 4 and the quantization operation circuit 5 to operate in parallel. As a result, the standby time of the convolution operation circuit 4 and the quantization operation circuit 5 is reduced, and the computational processing efficiency of the NN circuit 100 is improved. Although in Figure 6 In the example shown, the number of segments is 2, but the same applies when the number of segments is greater than 2. The NN circuit 100 enables the convolution operation circuit 4 and the quantization operation circuit 5 to work in parallel.
[0120] For example, when input data a is divided into "first part tensor a1", "second part tensor a2", and "third part tensor a3", the NN circuit 100 can perform convolution operations of layer 2M-1 corresponding to the second part tensor a2 and quantization operations of layer 2M corresponding to the third part tensor a3 in parallel. The order of operations is appropriately changed according to the storage status of input data a in the first memory 1 and the second memory 2.
[0121] Furthermore, as a method for operating on partial tensors, the following example (Method 1) is shown: after operating on partial tensors in the same layer using convolution operation circuit 4 or quantization operation circuit 5, the operation on partial tensors in the next layer is performed. For example, as... Figure 6 As shown, in the convolution operation circuit 4, convolution operations are performed on layer 2M-1 corresponding to the first tensor a1 and the second tensor a2 (in... Figure 6 After the operations represented by layers 2M-1(a1) and 2M-1(a2) are performed, the convolution operation of layer 2M+1 corresponding to the first tensor a1 and the second tensor a2 is performed (in... Figure 6The operations are represented by layer 2M+1(a1) and layer 2M+1(a2).
[0122] However, the operation method for partial tensors is not limited to this. The operation method for partial tensors can also be as follows: after performing operations on a portion of the partial tensors in multiple layers, operations on the remaining partial tensors are performed (Method 2). For example, in the convolution operation circuit 4, after performing convolution operations on layer 2M-1 corresponding to the first partial tensor a1 and layer 2M+1 corresponding to the first partial tensor a1, convolution operations on layer 2M-1 corresponding to the second partial tensor a2 and layer 2M+1 corresponding to the second partial tensor a2 can be performed.
[0123] Alternatively, the operation method for partial tensors can be a combination of method 1 and method 2. However, when using method 2, the operation needs to be performed according to the dependency relationship related to the order of operations on the partial tensors.
[0124] The following section provides a detailed explanation of each structure of the NN circuit 100.
[0125] [DMAC 3]
[0126] Figure 7 This is an internal block diagram of DMAC 3.
[0127] The DMAC 3 has a data forwarding circuit 31 and a status controller 32. The DMAC 3 has a dedicated status controller 32 for the data forwarding circuit 31, which can perform DMA data forwarding without an external controller when a command instruction is input.
[0128] The data forwarding circuit 31 is connected to the external bus EB and performs DMA data forwarding between external memory such as DRAM and the first memory 1. Additionally, the data forwarding circuit 31 performs DMA data forwarding between external memory such as DRAM and the second memory 2. Furthermore, the data forwarding circuit 31 performs data forwarding between external memory such as DRAM and the convolution operation circuit 4. Additionally, the data forwarding circuit 31 performs data forwarding between external memory such as DRAM and the quantization operation circuit 5. The number of DMA channels in the data forwarding circuit 31 is not limited. For example, dedicated DMA channels can be provided for both the first memory 1 and the second memory 2.
[0129] The state controller 32 controls the state of the data forwarding circuit 31. Additionally, the state controller 32 is connected to the controller 6 via the internal bus IB. The state controller 32 has a command queue 33 and a control circuit 34.
[0130] Command queue 33 is a queue that stores command instructions C3 used by DMAC 3, and may be constructed, for example, by a FIFO memory. One or more command instructions C3 are written to command queue 33 via internal bus IB.
[0131] The control circuit 34 is a state machine that decodes command instruction C3 and sequentially controls the data forwarding circuit 31 based on command instruction C3. The control circuit 34 can be implemented using logic circuits or by a software-controlled CPU.
[0132] Figure 8 This is a state transition diagram for control circuit 34.
[0133] When command instruction C3 is input to command queue 33 (Not empty), control circuit 34 transitions from idle state ST1 to decoding state ST2.
[0134] In decoding state ST2, control circuit 34 decodes the command instruction C3 output from command queue 33. Additionally, control circuit 34 reads the semaphore S stored in register 61 of controller 6 to determine whether the operation of data forwarding circuit 31 as indicated in command instruction C3 can be executed. If execution is not possible (Not ready), control circuit 34 waits until execution is possible. If execution is possible (ready), control circuit 34 transitions from decoding state ST2 to execution state ST3.
[0135] In execution state ST3, control circuit 34 controls data forwarding circuit 31, causing data forwarding circuit 31 to perform the work indicated in command instruction C3. When the work of data forwarding circuit 31 is finished, control circuit 34 removes the executed command instruction C3 from command queue 33 and updates the semaphore S stored in register 61 of controller 6. If there is a command in command queue 33 (Not empty), control circuit 34 transitions from execution state ST3 to decoding state ST2. If there is no command in command queue 33 (empty), control circuit 34 transitions from execution state ST3 to idle state ST1.
[0136] [Convolution Operation Circuit 4]
[0137] Figure 9 This is the internal block diagram of the convolution operation circuit 4.
[0138] The convolution operation circuit 4 has a weight memory 41, a multiplier 42, an accumulator circuit 43, and a state controller 44. The convolution operation circuit 4 has a dedicated state controller 44 for the multiplier 42 and the accumulator circuit 43, which can perform convolution operations without an external controller when a command instruction is input.
[0139] Weight memory 41 is a memory that stores the weights w used in the convolution operation, such as a rewritable memory like volatile memory composed of SRAM (Static RAM). DMAC 3 uses DMA forwarding to write the weights w required for the convolution operation into weight memory 41.
[0140] Figure 10 This is an internal block diagram of the multiplication unit 42.
[0141] Multiplier 42 multiplies the input vector A with the weight matrix W. As described above, the input vector A is a vector data having Bc elements obtained by expanding the segmented input data a(x+i, y+j, co) for each i and j. The weight matrix W is a matrix data having Bc×Bd elements obtained by expanding the segmented weights w(i, j, co, do) for each i and j. Multiplier 42 has Bc×Bd product sum operation units 47, enabling parallel multiplication of the input vector A with the weight matrix W.
[0142] The multiplier 42 reads the input vector A and weight matrix W required for the multiplication operation from the first memory 1 and the weight memory 41, and performs the multiplication operation. The multiplier 42 outputs Bd product sums O(di).
[0143] Figure 11 This is an internal block diagram of the product summation unit 47.
[0144] The product summation unit 47 performs a multiplication operation on the elements A(ci) of the input vector A and the elements W(ci, di) of the weight matrix W. Additionally, the product summation unit 47 adds the result of the multiplication operation to the multiplication results S(ci, di) of other product summation units 47. The product summation unit 47 outputs the addition result S(ci+1, di). Element A(ci) is a 2-bit unsigned integer (0, 1, 2, 3). Element W(ci, di) is a 1-bit signed integer (0, 1), where a value "0" represents +1 and a value "1" represents -1.
[0145] The product summation unit 47 has an inverter 47a, a selector 47b, and an adder 47c. The product summation unit 47 does not use a multiplier; it only uses the inverter 47a and the selector 47b to perform multiplication. When element W(ci, di) is "0", the selector 47b selects the input of element A(ci). When element W(ci, di) is "1", the selector 47b selects the complement obtained by inverting element A(ci) using the inverter. Element W(ci, di) is also input to the carry-in of the adder 47c. When element W(ci, di) is "0", the adder 47c outputs the value obtained by adding element A(ci) to S(ci, di). When W(ci, di) is "1", the adder 47c outputs the value obtained by subtracting element A(ci) from S(ci, di).
[0146] Figure 12 This is the internal block diagram of accumulator circuit 43.
[0147] The accumulator circuit 43 accumulates the product sum result O(di) of the multiplication unit 42 in the second memory 2. The accumulator circuit 43 has Bd accumulator units 48, which can accumulate Bd product sum results O(di) in parallel in the second memory 2.
[0148] Figure 13 This is an internal block diagram of accumulator unit 48.
[0149] The accumulator unit 48 has an adder 48a and a shield 48b. The adder 48a adds element O(di) of the product sum result O to the intermediate process of the convolution operation shown in Equation 1 stored in the second memory 2, i.e., the partial sum. As the result of the addition operation, each element is 16 bits. The result of the addition operation is not limited to 16 bits per element, but can also be, for example, 15 bits or 17 bits per element.
[0150] The adder 48a writes the addition result to the same address in the second memory 2. When the initialization signal clear is asserted, the shield 48b shields the output from the second memory 2, setting the addition operand for element O (di) to zero. The initialization signal clear is asserted when the second memory 2 does not store the partial sum of the intermediate process.
[0151] When the convolution operation performed by the multiplier 42 and the accumulator circuit 43 is completed, the output data f(x, y, do) is stored in the second memory.
[0152] The state controller 44 controls the state of the multiplier 42 and the accumulator circuit 43. Additionally, the state controller 44 is connected to the controller 6 via the internal bus IB. The state controller 44 has a command queue 45 and a control circuit 46.
[0153] Command queue 45 is a queue for storing command instructions C4 used by convolution operation circuit 4, and may be constructed, for example, by a FIFO memory. Command instructions C4 are written into command queue 45 via internal bus IB.
[0154] Control circuit 46 is a state machine that decodes command instruction C4 and controls multiplier circuit 42 and accumulator circuit 43 based on command instruction C4. Control circuit 46 has the same structure as control circuit 34 of state controller 32 of DMAC 3.
[0155] [Quantization Circuit 5]
[0156] Figure 14 This is an internal block diagram of the quantization operation circuit 5.
[0157] The quantization circuit 5 includes a quantization parameter memory 51, a vector operation circuit 52, a quantization circuit 53, and a state controller 54. The quantization circuit 5 has a dedicated state controller 54 for the vector operation circuit 52 and the quantization circuit 53, which can perform quantization operations without an external controller when input with a command instruction.
[0158] The quantization parameter memory 51 is a memory that stores the quantization parameters q used in the quantization operation. For example, it can be a rewritable memory such as a volatile memory composed of SRAM (Static RAM). DMAC 3 uses DMA forwarding to write the quantization parameters q required for the quantization operation into the quantization parameter memory 51.
[0159] Figure 15 This is an internal block diagram of vector operation circuit 52 and quantization circuit 53.
[0160] The vector operation circuit 52 performs operations on the output data f(x, y, do) stored in the second memory 2. The vector operation circuit 52 has Bd operation units 57, which perform SIMD operations on the output data f(x, y, do) in parallel.
[0161] Figure 16 This is a block diagram of the arithmetic unit 57.
[0162] The arithmetic unit 57 may include, for example, an ALU 57a, a first selector 57b, a second selector 57c, a register 57d, and a shifter 57e. The arithmetic unit 57 may also include other arithmetic units found in well-known general-purpose SIMD arithmetic circuits.
[0163] The vector operation circuit 52 performs at least one of the operations of the pooling layer 221, the batch normalization layer 222, and the activation function layer 223 in the quantization operation layer 220 on the output data f(x, y, do) through the arithmetic unit of the combined operation unit 57.
[0164] The arithmetic unit 57 can add the data stored in register 57d to the element f(di) of the output data f(x, y, do) read from the second memory 2 using ALU 57a. The arithmetic unit 57 can store the addition result of ALU 57a in register 57d. The arithmetic unit 57 can initialize the addition result by inputting "0" to ALU 57a instead of the data stored in register 57d according to the selection of the first selector 57b. For example, when the pooling region is 2×2, the shifter 57e can output the average value of the addition result by right-shifting the output of ALU 57a by 2 bits. The vector arithmetic circuit 52 can implement the average pooling operation shown in Equation 2 by repeatedly performing the above operations performed by Bd arithmetic units 57.
[0165] The arithmetic unit 57 can use ALU 57a to compare the data stored in register 57d with the element f(di) of the output data f(x, y, do) read from the second memory 2.
[0166] The arithmetic unit 57 can control the second selector 57c based on the comparison result of ALU 57a to select the larger of the data stored in register 57d and element f(di). The arithmetic unit 57 initializes the comparison object to the minimum value by inputting the minimum possible value of element f(di) to ALU 57a according to the selection of the first selector 57b. In this embodiment, element f(di) is a 16-bit signed integer, therefore the minimum possible value of element f(di) is "0x8000". The vector arithmetic circuit 52 can implement the MAX pooling operation of Equation 3 by repeatedly performing the above operations performed by Bd arithmetic units 57. Furthermore, in the MAX pooling operation, the shifter 57e does not shift the output of the second selector 57c.
[0167] The arithmetic unit 57 can use the ALU 57a to perform a subtraction operation on the data stored in the register 57d and the element f(di) of the output data f(x, y, do) read from the second memory 2. The shifter 57e can shift the output of the ALU 57a to the left (i.e., multiplication) or to the right (i.e., division). The vector arithmetic circuit 52 can implement the batch normalization operation of Equation 4 by repeatedly performing the above operations performed by Bd arithmetic units 57.
[0168] The arithmetic unit 57 can use the ALU 57a to compare the element f(di) of the output data f(x, y, do) read from the second memory 2 with the "0" selected by the first selector 57b. Based on the comparison result of the ALU 57a, the arithmetic unit 57 can select and output any value between the element f(di) and the constant value "0" pre-stored in the register 57d. The vector arithmetic circuit 52 can implement the ReLU operation of Equation 5 by repeatedly performing the above operations performed by Bd arithmetic units 57.
[0169] The vector operation circuit 52 can perform average pooling, max pooling, batch normalization, activation function operations, and combinations of these operations. Since the vector operation circuit 52 can perform general SIMD operations, it can also perform other operations required for the operations in the quantization layer 220. Furthermore, the vector operation circuit 52 can also perform operations other than those in the quantization layer 220.
[0170] Furthermore, the quantization circuit 5 may not have a vector operation circuit 52. When the quantization circuit 5 does not have a vector operation circuit 52, the output data f(x, y, do) is input to the quantization circuit 53.
[0171] Quantization circuit 53 quantizes the output data of vector operation circuit 52. For example... Figure 15 As shown, the quantization circuit 53 has Bd quantization units 58, which perform parallel calculations on the output data of the vector operation circuit 52.
[0172] Figure 17 This is an internal block diagram of quantization unit 58.
[0173] The quantization unit 58 quantizes the elements in(di) of the output data of the vector operation circuit 52. The quantization unit 58 has a comparator 58a and an encoder 58b. The quantization unit 58 performs the quantization layer 224 operation (Equation 6) in the quantization operation layer 220 on the output data (16 bits / element) of the vector operation circuit 52. The quantization unit 58 reads the required quantization parameters q(th0, th1, th2) from the quantization parameter memory 51 and compares the input in(di) with the quantization parameters q using the comparator 58a. The quantization unit 58 uses the encoder 58b to quantize the comparison result of the comparator 58a into 2 bits / element. Since α(c) and β(c) in Equation 4 are parameters that are different for each variable c, the quantization parameters q(th0, th1, th2) reflecting α(c) and β(c) are parameters that are different for each in(di).
[0174] The quantization unit 58 compares the input in(di) with three thresholds th0, th1, and th2, thereby classifying the input in(di) into four regions (e.g., in≤th0, th0<in≤th1, th1<in≤th2, th2<in), encoding the classification result into 2 bits and outputting it. By setting the quantization parameters q(th0, th1, th2), the quantization unit 58 can also perform batch normalization, activation function calculation, and quantization simultaneously.
[0175] The quantization unit 58 performs quantization by setting a threshold th0 as β(c) in Equation 4 and setting the threshold differences (th1-th0) and (th2-th1) as α(c) in Equation 4, thereby enabling the batch normalization operation shown in Equation 4 to be performed simultaneously with quantization. α(c) can be decreased by increasing (th1-th0) and (th2-th1). α(c) can be increased by decreasing (th1-th0) and (th2-th1).
[0176] The quantization unit 58 can perform the ReLU operation of the activation function and the quantization of the input in(di) simultaneously. For example, the quantization unit 58 saturates the output value in the region where in(di) ≤ th0 and th2 < in(di). The quantization unit 58 can perform the activation function operation and quantization simultaneously by setting the quantization parameter q in a way that makes the output nonlinear.
[0177] The state controller 54 controls the state of the vector operation circuit 52 and the quantization circuit 53. Additionally, the state controller 54 is connected to the controller 6 via the internal bus IB. The state controller 54 includes a command queue 55 and a control circuit 56.
[0178] Command queue 55 is a queue for storing command instructions C5 used by the quantization circuit 5, and may be constructed, for example, by a FIFO memory. Command instructions C5 are written into command queue 55 via the internal bus IB.
[0179] Control circuit 56 is a state machine that decodes command instruction C5 and controls vector operation circuit 52 and quantization circuit 53 based on command instruction C5. Control circuit 56 has the same structure as control circuit 34 of state controller 32 of DMAC 3.
[0180] The quantization circuit 5 writes the quantization output data with Bd elements into the first memory 1. Furthermore, Equation 10 shows a preferred relationship between Bd and Bc. In Equation 10, n is an integer.
[0181] [Mathematical Expression 10]
[0182] Bd=2 n ·Bc......Formula (10)
[0183] [Controller 6]
[0184] The controller 6 forwards commands from the external host CPU to the command queues of the DMAC 3, convolution operation circuit 4, and quantization operation circuit 5. The controller 6 may have a command memory that stores the command instructions for each circuit.
[0185] Controller 6 is connected to the external bus EB and operates as a slave device of the external host CPU. Controller 6 has a register 61 that includes a parameter register and a status register. The parameter register controls the operation of the NN circuit 100. The status register includes a semaphore S that indicates the status of the NN circuit 100.
[0186] [Semaphore S]
[0187] Figure 18 A diagram illustrating the control of the NN circuit 100 based on the semaphore S.
[0188] Semaphore S has a first semaphore S1, a second semaphore S2, and a third semaphore S3. Semaphore S is decremented by the P operation and incremented by the V operation. The P and V operations performed by DMAC 3, convolution operation circuit 4, and quantization operation circuit 5 update the semaphore S of controller 6 via the internal bus IB.
[0189] The first semaphore S1 is used to control the first data stream F1. The first data stream F1 is a data stream in which the DMAC 3 (Producer) writes input data a to the first memory 1 and the convolution operation circuit 4 (Consumer) reads input data a. The first semaphore S1 has a first write semaphore S1W and a first read semaphore S1R.
[0190] The second semaphore S2 is used to control the second data stream F2. The second data stream F2 is a data stream in which the convolution operation circuit 4 (producer) writes the output data f to the second memory 2, and the quantization operation circuit 5 (consumer) reads the output data f. The second semaphore S2 has a second write semaphore S2W and a second read semaphore S2R.
[0191] The third semaphore S3 is used to control the third data stream F3. The third data stream F3 is a data stream in which the quantization operation circuit 5 (producer) writes the quantization operation output data to the first memory 1, and the convolution operation circuit 4 (consumer) reads the quantization operation output data of the quantization operation circuit 5. The third semaphore S3 has a third write semaphore S3W and a third read semaphore S3R.
[0192] [First Data Stream F1]
[0193] Figure 19 This is the timing diagram for the first data stream F1.
[0194] The first write semaphore S1W is a semaphore that restricts the writing of data from DMAC 3 to the first memory 1 in the first data stream F1. The first write semaphore S1W represents the number of memory regions in the first memory 1 capable of storing data of a predetermined size, such as input vector A, which can be read and then written to with other data. When the first write semaphore S1W is "0", DMAC 3 cannot write to the first memory 1 in the first data stream F1, and must wait until the first write semaphore S1W becomes "1" or higher.
[0195] The first read signal S1R is a signal that limits the readings made by the convolution operation circuit 4 from the first memory 1 in the first data stream F1. The first read signal S1R represents the number of memory regions in the first memory 1 that can store data of a predetermined size, such as the input vector A, and that can be read after the data has been written. When the first read signal S1R is "0", the convolution operation circuit 4 cannot read from the first data stream F1 from the first memory 1, and must wait until the first read signal S1R becomes "1" or higher.
[0196] Command C3 is stored in command queue 33, thus DMAC 3 begins DMA forwarding. For example... Figure 19 As shown, since the first write semaphore S1W is not "0", DMAC 3 starts DMA forwarding (DMA forwarding 1). When starting DMA forwarding, DMAC 3 performs a P operation on the first write semaphore S1W. After DMA forwarding is completed, DMAC 3 performs a V operation on the first read semaphore S1R.
[0197] Command instruction C4 is stored in command queue 45, thereby initiating convolution operation circuit 4. For example... Figure 19 As shown, since the first read semaphore S1R is "0", the convolution operation circuit 4 waits until the first read semaphore S1R becomes "1" or higher (waiting in decoding state ST2). When the first read semaphore S1R becomes "1" due to the V operation of DMAC 3, the convolution operation circuit 4 starts the convolution operation (convolution operation 1). When starting the convolution operation, the convolution operation circuit 4 performs a P operation on the first read semaphore S1R. After the convolution operation is completed, the convolution operation circuit 4 performs a V operation on the first write semaphore S1W.
[0198] Starting with DMAC 3 Figure 19When DMA forwarding is recorded as "DMA forwarding 3", the first write semaphore S1W is "0", so DMAC 3 waits until the first write semaphore S1W becomes "1" or higher (waiting in decoding state ST2). When the first write semaphore S1W becomes "1" or higher due to the V operation of the convolution operation circuit 4, DMAC 3 starts DMA forwarding.
[0199] By using semaphore S1, DMAC 3 and convolution operation circuit 4 can prevent access conflicts to the first memory 1 in the first data stream F1. Furthermore, by using semaphore S1, DMAC 3 and convolution operation circuit 4 can operate independently and in parallel while synchronizing data forwarding in the first data stream F1.
[0200] [Second data stream F2]
[0201] Figure 20 This is the timing diagram for the second data stream F2.
[0202] The second write semaphore S2W is a semaphore that restricts the writing of data from the convolution operation circuit 4 to the second memory 2 in the second data stream F2. The second write semaphore S2W represents the number of memory regions in the second memory 2 capable of storing data of a predetermined size, such as output data f, which can be read and then used to write other data. When the second write semaphore S2W is "0", the convolution operation circuit 4 cannot write data to the second memory 2 in the second data stream F2, and must wait until the second write semaphore S2W becomes "1" or higher.
[0203] The second read signal S2R is a signal that restricts the reading of data from the second memory 2 by the quantization circuit 5 in the second data stream F2. The second read signal S2R represents the number of memory regions in the second memory 2 that can store data of a predetermined size, such as output data f, and that can be read after the data has been written. When the second read signal S2R is "0", the quantization circuit 5 cannot read data from the second memory 2 in the second data stream F2, and must wait until the second read signal S2R becomes "1" or higher.
[0204] like Figure 20 As shown, when the convolution operation circuit 4 starts the convolution operation, it performs a P operation on the second write semaphore S2W. After the convolution operation is completed, the convolution operation circuit 4 performs a V operation on the second read semaphore S2R.
[0205] Command instruction C5 is stored in command queue 55, thereby initiating quantization operation by quantization circuit 5. For example... Figure 20As shown, since the second read semaphore S2R is "0", the quantization circuit 5 waits until the second read semaphore S2R becomes "1" or higher (waiting in decoding state ST2). When the second read semaphore S2R becomes "1" due to the V operation of the convolution circuit 4, the quantization circuit 5 begins quantization (quantization operation 1). When starting quantization, the quantization circuit 5 performs a P operation on the second read semaphore S2R. After quantization is complete, the quantization circuit 5 performs a V operation on the second write semaphore S2W.
[0206] Starting from quantization circuit 5 Figure 20 During the quantization operation recorded as "quantization operation 2", the second read signal S2R is "0", so the quantization operation circuit 5 waits until the second read signal S2R becomes "1" or higher (waiting under decoding state ST2). When the second read signal S2R becomes "1" or higher due to the V operation of the convolution operation circuit 4, the quantization operation circuit 5 starts the quantization operation.
[0207] By using semaphore S2, convolution circuit 4 and quantization circuit 5 can prevent access conflicts to the second memory 2 in the second data stream F2. Furthermore, by using semaphore S2, convolution circuit 4 and quantization circuit 5 can operate independently and in parallel while synchronizing data forwarding in the second data stream F2.
[0208] [Third Data Stream F3]
[0209] The third write semaphore S3W is a semaphore that restricts the writing of data from the quantization circuit 5 to the first memory 1 in the third data stream F3. The third write semaphore S3W represents the number of memory regions in the first memory 1 that can store data of a predetermined size, such as the quantization output data of the quantization circuit 5, and that can be used to write other data after the data has been read. When the third write semaphore S3W is "0", the quantization circuit 5 cannot write to the first memory 1 in the third data stream F3, and must wait until the third write semaphore S3W becomes "1" or higher.
[0210] The third read signal S3R is a signal that restricts the reading of data from the first memory 1 by the convolution operation circuit 4 in the third data stream F3. The third read signal S3R represents the number of memory regions in the first memory 1 that can store data of a predetermined size, such as the quantization output data of the quantization operation circuit 5, and which can be read after the data has been written. When the third read signal S3R is "0", the convolution operation circuit 4 cannot read data from the first memory 1 in the third data stream F3, and must wait until the third read signal S3R becomes "1" or higher.
[0211] By using semaphore S3, quantization circuit 5 and convolution circuit 4 can prevent access conflicts to the first memory 1 in the third data stream F3. Furthermore, by using semaphore S3, quantization circuit 5 and convolution circuit 4 can operate independently and in parallel while synchronizing data forwarding in the third data stream F3.
[0212] The first memory 1 is shared in the first data stream F1 and the third data stream F3. The NN circuit 100 can distinguish between the first data stream F1 and the third data stream F3 and synchronize data forwarding by separately setting the first semaphore S1 and the third semaphore S3.
[0213] [Operation of Convolution Circuit 4 (1)]
[0214] When performing convolution operations, the convolution operation circuit 4 reads from the first memory 1 and writes to the second memory 2. That is, the convolution operation circuit 4 acts as a consumer in the first data stream F1 and a producer in the second data stream F2. Therefore, when starting the convolution operation, the convolution operation circuit 4 performs a P operation on the first read semaphore S1R (refer to...). Figure 19 ), perform a P operation on the second write semaphore S2W (refer to Figure 20 After the convolution operation is completed, the convolution operation circuit 4 performs a V operation on the first write semaphore S1W (refer to...). Figure 19 ), perform a V operation on the second read semaphore S2R (refer to Figure 20 ).
[0215] When the convolution operation circuit 4 starts the convolution operation, it waits until the first read semaphore S1R becomes "1" or higher and the second write semaphore S2W becomes "1" or higher (waiting in the decoding state ST2).
[0216] [Operation of Quantization Circuit 5]
[0217] During quantization, the quantization circuit 5 reads from the second memory 2 and writes to the first memory 1. That is, the quantization circuit 5 acts as a consumer in the second data stream F2 and a producer in the third data stream F3. Therefore, at the start of quantization, the quantization circuit 5 performs a P operation on the second read semaphore S2R and a P operation on the third write semaphore S3W. After quantization, the quantization circuit 5 performs a V operation on the second write semaphore S2W and a V operation on the third read semaphore S3R.
[0218] When the quantization operation circuit 5 starts the quantization operation, it waits until the second read signal S2R becomes "1" or higher and the third write signal S3W becomes "1" or higher (waiting in the decoding state ST2).
[0219] [Operation of Convolution Circuit 4 (2)]
[0220] The input data read by the convolution operation circuit 4 from the first memory 1 is sometimes also the data written by the quantization operation circuit 5 in the third data stream. In this case, the convolution operation circuit 4 acts as a consumer in the third data stream F3 and a producer in the second data stream F2. Therefore, when starting the convolution operation, the convolution operation circuit 4 performs a P operation on the third read semaphore S3R and a P operation on the second write semaphore S2W. After the convolution operation is completed, the convolution operation circuit 4 performs a V operation on the third write semaphore S3W and a V operation on the second read semaphore S2R.
[0221] When the convolution operation circuit 4 starts the convolution operation, it waits until the third read signal S3R becomes "1" or higher and the second write signal S2W becomes "1" or higher (waiting in the decoding state ST2).
[0222] [Command to perform convolution operation]
[0223] Figure 21 A diagram illustrating the commands executed during convolution operations.
[0224] The convolution operation execution command is one of the command instructions C4 for the convolution operation circuit 4. The convolution operation execution command has a command field IF that stores the command for the convolution operation circuit 4 and a semaphore operation field SF that stores operations such as those for the semaphore S. The command field IF and the semaphore operation field SF are stored together as a single command for the convolution operation execution command.
[0225] The command field IF, which executes the convolution operation command, is a field that stores commands for the convolution operation circuit 4. For example, the command field IF stores instructions to perform convolution operations on the multiplier 42 and the accumulator circuit 43, control instructions for the clear signal of the accumulator circuit 43, the size of the input vector A and the weight matrix W, and the memory address, etc.
[0226] The semaphore operation field SF, which executes the convolution operation command, stores operations on the semaphore S associated with the command stored in the command field IF. The convolution operation circuit 4 acts as a consumer receiving and consuming data from the other party in the first data stream F1 and the third data stream F3, and as a producer sending produced data to the other party in the second data stream F2. Therefore, the associated semaphore S is the first semaphore S1, the second semaphore S2, and the third semaphore S3. Thus, as... Figure 21 As shown, the semaphore operation field SF of the convolution operation execution command contains operation fields for the first semaphore S1, the second semaphore S2, and the third semaphore S3.
[0227] In the semaphore operation field SF, P operation field and V operation field are set for each semaphore. For example Figure 21 As shown, the semaphore operation field SF of the convolution operation execution command contains 6 operation fields. Each operation field of the semaphore operation field SF is 1 bit. Each operation field of the semaphore operation field SF can be multiple bits.
[0228] For the first data stream F1 and the third data stream F3 of the convolution operation circuit 4 as consumers, the first semaphore S1 and the third semaphore S3 are provided with a P operation field for the read semaphore (S1R, S3R) and a V operation field for the write semaphore (S1W, S3W).
[0229] For the second semaphore S2 of the second data stream F2 produced by the convolution operation circuit 4, a P operation field for the write semaphore (S2W) and a V operation field for the read semaphore (S2R) are provided.
[0230] Figure 22 A diagram illustrating a specific example of the convolution operation command.
[0231] Figure 22 The specific example shown consists of four convolution operation commands (hereinafter referred to as "command 1" to "command 4"). The four convolution operation commands divide the input data a(x+i, y+j, co) stored in the first memory 1 into four parts to enable the convolution operation circuit 4 to perform convolution operation.
[0232] The state controller 44 of the convolution operation circuit 4 transitions to the decoding state ST2, and decodes the first saved command 1 among the four commands (command 1 to command 4) stored in the command queue 45.
[0233] When the P operation field is set to "1", the state controller 44 reads the semaphore S corresponding to the P operation field set to "1" from the controller 6 via the internal bus IB, and determines whether the implementation condition is met. The implementation condition means that all semaphores S corresponding to the P operation field set to "1" are "1" or higher. In command 1, the P operation field for the first read semaphore S1R and the P operation field for the second write semaphore S2W are set to "1". Therefore, the state controller 44 reads the first read semaphore S1R and the second write semaphore S2W to determine whether the implementation condition is met.
[0234] When the P operation field is set to "1", the state controller 44 waits until the semaphore S corresponding to the P operation field set to "1" is updated to meet the implementation conditions. In the case of command 1, if neither the first read semaphore S1R is "1" or higher and the second write semaphore S2W is "1" or higher (Not Ready), the state controller 44 waits until the semaphore S is updated to meet the implementation conditions (Wait).
[0235] When the P operation field is set to "1", if the implementation conditions are met, the state controller 44 transitions to the execution state ST3 and performs a convolution operation based on the command field IF. In the case of command 1, if the first read semaphore S1R is "1" or higher and the second write semaphore S2W is "1" or higher (Ready), the state controller 44 transitions to the execution state ST3 and performs a convolution operation based on the command field IF.
[0236] When the P operation field is set to "1", the state controller 44 performs a P operation on the semaphore S corresponding to the P operation field set to "1" before performing the convolution operation. In the case of command 1, the state controller 44 performs a P operation on the first read semaphore S1R and the second write semaphore S2W before performing the convolution operation.
[0237] After executing command 1, state controller 44 transitions to decoding state ST2 to decode command 2. In command 2, all semaphore operation fields SF are not set to "1". Therefore, state controller 44 does not acknowledge or update semaphore S but transitions to execution state ST3 to perform convolution operation based on command field IF.
[0238] After executing command 2, state controller 44 transitions to decoding state ST2 to decode command 3. In command 3, all semaphore operation fields SF are not set to "1". Therefore, state controller 44 does not acknowledge or update semaphore S but transitions to execution state ST3 to perform convolution operation based on command field IF.
[0239] After executing command 3, state controller 44 transitions to decoding state ST2 to decode command 4. In command 4, none of the P operation fields are set to "1". Therefore, state controller 44 does not acknowledge or update semaphore S but transitions to execution state ST3 to perform convolution operation based on command field IF.
[0240] When the V operation field is set to "1", the state controller 44 performs a V operation on the semaphore S corresponding to the V operation field set to "1" after the convolution operation of command 4 is completed. In command 4, the V operation field for the first write semaphore S1W and the V operation field for the second read semaphore S2R are set to "1". Therefore, after the convolution operation of command 4 is completed, the state controller 44 performs V operations on the first write semaphore S1W and the second read semaphore S2R.
[0241] After executing command 4, state controller 44 transitions to idle state ST1, ending the execution of a series of convolution operation commands consisting of 4 commands.
[0242] When the convolution operation circuit 4 uses the quantization operation output data written to the first memory 1 by the quantization operation circuit 5 as input data, the operation field corresponding to the third semaphore S3 is used.
[0243] The convolution operation is implemented by a command instruction based on the command field IF, and the associated semaphore S is acknowledged and updated based on the semaphore operation field SF. Since the command field IF and the semaphore operation field SF are stored as a single command for implementing the convolution operation, the number of command instructions C4 used to perform the convolution operation can be reduced. Furthermore, the processing time spent on executing commands such as decoding can be shortened.
[0244] [Quantization Execution Command]
[0245] Figure 23 A diagram illustrating the commands executed during quantization operations.
[0246] The quantization execution command is one of the command instructions C5 for the quantization circuit 5. The quantization execution command has a command field IF that stores the command for the quantization circuit 5 and a semaphore operation field SF that stores operations for the semaphore S, etc. The command field IF and the semaphore operation field SF are stored together as a single command for the quantization execution command.
[0247] The command field IF of the quantization operation execution command is a field that stores the command for the quantization operation circuit 5. For example, the command field IF stores the instructions for the vector operation circuit 52 and the quantization circuit 53 to perform the operation, the output data f, the size of the quantization parameter p, and the memory address.
[0248] The semaphore operation field SF of the quantization operation command stores operations on the semaphore S associated with the command stored in the command field IF. The quantization operation circuit 5 is a consumer in the second data stream F2 and a producer in the third data stream F3. Therefore, the associated semaphore S is the second semaphore S2 and the third semaphore S3. Thus, as... Figure 23As shown, the semaphore operation field SF of the quantization operation execution command includes operation fields for the second semaphore S2 and the third semaphore S3.
[0249] For the second semaphore S2 of the second data stream F2 for the quantization circuit 5 as a consumer, a P operation field for the read semaphore (S2R) and a V operation field for the write semaphore (S2W) are provided.
[0250] For the third semaphore S3 of the third data stream F3 produced by the quantization operation circuit 5, a P operation field for the write semaphore (S3W) and a V operation field for the read semaphore (S3R) are provided.
[0251] Similar to the operation of the state controller 44 in executing commands for convolution operations, the state controller 54 of the quantization operation circuit 5 confirms and updates the semaphore S when the P operation field and V operation field are set to "1" in the quantization operation execution command.
[0252] [DMA forwarding execution command]
[0253] Figure 24 A diagram illustrating the commands executed during DMA forwarding.
[0254] The DMA forwarding execution command is one of the C3 command instructions for DMAC 3. The DMA forwarding execution command has a command field IF that stores the command for DMAC 3 and a semaphore operation field SF that stores operations for semaphore S, etc. The command field IF and the semaphore operation field SF are stored together as a single command for the DMA forwarding execution command.
[0255] The command field IF of the DMA forwarding command is a field that stores the command for DMAC 3. The command field IF stores information such as the memory forwarding source, the memory address of the memory forwarding destination, and the size of the forwarded data.
[0256] The semaphore operation field SF, which executes the DMA forwarding command, stores operations related to the semaphore S associated with the command stored in the command field IF. DMAC 3 is the producer in the first data stream F1. Therefore, the associated semaphore S is the first semaphore S1. Thus, as... Figure 24 As shown, the semaphore operation field SF of the DMA forwarding execution command contains an operation field for the first semaphore S1.
[0257] For the first semaphore S1 of the first data stream F1 produced by DMAC 3, there are P operation fields for the write semaphore (S1W) and V operation fields for the read semaphore (S1R).
[0258] Similar to the operation of the state controller 44 in executing commands for convolution operations, the state controller 32 of the DMAC 3 executes commands for DMA forwarding when the P operation field and V operation field are set to "1", and performs acknowledgment and update of semaphore S.
[0259] The control method for the neural network circuit according to this embodiment enables the NN circuit 100, which can be embedded in embedded devices such as IoT devices, to operate with high performance. In the convolution operation execution command, quantization operation execution command, and DMA forwarding execution command, the command field IF and the semaphore operation field SF are stored in a single command. Therefore, the number of command instructions used to perform convolution operations, etc., can be reduced. Furthermore, the processing time spent executing commands such as decoding can be shortened.
[0260] The first embodiment of the present invention has been described in detail above with reference to the accompanying drawings. However, the specific structure is not limited to this embodiment and includes design changes that do not depart from the spirit of the present invention. Furthermore, the constituent elements shown in the above embodiments and variations can be appropriately combined to form a configuration.
[0261] (Variation Example 1)
[0262] In the above embodiment, an example of a command that stores multiple semaphore operation fields SF in a single command for a command field IF is shown, but the form of the command is not limited to this. The command can be in the form of storing multiple command fields IF and multiple semaphore operation fields SF associated with each command field IF in a single command. Furthermore, the method of storing the command field IF and the semaphore operation fields SF in a single command is not limited to the structure of the above embodiment. Moreover, the command field IF and the semaphore operation fields SF can be stored separately as multiple commands. If the command field IF is associated with the corresponding semaphore operation field SF in a single command, the same effect can be achieved.
[0263] (Variation Example 2)
[0264] In the above embodiments, the first memory 1 and the second memory 2 are separate memories, but the form of the first memory 1 and the second memory 2 is not limited to this. For example, the first memory 1 and the second memory 2 can be a first memory region and a second memory region in the same memory.
[0265] (Variation Example 3)
[0266] In the above embodiments, the semaphore S is set for the first data stream F1, the second data stream F2, and the third data stream F3, but the form of the semaphore S is not limited to this. For example, the semaphore S can be set for the DMAC 3 to write the weight w into the weight memory 41 and the multiplier 42 to read the weight w data stream. For example, the semaphore S can also be set for the DMAC 3 to write the quantization parameter q into the quantization parameter memory 51 and the quantization circuit 53 to read the quantization parameter q data stream.
[0267] (Variation Example 4)
[0268] For example, the data input to the NN circuit 100 described in the above embodiment is not limited to a single form, but can be composed of still images, video images, voice, text, numerical values, and combinations thereof. Furthermore, the data input to the NN circuit 100 is not limited to measurement results from physical quantity measuring devices such as light sensors, thermometers, Global Positioning System (GPS) measuring instruments, angular velocity measuring instruments, and anemometers mounted on edge devices equipped with the NN circuit 100. It can also be a combination of different information received from peripheral devices via wired or wireless communication, such as base station information, vehicle / ship information, weather information, traffic congestion-related information, financial information, and personal information.
[0269] (Variation Example 5)
[0270] Assuming the edge device equipped with NN circuit 100 is a battery-powered communication device such as a mobile phone, a smart device such as a personal computer, a digital camera, a gaming device, or a robotic product, but not limited to these. Even in products with high requirements for peak power supply limits, reduced product heat generation, or long-term operation, such as those using Power on Ethernet (PoE), effects not found in other existing examples can be achieved. For example, by applying it to vehicle-mounted cameras mounted on vehicles and ships, and surveillance cameras installed in public facilities and streets, not only can long-term recording be achieved, but it also contributes to lightweight design and increased durability. Furthermore, the same effects can be achieved by applying it to display devices such as televisions and monitors, medical cameras, medical equipment such as surgical robots, and operational robots used in manufacturing and construction sites.
[0271] (Variation Example 6)
[0272] In the neural network circuit 100, one or more processors can be used to implement part or all of the neural network circuit 100. For example, in the neural network circuit 100, part or all of the input layer or output layer can be implemented using software processing performed by the processor. Part of the input layer or output layer implemented using software processing may be, for example, data normalization or transformation. Accordingly, various forms of input or output can be accommodated. Furthermore, as software executed by the processor, it can be configured in a rewritable manner using communication units or external media.
[0273] (Variation Example 7)
[0274] As the NN circuit 100, a portion of the processing in CNN 200 can be implemented by combining graphics processing units (GPUs) in the cloud. As the NN circuit 100, by performing processing in the cloud in addition to processing on the edge device equipped with the NN circuit 100, or by performing processing on the edge device in addition to processing in the cloud, more complex processing can be achieved with fewer resources. Based on this structure, the NN circuit 100 can reduce the communication volume between the edge device and the cloud by distributing processing.
[0275] (Variation Example 8)
[0276] The operations performed by the NN circuit 100 are at least a portion of the learned CNN 200, but the objects of the operations performed by the NN circuit 100 are not limited to this. The operations performed by the NN circuit 100 can be, for example, at least a portion of the learned neural network that repeats two types of operations such as convolution and quantization.
[0277] Furthermore, the effects described in this specification are illustrative or exemplary only, and not limiting. That is to say, the technology disclosed herein can be used in conjunction with or in place of the above-described effects to achieve other effects that are obvious to those skilled in the art based on the description herein.
[0278] Industrial applicability
[0279] This invention can be applied to neural network operations.
Claims
1. A control method for a neural network circuit, wherein, This neural network circuit has the following features: The first memory unit stores the input data; A convolution operation circuit performs a convolution operation on the input data stored in the first memory; The second memory stores the convolution operation output data of the convolution operation circuit; A quantization circuit performs quantization operations on the convolution output data stored in the second memory; The second write semaphore restricts the writing to the second memory by the convolution operation circuit; The second read signal restricts the reading from the second memory by the quantization circuit; The third write semaphore restricts the writing to the first memory by the quantization operation circuit; as well as The third read signal restricts reads from the first memory by the convolution operation circuit. In the control method of the neural network circuit, when the third read semaphore represents a value that is not restricted from being read from the first memory and the second write semaphore represents a value that is not restricted from being written to the second memory, the convolution operation circuit is determined to be set to the condition that the convolution operation can be performed. Based on the determination of the implementation conditions, and after waiting until the convolution operation can be performed, the convolution operation circuit is made to perform the convolution operation.
2. The control method for the neural network circuit according to claim 1, wherein, The system has a convolution operation execution command, which issues a single command to the convolution operation circuit to determine the execution conditions of the convolution operation based on the third read signal and the second write signal, and to execute the convolution operation based on the determination.
3. The control method for the neural network circuit according to claim 2, wherein, The convolution operation execution command causes the convolution operation circuit to update the third read semaphore and the second write semaphore before performing the convolution operation.
4. The control method for the neural network circuit according to claim 2 or 3, wherein, The convolution operation execution command causes the convolution operation circuit to update the third write semaphore and the second read semaphore after performing the convolution operation.
5. The control method for the neural network circuit according to claim 1, wherein, When the second read semaphore indicates that the value read from the second memory is not restricted and the third write semaphore indicates that the value written to the first memory is not restricted, the quantization circuit determines that the conditions for performing the quantization operation are met. Based on the determination of the implementation conditions, and after waiting until the quantization operation can be performed, the quantization operation circuit is made to perform the quantization operation.
6. The control method for the neural network circuit according to claim 5, wherein, The system has a quantization operation execution command, which issues a single command to the quantization operation circuit to determine the execution conditions of the quantization operation based on the second read signal and the third write signal, and to execute the quantization operation based on the determination.
7. The control method for the neural network circuit according to claim 6, wherein, The quantization operation execution command causes the quantization operation circuit to update the second read semaphore and the third write semaphore before performing the quantization operation.
8. The control method for the neural network circuit according to claim 6 or 7, wherein, The quantization operation execution command causes the quantization operation circuit to update the second write semaphore and the third read semaphore after performing the quantization operation.
9. The control method for the neural network circuit according to claim 1, wherein, The neural network circuit also features: The DMA controller forwards the input data to the first memory; A first write semaphore restricts writes to the first memory by the DMA controller; as well as The first read semaphore restricts the reading from the first memory by the convolution operation circuit. In the control method of the neural network circuit, when the first read semaphore represents a value that is not restricted from being read from the first memory and the second write semaphore represents a value that is not restricted from being written to the second memory, the convolution operation circuit is determined to be set to the condition that the convolution operation can be performed. Based on the determination of the implementation conditions, and after waiting until the convolution operation can be performed, the convolution operation circuit is made to perform the convolution operation.
10. The control method for the neural network circuit according to claim 9, wherein, The system has a convolution operation execution command, which issues a single command to the convolution operation circuit to determine the execution conditions of the convolution operation based on the first read semaphore and the second write semaphore, and to execute the convolution operation based on the determination.
11. The control method for the neural network circuit according to claim 10, wherein, The convolution operation execution command causes the convolution operation circuit to update the first read semaphore and the second write semaphore before performing the convolution operation.
12. The control method for the neural network circuit according to claim 10 or 11, wherein, The convolution operation execution command causes the convolution operation circuit to update the first write semaphore and the second read semaphore after performing the convolution operation.
Citation Information
Patent Citations
Information processing method, information processing device and program
JP2018077829A
DC cutoff device
JP2020071933A
Convolutional neural network arithmetic circuit
CN107704923A
Arithmetic device, arithmetic execution device, and arithmetic execution method
CN108364061A
