Implementation of Softmax and Exponential in Hardware

Information

  • Patent Application
  • 20220391172
  • Publication Number
    20220391172
  • Date Filed
    February 25, 2022
    2 years ago
  • Date Published
    December 08, 2022
    a year ago
Abstract
Methods for implementing an exponential operation, and a softmax neural network layer, in neural network accelerator hardware, and a data processing system for implementing the exponential operation and a data processing system for implementing the softmax layer. The exponential operation or softmax layer is mapped to a plurality of elementary neural network operations, and the neural network accelerator hardware evaluates these operations, to produce the result of the operation or layer respectively.
Description
BACKGROUND

Softmax is a common operation in neural networks, often used where a discrete probability is needed. It is also used in some cases to normalise a tensor so that all elements along a certain axis or axes are strictly in the range [0,1] and sum to 1. The challenge of implementing a softmax layer in a neural network is that it is a relatively complicated operation with several steps.


A softmax layer performs, for any value xj in a set or vector of values, the operation:







s

(

x
j

)

=


e

x
j





i


e

x
i








In order to drop the subscript notation, this equation can be rewritten in terms of a vector x:







s

(
x
)

=


e
x





z

x



e
z







Softmax maps input values in the range (−∞, +∞) to outputs in the range [0,1]. Furthermore, the sum of the output values is 1 (as required for a discrete probability distribution).


It is known that the evaluation of a softmax layer may suffer from numerical instability problems if the input values x are large in magnitude. The input x may have such large positive values that overflow occurs in the output of the exponential ex, or such large negative values that underflow occurs. Even when overflow does not occur, with large values of x, some of the exponential values ex may be so large in comparison with others that the normalisation is no longer reliable.


A solution to at least some of these issues is to subtract the maximum value from all values in the tensor (or vector) x:







s

(
x
)

=


e

x
-
M






z

x



e

z
-
M








Where M=max(x). This redefined layer is identical to the definition above but is more stable numerically. The subtraction of the maximum reduces the range of the input from (−∞, +∞) to (−∞, 0], but does not affect the result.


Traditionally, a softmax layer has often been used as the final layer of a neural network used for classification—for example, image classification. Here, the softmax layer would produce a vector of probabilities, each value in the vector representing the probability (as estimated by the neural network) that the image belonged to a respective class from a set of mutually exclusive classes. Softmax is often applied over the channel dimension of a 4D tensor with dimensions for batch, height, width and channels, but the present disclosure is not limited to this usage.


It is becoming increasingly common to implement neural networks on specially adapted hardware accelerators, known as neural network accelerators (NNAs). These devices—usually integrated circuits—are typically specialised at evaluating the most computationally intensive operations encountered when using a neural network for inference. For example, a neural network accelerator may include a plurality of convolution engines, which are specialised at evaluating convolutional layers.


SUMMARY

This Summary is provided to introduce a selection of concepts in a simplified form that are further described below in the Detailed Description. This Summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.


Methods are disclosed for implementing an exponential operation, and a softmax neural network layer, in neural network accelerator hardware. Also disclosed are a data processing system for implementing the exponential operation and a data processing system for implementing the softmax layer. The exponential operation or softmax layer is mapped to a plurality of elementary neural network operations, and the neural network accelerator hardware evaluates these operations, to produce the result of the operation or layer respectively. It should be understood that the term “exponential operation” is used to refer to an operation implementing the natural exponential function ƒ(x)=ex.


According to one aspect, there is disclosed a method of implementing an exponential operation in a hardware accelerator comprising fixed-function circuitry configured to perform a set of available elementary neural network operations, according to claim 1.


The input to the layer may be a tensor or a vector. Where the input is a tensor, the tensor may have dimensions of batch, channel, height, and width.


The first, second, and/or third LUT may each be implemented by a separate hardware module. Alternatively, two of these LUTs (in particular, the first LUT and second LUT) may be implemented by the same hardware module at different times. For example, a single LUT hardware module may be loaded with values representing a sigmoid function, for evaluating the first lookup, at a first time, and may be loaded with values representing a reciprocal function, for evaluating the second lookup, at a second time. This can increase hardware utilisation, reuse, and flexibility, by re-using the same LUT hardware for different operations.


The representation may comprise or consist exclusively of the plurality of elementary neural network operations.


“Fixed-function,” in this context, refers to the property of the hardware that the logic it implements cannot be reconfigured after manufacture (or at least cannot be reconfigured extensively). This is in contrast to field programmable logic, for example, which is reconfigurable. It is also in contrast with general purpose processor hardware, which is fully programmable to implement any (arbitrary) function or algorithm. The hardware accelerator may be comprised in an application specific integrated circuit (ASIC). The behaviour of the fixed-function hardware may be programmable to a limited extent. A fixed-function hardware module may be able to perform its fixed function under the control of a limited set of parameters, for example. Each hardware module may therefore be reconfigurable only in the sense that it can implement, for example, convolution or pooling with various strides and kernel sizes, but it is not fully programmable in the sense that it could execute an arbitrary algorithm.


The plurality of elementary neural network operations may implement: a negation, applied to input values, to produce negated input values; a sigmoid function, applied to the negated input values, to produce sigmoid negated values; a reciprocal operation, applied to the sigmoid negated values, to produce reciprocal sigmoid values; and an addition or subtraction, applied to the reciprocal sigmoid values, to subtract a constant from the reciprocal sigmoid values and thereby produce output values of the exponential operation.


The constant may be equal to 1 (unity). The constant may be expressed as a positive number (for example, +1) and subtracted from the reciprocal sigmoid values. Alternatively, the constant may be expressed as a negative number (for example, −1) and added to the reciprocal sigmoid values.


According to this method, the exponential operation can be constructed from elementary operations using the identity







e
x

=


1

σ

(

-
x

)


-
1





This representation of the exponential operation consists entirely of operations that can be performed by existing hardware in an exemplary hardware accelerator. The use of the sigmoid function is based on the recognition that this function is related to the exponential operation. This relationship is usually used to evaluate the sigmoid function by first evaluating the exponential function. However, it has been recognised that the relationship can be inverted, to allow the exponential operation to be evaluated by first evaluating the sigmoid function. This can provide a convenient way to evaluate the exponential operation, since the sigmoid function is a common activation function and may therefore already be implemented efficiently in a hardware accelerator.


The negation may be evaluated by an element-wise subtraction operation, using an element-wise operations unit of the hardware accelerator.


The sigmoid function may be evaluated by a first lookup, using an activation unit of the hardware accelerator.


The sigmoid function is a standard choice for an activation function; therefore, a lookup table (LUT) in an exemplary hardware accelerator will commonly offer the ability to implement a sigmoid function.


The reciprocal operation may be evaluated by one of: a second lookup, using an activation unit of the hardware accelerator; a local response normalisation, using an LRN unit of the hardware accelerator; and an element-wise division, using an element-wise operations unit of the hardware accelerator.


Local response normalisation is a commonly used operation in neural networks, for scaling variables. The LRN is a computationally complex function; however, the inventors have realised that, by choosing the parameters of the function carefully, the LRN can be simplified and exploited to implement a reciprocal. Alternatively, reciprocals may be programmed into a lookup table (if the hardware and software implementation allows this flexibility).


In some embodiments, the reciprocal operation and the sigmoid function may be combined in the third lookup. For example, the third LUT may contain the function







f

(
x
)

=


1

σ

(
x
)


.





In some of these embodiments, the reciprocal operation and the sigmoid function may be further combined with the first subtraction, which negates the input values. That is, the third LUT may contain the function








f

(
x
)

=

1

σ

(

-
x

)



.




The third lookup, like the first lookup and the second lookup, may be evaluated using an activation unit of the hardware accelerator.


The addition or subtraction may be evaluated by an element-wise addition or element-wise subtraction, using an activation unit of the hardware accelerator. The activation unit may be configured to add/subtract the same value to/from every element of a tensor.


According to another aspect, there is provided a method of implementing a softmax layer in a hardware accelerator comprising fixed-function circuitry configured to perform a set of available elementary neural network operations, according to claim 7.


The plurality of elementary neural network operations may include at least one function approximation operation, wherein the function approximation operation is implemented as a lookup in an LUT, the LUT optionally comprising one of: a sigmoid function; a reciprocal function; a reciprocal of a sigmoid function; the function ƒ(z)=2z, where z is a value in the range (0,1) and an exponential function.


If the plurality of elementary neural network operations comprises two or more lookups, then these lookups may be implemented by separate LUTs, in separate hardware modules. Alternatively, they may be implemented by a single LUT hardware module carrying out different lookups at different times. Reuse of a single LUT in this way can improve hardware utilisation.


The plurality of elementary neural network operations may implement: a maximum operation, applied to input values, to obtain the maximum among the input values; a first subtraction, subtracting the maximum from each of the input values, to produce negative-shifted input values; an exponential operation, applied to the negative-shifted input values, to produce exponentiated values; a summation, applied to the exponentiated values, to produce a sum of the exponentiated values; and a division, dividing each of the exponentiated values by the sum of the exponentiated values.


The maximum operation may be evaluated by one of: a max pooling operation, using a pooling unit of the hardware accelerator; and repeated iterations of an element-wise maximum operation, using an element-wise operations unit of the hardware accelerator.


If the softmax layer is to be evaluated over a channel dimension (or batch dimension) of an input tensor, evaluating the maximum operation by means of the max pooling operation may comprise applying a transpose (or permute) operation to the input tensor prior to the max pooling, so that the elements whose maximum is to be calculated are arranged over one or both of a height dimension and a width dimension. This may be beneficial if the pooling unit is specialised at evaluating pooling operations over one or both of these spatial dimensions. A transpose (or permute) operation may be applied after the max pooling, to invert the first transpose and return the dimensions to their original configuration.


If the maximum operation is to be evaluated by means of repeated element-wise maximum operations, the evaluating may comprise splitting the input tensor into two halves, comparing the two halves element-wise by means of an element-wise maximum, and repeating this process until a single unique maximum value (in the relevant dimension or dimensions) is obtained.


The first subtraction may be evaluated by an element-wise subtraction operation, using an element-wise operations unit of the hardware accelerator.


The exponential operation may be mapped to a subset of the plurality of elementary neural network operations, wherein said subset implements: a negation, applied to the negative-shifted input values, to produce negated input values; a sigmoid function, applied to the negated input values, to produce sigmoid negated values; a first reciprocal operation, applied to the sigmoid negated values, to produce reciprocal sigmoid values; and an addition or a second subtraction, applied to the reciprocal sigmoid values, to subtract a constant from the reciprocal sigmoid values and thereby produce output values of the exponential operation.


The component operations of the exponential operation may be implemented as already summarised previously above.


Alternatively, in some embodiments, the exponential operation may be evaluated directly by a lookup in an LUT, using an activation unit of the hardware accelerator.


The summation may be evaluated by a convolution, using one or more convolution engines of the hardware accelerator. The convolution may comprise a convolution with a tensor of ones of the same size as the tensor of exponentiated values in the dimensions over which the sum is to be taken. If the softmax layer is to be applied over the channel dimension, the convolution may be a 1×1 convolution, wherein the kernel has width=height=1, a number of input channels equal to the number of channels in the tensor of exponentiated values, and a single output channel.


The division may be implemented as a second reciprocal operation and a multiplication.


The multiplication operation may be evaluated by an element-wise multiplication operation, using an element-wise operations unit of the hardware accelerator.


At least one of the first reciprocal operation and the second reciprocal operation may be evaluated by one of: a lookup, using an activation unit of the hardware accelerator; a local response normalisation, using an LRN unit of the hardware accelerator; and an element-wise division, using an element-wise operations unit of the hardware accelerator.


The inventors have recognised that a local response normalisation can be used to calculate reciprocals. By setting the constants α, β=1 and k, n=0, the LRN reduces from a complicated normalisation function to one that returns the reciprocal of the input.


One reciprocal operation may be evaluated using the activation unit and the other reciprocal operation may be evaluated by the LRN unit. Alternatively, both reciprocal operations may be evaluated by the activation unit, or both reciprocal operations may be evaluated by the LRN unit.


In some embodiments, the softmax layer is to be applied to input data comprising a first element and a second element, and wherein the plurality of elementary neural network operations implements: at least one subtraction, to obtain at least one difference between the first element and the second element; and a sigmoid function, applied to the at least one obtained difference, to produce an output of the softmax layer.


The first element and second element may be elements of a tensor. The tensor may have a size of 2 in the dimension in which the softmax layer is to be evaluated.


The at least one subtraction may be evaluated by a convolution, using one or more convolution engines of the hardware accelerator. Alternatively, or in addition, the sigmoid function may be evaluated by a function approximation operation, optionally using an activation unit of the hardware accelerator. The function approximation operation may comprise a lookup in an LUT of the activation unit.


Mapping the neural network layer to the representation comprising the plurality of elementary neural network operations optionally comprises: identifying at least two consecutive elementary neural network operations that can be combined; and combining the at least two consecutive elementary neural network operations into a smaller number of elementary neural network operations.


For example, a negation operation may be combined with an addition or subtraction operation. In another example, two consecutive LUT lookup operations could be combined by loading into a single LUT a representation of a single compound function that combines the individual functions that were implemented by the consecutive LUTs.


Also provided is a data processing system for implementing an exponential operation, according to claim 19. The representation may comprise or consist exclusively of the plurality of elementary neural network operations.


Additionally provided is a data processing system for implementing a softmax layer, according to claim 20. Again, the representation may comprise or consist exclusively of the plurality of elementary neural network operations. The function approximation operation may be implemented as a lookup in an LUT.


The hardware accelerator may comprise any one of, or any combination of two or more of: an activation unit, comprising an LUT; a local response normalisation unit, configured to perform a local response normalisation; an element-wise operations unit, configured to apply a selected operation to every pair of respective elements of two tensor of identical size; one or more convolution engines, configured to perform convolution operations; and a pooling unit, configured to perform pooling operations, including (but generally not limited to) max pooling.


Optionally, when the hardware accelerator comprises the activation unit, one or more of the plurality of elementary neural network operations may implement a sigmoid function, and the activation unit may be configured to evaluate the sigmoid function.


Optionally, when the hardware accelerator comprises the local response normalisation unit, one or more of the plurality of elementary neural network operations may implement a reciprocal operation, and the local response normalisation unit may be configured to evaluate the reciprocal operation.


The data processing system may further comprise a memory manipulation module, configured to manipulate data stored in a memory, and the hardware accelerator may comprise a pooling unit, configured to perform pooling operations, including max pooling. The one or more of the plurality of elementary neural network operations may implement a maximum operation, applied to input data over a channel dimension, wherein the memory manipulation module is configured to rearrange the dimensions of the input data to arrange the channel dimension over one or more spatial dimensions, and wherein the pooling unit is configured to evaluate the maximum operation by performing max pooling over the one or more spatial dimensions.


Also provided is a data processing system configured to perform the method of any of the appended claims.


A data processing system may be embodied in hardware on an integrated circuit.


Also provided is a method of manufacturing, using an integrated circuit manufacturing system, a data processing system as summarised above or as claimed in any of the appended claims.


Also provided is a method of manufacturing, using an integrated circuit manufacturing system, a data processing system as summarised above or as claimed in any of the appended claims, the method comprising: processing, using a layout processing system, a computer readable description of the data processing system so as to generate a circuit layout description of an integrated circuit embodying the data processing system; and manufacturing, using an integrated circuit generation system, the data processing system according to the circuit layout description.


Also provided is computer readable code configured to cause a method as summarised above or the method of any of the appended claims to be performed when the code is run. Also provided is a computer readable storage medium having encoded thereon said computer readable code.


Further provided is an integrated circuit definition dataset that, when processed in an integrated circuit manufacturing system, configures the integrated circuit manufacturing system to manufacture a data processing system as summarised above or as claimed in any of the appended claims.


Additionally provided is a computer readable storage medium (optionally non-transitory) having stored thereon a computer readable description of a data processing system as summarised above or as claimed in any of the appended claims that, when processed in an integrated circuit manufacturing system, causes the integrated circuit manufacturing system to manufacture an integrated circuit embodying the data processing system or NNA.


Also provided is a computer readable storage medium (optionally non-transitory) having stored thereon a computer readable description of a data processing system as claimed in any of the appended claims which, when processed in an integrated circuit manufacturing system, causes the integrated circuit manufacturing system to: process, using a layout processing system, the computer readable description of the data processing system so as to generate a circuit layout description of an integrated circuit embodying the data processing system; and manufacture, using an integrated circuit generation system, the data processing system according to the circuit layout description.


Also provided is an integrated circuit manufacturing system configured to manufacture a data processing system as summarised above or as claimed in any of the appended claims.


Also provided is an integrated circuit manufacturing system comprising: a non-transitory computer readable storage medium having stored thereon a computer readable description of a data processing system as summarised above or as claimed in any of the appended claims; a layout processing system configured to process the computer readable description so as to generate a circuit layout description of an integrated circuit embodying the data processing system; and an integrated circuit generation system configured to manufacture the data processing system according to the circuit layout description.


The layout processing system may be configured to determine positional information for logical components of a circuit derived from the integrated circuit description so as to generate a circuit layout description of an integrated circuit embodying the data processing system.


The above features may be combined as appropriate, as would be apparent to a skilled person, and may be combined with any of the aspects of the examples described herein.





BRIEF DESCRIPTION OF THE DRAWINGS

Examples will now be described in detail with reference to the accompanying drawings in which:



FIG. 1A shows a computational graph of a softmax layer;



FIG. 1B is a computational graph showing one way of calculating the exponential operation in FIG. 1A;



FIG. 2 is a block diagram of a hardware accelerator according to an example of the present disclosure;



FIG. 3 is a block diagram of a convolution engine as used in FIG. 2;



FIG. 4 is a block diagram of a data processing system according to an example, for implementing a softmax layer or an exponential operation;



FIG. 5 is a block diagram of the memory manipulation module in FIG. 4;



FIG. 6A is a flowchart illustrating a method of implementing an exponential operation in a hardware accelerator, according to an example;



FIG. 6B is a flowchart illustrating a method of implementing a softmax layer in a hardware accelerator, according to an example;



FIG. 7A illustrates a maximum operation;



FIG. 7B is a computational graph illustrating one approach for implementing the maximum operation of FIG. 7A;



FIG. 7C shows a way of determining the maximum of a tensor by successive element-wise comparisons;



FIG. 7D shows another example of determining a maximum by successive element-wise comparisons;



FIG. 8 is a computational graph illustrating an alternative approach for implementing the maximum operation of FIG. 7A;



FIG. 9A illustrates a summation operation;



FIG. 9B is a computational graph illustrating one way in which the summation operation of FIG. 9A can be mapped to an elementary neural network operation;



FIG. 10A illustrates a division operation;



FIG. 10B is a computational graph illustrating one way in which the division operation of FIG. 10A can be mapped to elementary neural network operations;



FIG. 10C is a computational graph illustrating an alternative way in which the division operation of FIG. 10A can be mapped to elementary neural network operations;



FIG. 11A is a computational graph illustrating one way in which a softmax layer can be evaluated using a plurality of elementary neural network operations, according to an example;



FIG. 11B is a computational graph illustrating an alternative way in which a softmax layer can be evaluated using a plurality of elementary neural network operations, according to another example;



FIG. 12 is a computational graph illustrating a further alternative way in which a softmax layer can be evaluated using a plurality of elementary neural network operations, according to one special case;



FIG. 13 shows a computer system in which a data processing system is implemented; and



FIG. 14 shows an integrated circuit manufacturing system for generating an integrated circuit embodying a data processing system.





The accompanying drawings illustrate various examples. The skilled person will appreciate that the illustrated element boundaries (e.g., boxes, groups of boxes, or other shapes) in the drawings represent one example of the boundaries. It may be that in some examples, one element may be designed as multiple elements or that multiple elements may be designed as one element. Common reference numerals are used throughout the FIGs., where appropriate, to indicate similar features.


DETAILED DESCRIPTION

The following description is presented by way of example to enable a person skilled in the art to make and use the invention. The present invention is not limited to the embodiments described herein and various modifications to the disclosed embodiments will be apparent to those skilled in the art.


Embodiments will now be described by way of example only.


Faced with a desire to implement a softmax layer in a system using a neural network accelerator (NNA), one possibility would be to design a dedicated fixed-function hardware module that is specialised at evaluating softmax layers. This hardware module could then be included in the NNA, where it would take responsibility for evaluating any softmax layers, as needed.


Another alternative would be to evaluate softmax layers in general purpose hardware outside the NNA, such as a general purpose CPU or DSP.


Providing a dedicated fixed-function hardware module in an NNA, to handle the evaluation of softmax layers, may allow for an optimised, fast evaluation. However, it has the drawback that the dedicated fixed-function hardware module occupies additional area in the integrated circuit. Moreover, because the evaluation of softmax layers typically represents a small part of the workload of the NNA, the utilisation of the dedicated fixed-function hardware module will be low for most typical neural networks. In other words, the dedicated fixed-function softmax module will be inactive most of the time.


Meanwhile, evaluating softmax layers in general purpose hardware allows for flexibility, and avoids leaving large areas of the NNA underutilised; however, it is typically less efficient, because the hardware is less specialised.


The configurability of general purpose hardware incurs a cost in power and area because: (i) additional logic is required to route the data flexibly; (ii) computational elements cannot be as specialised, meaning that computational density is generally not as high as for fixed-function hardware; and (iii) it is harder to balance the bandwidth and compute requirements of the hardware. Dedicated hardware can be more efficient because it is designed such that it does not include any more functionality than is strictly necessary for the task at hand.


Additionally, when using general-purpose hardware that is external to the NNA, there is an overhead in transferring the necessary data from the NNA to the general-purpose hardware (for example, CPU). This typically involves the NNA writing the data to a memory, and the CPU reading the data from the memory, before evaluating the softmax layer. This is likely to slow down the evaluation of the layer, especially if—as is often the case—the speed of memory access dominates. Furthermore, CPU time is often at a premium due to the requirements of the operating system and other processes being run. Spending CPU time evaluating the softmax layer can cause these other processes to slow down and is an inefficient use of resources. The same is also true for GPUs and DSPs.


The performance penalty incurred by using an external CPU to evaluate the softmax layer might be mitigated when this layer is the final layer of the neural network. In this case, the output of the softmax layer does not need to be transferred back to the NNA for further processing. However, this still consumes host CPU time (potentially in considerable quantities, especially at high inference rates). Moreover, in some recent attention based neural networks, it is becoming more common to include softmax layers as intermediate layers within the neural network. This means that the output data of the softmax layer needs to be transferred back to the NNA for further processing. A softmax layer within a neural network may also have larger input and output tensors than a typical softmax layer at the output of the neural network. This increase in the size of the data increases the memory bandwidth required, and therefore increases the performance penalty for using an external CPU to evaluate the layer. Increasing the bandwidth used also has the effect of increasing power consumption.


Still another alternative would be to include one or more general programmable units, such as a CPU or digital signal processor (DSP), within the NNA itself. This would in one sense be a hybrid of the two possible solutions mentioned above. It would avoid the need to consume system bandwidth in order to hand over the evaluation of each softmax layer to an external general-purpose processor; however, it would have the disadvantages of increased hardware/software complexity, increased power consumption and greater integrated circuit area occupied.


It would be desirable to implement softmax layers within an NNA, but without the need to add a dedicated hardware unit, or additional general-purpose hardware, to the NNA architecture for this purpose. However, until now, it has not been apparent how a relatively complex softmax layer could be evaluated by the relatively limited set of operations that an exemplary NNA is adapted to perform. Unlike the operations performed by a CPU, the operations performed by an NNA are not designed to be a flexible or complete set of general purpose operations. Instead, each neural network operation is specialised to perform a particular computationally intensive neural network calculation quickly and efficiently. The trade-off is that an NNA has a very limited capacity to perform functions beyond this specialised set. For this reason, it is challenging to repurpose existing neural network operations to evaluate softmax layers.


Examples according to the present disclosure provide ways to implement a softmax layer in hardware, based on elementary neural network operations that are available on an exemplary NNA. The softmax layer can be viewed as a computational graph, as shown in FIG. 1A, and the individual operations in the graph can each be replaced with one or more operations in the NNA hardware. The graph containing these substituted operations can then be evaluated by the NNA.


As shown in FIG. 2, an exemplary hardware accelerator 200 (also referred to herein as a neural network accelerator or NNA) includes the following fixed-function hardware units:

    • A set of convolution engines 240, specialised at convolution operations;
    • An element-wise operations unit 285, specialised at performing the same operation to every pair of respective elements of two tensors of corresponding size;
    • An activation unit 255, specialised at applying an activation function (which may be selectable, configurable, or fully programmable) to every element of a tensor;
    • A local response normalisation (LRN) unit 265 (or normalisation unit, for short), specialised at performing neighbourhood-based normalisation operations; and
    • A pooling unit 275, specialised at performing pooling operations, such as max-pooling and min-pooling.


Examples of the present disclosure use elementary neural network operations, executed by these fixed-function hardware units, to implement a softmax layer. In the present implementation, the calculations are performed in fixed point arithmetic. Experiments have shown that the fixed point implementation is sufficiently accurate that it does not significantly degrade the overall accuracy of the exemplary neural networks tested.


A softmax layer may be constructed from the following operations:

    • A maximum operation;
    • A subtraction;
    • An exponential operation implementing the function ƒ(x)=ex;
    • A summation; and
    • A division.


For each of these operations, there may be more than one way that the operation can be restructured for execution on the hardware accelerator. The operations will be explained in turn in more detail below.



FIG. 1A is a computational graph illustrating how the operations available in the exemplary NNA can be used to implement a softmax layer. In this example, an exemplary input tensor x will be considered, the tensor having batch, height, width, and channel dimensions. In this example, it is assumed that the softmax layer is to be evaluated over the channel dimension of the input. It should be understood that the softmax layer could be evaluated over one or more other dimensions, and that it may be applied to tensors with any number of dimensions ordered in any way.


First, the input tensor x undergoes a maximum operation 110. This operation is performed over the dimension or dimensions in which the softmax layer is to be evaluated. In the current example of channel-wise softmax, this operation is performed along the channel dimension. Where the softmax layer is evaluated over a different dimension or dimensions, the maximum operation 110 would instead be performed along that different dimension or dimensions. The maximum operation 110 returns the largest positive value over the relevant dimension(s) within x, to produce a tensor of maximum values M. In subtraction operation 120, also referred to as the first subtraction, the tensor of maximum values M is subtracted from the respective elements of the tensor x. (This can be implemented using broadcasting, as discussed in further detail below). This subtraction operation 120 results in a negative-shifted tensor x−M. The negative-shifted tensor is input to an exponential operation 130. This calculation applies each element of the negative-shifted tensor as a power of Euler's number e. The exponential operation 130 results in a tensor of exponentiated values, referred to herein as the exponential tensor ex−m. The exponential tensor ex−M undergoes a summation 140. This summation sums all of the elements of the exponential tensor along the dimension or dimensions in which the softmax layer is to be evaluated (in the current example, the channel dimension), resulting in a tensor containing the sum of the exponentiated values Σex−M. In division operation 150, the exponentiated values are divided by their sum. This returns the output of the softmax layer:








e

x
-
M





e

x
-
M




.





FIG. 1B is a computational graph illustrating an example of how the operations available in the exemplary NNA can be used to implement the exponential operation 130. According to this example, the exponential operation 130 consists of the following operations:

    • A negation 132;
    • A sigmoid function 134;
    • A reciprocal operation 136; and
    • A second subtraction 138.


Continuing with the example of FIG. 1A, the input for the exponential operation 130 is the negative-shifted tensor x−M. This tensor undergoes a negation 132 to produce a negated tensor−(x−M). The negation 132 may be implemented in a variety of ways—for example, by subtracting the negative-shifted tensor from 0, or by subtracting the negative-shifted tensor from itself twice. The negated tensor is input to a sigmoid function 134, which determines a sigmoid value for each element of the negated tensor. The output of the sigmoid function 134 is a tensor of sigmoid negated values σ(−(x−M)). The tensor of sigmoid negated values undergoes a reciprocal operation 136, which determines the reciprocal of each of the sigmoid negated values. The sigmoid operation 136 returns a tensor of reciprocal sigmoid values







1

σ

(

-

(

x
-
M

)


)


.




Finally, the tensor of reciprocal sigmoid values undergoes a second subtraction 138, to subtract a constant (one) from each element of the tensor. This returns the exponential tensor








1

σ

(

-

(

x
-
M

)


)


-
1

,




which is identical to ex−M.


In general, this exemplary method of using the operations available in the exemplary NNA to perform the exponential operation 130 may be used either on its own to evaluate an exponential operation, or as part of an implementation of a softmax layer.



FIG. 2 illustrates an exemplary hardware accelerator 200 that is configured to evaluate a plurality of elementary neural network operations according to examples of the present disclosure. The hardware accelerator 200 comprises digital logic circuitry that is configured to receive data (including weights and input tensors) and commands for processing them. The hardware accelerator 200 comprises a memory interface 210, an input buffer controller 215, a command decoder 220, a coefficient buffer controller 225, a coefficient buffer 230, n input buffers 235, n convolution engines 240, n accumulators 245, an accumulation buffer 250, an activation unit 255, a local response normalize (LRN) unit 265, a shared buffer 270, a pooling unit 275, and an element-wise operations unit 285. The hardware accelerator 200 can be used to evaluate elementary neural network operations in order to implement a softmax layer or an exponential operation.


The memory interface 210 is configured to provide an interface between the hardware accelerator 200 and external memory 25. The external memory 25 may be considered as a separate module to the hardware accelerator 200. The command or configuration information may, for example, comprise information regarding weight and data size and format as well as their location in the external memory.


The memory interface 210 is configured to receive, from external memory 25, weights and data to be used in calculations within the neural network, as well as command information to control the operation of the hardware accelerator 200. The received weights (also referred to herein as coefficients) are passed to the coefficient buffer controller 225 and the received data is passed to the input buffer controller 215. The received commands are passed to the command decoder 220, which, in turn, is configured to decode the commands and subsequently issue control information to elements of the hardware accelerator, including the coefficient buffer controller 225 and input buffer controller 215 to control the manner in which the weight and input data is stored in the buffers.


The weights and input data received from external memory via memory interface 210 during a read of the external memory may form the weights and input data for only a portion of a single layer, all of the weights and input data to be used in processing a single layer, or may comprise the weights and input data for processing multiple layers. For example, the weights received from external memory may form the weights of a single layer and the input data received may form only a portion of the input data for a single layer (or vice versa). Any combination of data and weights across one or more layers may be received from external memory 25 in a single read from the memory (for example using a burst read).


In practice, the number of weights and data received in a single read from external memory 25 will depend upon the size of the coefficient buffer 230 and the input buffer 235. The weights are passed from the coefficient buffer controller 225 to the coefficient buffer 230 and the data received is passed from the input buffer controller 215 to a plurality of input buffers 235a-235n. The number of input buffers will depend upon the specific implementation of the accelerator 200 but may take any value. The input data is shared across all of the input buffers 235a-235n. The input buffers each form an effective bank such that the number of input buffers can be increased or decreased depending on the application.


The input buffers 235a-235n are connected to each of a plurality of multiplexers since each convolution engine 240a-240n requires access to all of the effective ‘banks’ of the input data. The multiplexers are each configured to select an output from one of the input buffers 235 and to pass the values output from the selected input buffer 235 to a respective convolution engine 240a-240n. In addition, weights from the coefficient buffer 230 are provided as a second input into each convolution engine 240a-240n. The convolution engines 240 are configured to perform a convolution calculation on the received input data using the weights received from the coefficient buffer 230. The resultant output of each convolution engine 240a-240n is provided as an input to a respective accumulator of a plurality of accumulators 245a-245n.


Each accumulator 245a-245n is connected to an accumulation buffer 250. The accumulation buffer 250 is configured to store accumulated results received from each accumulator 245a-245n. The accumulation buffer 250 is connected to the memory interface 210. As such, the accumulation buffer 250 is configured to send and receive data to and from external memory 25 via memory interface 210. Specifically, the accumulation buffer 250 is configured to be able to store and restore its values from the external memory 25 via memory interface 210, as will be described in more detail below. The accumulation buffer 250 is connected to the input of the accumulators 245a-245n and is configured to feed values back into the accumulators 245a-245n to enable accumulation calculations to take place.


The accumulation buffer 250 is configured to pass accumulated values to the activation unit 255 and/or the element-wise operations unit 285. The activation unit 255 is configured to perform at least one of a number of different activation functions. The activation unit 255 incorporates a lookup table (LUT), for storing an activation function, such as a sigmoid activation, to be applied to data input to the activation unit. The activation unit 255 is also operable to add/subtract a bias value to/from a tensor. This can be used to add a constant to the tensor or subtract a constant from the tensor.


The resultant value calculated by the activation unit 255 can be passed to be processed by the LRN unit 265 and/or the pooling unit 275 via the shared buffer 270. The LRN unit 265 is configured to perform a local response normalisation. This may be performed within a single plane of input data. Alternatively or in addition, the LRN operation may also be performed across planes.


A result stored in the shared buffer 270 is passed to the memory interface 210, which can either store the result in external memory 25 or pass the result back into the input buffers for further processing without having to first be passed out to external memory.


The shared buffer 270 is configured to buffer values from any one or more of the activation unit 255, the LRN unit 265, the pooling unit 275, and the element-wise operations unit 285 until all the values required to perform the next operation are available. In this way, the shared buffer 270 is used for efficiency of storage as it can hold values required in later operations without having to use external memory 25.


The element-wise operations unit 285 comprises circuitry configured to perform element-wise operations on tensors received from the accumulation buffer 250 and/or activation unit 255. The supported element-wise operations may include element-wise addition, subtraction, multiplication, division, and maximum (or minimum) of the respective elements of the tensors.


Element-wise operations are operations that are repeated for multiple elements of at least one tensor. The operations are typically repeated for all elements of the tensor. Two categories of element-wise operation may be considered: unary operations, having a single operand, and binary operations, having two operands. The element-wise operations unit 285 handles binary element-wise operations. Element-wise operations may also be performed by other components of the hardware accelerator. For example, the activation unit 255 may perform unary element-wise operations, by loading a desired function into the LUT and applying the function to every element of a tensor.


Whilst the hardware accelerator of FIG. 2 illustrates a particular order in which the units are arranged and thus how the processing of data flows through the hardware implementation, it will be appreciated that the specific calculations required and the order in which data is processed across layers may vary.


In some examples, the functions performed by the activation 255, LRN 265, pooling 275, and element-wise 285 units may all be performed. In other examples, only some of these functions may be performed and not necessarily in the order set out in the hardware accelerator 200. To achieve a configurable order of processing these functions, each of the activation 255, LRN 265, pooling 275 and element-wise 285 units may be configured to receive control signalling configuring the unit into a bypass mode in which the function is not performed and the input values are simply passed through the unit without change.


In some examples, the data of a particular layer may need to be processed first by the convolution engines 240a-n and then second according to the activation, LRN, pooling, and element-wise units 255, 265, 275, 285. In these examples, the outputs from the convolution engines 240a-n are passed via the accumulators 245a-n to the accumulation buffer 250 and are then passed to activation, LRN, pooling, and element-wise units 255, 265, 275, 285 for further processing. In other examples, the data may need to be processed differently. For example, data may need to be processed first according to the activation, LRN, pooling, and element-wise units 255, 265, 275, 285 and second according to the convolution engines 240a-n.


In these arrangements, data can be passed directly to the activation unit 255 via the accumulation buffer 250, where the accumulation buffer 250 has received the input data directly from the memory interface 210 which has received the data from external memory. In this way, the processing performed by convolution engines 240a-n and accumulator 245a-n is effectively skipped and the data can be passed directly to the activation 255, LRN 265, pooling 275, and element-wise 285 units. Then, once processing using activation, LRN, pooling, and element-wise units 255, 265, 275, 285 is completed, the resultant values can be passed into the input buffer controller 215 via the memory interface 210. In some arrangements, the resultant values can be first passed to external memory 25 via memory interface 210 and then retrieved from external memory 25 before use.


In other arrangements, the memory interface 210 may pass the resultant values to the input buffer controller 215 without passing the values to external memory 25. By avoiding the need to pass the values resulting from calculations using the activation, LRN, pooling, and element-wise unit 255, 265, 275, 285 to external memory 25, memory bandwidth is reduced and therefore the latency in processing the data is also reduced.


Advantageously, since the activation, LRN, pooling, and element-wise units 255, 265, 275, 285 are placed linearly, it is possible to perform these operations back-to-back without having to retrieve data from external memory 25. In some implementations, the order in which the activation, LRN, pooling, and element-wise units 255, 265, 275, 285 are connected may vary. For example, the activation, LRN, and pooling units 255, 265, 275 may be connected in reverse order such that the pooling unit is connected to the accumulation buffer 250 and the activation unit is connected to the memory interface 210.



FIG. 3 illustrates the structure of each of the convolution engines 240 in FIG. 2. The convolution engine 240 comprises a plurality of elements of multiply logic 242, each configured to multiply a weight by an input data element, and a plurality of elements of addition logic 244, configured in a tree structure to sum the outputs of the elements of multiply logic 242.



FIG. 4 is a block diagram of a data processing system 10 for implementing a softmax layer or an exponential operation in a hardware accelerator 200 (NNA), according to an example. The data processing system comprises the hardware accelerator 200; a controller 15; a memory 25; and a memory manipulation module (MMM) 40. At least the hardware accelerator 200, the memory 25, and the MMM 40 are connected by a data bus 30. The controller 15 is configured to receive a definition of at least one softmax neural network layer or a neural network layer comprising an exponential operation, and map the layer to a plurality of elementary neural network operations that can be performed natively by the hardware accelerator 200. The controller 15 is further configured to control the hardware accelerator 200 (and if necessary the MMM 40) to evaluate the softmax layer or the layer comprising the exponential operation by means of these elementary operations.


The hardware accelerator 200 is configured to evaluate the plurality of elementary neural network operations. The MMM 40 is configured to manipulate multidimensional data in memory in various ways, including transpose or permute operations that interchange different dimensions of the data. In some examples, the MMM 40 may be configured to transform data by embedding the channel dimension of the data in one or both of the width or height dimensions, or exchanging the channel dimension with one or both of these spatial dimensions. In alternative examples, the MMM may transpose or permute any other combination of the dimensions of the input data, including the batch dimension.



FIG. 5 is a block diagram of the MMM 40 used in FIG. 4. As mentioned already, the MMM 40 is coupled to the memory 25, via the bus 30. The MMM 40 comprises a memory reading block 420; an internal buffer 410; and a memory writing block 430. A control channel 440 is used to coordinate the operations performed by the memory reading block 420 and the memory writing block 430. Both the memory reading block 420 and the memory writing block 430 are coupled to the bus 30. An output of the memory reading block 420 is coupled to an input of the internal buffer 410. An input of the memory writing block 430 is coupled to an output of the internal buffer 410.


The memory reading block 420 reads data from the memory 25. The memory reading block 420 writes the data (that was read from the memory 25) to the internal buffer 410. The memory writing block 430 reads data from the internal buffer 410 and writes the data (that was read from the internal buffer 410) back to the external memory 25. By the combination of operations performed by the memory reading block 420 and the memory writing block 430, the data may be transformed in the ways previously described. The transformation may occur when moving the data from the memory 25 to the internal buffer 410, or it may occur when moving the data from the internal buffer 410 to the memory 25. In some cases, the transformation may occur in part between the memory 25 and the internal buffer 410, and in part between the internal buffer 410 and the memory 25.


Because the memory reading block 420 and the memory writing block 430 are provided as separate hardware blocks, they are able to operate in parallel. That is, the memory reading block 420 can perform steps 310 and 320 while the memory writing block 230 is performing steps 330 and 340 (the steps are explained in detail below with reference to FIG. 6A and 6B). The control channel 240 provides for communication between the memory reading block 220 and the memory writing block 230, to maintain synchronisation between the two blocks.



FIG. 6A is a flowchart illustrating a method performed by the data processing system 10 according an example of the present disclosure. In this example, the data processing system 10 implements an exponential operation.


In step 310, the controller 15 receives as an input a definition of a neural network layer involving an exponential operation. In step 320, the controller maps the layer to an equivalent computational graph comprising a plurality of elementary neural network operations. In step 330, the hardware accelerator 200 evaluates the plurality of elementary neural network operations, to produce the result of the exponential operation. In the present example, the mapping to the plurality of elementary operations is based on the computational graph of FIG. 1B, which re-casts the exponential operation in terms of a sigmoid function. This will be described in greater detail below.



FIG. 6B is a flowchart illustrating a method performed by the data processing system 10 according to another example of the present disclosure. In this example, the data processing system 10 implements a softmax layer. In step 311, the controller 15 receives as an input a definition of a softmax neural network layer. In step 321, the controller 15 maps the layer to an equivalent computational graph comprising a plurality of elementary neural network operations. In step 331, the hardware accelerator 200 evaluates the plurality of elementary neural network operations, to produce the output of the softmax layer. In the present example, the mapping to the plurality of elementary operations is based on the computational graph of FIG. 1A. This will now be described in greater detail.


The softmax layer and exponential operation are mapped to elementary neural network operations based on manipulation of the computational graphs of FIGS. 1A and 1B. It is convenient to consider each step in each computational graph separately, since there may be several ways to map each step in the graph. In general a particular implementation (consisting of a particular set of one or more elementary operations) can be chosen for each step independently of the others.


Two possible implementations of the maximum operation 110 will be explained with reference to FIGS. 7A, 7B, 7C, and 8. As was explained with reference to FIG. 1, and as shown again in FIGS. 7A and 8, the maximum operation 110 receives an input tensor and returns the maximum value of the elements over the channel dimension. The channel dimension is given as an example because softmax is most commonly applied over the channel dimension. However, it should be understood that the scope of the present disclosure is not limited to this example.


The maximum operation 110 can be implemented:


In the pooling unit 275; or


In the element-wise operations (EWO) unit 285.


These units may be assisted by transpose or permute operations performed, for example, in the memory manipulation module 40.



FIG. 7B illustrates an implementation of the maximum operation 110 using the EWO unit 285. An iterative sequence of pairwise maximum operations can be used. The input tensor is split 600 in two on the dimension on which we are computing softmax (the channel dimension in the present example), and the two halves are compared using an element-wise maximum operation 610. For each pair of elements compared, the higher (that is, maximum) of the two is output as the result of the element-wise maximum 610. The result of this operation is a tensor that is half the size of the original. This is itself split in two, and the two halves are compared using a further element-wise maximum operation 610. This process continues iteratively, halving the number of values in each iteration, until the overall maximum values over the channel dimension are found. If the tensor does not have a size that is a power of 2, along the dimension over which the maximum operation is to be applied, then padding may be necessary, to increase the size to the nearest power of 2. The tensor could be padded with zeros, in some examples. If the values in the original tensor are all negative, this will cause the maximum operation to instead return a maximum value of zero. Alternatively, for better conditioning of the softmax layer, the padding could be done with a very large negative value, or by copying one or more existing values in the original tensor. This would be less likely to affect the calculation of the maximum. (In the case of one or more copied values or by using the largest representable negative value, it would be guaranteed not to affect the calculation).



FIG. 7C illustrates the application of the iterative element-wise maximum approach to an exemplary input tensor—here a vector “x” 601, for simplicity. The input vector 601 has 4 channels, each containing a numerical value represented by x1, x2, x3 and x4. First, the vector 601 is split 600 into two sub-vectors 602, 603 each having two elements. Using an element-wise maximum operation 610, the first element of the first sub vector 602 is compared with the first element of the second sub-vector 603. Similarly, the second element of the sub-vector 602 is compared with the second element of the sub-vector 603. This comparison results in a vector 604. In the example of FIG. 7C, x1, x2, x3 and x4>x2; therefore, the vector 604 output by the first element-wise maximum operation consists of x1 and x4. The vector 604 is split 600 to produce a sub-vectors 605 and 606, which are again compared using the element-wise maximum operation 610. This returns the maximum element “M” of the input vector 601—which, in this example, happens to be x4. While this example used a vector having 4 elements, the process applies in the same fashion to vectors having more elements or to tensors with more dimensions. It can also be applied over dimensions other than the channel dimension.


An alternative to padding is to split the tensor into more than two sub-tensors, each sub-tensor having a size in the relevant dimension that is a power of 2. For example, a tensor with 5 channels may be split into two tensors with 2 channels each and a final tensor with 1 channel. The two tensors with 2 channels can be reduced by splitting and taking the element-wise maximum, as described above. The resulting 1-channel tensors can be compared to produce a tensor with 1 channel. Finally, this tensor can be compared with the remaining tensor with 1 channel, to return the maximum of the original tensor on the channel dimension. This process is illustrated by way of example in FIG. 7D. The exemplary input tensor, the vector “x” 611, differs from the input in FIG. 7C by the addition of a fifth channel, containing a numerical value x5. The first four channels are processed as illustrated in FIG. 7C. This is then followed by a final, additional step, in which the maximum over the first four channels, x4, is compared with the fifth channel, x5, in a further element-wise maximum operation 610. The result of this comparison is the overall maximum over the five channels. (In this example, as illustrated, the maximum happens still to be x4).


The splitting operation may be performed by the memory manipulation module 40, by reading data from one location and writing a first part of the data to a first location and a second part of the data to a second location. Alternatively, the splitting might not require a separate operation, and may instead be performed as part of the output of the preceding operation. In the example of FIG. 7B, the output of the element-wise maximum 610 may be split by writing a first part of the output to a first location in the memory 25 and a second part of the output to a second location in the memory 25.



FIG. 8 illustrates the implementation of the maximum operation 110 using the pooling unit 275. As mentioned at the outset above, in the present example softmax is applied over the channel dimension. Therefore, the maximum operation 110 is also applied over the channels. To facilitate implementing the maximum operation 110 in the pooling unit 275, a transpose or permute operation 510 can be applied to the input tensor before the maximum pooling operation 520 is performed by the pooling unit 275. This is done because, in the exemplary hardware accelerator, the pooling unit is specialised at pooling over spatial dimensions. In order to pool the channel elements of the input, the channel dimension is transposed with one of the spatial dimensions. (This can be done using the MMM 40). Then, the result of the maximum pooling operation 520 can be transformed back to the original dimensions of the input by another transpose or permute operation 512 that inverts the transpose or permute operation 510 to restore the original ordering of the dimensions. (Again, this can be done using the MMM 40). If softmax is being performed in the spatial dimensions (for example, the height and/or width dimensions) then these transpose operations might not be needed. Similarly, where the pooling unit 275 is designed to operate in the channel dimension, transpose operations might not be necessary. In some cases, the pooling unit 275 may have a maximum window size that is smaller than the size of the dimension(s) over which the maximum is to be calculated. If this arises, the max pooling can be iterated a number of times, in order to calculate the maximum over the larger set of values.


The subtractions 120, 138 and the negation 132 can be performed by the element-wise operations unit 285. The element-wise operations unit can perform a respective subtraction operation on each element of a tensor. Where a constant is subtracted—as in the subtraction 138—the subtraction may be performed either by the element-wise operations unit 285 or by the activation unit 255. Subtraction of a constant (for example, subtraction of 1) can be implemented in the activation unit by loading the function y=x−c into the LUT, where c is the constant to be subtracted. Subtraction of a constant can be implemented as an element-wise addition in the element-wise operations unit, by adding the negative of the constant (for example, adding −1). Similarly, the negation 132 could be performed either by the element-wise operations unit 285 (by subtracting the input tensor from a constant, 0), or by the activation unit 255 (by loading the function y=−x into the LUT).


In the present example, the negation 132 is performed by subtracting each element of the tensor from zero. It could also be performed by element-wise subtraction in other ways—for example, by subtracting the tensor from itself twice, or multiplying every element of the tensor by two and subtracting the result from the original tensor. Alternatively, the negation may be performed by changing the sign bit of each element of the tensor where a sign and magnitude representation of numbers is used. Where a two's complement representation is used, the negation may be performed by inverting all of the bits representing the number and then adding one.


The exponential operation 130 receives an input and raises e to the power of that input. For an input of x, the output of the exponential operation 130 is ex.


The exponential operation could be evaluated:


1. Directly in a lookup table (LUT), in the activation unit 255;


2. By means of a sigmoid function 134, reciprocal 136, negation 132 and subtraction 138 as shown in FIG. 1B; or


3. By means of a reciprocal sigmoid function, negation 132 and subtraction 138.


The first implementation is relatively straightforward, provided that the hardware and software of the hardware accelerator allows the LUT to be programmed with the exponential function. However, this might not always be possible. Therefore, the second implementation may be used as an alternative.


The second implementation makes use of the following identity:







e
x

=


1

σ

(

-
x

)


-
1





Where σ(−x) is the negative sigmoid function. Here, in common with most literature in the field of neural networks, we use the term “sigmoid” synonymously with “logistic function”. That is, the sigmoid (logistic) function is defined as:







σ

(
x
)

=

1

1
+

e

-
x








The negative sigmoid function is therefore:







σ

(

-
x

)

=

1

1
+

e
x







The second implementation uses elementary neural network operations to implement the steps shown in FIG. 1B. The negation 132 and subtraction 138 can be evaluated by the EWO unit 285, as explained above. The sigmoid function 134 can be evaluated by the activation unit 255, as a sigmoid activation. In other words, instead of loading the exponential function into the LUT, the sigmoid function is instead loaded and evaluated. Because the sigmoid is a common activation function, it is likely to be available natively in the activation unit 255. Thus, in this case, the exponential operation is implemented indirectly by means of a sigmoid activation (together with other elementary operations).


The reciprocal 136 of the value of σ(−x) can be evaluated in several ways, depending on the exact capabilities of the hardware accelerator 200. The options for evaluation of a reciprocal include:

    • A reciprocal lookup in the LUT of the activation unit 255
    • Using the LRN unit 265; and
    • An element-wise division, using the EWO unit 285.


      In the present example, the reciprocal function is performed using the LRN unit. Each of the three options will be described in greater detail below.


Referring once again to FIG. 1B, in principle, the sigmoid function 134 and the reciprocal 136 could be combined, if both are implemented by means of lookups in an LUT. Rather than carry out two lookups in two LUTs, the functions could be combined and a single lookup performed. That is, the LUT of the activation unit 255 could be programmed to contain a reciprocal sigmoid function








f

(
x
)

=

1

σ

(
x
)



.




Going one step runner, the negation 132 could also be subsumed into the LUT, so that it returns the result of the function








f

(
x
)

=

1

σ

(

-
x

)



.




In practice, however, it is likely that if the LUT were fully programmable in this way, it would be easier to simply program it with the exponential function.


The summation 140, shown in FIG. 9A, can be implemented by a 1−1 convolution with a kernel of ones, using the convolution engines 240. The convolution operation 570 is shown in FIG. 9B. Using the example of FIG. 1, consider the exponential tensor ex−M. This tensor has dimensions B×C×H×W, with B batches, C channels, H rows and W columns. To evaluate a softmax layer over the channel dimension, the elements of the exponential tensor must be summed over the channel dimension. In other words, elements sharing the same height, width and batch location but in different channels will be summed together. This summation 140 is performed by convolving 570 the input tensor with a kernel having dimensions 1×C×1×1, where the kernel has dimensions O×I×KH×KW, where I is the number of input channels, O is the number of output channels, KH is the kernel height and KW is the kernel width. Each element of the kernel has a value of one. The kernel is convolved 570 across the height, width and batch dimensions of the input tensor. The result of this process is a tensor that contains the summation of the elements of the exponential tensor across the channel dimension.


Where a softmax layer is evaluated over one or more spatial dimensions, a depth-wise convolution may be used, meaning that the kernel is applied to each channel separately. In this case, the kernel would have a size of one in the channel dimension and a size greater than one in the height and/or width dimensions. If the hardware accelerator is limited to a certain maximum kernel size, it may be necessary to iterate the convolution in order to capture all elements of the input tensor, in a similar manner to that described above for the max pooling operation. It should be understood that in other examples, the softmax layer may be evaluated over other combinations of dimensions, such as the channel dimension and one or more spatial dimensions. The convolution kernel will be adapted according to the relevant dimensions.


Alternatively, the summation 140 could be implemented by the EWO unit 285 using iterated pairwise addition operations. This approach is very similar to the element-wise maximum operation explained in relation to FIGS. 7B and 7C. The difference is that instead of implementing an element-wise maximum operation after each split, an element-wise addition operation is used. Each element of the sub vector produced in this operation is the sum of two respective elements of the vectors on which it operated. The split and addition processes are repeated until all the elements have been summed over the channel dimension. Similarly to the maximum operation of FIGS. 7B and 7C, it may be necessary to pad the tensor beforehand, so that its size in the relevant dimension is a power of 2 (that is, its size is 2P, where P is a positive integer). In this case, because the element-wise operation is addition, the tensor should be padded with zeros. As with the maximum operation, padding may be avoided by instead splitting the input tensor into more than two sub-tensors, each having a size in the relevant dimension that is a power of 2.


The reciprocal 136 can be implemented:


Using the LRN unit 265;


Using the activation unit 255, by loading a reciprocal function into an LUT of the activation unit; or


As an element-wise division, using the element-wise operations unit 285, by dividing a constant, 1, by the input values whose reciprocal is to be calculated.


If the LUT of the activation unit 255 is available, and is programmable, it can be programmed with a reciprocal function ƒ(x)=1/x.


The LRN unit 265 may be used, in particular, if the LUT is not available or if it is not programmable to implement arbitrary functions. The LRN unit 265 is designed to carry out the following LRN calculation:







b

i
,
x
,
y



=


a

i
,
x
,
y


/


(

k
+

α






j
=

max
(

0
,

i
-

n
2



)




min
(


N
-
1

,

i
+

n
2



)




(

a

j
,
x
,
y


)

2




)

β






By setting α=1, β=1, k=n=0, this function can be reduced to






b
i,x,yi,x,y/(αi,x,y)2


Which is identical to the desired reciprocal:






b
i,x,y=1/ai,x,y


Either of these two solutions can be used to evaluate reciprocals. Both ways of evaluating reciprocals can also be useful for evaluating division operations, as explained further below. Alternatively, as mentioned above, the reciprocal could itself be implemented by means of an element-wise division, in the element-wise operations unit 285 (assuming that element-wise division is supported).


In the evaluation of the exponential operation as shown in FIG. 1B, the reciprocal 136 (for example, implemented by the LRN unit 265) produces a reciprocal tensor







1

σ

(

-

(

x
-
M

)


)


,




which is passed to the subtraction operation 138 (for example, implemented by element-wise subtraction in the EWO unit 285).


In some examples, division 150 (reproduced in FIG. 10A) may be performed directly by means of an element-wise division operation, using the element-wise operations unit 285. However, some hardware accelerators 200 might not support element-wise division. For such eventualities, it is desirable to be able to implement the division in other ways.



FIGS. 10B and 10C show two alternative ways to implement the division 150 shown in FIG. 10A—in particular, if it cannot be performed directly by the EWO unit 285. Both of these approaches exploit the recognition that a division can be evaluated as a combination of a reciprocal operation and a multiplication. In both cases, the multiplication 580 can be performed by the EWO unit 285.



FIG. 10B illustrates the use of an LRN operation 552 to evaluate the reciprocal. Using this method, in the context of the example of FIG. 1A, the reciprocal of the tensor containing the sum of the exponentiated values Σex−M can be evaluated. The reciprocal tensor is passed to the EWO unit 285, where it is multiplied 580 with the exponential tensor ex−M, to return the output of the softmax layer.



FIG. 10C illustrates an alternative to the method of FIG. 10B, in which a reciprocal lookup 545 in the LUT of the activation unit 255 is used instead of the LRN 552 to implement the reciprocal. In some cases, if the activation unit 255 is programmable to implement arbitrary functions, such as the reciprocal function, it may be preferable to use the activation unit 255 to carry out a reciprocal lookup 545 (as shown in FIG. 100) instead of using the LRN unit 265 to perform an LRN operation 552 (as shown in FIG. 10B). A lookup may be faster and more energy efficient than an LRN operation once the reciprocal function has been loaded into the LUT.


While examples of the present disclosure have been described using an LUT lookup to approximate one or more of the exponential operation, the sigmoid function and the reciprocal function, this does not have to be the case. Other function approximation operations that do not use an LUT are possible, and may be used to approximate one or more of the exponential operation, the sigmoid function and the reciprocal function. One such example of an alternative type of function approximation is iterative refinement. For example, the exponential operation may be approximated iteratively by calculating the Taylor series expansion of ex.


It should be noted that several of the substitutions outlined above involve substitute operations that are equally as complex as, or more complex than, the operations replaced. This is true of the use of the LRN unit to perform the reciprocal, for example, as well as the implementation of the exponential operation by means of the sigmoid, reciprocal, and subtraction. However, the present inventors have recognised that such substitutions—which at first glance might seem far from optimal—are nevertheless often more attractive than the alternatives of (a) using a CPU or DSP to evaluate softmax layers or (b) implementing a bespoke hardware unit to evaluate softmax layers. This is because the substitutions allow the evaluation to take advantage of the considerable computational power of the dedicated hardware modules. The use of these dedicated modules, even in a relatively “inefficient” manner, can therefore still offer performance gains in terms of power and bandwidth consumption (for example), compared with the alternatives.



FIG. 11A illustrates one example of a full implementation of a softmax layer. In FIG. 11A, the various steps in the computational graphs of FIGS. 1A and 1B have been mapped to elementary neural network operations, in line with the principles described above.


The maximum 110 of FIG. 1A is evaluated by a transpose 510 (using the MMM 40), a max pooling 520 (using the pooling unit 275), and a further transpose 512 (using the MMM 40).


The subtraction 120 is evaluated by an element-wise subtraction 530 in the element-wise operations unit 285.


The exponential operation 130 has been replaced by the operations of FIG. 1B. In the example of FIG. 11A, the sigmoid function 134 is evaluated by a sigmoid activation 540, using a lookup in an LUT of the activation unit 255. The reciprocal 136 is evaluated by an LRN operation 550, using the LRN unit 265. The negation 132 is implemented by an element-wise subtraction 532 (subtracting each element from zero), using the element-wise operations unit 285. The subtraction 138 of the constant (1) is similarly evaluated using the element-wise operations unit 285. This could be done either by addition (of −1) or by subtraction (of +1). In the example illustrated in FIG. 11A, an element-wise addition of −1 is adopted.


The summation 140 is evaluated by a convolution 570, using one or more of the plurality of convolution engines 240.


The division 150 is evaluated by an LRN operation 552, using the LRN unit 265, and an element-wise multiplication 580, using the element-wise operations unit 285.


It should be understood that for each step shown in FIG. 1A and 1B, any of the described implementations of that step as elementary operations can be used.


In general, when performing element-wise operations where the inputs are tensors of different sizes (like the element-wise subtraction 530 and element-wise multiplication 580), broadcasting is used. The smaller tensor is “broadcast” across the larger tensor, to repeat similar calculations for all corresponding elements of the two tensors. In the element-wise subtraction 530, for example, the original input tensor has dimensions B×C×H×W. The result of the maximum operation 510, 520, 513 has reduced dimensionality B×1×H×W, because the maximum was calculated over the channel dimension. Broadcasting, performed by the element-wise operations unit 285, enables the maximum value in each channel to be subtracted from each individual value in that channel. Broadcasting could also be used—but is not required—for operations involving a tensor and a scalar, like the element-wise subtraction 532. As an alternative to element-wise broadcasting, these tensor-scalar operations may be implemented in the activation unit 255, which always applies an operation uniformly to all elements of the tensor. As explained above, this can be done by loading an appropriate function, such as y=x−c, into the LUT of the activation unit.



FIG. 11B illustrates the modularity and flexibility of the present approach. Comparing FIG. 11A with FIG. 11B, it can be seen that the LRN operation 550 used to evaluate the reciprocal 136 (as part of the exponential operation 130) has been replaced by a reciprocal LUT lookup 545 in FIG. 11B. This LUT lookup is performed using the activation unit 255. Meanwhile, the LRN 552 and multiplication 580, which were used to implement the division 150 in FIG. 11A have been replaced by an element-wise division 590 in FIG. 11B. This element-wise division 590 is performed by the element-wise operations unit 285.


When using an LUT as part of the evaluation of a softmax layer, whether as part of the exponential operation 130 or for the reciprocal 136, precision may be improved by restricting the range of values loaded into the LUT. Using the example of FIGS. 11A and 11B, in order to improve the output precision of the sigmoid LUT lookup 540, the LUT may only be loaded with sigmoid values that correspond to an input greater than or equal to zero. This is because, in this example, the input to the LUT is the negated tensor −(x−M). All values of the negated tensor are greater than or equal to zero, so there is no need to load the LUT with sigmoid values corresponding to negative inputs. Instead, the additional memory may be used to store the relevant sigmoid values to a higher precision. This restriction of the LUT output depends on the flexibility of the LUT. In some implementations, the LUT may only be able to provide outputs symmetric about zero—for example, where the LUT uses a two's complement representation of numbers. In this case, restricting the LUT to only contain sigmoid values for positive inputs would only confer a precision benefit where the negative two's complement numbers could be offset to also encode positive values.


In another example, an LUT loaded with exponential values may have its outputs limited in order to improve precision within a desired range. In the example of FIG. 1A, the input for the exponential operation is (x−M). All of the values of this input are negative or equal to zero, therefore the output range needs only to span [0,1]. In some implementations, the LUT may represent fixed point numbers in a two's complement representation. This will mean that the ranges of the inputs and outputs of the exponential LUT are symmetric about zero. In order to improve precision in the output range of interest in such implementations, the LUT output range may be restricted to [−1,1]. Output values greater than one can no longer be represented accurately, but this does not matter because these output values are never needed. The benefit of discarding this unwanted part of the output range is much greater precision in the range of interest.


The implementation of a special case of a softmax layer will now be described, with reference to FIG. 12. The inventors have recognised that, in the case that the input tensor x contains only two channels, referred to here as “a” and “b” (with any size in the height, width and batch dimensions), the evaluation of the softmax layer over the channel dimension can be simplified in the following way:







s

(

[

a
,
b

]

)

=


[






e
a



e
a

+

e
b



,










e
b



e
a

+

e
b





]

=





[






e

a
-
b




e

a
-
b


+

e

b
-
b




,



e

b
-
a




e

a
-
a


+

e

b
-
a






]

=







[




e

a
-
b




e

a
-
b


+
1


,



e

b
-
a



1
+

e

b
-
a





]








=

[


σ


(

a
-
b

)


,

σ


(

b
-
a

)



]










Accordingly, the evaluation of the softmax layer can be broken down into two steps:


The calculation of the differences, (a−b) and (b−a); and


The application of the sigmoid function to each difference.


The first difference, a−b, can be evaluated by convolving the input tensor with a filter [1, −1]. Similarly, the second difference, b−a, can be evaluated by convolving the input tensor with a filter [−1, 1]. These two operations can be carried out by a single convolution operation 571, with two input channels, and two filters (that is, two output channels), with dimensions 2×2×1×1. In other words, just a single call to a convolution routine can evaluate both operations together, using the convolution engines 240.


As an alternative, it will be apparent that each difference is the negative of the other:






a−b=−(b−a)


Therefore, a first difference could be formed (for example, by convolution or element-wise subtraction), and the second difference could be obtained by negating the first (for example, by changing the sign bit of each value). Nevertheless, in the present example, because of the optimised implementation of the convolution operation in the hardware accelerator, it has been found that using the convolution operation 571 is more efficient.


Having obtained the tensor containing the differences (a−b) and (b−a), a sigmoid activation 541 can be applied by means of a lookup in the LUT of the activation unit 255, as described above. This returns the output of the softmax layer, for this special case.


It will be understood that the examples described above are not limiting, and many variations are possible. For instance, although the examples above have focused on the case of a softmax layer evaluated over the channel dimension, a softmax layer could alternatively be evaluated over any other dimension or combination of dimensions, without limitation. The specific substitutions to map the layer to elementary neural network operations might vary, but the same principles (and same advantages) would apply.


In addition to the examples mentioned above, there may be other ways in which an exponential operation could be implemented in hardware. For example, an exponential operation could be implemented using the relationship ex=2kx, where k=log2e is a constant. This may be evaluated in two parts: firstly an element-wise multiply, to evaluate the product kx, followed by raising 2 to the power of this product. This latter step can be accomplished in two stages. The integer part of the power can be implemented by a bit-shift—for example, to raise 2 to the power of 3, a bit may be shifted to the left by three places. The non-integer part of the power—a number in the range (0,1)—can be implemented using an LUT with a further element-wise multiplication to combine this with the integer part of the power.


Alternatively, in some implementations, the hardware accelerator may natively support the operation 2z, where z is in general a non-integer value—for example by adding an additional fixed-function unit to handle this elementary operation, in the block diagram of FIG. 2. This would allow the exponential operation to be evaluated efficiently and could also be reused for calculations in other neural network layers.


Some optimisations may also be possible. For example, it may be noted that the computational graphs of FIGS. 11A, 11B and 12 each include two successive subtraction operations 530 and 532. The second subtraction 532 merely negates the result of the first subtraction, to form the negated tensor −(x−M). These two operations could be combined into a single subtraction operation, to be evaluated by a single element-wise subtraction (M−x) in the element-wise operations unit 285. Other optimisations could also be found, by examining the computational graph produced by the controller 15 in the mapping step 320, 321. In some embodiments, the mapping step may include the active steps of identifying at least two consecutive elementary neural network operations that can be combined; and combining these consecutive elementary neural network operations into a smaller number of elementary neural network operations.


In the example of FIG. 4, the data processing system 10 was constructed around the hardware accelerator 200—which, in those examples, was an NNA. However, the data processing system may instead be implemented partially or entirely within an NNA. For example, the hardware accelerator 200, the MMM 40, and the controller 15 may represent sub-components within an NNA.



FIG. 13 shows a computer system in which the data processing systems described herein may be implemented. The computer system comprises a CPU 902, an NNA 904, a memory 906 and other devices 914, such as a display 916, speakers 918 and a camera 919. A processing block 910 (corresponding to processing blocks 15, 40 and 200) is implemented on the NNA 904. In other examples, the processing block 910 may be implemented on the CPU 902. The components of the computer system can communicate with each other via a communications bus 920. A store 912 (corresponding to memory 25) is implemented as part of the memory 906.


While FIG. 13 illustrates one implementation of a neural network accelerator system, it will be understood that a similar block diagram could be drawn for a graphics processing system—for example, by replacing either the CPU 902 or the NNA 904 with a graphics processing unit (GPU), or by adding the GPU as an additional unit. In such cases, the processing block 910 can be implemented in the GPU.


The data processing system of FIG. 4 is shown as comprising a number of functional blocks. This is schematic only and is not intended to define a strict division between different logic elements of such entities. Each functional block may be provided in any suitable manner. It is to be understood that intermediate values described herein as being formed by a data processing system need not be physically generated by the data processing system at any point and may merely represent logical values which conveniently describe the processing performed by the data processing system between its input and output.


The data processing systems described herein may be embodied in hardware on an integrated circuit. The data processing systems described herein may be configured to perform any of the methods described herein. Generally, any of the functions, methods, techniques or components described above can be implemented in software, firmware, hardware (e.g., fixed logic circuitry), or any combination thereof. The terms “module,” “functionality,” “component”, “element”, “unit”, “block” and “logic” may be used herein to generally represent software, firmware, hardware, or any combination thereof. In the case of a software implementation, the module, functionality, component, element, unit, block or logic represents program code that performs the specified tasks when executed on a processor. The algorithms and methods described herein could be performed by one or more processors executing code that causes the processor(s) to perform the algorithms/methods. Examples of a computer-readable storage medium include a random-access memory (RAM), read-only memory (ROM), an optical disc, flash memory, hard disk memory, and other memory devices that may use magnetic, optical, and other techniques to store instructions or other data and that can be accessed by a machine.


The terms computer program code and computer readable instructions as used herein refer to any kind of executable code for processors, including code expressed in a machine language, an interpreted language or a scripting language. Executable code includes binary code, machine code, bytecode, code defining an integrated circuit (such as a hardware description language or netlist), and code expressed in a programming language code such as C, Java® or OpenCL. Executable code may be, for example, any kind of software, firmware, script, module or library which, when suitably executed, processed, interpreted, compiled, executed at a virtual machine or other software environment, cause a processor of the computer system at which the executable code is supported to perform the tasks specified by the code.


A processor, computer, or computer system may be any kind of device, machine or dedicated circuit, or collection or portion thereof, with processing capability such that it can execute instructions. A processor may be any kind of general purpose or dedicated processor, such as a CPU, GPU, NNA, System-on-chip, state machine, media processor, an application-specific integrated circuit (ASIC), a programmable logic array, a field-programmable gate array (FPGA), or the like. A computer or computer system may comprise one or more processors.


It is also intended to encompass software which defines a configuration of hardware as described herein, such as HDL (hardware description language) software, as is used for designing integrated circuits, or for configuring programmable chips, to carry out desired functions. That is, there may be provided a computer readable storage medium having encoded thereon computer readable program code in the form of an integrated circuit definition dataset that when processed (i.e. run) in an integrated circuit manufacturing system configures the system to manufacture a data processing system configured to perform any of the methods described herein, or to manufacture a data processing system comprising any apparatus described herein. An integrated circuit definition dataset may be, for example, an integrated circuit description.


Therefore, there may be provided a method of manufacturing, at an integrated circuit manufacturing system, a data processing system as described herein. Furthermore, there may be provided an integrated circuit definition dataset that, when processed in an integrated circuit manufacturing system, causes the method of manufacturing a data processing system to be performed.


An integrated circuit definition dataset may be in the form of computer code, for example as a netlist, code for configuring a programmable chip, as a hardware description language defining hardware suitable for manufacture in an integrated circuit at any level, including as register transfer level (RTL) code, as high-level circuit representations such as Verilog or VHDL, and as low-level circuit representations such as OASIS (RTM) and GDSII. Higher level representations which logically define hardware suitable for manufacture in an integrated circuit (such as RTL) may be processed at a computer system configured for generating a manufacturing definition of an integrated circuit in the context of a software environment comprising definitions of circuit elements and rules for combining those elements in order to generate the manufacturing definition of an integrated circuit so defined by the representation. As is typically the case with software executing at a computer system so as to define a machine, one or more intermediate user steps (e.g. providing commands, variables etc.) may be required in order for a computer system configured for generating a manufacturing definition of an integrated circuit to execute code defining an integrated circuit so as to generate the manufacturing definition of that integrated circuit.


An example of processing an integrated circuit definition dataset at an integrated circuit manufacturing system so as to configure the system to manufacture a data processing system will now be described with respect to FIG. 14.



FIG. 14 shows an example of an integrated circuit (IC) manufacturing system 1002 which is configured to manufacture a data processing system as described in any of the examples herein. In particular, the IC manufacturing system 1002 comprises a layout processing system 1004 and an integrated circuit generation system 1006. The IC manufacturing system 1002 is configured to receive an IC definition dataset (e.g. defining a data processing system as described in any of the examples herein), process the IC definition dataset, and generate an IC according to the IC definition dataset (e.g. which embodies a data processing system as described in any of the examples herein). The processing of the IC definition dataset configures the IC manufacturing system 1002 to manufacture an integrated circuit embodying a data processing system as described in any of the examples herein.


The layout processing system 1004 is configured to receive and process the IC definition dataset to determine a circuit layout. Methods of determining a circuit layout from an IC definition dataset are known in the art, and for example may involve synthesising RTL code to determine a gate level representation of a circuit to be generated, e.g. in terms of logical components (e.g. NAND, NOR, AND, OR, MUX and FLIP-FLOP components). A circuit layout can be determined from the gate level representation of the circuit by determining positional information for the logical components. This may be done automatically or with user involvement in order to optimise the circuit layout. When the layout processing system 1004 has determined the circuit layout it may output a circuit layout definition to the IC generation system 1006. A circuit layout definition may be, for example, a circuit layout description.


The IC generation system 1006 generates an IC according to the circuit layout definition, as is known in the art. For example, the IC generation system 1006 may implement a semiconductor device fabrication process to generate the IC, which may involve a multiple-step sequence of photo lithographic and chemical processing steps during which electronic circuits are gradually created on a wafer made of semiconducting material. The circuit layout definition may be in the form of a mask which can be used in a lithographic process for generating an IC according to the circuit definition. Alternatively, the circuit layout definition provided to the IC generation system 1006 may be in the form of computer-readable code which the IC generation system 1006 can use to form a suitable mask for use in generating an IC.


The different processes performed by the IC manufacturing system 1002 may be implemented all in one location, e.g. by one party. Alternatively, the IC manufacturing system 1002 may be a distributed system such that some of the processes may be performed at different locations, and may be performed by different parties. For example, some of the stages of: (i) synthesising RTL code representing the IC definition dataset to form a gate level representation of a circuit to be generated, (ii) generating a circuit layout based on the gate level representation, (iii) forming a mask in accordance with the circuit layout, and (iv) fabricating an integrated circuit using the mask, may be performed in different locations and/or by different parties.


In other examples, processing of the integrated circuit definition dataset at an integrated circuit manufacturing system may configure the system to manufacture a data processing system without the IC definition dataset being processed so as to determine a circuit layout. For instance, an integrated circuit definition dataset may define the configuration of a reconfigurable processor, such as an FPGA, and the processing of that dataset may configure an IC manufacturing system to generate a reconfigurable processor having that defined configuration (e.g. by loading configuration data to the FPGA).


In some embodiments, an integrated circuit manufacturing definition dataset, when processed in an integrated circuit manufacturing system, may cause an integrated circuit manufacturing system to generate a device as described herein. For example, the configuration of an integrated circuit manufacturing system in the manner described above with respect to FIG. 14 by an integrated circuit manufacturing definition dataset may cause a device as described herein to be manufactured.


In some examples, an integrated circuit definition dataset could include software which runs on hardware defined at the dataset or in combination with hardware defined at the dataset. In the example shown in FIG. 14, the IC generation system may further be configured by an integrated circuit definition dataset to, on manufacturing an integrated circuit, load firmware onto that integrated circuit in accordance with program code defined at the integrated circuit definition dataset or otherwise provide program code with the integrated circuit for use with the integrated circuit.


The implementation of concepts set forth in this application in devices, apparatus, modules, and/or systems (as well as in methods implemented herein) may give rise to performance improvements when compared with known implementations. The performance improvements may include one or more of increased computational performance, reduced latency, increased throughput, and/or reduced power consumption. During manufacture of such devices, apparatus, modules, and systems (e.g. in integrated circuits) performance improvements can be traded-off against the physical implementation, thereby improving the method of manufacture. For example, a performance improvement may be traded against layout area, thereby matching the performance of a known implementation but using less silicon. This may be done, for example, by reusing functional blocks in a serialised fashion or sharing functional blocks between elements of the devices, apparatus, modules and/or systems. Conversely, concepts set forth in this application that give rise to improvements in the physical implementation of the devices, apparatus, modules, and systems (such as reduced silicon area) may be traded for improved performance. This may be done, for example, by manufacturing multiple instances of a module within a predefined area budget.


The applicant hereby discloses in isolation each individual feature described herein and any combination of two or more such features, to the extent that such features or combinations are capable of being carried out based on the present specification as a whole in the light of the common general knowledge of a person skilled in the art, irrespective of whether such features or combinations of features solve any problems disclosed herein. In view of the foregoing description it will be evident to a person skilled in the art that various modifications may be made within the scope of the invention.

Claims
  • 1. A method of implementing an exponential operation in a hardware accelerator comprising fixed-function circuitry configured to perform a set of available elementary neural network operations, the method comprising: receiving a definition of at least one neural network layer comprising the exponential operation;mapping the neural network layer to a representation comprising a plurality of elementary neural network operations from the set of available elementary neural network operations; andevaluating the plurality of elementary neural network operations,wherein each of the plurality of elementary neural network operations is selected from the list consisting of:an element-wise negation or subtraction operation;an element-wise addition operation;an element-wise division operation;an element-wise bit-shifting operation;an element-wise operation of the form ƒ(z)=2z, where z is in general a non-integer value;an element-wise multiplication operation;a first lookup in a first Lookup table (LUT), wherein the first LUT comprises a sigmoid function;a second lookup in a second LUT, wherein the second LUT comprises a reciprocal function;a third lookup in a third LUT, wherein the third LUT comprises a reciprocal of a sigmoid function;a fourth lookup in a fourth LUT, wherein the fourth LUT comprises a function ƒ(z)=2z, where z is a value in the range anda local response normalisation.
  • 2. The method of claim 1, wherein the plurality of elementary neural network operations implements: a negation, applied to input values, to produce negated input values;a sigmoid function, applied to the negated input values, to produce sigmoid negated values;a reciprocal operation, applied to the sigmoid negated values, to produce reciprocal sigmoid values; andan addition or subtraction, applied to the reciprocal sigmoid values, to subtract a constant from the reciprocal sigmoid values and thereby produce output values of the exponential operation.
  • 3. The method of claim 2, wherein the negation is evaluated by an element-wise subtraction operation, using an element-wise operations unit of the hardware accelerator.
  • 4. The method of claim 2, wherein the sigmoid function is evaluated by a first lookup, using an activation unit of the hardware accelerator.
  • 5. The method of claim 2, wherein the reciprocal operation is evaluated by one of: a second lookup, using an activation unit of the hardware accelerator;a local response normalisation, using an LRN unit of the hardware accelerator; andan element-wise division, using an element-wise operations unit of the hardware accelerator.
  • 6. The method of claim 2, wherein the addition or subtraction is evaluated by an element-wise addition or element-wise subtraction, using an activation unit of the hardware accelerator.
  • 7. A method of implementing a softmax layer in a hardware accelerator comprising fixed-function circuitry configured to perform a set of available elementary neural network operations, the method comprising: receiving a definition of at least one softmax neural network layer;mapping the softmax neural network layer to a representation comprising a plurality of elementary neural network operations from the set of available elementary neural network operations; andevaluating the plurality of elementary neural network operations,wherein each of the plurality of elementary neural network operations is selected from the list consisting of:a transpose or permute operation;a max pooling operation;an element-wise maximum operation;an element-wise subtraction operation;an element-wise negation operation;an element-wise addition operation;an element-wise division operation;an element-wise multiplication operation;an element-wise bit-shifting operation;an element-wise operation ƒ(z)=2z, where z is in general a non-integer value;a convolution operation;a function approximation operation; anda local response normalisation.
  • 8. The method of claim 7, wherein the plurality of elementary neural network operations includes at least one function approximation operation, wherein the function approximation operation is implemented as a lookup in an LUT, the LUT optionally comprising one of: a sigmoid function;a reciprocal function;a reciprocal of a sigmoid function;the function ƒ(z)=2z, where z is a value in the range (0,1) andan exponential function.
  • 9. The method of claim 7, wherein the plurality of elementary neural network operations implements: a maximum operation, applied to input values, to obtain the maximum among the input values;a first subtraction, subtracting the maximum from each of the input values, to produce negative-shifted input values;an exponential operation, applied to the negative-shifted input values, to produce exponentiated values;a summation, applied to the exponentiated values, to produce a sum of the exponentiated values; anda division, dividing each of the exponentiated values by the sum of the exponentiated values.
  • 10. The method of claim 9, wherein the exponential operation is mapped to a subset of the plurality of elementary neural network operations, wherein said subset implements: a negation, applied to the negative-shifted input values, to produce negated input values;a sigmoid function, applied to the negated input values, to produce sigmoid negated values;a first reciprocal operation, applied to the sigmoid negated values, to produce reciprocal sigmoid values; andan addition or a second subtraction, applied to the reciprocal sigmoid values, to subtract a constant from the reciprocal sigmoid values and thereby produce output values of the exponential operation.
  • 11. The method of claim 10, wherein the first reciprocal operation is evaluated by one of: a lookup, using an activation unit of the hardware accelerator;a local response normalisation, using an LRN unit of the hardware accelerator; andan element-wise division, using an element-wise operations unit of the hardware accelerator.
  • 12. The method of claim 7, wherein the softmax layer is to be applied to input data comprising a first element and a second element, and wherein the plurality of elementary neural network operations implements: at least one subtraction, to obtain at least one difference between the first element and the second element; anda sigmoid function, applied to the at least one obtained difference, to produce an output of the softmax layer.
  • 13. The method of claim 7, wherein mapping the neural network layer to the representation comprising the plurality of elementary neural network operations comprises: identifying at least two consecutive elementary neural network operations that can be combined; andcombining the at least two consecutive elementary neural network operations into a smaller number of elementary neural network operations.
  • 14. A data processing system for implementing an exponential operation, the system comprising: a hardware accelerator, comprising fixed-function circuitry configured to perform a set of available elementary neural network operations; anda controller, configured to: receive a definition of at least one neural network layer comprising the exponential operation; andmap the neural network layer to a representation comprising a plurality of elementary neural network operations from the set of available elementary neural network operations,wherein the hardware accelerator is configured to evaluate the plurality of elementary neural network operations, andwherein each of the plurality of elementary neural network operations is selected from the list consisting of:an element-wise negation or subtraction operation;an element-wise addition operation;an element-wise division operation;an element-wise bit-shifting operation;an element-wise operation of the form ƒ(z)=2z, where z is in general a non-integer value;an element-wise multiplication operation;a first lookup in a first LUT, wherein the first LUT comprises a sigmoid function;a second lookup in a second LUT, wherein the second LUT comprises a reciprocal function;a third lookup in a third LUT, wherein the third LUT comprises a reciprocal of a sigmoid function;a fourth lookup in a fourth LUT, wherein the fourth LUT comprises a function ƒ(z)=2z, where z is a value in the range (0,1); anda local response normalisation.
  • 15. A data processing system for implementing a softmax layer, the system comprising: a hardware accelerator, comprising fixed-function circuitry configured to perform a set of available elementary neural network operations; anda controller, configured to: receive a definition of at least one softmax neural network layer; andmap the softmax neural network layer to a representation comprising a plurality of elementary neural network operations from the set of available elementary neural network operations,wherein the hardware accelerator is configured to evaluate the plurality of elementary neural network operations, andwherein each of the plurality of elementary neural network operations is selected from the list consisting of:a transpose or permute operation;a max pooling operation;an element-wise maximum operation;an element-wise subtraction operation;an element-wise negation operation;an element-wise addition operation;an element-wise division operation;an element-wise multiplication operation;an element-wise bit-shifting operation;an element-wise operation ƒ(z)=2z, where z is in general a non-integer value;a convolution operation;a function approximation operation; anda local response normalisation.
  • 16. The data processing system of claim 14, wherein the hardware accelerator comprises any one of, or any combination of two or more of: an activation unit, comprising an LUT;a local response normalisation unit, configured to perform a local response normalisation;an element-wise operations unit, configured to apply a selected operation to every pair of respective elements of two tensor of identical size;one or more convolution engines, configured to perform convolution operations; anda pooling unit, configured to perform pooling operations, including max pooling.
  • 17. The data processing system of claim 16, wherein the hardware accelerator comprises the local response normalisation unit, wherein one or more of the plurality of elementary neural network operations implements a reciprocal operation, and wherein the local response normalisation unit is configured to evaluate the reciprocal operation.
  • 18. A method of manufacturing, using an integrated circuit manufacturing system, a data processing system as claimed in claim 14, the method comprising: processing, using a layout processing system, a computer readable dataset description of the data processing system so as to generate a circuit layout description of an integrated circuit embodying the data processing system; andmanufacturing, using an integrated circuit generation system, the data processing system according to the circuit layout description.
  • 19. A non-transitory computer readable storage medium having stored thereon a computer readable dataset description of a data processing system as claimed in claim 14 that, when processed in an integrated circuit manufacturing system, causes the integrated circuit manufacturing system to manufacture an integrated circuit embodying the data processing system.
  • 20. An integrated circuit manufacturing system comprising: a non-transitory computer readable storage medium having stored thereon a computer readable dataset description of a data processing system as claimed in claim 14;a layout processing system configured to process the computer readable description so as to generate a circuit layout description of an integrated circuit embodying the data processing system; andan integrated circuit generation system configured to manufacture the data processing system according to the circuit layout description.
Priority Claims (1)
Number Date Country Kind
2102728.9 Feb 2021 GB national