TECHNICAL FIELD
[0001] The present disclosure relates to the field of information processing technology, and specifically relates to a computation device and a computation method.
BACKGROUND
[0002] With the continuous development of information technology and the increasing demand, there are increasing requirements for information timeliness. Currently, the terminal acquires and processes information based on a general purpose processor.
[0003] In practice, it has been found that the way in which the general purpose processor runs a software program to process information is limited by the operating speed of the general purpose processor. Specifically, in the case that the general purpose processor has a large load, the information processing efficiency is low and the delay is large. For a computation model of information processing, such as a training model, the computation amount of the training operations is large, such that it will cost a long time for the general purpose processor to complete the training operations, and the efficiency of the training operations is low.
SUMMARY
[0004] A computation device and a computation method are provided according to examples of the present disclosure, which may improve the processing speed of operations and the efficiency.
[0005] In a first aspect, there is provided a computation device. The computation device may be configured to perform a machine learning computation, and may include a controller unit, an operation unit, and a conversion unit. The operation unit may include a primary processing circuit and a plurality of secondary processing circuits.
[0006] The controller unit may be configured to acquire first input data and a computation instruction, to parse the computation instruction to obtain at least one of a data conversion instruction and at least one operation instruction, where the data conversion instruction may include an opcode field and an opcode. The opcode may be configured to indicate information of a function of the data conversion instruction. The opcode field may include information of a decimal point position, a flag bit indicating a data type of the first input data, and an identifier of data type conversion. The controller unit may be further configured to transmit the opcode and the opcode field of the data conversion instruction and the first input data to the conversion unit, and to transmit a plurality of operation instructions to the operation unit.
[0007] The conversion unit may be configured to convert the first input data into second input data according to the opcode and the opcode field of the data conversion instruction, where the second input data is fixedpoint data, and to transmit the second input data to the operation unit.
[0008] The operation unit may be configured to perform operations on the second input data according to the plurality of operation instructions to obtain a computation result of the computation instruction.
[0009] In an example, the machine learning computation may include an artificial neural network operation. The first input data may include an input neuron and a weight. The computation result is an output neuron.
[0010] In an example, the operation unit may include the primary processing circuit and the plurality of secondary processing circuits.
[0011] The primary processing circuit may be configured to perform preprocessing on the second input data and to transmit data and the plurality of operation instructions between the plurality of secondary processing circuits and the primary processing circuit.
[0012] The plurality of secondary processing circuits may be configured to perform an intermediate operation to obtain a plurality of intermediate results according to the second input data and the plurality of operation instructions transmitted from the primary processing circuit, and to transmit the plurality of intermediate results to the primary processing circuit.
[0013] The primary processing circuit may be further configured to perform postprocessing on the plurality of intermediate results to obtain the computation result of the computation instruction.
[0014] In an example, the computation device may further include a storage unit and a direct memory access (DMA) unit;
the storage unit may include any combination of a register and a cache;
the cache may include a scratch pad cache and may be configured to store the first input data; and
the register may be configured to store scalar data in the first input data.
[0015] In an example, the controller unit may include an instruction cache unit, an instruction processing unit, and a storage queue unit.
[0016] The instruction cache unit may be configured to store the computation instruction associated with the artificial neural network operation.
[0017] The instruction processing unit may be configured to parse the computation instruction to obtain the data conversion instruction and the plurality of operation instructions, and to parse the data conversion instruction to obtain the opcode and the opcode field of the data conversion instruction.
[0018] The storage queue unit may be configured to store an instruction queue. The instruction queue may include a plurality of operation instructions or computation instructions, where the plurality of operation instructions or computation instructions is to be executed in a sequence.
[0019] In an example, the controller unit may further include a dependency relationship processing unit.
[0020] The dependency relationship processing unit may be configured to determine whether there exists an associated relationship between a first operation instruction and a zeroth operation instruction before the first operation instruction, to cache the first operation instruction in the instruction cache unit based on a determination that there exists an associated relationship between the first operation instruction and the zeroth operation instruction, and to extract the first operation instruction from the instruction cache unit to the operation unit if an execution of the zeroth operation instruction is completed;
[0021] Where the determining whether there exists an associated relationship between a first operation instruction and a zeroth operation instruction before the first operation instruction by the dependency relationship processing unit may include: extracting a first storage address interval of data required in the first operation instruction according to the first operation instruction, extracting a zeroth storage address interval of data required in the zeroth operation instruction according to the zeroth operation instruction, determining that there exists an associated relationship between the first operation instruction and the zeroth operation instruction, if an overlapped region exists between the first storage address interval and the zeroth storage address interval, and determining that there does not exist an associated relationship between the first operation instruction and the zeroth operation instruction, if no overlapped region exists between the first storage address interval and the zeroth storage address interval.
[0022] In an example, if the first input data is fixedpoint data, the operation unit may further include a derivation unit.
[0023] The derivation unit may be configured to derive a decimal point position of at least one intermediate result according to the decimal point position of the first input data, where the one or more intermediate results are obtained according to the first input data.
[0024] In an example, the operation unit may further include a data cache unit.
[0025] The data cache unit may be configured to cache one or more intermediate results.
[0026] In an example, the operation unit may include a tree module. The tree module may include a root port coupled with the primary processing circuit and a plurality of branch ports, and each of the plurality of branch ports may be coupled with one of the plurality of secondary processing circuits.
[0027] The tree module may be configured to forward data blocks, weights, and the plurality of operation instructions transmitted among the primary processing circuit and the plurality of secondary processing circuits.
[0028] In an example, the operation unit may further include a branch processing circuit.
[0029] The primary processing circuit may be configured to determine that the input neurons are broadcast data and the weights are distribution data, to divide the distribution data into a plurality of data blocks, and to transmit at least one of the plurality of data blocks, the broadcast data, and at least one of the plurality of operation instructions to the branch processing circuit.
[0030] The branch processing circuit may be configured to forward the data blocks, the broadcast data, and the plurality of operation instructions transmitted among the primary processing circuit and the plurality of secondary processing circuits.
[0031] The plurality of secondary processing circuits may be configured to perform operations on the data blocks received and the broadcast data received according to the plurality of operation instructions to obtain a plurality of intermediate results, and to transmit the plurality of intermediate results to the branch processing circuit.
[0032] The primary processing circuit may be further configured to perform postprocessing on the plurality of intermediate results received from the branch processing circuit to obtain a computation result of the computation instruction, and to send the computation result of the computation instruction to the controller unit.
[0033] In an example, the operation unit may include one primary processing circuit and multiple secondary processing circuits.
[0034] In an example, the plurality of secondary processing circuits may be distributed in an array. Each secondary processing circuit may be coupled with adjacent other secondary processing circuits. The primary processing circuit may be coupled with K secondary processing circuits of the plurality of secondary processing circuits. The K secondary processing circuits may include n secondary processing circuits in the first row, n secondary processing circuits in the m
^{th} row, and m secondary processing circuits in the first column.
[0035] The K secondary processing circuits may be configured to forward data and instructions transmitted among the primary processing circuit and the plurality of secondary processing circuits.
[0036] The primary processing circuit may be further configured to determine that the input neurons are broadcast data and the weights are distribution data, to divide the distribution data into a plurality of data blocks, and to transmit at least one of the plurality of data blocks and at least one of the plurality of operation instructions to the K secondary processing circuits.
[0037] The K secondary processing circuits may be configured to convert the data transmitted among the primary processing circuit and the plurality of secondary processing circuits.
[0038] The plurality of secondary processing circuits may be configured to perform operations on the data blocks received according to the plurality of operation instructions to obtain a plurality of intermediate results, and to transmit the plurality of intermediate results to the K secondary processing circuits.
[0039] The primary processing circuit may be configured to process the plurality of intermediate results received from the K secondary processing circuits to obtain the computation result of the computation instruction, and to send the computation result of the computation instruction to the controller unit.
[0040] In an example, the primary processing circuit may be configured to perform a combined ranking processing on the plurality of intermediate results received from the plurality of processing circuits to obtain the computation result of the computation instruction. Alternatively, the primary processing circuit may be configured to perform a combined ranking processing and an activation processing on the plurality of intermediate results received from the plurality of processing circuits to obtain the computation result of the computation instruction.
[0041] In an example, the primary processing circuit may include one or any combination of an activation processing circuit and an addition processing circuit.
[0042] The activation processing circuit may be configured to perform an activation operation on data in the primary processing circuit.
[0043] The addition processing circuit may be configured to perform an addition operation or an accumulation operation.
[0044] In an example, the plurality of secondary processing circuits may include multiplication processing circuits configured to perform multiplication operations on the data blocks received to obtain product results.
[0045] In an example, the plurality of secondary processing circuits may include accumulation processing circuits configured to perform accumulation operations on the product results to obtain the plurality of intermediate results.
[0046] In an example, the tree module is an ntree structure and the n is an integer greater than or equal to two.
[0047] In an example, the controller unit may be further configured to determine a decimal point position of the first input data and a bit width of the fixedpoint data prior to acquiring the first input data and the computation instruction. The bit width of fixedpoint data is a bit width of the first input data converted into fixedpoint data.
[0048] The operation unit may be further configured to initialize a decimal point position of the first input data and adjust a decimal point position of the first input data.
[0049] In an example, the operation unit may be configured to initialize the decimal point position of the first input data as follows.
[0050] The decimal point position of the first input data may be initialized according to a maximum absolute value of the first input data.
[0051] Alternatively, the decimal point position of the first input data may be initialized according to a minimum absolute value of the first input data.
[0052] Alternatively, the decimal point position of the first input data may be initialized according to a relationship between different data types in the first input data.
[0053] Alternatively, the decimal point position of the first input data may be initialized according to an empirical value constant.
[0054] In an example, the operation unit may be configured to initialize the decimal point position of the first input data according to the maximum absolute value of the first input data.
[0055] As an implementation, the operation unit may be configured to initialize the decimal point position of the first input data according to a first preset formula and the maximum absolute value of the first input data.
[0056] The preset first formula is
s_{a} = ┌log
_{2} a_{max}
bitnum + 1┐. The
s_{a} represents the decimal point position of the first input data. The
a_{max} represents the maximum absolute value of the first input data. The
bitnum represents the bit width of the fixedpoint data converted from the first input data.
[0057] In an example, a maximum absolute value of the first input data may include a maximum absolute value acquired by data category, a maximum absolute value acquired by layer and data category, and a maximum absolute value acquired by layer, data category, and group.
[0058] In an example, the operation unit may initialize the decimal point position of the first input data according to the minimum absolute value of the first input data.
[0059] In one implementation, the operation unit may initialize the decimal point position of the first input data according to a second preset formula and the minimum absolute value of the first input data.
[0060] The second preset formula is
s_{a} = └log 2(
a_{min})┘. The
s_{a} represents the decimal point position of the first input data. The
a_{min} is the minimum absolute value of the first input data. The
bitnum represents the bit width of the fixedpoint data converted from the first input data.
[0061] In an example, a minimum absolute value of the first input data may include a minimum absolute value acquired by data category, a minimum absolute value acquired by layer and data category, and a minimum absolute value acquired by layer, data category, and group.
[0062] In an example, the operation unit may be configured to initialize the decimal point position of the first input data according to the relationship between different data types in the first input data.
[0063] In one implementation, the operation unit may be configured to determine the decimal point position
of the data type
b^{(1)} of the first layer according to the decimal point position
of the data type
a^{(l)} of any layer (such as the first layer) of the multilayer network model with a formula of
[0064] The
a^{(l)} and
b^{(l)} are input neurons X
^{(l)}, output neurons
Y^{(l)}, weights
W^{(l)}, input neuron derivatives ∇
_{X}^{(l)}, output neuron derivatives ∇
_{Y}^{(l)}, or weight derivatives ∇
_{W}^{(l)}. The
a^{(l)} is inconsistent with
b^{(l)}. The
α_{b} and
β_{b} are integer constants.
[0065] In an example, the computation device may be configured to adjust the decimal point position of the first input data as follows.
[0066] The decimal point position may be adjusted upwardly by a single step according to the maximum absolute value of the first input data. The decimal point position may be adjusted upwardly step by step according to the maximum absolute value of the first input data. The decimal point position may be adjusted upwardly by a single step according to the first input data distribution. The decimal point position may be adjusted upwardly step by step according to the first input data distribution. The decimal point position may be adjusted downwardly according to the absolute value of the first input date.
[0067] In a second aspect, there is provided a method for performing machine learning computations. The method may include the following:
obtaining input data and a computation instruction;
parsing the computation instruction to obtain a data conversion instruction and a plurality of operation instructions, in which the data conversion instruction may include an opcode field and an opcode, where the opcode may be configured to indicate information of a function of the data conversion instruction, and the opcode field may include information of a decimal point position, a flag bit indicating a data type of the first input data, and a data type conversion;
converting the first input data into second input data according to the data conversion instruction, and the second input data is fixedpoint data; and
performing operations on the second input data according to the plurality of operation instructions to obtain a computation result of the computation instruction.
[0068] In an example, the machine learning computation may include an artificial neural network operation. The first input data may include an input neuron and a weight. The computation result is an output neuron.
[0069] In an example, the converting the first input data into second input data according to the data conversion instruction may include the following:
parsing the computation instruction to obtain information of the decimal point position, in which the flag bit indicates a data type of the first input data, and the data type conversion;
determining the data type of the first input data according to the flag bit which indicates the data type of the first input data; and
converting the first input data into the second input data according to the decimal point position and the data type conversion, and the data type of the first input data is inconsistent with that of the second input data.
[0070] In an example, if the first input data and the second input data are both fixedpoint data, the decimal point position of the first input data is inconsistent with that of the second input data.
[0071] In an example, if the first input data is fixedpoint data, the method may further include the following:
deriving the decimal point position of at least one intermediate result according to the decimal point position of the first input data, where the at least one intermediate result is obtained according to the first input data.
[0072] In an example, the method may further include the following:
determining the decimal point position of the first input data and a bit width of the fixedpoint data prior to acquiring the first input data and the computation instruction. The bit width of fixedpoint data is a bit width of the first input data converted into fixedpoint data; and
initializing the decimal point position of the first input data and adjusting the decimal point position of the first input data.
[0073] In an example, the initializing the decimal point position of the first input data may include:
initializing the decimal point position of the first input data according to a maximum absolute value of the first input data; or
initializing the decimal point position of the first input data according to a minimum absolute value of the first input data; or
initializing the decimal point position of the first input data according to a relationship between different data types in the first input data; or
initializing the decimal point position of the first input data according to an empirical value constant.
[0074] In an example, the initializing decimal point position of the first input data according to the maximum absolute value of the first input data may include:
initializing the decimal point position of the first input data according to a first preset formula and the maximum absolute value of the first input data.
[0075] The preset first formula is
s_{a} = ┌log
_{2} a_{max} 
bitnum +1┐. The
s_{a} represents the decimal point position of the first input data. The
a_{max} represents the maximum absolute value of the first input data. The
bitnum represents the bit width of the fixedpoint data converted from the first input data.
[0076] In an example, the maximum absolute value of the first input data may include a maximum absolute value acquired by data category. Alternatively, the maximum absolute value of the first input data may include a maximum absolute value acquired by layer and data category, or a maximum absolute value acquired by layer, data category, and group.
[0077] In an example, the initializing the decimal point position of the first input data according to the maximum absolute value of the first input data may include:
initializing the decimal point position of the first input data according to a second preset formula and the maximum absolute value of the first input data.
[0078] The second preset formula is
s_{a} = └log 2(
a_{min})┘. The
s_{a} represents the decimal point position of the first input data. The
a_{min} is the minimum absolute value of the first input data. The
bitnum represents the bit width of the fixedpoint data converted from the first input data.
[0079] In an example, a minimum absolute value of the first input data may include a minimum absolute value acquired by data category, a minimum absolute value acquired by layer and data category, or a minimum absolute value acquired by layer, data category, and group.
[0080] In an example, the initializing the decimal point position of the first input data according to the relationship between different data types in the first input data may include:
the determining the decimal point position
of the data type
b^{(1)} of the first layer according to the decimal point position
of the data type
a^{(l)} of any layer (such as the first layer) of the multilayer network model with a formula of
[0081] The
a^{(l)} and
b^{(l)} are input neurons
X^{(l)}, output neurons
Y^{(l)}, weights
W^{(l)}, input neuron derivatives ∇
_{X}^{(l)}, output neuron derivatives ∇
_{Y}^{(l)}, or weight derivatives ∇
_{W}^{(l)}. The
a^{(l)} is inconsistent with
b^{(l)}. The
α_{b} and
β_{b} are integer constants.
[0082] In an example, the adjusting the decimal point position of the first input data includes:
adjusting the decimal point position upwardly by a single step according to the maximum absolute value of the first input data; or
adjusting the decimal point position upwardly step by step according to the maximum absolute value of the first input data; or
adjusting the decimal point position upwardly by a single step according to the first input data distribution; or
adjusting the decimal point position upwardly step by step according to the first input data distribution; or
adjusting the decimal point position downwardly according to the absolute value of the first input date.
[0083] In a third aspect, a machine learning operation device is provided. The machine learning operation device may include at least one computation device of the first aspect. The at least one computation device may be configured to obtain data to be processed and control information from other processing devices, to perform specified machine learning computations, and to transmit an execution result to the other processing devices through I/O interfaces.
[0084] If the machine learning operation device includes a plurality of the computation devices, the plurality of computation devices may be configured to couple and transmit data with each other through a specific structure.
[0085] The plurality of computation devices may be configured to interconnect and to transmit data through a peripheral component interconnect express (PCIE) bus to support largerscale machine learning computations, to share the same one control system or have respective control systems, to share the same one memory or have respective memories, and to deploy an interconnection manner of any arbitrary interconnection topology.
[0086] In a fourth aspect, a combination processing device is provided. The combination processing device may include the machine learning operation device of the third aspect, universal interconnection interfaces, and other processing devices. The machine learning operation device may be configured to interact with the other processing devices to jointly perform userspecified computing operations. The combination processing device may further include a storage device. The storage device may be configured to couple with the machine learning operation device and the other processing devices for storing data of the machine learning operation device and the other processing devices
[0087] In a fifth aspect, a neural network chip is provided. The neural network chip may include one of the machine learning operation device of the first aspect, the machine learning operation device of the third aspect, and the combination processing device of the fourth aspect.
[0088] In a sixth aspect, a neural network chip package structure is provided. The neural network chip package structure may include the neural network chip of the fifth aspect.
[0089] In a seventh aspect, a board is provided. The board may include a storage device, an interface device, a control device, and the neural network chip of the fifth aspect.
[0090] The neural network chip is respectively coupled with the storage device, the control device, and the interface device.
[0091] The storage device may be configured to store data.
[0092] The interface device may be configured to implement data transmission between the neural network chip and external devices.
[0093] The control device may be configured to monitor a status of the neural network chip.
[0094] Furthermore, the storage device may include a plurality of groups of storage units, each group of the plurality of groups of the storage units is coupled with the neural network chip through a bus, and the storage unit being a double data rate (DDR) synchronous dynamic random access memory (SDRAM).
[0095] The neural network chip may include a DDR controller for controlling data transmission and data storage of each of the storage units.
[0096] The interface device may include standard PCIE interfaces.
[0097] In an eighth aspect, an electronic device is provided. The electronic device may include one of the neural network chip of the fifth aspect, the neural network chip package structure of the sixth aspect, and the board of the seventh aspect.
[0098] In examples of the present disclosure, the electronic device may include data processing devices, robots, computers, printers, smayners, tablets, smart terminals, mobile phones, driving recorders, navigators, sensors, cameras, servers, cloud servers, cameras, cameras, projectors, watches, headphones, mobile storage, wearable devices, vehicles, household appliances, and/or medical devices.
[0099] The vehicle may include an aircraft, a ship, and/or a car. The household appliance may include a television, an air conditioner, a microwave oven, a refrigerator, a rice cooker, a humidifier, a washing machine, an electric lamp, a gas stove, a range hood. The medical device may include a nuclear magnetic resonance instrument, a Bultrasound, and/or an electrocardiograph.
[0100] In the examples of the present disclosure, the computation device may include an operation unit, a controller unit, and a conversion unit. The controller unit may be configured to extract a computation instruction from a storage unit, and to parse the computation instruction to obtain at least one of a data conversion instruction and at least one operation instruction, and to transmit the data conversion instruction, at least one operation instruction, and first input data to the operation unit. The operation unit may be configured to convert the first input data into the second input data represented by fixedpoint data according to the data conversion instruction, and to perform operations on the second input data according to the at least one operation instruction to obtain a computation result of the computation instruction. In the examples of the present disclosure, the first data involved in machine learning computations is represented by fixedpoint data, thereby improving the processing speed and processing efficiency of training operations.
BRIEF DESCRIPTION OF THE DRAWINGS
[0101] To describe the technical solutions in the examples of the present disclosure more clearly, the following briefly introduces the accompanying drawings required for describing the examples. Apparently, the accompanying drawings in the following description illustrate some examples of the present disclosure. Those of ordinary skill in the art may also obtain other drawings based on these accompanying drawings without creative efforts.
FIG. 1 is a schematic diagram of a data structure of fixedpoint data according to an example of the present disclosure;
FIG. 2 is a schematic diagram of another data structure of fixedpoint data according to an example of the present disclosure;
FIG. 2A is a schematic diagram of yet another data structure of fixedpoint data according to an example of the present disclosure;
FIG. 2B is a schematic diagram of a still another data structure of fixedpoint data according to an example of the present disclosure;
FIG. 3 is a schematic structural diagram of a computation device according to an example of the present disclosure;
FIG. 3A is a schematic structural diagram of another computation device according to an example of the present disclosure;
FIG. 3B is a schematic structural diagram of yet another computation device according to an example of the present disclosure;
FIG. 3C is a schematic structural diagram of still another computation device according to an example of the present disclosure;
FIG. 3D is a schematic structural diagram of a primary processing circuit according to an example of the present disclosure;
FIG. 3E is a schematic structural diagram of still another computation device according to an example of the present disclosure;
FIG. 3F is a schematic structural diagram of a tree module according to an example of the present disclosure;
FIG. 3G is a schematic structural diagram of still another computation device according to an example of the present disclosure;
FIG. 3H is a schematic structural diagram of still another computation device according to an example of the present disclosure;
FIG. 4 is a flow chart of a forward operation of a singlelayer artificial neural network according to an example of the present disclosure;
FIG. 5 is a flow chart of a forward and reverse training of a neural network according to an example of the present disclosure;
FIG. 6 is a structural diagram of a combined processing device according to an example of the present disclosure;
FIG. 6A is a schematic structural diagram of still yet another computation device according to an example of the present disclosure;
FIG. 7 is a structural diagram of another combined processing device according to an example of the present disclosure;
FIG. 8 is a schematic structural diagram of a board according to an example of the present disclosure;
FIG. 9 is a schematic flow chart of a computation method according to an example of the present disclosure;
FIG. 10 is a schematic flow chart of a process for determining and adjusting a decimal point position of data according to an example of the present disclosure;
FIG. 11 is a schematic structural diagram of a distributed system according to an example of the present disclosure;
FIG. 12 is a schematic structural diagram of another distributed system according to an example of the present disclosure.
DETAILED DESCRIPTION OF ILLUSTRATED EXAMPLES
[0102] Technical solutions in the examples of the present disclosure will be described clearly and completely hereinafter with reference to the accompanying drawings in the examples of the present disclosure. Apparently, the described examples are merely some rather than all examples of the present disclosure. All other examples obtained by those of ordinary skill in the art based on the examples of the present disclosure without creative efforts shall fall within the protection scope of the present disclosure.
[0103] The terms such as "first", "second", "third", and "fourth" used in the specification, the claims, and the accompanying drawings of the present disclosure are used for distinguishing between different objects rather than describing a particular order. The terms "include" and "comprise" as well as variations thereof are intended to cover nonexclusive inclusion. For example, a process, method, system, product, device, or apparatus including a series of steps or units is not limited to the listed steps or units, it may optionally include other steps or units that are not listed; alternatively, other steps or units inherent to the process, method, product, or device may be included either.
[0104] The term "example" or "implementation" referred to herein means that a particular feature, structure, or feature described in conjunction with the example may be contained in at least one example of the present disclosure. The phrase appearing in various places in the specification does not necessarily refer to the same example, nor does it refer to an independent or alternative example that is mutually exclusive with other examples. It is expressly and implicitly understood by those skilled in the art that an example described herein may be combined with other examples.
[0105] Examples of the present disclosure provide a data type. The data type may include an adjustment factor. The adjustment factor may be configured to indicate a value range and precision of the data type.
[0106] The adjustment factor may include a first scaling factor. Optionally, the adjustment factor may further include a second scaling factor. The first scaling factor may be configured to indicate the precision of the data type, and the second scaling factor may be configured to adjust the value range of the data type.
[0107] Optionally, the first scaling factor may be 2
^{m}, 8
^{m}, 10
^{m}, 2, 3, 6, 9, 10, 2
^{m}, 8
^{m}, 10
^{m}, or other values.
[0108] In an example, the first scaling factor may be configured to adjust a decimal point position. For example, an input data INB1=INA1
^{∗}2
^{m} may be obtained by shifting the decimal point position of an input data INA1 expressed in binary to the right by m bits, that is, the input data INB1 is 2
^{m} times greater than the input data INA1. For another example, an input data INB2=INA2/10
^{n} may be obtained by shifting the decimal point position of an input data INA2 expressed in decimal to the left by n bits, that is, the input data INB2 is 10
^{n} times less than the input data INA2, and m and n are integers.
[0109] Optionally, the second scaling factor may be 2, 8, 10, 16, or other values.
[0110] For example, the value range of the data type corresponding to the input data is 8
^{15}8
^{16}. In the process of performing operations, if an operation result obtained is greater than the maximum value corresponding to the value range of the data type corresponding to the input data, the value range of the data type is multiplied by a second scaling factor (for example, 8) of the data type to obtain a new value range of 8
^{14}8
^{17}. If the operation result obtained is smaller than the minimum value corresponding to the value range of the data type corresponding to the input data, divide the value range of the data type by the second scaling factor (for example, 8) of the data type to obtain a new value range of 8
^{16}8
^{15}.
[0111] Scaling factors may be applied to any format of data (such as floating point data and discrete data), so as to adjust the size and precision of the data.
[0112] It should be noted that the decimal point position mentioned in the specification of the present disclosure may be adjusted by the aboveidentified first scaling factor, which will not be described herein.
[0113] The structure of fixedpoint data is described as follows. FIG. 1 is a schematic diagram of a data structure of the fixedpoint data according to an example of the present disclosure. As illustrated in FIG. 1, signed fixedpoint data is provided. The signed fixedpoint data occupies X bits, which may be referred to as Xbit fixedpoint data. The Xbit fixedpoint data may include a 1bit sign bit, an Mbit integer bit, and an Nbit decimal bit, where X1=M+N. For unsigned fixedpoint data, only an integer bit of M bits and a decimal bit of N bits are included, that is, X=M+N.
[0114] Compared with a 32bit floating point data representation, the shortbit fixedpoint data representation adopted by the present disclosure occupies fewer bits. In addition, for data of the same layer of the same type in a network model (such as all convolution kernels, input neurons, or offset data of the first convolutional layer), the shortbit fixedpoint data representation adopted by the present disclosure may be further provided with a flag bit for recording the decimal point position of the fixedpoint data, where the flag bit represents a point location. In this way, the value of the abovementioned flag bit may be adjusted according to the distribution of the input data, thereby achieving the adjustment of the precision and the representable range of the fixedpoint data.
[0115] For example, a floating point number 68.6875 may be converted to signed 16bit fixedpoint data with a decimal point position of five, where the integer part of the floating point number occupies 10 bits, the fractional part of the floating point number occupies 5 bits, and the sign bit of the floating point number occupies 1 bit. As illustrated in FIG. 2, a conversion unit may be configured to convert the abovementioned floating point number 68.6875 into signed 16bit fixedpoint data of 0000010010010110.
[0116] In an example, the abovementioned fixedpoint data may also be represented in the manner illustrated in FIG. 2A. As illustrated in FIG. 2A, "bitnum" represents the bit number occupied by the fixedpoint data, "s" represents the decimal point position, and "2s" represents the precision of the fixedpoint data. The first bit is a sign bit that indicates the data is positive or negative. For example, if the sign bit is zero, it indicates that the fixedpoint data is a positive number; if the sign bit is one, it indicates that the fixedpoint data is a negative number. The value of the fixedpoint data ranges from "neg" to "pos", where
pos = (2
^{bitnum1}1)
^{∗}2
^{s}, and
neg = (2
^{bitnum1}1)
^{∗}2
^{s}, wherein the abovementioned
bitnum may be any positive integer. The abovementioned s may be any integer not less than
s_min.
[0117] In an example, the abovementioned
bitnum may be 8, 16, 24, 32, 64, or other values. Further, the abovementioned
s_min is 64.
[0118] In an example, the abovementioned
bitnum may be 8, 16, 24, 32, 64, or other values. The abovementioned s may be any integer not less than
s_min. Further, the abovementioned
s_min is 64.
[0119] In an example, a plurality of fixedpoint representations may be adopted for data having a larger value, as illustrated in FIG. 2B. Referring to FIG. 2B, the data having a larger value is represented by a combination of three kinds of fixedpoint data, that is, the fixedpoint data may include fixedpoint data 1, fixedpoint data 2, and fixedpoint data 3. The bit width of the fixedpoint data 1 is
bitnum1, the decimal point position of the fixedpoint data 1 is
s1; the bit width of the fixedpoint data 2 is
bitnum2, and the decimal point position of the fixedpoint data 2 is
s2; the bit width of the fixedpoint data 3 is
bitnum3, and the decimal point position of the fixedpoint data 3 is
s3, where
bitnum2  2 =
s11,
bitnum3  2 =
s21. The range represented by the three fixedpoint data is [
neg,pos], where
pos = (2
^{bitnum1}1)
^{∗}2
^{s},
neg = (2
^{bitnum1}1)
^{∗}2
^{s}.
[0120] First, a computation device adopted in the present disclosure will be introduced. Referring to FIG. 3, the computation device is provided. The computation device may include a controller unit 11, an operation unit 12, and a conversion unit 13, where the controller unit 11 is coupled with the operation unit 12, and the conversion unit 13 is coupled with the controller unit 11 and the operation unit 12.
[0121] In an example, a controller unit 11 may be configured to acquire first input data and a computation instruction.
[0122] In an example, the first input data may be machine learning data. Further, the machine learning data may include input neurons and weights. Output neurons are final output data or intermediate data.
[0123] In an example, the first input data and the computation instruction may be acquired via a data input and output unit. The data input and output unit may specifically include one or more data I/O interfaces or I/O pins.
[0124] The abovementioned computation instruction may include, but is not limited to, a forward operation instruction, a reverse training instruction, other neural network operation instructions (such as a convolution operation instruction), and the like. The examples of the present disclosure do not limit the specific expression of the abovementioned computation instruction.
[0125] In an example, according to the technical solution provided by the present disclosure, the operation unit 12 may be configured as a onemaster multislave structure. For the forward operation instruction, data may be divided according to the forward operation instruction. In this way, multiple secondary processing circuits 102 may perform parallel operations on data with a large amount of computation, thereby increasing the operation speed, saving computation time, and further reducing power consumption. As illustrated in FIG. 3A, the operation unit 12 may include a primary processing circuit 101 and the multiple secondary processing circuits 102.
[0126] The primary processing circuit 101 may be configured to perform preprocessing on the second input data and to transmit data and the multiple operation instructions between the multiple secondary processing circuits 102 and the primary processing circuit 101.
[0127] The multiple secondary processing circuits 102 may be configured to perform intermediate operations to obtain multiple intermediate results according to the second input data and the multiple operation instructions transmitted from the primary processing circuit 101, and to transmit the multiple intermediate results to the primary processing circuit 101.
[0128] The primary processing circuit 101 may be further configured to perform postprocessing on the multiple intermediate results to obtain the computation result of the computation instruction.
[0129] In an example, the machine learning computations may include deep learning operations (that is, artificial neural network operations). Machine learning data (that is, the first input data) may include input neurons and weights. Output neurons include the computation result or the multiple intermediate results of the computation instruction. The deep learning operations are described as an example, but it should be understood that it is not limited to the deep learning operations.
[0130] In an example, the computation device may further include a storage unit 10 and a direct memory access (DMA) unit 50, where the storage unit 10 may include one or any combination of a register and a cache. Specifically, the cache may be configured to store the computation instruction. The register 201 may be configured to store the first input data and scalar data. The first input data may include the input neurons, the weights, and the output neurons.
[0131] The cache 202 may be a scratch pad cache.
[0132] The DMA unit 50 may be configured to read or store data from the storage unit 10.
[0133] In an example, the controller unit 11 may include an instruction cache unit 110, an instruction processing unit 111, and a storage queue unit 113.
[0134] The instruction cache unit 110 may be configured to store the computation instruction associated with artificial neural network operations.
[0135] The instruction processing unit 111 may be configured to parse the computation instruction to obtain the data conversion instruction and the multiple operation instructions, and to parse the data conversion instruction to obtain the opcode and the opcode field of the data conversion instruction.
[0136] The storage queue unit 113 may be configured to store an instruction queue, the instruction queue may include the multiple operation instructions or the computation instruction to be executed in a sequence.
[0137] For example, in an optional technical solution, the primary processing circuit 101 may also include a control unit, which may include a primary instruction processing unit for decoding instructions into microinstructions. Of course, in another example, the secondary processing circuit 102 may also include another control unit, which may include a secondary instruction processing unit for receiving and processing the microinstructions. The microinstructions may be at a next stage of the instructions, and the microinstruction may be obtained by splitting or decoding the instructions, and may be further decoded into control signals of each component, each unit or each processing circuit.
[0138] In an example, the structure of the computation instruction may be shown as in Table 1 below.
Table 1
Opcode 
Register or Immediate 
Register/Immediate data 
...... 
[0139] The ellipsis in the above table indicates that multiple registers or immediate data may be included.
[0140] In another example of the present disclosure, the computation instruction may include at least one opcode field and one opcode. The computation instruction may include neural network operation instructions. The neural network operation instructions are described as an example, as illustrated in Table 2, where the register number 0, the register number 1, the register number 2, the register number 3, and the register number 4 may be opcode fields. Each of the register number 0, the register number 1, the register number 2, the register number 3, and register number 4 may correspond to one or more registers.
Table 2
Opcode  Register number 0  Register number 1  Register number 2  Register number 3  Register number 4 
COMPUTE 
Starting address of the input data 
Length of the input data 
Starting address of the weight 
Length of the weight 
Address of activation function interpolation table 
IO 
Address of external data memory 
Data length 
Address of internal data memory 


NOP 





JUMP 
Destination address 




MOVE 
Input address 
Data size 
Output address 


[0141] The abovementioned registers may be offchip memories. Of course, in practice, the abovementioned registers may also be onchip memories for storing data, and the data may be ndimensional data, where n is an integer greater than or equal to one. For example, if n=1, the data is a onedimensional data (that is, a vector). For another example, if n=2, the data is a twodimensional data (that is, a matrix). If n=3 or more, the data is a multidimensional tensor.
[0142] In an example, the controller unit 11 may further include a dependency relationship processing unit 112. If the multiple operation instructions are provided, the dependency relationship processing unit 112 may be configured to determine whether there exists an associated relationship between a first operation instruction and a zeroth operation instruction before the first operation instruction, to cache the first operation instruction in the instruction cache unit 110 based on a determination that there exists an associated relationship between the first operation instruction and the zeroth operation instruction, and to extract the first operation instruction from the instruction cache unit 110 to the operation unit, if an execution of the zeroth operation instruction is completed.
[0143] The dependency relationship processing unit 112 configured to determine whether there exists an associated relationship between a first operation instruction and a zeroth operation instruction before the first operation instruction may be configured to extract a first storage address interval of data required (such as a matrix) in the first operation instruction according to the first operation instruction, to extract a zeroth storage address interval of matrix required in the zeroth operation instruction according to the zeroth operation instruction, to determine that there exists an associated relationship between the first operation instruction and the zeroth operation instruction, if an overlapped region exists between the first storage address interval and the zeroth storage address interval, and to determine that there does not exist an associated relationship between the first operation instruction and the zeroth operation instruction, if no overlapped region exists between the first storage address interval and the zeroth storage address interval.
[0144] In an example, as illustrated in FIG. 3B, the operation unit 12 may include a primary processing circuit 101, multiple secondary processing circuits 102, and multiple branch processing circuits 103.
[0145] The primary processing circuit 101 may be configured to determine that the input neurons are broadcast data and the weights are distribution data, to divide the distribution data into multiple data blocks, and to transmit at least one of the multiple data blocks, the broadcast data, and at least one of the multiple operation instructions to the branch processing circuits 103.
[0146] The multiple branch processing circuits 103 may be configured to forward the data blocks, the broadcast data, and the multiple operation instructions transmitted among the primary processing circuit 101 and the multiple secondary processing circuits 102.
[0147] The multiple secondary processing circuits 102 may be configured to perform operations on the data blocks received and the broadcast data received according to the multiple operation instructions to obtain multiple intermediate results, and to transmit the multiple intermediate results to the plurality of branch processing circuits 103.
[0148] The primary processing circuit 101 may be further configured to perform postprocessing on the multiple intermediate results received from the branch processing circuits 103 to obtain a computation result of the computation instruction, and to send the computation result of the computation instruction to the controller unit 11.
[0149] In another example of the present disclosure, as illustrated in FIG. 3C, the operation unit 12 may include a primary processing circuit 101 and multiple secondary processing circuits 102. The multiple secondary processing circuits 102 are distributed in an array. Each secondary processing circuit 102 is coupled with adjacent other secondary processing circuits 102. The primary processing circuit 101 is coupled with K secondary processing circuits 102 of the plurality of secondary processing circuits 102. The K secondary processing circuits 102 may include n secondary processing circuits 102 in the first row, n secondary processing circuits 102 in the m
^{th} row, and m secondary processing circuits 102 in the first column. It should be noted that the K secondary processing circuits 102 as illustrated in FIG. 3C include only the n secondary processing circuits 102 in the first row, the n secondary processing circuits 102 in the m
^{th} row, and the m secondary processing circuits 102 in the first column. That is, the K secondary processing circuits 102 of the multiple secondary processing circuits 102 are directly coupled with the primary processing circuit 101.
[0150] The K secondary processing circuits 102 may be configured to forward data and instructions transmitted among the primary processing circuit 101 and the multiple secondary processing circuits 102.
[0151] The primary processing circuit 101 may be further configured to determine that the input neurons are broadcast data, the weights are distribution data, to divide the distribution data into multiple data blocks, and to transmit at least one of the multiple data blocks and at least one of the multiple operation instructions to the K secondary processing circuits 102.
[0152] The K secondary processing circuits 102 may be configured to convert the data transmitted among the primary processing circuit 101 and the plurality of secondary processing circuits 102.
[0153] The multiple secondary processing circuits 102 may be configured to perform operations on the data blocks received according to the multiple operation instructions to obtain multiple intermediate results, and to transmit the multiple intermediate results to the K secondary processing circuits 102.
[0154] The primary processing circuit 101 may be configured to process the multiple intermediate results received from the K secondary processing circuits 102 to obtain the computation result of the computation instruction, and to send the computation result of the computation instruction to the controller unit 11.
[0155] In an example, as illustrated in FIG. 3D, the primary processing circuit 101 illustrated in FIGS. 3A3C may further include one or any combination of an activation processing circuit 1011 and an addition processing circuit 1012.
[0156] The activation processing circuit 1011 may be configured to perform an activation operation on data in the primary processing circuit 101.
[0157] The addition processing circuit 1012 may be configured to perform an addition operation or an accumulation operation.
[0158] The multiple secondary processing circuits 102 include multiplication processing circuits configured to perform multiplication operations on the data block received to obtain product results. The multiple secondary processing circuits 102 may further include a forwarding processing circuit configured to perform forward processing on the data block received or the product results. The multiple secondary processing circuits 102 may further include accumulation processing circuits configured to perform accumulation operations on the product results to obtain intermediate results.
[0159] In an example, the data type of the first input data is inconsistent with an operation type indicated by the multiple operation instructions involved in the operations, and the data type of the second input data is inconsistent with the operation type indicated by the multiple operation instructions involved in the operations. The conversion unit 13 may be configured to obtain the opcode and the opcode field of the data conversion instruction. The opcode may be configured to indicate information of a function of the data conversion instruction. The opcode field may include information of the decimal point position, the flag bit indicating the data type of the first input data, and the identifier of data type conversion. The conversion unit 13 may be configured to convert the first input data into the second input data according to the decimal point position and the identifier of data type conversion.
[0160] Specifically, identifiers of data type conversion are in onetoone correspondence with conversion manners of data type. Table 3 is a table illustrating correspondence relation between the identifier of data type conversion and the conversion manner of data type.
[0161] As illustrated in Table 3, if the identifier of data type conversion is 00, the conversion manner of data type is converting the fixedpoint data into fixedpoint data. If the identifier of data type conversion is 01, the conversion manner of data type is converting the floating point data into floating point data. If the identifier of data type conversion is 10, the conversion manner of data type is converting the fixedpoint data into floating point data. If the identifier of data type conversion is 11, the conversion manner of data type is converting the floating point data into fixedpoint data.
Table 3
Identifier of data type conversion  Conversion manner of data type 
00 
Converting the fixedpoint data into fixedpoint data 
01 
Converting the floating point data into floating point data 
10 
Converting the fixedpoint data into floating point data 
11 
Converting the floating point data into fixedpoint data 
[0162] Optionally, the correspondence relationship between the identifier of data type conversion and the conversion manner of data type may also be as illustrated in Table 4.
Table 4
Identifier of data type conversion  Conversion manner of data type 
0000 
Converting 64bit fixedpoint data into 64bit floating point data 
0001 
Converting 32bit fixedpoint data into 64bit floating point data 
0010 
Converting 16bit fixedpoint data into 64bit floating point data 
0011 
Converting 32bit fixedpoint data into 32bit floating point data 
0100 
Converting 16bit fixedpoint data into 32bit floating point data 
0101 
Converting 16bit fixedpoint data into 16bit floating point data 
0110 
Converting 64bit floating point data into 64bit fixedpoint data 
0111 
Converting 32bit floating point data into 64bit fixedpoint data 
1000 
Converting 16bit floating point data into 64bit fixedpoint data 
1001 
Converting 32bit floating point data into 32bit fixedpoint data 
1010 
Converting 16bit floating point data into 32bit fixedpoint data 
1011 
Converting 16bit floating point data into 16bit fixedpoint data 
[0163] As illustrated in Table 4, if the identifier of data type conversion is 0000, the conversion manner of data type is converting 64bit fixedpoint data into 64bit floating point data. If the identifier of data type conversion is 0001, the conversion manner of data type is converting 32bit fixedpoint data into 64bit floating point data. If the identifier of data type conversion is 0010, the conversion manner of data type is converting 16bit fixedpoint data into 64bit floating point data. If the identifier of data type conversion is 0011, the conversion manner of data type is converting 32bit fixedpoint data into 32bit floating point data. If the identifier of data type conversion is 0100, the conversion manner of data type is converting 16bit fixedpoint data into 32bit floating point data. If the identifier of data type conversion is 0101, the conversion manner of data type is converting 16bit fixedpoint data into 16bit floating point data. If the identifier of data type conversion is 0110, the conversion manner of data type is converting 64bit floating point data into 64bit fixedpoint data. If the identifier of data type conversion is 0111, the conversion manner of data type is converting 32bit floating point data into 64bit fixedpoint data. If the identifier of data type conversion is 1000, the conversion manner of data type is converting 16bit floating point data into 64bit fixedpoint data. If the identifier of data type conversion is 1001, the conversion manner of data type is converting 32bit floating point data into 32bit fixedpoint data. If the identifier of data type conversion is 1010, the conversion manner of data type is converting 16bit floating point data into 32bit fixedpoint data. If the identifier of data type conversion is 1011, the conversion manner of data type is converting 16bit floating point data into 16bit fixedpoint data.
[0164] The operation type identifier may be configured to indicate a type of data involved in operations if the operation unit 12 performs the operations. The type may include fixedpoint data, floating point data, integer data, discrete data, or the like.
[0165] In an example, the storage unit 10 may be configured to store the first address of the first input data, the length of the first input data, the first address of the output data, the decimal point position, the flag bit indicating the data type of the first input data, and the operation type identifier. The controller unit 11 may be configured to directly acquire the first address of the first input data, the length of the first input data, the first address of the output data, the decimal point position, the flag bit indicating the data type of the first input data, and the operation type identifier from the storage unit 10. And then, subsequent operations may be performed as the above process.
[0166] For example, the abovementioned operation type identifier may be zero or one. If the flag bit is one, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform floating point operations, that is, the data type of data involved in the floating point operations is floating point type. If the flag bit is zero, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform fixedpoint operations, that is, the data type of data involved in the fixedpoint operations is fixedpoint type.
[0167] The operation unit 12 may determine the data type of the input data and the operation type according to the flag bit and the operation type identifier.
[0168] Specifically, referring to Table 5. Table 5 is a mapping relationship table of the flag bits and the operation type identifiers.
[0169] As illustrated in Table 5, if the operation type identifier is 0 and the flag bit indicating the data type is 0, the first input data is fixedpoint data, and the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform fixedpoint operations without performing data type conversion. If the operation type identifier is 0 and the flag bit indicating the data type is 1, the first input data is floating point data, and the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform floating point operations without performing data type conversion. If the operation type identifier is 1 and the flag bit indicating the data type is 0, the first input data is fixedpoint data, and the conversion unit 13 first converts the first input data into the second input data according to the decimal point position, where the second input data is floating point data, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform operations on the second input data. If the operation type identifier is 1 and the flag bit indicating the data type is 1, the first input data is floating point data, and the conversion unit 13 first converts the first input data into the second input data according to the decimal point position, where the second input data is fixedpoint data, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform operations on the second input data.
[0170] The abovementioned fixedpoint data may include 64bit fixedpoint data, 32bit fixedpoint data, and 16bit fixedpoint data. The abovementioned floating point data may include 64bit floating point data, 32bit floating point data, and 16bit floating point data. The mapping relationship between the abovementioned flag bits and the operation type identifiers is illustrated in Table 6.
[0171] As illustrated in Table 6, if the operation type identifier is 0000 and the flag bit indicating the data type is 0, the first input data is 64bit fixedpoint data, and the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 64bit fixedpoint operations without performing data type conversion. If the operation type identifier is 0000 and the flag bit indicating the data type is 1, the first input data is 64bit floating point data, and the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 64bit floating point operations without performing data type conversion. If the operation type identifier is 0001 and the flag bit indicating the data type is 0, the first input data is 32bit fixedpoint data, and the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 32bit fixedpoint operation without performing data type conversion. If the operation type identifier is 0001 and the flag bit indicating the data type is 1, the first input data is 32bit floating point data, and the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 32bit floating point operation without performing data type conversion. If the operation type identifier is 0010 and the flag bit indicating the data type is 0, the first input data is 16bit fixedpoint data, and the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 16bit fixedpoint operation without performing data type conversion. If the operation type identifier is 0010 and the flag bit indicating the data type is 1, the first input data is 16bit floating point data, and the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 16bit floating point operation without performing data type conversion.
[0172] If the operation type identifier is 0011 and the flag bit indicating the data type is 0, the first input data is 64bit fixedpoint data. The conversion unit 13 first converts the first input data into the second input data according to the decimal point position, and the second input data is 64bit floating point data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 64bit floating point operations on the second input data. If the operation type identifier is 0011 and the flag bit indicating the data type is 1, the first input data is 64bit floating point data. The conversion unit 13 first converts the first input data into the second input data according to the decimal position, and the second input data is 64bit fixedpoint data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 64bit fixedpoint operations on the second input data.
[0173] If the operation type identifier is 0100 and the flag bit indicating the data type is 0, the first input data is 32bit fixedpoint data. The conversion unit 13 first converts the first input data into the second input data according to the decimal point position, and the second input data is 64bit floating point data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 64bit floating point operations on the second input data. If the operation type identifier is 0100 and the flag bit indicating the data type is 1, the first input data is 32bit floating point data. The conversion unit 13 first converts the first input data into the second input data according to the decimal position, and the second input data is 64bit fixedpoint data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 64bit fixedpoint operations on the second input data.
[0174] If the operation type identifier is 0101 and the flag bit indicating the data type is 0, the first input data is 16bit fixedpoint data. The conversion unit 13 first converts the first input data into the second input data according to the decimal point position, and the second input data is 64bit floating point data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 64bit floating point operations on the second input data. If the operation type identifier is 0101 and the flag bit indicating the data type is 1, the first input data is 16bit floating point data. The conversion unit 13 first converts the first input data into the second input data according to the decimal position, and the second input data is 64bit fixedpoint data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 64bit fixedpoint operations on the second input data.
[0175] If the operation type identifier is 0110 and the flag bit indicating the data type is 0, the first input data is 32bit fixedpoint data. The conversion unit 13 first converts the first input data into the second input data according to the decimal point position, and the second input data is 32bit floating point data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 32bit floating point operations on the second input data. If the operation type identifier is 0110 and the flag bit indicating the data type is 1, the first input data is 32bit floating point data. The conversion unit 13 first converts the first input data into the second input data according to the decimal position, and the second input data is 32bit fixedpoint data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 32bit fixedpoint operations on the second input data.
[0176] If the operation type identifier is 0111 and the flag bit indicating the data type is 0, the first input data is 16bit fixedpoint data. The conversion unit 13 first converts the first input data into the second input data according to the decimal point position, and the second input data is 32bit floating point data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 32bit floating point operations on the second input data. If the operation type identifier is 0111 and the flag bit indicating the data type is 1, the first input data is 16bit floating point data. The conversion unit 13 first converts the first input data into the second input data according to the decimal position, and the second input data is 32bit fixedpoint data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 32bit fixedpoint operations on the second input data.
[0177] If the operation type identifier is 1000 and the flag bit indicating the data type is 0, the first input data is 16bit fixedpoint data. The conversion unit 13 first converts the first input data into the second input data according to the decimal point position, and the second input data is 16bit floating point data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 16bit floating point operations on the second input data. If the operation type identifier is 1000 and the flag bit indicating the data type is 1, the first input data is 16bit floating point data. The conversion unit 13 first converts the first input data into the second input data according to the decimal position, and the second input data is 16bit fixedpoint data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 16bit fixedpoint operations on the second input data.
[0178] If the operation type identifier is 1001 and the flag bit indicating the data type is 0, the first input data is 64bit fixedpoint data. The conversion unit 13 first converts the first input data into the second input data according to the decimal point position, and the second input data is 32bit floating point data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 32bit floating point operations on the second input data. If the operation type identifier is 1001 and the flag bit indicating the data type is 1, the first input data is 64bit floating point data. The conversion unit 13 first converts the first input data into the second input data according to the decimal position, and the second input data is 32bit fixedpoint data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 32bit fixedpoint operations on the second input data.
[0179] If the operation type identifier is 1010 and the flag bit indicating the data type is 0, the first input data is 64bit fixedpoint data. The conversion unit 13 first converts the first input data into the second input data according to the decimal point position, and the second input data is 16bit floating point data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 16bit floating point operations on the second input data. If the operation type identifier is 1010 and the flag bit indicating the data type is 1, the first input data is 64bit floating point data. The conversion unit 13 first converts the first input data into the second input data according to the decimal position, and the second input data is 16bit fixedpoint data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 16bit fixedpoint operations on the second input data.
[0180] If the operation type identifier is 1011 and the flag bit indicating the data type is 0, the first input data is 32bit fixedpoint data. The conversion unit 13 first converts the first input data into the second input data according to the decimal point position, and the second input data is 16bit floating point data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 16bit floating point operations on the second input data. If the operation type identifier is 1011 and the flag bit indicating the data type is 1, the first input data is 32bit floating point data. The conversion unit 13 first converts the first input data into the second input data according to the decimal position, and the second input data is 16bit fixedpoint data. And then, the primary processing circuit 101 and the secondary processing circuits 102 of the operation unit 12 perform 16bit fixedpoint operations on the second input data.
[0181] In another example of the present disclosure, the operation instruction may be an instruction of matrix multiplying matrix, an accumulation instruction, an activation instruction, and the like.
[0182] In an example, as illustrated in FIG. 3E, the operation unit may include a tree module 40. The tree module 40 may include a root port 401 coupled with the primary processing circuit 101 and multiple branch ports 402. Each of the multiple branch ports 402 is respectively coupled with one of the multiple secondary processing circuits 102.
[0183] The tree module 40 may have a transceiving function. As illustrated in FIG. 3E, the tree module 40 may have a transmitting function. As illustrated in FIG. 6A, the tree module 40 may have a receiving function.
[0184] The tree module may be configured to forward data and the multiple operation instructions transmitted among the primary processing circuit 101 and the multiple secondary processing circuits 102.
[0185] The tree module 40 may be configured to forward data blocks, weights, and operation instructions transmitted among the primary processing circuit 101 and the multiple secondary processing circuits 102.
[0186] In an example, the tree module 40 is an operation module of the computation device, and may include at least one layer of nodes. Each node is a line structure with a forwarding function and may not have a computing function. If the tree module 40 has a zero layer of nodes, the tree module 40 may not be needed for the computation device.
[0187] In an example, the tree module 40 may be an ntree structure, for example, a binary tree structure as illustrated in FIG. 3F, and may also be a tritree structure. The n may be an integer greater than or equal to two. The examples of the present disclosure do not limit the specific value of the foregoing n. The number of layers may be two, and the secondary processing circuit 102 may be coupled with nodes other than nodes of the second last layer. For example, the secondary processing circuit 102 may be coupled with nodes of the first last layer illustrated in FIG. 3F.
[0188] In an example, the operation unit 12 may be provided with a separate cache. As illustrated in FIG. 3G, the operation unit 12 may include a neuron cache unit 63 configured to buffer input neuron vector data and output neuron weight data of the secondary processing circuits 102.
[0189] As illustrated in FIG. 3H, the operation unit 12 may further include a weight cache unit 64 configured to buffer weight data required by the secondary processing circuit 102 in the operation process.
[0190] In an example, fully coupled operations in neural network operations are described as an example, and the operation process may be expressed as y=f (wx+b), where x is an input neuron matrix, w is a weight matrix, b is an offset scalar, and f is an activation function. The activation function f may be one of sigmoid function, tanh function, relu function, and softmax function. In this example, assuming a binary tree structure with 8 secondary processing circuits 102 is provided, which may be implemented as follows:
obtaining, by the controller unit 11, the input neuron matrix x, the weight matrix w, and a fully coupled operation instruction from the storage unit 10, and transmitting the input neuron matrix x, the weight matrix w, and the fully coupled operation instruction to the primary processing circuit 101;
dividing, by the primary processing circuit 101, the input neuron matrix x into eight submatrices, distributing the eight submatrices through the tree module to the eight secondary processing circuits 102, and broadcasting the weight matrix w to the eight secondary processing circuits 102; and
performing, by the plurality of secondary processing circuits 102, multiplication and accumulation operations of the eight submatrices and the weight matrix w in parallel to obtain eight intermediate results, and sending the eight intermediate results to the primary processing circuit 101.
[0191] The primary processing circuit 101 may be configured to rank eight internal results to obtain an operation result, to perform an offset operation with the offset b on the operation result, and to perform an activation operation to obtain a final result y. The final result y is sent to the controller unit 11, and the controller unit 11 may be configured to output or store the final result y into the storage unit 10.
[0192] In an example, the operation unit 12 may include, but not limited to, one or more multipliers of a first part, one or more adders of a second part (more specifically, the adders of the second part may also constitute an addition tree), an activation function unit of a third part, and/or a vector processing unit of the fourth part. More specifically, the vector processing unit may process vector operations and/or pooling operations. In the first part, input data 1 (i.e., in1) multiplies input data 2 (i.e., in2) to obtain output data (i.e., out), the operations in the first part may be represented by out=in1
^{∗}in2. In the second part, an addition operation is performed on the input data (inl) via the adder(s) to obtain the out data (out). More specifically, if the second part is an addition tree, an addition operation is performed step by step on the input data (inl) through the addition tree to obtain the output data (out). The in1 is a vector of length N, and N is greater than one, the operations in the second part may be represented by out=in1[1]+in1[2]+...+in1[N], and/or the input data (inl) is added step by step via the adder, and then added to the input data (in2) to obtain the output data (out), that is, out=in1[1]+in1[2]+...+in1[N]+in2. Alternatively, the input data (inl) and the input data (in2) is added to obtain the output data (out), that is, out=in1+in2. In the third part, operations of an activation function (active) may be performed on input data (in) to obtain an activation output data (out), and the operations in the third part may be represented by out=active(in). The activation function (active) may be one of functions sigmoid, tanh, relu, softmax, etc. In addition to the activation operation, the third part may implement other nonlinear functions. The input data (in) may be used to obtain the output data (out) via an operation function (f), that is, out=f (in). The vector processing unit may be configured to perform the pooling operation on the input data (in) to obtain the output data (out), that is, out=pool(in), where the function pool is a pooling operation. The pooling operation may include, but not limited to, average pooling, maximum pooling, median pooling. The input data is data in a pooled core associated with output out.
[0193] The operation unit 12 may be configured to perform operations, which may include at least one of operations in the first part, operations in the second part, operations in the third part, and operations in the fourth part. The operations in the first part may include multiplying the input data 1 and the input data 2 to obtain the output data. In the operations in the second part, an addition operation is performed (more specifically, the addition operation is an addition tree operation, and with the addition operation, the input data 1 is added step by step via the addition tree), or the input data 1 is added with the input data 2 to obtain the out data. In the third part, operations of the activation function (active) may be performed on the input data to obtain the output data. In the fourth part, the pooling operation may be performed, that is, out=pool (in), and the function pool is a pooling operation. The pooling operation may include, but is not limited to, average pooling, maximum pooling, median pooling. The input data is data in a pooled core associated with output out. The operations of the aboveidentified parts may be freely selected by combining multiple parts in different sequences to achieve various functions. Accordingly, the operation unit 12 may include a secondary, tertiary, or quaternary flowlevel architecture.
[0194] It should be noted that the first input data is longdigit nonfixedpoint data, for example, 32bit floating point data, and may be standard 64bit or 16bit floating point data, etc. In this example of the present disclosure, only 32bit data is described as an example. The second input data is shortdigit fixedpoint data, which is also referred to as a smalldigit fixedpoint data, and represents fixedpoint data represented by a smaller number of bits than the first input data of the longdigit nonfixedpoint data.
[0195] In an example, the first input data is nonfixedpoint data, and the second input data is fixedpoint data, and a bit number occupied by the first input data is greater than or equal to that occupied by the second input data. For example, the first input data is 32bit floating point data, and the second input data is 32bit fixedpoint data. For another example, the first input data is 32bit floating point data, and the second input data is 16bit fixedpoint data.
[0196] Specifically, for different layers of different network models, the abovementioned first input data may include different types of data. The decimal point positions of the different types of data are different, that is, the accuracy of corresponding fixedpoint data is different from that of other data. For a fully coupled layer, the first input data may include data such as input neurons, weights, and offset data. For a convolution layer, the first input data may include data such as convolution kernels, input neurons, and offset data.
[0197] For example, for a fully coupled layer, the abovementioned decimal point position may include a decimal point position of the input neuron, a decimal point position of the weight, and a decimal point position of the offset data. It should be noted that the decimal point position of the input neuron, the decimal point position of the weight, and the decimal point position of the offset data may all be the same or partially the same or different from each other.
[0198] In an example, the controller unit 11 may be further configured to determine a decimal point position of the first input data and a bit width of the fixedpoint data prior to acquiring the first input data and the computation instruction. The bit width of fixedpoint data is a bit width of the first input data converted into fixedpoint data.
[0199] The operation unit 12 may be further configured to initialize a decimal point position of the first input data and adjust a decimal point position of the first input data.
[0200] The bit width of fixedpoint data of the first input data is bits occupied by the first input data represented by fixedpoint data. The abovementioned decimal point position is bits occupied by a fractional part of the first data represented by fixedpoint data. The decimal point position may be configured to indicate the accuracy of the fixedpoint data. Referring to the related description of FIG. 2A for details.
[0201] In an example, the first input data may be any type of data, and first input data
a is converted into the second input data
â according to the decimal point position and the bit width of the fixedpoint data, which is described as follows.
[0202] If the first input data
a satisfies a condition of
neg ≤
a ≤
pos, the second input data
â is represented as 
a / 2
^{s}∗2
^{s}. If the first input data
a is greater than
pos, the second input data
â is represented as
pos. If the first input data
a is less than
neg, the second input data
â is represented as
neg.
[0203] In an example, input neurons, weights, output neurons, input neuron derivatives, output neuron derivatives, and weight derivatives of a convolutional layer and a fully coupled layer are represented by fixedpoint data.
[0204] In an example, the bit width of fixedpoint data of the input neuron may be 8, 16, 32, 64, or other bits. Specifically, the bit width of fixedpoint data of the input neuron is 8.
[0205] In an example, the bit width of fixedpoint data of the weight may be 8, 16, 32, 64, or other bits. Specifically, the bit width of the fixedpoint data of the weight is 8.
[0206] In an example, the bit width of fixedpoint data of the input neuron derivative may be 8, 16, 32, 64, or other bits. Specifically, the bit width of fixedpoint data of the input neuron derivative is 16.
[0207] In an example, the bit width of fixedpoint data of the output neuron derivative may be 8, 16, 32, 64, or other bits. Specifically, the bit width of fixedpoint data of the output neuron derivative is 24 bits.
[0208] In an example, the bit width of fixedpoint data of the weight derivative may be 8, 16, 32, 64, or other bits. Specifically, the bit width of fixedpoint data of the weight derivative is 24 bits.
[0209] In an example, the data
a with a large value in data involved in a multilayer network model operation may adopt multiple representation manners of fixedpoint data. Referring to the related description of FIG 2B for details.
[0210] In an example, the first input data may be any type of data, and the first input data
a is converted into the second input data
â according to the decimal point position and the bit width of fixedpoint data, which is described as follows.
[0211] If the first input data
a satisfies a condition of
neg ≤
a ≤
pos, the second input data
â is represented as
where
â_{0} = 0. If the first input data
a is greater than
pos, the second input data
â is represented as
pos. If the first input data
a is less than
neg, the second input data
â is represented as
neg
[0212] Further, the operation unit 12 may be configured to initialize the decimal point position of the first input data as follows:
initializing the decimal point position of the first input data according to a maximum absolute value of the first input data; or
initializing the decimal point position of the first input data according to a minimum absolute value of the first input data; or
initializing the decimal point position of the first input data according to a relationship between different data types in the first input data; or
initializing the decimal point position of the first input data according to an empirical value constant.
[0213] Specifically, the above decimal point position
s need to be initialized and dynamically adjusted according to data of different categories, data of different neural network layers, and data of different iteration rounds.
[0214] An initialization process of the decimal point position of the first input data is specifically described as follows, for example, the decimal point position adopted by the fixedpoint data is determined when converting the first input data at the first time.
[0215] The operation unit 12 may be configured to initialize the decimal point position
s of the first input data as follows:
initializing the decimal point position
s of the first input data according to the maximum absolute value of the first input data; initializing the decimal point position
s of the first input data according to the minimum absolute value of the first input data; initializing the decimal point position
s of the first input data according to relationship between different data types in the first input data; and initializing the decimal point position
s of the first input data according to the empirical value constant.
[0216] Specifically, the abovementioned initialization process is specifically described as follows.
[0217] At step (a), the operation unit 12 may be configured to initialize the decimal point position
s of the first input data according to the maximum absolute value of the first input data.
[0218] The abovementioned operation unit 12 specifically initializes the decimal point positions of the first input data by performing an operation shown by the following formula.
[0219] The
a_{max} represents the maximum absolute value of the first input data. The
bitnum represents the bit width of the fixedpoint data converted from the first input data. The
s_{a} represents the decimal point position of the first input data.
[0220] According to categories and network levels, the data involved in operations may be divided into the input neuron
X^{(l)}, the output neuron
Y^{(l)}, the weight
W^{(l)}, the input neuron derivative ∇
_{X}^{(l)}, the output neuron derivative ∇
_{Y}^{(l)}, and the weight derivative ∇
_{W}^{(l)} of the
lth layer. The maximum absolute value may be searched by one of manners including searching by data category, searching by layer and data category, searching by layer, data category, and group. The maximum absolute value of the first input data may be determined as follows.
[0221] At step (a.1), the operation unit 12 may be configured to search the maximum absolute value by data category.
[0222] Specifically, the first input data may include each element
a_{i}^{(l)} in a vector/matrix, where element
a^{(l)} may be an input neuron X
^{(l)}, an output neuron
Y^{(l)}, a weight
W^{(l)}, an input neuron derivative ∇
_{X}^{(l)}, an output neuron derivative ∇
_{Y}^{(l)}, or a weight derivative ∇
_{W}^{(l)}. In other words, the abovementioned first input data may include input neurons, weights, output neurons, input neuron derivatives, weight derivatives, and output neuron derivatives. The abovementioned decimal point position of the first input data may include a decimal point position of the input neuron, a decimal point position of the weight, a decimal point position of the output neuron, a decimal point position of the input neuron derivative, a decimal point position of the weight derivative, and a decimal point position of the neuron derivative. The input neurons, the weights, the output neurons, the input neuron derivatives, the weight derivatives, and the output neuron derivatives are all represented in a matrix or vector form. The operation unit 12 may be configured to acquire the maximum absolute value (that is,
) of each category data by traversing all elements in the vector/matrix of each layer of the abovementioned multilayer network model. The decimal point position
s_{a} of the fixedpoint data converted from the input data
a of each category data is determined by a formula of
s_{a} = ┌log
_{2} a_{max}bitnum + 1┐.
[0223] At step (a.2), the operation unit 12 may be configured to search the maximum absolute value by layer and data category.
[0224] Specifically, the first input data may include each element
a_{i}^{(l)} in a vector/matrix, where a
^{(l)} may be input neurons
X^{(l)}, output neurons
Y^{(l)}, weights
W^{(l)}, an input neuron derivative ∇
_{X}^{(l)}, an output neuron derivative ∇
_{Y}^{(l)}, or a weight derivative ∇
_{W}^{(l)}. In other words, each layer of the abovementioned multilayer network model may include input neurons, weights, output neurons, input neuron derivatives, weight derivatives, and output neuron derivatives. The abovementioned decimal point position of the first input data may include a decimal point position of the input neuron, a decimal point position of the weight, a decimal point position of the output neuron, a decimal point position of the input neuron derivative, a decimal point position of the weight derivative, and a decimal point position of the neuron derivative. The input neurons, the weights, the output neurons, the input neuron derivatives, the weight derivatives, and the output neuron derivatives are all represented in a matrix or vector form. The operation unit 12 may be configured to acquire the maximum absolute value (that is,
) of each category data by traversing all elements in the vector/matrix of each data of each layer of the abovementioned multilayer network model. The decimal point position
of the input data
a of each category of
lth layer is determined by a formula of
[0225] At step (a.3), the operation unit 12 may be configured to search the maximum absolute value by layer, data category, and group.
[0226] Specifically, the first input data may include each element
a_{i}^{(l)} in a vector/matrix, where
a^{(l)} may be input neurons
X^{(l)}, output neurons
Y^{(l)}, weights
W^{(l)}, an input neuron derivative ∇
_{X}^{(l)}, an output neuron derivative ∇
_{Y}^{(l)}, or a weight derivative ∇
_{W}^{(l)}. In other words, data categories of each layer of the abovementioned multilayer network model may include input neurons, weights, output neurons, input neuron derivatives, weight derivatives, and output neuron derivatives. The abovementioned operation unit 12 divides data of each category of each layer of the abovementioned multilayer network model into g groups, or into groups by other arbitrary grouping rules. The operation unit 12 then traverses each element of each group of data in the g groups data corresponding to the data of each category of each layer of the abovementioned multilayer network model, and obtains the element with the largest absolute value (that is,
) in the group of data. The decimal point position
of data of each group of the g groups data corresponding to each category of each layer is determined by a formula of
[0227] The foregoing arbitrary grouping rules may include, but not limited to, rule for grouping according to data ranges, rule for grouping according to data training batches, and the like.
[0228] In an example, if the controller unit 11 or the operation unit 12 obtains the decimal point position of the first input data according to the aboveidentified process, the decimal point position of the first input data is stored in the cache 202 of the storage unit 10.
[0229] If the abovementioned computation instruction is an immediate address instruction, the primary processing unit 101 directly converts the first input data into the second input data according to the decimal point position indicated by the opcode field of the computation instruction. If the abovementioned computation instruction is a direct addressing instruction or an indirect addressing instruction, the primary processing unit 101 obtains the decimal point position of the first input data according to the storage space indicated by the opcode field of the computation instruction. The first input data is then converted to the second input data according to the decimal point position.
[0230] The abovementioned computation device may also include a rounding unit. During the operation, the accuracy of the operation result obtained by adding, multiplying, and/or other operations on the second input data (the operation result may include the intermediate results and the computation result of the computation instruction) exceeds the accuracy range of the current fixedpoint data. Therefore, a data cache unit may be configured to buffer the abovementioned intermediate results. After the end of the operation, the rounding unit performs a rounding operation on the operation result exceeding the precision range of the fixedpoint data, and obtains the rounded operation result. After the operation is completed, the rounding unit rounds the operation result exceeding the precision range of the fixedpoint data, and obtains a rounded operation result. The data conversion unit then converts the rounded operation result into data of the type of the current fixedpoint data.
[0231] Specifically, the rounding unit performs a rounding operation on the intermediate results, where the rounding operation may be any one of a random rounding operation, a roundingoff operation, a roundingup operation, a roundingdown operation, and a truncation rounding operation.
[0232] If the rounding unit performs the random rounding operation, the rounding unit performs the following operations.
[0233] The
y represents data obtained by performing random rounding operation on the operation result
x before rounding, that is, the abovementioned rounded operation result. The
ε represents the minimum positive number that may be represented by the current fixedpoint data representation format, that is, 2
^{Point Location}. The └
x┘ represents data obtained by directly truncating the fixedpoint data from the operation result
x before rounding (similar to rounding down the decimal). The
w.
p. represents a probability. A probability expressed by the aboveidentified formula of obtaining the data └
x┘ by performing random rounding operation on the operation result
x before rounding is
A probability of obtaining data └x┘+
ε by performing random rounding operation on the intermediate result
x before rounding is
[0234] If the rounding unit performs the roundingoff operation, the rounding unit performs the following operations.
[0235] The
y represents data obtained by performing roundingoff operation on the operation result
x before rounding, that is, the abovementioned rounded operation result. The
ε represents the minimum positive number that may be represented by the current fixedpoint data representation format, that is, 2
^{Point Location}. The └
x┘ is an integral multiple of the
ε, and a value of the └
x┘ is a maximum number less than or equal to the
x. If operation result
x before rounding satisfies a condition of
the abovementioned rounded operation result is └
x┘. If operation result
x before rounding satisfies a condition of
the abovementioned rounded operation result is └
x┘+
ε.
[0236] If the rounding unit performs the roundingup operation, the rounding unit performs the following operations.
y = ┌
x┐
[0237] The
y represents data obtained by performing roundingup operation on the operation result
x before rounding, that is, the abovementioned rounded operation result. The ┌
x┐ is an integral multiple of the
ε, and a value of the ┌
x┐ is a maximum number less than or equal to the
x. The
ε represents the minimum positive number that may be represented by the current fixedpoint data representation format, that is, 2
^{Po int Location}.
[0238] If the rounding unit performs the roundingdown operation, the rounding unit performs the following operations.
[0239] The
y represents data obtained by performing roundingup operation on the operation result
x before rounding, that is, the abovementioned rounded operation result. The └
x┘ is an integral multiple of the
ε, and a value of the └
x┘ is a maximum number less than or equal to the
x. The
ε represents the minimum positive number that may be represented by the current fixedpoint data representation format, that is, 2
^{Po int Location}.
[0240] If the rounding unit performs the truncation rounding operation, the rounding unit performs the following operations.
[0241] The
y represents data obtained by performing truncation rounding operation on the operation result
x before rounding, that is, the abovementioned rounded operation result. The [
x] represents data obtained by directly truncating the fixedpoint data from the operation result
x.
[0242] If the rounding unit obtains an intermediate result after the rounding (that is, a rounded intermediate result), the operation unit 12 converts the rounded intermediate result into data of the type of the current fixedpoint data according to the decimal point position of the first input data.
[0243] In an example, the operation unit 12 may further include a derivation unit. If the operation unit 12 receives the decimal point position of the input data involved in the fixedpoint operation, the derivation unit derives a decimal point position of the at least one intermediate result obtained during the fixedpoint operation according to the decimal point position of the input data involved in the fixedpoint operation. If the intermediate result obtained by operation subunits exceeds the range indicated by the corresponding decimal point position, the derivation unit shifts the decimal point position of the intermediate result to the left by M bits, such that the accuracy of the intermediate result is within a precision range indicated by the decimal point position of the intermediate result, and the M is an integer greater than zero.
[0244] For example, the first input data may include the input data I1 and the input data I2, and the corresponding decimal point positions are P1 and P2, and P1>P2. If the operation type indicated by the abovementioned operation instruction is an addition operation or a subtraction operation, that is, if the operation subunit performs the operation of 11+12 or 1112, the derivation unit derives a decimal point position of the intermediate result of the operation process indicated by the operation instruction as PI. If the operation type indicated by the operation instruction is a multiplication operation, that is, if the operation subunit performs an I1
^{∗}I2 operation, the derivation unit derives a decimal point position of the intermediate result of the operation process indicated by the operation instruction as P1
^{∗}P2.
[0245] In an example, the operation unit 12 may further include a data cache unit for buffering the at least one intermediate result.
[0246] In an example, the computation device may further include a data statistical unit. The data statistical unit may be configured to perform statistics on the input data of the same type of the each layer in the multilayer network model, so as to obtain the decimal point position of each type of each layer of the multilayer network model.
[0247] The data statistical unit may also be part of an external device. The computation device obtains a decimal point position of data involving operations from the external device before performing the data conversion.
[0248] Specifically, the data statistical unit may include an acquiring subunit, a statistical subunit, and an analysis subunit.
[0249] The acquiring subunit may be configured to extract the input data of the same type of the each layer in the multilayer network model.
[0250] The statistical subunit may be configured to compute and obtain a distribution ratio of the input data of the same type of the each layer in the multilayer network model on a preset interval;
[0251] The analysis subunit may be configured to obtain a decimal point position of the input data of the same type of the each layer in the multilayer network model according to the distribution ratio.
[0252] The preset interval may be [2
^{X1i},2
^{X1i}2
^{i}],
i = 0,1,2,...,n, n is a preset positive integer, and X is a bit number occupied by the fixedpoint data. The abovementioned preset interval [2
^{X1}^{i},2
^{X1i}2
^{i}] may include n+1 subintervals. The statistical subunit may be configured to count distribute information of the input data of the same type of the each layer in the multilayer network model on the n+1 subintervals, and to obtain a first distribution ratio according to the distribution information. The first distribution ratio is
p_{0},
p_{1},p_{2},...,
p_{n}. The n+1 values of the first distribution ratio distribution are ratios of the input data of the same type of the each layer in the multilayer network model in the n+1 subintervals. The analysis subunit sets an overflow rate EPL in advance, and obtains a maximum value
i from 0,1,2,...,n, such that
p_{i} ≥ 1
EPL. The maximum value
i is the decimal point position of the input data of the same type of the each layer in the multilayer network model. In other words, the analysis subunit takes the decimal point position of the input data of the same type of the each layer in the multilayer network model as max{
i /
p_{i} ≥ 1 
EPL, i ∈ {0,1,2,...,
n}}, that is, a largest subscript value
i is selected as the decimal point position of the input data of the same type of the each layer in the multilayer network model from the
p_{i} which is greater than or equal to 1
EPL.
[0253] It should be noted that, the
p_{i} is a ratio of the number of the input data of the same type of the each layer in the multilayer network model whose value ranged in the interval [2
^{X1i},2
^{X1i}2
^{i}] to the total number of the input data of the same type of the each layer in the multilayer network model. For example, there are m1 input data of the same type of the each layer in the multilayer network model, and m2 input data of the m1 input data are in the interval [2
^{x1i},2
^{X1i}2
^{i}], and then
[0254] In an example, in order to improve the operation efficiency, the acquiring subunit may be configured to randomly or sample extract part of the input data of the same type of the each layer in the multilayer network model, to acquire the decimal point position of the part of the input data according to the aboveidentified method, and to perform data conversion on the decimal point position of the part of the input data (including conversion of floating point data into fixedpoint data, conversion of fixedpoint data into fixedpoint data, conversion of fixedpoint data into fixedpoint data, etc.), thereby improving the computation speed and efficiency under the premise of maintaining accuracy.
[0255] In an example, the data statistical unit may determine the bit width and the decimal point position of the input data of the same type or the input data of the same layer according to a median value of the input data of the same type or the input data of the same layer. Alternatively, the data statistical unit may determine the bit width and the decimal point position of the input data of the same type or the input data of the same layer according to an average value of the input data of the same type or the input data of the same layer.
[0256] In an example, if the operation unit may be configured to perform operations on the input data of the same type or the input data of the same layer to obtain an intermediate result, and the intermediate result exceeds a value range corresponding to the decimal point position and the bit width of the input data of the same type or the input data of the same layer, the operation unit does not perform truncation processing on the intermediate result, and caches the intermediate result in the data cache unit of the operation unit for subsequent operations.
[0257] Specifically, the opcode field may include a decimal point position and an identifier of data type conversion of the input data. The instruction processing unit parses the data conversion instruction to obtain the decimal point position and the identifier of data type conversion of the input data. The instruction processing unit may further include a data conversion unit, and the data conversion unit converts the first input data into the second input data according to the decimal point position and the identifier of data type conversion of the input data.
[0258] It should be noted that the abovementioned network model may include multiple layers, such as a fully coupled layer, a convolution layer, a pooling layer, and an input layer. In the abovementioned at least one input data, the input data belonging to the same layer has the same decimal point position, that is, the abovementioned input data of the same layer shares the same decimal point position.
[0259] The abovementioned input data may include different types of data, such as input neurons, weights, and offset data. The input data of the same type in the input data has the same decimal point position, that is, the abovementioned input data of the same type shares the same decimal point position.
[0260] For example, if the operation type indicated by the operation instruction is a fixedpoint operation, and the input data involved in the operation indicated by the operation instruction is floating point data, the data conversion unit converts the input data from the floating point data to fixedpoint data before performing the fixedpoint operation. For another example, if the operation type indicated by the operation instruction is a floating point operation, and the input data involved in the operation indicated by the operation instruction is fixedpoint data, the data conversion unit converts the input data corresponding to the operation instruction from fixedpoint data to floating point data before performing the floating point operation.
[0261] For macro instructions (such as the computation instruction and the data conversion instruction) involved in the present disclosure, the controller unit 11 may parse the macro instruction to obtain an opcode field and an opcode of the macro instruction. A micro instruction corresponding to the macro instruction is generated according to the opcode field and the opcode. Alternatively, the controller unit 11 decodes the macro instruction to obtain the micro instruction corresponding to the macro instruction.
[0262] In an example, a main processor and a coprocessor are included in a system on chip (SOC), and the main processor may include the abovementioned computation device. The coprocessor obtains the decimal point position of input data of the same type of the each layer in the multilayer network model according to the aboveidentified method, and transmits the decimal point position of the input data of the same type of the each layer in the multilayer network model to the computation device. Alternatively, if the computation device needs to use the decimal point position of the input data of the same type of the each layer in the multilayer network model, the decimal point position of the input data of the same type of the each layer in the multilayer network model is obtained from the abovementioned coprocessor.
[0263] In an example, the first input data is nonfixedpoint data, and the nonfixedpoint data may include longdigit floating point data, shortdigit floating point data, integer data, and discrete data.
[0264] The data types of the abovementioned first input data are different from each other. For example, the input neurons, weights, and offset data are floating point data. Alternatively, some of the input neurons, weights, and offset data are floating point data, and some of the input neurons, weights, and offset data are integer data. Alternatively, the abovementioned input neurons, weights, and offset data are all integer data. The computation device may realize the conversion of nonfixedpoint data to fixedpoint data, that is, the computation device may realize the conversion of data such as long digit floating point data, shortdigit floating point data, integer data, and discrete data to fixedpoint data. The fixedpoint data may be signed fixedpoint data or unsigned fixedpoint data.
[0265] In an example, the first input data and the second input data are both fixedpoint data, and the first input data and the second input data may both be signed fixedpoint data, or both are unsigned fixedpoint data. Alternatively, one of the first input data and the second input data is unsigned fixedpoint data and the other is signed fixedpoint data. And the decimal point position of the first input data is different from that of the second input data.
[0266] In an example, the first input data is fixedpoint data, and the second input data is nonfixedpoint data. In other words, the computation device may realize the conversion of fixedpoint data to nonfixedpoint data.
[0267] FIG. 4 is a flow chart of a forward operation of a singlelayer neural network according to an example of the present disclosure. The flow chart depicts a forward operation process of a single layer neural network implemented by using the computation device and an instruction set of the present disclosure. For each layer, an input neuron vector is first weighted and summed to compute an intermediate result vector of the layer. The intermediate result vector is offset and activated to obtain an output neuron vector. The output neuron vector is used as an input neuron vector of the next layer.
[0268] In a specific application scenario, the computation device may be a training device. Before training the neural network model, the training device may be configured to acquire training data involved in a training of the neural network model, and the training data is nonfixedpoint data. The training device may be further configured to obtain decimal point position of the training data according to the aboveidentified method. The training device converts the training data into training data represented by fixedpoint data according to the decimal point position of the training data. The training device performs a forward neural network operation based on the training data represented by fixedpoint data to obtain a neural network operation result. The training device performs a random rounding operation on the neural network operation result exceeding a range of data precision represented by the decimal point position of the training data, to obtain a rounded neural network operation result, where the neural network operation result is located in the range of data precision represented by the decimal point position of the training data. According to the aboveidentified method, the training device acquires the neural network operation result (that is, the output neurons) of each layer of the multilayer neural network. The training device obtains an output neuron gradient according to the output neurons of each layer, and performs a reverse operation according to the output neuron gradient to obtain a weight gradient, thereby updating the weights of the neural network model according to the weight gradient.
[0269] The abovementioned training device repeatedly performs the aboveidentified process to achieve the purpose of training the neural network model.
[0270] It should be noted that, before the forward operation and a reverse training, the computation device performs data conversion on the data involved in the forward operation, and does not perform data conversion on the data involved in the reverse training. Alternatively, the computation device does not perform data conversion on data involved in the forward operation, and performs data conversion on the data participating in the reverse training. Alternatively, the computation device performs data conversion on data involved in the reverse training and on data involved in the forward operation. The specific data conversion process may be referred to the description of the abovementioned related examples, and will not be described herein.
[0271] The forward operation may include the abovementioned multilayer neural network operation, and the multilayer neural network operation may include operations such as convolution, which is implemented by a convolution operation instruction.
[0272] The abovementioned convolution operation instruction may be an instruction in the Cambricon instruction set. The Cambricon instruction set is characterized in that the instruction may include an opcode and operands. The instruction set may include four types of instructions, that is, control instructions, data transfer instructions, operation instructions, and logical instructions.
[0273] Preferably, each instruction in the instruction set has a fixed length. For example, each instruction in the instruction set may be 64 bits in length.
[0274] Further, the control instructions may be configured to control an execution process. The control instructions include jump instructions and conditional branch instructions.
[0275] Further, the data transfer instructions may be configured to complete data transfer between different storage media. The data transfer instruction may include a load instruction, a store instruction, and a move instruction. The load instruction may be configured to load data from a main memory to a cache, the store instruction may be configured to store data from the cache to the main memory, and the move instruction may be configured to transfer data between the cache and the cache, or between the cache and registers, or between registers and registers. The data transfer instructions support three different ways of organizing data, which include matrices, vectors, and scalars.
[0276] Further, the operation instructions may be configured to perform neural network operations. The operation instruction may include a matrix operation instruction, a vector operation instruction, and a scalar operation instruction.
[0277] Furthermore, the matrix operation instruction performs matrix operations in neural networks, which include operations of matrix multiplying vector, vector multiplying matrix, and matrix multiplying scalar, outer products, matrix adding matrix, matrix subtracting matrix.
[0278] Furthermore, the vector operation instruction performs vector operations in the neural networks, which include operations of vector elementary arithmetics, vector transcendental functions, dot products, random vector generators, and maximum/minimum of a vector). The elementary arithmetics include vector addition, vector subtraction, vector multiplication, and vector division. The vector transcendental functions are functions that do not satisfy any polynomial equations that use polynomials as coefficients, including but not limited to exponential functions, logarithmic functions, trigonometric functions, and inverse trigonometric functions.
[0279] Furthermore, the scalar operation instruction performs scalar operations in the neural networks, including scalar elementary arithmetics and scalar transcendental functions. The scalar basic operations include scalar addition, scalar subtraction, scalar multiplication, and scalar division, the scalar transcendental functions are functions that do not satisfy any polynomial equations that use polynomials as coefficients, including but not limited to exponential functions, logarithmic functions, trigonometric functions, and inverse trigonometric functions.
[0280] Further, the logical instructions may be configured to perform logical operations in the neural networks. The logical operations include vector logical operation instructions and scalar logical operation instructions.
[0281] Furthermore, the vector logical operation instruction may include a vector comparison, a vector logical operation, and a vector greater than merge. The vector comparison may include, but are not limited to, greater than, less than, equal to, greater than or equal to, less than or equal to, and not equal to. The vector logical operations include with, or, not.
[0282] Further, the scalar logical operations may include scalar comparison, scalar logical operations. The scalar comparison may include, but is not limited to, greater than, less than, equal to, greater than or equal to, less than or equal to, and not equal to. The scalar logical operations include AND, OR, and NOT.
[0283] For a multilayer neural network, the implementation process may be executed as follows. In the forward operation, if the forward operation of a previous layer artificial neural network is completed, operation instructions of a next layer will operate the output neuron processed in the operation unit as the input neuron of the next layer (or perform some operations on the output neuron, and then the output neuron is operated as the input neuron of the next layer). At the same time, the weight is also replaced by the weight of the next layer. In the reverse operation, if the reverse operation of a previous artificial neural network is completed, operation instructions of a next layer will operate an input neuron gradient processed in the operation unit as an output neuron gradient of the next layer (or perform some operations on the input neuron gradient, and then the input neuron gradient is operated as the output neuron gradient of the next layer). At the same time, the weight is also replaced by the weight of the next layer. As illustrated in FIG. 5, arrows of the broken line in FIG. 5 indicate the reverse operation, and arrows of the solid line indicate the forward operation.
[0284] In another example, the operation instruction may be a matrix multiplying matrix instruction, an accumulation instruction, an activation instruction, and the like. The operation instruction may include a forward operation instruction and a direction training instruction.
[0285] The specific computation method of the computation device illustrated in FIG. 3A is explained herein via the neural network operation instruction. For the neural network operation instruction, the formula that it actually needs to execute may be
s =
s(∑
wx_{i} +
b), where the weight
w is multiplied by the input data, then a summation operation is performed, and then the offset b is added to perform the activation operation
s(
h) to obtain the final output result
s.
[0286] The method for performing the neural network forward operation instruction by the computation device is illustrated in FIG. 3A, which may include the following.
[0287] If the conversion unit 13 has performed data type conversion on the first input data, the controller unit 11 extracts the neural network forward operation instruction, and an opcode field and at least one opcode corresponding to the neural network operation instruction from the instruction cache unit 110, and the controller unit 11 transmits the opcode field to the data access unit, and transmits the at least one opcode to the operation unit 12.
[0288] The controller unit 11 extracts the weight w and the offset b corresponding to the opcode field from the storage unit 10 (if b is zero, the offset b does not need to be extracted). The weight w and the offset b are transmitted to the primary processing circuit 101 of the operation unit, and the controller unit 11 extracts the input data Xi from the storage unit 10, and transmits the input data Xi to the primary processing circuit 101.
[0289] The primary processing circuit 101 divides the input data Xi into n data blocks.
[0290] The instruction processing unit 111 of the controller unit 11 determines a multiplication instruction, an offset instruction, and an accumulation instruction according to the at least one opcode, and sends the multiplication instruction, the offset instruction, and the accumulation instruction to the primary processing circuit 101. The primary processing circuit 101 broadcasts the multiplication instruction and the weight w to the multiple secondary processing circuits 102, and distributes the n data blocks to the multiple secondary processing circuits 102 (for example, there are n secondary processing circuits 102, then each secondary processing circuit 102 is distributed with one data block). The multiple secondary processing circuits 102 perform multiplication operations on the data blocks received and the weight w to obtain intermediate results according to the multiplication instruction, and send the intermediate results to the primary processing circuit 101. The primary processing circuit 101 performs an accumulation operation on the intermediate results sent by the multiple secondary processing circuits 102 to obtain an accumulation result according to the accumulation instruction, and performs an addition operation on the accumulation result and the offset b to obtain the final result according to the offset instruction, and transmits the final result to the controller unit 11.
[0291] In addition, the order of the addition operation and the multiplication operation may be reversed.
[0292] It should be noted that the method for performing the neural network reverse training instruction by the abovementioned computation device is similar to a method for performing the neural network forward operation instruction by the abovementioned computation device. Specific details may refer to the related description of the reverse training, which are not described herein.
[0293] The technical solution provided by the present application may realize the multiplication operation and the offset operation of the neural network through an instruction (that is, the neural network operation instruction), and the intermediate results of the neural network operation may be performed without storage and extraction operations, which may reduce the storage and extraction operations of the intermediate data. Therefore, the technical solution provided by the present application may reduce the corresponding operational steps and improve the computational effect of the neural network.
[0294] A machine learning operation device may be further provided. The machine learning operation device may include one or more computation devices mentioned in the present disclosure for acquiring data to be processed and control information from other processing devices, performing specified machine learning computations, and transmitting execution results to peripheral devices through I/O interfaces. The peripherals include cameras, monitors, mice, keyboards, network cards, WIFI interfaces, servers, and the like. If multiple computation devices are provided, the computation devices may link and transfer data with each other through a specific structure. For example, data may be interconnected and transmitted via the PCIE bus, so as to support larger scale machine learning computations. In this case, the multiple computation devices may share the same control system, or have separate control systems. Further, the multiple computation devices may share the same memory, or each accelerator may have its own memory. In addition, the interconnection method may be any interconnection topology.
[0295] The machine learning operation device may have high compatibility and may be coupled with various types of servers through the PCIE interface.
[0296] The present disclosure also discloses a combined processing device, which may include the abovementioned machine learning operation device, universal interconnection interfaces, and other processing devices. The machine learning operation device interacts with other processing devices to perform userspecified operations. FIG. 6 is a schematic diagram illustrated the combined processing device.
[0297] The other processing devices may include at least one of general purpose/dedicated processors such as a central processing unit (CPU), a graphics processing unit (GPU), a machine learning processor, and the like. The number of processors included in other processing devices is not limited. The other processing devices served as an interface between the machine learning operation device and external data and control, may include data handling, and perform the basic control of start and stop operations of the machine learning operation device. The other processing devices may also cooperate with the machine learning operation device to complete the computing task.
[0298] The universal interconnection interfaces for transmitting data and control instructions between the machine learning operation device and the other processing devices. The machine learning operation device may obtain the input data required from the other processing devices, and writes the input data required into onchip storage devices of the machine learning operation device. The machine learning operation device may acquire control instructions from the other processing devices, and writes the control instructions into onchip control caches of the machine learning operation device. The machine learning operation device may read data in the storage module of the machine learning operation device and transmit the data to the other processing devices.
[0299] In an example, a structure of another combined processing device is as illustrated in FIG. 7. A storage device may be further provided, the storage device is respectively coupled with the machine learning operation device and the other processing device. The storage device may be configured to store data in the machine learning operation device and the other processing devices, and is particularly suitable for storing data to be processed which may not be completely stored in the internal storage of the machine learning operation device or the other processing devices.
[0300] The combined processing device may be used as an SOC onchip system of devices such as mobile phones, robots, drones, video monitoring devices, etc., thereby effectively reducing the core area of control parts, increasing the processing speed, and reducing the overall power consumption. In this case, the universal interconnection interfaces of the combined processing device are coupled with certain components of the device. The components may include cameras, monitors, mice, keyboards, network cards, and WIFI interfaces.
[0301] In an example, a distributed system is also applied. The distributed system may include n1 main processors and n2 coprocessors. The n1 is an integer greater than or equal to zero, and the n2 is an integer greater than or equal to one. The distributed system may be various types of topologies including, but not limited to, topologies illustrated in FIG. 3B, FIG. 3C, FIG. 11, and FIG. 12.
[0302] The main processor transmits the input data, the decimal point position of the input data, and the computation instruction to the multiple coprocessors. Alternatively, the main processor transmits the input data, the decimal point position of the input data and the computation instruction to some of the multiple coprocessors, and the some coprocessors further transmit the input data, the decimal point position of the input data, and the computation instruction to other coprocessors. The coprocessor may include the abovementioned computation device, and the computation device performs operations on the input data according to the aboveidentified method and the computation instruction to obtain an operation result.
[0303] The input data may include, but not limited to, input neurons, weights, offset data, and the like.
[0304] The coprocessor sends the operation result directly to the main processor. Alternatively, the coprocessor without coupling relationship with the main processor sends the operation result to the coprocessor coupled with the main processor, and then the coprocessor coupled with the main processor transmits the operation result received to the main processor.
[0305] In some examples, a chip may be provided. The chip may include the abovementioned machine learning operation device or the combination processing device.
[0306] In some examples, a chip package structure may be provided. The chip package structure may include the abovementioned chip.
[0307] In some examples, a board is provided. The board may include the abovementioned chip package structure.
[0308] In some examples, an electronic device may be provided. The electronic device may include the abovementioned board. A board is illustrated in FIG. 8. In addition to the chip 389, the board may also include other supporting components including, but not limited to, a storage device 390, a receiving device 391, and a control device 392.
[0309] The memory device 390 for storing data is coupled with the chip in the chip package structure via a bus. The memory device may include multiple sets of storage units 393. Each set of the storage units 393 is coupled with the chip via the bus. It may be understood that each set of the storage units 393 may be a double data rate synchronous dynamic random access memory (DDR SDRAM).
[0310] The double data rate (DDR) is capable to double the speed of SDRAM without increasing the clock frequency. The DDR allows data to be read on rising and falling edges of the clock pulse. The DDR is twice as fast as the standard SDRAM. In one example, the storage device may include four sets of the storage units. Each set of the memory cells may include multiple DDR4 particles (chips). In one example, the chip may internally include four 72bit DDR4 controllers. 64 bits of the 72bit DDR4 controller are used for data transmission, and 8 bits of the 72bit DDR4 controller are used for error checking and correcting (ECC) verification. It should be understood that if DDR43200 particles are used in each set of the storage units, a theoretical bandwidth of data transmission may reach 25600 MB/s.
[0311] In one example, each set of the memory cells may include multiple double rate synchronous dynamic random access memories arranged in parallel. The DDR may transfer data twice in one clock cycle. A controller for controlling the DDR is provided in the chip for controlling data transmission and data storage for each of the storage units.
[0312] The interface device is electrically coupled with the chip within the chip package structure. The interface device may be configured to implement data transmission between the chip and external devices such as a server and a computer. For example, in one example, the interface device may be a standard PCIE interface. For example, the data to be processed is transmitted to the chip by the server through a standard PCIE interface to implement data transmission. Preferably, if the data to be processed is transmitted over the PCIE 3.0 X 16 interface, the theoretical bandwidth may reach 16000 MB/s. In another example, the interface device may also be another interface. The application does not limit the specific expression of the other interfaces, and an interface unit capable of implementing the transfer function will be available. In addition, the computation result of the chip is still transmitted by the interface device back to the external devices (such as a server).
[0313] The control device is electrically coupled with the chip. The control device may be configured to monitor the status of the chip. Specifically, the chip may be electrically coupled with the control device through an SPI interface. The control device may include a micro controller unit (MCU). For example, the chip may include multiple processing chips, multiple processing cores, or multiple processing circuits, and multiple loads may be driven. Therefore, the chip may be in different operating states such as multiple loads and light loads. The control device may implement the control of the operating states of the multiple processing chips, the multiple processing cores, and/or the multiple processing circuits in the chip.
[0314] The electronic device may include data processing devices, robots, computers, printers, smayners, tablets, smart terminals, mobile phones, driving recorders, navigators, sensors, cameras, servers, cloud servers, cameras, cameras, projectors, watches, headphones, mobile storage, wearable devices, vehicles, household appliances, and/or medical devices.
[0315] The vehicle may include an aircraft, a ship, and/or a car. The household appliance may include a television, an air conditioner, a microwave oven, a refrigerator, a rice cooker, a humidifier, a washing machine, an electric lamp, a gas stove, a range hood. The medical device may include a nuclear magnetic resonance instrument, a Bultrasound, and/or an electrocardiograph.
[0316] FIG. 9 is a schematic flow chart of a method for executing machine learning computations according to an example of the present disclosure. The method may include the following steps.
[0317] At S901, obtaining, by the computation device, first input data and a computation instruction,
where the first input data may include input neurons and weights.
[0318] At S902, parsing, by the computation device, the computation instruction to obtain a data conversion instruction and an at least one operation instruction,
where the data conversion instruction may include a data conversion instruction including an opcode field and an opcode, where the opcode indicates a function of the data conversion instruction, and the opcode field of the data conversion instruction may include information of a decimal point position, a flag bit indicating a data type of the first input data, and an identifier of data type conversion.
[0319] At S903, converting, by the computation device, the first input data into second input data according to the data conversion instruction, where the second input data is fixedpoint data,
where the converting the first input data into second input data by the computation device according to the data conversion instruction includes:
parsing the computation instruction to obtain information of the decimal point position, the flag bit indicating a data type of the first input data, and the data type conversion;
determining the data type of the first input data according to the flag bit indicating the data type of the first input data; and
converting the first input data into the second input data according to the decimal point position and the data type conversion. The data type of the first input data is inconsistent with that of the second input data.
[0320] If the first input data and the second input data are fixedpoint data, the decimal point position of the first input data is inconsistent with that of the second input data.
[0321] In an example, if the first input data is fixedpoint data, the method may further include: deriving a decimal point position of at least one intermediate result according to the decimal point position of the first input data, where the at least one intermediate result is derived according to the first input data.
[0322] At S904, performing, by the computation device, operations on the second input data according to the multiple operation instructions to obtain a computation result of the computation instruction.
[0323] The operation instruction may include a forward operation instruction and a reverse training instruction. In other words, in the process of executing the forward operation instruction and the reverse training instruction (that is, the computation device performs the forward operation and/or the reverse training), the computation device may convert the data involved in operations into fixedpoint data according to the example illustrated in FIG. 9 to perform fixedpoint operations.
[0324] It should be noted that the detailed description of the foregoing steps S901S904 may be referred to the related description of the example illustrated in FIGS. 1 to 8, which are not described herein.
[0325] In a specific application scenario, the computation device may convert the data involved in operations into fixedpoint data, and adjust the decimal point position of the fixedpoint data. The specific process is illustrated in FIG. 10. The method may include the following steps.
[0326] At S1001, obtaining, by the computation device, the first input data.
[0327] The first input data is data involved in operations of m
^{th} layer of a multilayer network model, and the first input data is any type of data. For example, the first input data is fixedpoint data, floating point data, integer data or discrete data, and m is an integer greater than zero.
[0328] The m
^{th} layer of the abovementioned multilayer network model is a linear layer, and the linear layer may include, but not limited to, a convolution layer and a fully coupled layer. The abovementioned first input data may include input neurons, weights, output neurons, input neuron derivatives, weight derivatives, and output neuron derivatives.
[0329] At S1002, determining, by the computation device, a decimal point position of the first input data and a bit width of the fixedpoint data.
[0330] The bit width of fixedpoint data of the first input data is bits occupied by the first input data represented by fixedpoint data. The abovementioned decimal point position is bits occupied by a fractional part of the first data represented by fixedpoint data. The decimal point position may be configured to indicate the accuracy of the fixedpoint data. Referring to the related description of FIG. 2A for details.
[0331] In an example, the first input data may be any type of data, and first input data
a is converted into the second input data
â according to the decimal point position and the bit width of the fixedpoint data, which is described as follows.
[0332] If the first input data
a satisfies a condition of
neg ≤
a ≤
pos, second input data
â is represented as 
a / 2
^{s} ∗ 2
^{s}. If the first input data
a is greater than
pos, the second input data
â is represented as
pos. If the first input data
a is less than
neg, the second input data
â is represented as
neg.
[0333] In an example, input neurons, weights, output neurons, input neuron derivatives, output neuron derivatives, and weight derivatives of a convolutional layer and a fully coupled layer are represented by fixedpoint data.
[0334] In an example, the bit width of fixedpoint data of the input neuron may be 8, 16, 32, 64, or other bits. Specifically, the bit width of fixedpoint data of the input neuron is 8.
[0335] In an example, the bit width of fixedpoint data of the weight may be 8, 16, 32, 64, or other bits. Specifically, the bit width of the fixedpoint data of the weight is 8.
[0336] In an example, the bit width of fixedpoint data of the input neuron derivative may be 8, 16, 32, 64, or other bits. Specifically, the bit width of fixedpoint data of the input neuron derivative is 16 bits.
[0337] In an example, the bit width of fixedpoint data of the output neuron derivative may be 8, 16, 32, 64, or other bits. Specifically, the bit width of fixedpoint data of the output neuron derivative is 24 bits.
[0338] In an example, the bit width of fixedpoint data of the weight derivative may be 8, 16, 32, 64, or other bits. Specifically, the bit width of fixedpoint data of the weight derivative is 24 bits.
[0339] In an example, the data
a with a large value in data involved in a multilayer network model operation may adopt multiple representation manners of fixedpoint data. Referring to the related description of FIG 2B for details.
[0340] In an example, the first input data may be any type of data, and the first input data
a is converted into the second input data
â according to the decimal point position and the bit width of fixedpoint data, which is described as follows.
[0341] If the first input data
a satisfies a condition of
neg ≤
a ≤
pos, the second input data
â is represented as
where
â_{0} = 0. If the first input data
a is greater than
pos, the second input data
â is represented as
pos. If the first input data
a is less than
neg, the second input data
â is represented as
neg
[0342] At S1003, initializing, by the computation device, a decimal point position of the first input data and adjusts the decimal point position of the first input data.
[0343] The above decimal point position
s need to be initialized and dynamically adjusted according to data of different categories, data of different neural network layers, and data of different iteration rounds.
[0344] An initialization process of the decimal point position
s of the first input data is specifically described as follows, for example, the decimal point position adopted by the fixedpoint data is determined if converting the first input data at the first time.
[0345] Where the initializing the computation device the decimal point position
s of the first input data includes:
initializing the decimal point position
s of the first input data according to the maximum absolute value of the first input data; initializing the decimal point position
s of the first input data according to the minimum absolute value of the first input data; initializing the decimal point position
s of the first input data according to relationship between different data types in the first input data; and initializing the decimal point position
s of the first input data according to the empirical value constant.
[0346] Specifically, the abovementioned initialization process is specifically described as follows.
[0347] At step (a), the computation device initializes the decimal point position
s of the first input data according to the maximum absolute value of the first input data.
[0348] The abovementioned computation device specifically initializes the decimal point positions of the first input data by performing an operation shown by the following formula.
[0349] The
a_{max} represents the maximum absolute value of the first input data. The
bitnum represents the bit width of the fixedpoint data converted from the first input data. The
s_{a} represents the decimal point position of the first input data.
[0350] According to categories and network levels, the data involved in operations may be divided into the input neuron
X^{(l)}, the output neuron
Y^{(l)}, the weight
W^{(l)}, the input neuron derivative ∇
_{X}^{(l)}, the output neuron derivative ∇
_{Y}^{(l)}, and the weight derivative ∇
_{W}^{(l)} of the
lth layer. The maximum absolute value may be searched by one of manners including searching by data category, searching by layer and data category, searching by layer, data category, and group. Determining the maximum absolute value of the first input data may include the following methods.
[0351] At step (a.1), the computation device searches the maximum absolute value by data category.
[0352] Specifically, the first input data may include each element
a_{i}^{(l)} in a vector/matrix, where the element
a_{i}^{(l)} may be an input neuron X
^{(l)}, an output neuron
Y^{(l)}, a weight
W^{(l)}, an input neuron derivative ∇
_{X}^{(l)}, an output neuron derivative ∇
_{Y}^{(l)}, or a weight derivative ∇
_{W}^{(l)}. In other words, the abovementioned first input data may include input neurons, weights, output neurons, input neuron derivatives, weight derivatives, and output neuron derivatives. The abovementioned decimal point position of the first input data may include a decimal point position of the input neuron, a decimal point position of the weight, a decimal point position of the output neuron, a decimal point position of the input neuron derivative, a decimal point position of the weight derivative, and a decimal point position of the neuron derivative. The input neurons, the weights, the output neurons, the input neuron derivatives, the weight derivatives, and the output neuron derivatives are all represented in a matrix or vector form. The computation device acquires the maximum absolute value (that is,
) of each category data by traversing all elements in the vector/matrix of each layer of the abovementioned multilayer network model. The decimal point position
s_{a} of the fixedpoint data converted from the input data
a of each category data is determined by a formula of
s_{a} = ┌log
_{2}a_{max} 
bitnum +1┐.
[0353] At step (a.2), the computation device searches the maximum absolute value by layer and data category.
[0354] Specifically, the first input data may include each element
a_{i}^{(l)} in a vector/matrix, where the
a^{(l)} may be an input neuron
X^{(l)}, an output neuron
Y^{(l)}, a weight
W^{(l)}, an input neuron derivative ∇
_{X}^{(l)}, an output neuron derivative ∇
_{Y}^{(l)}, or a weight derivative ∇
_{W}^{(l)}. In other words, each layer of the abovementioned multilayer network model may include input neurons, weights, output neurons, input neuron derivatives, weight derivatives, and output neuron derivatives. The abovementioned decimal point position of the first input data may include a decimal point position of the input neuron, a decimal point position of the weight, a decimal point position of the output neuron, a decimal point position of the input neuron derivative, a decimal point position of the weight derivative, and a decimal point position of the neuron derivative. The input neurons, the weights, the output neurons, the input neuron derivatives, the weight derivatives, and the output neuron derivatives are all represented in a matrix or vector form. The computation device acquires the maximum absolute value (that is,
) of each category data by traversing all elements in the vector/matrix of each data of each layer of the abovementioned multilayer network model. The decimal point position
of the input data
a of each category of
lth layer is determined by a formula of
[0355] At step (a.3), the computation device searches the maximum absolute value by layer, data category, and group.
[0356] Specifically, the first input data may include each element
a_{i}^{(l)} in a vector/matrix, where
a^{(l)} may be input neurons X
^{(l)}, output neurons
Y^{(l)}, weights
W^{(l)}, an input neuron derivative ∇
_{X}^{(l)}, an output neuron derivative ∇
_{Y}^{(l)}, or a weight derivative ∇
_{W}^{(l)}. In other words, data categories of each layer of the abovementioned multilayer network model may include input neurons, weights, output neurons, input neuron derivatives, weight derivatives, and output neuron derivatives. The abovementioned computation device divides data of each category of each layer of the abovementioned multilayer network model into g groups, or into groups by other arbitrary grouping rules. The computation device then traverses each element of each group of data in the g groups data corresponding to the data of each category of each layer of the abovementioned multilayer network model, and obtains the element with the largest absolute value (that is,
) in the group of data. The decimal point position
of data of each group of the g groups data corresponding to each category of each layer is determined by a formula of
[0357] The foregoing arbitrary grouping rules include, but are not limited to, rule for grouping according to data ranges, rule for grouping according to data training batches, and the like.
[0358] At step (b), the computation device initializes the decimal point position
s of the first input data according to the maximum absolute value of the first input data.
[0359] Specifically, the computation device determines the minimum absolute value
a_{min} of data to be quantized, and determines the fixedpoint precision s by the following formula.
[0360] The abovementioned
a_{min} is the minimum absolute value of the first input data. For the process of acquiring
a_{min}, please refer to the aboveidentified steps (a. 1), (a.2), and (a.3).
[0361] At step (c), the computation device initializes the decimal point position
s of the first input data according to the relationship between different data types in the first input data.
[0362] Specifically, the decimal point position
of the data type
a^{(l)} of any layer (such as the first layer) of the multilayer network model is determined by the abovementioned operation unit 12 according to the decimal point position
of the data type
b^{(l)} of the first layer and a formula of
[0363] The
a^{(l)} and b
^{(l)} may be input neurons
X^{(l)}, output neurons
Y^{(l)}, weights
W^{(l)}, input neuron derivatives ∇
_{X}^{(l)}, output neuron derivatives ∇
_{Y}^{(l)}, or weight derivatives ∇
_{W}^{(l)}. The
a^{(l)} and b
^{(l)} are integer constants.
[0364] At step (d), the computation device initializes the decimal point position
s of the first input data according to the empirical value constant.
[0365] Specifically, the decimal point position
s_{a}^{(l)} of the data type
a^{(l)} of any layer (such as the first layer) of the multilayer network model may be artificially set as
s_{a}^{(l)} =
c, where c is an integer constant. The abovementioned
a^{(l)} may be input neurons
X^{(l)}, output neurons
Y ^{(l)}, weights
W^{(l)}, input neuron derivatives ∇
_{X}^{(l)}, output neuron derivatives ∇
_{Y}^{(l)}, or weight derivatives ∇
_{W}^{(l)}.
[0366] Further, an initialization value of the decimal point position of the input neuron and an initialization value of the decimal point position of the output neuron may be selected within the range of [8, 8]. An initialization value of the decimal point position of the weight may be selected within the range of [17, 8]. An initialization value of the decimal point position of the input neuron derivative and an initialization value of the decimal point position of the output neuron derivative may be selected within the range of [40, 20]. An initialization value of the decimal point position of the weight derivative may be selected within the range of [48, 12].
[0367] The method of dynamically adjusting the abovementioned decimal point position of the data by the abovementioned computation device will be specifically described as follows.
[0368] The method of dynamically adjusting the abovementioned decimal point position s by the abovementioned computation device may include adjusting the abovementioned decimal point position s upwards (that is, value of the decimal point position s becomes larger) and adjusting the abovementioned decimal point position s downwards (that is, value of the decimal point position s becomes smaller). Specifically, the abovementioned decimal point position s is adjusted upwardly by a single step according to the maximum absolute value of the first input data. The abovementioned decimal point position s is adjusted upwardly step by step according to the maximum absolute value of the first input data. The abovementioned decimal point position s is adjusted upwardly by a single step according to the first input data distribution. The abovementioned decimal point position s is adjusted upwardly step by step according to the first input data distribution. The abovementioned decimal point position s is adjusted downwardly according to the absolute value of the first input date.
[0369] In case (a), the computation device upwardly adjusts the abovementioned decimal point position
s by a single step according to the maximum absolute value of the first input data.
[0370] Assuming that the abovementioned decimal point position is
s_old before being adjusted, the fixedpoint data corresponding to the decimal point position
s_old may represent data with a range of [
neg,
pos], where
pos = (2
^{bitnum1}1)
^{∗}2
^{s_old},
neg = (2
^{bitnum1}1)
^{∗}2
^{s_old}. If the maximum absolute value
a_{max} of the data in the first input data is greater than and equal to
pos, the decimal point position adjusted is
s_
new = ┌log
_{2} a_{max}
bitnum +1┐; otherwise, the abovementioned decimal point position will not be adjusted, that is,
s_
new =
s_old.
[0371] In case (b), the computation device upwardly adjusts the abovementioned decimal point position s step by step according to the maximum absolute value of the first input data.
[0372] Assuming that the abovementioned decimal point position is
s_
old before being adjusted, the fixedpoint data corresponding to the decimal point position
s_
old may represent data with a range of [
neg,
pos], where
pos = (2
^{bitnum1}1)
^{∗}2
^{s_old},
neg = (2
^{bitnum1}1)
^{∗}2
^{s_old}. If the maximum absolute value
a_{max} of the data in the first input data is greater than and equal to
pos, the decimal point position adjusted is
s_
new =
s_
old+1; otherwise, the abovementioned decimal point position will not be adjusted, that is,
s_
new =
s_
old.
[0373] In case (c), the computation device upwardly adjusts the abovementioned decimal point position
s by single step according to the first input data distribution.
[0374] Assuming that the abovementioned decimal point position is
s_old before being adjusted, the fixedpoint data corresponding to the decimal point position
s_
old may represent data with a range of [
neg,
pos], where
pos = (2
^{bitnum1}1)
^{∗}2
^{s_old},
neg = (2
^{bitnum1}1)
^{∗}2
^{s_old}. Statistical parameters of the absolute value of first input data are processed, such as a mean value
a_{mean} of the absolute value and a standard deviation
a_{std} of the absolute value. The maximum range of data is set as
a_{max} =
a_{mean} +
na_{std}. If
a_{max} ≥
pos,
s_
new = ┌log
_{2} a_{max} 
bitnum + 1┐; otherwise, the abovementioned decimal point position will not be adjusted, that is,
s_
new =
s_
old.
[0375] Further, the abovementioned n may be two or three.
[0376] In case (d), the computation device upwardly adjusts the abovementioned decimal point position
s step by step according to the first input data distribution.
[0377] Assuming that the abovementioned decimal point position is
s_
old before being adjusted, the fixedpoint data corresponding to the decimal point position
s_
old may represent data with a range of [
neg,
pos], where
pos = (2
^{bitnum1}1)
^{∗}2
^{s_old},
neg = (2
^{bitnum1}1)
^{∗}2
^{s_old}. The statistical parameters of the absolute value of first input data are processed, such as the mean value
a_{mean} of the absolute value and the standard deviation
a_{std} of the absolute value. The maximum range of data is set as
a_{max} =
a_{mean} +
na_{std}, where n is three. If
a_{max} ≥
pos,
s_new =
s_old + 1; otherwise, the abovementioned decimal point position will not be adjusted, that is,
s_
new =
s_
old.
[0378] In case (e), the computation device downwardly adjusts the abovementioned decimal point position
s according to the maximum absolute value of the first input date.
[0379] Assuming that the abovementioned decimal point position is
s_
old before being adjusted, the fixedpoint data corresponding to the decimal point position
s_
old may represent data with a range of [
neg,
pos], where
pos = (2
^{bitnum1}1)
^{∗}2
^{s_old},
neg = (2
^{bitnum1}1)
^{∗}2
^{s_old}. If the maximum absolute value
a_{max} of the first input date is less than 2
^{s_old+(bitnumn)} and
s_
old ≥
s_{min},
s_new =
s_
old, where the n is an integer constant, and the
s_{min} may be an integer or a negative infinity.
[0380] Further, the abovementioned n is three, and the abovementioned
s_{min} is 64.
[0381] In an example, an adjusting frequency of the decimal point position may be determined as follows. The decimal point position of the first input data may never be adjusted. Alternatively, the decimal point position of the first input data may be adjusted every n first training cycles (i.e., iteration), where the n is a constant. Alternatively, the decimal point position of the first input data may be adjusted every n second training cycles (i.e., epoch), where the n is a constant. Alternatively, the decimal point position of the first input data may be adjusted every n first training periods or n second training periods, and adjusting the decimal point position of the first input data every n first training periods or second training periods, and then the n may be adjusted, that is,
n =
αn, where
α is greater than one. Alternatively, the decimal point position of the first input data may be adjusted every n first training period or second training period, and the n is gradually decreased as the number of training rounds increases.
[0382] Further, the decimal point position of the input neuron, the decimal point position of the weight, and the decimal point position of the output neuron may be adjusted every 100 first training cycles. The decimal point position of the input neuron derivative and the decimal point position of the output neuron derivative may be adjusted every 20 first training cycles.
[0383] It should be noted that the first training period is the time required to train a batch of samples, and the second training period is the time required to perform training for all training samples.
[0384] It should be noted that the decimal point position of the above data is initialized and adjusted according to the average value or the intermediate value of the absolute value of the above data. Specific details may refer to the aboveidentified related description of initializing and adjusting the decimal point position of the above data according to the maximum value of the absolute value of the data, which will not be described herein.
[0385] It is to be noted that, for the sake of simplicity, the foregoing method examples are described as a series of action combinations, however, it will be appreciated by those skilled in the art that the present disclosure is not limited by the sequence of actions described. According to the present disclosure, certain steps or operations may be performed in other order or simultaneously. Besides, it will be appreciated by those skilled in the art that the examples described in the specification are exemplary examples and the actions and modules involved are not necessarily essential to the present disclosure.
[0386] In the foregoing examples, the description of each example has its own emphasis. For the parts not described in detail in one example, reference may be made to related descriptions in other examples.
[0387] In the examples of the disclosure, it should be understood that, the apparatus disclosed in examples provided herein may be implemented in other manners. For example, the device/apparatus examples described above are merely illustrative; for instance, the division of the unit is only a logical function division and there may be other manners of division during actual implementations, for example, multiple units or components may be combined or may be integrated into another system, or some features may be ignored, omitted, or not performed. In addition, coupling or communication connection between each illustrated or discussed component may be direct coupling or communication connection, or may be indirect coupling or communication among devices or units via some interfaces, and may be electrical connection, mechanical connection, or other forms of connection.
[0388] The units described as separate components may or may not be physically separated, the components illustrated as units may or may not be physical units, that is, they may be in the same place or may be distributed to multiple network elements. All or part of the units may be selected according to actual needs to achieve the purpose of the technical solutions of the examples.
[0389] In addition, the functional units in various examples of the present disclosure may be integrated into one processing unit, or each unit may be physically present, or two or more units may be integrated into one unit. The abovementioned integrated unit may be implemented in the form of hardware or a software function unit.
[0390] The integrated unit may be stored in a computerreadable memory if it is implemented in the form of a software functional unit and is sold or used as a separate product. Based on such understanding, the technical solutions of the present disclosure essentially, or the part of the technical solutions that contributes to the related art, or all or part of the technical solutions, may be embodied in the form of a software product which is stored in a memory and may include instructions for causing a computer device (which may be a personal computer, a server, or a network device and so on) to perform all or part of the steps described in the various examples of the present disclosure. The memory may include various medium capable of storing program codes, such as a USB (universal serial bus) flash disk, a readonly memory (ROM), a random access memory (RAM), a removable hard disk, Disk, compact disc (CD), or the like.
[0391] It will be understood by those of ordinary skill in the art that all or a part of the various methods of the examples described above may be accomplished by means of a program to instruct associated hardware. The program may be stored in a computerreadable memory, which may include a flash memory, a readonly memory (ROM), a randomaccess memory (RAM), a disk or a compact disc (CD), and so on.
[0392] The examples of the present disclosure are described in detail above, specific examples are used herein to describe the principle and implementation manners of the present disclosure. The description of the above examples is merely used to help understand the method and the core idea of the present disclosure. Meanwhile, those skilled in the art may make modifications to the specific implementation manners and the application scope according to the idea of the present disclosure. In summary, the contents of the specification should not be construed as limiting the present disclosure.