This application relates to the chip field, including floating-point operation control.
A multiply accumulator used for floating-point operation is used as a basic operation unit, and is a core component on a chip such as a graphics processing unit (GPU), an artificial intelligence (AI) chip, a central processing unit (CPU), a field-programmable gate array (FPGA), or an application specific integrated circuit (ASIC).
Different hardware structures need to be used for floating-point operation with bit widths of FP16, FP32, and FP64. For example, FP64 floating-point operation uses a set of hardware structure, FP16 floating-point operation and FP32 floating-point operation use a set of hardware structure, and the two sets of hardware structures are mutually independent. Even though FP16 floating-point operation and FP32 floating-point operation use one set of hardware structure, an operation bit width used when FP16 floating-point operation performs a multiplication operation of a fractional part is 16 bits, and an operation bit width used when FP32 floating-point operation performs a multiplication operation of a fractional part is 32 bits.
Embodiments of this disclosure provide a chip, a terminal, a floating-point operation control method, and a related apparatus. A floating-point number of a high bit width is split into operands of low bit widths to perform a multiply accumulate operation, so that a single hardware structure can support multiply accumulate operations of floating-point numbers of a plurality of bit widths, and it is unnecessary to integrate at least two sets of hardware structures or integrate many operation units on the chip to support multiply accumulate operations of floating-point numbers of a plurality of bit widths, thereby effectively reducing an area of the chip and reducing power consumption during running of the chip. The technical solutions are as follows.
In an embodiment, a chip includes a multiply accumulator, the multiply accumulator including an input configured to receive a floating-point number, a first selection input, a floating-point general-purpose processing circuitry, and an output circuitry. The floating-point general-purpose processing circuitry is separately connected to the input configured to receive the floating-point number and the first selection input. An output of the floating-point general-purpose processing circuitry is connected to an input of the output circuitry. The floating-point general-purpose processing circuitry is configured to receive a first operand, a second operand, and a third operand. Each of the first operand, the second operand, and the third operand has a first bit width k1 and are inputted at the input configured to receive the floating-point number. The floating-point general-purpose processing circuitry is further configured to divide a fractional part of the first operand into m first suboperands of a second bit width k2 according to a floating-point operation mode indicated by the first selection input, and divide a fractional part of the second operand into m second suboperands of the second bit width k2. The second bit width k2=k1/m, and m is a positive integer. The floating-point general-purpose processing circuitry is further configured to perform a multiplication operation of fractional parts based on the m first suboperands and the m second suboperands to obtain a fractional product, and determine a floating-point number product of the first operand and the second operand based on a sign bit and an exponent part of the first operand, a sign bit and an exponent part of the second operand, and the fractional product. The floating-point general-purpose processing circuitry is further configured to perform an addition operation on the floating-point number product and the third operand to obtain a floating-point number. The output circuitry is configured to output an operation result in a specified data format according to the floating-point number sum.
In an embodiment, a floating-point operation control method is applied to a chip comprising a multiply accumulator. The method includes receiving a first selection signal, and controlling an operation circuit in the multiply accumulator to be an operation circuit corresponding to a floating-point operation mode indicated by the first selection signal. The floating-point operation mode supports a multiply accumulate operation of a floating-point number of a first bit width k1, The method further includes receiving a first operand, a second operand, and a third operand, each of the first operand, the second operand, and the third operand having the first bit width k1. The method further includes dividing a fractional part of the first operand into m first suboperands of a second bit width k2, and dividing a fractional part of the second operand into m second suboperands of the second bit width k2, the second bit width k2=k1/m, and m being a positive integer. The method further includes performing a multiplication operation of fractional parts based on the m first suboperands and the m second suboperands to obtain a fractional product, and determining a floating-point number product of the first operand and the second operand based on a sign bit and an exponent part of the first operand, a sign bit and an exponent part of the second operand, and the fractional product. The method further includes performing an addition operation on the floating-point number product and the third operand to obtain a floating-point number sum, and outputting an operation result in a specified data format according to the floating-point number sum.
In an embodiment, a non-transitory computer-readable storage medium stores computer-readable instructions thereon, which, when executed by a chip comprising a multiply accumulator, cause the chip to perform a floating-point operation control method. The method includes receiving a first selection signal, and controlling an operation circuit in the multiply accumulator to be an operation circuit corresponding to a floating-point operation mode indicated by the first selection signal. The floating-point operation mode supports a multiply accumulate operation of a floating-point number of a first bit width k1, The method further includes receiving a first operand, a second operand, and a third operand, each of the first operand, the second operand, and the third operand having the first bit width k1. The method further includes dividing a fractional part of the first operand into m first suboperands of a second bit width k2, and dividing a fractional part of the second operand into m second suboperands of the second bit width k2, the second bit width k2=k1/m, and m being a positive integer. The method further includes performing a multiplication operation of fractional parts based on the m first suboperands and the m second suboperands to obtain a fractional product, and determining a floating-point number product of the first operand and the second operand based on a sign bit and an exponent part of the first operand, a sign bit and an exponent part of the second operand, and the fractional product. The method further includes performing an addition operation on the floating-point number product and the third operand to obtain a floating-point number sum, and outputting an operation result in a specified data format according to the floating-point number sum.
The floating-point general-purpose unit (floating-point general-purpose processing circuitry) is arranged in the multiply accumulator on the chip. In different floating-point operation modes, the floating-point general-purpose unit may split a floating-point number of a high bit width into suboperands of low bit widths to perform a multiply accumulate operation. Floating-point numbers of different high bit widths may be split into different quantities of suboperands of low bit widths. Correspondingly, the floating-point general-purpose unit controls, according to selection of a floating-point operation mode, a multiplier and an adder in the multiply accumulator to perform splitting and reassembly, and an operation circuit in the multiply accumulator becomes an operation circuit corresponding to the floating-point operation mode so as to perform a multiply accumulate operation, so that the operation circuit can support a multiply accumulate operation of floating-point numbers of different bit widths, and there is no need to integrate at least two hardware structures on the chip to support the multiply accumulate operation of floating-point numbers of different bit widths. In addition, the multiplier and the adder can be reused, and a quantity of multipliers and adders arranged can be reduced, thereby effectively reducing an area of the chip and reducing power consumption during running of the chip.
To make objectives, technical solutions, and advantages of this disclosure clearer, the following further describes implementations of this disclosure in detail with reference to the accompanying drawings.
First, several terms involved in this disclosure are introduced.
A multiply accumulate (MAC) operation is an operation of multiplying a first operand A by a second operand B, and then adding a product and a third operand C. That is, Cout=A*B+C.
A multiply accumulator is a hardware circuit unit configured to implement a multiply accumulate operation in a digital signal processor or some microprocessors.
A fixed-point number is a representation method, of a number used in a computer, for ensuring that decimal point positions of all data in a machine are fixed. Two simple agreements are generally used in a computer: fixing a position of a decimal point before the highest bit of data, or fixing a position of a decimal point after the lowest bit. Generally, the former is often referred to as a fixed-point decimal, and the latter is often referred to as a fixed-point integer. When data is less than the minimum value that can be represented by a fixed-point number, the computer processes them as 0, called underflow. When the data is greater than the maximum value that can be represented by the fixed-point number, the computer cannot represent them, called overflow. Overflow and underflow are collectively referred to as overflow.
A floating-point number is an identification method of another number used in a computer, which is similar to scientific notation. Any binary number N may always be written as:
N=(−1)S*2E*M;
In the formula, M becomes a fractional part (also referred to as a mantissa) of the floating-point number N, and is a pure fractional; E is an exponent part (also referred to as an exponent) of the floating-point number N, and is an integer; and S is a sign bit of the floating-point number N. When the sign bit is 0, it indicates that the floating-point number N is positive, and when the sign bit is 1, it indicates that the floating-point number N is negative. This representation method is equivalent to that a decimal point position of a number may float freely with different scale factors within a specific range, and therefore, is referred to as a floating-point identification method.
Floating-point multiplication defines that, for a first floating-point number NA=(−1)Sa*2Ea*Ma and a second floating-point number NB=(−1)Sb*2Eb*Mb, a product of the two floating-point numbers is as follows:
N
A
*N
B=(−1)(Sa+Sb)*2(Ea+Eb)*(Ma*Mb).
As a basic calculation unit, a multiply accumulator is widely used in a chip such as a CPU, a GPU, and an AI chip. With popularization of application scenarios such as AI, big data processing, and new air interface technologies, a high-performance floating-point operation becomes a main indicator of a chip. Because a floating-point calculation unit occupies more than 80% of an overall service operation amount, a hardware architecture that meets a plurality of factors such as universality, operation performance, and chip area is required. Therefore, this disclosure proposes a chip including a multiply accumulator, which features universality, scalability, smaller area, wider application, and better performance, and is applicable to products such as a GPU, an AI chip, a CPU, a DSP, and a dedicated chip.
The chip including a multiply accumulator provided in this disclosure can cover the following three features.
First, the chip has a smaller area but higher universality, that is, the chip is scalable. The same set of hardware structure is fully compatible with floating-point number operations of a plurality of bit widths. For example, floating-point number operations of a plurality of bit widths such as FP16, FP32, FP64, and even FP128 can be supported by using only one set of hardware structure.
Second, a customized floating-point operation mode is supported. For example, a set of hardware structure includes 16 multipliers whose operation bit widths are 16 bits. Therefore, by using the floating-point operation method provided in this disclosure, the hardware structure can support calculation of one group of FP64 operations, can support calculation of two groups of FP32 operations, and can support calculation of four groups of FP16 operations. Calculation of up to 16 groups of FP16 operands at the same time can also be supported, and calculation of up to four groups of FP32 operands at the same time can be supported. While a non-extended floating-point operation mode is implemented, different types of floating-point operation modes can be customized. For example, a floating-point operation mode that supports calculation of eight groups of FP16 operands can be customized.
Third, performance is higher. For example, in addition to supporting a non-extended floating-point operation mode, a data extension interface is further reserved on the chip. For example, the chip supports calculation of two groups of FP32 operands in the non-extended floating-point operation mode. However, the chip can further support, by using the data extension interface, a floating-point operation mode in which four groups of FP32 operands are calculated. Therefore, floating-point operation performance is greatly improved. As shown in Table 1, a floating-point processing performance relationship of a GPU is as follows for processing cases of three floating-point operations: one group of PF64 operands, two groups of PF32 operands, and four groups of FP16 operands.
FP32 processing performance=FP64 processing performance*2;
FP16 processing performance=FP32 processing performance*4;
FP16 processing performance=FP64 processing performance*8;
A floating-point processing performance relationship of the chip provided in this disclosure is as follows:
FP32 processing performance=FP64 processing performance*4;
FP16 processing performance=FP32 processing performance*4;
FP16processing performance=FP64processing performance*16.
It may be concluded from Table 1 that, compared with the GPU in Table 1, on the chip provided in this disclosure, FP32 processing performance is improved by one time (100%), and FP16 processing performance is improved by one time (100%). Tera floating-point operations per second (TFLOPS) is a quantity of floating-point operations performed per second in a trillion unit.
The floating-point general-purpose unit 220 is configured to receive a first operand, a second operand, and a third operand of a first bit width k1 that are inputted at the input end of the floating-point number; divide a fractional part of the first operand into m first suboperands of a second bit width k2 according to a floating-point operation mode indicated by the first selection end, and divide a fractional part of the second operand into m second suboperands of the second bit width k2, m being a positive integer; perform a multiplication operation of fractional parts based on the m first suboperands and the m second suboperands to obtain a fractional product; determine a floating-point number product of the first operand and the second operand based on a sign bit and an exponent part of the first operand, a sign bit and an exponent part of the second operand, and the fractional product; perform an addition operation on the floating-point number product and the third operand to obtain a floating-point number sum; and the output unit 240 is configured to output an operation result of a specified data format according to the floating-point number sum.
The second bit width k2=k1/m, and k2 and k1 are each a multiple of 2.
Different selection signals are corresponding to different floating-point operation modes; the floating-point general-purpose unit 220 includes a data extraction unit 221, and the data extraction unit 221 is separately connected to the input ends A, B, and C of the floating-point number and the first selection end mode_1; the data extraction unit 221 is configured to determine a floating-point operation mode corresponding to a selection signal inputted by the first selection end mode_1, an operation circuit indicated by the floating-point operation mode being configured to perform a multiply accumulate operation on the floating-point number of the first bit width k1, and the first bit width k1 being corresponding to a quantity m of split floating-point numbers; perform division from a lower order of the fractional part of the first operand according to the second bit width k2 to obtain the m first suboperands; and perform division from a lower order of the fractional part of the second operand according to the second bit width k2 to obtain the m second suboperands.
For example, if the first bit width k1 is 32, and the second bit width k2 is 16, lower 16 bits in 24 bits (including significand bits) of the fractional part of the first operand may be mapped to a 16-bit first suboperand, and higher 8 bits are mapped to a 16-bit first suboperand. The mapping of the foregoing suboperand starts from lower bits of the 16-bit width. If fractional bits are insufficient, 0 is used as a complement, for example, bits 8-15 in the 16-bit first suboperand obtained after mapping of the higher 8 bits are all 0s.
For example, when an exponent part value is 0, the fractional part in the value S*2E*M includes an integer part 0, that is, the fractional part is actually 0.M. When the exponent part value is not 0, the fractional part in the value S*2E*M includes an integer part 1, that is, the fractional part is actually 1.M. In the foregoing two cases, before an operation is performed on the fractional part 0.M and/or 1.M, one integer bit, that is, a significand bit, needs to be supplemented before the fractional part M.
A fractional part of the floating-point number of the first bit width k1 supported by the floating-point operation mode is corresponding to a bit width N1, and a fractional part of an operand of a minimum bit width supported by the multiply accumulator is corresponding to a bit width N2; a remainder of N1 divided by m is calculated, and a difference obtained by subtracting the remainder from m is determined as a first parameter P1; a quotient value of a sum of N1 and P1 divided by m is calculated, and a difference obtained by subtracting N2 from the quotient value is determined as a second parameter P2; and in a case that both P1 and P2 are non-negative integers, m is determined as a split quantity corresponding to the floating-point number of the first bit width k1.
In the foregoing process, an operand of a high bit width may be split into a quantity m of operands of low bit widths. It is also proved that a floating-point number of a high bit width can be degraded and then calculated. That is, the operand of the high bit width has scalability and matches scalability to be achieved by the chip.
For example, if the first bit width k1 is 64, N1 is 53 (including significand bits). If the foregoing minimum bit width is 16, N2 is 11 (including significand bits). Assuming that m is 4, P1=P2=3 may be calculated based on the following formulas (1) to (3), and a fractional part of each floating-point number of the first bit width k1 may be split into four suboperands, where the formulas are as follows:
For example, the second bit width k2=16 is used as an example to describe a mapping manner of operands of different bit widths.
k2=16 is used as an example to describe a correspondence between an input signal and a floating-point operation mode. Table 2 shows a structural diagram of an input signal and an output signal in three operation modes in this example.
The foregoing is merely described by using 16 bits as an example. In different embodiments, possible designs with other numbers of bits, such as 64 bits, 32 bits, 16 bits, 8 bits, 4 bits, and 2 bits, may alternatively be used.
In conclusion, the chip provided in this embodiment includes a multiply accumulator, and a floating-point general unit is disposed in the multiply accumulator. In different floating-point operation modes, the floating-point general-purpose unit may split a floating-point number of a high bit width into suboperands of low bit widths to perform a multiply accumulate operation. Floating-point numbers of different high bit widths may be split into different quantities of suboperands of low bit widths. Correspondingly, the floating-point general-purpose unit controls, according to selection of a floating-point operation mode, a multiplier and an adder in the multiply accumulator to perform splitting and reassembly, and an operation circuit in the multiply accumulator becomes an operation circuit corresponding to the floating-point operation mode so as to perform a multiply accumulate operation, so that the operation circuit can support a multiply accumulate operation of floating-point numbers of different bit widths, and there is no need to integrate at least two hardware structures on the chip to support the multiply accumulate operation of floating-point numbers of different bit widths. In addition, the multiplier and the adder can be reused, and a quantity of multipliers and adders arranged can be reduced, thereby effectively reducing an area of the chip and reducing power consumption during running of the chip.
In an exemplary embodiment, as shown in
For example, as shown in
For another example, when a selection signal 1 indicates an operation of two groups of FP32 operands, a multiplier mul1, a multiplier mul2, a multiplier mul3, a multiplier mul4, a multiplier mul5, a multiplier mul6, a multiplier mul7, and a multiplier mul8 are split from a multiplication array including 16 multipliers when a multiplication operation is performed on the fractional parts of the first operand and the second operand. Eight adders are split from an addition array, and the eight adders and the eight multipliers are combined into one operation circuit. The operation circuit performs a multiplication operation on m first operands and m second operands to finally obtain a fractional product.
For another example, when a selection signal 2 indicates an operation of one group of FP64 operands, 16 multipliers in a multiplication array and 26 adders in an addition array are combined into an operation circuit when a multiplication operation is performed on the fractional parts of the first operand and the second operand, and the operation circuit performs a multiplication operation on m first suboperands and m second suboperands to finally obtain a fractional product.
For example, a multiplication operation of fractional parts of a group of FP32 operands is described in detail. As shown in
When a multiplication operation is performed on m first suboperands and m second suboperands, G adders need to be used for accumulating intermediate fractional products, and a quantity G of adders is determined based on m and an adder structure. For example, m=2 and 4 is used for describing a rule of a quantity of addition suboperands corresponding to each intermediate fractional product, where the addition suboperands include at least one of suboperands obtained after splitting of the intermediate fractional product and suboperands generated due to carrying. For example, as shown in
If carrying is considered, as shown in
In conclusion, the multiplier and the adder included in the multiply accumulator on the chip provided in this embodiment can be split and reassembled to form an operation circuit that supports a floating-point operation of a type corresponding to a floating-point operation mode, so as to implement calculation of fractional parts of the first operand and the second operand, which gives scalability to a multiplication operation of the fractional part, and can perform split calculation on a fractional part of a floating-point number with a high bit width, so that the multiply accumulator can support a multiplication operation of floating-point numbers with a plurality of bit widths.
In some exemplary embodiments, the floating-point general-purpose unit 220 includes a first mapping unit 223, a second operation unit 224, and a second mapping unit 225. As shown in
The first mapping unit 223 is configured to map the fractional product to a register according to a first specified format.
The second operation unit 224 is configured to: read the fractional product of the first specified format from the register, extend and generate a first intermediate result of a second specified format for the fractional product of the first specified format based on the sign bit and the exponent part of the first operand and the sign bit and the exponent part of the second operand; and extend and generate a second intermediate result of the second specified format for a fractional part of the third operand based on a sign bit and an exponent part of the third operand; and the second mapping unit 225 is configured to add the first intermediate result and the second intermediate result to obtain the floating-point number sum.
The fractional product includes an original integer part I and an original fractional part M; and the first mapping unit 223 is configured to cut the original integer part I according to an integer cutting bit width ε to obtain a cut integer part I′; cut the original fractional part M according to a fractional cutting bit width 3, to obtain a cut fractional part M′; and map the cut integer part I′ and the cut fractional part M′ to coordinates (X, Y) of the register to obtain the fractional product of the first specified format. For example,
I′
i-1
=I
i-1−εi-1; (4)
M′
i-1
=M
i-1−3i-1; (5)
0≤εi-1<Ii-1;εi-1 is an integer; (6)
0≤3i-1<Mi-1;3i-1 is an integer; (7)
Mapping formulas are as follows:
X
i-1
=I′
i-1+Offseti-1; (8)
Y
i-1=Offseti-1−M′i-1; (9)
S
i-1=2e-1−1+I′i-1+Offseti-1; (10)
T
i-1=Offseti-1−(2e-1−2+M′i-1); (11)
Offseti-1 refers to a location offset value corresponding to the ith group of operands, and the location offset value is a phenomenon that when a multiply accumulate operation is performed on at least two groups of operands at the same time, at least two fractional products need to be mapped to different locations, so that some data does not overlap between two fractional products; and e is a bit width of an exponent part of the ith group of operands, reserved space (Si-1, Ti-1) on the register is space reserved for a fractional product corresponding to the ith group of operands, and (Xi-1, Yi-1) is located in reserved space (Si-1, Ti-1).
The integer cutting bit width ε and the fractional cutting bit width 3 are set based on system requirements. The integer cutting bit width ε and the fractional cutting bit width 3 that are corresponding to floating-point numbers of different bit widths in a multiply accumulate operation process are different or the same. For example, an integer cutting bit width ε and a fractional cutting bit width 3 that are corresponding to an FP16 operand are different from an integer cutting bit width ε and a fractional cutting bit width 3 that are corresponding to an FP64 operand.
In a process of performing a multiply accumulate operation on i groups of operands, integer cutting bit widths ε and fractional cutting bit widths 3 that are corresponding to different groups of operands are different or the same. For example, in a floating-point operation mode in which four groups of FP16 operands are simultaneously calculated, an integer cutting bit width ε and a fractional cutting bit width 3 that are corresponding to the first group of FP16 operands are different from an integer cutting bit width ε and a fractional cutting bit width 3 that are corresponding to the second group of FP16 operands. The fractional product is cut to obtain a valid range of data or meet a specific application requirement, and a cutting range is not limited in this embodiment.
The second mapping unit 225 includes K basic operation units (basic operation circuits), two adjacent basic operation units are connected in a cascading manner, and K is a positive integer; and the second mapping unit 225 is configured to: decompose the first intermediate result into K first numerical parts, decompose the second intermediate result into K second numerical parts, and generate K signal values corresponding to the K first numerical parts and the K second numerical parts, a tth signal value being used for indicating a connection relationship between a tth basic operation unit and a (t+1)th basic operation unit, and t being a positive integer less than or equal to K; map the K first numerical parts and the K second numerical parts to K storage units of the register according to a correspondence between numerical locations on operation bit widths, to obtain K groups of numerical parts in the K storage units; read the K groups of numerical parts into the K basic operation units, and correspondingly input the K signal values into the K basic operation units; and perform superposition and combination on the K groups of numerical parts by using the K basic operation units, to obtain the floating-point number sum.
For example, an operation bit width supported by the basic operation unit is L, and reserved space on the register is (S, T); and a quotient value of a difference between T and S divided by L is rounded up to obtain the K storage units on the register, S being one boundary coordinate of the reserved space, T being the other boundary coordinate of the reserved space, and L, T, and S being positive integers. For example, K may be represented by using the following formula:
K=ceiling((S−T)/L); (12)
ceiling( ) means rounding up.
The second mapping unit 225 may calculate reserved space (S, T) according to formulas (10) and (11), that is, a bit width of an exponent part of an operand of the first bit width k1 is e, the fractional product of the first specified format includes an integer part I′ and a fractional part M′, and a location offset value of the fractional product of the first operand and the second operand in the register is Offset; and 1 is subtracted from a sum of 2e-1, I′, and Offset to obtain S, and a difference obtained by subtracting a sum of 2e-1 and M′ from a sum of Offset and 2 to obtain the reserved space (S, T).
For example, the second operation unit 224 determines a first intermediate result and a second intermediate result. As shown in
As shown in
For example, the fractional product of the second specified format and the third operand are fixed-point data, and the fractional product is in a one-to-one correspondence with an integer location, a fractional point location, and a fractional location of the third operand. For example, as shown in
In conclusion, in a process of performing a floating-point operation, the multiply accumulator in the chip provided in this embodiment first calculates the fractional product of the fractional parts of the first operand and the second operand, and performs first mapping on the fractional product to generate a fractional product that meets the first specified format, so as to obtain a fractional product; then, performs sign extension and location movement on the fractional product and the fractional part of the third operand, so as to obtain the first intermediate result and the second intermediate result whose sign bits, integer bits, and fractional bits can be in a one-to-one correspondence, performs second mapping on the first intermediate result and the second intermediate result in a uniform format, decomposes the first intermediate result and the second intermediate result according to the operation bit width of the basic operation unit, and calculates the final floating-point number sum by using K basic operation units that are cascaded. The chip implements, by using the foregoing two operations and two times of mapping, an objective of performing a multiply accumulate operation on floating-point numbers with a plurality of bit widths by using one set of hardware structure.
The floating-point number sum is in a fixed-point format, and the specified data format includes a fixed-point format or a floating-point format; the multiply accumulator includes a second selection end out mode; and the output unit 240 is configured to output the floating-point number sum of the fixed-point format as the operation result according to a fixed-point format indicated by the second selection end; the output unit 240 is configured to: convert the floating-point number sum of the fixed-point format into a floating-point number sum of the floating-point format according to a floating-point format indicated by the second selection end, and output the floating-point number sum of the floating-point format as the operation result.
For example, as shown in
In conclusion, a selection unit for outputting a data format is added to the multiply accumulate unit in the chip provided in this embodiment, so that an outputted data format can be independently selected.
In Step 301, a first selection signal is received.
The multiply accumulator includes a first selection end, the multiply accumulator supports a multiply accumulate operation of floating-point numbers with at least two types of bit widths, and the first selection end is used for selecting a floating-point operation mode. The multiply accumulator receives the first selection signal by using the first selection end, the first selection signal is used for indicating a floating-point operation mode. For example, the first selection signal is represented by using a four-digit binary number, and the first selection signal “0000” indicates a floating-point operation mode that supports operation of four groups of FP16 operands at the same time. Alternatively, the first selection signal “0001” indicates a floating-point operation mode that supports operation two groups of FP32 operands at the same time. Alternatively, the first selection signal “0010” indicates a floating-point operation mode that supports one group of FP64 operands at the same time, and so on.
In Step 302, an operation circuit in the multiply accumulator is controlled to be in an operation circuit corresponding to a floating-point operation mode indicated by the first selection signal.
The floating-point operation mode supports a multiply accumulate operation of a floating-point number of a first bit width k1. The chip controls the operation circuit in the multiply accumulator to be in the operation circuit corresponding to the floating-point operation mode indicated by the first selection signal. That is, the chip determines a connection state of each operation unit used when the multiply accumulator is in the foregoing floating-point operation mode. For example, the multiply accumulator includes an addition array and a multiplication array used for a multiplication operation of a fractional part, and the chip determines, from the multiplication array and the addition array of the multiply accumulator, a multiplier and an adder that are correspondingly used for the floating-point operation mode, and determines a corresponding connection correspondence between multipliers, between the multiplier and the adder, and between adders, to obtain an operation circuit corresponding to a floating-point operation unit, so as to perform a multiply accumulate operation of a floating-point number by using a correct operation circuit after operands are inputted.
In Step 303, a first operand, a second operand, and a third operand of the first bit width k1 are received.
The multiply accumulate unit includes an input end of a floating-point number and a data extraction unit, and the input end of the floating-point number is connected to an input end of the data extraction unit, and inputs the first operand, the second operand, and the third operand of the first bit width k1 into the data extraction unit by using the input end of the floating-point number. The data extraction unit is configured to separately extract a sign bit, an exponent part, and a fractional part of each of the first operand, the second operand, and the third operand. The data extraction unit is further configured to: split the fractional parts of the first operand and the second operand, and split a fractional part of a floating-point number of a high bit width into suboperands of an operation bit width supported by the multiplier. For example, the operation bit width supported by the multiplier is 16 bits. If N1=24, N2=11, and m=2, P1=P2=2 can be calculated by using formulas (1) to (3), a fractional part of a 32-bit first operand may be split into two 13-bit first suboperands. For another example, the operation bit width supported by the multiplier is 16 bits. If N1=53, N2=11, and m=4, P1=P2=3 can be calculated by using formulas (1) to (3), a fractional part of a 64-bit first operand may be split into two 14-bit first suboperands.
In Step 304, a fractional part of the first operand is divided into m first suboperands of a second bit width k2, and a fractional part of the second operand is divided into m second suboperands of the second bit width k2.
The second bit width k2=k1/m, both k2 and k1 are multiples of 2, and m is a positive integer. For example, as shown in
In Step 305, a multiplication operation of fractional parts is performed based on the m first suboperands and the m second suboperands to obtain a fractional product.
For example, the multiply accumulator includes a first operation unit, and an operation circuit in the first operation unit corresponding to the floating-point operation mode includes m2 multipliers and G adders. The chip performs, by using the m2 multipliers, a multiplication operation on the m first suboperands and the m second suboperands to obtain m2 intermediate fractional products; and invokes the G adder to superpose and combine the m2 intermediate fractional products to obtain the fractional product, G being a positive integer.
For example, as shown in
In Step 306, a floating-point number product of the first operand and the second operand is determined based on a sign bit and an exponent part of the first operand, a sign bit and an exponent part of the second operand, and the fractional product; and an addition operation is performed on the floating-point number product and the third operand to obtain a floating-point number sum.
The multiply accumulator further includes a first mapping unit, a second operation unit, and a second mapping unit. The chip maps the fractional product to a register according to a first specified format by using the first mapping unit; reads, by using the second operation unit, the fractional product of the first specified format from the register, extends and generates a first intermediate result (that is, a floating-point number product) of a second specified format for the fractional product of the first specified format based on the sign bit and the exponent part of the first operand and the sign bit and the exponent part of the second operand; extends and generates a second intermediate result of the second specified format for a fractional part of the third operand based on a sign bit and an exponent part of the third operand; and adds the first intermediate result and the second intermediate result to obtain the floating-point number sum by using the second mapping unit.
The fractional product includes an original integer part and an original fractional part; and for mapping of the fractional product, the first mapping unit cuts the original integer part according to an integer cutting bit width to obtain a cut integer part; cuts the original fractional part according to a fractional cutting bit width, to obtain a cut fractional part; and maps the cut integer part and the cut fractional part to coordinates of the register to obtain the fractional product of the first specified format. For example, the first mapping unit calculates the cut fractional part and integer part by using the foregoing formulas (4) to (7); and then, determines storage space (that is, reserved space) that is in the register and that is reserved for the fractional product by using the foregoing formulas (10) and (11), and maps the cut fractional part and integer part to the reserved space by using the foregoing formulas (8) and (9).
The multiply accumulator includes K basic operation units, two adjacent basic operation units are connected in a cascading manner, and K is a positive integer; and for summing calculation of the first intermediate result and the second intermediate result, the second mapping unit decomposes the first intermediate result into K first numerical parts, decomposes the second intermediate result into K second numerical parts, and generates K signal values corresponding to the K first numerical parts and the K second numerical parts, a tth signal value being used for indicating a connection relationship between a tth basic operation unit and a (t+1)th basic operation unit, and t being a positive integer less than or equal to K; maps the K first numerical parts and the K second numerical parts to K storage units of the register according to a correspondence between numerical locations on operation bit widths, to obtain K groups of numerical parts in the K storage units; reads the K groups of numerical parts into the K basic operation units, and correspondingly inputs the K signal values into the K basic operation units; and performs superposition and combination on the K groups of numerical parts by using the K basic operation units, to obtain the floating-point number sum.
For example, referring to
The fractional product of the first specified format refers to a product of the fractional parts of the first operand and the second operand. The fractional product of the second specified format is a product of the first operand and the second operand. For example, when a signed first operand NA=(−1)Sa*2Ea*Ma, and a signed second operand NB=(−1)Sb*2Eb*Mb, the fractional product of the first specified format refers to a product Ma*Mb of Ma and Mb, and the fractional product of the second specified format refers to a product (−1)(Sa+Sb)*2(Ea+Eb)*(Ma*Mb) of NA and NB.
In Step 307, an operation result in a specified data format is output according to the floating-point number sum.
The floating-point number sum is in a fixed-point format. The specified data format includes a fixed-point format or a floating-point format; a second selection signal is received, and the second selection signal is used for indicating that the specified data format is a fixed-point format or a floating-point format; and the chip outputs, according to the fixed-point format indicated by the second selection signal, the floating-point number sum of the fixed-point format as the operation result; or converts the floating-point number sum of the fixed-point format into a floating-point number sum of the floating-point format according to a floating-point format indicated by the second selection signal, and outputs the floating-point number sum of the floating-point format as the operation result.
In conclusion, in the floating-point operation control method provided in this embodiment, in different floating-point operation modes, the chip may split a floating-point number of a high bit width into suboperands of low bit widths to perform a multiply accumulate operation. Floating-point numbers of different high bit widths may be split into different quantities of suboperands of low bit widths. Correspondingly, the chip controls, according to selection of a floating-point operation mode, a multiplier and an adder in the multiply accumulator to perform splitting and reassembly, and an operation circuit in the multiply accumulator becomes an operation circuit corresponding to the floating-point operation mode so as to perform a multiply accumulate operation, so that the operation circuit can support a multiply accumulate operation of floating-point numbers of different bit widths, and there is no need to integrate at least two hardware structures on the chip to support the multiply accumulate operation of floating-point numbers of different bit widths. In addition, the multiplier and the adder can be reused, and a quantity of multipliers and adders arranged can be reduced, thereby effectively reducing an area of the chip and reducing power consumption during running of the chip.
An electronic device 400 may include components such as a radio frequency (RF) circuit 410, a memory 420 including one or more non-transitory computer readable storage media, an input unit 430, a display unit 440, a sensor 450, an audio circuit 460, a WiFi module 470, a processor 480 (e.g., processing circuitry) including one or more processing cores, and a power supply 490. A person skilled in the art may understand that the electronic device structure shown in
The input unit 430 may be configured to receive input digit or character information, and generate a keyboard, mouse, joystick, optical, or track ball signal input related to user setting and function control. Specifically, the input unit 430 may include an image input device 431 and another input device 432.
The display unit 440 may be configured to display information input by the user or information provided for the user, and various graphical user interfaces of the electronic device 400. The graphical user interfaces may be formed by a graph, a text, an icon, a video, and any combination thereof. The display unit 440 may include a display panel 441.
The audio circuit 460, a speaker 461, and a microphone 462 may provide audio interfaces between the user and the electronic device 400.
The electronic device 400 further includes a chip 482 including a multiply accumulator shown in any one of
Although not shown in the figure, the electronic device 400 may further include a Bluetooth module and the like, and details are not described herein again.
The basic input/output system 506 includes a display 508 configured to display information and an input device 509 such as a mouse and a keyboard for a user to input information. The display 508 and the input device 509 are both connected to the central processing unit 501 through an input/output controller 510 connected to the system bus 505. The mass storage device 507 is connected to the CPU 501 through a mass storage controller (not shown) connected to the system bus 505. The mass storage device 507 and its associated computer-readable media provide non-volatile storage for the server 500. That is, the mass storage device 507 may include a computer-readable medium (not shown) such as a hard disk or a compact disc read-only memory (CD-ROM) drive.
According to various embodiments of this disclosure, the server 500 may also be run by a remote computer connected to a network through a network such as the Internet. That is, the server 500 can be connected to a network 512 through a network interface unit 511 connected to the system bus 505, or can also be connected to other types of networks or a remote computer system (not shown) through the network interface unit 511.
The server 500 further includes a chip 516 including a multiply accumulator as shown in any one of
In addition, an embodiment of this disclosure further provides a storage medium, where the storage medium is configured to store a computer program, and the computer program is configured to perform the floating-point operation control method provided in the foregoing embodiment.
An embodiment of this disclosure further provides a computer program product including instructions, when run on a computer, causing the computer to perform the floating-point operation control method provided in the foregoing embodiment.
The sequence numbers of the foregoing embodiments of this disclosure are merely for description purpose, and are not intended to indicate the preference among the embodiments.
A person of ordinary skill in the art may understand that all or some of the steps of the embodiments may be implemented by hardware or a program instructing related hardware. The program may be stored in a computer-readable storage medium. The storage medium may include: a read-only memory, a magnetic disk, or an optical disc.
The term module (and other similar terms such as unit, submodule, etc.) in this disclosure may refer to a software module, a hardware module, or a combination thereof. A software module (e.g., computer program) may be developed using a computer programming language. A hardware module may be implemented using processing circuitry and/or memory. Each module can be implemented using one or more processors (or processors and memory). Likewise, a processor (or processors and memory) can be used to implement one or more modules. Moreover, each module can be part of an overall module that includes the functionalities of the module.
The foregoing disclosure includes some exemplary embodiments of this disclosure which are not intended to limit the scope of this disclosure. Other embodiments shall also fall within the scope of this disclosure.
Number | Date | Country | Kind |
---|---|---|---|
202010774707.3 | Aug 2020 | CN | national |
This application is a continuation of International Application No. PCT/CN2021/101378, filed on Jun. 22, 2021, which claims priority to Chinese Patent Application No. 202010774707.3, entitled “CHIP INCLUDING MULTIPLY ACCUMULATOR, TERMINAL, FLOATING-POINT OPERATION CONTROL METHOD” filed on Aug. 4, 2020. The entire disclosures of the prior applications are hereby incorporated by reference.
Number | Date | Country | |
---|---|---|---|
Parent | PCT/CN2021/101378 | Jun 2021 | US |
Child | 17898461 | US |