Batch Processing in Neural Network Processors

Through the batch processing and weight reuse technology of dedicated hardware circuits at the neural network layer level, the problem of inefficiency of traditional neural network systems in multi-input processing is solved, and efficient multi-layer neural network calculations and circuit throughput are maximized.

CN112465131BActive Publication Date: 2024-09-27GOOGLE LLC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011246313.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2015-09-03
Filing Date
2016-05-03
Publication Date
2024-09-27
Estimated Expiration
2036-05-03

AI Technical Summary

Technical Problem

When traditional neural network systems process multiple inputs, the serial calculation method leads to inefficiency, especially when weight inputs need to be frequently reused, which may lead to circuit stalls and poor throughput.

Method used

Using dedicated hardware circuits, through the matrix calculation unit and the vector calculation unit, multiple inputs are received for each neural network layer to form a batch process, the weight input is reused, the accumulated value is calculated and the output is generated, ensuring that the batch size of each layer is based on weight reuse value to maximize the number of weight reuses to improve efficiency.

Benefits of technology

Effectively perform multi-layer neural network calculations to maximize circuit throughput and avoid stalls, especially when weight inputs are reused different times to improve calculation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112465131B_ABST
    Figure CN112465131B_ABST
Patent Text Reader

Abstract

The present disclosure relates to batch processing in a neural network processor. Methods, systems and apparatus for generating a corresponding neural network output for each of a plurality of inputs, including a computer program encoded on a computer storage medium, the method comprising, for each of a neural network layer: receiving a plurality of inputs to be processed at the neural network layer; forming one or more batches of inputs from the plurality of inputs, each batch having a plurality of inputs up to a corresponding batch size of the neural network layer; selecting a plurality of the one or more batches of inputs for processing, wherein the count of the inputs of the plurality of the one or more batches is greater than or equal to the corresponding associated batch size of the subsequent layer in sequence; and processing a plurality of the one or more batches of inputs to generate a corresponding neural network layer output.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] Description of the case

[0002] This application is a divisional application of Chinese invention patent application No. 201680020154.4, filed on May 3, 2016. Technical Field

[0003] This specification relates to computing neural network inference in hardware. Background Art

[0004] A neural network is a machine learning model that uses one or more layers of neurons to generate an output, such as a classification, for a received input. In addition to the output layer, some neural networks also include one or more hidden layers. The output of each hidden layer is used as the input to the next layer in the network, which is the next hidden layer or output layer in the network. Each layer of the network generates an output from the received input based on the current values ​​of the corresponding set of parameters.

[0005] Traditionally, some neural network systems compute inferences serially. That is, when computing inferences for multiple inputs, the neural network system can process each input through each layer of the neural network to generate an output for the input before processing the next input. Summary of the invention

[0006] In general, this specification describes a dedicated hardware circuit for computing neural network inferences.

[0007] In general, one innovative aspect of the subject matter described in this specification can be embodied in a method, the method comprising an act of generating a respective neural network output for each of a plurality of inputs, wherein the generating comprises processing each input via each of a plurality of neural network layers to generate a respective neural network output for the input, wherein the neural network layers are arranged in a sequence and wherein each neural network layer has a respective batch size, the method comprising, for each neural network layer: receiving a plurality of inputs to be processed at the neural network layer; forming one or more batches of inputs from the plurality of inputs, each batch having a number of inputs up to a respective batch size for the neural network layer; selecting a number of the one or more batches of inputs for processing, wherein a count of inputs in the number of the one or more batches is greater than or equal to a respective associated batch size of a subsequent layer in the sequence; and processing the one or more batches of inputs to generate a respective neural network layer output.

[0008] Implementations may include one or more of the following features. The respective batch sizes are based at least on a weight reuse value, the weight reuse value representing the number of times a weight input needs to be reused within an output value calculation time using the weight input in a matrix computation unit that is longer than a load time of the weight input from a memory. The weight reuse value is based at least on a clock rate of a memory storing the weight input. Each batch size is based at least on the weight reuse value divided by the number of times the weight input is reused for the respective layer. The plurality of neural network layers are processed in a matrix processing unit, wherein processing a number of one or more batches of inputs includes calculating an accumulated value for each input using the matrix computation unit. The weight reuse value is based on the number of arithmetic operation units within the matrix computation unit. Each input corresponds to a different image resource. Batches are formed from one or more layer outputs for processing in subsequent layers. Corresponding inferences are generated for each output.

[0009] Certain embodiments of the subject matter described in this specification can be implemented to achieve one or more of the following advantages. Special-purpose hardware circuits can efficiently perform computations for a neural network having multiple layers by reusing weight inputs of a given layer for multiple independent inputs. In particular, the weight inputs are reused multiple times so that the computation time for reusing the weight inputs multiple times is greater than the ingestion time for accessing new weight inputs from memory, thereby maximizing throughput in the circuit and avoiding stalling of the circuit. The circuit can efficiently perform computations even when the weight inputs are reused a different number of times in each layer.

[0010] The details of one or more embodiments of the subject matter of this specification are set forth in the accompanying drawings and the description below. Other features, aspects, and advantages of the subject matter will be apparent from the description, drawings, and claims. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] Figure 1 is a flow chart of an example method for performing computations for a given layer of a neural network.

[0012] Figure 2 An example neural network processing system is shown.

[0013] Figure 3 An example architecture including a matrix computation unit is shown.

[0014] Figure 4 An example architecture of a cell including a systolic matrix is ​​shown.

[0015] Figure 5 is a flow chart of an example method for performing neural network computations for multiple layers.

[0016] Figure 6 An example neural network with multiple layers is shown, along with the batch size for each layer.

[0017] Like reference numbers and designations in the various drawings represent like elements. DETAILED DESCRIPTION

[0018] A neural network having multiple layers can be used to compute inferences. For example, given an input, the neural network can compute an inference for the input. The neural network computes the inference by processing the input through each layer of the neural network. In particular, the layers of the neural network can be arranged in a sequence, each with a corresponding set of weights. Each layer receives an input and processes the input according to the layer's set of weights to generate an output. The output can be used as an input at the next neural network layer.

[0019] Thus, to compute inferences from received computations, a neural network receives inputs and processes them in sequence through each neural network layer to generate inferences, wherein outputs from one neural network layer are provided as inputs to the next neural network layer. Data inputs to a neural network layer, such as inputs to a neural network or outputs to a layer below the layer in the sequence of neural networks, can be referred to as excitation inputs to the layer.

[0020] In some embodiments, the layers of the neural network are arranged in a directed graph structure. That is, any particular layer can receive multiple inputs, multiple outputs, or both. The layers of the neural network can also be arranged so that the output of a layer can be sent back as an input to a previous layer.

[0021] Figure 1 is a flow chart of an example process 100 for performing computations for a given layer of a neural network using dedicated hardware circuits. For convenience, method 100 will be described with respect to a system having one or more circuits that perform method 100. Method 100 can be performed for each layer of a neural network to compute inferences from received inputs.

[0022] The system receives a set of weight inputs (step 102) and a set of excitation inputs (step 104) for a given layer. The set of weight inputs and the set of excitation inputs can be received from a dynamic memory and a unified buffer of the dedicated hardware circuit, respectively. In some embodiments, the set of weight inputs and the set of excitation inputs can both be received from a unified buffer.

[0023] The system generates a cumulative value from the weight inputs and the stimulus inputs using a matrix multiplication unit of the dedicated hardware circuit (step 106). In some embodiments, the cumulative value is the dot product of the set of weight inputs and the set of stimulus inputs. That is, for one set of weights, the system can multiply each weight input with each stimulus input and add the products together to form the cumulative value. The system can then calculate the dot products of other sets of weights with other sets of stimulus inputs.

[0024] The system can generate an output from the layer using a vector computation unit of the dedicated hardware circuit (step 108). In some embodiments, the vector computation unit applies an activation function to the accumulated value. The output of the layer can be stored in a unified buffer for use as an input to a subsequent layer in the neural network, or can be used to determine an inference. The system completes processing of the neural network when the received input has been processed by each layer of the neural network to generate an inference for the received input.

[0025] Figure 2 An example application specific integrated circuit 200 for performing neural network computations is shown. The system 200 includes a host interface 202. The host interface 202 can receive instructions including configuration information for neural network computations. The configuration information can include at least one or more of the following: how many layers should be processed, a corresponding set of weight inputs for each of the layers, an initial set of excitation inputs, i.e., inputs to the neural network from which inference is to be computed, corresponding input and output sizes for each layer, a stride value for the neural network computation, and the type of layer to be processed, such as a convolutional layer or a fully connected layer.

[0026] The host interface 202 can send instructions to the sequencer 206, which converts the instructions into low-level control signals that control the circuit to perform neural network calculations. In some embodiments, the control signals regulate the data flow in the circuit, such as how the set of weight inputs and the set of excitation inputs flow through the circuit. The sequencer 206 can send control signals to the unified buffer 208, the matrix calculation unit 212, and the vector calculation unit 214. In some embodiments, the sequencer 206 also sends control signals to the direct memory access engine 204 and the dynamic memory 210. In some embodiments, the sequencer 206 is a processor that generates a clock signal. The sequencer 206 can use the timing of the clock signal to send control signals to each component of the circuit 200 at the appropriate time. In some other embodiments, the host interface 202 feeds in a clock signal from an external processor.

[0027] The host interface 202 can send the set of weight inputs and the initial set of stimulus inputs to the direct memory access engine 204. The direct memory access engine 204 can store the set of stimulus inputs in a unified buffer 208. In some embodiments, the direct memory access stores the weights to a dynamic memory 210, which can be a memory unit. In some embodiments, the dynamic memory is located outside the circuit.

[0028] The unified buffer 208 is a memory buffer that can be used to store a collection of stimulus inputs from the direct memory access engine 204 and outputs from the vector calculation unit 214. The direct memory access engine 204 can also read the outputs of the vector calculation unit 214 from the unified buffer 208.

[0029] The dynamic memory 210 and the unified buffer 208 can send the set of weight inputs and the set of excitation inputs to the matrix calculation unit 212, respectively. In some embodiments, the matrix calculation unit 212 is a two-dimensional systolic matrix. The matrix calculation unit 212 can also be a one-dimensional systolic matrix, or other circuits capable of performing arithmetic operations such as multiplication and addition. In some embodiments, the matrix calculation unit 212 is a general-purpose matrix processor.

[0030] The matrix calculation unit 212 can process the weight input and the excitation input and provide the output vector to the vector calculation unit 214. In some embodiments, the matrix calculation unit sends the output vector to the unified buffer 208, and the unified buffer 208 sends the output vector to the vector calculation unit 214. The vector calculation unit can process the output vector and store the processed output vector in the unified buffer. For example, the vector calculation unit 214 can apply a nonlinear function to the output of the matrix calculation unit, such as a vector of accumulated values, to generate an excitation value. In some embodiments, the vector calculation unit 214 generates a normalized value, a pooled value, or both. The processed output vector can be used as an excitation input of the matrix calculation unit 212, for example for use in a subsequent layer of a neural network. Reference will be made below to Figure 3 and Figure 4 The matrix calculation unit 212 is described in more detail.

[0031] Figure 3An example architecture 300 including a matrix computing unit is shown. The matrix computing unit is a two-dimensional systolic array 306. The array 306 includes a plurality of cells 304. In some embodiments, a first dimension 320 of the systolic array 306 corresponds to columns of cells, and a second dimension 320 of the systolic array 306 corresponds to rows of cells. The systolic array can have more rows than columns, more columns than rows, or an equal number of columns and rows.

[0032] In the illustrated example, the value loader 302 sends stimulus inputs to the rows of the array 306, and the weight ingestor interface 308 sends weight inputs to the columns of the array 306. However, in some other implementations, stimulus inputs are transmitted to the columns of the array 306 and weight inputs are transmitted to the rows.

[0033] The value loader 302 can be from, for example Figure 2 The unified buffer of the unified buffer 208 of the array 306 receives the stimulus input. Each value loader can send the corresponding stimulus input to a different leftmost cell of the array 306. The leftmost cell can be a cell along the leftmost column of the array 306. For example, the value loader 312 can send the stimulus input to the cell 314. The value loader can also send the stimulus input to an adjacent value loader, and the stimulus input can be used in another leftmost cell of the array 306. This allows the stimulus input to be transferred for use in another specific cell of the array 306.

[0034] The weight ingestor interface 308 can be obtained from, for example Figure 2 The memory cells of the dynamic memory 210 of the array 306 receive the weight inputs. The weight ingestor interface 308 can send the corresponding weight inputs to different top cells of the array 306. The top cell can be a cell along the topmost row of the array 306. For example, the weight ingestor interface 308 can send the weight inputs to cells 314 and 316.

[0035] In some embodiments, for example Figure 2 The host interface 202 of the host interface 202 transfers the stimulus input throughout the array 306 along one dimension, such as to the right, while transferring the weight input along another dimension throughout the array 306, such as to the bottom. For example, in one clock cycle, the stimulus input of cell 314 can be transferred to the stimulus register in cell 316 to the right of cell 314. Similarly, the weight input in cell 316 can be transferred to the weight register at cell 318 below cell 314.

[0036] At each clock cycle, each cell can process a given weight input and a given excitation input to generate an accumulated output. The accumulated output can also be sent to adjacent cells along the same dimension as the given weight input. Figure 4 Further describe the individual cells.

[0037] The accumulated output can be sent, for example, to the bottom of a column in array 306 along the same column as the weight input. In some embodiments, at the bottom of each column, array 306 can include an accumulator unit 310 that stores and accumulates the accumulated output from each column when performing calculations using a layer with more weight inputs than columns or a layer with more excitation inputs than rows. In some embodiments, each accumulator unit stores multiple parallel accumulated values. This will refer to Figure 6 Further described. The accumulator unit 310 can accumulate each accumulated output to generate a final accumulated value. The final accumulated value can be transmitted to the vector calculation unit. In some embodiments, the accumulator unit 310 sends the accumulated value to the vector calculation unit without performing any accumulation when processing a layer with fewer weight inputs than columns or a layer with fewer excitation inputs than rows.

[0038] Figure 4 For example, Figure 3 An example architecture 400 of a cell within a systolic array 306 of FIG.

[0039] The cell can include an excitation register 406 that stores an excitation input. Depending on the position of the cell within the systolic array, the excitation register can receive the excitation input from a left neighboring cell, i.e., a neighboring cell to the left of a given cell, or from a unified buffer. The cell can include a weight register 402 that stores a weight input. Depending on the position of the cell within the systolic array, the weight input can be transmitted from a top neighboring cell or from a weight ingestor interface. The cell can also include a sum in register 404. The sum in register 404 can store an accumulated value from a top neighboring register. A multiplication circuit 408 can be used to multiply the weight input from the weight register 402 with the excitation input from the excitation register 406. The multiplication circuit 408 can output the product to a summing circuit 410.

[0040] The summing circuit 410 can sum the product and the accumulated value from the sum input register 404 to generate a new accumulated value. The summing circuit 410 can then send the new accumulated value to another sum input register located in the bottom adjacent cell. The new accumulated value can be used as the operand for the summation in the bottom adjacent cell.

[0041] The cell can also transfer weight inputs and excitation inputs to adjacent cells for processing. For example, weight register 402 can send weight inputs to another weight register in the bottom adjacent cell. Excitation register 406 can send excitation inputs to another excitation register in the right adjacent cell. The weight inputs and excitation inputs can therefore be reused by other cells in the array in subsequent clock cycles.

[0042] In some embodiments, the cell further comprises a control register. The control register can store a control signal that determines whether the cell should transfer a weight input or an excitation input to an adjacent cell. In some embodiments, transferring a weight input or an excitation input takes one or more clock cycles. The control signal can also determine whether the excitation input or the weight input is transmitted to the multiplication circuit 408, or can determine whether the multiplication circuit 408 operates on the excitation and weight inputs. The control signal can also be sent to one or more adjacent cells, for example, using a line.

[0043] In some embodiments, the weights are pre-transferred to the weight path register 412. The weight path register 412 can receive weight inputs, for example, from the top neighboring cell, and transmit the weight inputs to the weight register 402 based on the control signal. The weight register 402 can statically store the weight inputs so that when the stimulus input is transmitted to the cell over multiple clock cycles, for example, through the stimulus register 406, the weight input remains in the cell and is not transmitted to the neighboring cell. Therefore, the weight input can be applied to multiple stimulus inputs, for example, using the multiplication circuit 408, and the corresponding accumulated value can be transmitted to the neighboring cell.

[0044] In some embodiments, one neural network input is processed through each layer of the neural network to generate a neural network output for the neural network input. However, in some embodiments, the circuit processes multiple neural network inputs through the layers of the neural network at once to generate a neural network output for the input, thereby improving the utilization of the circuit.

[0045] The inputs to a particular layer of a neural network can be referred to as a set of excitation inputs. Thus, the neural network inputs can be excitation inputs to a first layer. The first layer can generate outputs to be processed by a second layer, and the outputs can be referred to as a set of excitation inputs to the second layer.

[0046] In some embodiments, rather than the circuit processing one set of stimulus inputs by sending the stimulus inputs from the first layer to the final layer of the neural network to generate inferences, the circuit can process multiple sets of stimulus inputs at the first layer, such as Figure 3 The circuit may generate a cumulative value for each set of excitation inputs as described in , then process multiple sets of excitation inputs at a second layer, and so on. Multiple sets of excitation inputs at a given layer can constitute one or more batches of inputs. In some embodiments, batches at a given layer are processed before the circuit processes batches at subsequent layers. The circuit can process a batch by generating a cumulative value for each input in the batch, each of which can be an independent set of excitation inputs.

[0047] In some embodiments, in order to maximize throughput while performing computations for a given neural network layer, the circuit can be configured to process multiple independent stimulus inputs while the weight inputs of the given neural network layer are loaded into the systolic array. That is, the weight inputs can be reused with multiple stimulus inputs. In particular, for example, using Figure 2 The matrix calculation unit 212 of the circuit can reuse the weight input by calculating the accumulated value by using the weight input and different excitation inputs. As an illustration, the excitation input can come from multiple different image resources or multiple audio samples. This will be referred to below Figure 6 Further description.

[0048] The circuit has a processing speed and a speed at which it can access memory. Typically, the processing speed is faster than the memory access speed. By reusing weights and thereby exploiting the processing speed of the circuit, the circuit can exploit cells of the systolic array in parallel while accessing weight inputs from memory to be used in subsequent calculations.

[0049] The circuit can determine how many times to reuse the weights from the weight reuse value of the circuit for each layer of the neural network. This can be determined by software compiled for hardware on the circuit or by hardware. In some embodiments, the weight reuse value is the number of times the circuit can reuse the weight input before the computation time of reusing the weight input several times under different stimulus inputs is greater than or equal to the ingestion time of accessing a new weight input from memory. Therefore, the weight reuse value can indicate how many times the circuit should reuse the weight input to maximize utilization and minimize memory access latency.

[0050] The weighted reuse value can be based on one or more of the following: Figure 2 The clock rate of the memory of the dynamic memory 210 storing the weight input; for example Figure 2The number of arithmetic units within the circuit of the matrix calculation unit 212; and for example Figure 2 The number of channels in the unified buffer 208 and the dynamic memory 210 of the neural network. The weight reuse value can be used to determine the corresponding batch size of each layer of the neural network. The batch size can be called the effective batch size, that is, the batch size that allows the layer to operate in a manner that produces the most effective amount of weight reuse. The batch size is the number of inputs to be processed in the layer so that the pulsation matrix in the circuit is maximized. In some embodiments, the batch size of a given layer is the weight reuse value divided by the upper limit of the number of times the weight input is reused in the layer. The number of times the weight input is reused can directly correspond to the number of excitation inputs stored in the cell of the pulsation array of the circuit when performing accumulation calculations. This is because the weight input can remain in the cell while loading a new set of excitation inputs, that is, "paused". When a new set of excitation inputs is loaded and the weight input is frozen in place, the circuit can reuse the weight input again to calculate the convolution with the new set of excitation inputs. Reference will be made below Figure 6 The examples are further described.

[0051] Figure 5 is a diagram 500 of an example method for performing neural network calculations for multiple layers. The method can be used, for example, Figure 2 The host 202 may be executed by a dedicated hardware circuit, or by one or more processors, firmware, off-chip processors, or by some other software process configured to control the circuit.

[0052] The circuit can receive a set of layer inputs during processing at each neural network layer for processing by the layer (step 502). The set of layer inputs can come from, for example, Figure 2 The memory of the unified buffer 208 of , or from the previous layer, that is, the input set is the output generated from the previous layer in the network, and as mentioned above with reference to Figure 2 As described, using the outputs as a set of inputs can be managed by the host 202. Each input can be a set of stimulus inputs and can be generated from a separate neural network input.

[0053] For a given neural network layer, the system can form one or more batches of inputs from the set of inputs (step 504). As described above, each neural network layer has an associated batch size. Each formed batch at a layer includes a number of inputs that does not exceed the batch size of the layer. The batch inputs for each neural network layer can be determined as a configuration of the neural network. In some embodiments, the batch size for each neural network layer is calculated when compiling the neural network model for execution on the circuit. Because the batch size for a given layer can be calculated before processing at the layer begins, the number of inputs within the batch can be formed based on the batch size for the given layer.

[0054] As an example, if there are 24 images to be processed by a neural network, and the first layer of the neural network has a batch size of 8, the circuit can form 3 batches of 8 images, i.e., divide the 24 images into 3 batches of 8 inputs. For each batch, the circuit can process 8 different images in the batch by reusing a particular set of weight inputs for the layer. The circuit can then (1) process one or more batches at a subsequent layer, or (2) process another batch of 8 different image resources using the particular set of weight inputs at the layer. The circuit determines whether to continue processing with (1) or (2) based on the batch sizes of other layers in the neural network, which will be described in step 506 below and in reference to Figure 6 Further description.

[0055] For a given neural network layer, the circuit can select multiple of the one or more batches for processing (step 506). In some embodiments, the number is selected so that the count of inputs in the number of the one or more batches is greater than or equal to the corresponding batch size of the subsequent layer. For example, if the current layer must process 3 batches with 5 inputs each, and the batch size of the subsequent layer is 10, the circuit can select 2 of the 3 batches for processing. The 2 selected batches have a total of 10 inputs, i.e., 2*5, which is equal to the corresponding batch size of the subsequent layer, i.e., 10. In some embodiments, the remaining third batch will be processed in a subsequent round of the systolic array in the circuit. Reference will be made below to Figure 6 Still another example is further described.

[0056] The circuit can process the selected number of input batches, for example using a systolic array, to generate a corresponding layer output for each input in the selected batch (step 508). The circuit can process each selected input batch by reusing the weight input when calculating the accumulated value for each input. As described above, the weight input is applied to multiple independent inputs because the weight input can remain in the cell, i.e., "paused", while a new set of stimulus inputs is loaded.

[0057] As an illustration, a batch can have two inputs - a set A1 of excitation inputs and a set A2 of excitation inputs. The circuit can reuse a set W1 of weight inputs by applying it to both sets A1 and A2 before retrieving a set W2 of weight inputs from memory, where set W2 is the set of weights for a subsequent layer, or, if a layer has more weights than can be processed by the circuit's systolic array, the next subset of weights for the layer. In another example, if there are 8 batches of 5 inputs each to be processed, i.e., 40 total inputs, and the circuit selects 4 batches for processing, the circuit can process the inputs within the 4 batches, i.e., 20 total inputs, to generate outputs for the corresponding layers, i.e., 20 total layer outputs. This will be referred to below Figure 6 Further description.

[0058] After processing the selected number of batches, the circuit can process a second number of batches at the layer or continue to process one or more batches at subsequent layers. This will be referred to below Figure 6 Further description.

[0059] Although the method is described as being implemented on a circuit that processes a neural network, the method can also be implemented on a processor such as a central processing unit (CPU) or a graphics processing unit (GPU). For example, the processor can reuse the weight values ​​a certain number of times while retrieving the weights from a memory, such as a dynamic random access memory (DRAM).

[0060] Figure 6 An example neural network 600 with multiple layers and the batch size of each layer are shown. As described above, the batch size of a given layer is the weight reuse value divided by the upper limit value of the number of times the weight input is reused at the layer. The upper limit function can process a quantity and return the smallest integer that is not less than the quantity. The number of times the weight input is reused can directly correspond to the number of stimulus inputs stored in the cell of the systolic array of the circuit. For example, the weight reuse value of the circuit can be 150. Layer 1 602 processes 170×170 inputs. Each of the 170×170 stimulus inputs can be stored in a cell of the systolic array. Therefore, the batch size of layer 1 602 is CEIL(1500 / (170*170))=1. The batch size of layer 2 604 is CEIL(1500 / (28*28))=2. Using the same calculation, layers 3-5 606-610 have a batch size of 8, and layer 6 612 has a batch size of 32. In some implementations, the batch size is rounded to the nearest power of 2.

[0061] As an illustration, layer 1 has a batch size of 1 input, while layer 2 has a batch size of 2 inputs. The circuit can, for example, receive 10 inputs for processing at layer 1, such as a total of 10 different images.

[0062] The circuit can determine that two batches out of ten at layer 1, i.e., a total of 2 inputs, should be processed. In some embodiments, the circuit determines this number by dividing the batch size at layer 2 by the batch size of layer 1, i.e., 2 / 1=2. By processing two batches of a single input, the circuit processes two inputs, which is equal to the batch size of layer 2, i.e., 2. The circuit can process these two batches to generate two layer outputs from the two inputs, for example, by calculating two vectors of accumulated values ​​- one for each image. Each layer output can be used as an input for input to a subsequent layer. The circuit can form batches of two inputs, such as two vectors of accumulated values, for processing at layer 2. The batches can be stored in a unified buffer.

[0063] The circuit can determine that four batches at layer 2 should be processed. By processing four batches of size 2, the circuit processes 8 inputs, which is equal to the batch size at layer 3, i.e., 8. The circuit can process these four batches to generate eight layer outputs from the 8 inputs. Subsequently, the circuit can form batches of 8 inputs for processing at layer 3.

[0064] The circuit can continue until the inputs have been processed at all layers of the neural network. For example, since layers 3-5 have a batch size of 8, the circuit can determine that one batch of 8 inputs at each of layers 3-5 should be processed. Similarly, the circuit can determine that four batches of 8 inputs each at layer 5 should be processed, thereby forming batches of 32 inputs that can be processed at layer 6. For each input, layer 6 can generate one or more layer outputs that can be used for inference.

[0065] In some embodiments, the circuit calculates the least common multiple of the batch sizes across all layers in the neural network using, for example, an arithmetic circuit. The circuit can then process a minimum number of inputs equal to or greater than the least common multiple at each layer before processing a subsequent layer. In other words, the circuit can determine based on the least common multiple whether to (1) process a batch at a subsequent layer or (2) process another batch at the current layer. For example, the least common multiple of the batch sizes for layers 1-6 602-612 is 32. After layer 1 processes a batch, the circuit can determine that layer 1 has only generated 1 output, which is less than the least common multiple of 32. Therefore, the circuit can determine that to process another batch at layer 1, a total of 2 outputs have been generated at layer 1. The circuit can continue to generate outputs until 32 outputs have been generated at layer 1, which is the least common multiple. Subsequently, the circuit can continue to process batches at subsequent layers. In some embodiments, each layer output is stored in a unified buffer, for example Figure 2 The unified buffer 208.

[0066] As an illustration, the circuit can select 32 batches for processing, which is a total of 32 inputs at layer 1. The circuit can then select 16 batches for a total of 32 inputs at layer 2, then select 4 batches at layer 3 to process a total of 32 inputs, then select 4 batches at layer 4 to process a total of 32 inputs, then select 4 batches at layer 5 to process a total of 32 inputs, and finally select 1 batch at layer 6 to process a total of 32 inputs.

[0067] In some embodiments, at a particular layer, the circuit processes a number of inputs greater than the least common multiple based on system parameters, such as parameters provided by a user. In some embodiments, the circuit processes a number of inputs that is divisible by a batch size of a subsequent layer. In some other embodiments, the circuit receives instructions to process a large number of inputs, and the circuit processes batches of inputs before continuing to generate outputs in a subsequent number so as to maximize the number of outputs generated at a particular layer. The circuit can limit the number of outputs generated at a particular layer so that the number of outputs generated is divisible by a batch size of a subsequent layer.

[0068] Embodiments of the subject matter and functional operations described in this specification can be implemented in digital electronic circuits, in tangibly embodied computer software or firmware, in computer hardware including the structures disclosed in this specification and their structural equivalents, or in a combination of one or more of them. Embodiments of the subject matter disclosed in this specification can be implemented as one or more computer programs, i.e., one or more computer program instruction modules encoded on a tangible non-transient program carrier for execution or control of its operation by a data processing device. Alternatively or additionally, the program instructions can be encoded on an artificially generated propagation signal, such as a machine-generated electrical, optical or electromagnetic signal, which is generated to encode information for transmission to an appropriate receiver device and execution by a data processing device. The computer storage medium can be a computer-readable storage device, a computer-readable storage substrate, a random or serial access memory device, or a combination of one or more of them.

[0069] The term "data processing apparatus" encompasses all types of apparatus, devices and machines for processing data, including, for example, a programmable processor, a computer, or a plurality of processors or computers. The apparatus may include special-purpose logic circuitry, such as an FPGA (field programmable gate array) or an ASIC (application-specific integrated circuit). In addition to hardware, the apparatus may also include code that creates an execution environment for the computer program in question, such as code constituting processor firmware, a protocol stack, a database management system, an operating system, or a combination of one or more of them.

[0070] A computer program (also referred to or described as a program, software, software application, module, software module, script or code) can be written in any form of programming language, including compiled or interpreted languages, or declarative or procedural languages, and can be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment. A computer program may correspond to a file in a file system, but this is not required. A program can be stored in a portion of a file of other programs or data, such as one or more scripts stored in a markup language document, in a single file dedicated to the program in question, or in multiple collaborative files, such as files storing one or more modules, subroutines or code portions. A computer program can be deployed to execute on one or more computers, which are located in one location or distributed across multiple locations and interconnected by a communication network.

[0071] The processes and logic flows described in this specification can be implemented by one or more programmable computers executing one or more computer programs to perform functions by operating on input data and generating output. The processes and logic flows can also be performed by, and the apparatus can also be implemented as, a special purpose logic circuit such as an FPGA (field programmable gate array) or an ASIC (application specific integrated circuit).

[0072] Processors suitable for executing computer programs include, for example, can be based on general and special microprocessors or both, and any other type of central processing unit. Typically, the central processing unit will receive instructions and data from a read-only memory or a random access memory or both. The essential components of a computer are a central processing unit for executing or performing instructions and one or more memories for storing instructions and data. Typically, a computer will also include one or more large storage devices for storing data, or be operatively coupled to the large storage device, or both, such as magnetic, magneto-optical disks or optical disks. However, a computer is not necessarily provided with such a device. In addition, a computer can be embedded in another device, and only a few examples are given, such as a mobile phone, a personal digital assistant (PDA), a mobile audio or video player, a game console, a global positioning system (GPS) receiver, or a portable storage device, such as a universal serial bus (USB) flash memory.

[0073] Computer-readable media suitable for storing computer program instructions and data include all forms of non-volatile memory, media and memory devices, including, for example, semiconductor memory devices, such as EPROM, EEPROM and flash memory devices; magnetic disks, such as internal hard disks or removable disks; magneto-optical disks; and CD ROM and DVD-ROM disks. The processor and memory may be supplemented by or incorporated in special purpose logic circuits.

[0074] To transmit interactions with a user, embodiments of the subject matter described in this specification may be implemented on a computer having a display device, such as a CRT (cathode ray tube) or LCD (liquid crystal display) monitor, for displaying information to the user, and a keyboard and pointing device, such as a mouse or trackball through which the user can transmit input to the computer. Other types of devices may also be used to provide interactions with the user; for example, the feedback provided to the user may be any form of sensory feedback, such as visual feedback, auditory feedback, or tactile feedback; and the input from the user may be received in any form, including sound, voice, or tactile input. In addition, the computer can interact with the user by sending documents to and receiving documents from the device used by the user; for example, by sending a web page to a web browser in response to a request received from the web browser on the user's client device.

[0075] Embodiments of the subject matter described in this specification may be implemented in a computing system that includes a back-end component, such as a data server; or includes a middleware component, such as an application server; or includes a front-end component, such as a client computer having a graphical user interface or a web browser through which a user can interact with an implementation of the subject matter described in this specification; or any combination of one or more such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication, such as a communication network. Examples of communication networks include local area networks ("LANs") and wide area networks ("WANs"), such as the Internet.

[0076] A computing system may include clients and servers. Clients and servers are generally remote from each other and typically interact through a communication network. The relationship of client and server is established by computer programs running on respective computers and having a client-server relationship to each other.

[0077] Although this specification contains many specific implementation details, these should not be understood as limiting the scope of any invention and the content claimed for protection, but as a description of features specific to a particular embodiment of a particular invention. Certain features described in this specification in the context of a single embodiment can also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment can also be implemented in multiple embodiments alone or in any appropriate sub-combination. In addition, although features may be described above as working in a certain combination and even initially required to be so, one or more features from the required combination may be separated from the combination in some cases, and the required combination may be directed to a sub-combination or a variation of the sub-combination.

[0078] Similarly, although the operations are depicted in a particular order in the figures, this should not be understood as requiring such operations to be performed in the particular order shown or in a continuous order, or that all illustrated operations must be performed to achieve the desired result. In certain cases, multitasking and parallel processing may be advantageous. In addition, the division of various system modules and components in the above described embodiments should not be understood as requiring such division in all embodiments, and it should be understood that the described program components and systems are typically integrated together in a single software product or packaged into multiple software products.

[0079] Specific embodiments of the subject matter have been described. Other embodiments are within the scope of the following claims. For example, the actions referenced in the claims can be performed in a different order and still achieve the desired results. As an example, the processes depicted in the accompanying drawings do not necessarily require the specific order or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing may be advantageous.

Claims

1. A method for performing neural network calculations using a hardware circuit, the method comprising: Obtaining a first batch of inputs to be processed at a layer of a neural network, wherein the layer has an associated batch size; obtaining a weight of the layer, wherein the weight has an associated reuse value, the reuse value defining an amount of reuse of the weight of the layer; selecting a particular number of inputs in the first batch to be processed at the layer using the weights based on the batch size, the reuse value of the weights, and a threshold ingestion time indicating a time required to access a memory of the hardware circuit to retrieve new weights for the layer, wherein the particular number of inputs is selected so as not to exceed: i) the batch size of the layer, or ii) a number of times the weights are allowed to be reused based on the reuse value; and The certain number of inputs are processed using the weights to generate a layer output.

2. The method according to claim 1, wherein: Selecting the particular number of inputs in the first batch includes: Determining the number of times the hardware circuit is allowed to reuse the weights of the layer before a computation time is at least equal to an ingestion time, wherein the computation time is the time to reuse the weights with different excitation inputs the number of times, and the ingestion time is the time to access new weight inputs for the layer.

3. The method according to claim 2, wherein: The inputs for selecting the specific number include: The particular number of inputs is selected so that the computation time for reusing the weights does not exceed the ingestion time for accessing new weight inputs for the layer.

4. The method according to claim 1, wherein: The hardware circuit includes an array of computational cells, and processing the specific number of inputs to generate the layer output includes: In a first processor clock cycle and a second subsequent processor clock cycle, weights of the layer and activation inputs of the specific number of inputs are reused by two or more corresponding computation cells in the array.

5. The method according to claim 4, wherein: Processing the specific number of inputs to generate the layer outputs includes: A plurality of independent stimulus inputs are processed while reusing weights of a given layer of the neural network that are loaded into the array, the weights of the given layer being reused based on the reuse value.

6. The method according to claim 1, further comprising: The weights of the layer are reused based on the processing speed of the hardware circuit, wherein the reuse of the weights of the layer includes reusing a first portion of the weights to process the inputs of the specific number of inputs, while accessing a second portion of the weights from a memory in parallel based on the processing speed of the hardware circuit, and the second portion of the weights will be used in subsequent calculations.

7. The method according to claim 6, wherein: The weighted reuse value is based on at least one of the following: the number of arithmetic units included in the hardware circuit; or The number of channels included in a memory of the hardware circuit for storing batches of inputs to be processed at one or more layers of the neural network.

8. A system for performing neural network computations using hardware circuits, the system comprising: processor; as well as a non-transitory machine-readable storage device for storing instructions executable by the processor to cause operations to be performed, the operations comprising: Obtaining a first batch of inputs to be processed at a layer of a neural network, wherein the layer has an associated batch size; obtaining a weight of the layer, wherein the weight has an associated reuse value, the reuse value defining an amount of reuse of the weight of the layer; selecting a particular number of inputs in the first batch to be processed at the layer using the weights based on the batch size, the reuse value of the weights, and a threshold ingestion time indicating a time required to access a memory of the hardware circuit to retrieve new weights for the layer, wherein the particular number of inputs is selected so as not to exceed: i) the batch size of the layer, or ii) a number of times the weights are allowed to be reused based on the reuse value; and The certain number of inputs are processed using the weights to generate a layer output.

9. The system according to claim 8, wherein: Selecting the particular number of inputs in the first batch includes: Determining the number of times the hardware circuit is allowed to reuse the weights of the layer before a computation time is at least equal to an ingestion time, wherein the computation time is the time to reuse the weights with different excitation inputs the number of times, and the ingestion time is the time to access new weight inputs for the layer.

10. The system according to claim 9, wherein: The inputs for selecting the specific number include: The particular number of inputs is selected so that the computation time for reusing the weights does not exceed the ingestion time for accessing new weight inputs for the layer.

11. The system according to claim 8, wherein: The hardware circuit includes an array of computational cells, and processing the specific number of inputs to generate the layer output includes: In a first processor clock cycle and a second subsequent processor clock cycle, weights of the layer and activation inputs of the specific number of inputs are reused by two or more corresponding computation cells in the array.

12. The system according to claim 11, wherein: Processing the specific number of inputs to generate the layer outputs includes: A plurality of independent stimulation inputs are processed while reusing weights loaded in the array for a given layer of the neural network, the weights of the given layer being reused based on the reuse value.

13. The system of claim 8, further comprising: The weights of the layer are reused based on the processing speed of the hardware circuit, wherein the reuse of the weights of the layer includes reusing a first portion of the weights to process the inputs of the specific number of inputs, while accessing a second portion of the weights from a memory in parallel based on the processing speed of the hardware circuit, and the second portion of the weights will be used in subsequent calculations.

14. The system according to claim 13, wherein: The weighted reuse value is based on at least one of the following: the number of arithmetic units included in the hardware circuit; or The number of channels included in a memory of the hardware circuit for storing batches of inputs to be processed at one or more layers of the neural network.

15. A non-transitory machine-readable storage device for storing instructions to perform neural network computations using hardware circuits, the instructions executable by a processor to cause operations to be performed, the operations comprising: Obtaining a first batch of inputs to be processed at a layer of a neural network, wherein the layer has an associated batch size; obtaining a weight of the layer, wherein the weight has an associated reuse value, the reuse value defining an amount of reuse of the weight of the layer; selecting a particular number of inputs in the first batch to be processed at the layer using the weights based on the batch size, the reuse value of the weights, and a threshold ingestion time indicating a time required to access a memory of the hardware circuit to retrieve new weights for the layer, wherein the particular number of inputs is selected so as not to exceed: i) the batch size of the layer, or ii) a number of times the weights are allowed to be reused based on the reuse value; and The certain number of inputs are processed using the weights to generate a layer output.

16. The machine-readable storage device of claim 15, wherein: Selecting the particular number of inputs in the first batch includes: Determining the number of times the hardware circuit is allowed to reuse the weights of the layer before a computation time is at least equal to an ingestion time, wherein the computation time is the time to reuse the weights with different excitation inputs the number of times, and the ingestion time is the time to access new weight inputs for the layer.

17. The machine-readable storage device of claim 15, wherein: The hardware circuit includes an array of computational cells, and processing the specific number of inputs to generate the layer output includes: In a first processor clock cycle and a second subsequent processor clock cycle, weights of the layer and activation inputs of the specific number of inputs are reused by two or more corresponding computation cells in the array.