Operation unit, floating-point number operation method and device
By designing a computing unit containing conversion circuits and calculation circuits, the floating-point numbers of different data types are uniformly converted and performed calculations, the problem of power consumption and accuracy balance in floating-point number calculation is solved, and efficient computing performance and accuracy are achieved.
Patent Information
- Application Number
- CN202310514406.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-08
- Publication Date
- 2024-11-08
AI Technical Summary
The prior art is difficult to optimize floating point number calculation methods in computers to balance power consumption and precision, especially in floating point number calculations with different precisions.
A calculation unit is designed, including conversion circuits and calculation circuits. By converting floating-point numbers of different data types into custom data types, and performing operations in the calculation circuit, floating-point numbers of different precisions and data types are realized, reducing the Power consumption and improve accuracy.
It realizes the balance between accuracy of data calculation while reducing computing power consumption, improving computing performance, and achieving a balance between accuracy and power consumption.
Smart Images

Figure CN118915995A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an operation unit, a floating-point operation method and a device. Background Art
[0002] Floating point numbers are an important digital format in computers. In computers, floating point numbers consist of three parts: sign, exponent, and mantissa. In order to meet the different requirements of different businesses for data accuracy, computers usually need to support multiple floating point calculation types.
[0003] Since low-precision floating point (FP) numbers (such as FP16) consume less power when processing, low-precision floating point numbers are often used for calculations. However, some businesses have higher requirements for data accuracy. If only low-precision floating point numbers are used, the accuracy of the calculation results cannot be guaranteed. High-precision floating point numbers (such as FP32) must also be used for calculations.
[0004] Therefore, computers need to integrate greater computing power to support the calculation of floating-point numbers with different precisions. How to optimize floating-point calculation methods and balance power consumption and precision has become a technical problem that needs to be solved urgently. Summary of the invention
[0005] The embodiments of the present application provide a computing unit, a floating-point computing method and a device, which can optimize the floating-point computing method, while ensuring data computing accuracy and taking computing power consumption into consideration.
[0006] In a first aspect, an embodiment of the present application provides an operation unit, which includes a conversion circuit and an operation circuit; the conversion circuit is used to obtain a first floating-point number and a second floating-point number; the conversion circuit is also used to convert a first floating-point number of a first data type into a third floating-point number of a third data type, and to convert a second floating-point number of a second data type into a fourth floating-point number of the third data type; the operation circuit is used to perform an operation based on the third floating-point number and the fourth floating-point number to obtain an operation result.
[0007] In this way, for floating-point numbers of different data types, the conversion circuit of the operation unit uniformly converts the floating-point numbers of different data types into a custom data type, and outputs the converted floating-point numbers to the operation circuit. The operation circuit performs operations according to the converted custom data type to obtain a calculation result. In the technical solution shown in the present application, floating-point operations of different precisions and data types can be realized by one operation unit, and the applicability of the operation unit is higher. Moreover, by performing operations based on floating-point numbers converted into the same data type, power consumption during operations can be reduced, and it is also beneficial to reasonably use computing performance and improve the accuracy of operation results, thereby achieving a relatively balanced effect between accuracy and power consumption.
[0008] According to the first aspect, the data type of the first floating point number is a first data type, the data type of the second floating point number is a second data type, and the first data type and the second data type are the same or different.
[0009] In some examples, the first floating-point number includes one or more floating-point numbers of a first data type, and the second floating-point number includes one or more floating-point numbers of a second data type.
[0010] According to the first aspect, or any implementation of the first aspect above, the bit width of the mantissa of the third data type is higher than the bit width of the mantissa of a half-precision floating-point number and lower than the bit width of the mantissa of a single-precision floating-point number.
[0011] According to the first aspect, or any implementation of the first aspect above, the third data type includes a sign, an exponent, and a mantissa.
[0012] According to the first aspect, or any implementation of the first aspect above, the bit width of the sign of the third data type is a first preset value, the bit width of the exponent of the third data type is a second preset value, and the bit width of the mantissa of the third data type is a third preset value.
[0013] According to the first aspect, or any implementation of the first aspect above, the first preset value is 1, the second preset value is 9, and the third preset value is 12.
[0014] According to the first aspect, or any implementation of the first aspect above, the conversion circuit is also used to decompose the first floating-point number of the first data type into multiple third floating-point numbers of the third data type, and decompose the second floating-point number of the second data type into multiple fourth floating-point numbers of the third data type if the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both higher than a third preset value.
[0015] In a possible implementation, if the data types of the first floating-point number and the second floating-point number are the same, and both the first floating-point number and the second floating-point number are high-precision floating-point numbers, and both are higher than the third preset value of the mantissa in the third data type, the conversion circuit is used to disassemble the first floating-point number into a plurality of third floating-point numbers of the third data type and disassemble the second floating-point number into a plurality of fourth floating-point numbers of the third data type according to the mantissa of the third data type (that is, the third preset value).
[0016] In this way, the conversion circuit can decompose the high-precision first floating-point number and the second floating-point number into multiple low-precision floating-point numbers, respectively. Then, the low-precision floating-point multiplier and the low-precision floating-point adder can be reused to perform corresponding processing, without separately designing a high-precision floating-point multiplier or a high-precision floating-point adder, which can save computing costs.
[0017] According to the first aspect, or any implementation of the first aspect above, the conversion circuit is also used to, if the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than a third preset value, then complete the first floating-point number of the first data type into a third floating-point number of the third data type, and complete the second floating-point number of the second data type into a fourth floating-point number of the third data type.
[0018] In a possible implementation, if the data types of the first floating point number and the second floating point number are the same, and both the first floating point number and the second floating point number are low-precision floating point numbers, and both are lower than the third preset value of the mantissa in the third data type, the conversion circuit is used to complete the first floating point number into a third floating point number of the third data type according to the mantissa of the third data type (that is, the third preset value), and complete the second floating point number into a plurality of fourth floating point numbers of the third data type.
[0019] In this way, the conversion circuit converts the mantissas of the low-precision first floating-point number and the second floating-point number into the first floating-point number and the second floating-point number of the third data type by padding the mantissas with zeros. The zero padding only changes the length of the mantissas of the first floating-point number and the second floating-point number, increases the data precision, and does not change the value. In subsequent operations, the actual value of the data does not change, does not affect the calculation result, and can also increase the data precision and improve the precision of the calculation result.
[0020] According to the first aspect, or any implementation of the first aspect above, the conversion circuit is also used to decompose the first floating-point number of the first data type into multiple third floating-point numbers of the third data type, and decompose the second floating-point number of the second data type into multiple fourth floating-point numbers of the third data type if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both higher than a third preset value.
[0021] In a possible implementation, if the data types of the first floating point number and the second floating point number are different, and both the first floating point number and the second floating point number are high-precision floating point numbers, and both are higher than the third preset value of the mantissa in the third data type, the conversion circuit is used to disassemble the first floating point number into a plurality of third floating point numbers of the third data type and disassemble the second floating point number into a plurality of fourth floating point numbers of the third data type according to the mantissa of the third data type (that is, the third preset value).
[0022] In this way, high-precision floating-point numbers of different data types are decomposed into multiple low-precision floating-point numbers according to the mantissa of the third data type, and low-precision floating-point multipliers are reused to reduce power consumption during calculation.
[0023] According to the first aspect, or any implementation of the first aspect above, the conversion circuit is also used to complete the first floating-point number of the first data type into a third floating-point number of the third data type, and complete the second floating-point number of the second data type into a fourth floating-point number of the third data type if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than a third preset value.
[0024] In a possible implementation, if the data types of the first floating point number and the second floating point number are different, and both the first floating point number and the second floating point number are low-precision floating point numbers, and both are lower than the third preset value of the mantissa in the third data type, the conversion circuit is used to complete the first floating point number into a third floating point number of the third data type according to the mantissa of the third data type (that is, the third preset value), and complete the second floating point number into a fourth floating point number of the third data type.
[0025] According to the first aspect, or any implementation of the first aspect above, the conversion circuit is also used to complete the first floating-point number of the first data type into a third floating-point number of the third data type, and disassemble the second floating-point number of the second data type into multiple fourth floating-point numbers of the third data type if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is lower than a third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is higher than the third preset value.
[0026] In a possible implementation, if the data types of the first floating point number and the second floating point number are different, and the first floating point number is a low-precision floating point number, which is lower than the third preset value of the mantissa in the third data type; and the second floating point number is a high-precision floating point number, which is higher than the third preset value of the mantissa in the third data type. Then the conversion circuit is used to complete the first floating point number into a third floating point number of the third data type according to the mantissa of the third data type (that is, the third preset value), and disassemble the second floating point number into a plurality of fourth floating point numbers of the third data type.
[0027] According to the first aspect, or any implementation of the first aspect above, the conversion circuit is also used to, if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is higher than a third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is lower than the third preset value, then disassemble the first floating-point number of the first data type into multiple third floating-point numbers of the third data type, and disassemble and complete the second floating-point number of the second data type into a fourth floating-point number of the third data type.
[0028] In a possible implementation, if the data types of the first floating point number and the second floating point number are different, and the first floating point number is a high-precision floating point number, which is higher than the third preset value of the mantissa in the third data type; and the second floating point number is a low-precision floating point number, which is lower than the third preset value of the mantissa in the third data type. Then the conversion circuit is used to disassemble the first floating point number into a plurality of third floating point numbers of the third data type according to the mantissa of the third data type (that is, the third preset value), and complete the second floating point number into a fourth floating point number of the third data type.
[0029] The floating-point multiplier in the embodiment of the present application is a multiplier corresponding to the mantissa of the third data type. For low-precision floating-point numbers, they are completed and converted into floating-point numbers of the third data type; for high-precision floating-point numbers, they are disassembled into multiple floating-point numbers of the third data type. In this way, the bit width of the mantissa of the floating-point numbers converted into the third data type is the third preset value, and the floating-point multiplier can be used for calculation. The floating-point multiplier in the embodiment of the present application can be reused by multi-precision floating-point multiplication calculations, making full use of the mantissa multiplier resources in each floating-point multiplier and reasonably using the computing performance.
[0030] According to the first aspect, or any implementation of the first aspect above, the bit width of the exponent of the third floating-point number of the third data type and the bit width of the exponent of the fourth floating-point number of the third data type are both greater than the bit width of the exponent of the first floating-point number of the first data type and the bit width of the exponent of the second floating-point number of the second data type.
[0031] Thus, in the embodiment of the present application, a first floating-point number of the first data type can be converted into a third floating-point number of the third data type, and a second floating-point number of the second data type can be converted into a fourth floating-point number of the third data type. The first floating-point number and the second floating-point number can be floating-point numbers of non-normalized types. In order to satisfy the shift condition of the exponent, it is only necessary to ensure that the bit width of the exponent of the third data type is greater than the bit width of the exponent of the first floating-point number of the first data type and the bit width of the exponent of the second floating-point number of the second data type.
[0032] According to the first aspect, or any implementation of the first aspect above, the operation circuit is further used to perform an addition operation according to the exponent of the third floating-point number and the exponent of the fourth floating-point number to obtain an exponential addition result.
[0033] According to the first aspect, or any implementation of the first aspect above, the operation circuit is further used to perform a multiplication operation based on the mantissa of the third floating-point number and the mantissa of the fourth floating-point number to obtain a mantissa product result.
[0034] According to the first aspect, or any implementation of the first aspect above, the operation circuit is further used to obtain an operation result according to the exponential addition result, the mantissa product result and the scalar value.
[0035] In one possible implementation, the operation unit includes a floating-point multiplier and a floating-point adder, the floating-point multiplier is used to perform a multiplication operation of a third floating-point number of the converted third data type and a fourth floating-point number of the converted third data type, and the floating-point adder is used to perform an addition operation of the third floating-point number of the converted third data type and a fourth floating-point number of the converted third data type.
[0036] In a possible implementation, the operation unit includes a plurality of floating-point multipliers and a plurality of floating-point adders, wherein the plurality of floating-point multipliers are used to perform an XOR calculation according to the sign of the third floating-point number of the converted third data type and the sign of the fourth floating-point number of the converted third data type to obtain a sign XOR result; perform addition calculation on the exponent of the third floating-point number of the converted third data type and the exponent of the fourth floating-point number of the converted third data type to obtain an exponential sum result; perform multiplication calculation on the mantissa of the third floating-point number of the converted third data type and the mantissa of the fourth floating-point number of the converted third data type to obtain a mantissa product result. Subsequently, the sign XOR result, the exponential sum result and the mantissa product result are output to the floating-point adder in the operation unit. The plurality of floating-point adders are used to perform addition calculation on the input mantissa product results to obtain a mantissa sum result, and obtain the operation result according to the mantissa sum result, the sign XOR result, the exponential sum result and the scalar value.
[0037] In this way, the operation unit is provided with a plurality of floating-point multipliers, and the plurality of floating-point multipliers can execute the mantissa segment multiplication calculation in parallel, or execute the floating-point multiplication calculation in parallel, which can effectively improve the calculation efficiency of the floating-point numbers.
[0038] In a second aspect, an embodiment of the present application provides a floating-point operation method, the method comprising: obtaining a first floating-point number and a second floating-point number; converting the first floating-point number of the first data type into a third floating-point number of the third data type, and converting the second floating-point number of the second data type into a fourth floating-point number of the third data type; performing operations based on the third floating-point number and the fourth floating-point number to obtain an operation result.
[0039] According to the second aspect, the data type of the first floating point number is a first data type, the data type of the second floating point number is a second data type, and the first data type and the second data type are the same or different.
[0040] According to the second aspect, or any implementation of the second aspect above, the bit width of the mantissa of the third data type is higher than the bit width of the mantissa of a half-precision floating-point number and lower than the bit width of the mantissa of a single-precision floating-point number.
[0041] According to the second aspect, or any implementation of the second aspect, the third data type includes a sign, an exponent, and a mantissa.
[0042] According to the second aspect, or any implementation of the second aspect above, the bit width of the sign of the third data type is a first preset value, the bit width of the exponent of the third data type is a second preset value, and the bit width of the mantissa of the third data type is a third preset value.
[0043] According to the second aspect, or any implementation of the second aspect, the first preset value is 1, the second preset value is 9, and the third preset value is 12.
[0044] According to the second aspect, or any implementation of the second aspect above, converting a first floating-point number of a first data type into a third floating-point number of a third data type, and converting a second floating-point number of a second data type into a fourth floating-point number of the third data type, includes: if the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both higher than a third preset value, then decomposing the first floating-point number of the first data type into a plurality of third floating-point numbers of the third data type, and decomposing the second floating-point number of the second data type into a plurality of fourth floating-point numbers and second floating-point numbers of the third data type.
[0045] According to the second aspect, or any implementation of the second aspect above, converting a first floating-point number of a first data type into a third floating-point number of a third data type, and converting a second floating-point number of a second data type into a fourth floating-point number of the third data type, includes: if the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than a third preset value, then completing the first floating-point number of the first data type into the third floating-point number of the third data type, and completing the second floating-point number of the second data type into the fourth floating-point number of the third data type.
[0046] According to the second aspect, or any implementation of the second aspect above, converting a first floating-point number of a first data type into a third floating-point number of a third data type, and converting a second floating-point number of a second data type into a fourth floating-point number of the third data type, includes: if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both higher than a third preset value, then decomposing the first floating-point number of the first data type into a plurality of third floating-point numbers of the third data type, and decomposing the second floating-point number of the second data type into a plurality of fourth floating-point numbers of the third data type.
[0047] According to the second aspect, or any implementation of the second aspect above, converting a first floating-point number of a first data type into a third floating-point number of a third data type, and converting a second floating-point number of a second data type into a fourth floating-point number of the third data type, includes: if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than a third preset value, then completing the first floating-point number of the first data type into the third floating-point number of the third data type, and completing the second floating-point number of the second data type into the fourth floating-point number of the third data type.
[0048] According to the second aspect, or any implementation of the second aspect above, converting a first floating-point number of a first data type into a third floating-point number of a third data type, and converting a second floating-point number of a second data type into a fourth floating-point number of the third data type, includes: if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is lower than a third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is higher than the third preset value, then completing the first floating-point number of the first data type into a third floating-point number of the third data type, and disassembling the second floating-point number of the second data type into multiple fourth floating-point numbers of the third data type.
[0049] According to the second aspect, or any implementation of the second aspect above, converting a first floating-point number of a first data type into a third floating-point number of a third data type, and converting a second floating-point number of a second data type into a fourth floating-point number of the third data type, includes: if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is higher than a third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is lower than the third preset value, then disassembling the first floating-point number of the first data type into multiple third floating-point numbers of the third data type, and disassembling and complementing the second floating-point number of the second data type into a fourth floating-point number of the third data type.
[0050] According to the second aspect, or any implementation of the second aspect above, the bit width of the exponent of the third floating-point number of the third data type and the bit width of the exponent of the fourth floating-point number of the third data type are both greater than the bit width of the exponent of the first floating-point number of the first data type and the bit width of the exponent of the second floating-point number of the second data type.
[0051] According to the second aspect, or any implementation of the second aspect above, an operation is performed according to the third floating-point number and the fourth floating-point number to obtain an operation result, including: performing an addition operation according to the exponent of the third floating-point number and the exponent of the fourth floating-point number to obtain an exponential addition result; performing a multiplication operation according to the mantissa of the third floating-point number and the mantissa of the fourth floating-point number to obtain a mantissa product result; and obtaining an operation result according to the exponential addition result, the mantissa product result, and a scalar value.
[0052] In a possible implementation, an XOR calculation is performed based on the sign of the converted third floating-point number of the third data type and the sign of the converted fourth floating-point number of the third data type to obtain a sign XOR result; an addition calculation is performed on the exponent of the converted third floating-point number of the third data type and the exponent of the converted fourth floating-point number of the third data type to obtain an exponential sum result; a multiplication calculation is performed on the mantissa of the converted third floating-point number of the third data type and the mantissa of the converted fourth floating-point number of the third data type to obtain a mantissa product result. Then, the mantissa product result is added to obtain a mantissa sum result. Finally, the operation result is obtained based on the mantissa sum result, the sign XOR result, the exponential sum result, and the scalar value.
[0053] In a third aspect, an embodiment of the present application provides a floating-point operation device, which includes: a conversion module, used to obtain a first floating-point number and a second floating-point number; the conversion module is also used to convert a first floating-point number of a first data type into a third floating-point number of a third data type, and to convert a second floating-point number of a second data type into a fourth floating-point number of a third data type; an operation module, used to perform operations based on the third floating-point number and the fourth floating-point number to obtain an operation result.
[0054] According to a third aspect, the data type of the first floating-point number is a first data type, the data type of the second floating-point number is a second data type, and the first data type and the second data type are the same or different.
[0055] According to the third aspect, or any implementation of the third aspect above, the bit width of the mantissa of the third data type is higher than the bit width of the mantissa of a half-precision floating-point number and lower than the bit width of the mantissa of a single-precision floating-point number.
[0056] According to the third aspect, or any implementation of the third aspect, the third data type includes a sign, an exponent, and a mantissa.
[0057] According to the third aspect, or any implementation of the third aspect above, the bit width of the sign of the third data type is a first preset value, the bit width of the exponent of the third data type is a second preset value, and the bit width of the mantissa of the third data type is a third preset value.
[0058] According to the third aspect, or any implementation of the third aspect, the first preset value is 1, the second preset value is 9, and the third preset value is 12.
[0059] According to the third aspect, or any implementation of the third aspect above, the conversion module is also used to, if the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both higher than the third preset value, then the first floating-point number of the first data type is disassembled into a plurality of third floating-point numbers of the third data type, and the second floating-point number of the second data type is disassembled into a plurality of fourth floating-point numbers and second floating-point numbers of the third data type. According to the third aspect, or any implementation of the third aspect above, the conversion module is also used to, if the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than the third preset value, then the first floating-point number of the first data type is completed into the third floating-point number of the third data type, and the second floating-point number of the second data type is completed into the fourth floating-point number of the third data type.
[0060] According to the third aspect, or any implementation of the third aspect above, the conversion module is also used to decompose the first floating-point number of the first data type into multiple third floating-point numbers of the third data type, and decompose the second floating-point number of the second data type into multiple fourth floating-point numbers of the third data type if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both higher than a third preset value.
[0061] According to the third aspect, or any implementation of the third aspect above, the conversion module is also used to complete the first floating-point number of the first data type into a third floating-point number of the third data type, and complete the second floating-point number of the second data type into a fourth floating-point number of the third data type if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than a third preset value.
[0062] According to the third aspect, or any implementation of the third aspect above, the conversion module is also used to complete the first floating-point number of the first data type into a third floating-point number of the third data type, and disassemble the second floating-point number of the second data type into multiple fourth floating-point numbers of the third data type if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is lower than a third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is higher than the third preset value.
[0063] According to the third aspect, or any implementation of the third aspect above, the conversion module is also used to, if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is higher than a third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is lower than the third preset value, then disassemble the first floating-point number of the first data type into multiple third floating-point numbers of the third data type, and disassemble and complete the second floating-point number of the second data type into a fourth floating-point number of the third data type.
[0064] According to the third aspect, or any implementation of the third aspect above, the bit width of the exponent of the third floating-point number of the third data type and the bit width of the exponent of the fourth floating-point number of the third data type are both greater than the bit width of the exponent of the first floating-point number of the first data type and the bit width of the exponent of the second floating-point number of the second data type.
[0065] According to the third aspect, or any implementation of the third aspect above, the operation module is further used to perform an addition operation based on the exponent of the third floating-point number and the exponent of the fourth floating-point number to obtain an exponential sum result. According to the third aspect, or any implementation of the third aspect above, the operation module is further used to perform a multiplication operation based on the mantissa of the third floating-point number and the mantissa of the fourth floating-point number to obtain a mantissa product result. According to the third aspect, or any implementation of the third aspect above, the operation module is further used to obtain an operation result based on the exponential sum result, the mantissa product result and the scalar value.
[0066] In a fourth aspect, an embodiment of the present application provides a chip, which includes at least one computing unit as described in the first aspect above, and the computing unit is used to execute the functions that can be implemented by the first aspect or any one of the computing units in the first aspect.
[0067] In a fifth aspect, an embodiment of the present application provides a computing device, which includes a mainboard and the chip described in the fourth aspect, wherein the chip is arranged on the mainboard, and the chip includes a computing unit, which executes the functions that can be implemented by the first aspect or any one of the computing units in the first aspect.
[0068] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium. The computer-readable storage medium stores a computer program (also referred to as instructions or codes), and when the computer program is executed by a computing device, the computing device executes the method of the second aspect and any one of the implementations of the second aspect.
[0069] According to a seventh aspect, a computer program product is provided. When the computer program product is run on a computing device, the computing device executes the method according to the second aspect and any one of the implementations of the second aspect.
[0070] In the eighth aspect, an embodiment of the present application provides a chip system, comprising at least one processor and at least one interface circuit, wherein the at least one interface circuit is used to perform transceiver functions and send instructions to the at least one processor, the at least one processor executes instructions, and the at least one processor executes the method of the second aspect and any one of the implementations of the second aspect.
[0071] In a ninth aspect, an embodiment of the present application provides a circuit system, the circuit system includes a processing circuit, and the processing circuit is configured to execute the method of the second aspect or any one of the implementations of the second aspect.
[0072] In the tenth aspect, an embodiment of the present application provides a server, which includes the chip, processor and memory described in the fourth aspect above, the memory and the chip are coupled to the processor, the memory is used to store computer program code, the computer program code includes computer instructions, and when the processor reads the computer instructions from the memory, the server executes the method as described in the second aspect or any one of the embodiments of the second aspect.
[0073] The technical effects corresponding to the second to tenth aspects and any implementation method in each aspect can be referred to the technical effects corresponding to the above-mentioned first aspect and any implementation method in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0074] Figure 1 A schematic diagram of the structure of a computing device provided in an embodiment of the present application;
[0075] Figure 2 A schematic diagram of the structure of a chip provided in an embodiment of the present application;
[0076] Figure 3 A schematic diagram of the structure of a computing unit provided in an embodiment of the present application;
[0077] Figure 4A A schematic diagram of the structure of a computing circuit provided in an embodiment of the present application;
[0078] Figure 4B A flowchart of a calculation process provided in an embodiment of the present application;
[0079] Figure 5 A flow chart of a floating point operation method provided in an embodiment of the present application;
[0080] Fig. 6A A schematic diagram of a floating point number composition provided in an embodiment of the present application;
[0081] Figure 6B A schematic diagram of the precision / data range of floating-point numbers of different data types provided in an embodiment of the present application;
[0082] Figure 7 A schematic diagram of an application scenario of a floating point operation method provided in an embodiment of the present application Figure 1 ;
[0083] Figure 8 A schematic diagram of an application scenario of a floating point operation method provided in an embodiment of the present application Figure 2 ;
[0084] Fig. 9 A schematic diagram of an application scenario of a floating point operation method provided in an embodiment of the present application Figure 3 ;
[0085] Fig.10 Schematic diagram 4 of an application scenario of a floating-point operation method provided in an embodiment of the present application;
[0086] Fig.11 A schematic diagram of an application scenario of a floating point operation method provided in an embodiment of the present application Figure 5 ;
[0087] Fig.12 Schematic diagram 6 of an application scenario of a floating-point operation method provided in an embodiment of the present application;
[0088] Fig.13 A schematic diagram of the structure of a floating-point operation device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0089] In the description of the embodiments of the present application, unless otherwise specified, “ / ” means or. For example, A / B can mean A or B. The “and / or” in this article is merely a way to describe the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0090] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.
[0091] In the description of the embodiments of the present application, unless otherwise specified, "multiple" means two or more. In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions.
[0092] Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0093] First, some of the terms and related technologies involved in this application are explained to facilitate understanding by those skilled in the art.
[0094] Institute of Electrical and Electronics Engineers (IEEE) Standard for Binary Floating-Point Arithmetic (IEEE 754): A widely used floating-point arithmetic standard. This standard defines the representation method (also described as data type or format) of double-precision floating-point numbers and single-precision floating-point numbers widely used by central processing units (CPUs) and floating-point arithmetic units, and also defines the representation method of half-precision floating-point numbers used by computer graphics (CG).
[0095] The floating-point number defined in the IEEE 754 standard usually consists of three parts, namely the sign, the exponent, and the mantissa. The exponent can also be called the exponent. Floating-point numbers are mainly used to represent decimals. Among them, the bit width of the sign is 1 bit, and the bit width of the exponent and mantissa can be multiple bits. The sign is used to indicate the positive and negative of the floating-point number. The bit width of the exponent determines the range of values that the floating-point number can represent, or the actual position of the decimal point in the data. The longer the exponent, the larger the range of data that the floating-point number can represent. The bit width of the mantissa determines the precision of the floating-point number. The longer the mantissa, the higher the precision that the floating-point number can represent.
[0096] The value expressed by the floating point number in the IEEE 754 standard is generally: value = (-1) sign *2 exponent-bias *1.mantissa. Among them, sign is used to indicate the positive or negative of a floating point number. If sign is 0, the floating point number is positive, and if sign is 1, the floating point number is negative.
[0097] exponent is used to indicate the exponent value, bias is used to indicate the exponent offset, and exponent-bias is used to indicate the true value of the exponent. IEEE 754 stipulates that the offset value is 2. e-1-1, e is the bit width of the exponent; when the exponent part is all 0, the floating point number is a denormalized number, and when the exponent part is all 1, it indicates that the floating point number is in a non-number state, that is, the floating point number may be positive / negative infinity, which is determined by the sign value and mantissa value of the floating point number. The floating point number may also be NaN (not a number). Mantissa is used to indicate the mantissa value.
[0098] IEEE 754 stipulates that the integer part of the mantissa of a normalized floating-point number is 1, and the highest integer 1 is hidden when the mantissa is encoded, and the integer part of the mantissa of a denormalized floating-point number is 0.
[0099] For example, if you want to store a data (such as 20.5) in FP32 format in a computer, according to the IEEE 754 standard, the exponent offset value is 2 8-1 -1=127.
[0100] First, 20.5 is a positive number, so the sign is 0. Then, convert the decimal floating point number (20.5) to binary format 10100.1, and then convert the binary number to base 2 exponential form 1.01001*2 4 The mantissa is 1.01001, and 4 is the true value of the exponent, which is the exponent before the shift. The exponent after the shift is the true value of the exponent plus the shift value (4+127=131). The shifted exponent 131 is converted to binary 1000 0011. The mantissa hides the highest integer 1 and fills the low bits with zeros when it is represented.
[0101] Thus, 20.5 is represented in FP32 as 0 1000 0011 0100 1000 0000 0000 0000 000, which is (-1). 0 *2 131-127 *1.01001=1*2 4 *1.01001.
[0102] Half-precision floating-point: A binary floating-point data type used by computers. It occupies 2 bytes (i.e. 16 bits) when stored in a computer. It can also be referred to as FP16.
[0103] Specifically, the bit width of the sign in FP16 is 1 bit, the bit width of the exponent is 5 bits, and the bit width of the mantissa is 10 bits (the fractional part of the mantissa). In addition to the stored 10-bit fractional part, the mantissa also includes a hidden 1-bit integer part, that is, the mantissa is a total of 11 bits.
[0104] Single-precision floating-point: A binary floating-point data type used by computers. It occupies 4 bytes (32 bits) when stored in a computer and can also be referred to as FP32.
[0105] Specifically, the bit width of the sign in FP32 is 1 bit, the bit width of the exponent is 8 bits, and the bit width of the mantissa is 23 bits (the fractional part of the mantissa). In addition to the stored 23 bits of fractional part, the mantissa also includes a hidden 1 bit integer part, that is, the mantissa is a total of 24 bits.
[0106] Double precision floating point: A binary floating point data type used by computers. It occupies 8 bytes (64 bits) when stored in a computer. It can also be referred to as FP64.
[0107] Specifically, the bit width of the sign in FP64 is 1 bit, the bit width of the exponent is 11 bits, and the bit width of the mantissa is 52 bits (the fractional part of the mantissa). In addition to the stored 52 bits of fractional part, the mantissa also includes a hidden 1 bit integer part, that is, the mantissa is a total of 53 bits.
[0108] In addition to the above floating-point numbers specified by the IEEE 754 standard, there are also the following data types of floating-point numbers:
[0109] 16-bit brain floating point: Different from the ordinary single-precision floating point number FP16, BF16 is a relatively new floating point data type between FP16 and FP32, which can also be referred to as BF16.
[0110] Specifically, the bit width of the sign in BF16 is 1 bit, the bit width of the exponent is 8 bits, and the bit width of the mantissa is 7 bits (the fractional part of the mantissa). In addition to the stored 7-bit fractional part, the mantissa also includes a hidden 1-bit integer part, that is, the mantissa is 8 bits in total.
[0111] TF32 (tensor float 32): is a truncated FP32 data type, which truncates the 23-bit mantissa in FP32 to 10 bits, while the exponent remains 8 bits.
[0112] Specifically, the bit width of the sign in FP32 is 1 bit, the bit width of the exponent is 8 bits, and the bit width of the mantissa is 10 bits (the fractional part of the mantissa). In addition to the stored 10-bit fractional part, the mantissa also includes a hidden 1-bit integer part, that is, the mantissa is a total of 11 bits.
[0113] Table 1 below shows a storage format of the above five floating point numbers respectively.
[0114] Table 1
[0115] symbol Exponent mantissa FP16 1bit 5bits 10 bits + 1 bit (hidden) FP32 1bit 8bits 23 bits + 1 bit (hidden) FP64 1bit 11bits 52 bits + 1 bit (hidden) BF16 1bit 8bits 7bits+1bit(hidden) TF32 1bit 8bits 10 bits + 1 bit (hidden)
[0116] As shown in Table 1, the exponent and mantissa of floating-point numbers of different data types are different, and the precision and data range that can be expressed are also different. When calculating the floating-point number A*B, the exponent part is calculated as A_exponent+B_exponent, and the mantissa part is calculated as A_mantissa*B_mantissa. Then the newly obtained exponent and mantissa are used to generate a new floating-point number according to the format in the standard.
[0117] When calculating the floating point number A+B, first determine the larger one of A_exponent and B_exponent. Assume that A_exponent is n larger than B_exponent. Then when adding mantissa, first shift B_mantissa right by n bits, then add it to A_mantissa to get the new mantissa, and finally generate a new floating point number according to the format in the standard.
[0118] In one possible implementation, when calculating the addition of multiple floating-point numbers, first find the largest exponent among the multiple floating-point numbers, shift the mantissa accordingly based on the difference between the largest exponent and the exponents of each floating-point number, and finally add the shifted mantissa.
[0119] In another possible implementation, when calculating the addition of multiple floating-point numbers, a pairwise addition operation is adopted, and only two floating-point numbers are added each time, and after the calculation result is obtained, the next floating-point number is added. In this way, the floating-point numbers are added in pairs, and the addition calculation of multiple floating-point numbers is completed in sequence.
[0120] Vector inner product operation of floating point numbers: in, and is a floating point vector, where a1, a2, ...an and b1, b2, ...bn are floating point numbers.
[0121] At present, convolutional neural networks (CNN) are widely used in image processing, speech recognition and other fields. CNN includes two processes: training and reasoning, and each process involves a large number of convolution calculations and matrix calculations. The data type used in the calculation process will affect the power consumption during the calculation and the accuracy of the calculation results. CNN often uses application specific integrated circuits (ASIC) to accelerate calculations, thereby improving calculation efficiency and shortening calculation time. ASIC usually reuses existing calculation logic and improves the calculation power for low-precision data types during calculations, thereby integrating greater computing power and performing floating-point calculations of different precisions.
[0122] In the existing floating-point operation scheme, the main processing method is to disassemble the floating-point numbers of high-precision data types (such as FP32) into floating-point numbers of low-precision data types (such as FP16), and complete the multiplication and accumulation operations according to the disassembled low-precision data types (such as FP16).
[0123] For example, the 24-bit mantissa part of the FP32 floating-point number is split into a first mantissa of 11 bits and a second mantissa of 13 bits. Thus, two FP32 floating-point numbers are split into four mantissa parts, and a 13-bit mantissa multiplier is used to multiply the four mantissas. The multiplier has a long timing overhead, a high hardware calculation cost, and generates high power consumption.
[0124] Alternatively, the floating point number of the high-precision data type is disassembled into a floating point number of a preset format, for example, in the preset format, the sign is 1 bit, the exponent is 9 bits, and the mantissa is 10 bits. For example, the mantissa part of a floating point number of the FP32 type is split into 3 mantissa parts according to the preset format, the amount of calculation during calculation increases, the power consumption also increases accordingly, and the accuracy of the calculation result is low.
[0125] In order to improve the problems existing in the above-mentioned existing calculation schemes, an embodiment of the present application provides a floating-point calculation method, which obtains a first floating-point number and a second floating-point number, wherein the data type of the first floating-point number is a first data type, the data type of the second floating-point number is a second data type, and the first data type and the second data type are the same or different; according to a custom third data type, the first floating-point number is converted from the first data type to a third data type, and the second floating-point number is converted from the second data type to a third data type; and the calculation result is obtained by performing calculations based on the first floating-point number and the second floating-point number converted into the third data type. In an embodiment of the present application, floating-point numbers of different data types are uniformly converted into custom data types, and calculations are performed based on the converted custom data types, which can reduce power consumption during calculations, is conducive to the rational use of computing performance, and improves the accuracy of calculation results, thereby achieving a relatively balanced effect between accuracy and power consumption.
[0126] It should be noted that the floating-point operation method involved in the embodiment of the present application can be applied to general computing, high performance computing clusters (high performance computing, HPC), artificial intelligence (artificial intelligence, AI) and data signal processing. For example, image processing systems, radar systems and communication systems. The method can optimize the performance of digital signal processing (digital signal processing, DSP) or other digital devices. For example, it is applied to digital devices in current communication systems, such as long term evolution (long term evolution, LTE), universal mobile telecommunications system (universal mobile telecommunications system, UMTS) and global system for mobile communications (global system for mobile communications, GSM) and other current communication systems.
[0127] Figure 1 This is a schematic diagram of the structure of a computing device provided in this embodiment. The computing device may be a device with computing capabilities such as a terminal, a network device or a server. Figure 1 The computing device may include a memory 101 , a processor 102 , a communication interface 103 and a bus 104 , and the memory 101 , the processor 102 and the communication interface 103 are interconnected via the bus 104 .
[0128] The memory 101 can be used to store data, software programs and modules, and mainly includes a program storage area and a data storage area. The program storage area can store an operating system, an application required for at least one function, etc., and the data storage area can store data created when the device is used, etc. For example, the operating system may include a Linux operating system, a Unix operating system, or a Window operating system, etc.; the application (application, APP) required for the at least one function may include an AI-related APP, an HPC-related APP, a deep learning-related APP, or a CG-related APP, etc.
[0129] In one possible exemplary embodiment, the memory 101 can be a read-only memory (ROM) or other types of static random access memory (SRAM) that can store static information and instructions, a random access memory (RAM) or other types of dynamic random access memory (DRAM) that can store information and instructions, a synchronous dynamic random access memory (SDRAM) or a high-speed random access memory; it can also be an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to this.
[0130] The memory 101 may exist independently and be connected to the processor via a bus, or the memory may be integrated with the processor.
[0131] The processor 102 is used to control and manage the operation of the computing device, such as by running or executing software programs and / or modules stored in the memory 101 and calling data stored in the memory 101 to perform various functions of the computing device and process data.
[0132] In one possible exemplary embodiment, the processor 102 includes but is not limited to a central processing unit (CPU), a network processing unit (NPU), a graphics processing unit (GPU), an ASIC, a field programmable gate array (FPGA), a logic circuit, other programmable logic devices, a transistor logic device, one or more integrated circuits for controlling the execution of the program of the present application, or any combination thereof.
[0133] The processor 102 may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the contents disclosed in this application.
[0134] The processor 102 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a digital signal processor and a microprocessor, etc.
[0135] The communication interface 103 is used to enable the computing device to communicate with an external device. The communication interface 103 may include an input interface and an output interface. The input interface may be used to obtain multiple floating point numbers in the following embodiments.
[0136] In some feasible embodiments, the input interface may have only one input interface or multiple input interfaces. The output interface may be used to output the operation results in the following method embodiments.
[0137] In some feasible embodiments, the operation result may be directly output by the processor, or may be first stored in a memory and then output via the memory. In other feasible embodiments, there may be only one output interface, or there may be multiple output interfaces.
[0138] The bus 104 may be a peripheral component interconnect express (PCIe) bus, or an extended industry standard architecture (EISA) bus, etc. The bus 104 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 1 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0139] In an embodiment of the present application, the processor 102 may include a computing unit, which may be used to support the processor in executing one or more steps in the following embodiments.
[0140] like Figure 2 , which is a schematic diagram of the structure of a chip 200 provided in an embodiment of the present application, wherein the chip 200 includes a control unit 201, a computing unit 202 and a storage unit 203 (eg, Cache).
[0141] The control unit 201, the operation unit 202 and the storage unit 203 are connected in pairs through an internal bus. The control unit 201 is used to send instructions to the storage unit 203 and the operation unit 202 to control the storage unit 203 and the operation unit 202. The operation unit 202 is used to receive the instructions sent by the control unit 201 and perform corresponding processing according to the instructions, for example, executing the floating-point operation method provided in the present application.
[0142] The storage unit 203 may also be referred to as a cache. Data may be stored in the storage unit 203 , for example, a first floating-point number and a second floating-point number may be stored.
[0143] The operation unit 202 may include an arithmetic and logic unit (ALU) ALU 2021 for performing arithmetic operations and a logic operation ALU 2022 for performing logic operations.
[0144] Among them, the arithmetic logic ALU2021 can be provided with a basic operation subunit 2023 for performing basic operations such as addition (add), subtraction (sub), multiplication (mul), division (dev) and other additional operations, and a floating-point operation subunit 2024 for performing floating-point operations of different data types, which can execute the floating-point operation method provided in this application.
[0145] The logic operation ALU 2022 may be provided with sub-units for performing operations such as shift, logical AND, logical OR, and comparison of two values.
[0146] The chip 200 may also be connected to the memory 210 for data exchange and instruction transmission with the memory 210. Figure 2 As shown, the memory 210 is connected to the control unit 201 and the storage unit 203, and the control unit 201 can obtain instructions or data stored in the memory 210 from the memory 210. For example, the control unit 201 reads instructions from the memory 210, further sends them to the operation unit 202, and the operation unit 202 executes the instructions.
[0147] It should be noted that Figure 2The logic architecture of the chip 200 shown can be the logic architecture of any chip, for example, a central processing unit (CPU) chip, a graphics processing unit (GPU) chip, a field-programmable gate array (FPGA) chip, an application specific integrated circuit (ASIC) chip, a tensor processing unit (TPU) chip or other artificial intelligence (AI) chips, etc. The main difference between different types of chips is that the proportions of the control unit 201, the storage unit 203 and the computing unit 202 are different.
[0148] like Figure 3 , which is a schematic diagram of the structure of a computing unit provided in an embodiment of the present application. The computing unit includes a conversion circuit 301 and a computing circuit 302 ( Figure 3 Take the example of an operation unit including two conversion circuits).
[0149] In the embodiment of the present application, the output end of the conversion circuit 301 is connected to the input end of the operation circuit 302 .
[0150] In the embodiment of the present application, a first floating-point number and a second floating-point number are stored in the memory, and the conversion circuit 301 is used to obtain the first floating-point number and the second floating-point number from the memory.
[0151] In the embodiment of the present application, the conversion circuit 301 is further configured to convert a first floating point number of the first data type into a third floating point number of the third data type, and to convert a second floating point number of the second data type into a fourth floating point number of the third data type.
[0152] The third data type is a user-defined data type, and the bit width of the mantissa of the third data type is greater than the bit width of the mantissa of a half-precision floating-point number and less than the bit width of the mantissa of a single-precision floating-point number. The third data type includes a sign, an exponent, and a mantissa; the bit width of the sign of the third data type is a first preset value, the bit width of the exponent of the third data type is a second preset value, and the bit width of the mantissa of the third data type is a third preset value.
[0153] Optionally, in the third data type, the first preset value is 1, the second preset value is 9, and the third preset value is 12. That is, in the user-defined data type (that is, the third data type), the bit width of the sign is 1 bit; the bit width of the exponent is 9 bits, and the value represented by the exponent is a true value, that is, the exponent-bias described in the above IEEE754 standard; the bit width of the mantissa is 12 bits, including an 11-bit fractional part and a hidden 1-bit integer part, if it is 1, it means that the integer value is 1, if it is 0, it means that the integer value is 0, and the data is a denormalized number.
[0154] Since the IEEE754 standard also includes denormalized numbers, when encountering such data, the denormalized number is normalized and converted to (-1) sign *2 E *1.mantissa, E is the exponent minus the number of leading zeros in the mantissa. For example, the denormalized number is (-1) 0 *2 x *0.011, then normalize it to (-1) 0 *2 x-2 *1.1.
[0155] In the embodiment of the present application, the operation circuit 302 is used to perform operation based on the third floating-point number and the fourth floating-point number to obtain an operation result.
[0156] In the embodiment of the present application, the operation circuit 302 may include a multiplying accumulator array (also described as a MAC array) computing core, an accumulation circuit, and an output circuit.
[0157] The MAC array computing core is composed of multiple processing engines (PEs) (which can also be described as computing sub-units). Figure 4A The figure is a schematic diagram of the structure of a MAC array provided in an embodiment of the present application.
[0158] For example, the conversion circuit obtains the first floating-point number of the third data type from the memory and transmits it to the operation circuit, and the operation circuit broadcasts the first floating-point number of the third data type to PEs in multiple columns in the same row.
[0159] The conversion circuit obtains the second floating point number of the third data type from the memory and transmits it to the operation circuit, and the operation circuit broadcasts the second floating point number of the third data type to PEs in multiple rows of the same column.
[0160] In this way, each PE receives two floating-point numbers in each cycle, performs a point multiplication operation based on the received data, and adds the scalar value stored in the accumulation circuit to obtain the operation result.
[0161] Optionally, the PE includes multiple floating-point multipliers and multiple floating-point adders.
[0162] The accumulator circuit can be used to store the initialized scalar value, which includes the initial bias value data (such as bias value c0) required for the first calculation. The scalar value also includes the cache value (cx, x=1~n) calculated in each cycle after the data is cut due to the limited processing power of PE during each cycle processing.
[0163] The output circuit is used to output and cache the operation results.
[0164] For example, Figure 4B As shown, it is a flow chart of operation processing provided by an embodiment of the present application. Taking the limited processing capability of PE as an example, it is impossible to process longer vectors, so the longer vectors obtained by broadcast are cut into basic vectors respectively (such as cutting the vector a obtained in a row into a0, a1, a2...an-1, and cutting the vector b obtained in a column into b0, b1, b2...bn-1).
[0165] In each cycle of PE operation, a0*b0+c0=c1 is calculated first, and the multiplication and accumulation calculations are repeated based on the cache value (scalar value) generated by the previous calculation and the basic vector, a1*b1+c1=c2, a2*b2+c2=c3, ..., an-1*bn-1+cn=cn+1, until the final operation result cn+1 is obtained. The operation result cn+1 can be represented in the standard format defined by IEEE754 or in the integer two's complement format, which is not limited here.
[0166] In an embodiment of the present application, the PE in the multiplier accumulator array computing core may also include a vector computing subunit, a matrix computing subunit, a tensor computing subunit, and the like.
[0167] Among them, the vector computing subunit is a computing subunit with a certain degree of parallelism designed for vector (also known as vector, usually refers to a one-dimensional array with a length greater than 1) computing. This vector computing subunit is mostly used in fields such as HPC high-performance computing and AI machine learning, including solving mathematical problems such as linear programming, Fourier transform, filtering calculation, and linear algebra, partial differential equations, and integration.
[0168] In the embodiment of the present application, the vector may be a one-dimensional array composed of floating-point numbers. The vector calculation subunit performs vector calculation based on the floating-point numbers converted into the third data type.
[0169] The matrix computing subunit is a computing subunit with corresponding parallelism designed for matrix (a 2D array arranged in a rectangular array) computing. This matrix computing subunit is mostly used for matrix computing in the fields of HPC high-performance computing and AI machine learning, such as matrix multiplication, matrix inversion, matrix decomposition and other calculations.
[0170] In the embodiment of the present application, the matrix may be a two-dimensional array composed of floating point numbers. The matrix calculation subunit performs matrix calculation based on the floating point numbers converted into the third data type. The matrix calculation in the embodiment of the present application may be converted into vector calculation.
[0171] The tensor computing subunit is a computing subunit with corresponding parallelism designed for tensor (multi-dimensional arrays with a dimension of more than 2, mostly 3-dimensional arrays) computing. This tensor computing subunit is mostly used in the field of AI machine learning, such as convolution operations.
[0172] In the embodiment of the present application, the tensor may be a multidimensional array composed of floating point numbers. The tensor calculation subunit performs tensor calculation based on the floating point numbers converted into the third data type. The tensor calculation in the embodiment of the present application may also be converted into vector calculation.
[0173] It is understandable that the floating-point operation method of the embodiment of the present application is a basic operation for vector calculation, matrix calculation, and tensor calculation. The floating-point operation method of the embodiment of the present application can be applied to operation scenarios such as vector calculation, matrix calculation, and tensor calculation.
[0174] Optionally, the computing unit may further include a storage unit ( Figure 3 The storage unit may cache one-dimensional vector data, or matrix data composed of multiple groups of one-dimensional vector data, or tensor data composed of multiple groups of one-dimensional vector data (such as a feature map expressed by a general convolution calculation, or a weight expressed by a general convolution calculation).
[0175] In the embodiment of the present application, the storage unit can store a first floating point number and a second floating point number.
[0176] For example, the operation unit includes two storage units, storage unit 1 and storage unit 2. Storage unit 1 stores a first floating point number, and storage unit 2 stores a second floating point number. The data type of the first floating point number is a first data type, and the data type of the second floating point number is a second data type, and the first data type and the second data type are the same or different.
[0177] In the embodiment of the present application, the output end of the storage unit is connected to the input end of the conversion circuit 301. In this way, the conversion circuit 301 obtains the first floating point number and the second floating point number from the storage unit.
[0178] Optionally, the storage unit may be an SRAM, a register file, a double data rate (DDR) memory, or other memory, which is not limited here.
[0179] Optionally, the storage unit sends the stored floating-point number to a corresponding conversion circuit according to a control signal generated by a finite-state machine (FSM).
[0180] In some embodiments of the present application, Figure 5 As shown, it is a flow chart of a floating-point operation method provided in an embodiment of the present application, and the method comprises:
[0181] S501: Obtain a first floating-point number and a second floating-point number.
[0182] In the embodiment of the present application, the operation unit obtains the first floating-point number and the second floating-point number from the storage unit or the memory.
[0183] The data type of the first floating point number is the first data type, the data type of the second floating point number is the second data type, and the first data type and the second data type may be the same or different. The first floating point number includes one or more floating point numbers of the first data type, and the second floating point number includes one or more floating point numbers of the second data type, which are not limited here.
[0184] For example, the data type of the first floating point number is FP32, and the data type of the second floating point number is also FP32. Alternatively, the data type of the first floating point number is FP32, and the data type of the second floating point number is FP16.
[0185] S502: Convert a first floating point number of the first data type into a third floating point number of the third data type, and convert a second floating point number of the second data type into a fourth floating point number of the third data type.
[0186] The bit width of the mantissa of the third data type is greater than the bit width of the mantissa of a half-precision floating-point number and less than the bit width of the mantissa of a single-precision floating-point number.
[0187] like Fig. 6A As shown, it is a schematic diagram of the composition of the FP20 type floating-point number provided in an embodiment of the present application.
[0188] The embodiment of the present application defines a new data type FP20 based on the floating point number of the FP32 type defined in the IEEE 754 standard. That is, a floating point number FP20 of a custom data type is derived from FP32.
[0189] Specifically, the bit width of the sign in FP20 is 1 bit, the bit width of the exponent is 8 bits, and the bit width of the mantissa is 11 bits (the fractional part of the mantissa). In addition to the stored 11 bits of fractional part, the mantissa also includes a hidden 1 bit integer part, that is, the mantissa is a total of 12 bits.
[0190] like Figure 6B The figure shows the precision / data range of floating-point numbers of different data types. Figure 6B The horizontal axis is used to indicate the data range of floating-point numbers, and the vertical axis is used to indicate the precision of floating-point numbers.
[0191] according to Figure 6B From the information shown, it can be seen that the accuracy of FP20 provided by the embodiment of the present application is higher than that of FP16, BF16 and TF32, and the accuracy of FP20 is lower than that of FP32. The data range of FP20 is the same as that of BF16, TF32 and FP32, which is higher than the data range of FP16.
[0192] The third data type is an internal data type determined according to the above FP20, and is also a user-defined data type.
[0193] Specifically, the third data type includes a sign, an exponent, and a mantissa, wherein the bit width of the sign is a first preset value, the bit width of the exponent is a second preset value, and the bit width of the mantissa is a third preset value.
[0194] Specifically, the first preset value is 1, the second preset value is 9, and the third preset value is 12. That is, in the third data type, the bit width of the sign is 1 bit, the bit width of the exponent is 9 bits, and the bit width of the mantissa includes 11 bits of decimals and 1 bit of hidden integers, for a total of 12 bits.
[0195] It can be understood that the bit width of the mantissa of the third data type in the embodiment of the present application is 12 bits, which is higher than the bit width of the mantissa in FP16, BF16 and TF32. If the first data type of the first floating-point number A is FP32, when the first floating-point number A is converted into a floating-point number of data type TF32, according to the bit width of the mantissa of the first floating-point number A (24 bits) and the bit width of the mantissa in TF32 (11 bits), the mantissa of the first floating-point number A is split into three tails (such as a1, a2 and a3), the bit width of the first tail a1 and the second tail a2 are both 11 bits, and the bit width of the third tail a3 is 2 bits. Finally, the operation is performed based on the three tails. In the present application, the bit width of the mantissa of the third data type corresponding to FP20 is 12 bits. When the first floating-point number A is split, the mantissa of the first floating-point number A is split into two tails (such as b1 and b2) according to the bit width of the mantissa of the first floating-point number (24 bits) and the bit width of the mantissa of the third data type (12 bits). The bit widths of the first tail b1 and the second tail b2 are both 12 bits. Finally, the operation is performed based on the two tails. In this way, the present application can perform operations based on the tails with fewer numbers after splitting, which can effectively reduce the power consumption during operation.
[0196] Since the IEEE754 standard includes unformatted floating point numbers and formatted floating point numbers, the data types defined by the IEEE754 standard are all formatted floating point numbers.
[0197] For example, taking the FP32 floating point number as an example, (-1) 0 *2 5 *1.011 is a formatted floating point number, (-1) 0 *2 -126 *0.0011 is an unformatted floating point number. For formatted floating point numbers, the data range corresponding to the exponent is [-126, 127], so 8 bits of width can satisfy the above data range.
[0198] However, for unformatted floating-point numbers, the integer of the mantissa is first converted to 1. According to the above example, the decimal point needs to be moved 3 places to the right, and the exponent is subtracted from the number of leading zeros in the mantissa, that is, -126-3 = -129. At this time, if the bit width of the exponent is only 8 bits, 129 cannot be represented.
[0199] Therefore, the bit width of the exponent is increased by 1 bit, and the data range corresponding to the exponent is expanded to [-254, 255] to meet the requirements of unformatted floating-point number conversion.
[0200] In this way, both unformatted floating point numbers and formatted floating point numbers can be converted to internal data types, that is, normalized to (-1) sign *2 exponent*1.mantissa. Convert floating-point numbers of different data types into floating-point numbers of the same data type so that the accelerator can perform multiplication and accumulation processing based on the floating-point numbers of the same data type.
[0201] The following describes methods for converting floating-point numbers of some different data types into internal data types provided in embodiments of the present application.
[0202] like Figure 7 As shown, a data type conversion schematic diagram provided in an embodiment of the present application is provided.
[0203] See also Figure 7 It can be seen that the data type of the floating point number A is FP32, the bit width of the sign is 1 bit, the bit width of the exponent is 8 bits, and the memory numbering from high to low is 7-0; the bit width of the mantissa is 24 bits, the hidden bit is Mi, and the remaining memory numbers are 22-0 from high to low.
[0204] FP32 is disassembled and converted into floating-point numbers of two internal data types, and the mantissa of the floating-point number A is split into two parts, the high-order tail msb and the low-order tail lsb, and each part of the tail can be 12 bits. Among them, the specific value of the high-order tail msb is the value between the 23rd and 12th bits of the mantissa of the floating-point number A before disassembly, and the specific value of the high-order tail lsb is the value between the 11th and 0th bits of the mantissa of the floating-point number A before disassembly.
[0205] The first floating point number A1 after conversion is determined by the MSB of the high-order tail, and the second floating point number A0 is determined by the LSB of the low-order tail. The exponent of the floating point numbers A1 and A0 is 9 bits, and the mantissa is 12 bits.
[0206] The exponent of the first floating-point number A1 is int_exp1=int_exp1=fp32_exp-offset-lzd(fp32_man), where fp32_exp is the exponent of the floating-point number A before disassembly, offset is the offset value 127 of FP32, and lzd(fp32_man) is used to determine the number of leading zeros in the mantissa of the first floating-point number after disassembly.
[0207] The mantissa is int_man1=msb12(norm({fp32_man})), where msb12(norm({fp32_man})) is the mantissa after the high-order tail msb is formatted (can also be described as normalized). The specific value is the value between the 23rd and 12th bits of the mantissa of the floating-point number A before disassembly.
[0208] The exponent of the second floating-point number A0 is int_exp0=a_exp-12-lzd(fp32_man)-lzd(lsb12(norm(fp32_man))), where fp32_exp is the exponent of the floating-point number A before decomposition, 12 is the number of shifts of the mantissa of the second floating-point number, lzd(fp32_man) is used to determine the number of leading zeros in the mantissa of the first floating-point number after decomposition, and lzd(lsb12(norm(fp32_man))) is used to determine the number of leading zeros in the mantissa of the second floating-point number after decomposition.
[0209] The mantissa is int_man0=norm(lsb12(norm(fp32_man))), where norm(lsb12(norm(fp32_man))) is the mantissa after the low-order tail lsb is formatted. The specific value is the value between the 11th and 0th bits of the mantissa of the floating-point number A before disassembly.
[0210] The floating point number A is decomposed into two floating point numbers of internal data types. The specific implementation methods include the following cases.
[0211] Case 1: When floating-point number A is a formatted floating-point number and is non-zero, the mantissa of floating-point number A is decomposed into a first mantissa and a second mantissa, and two floating-point numbers of internal data types are determined according to the first mantissa, the second mantissa, the shift number, and the number of leading zeros.
[0212] For example, ±1.xxx×2 N →m0×2 N +m1×2 N-12 →M0×2 N +M1×2 N-12-lzd_cnt , where 1.xxx is the mantissa of the floating point number A, the number corresponding to 12 bits-23 bits in the mantissa is determined as the high-order tail m0, and the number corresponding to 0-11 bits in the mantissa is determined as the low-order tail m1, and the lengths of m0 and m1 are both 12 bits.
[0213] Among them, the integer bit (Mi) of m0 is 1, and the fractional bit (Mf) of the mantissa is Mf[22:12] of FP32, which is normalized to M0. m1 can have 1 to 23 leading zeros, so m1 needs to be renormalized so that the integer bit of the normalized mantissa M1 is 1, and the fractional bit is the 12-bit fractional part of m1 after normalization. At the same time, the exponent corresponding to M1 is determined by subtracting 12 from the original FP32 exponent and then subtracting the number of leading zeros (i.e. lzd_cnt).
[0214] For example, the normalized floating point number A is a floating point number of FP32 type. Assuming that the exponent of floating point A is e and the mantissa is 100000000000100000000001, the mantissa of floating point number A can be decomposed into the high tail m0: 100000000000 and the low tail m1: 100000000001. The length of m0 and m1 is 12 bits. Based on the high tail m0, the low tail m1 after decomposition needs to be right shifted 12 bits and then added to the high tail m0 to get the mantissa of floating point number A. Therefore, the exponent corresponding to the high tail m0 is e, and the exponent of the low tail m1 is e-12.
[0215] Based on the above example, if the mantissa of floating point number A is 100000000000001000000001, and the exponent is still e, the mantissa of floating point number A can be decomposed into the high tail m2: 100000000000, and the low tail m3: 001000000001, and the length of m2 and m3 are both 12 bits. The integer in the low tail m3 after decomposition is 0, and there are 2 leading zeros before the first valid digit 1.
[0216] Therefore, the low-order tail m3 needs to be normalized to make it an integer of 1, so on the basis of right shifting the low-order tail m3 by 12 bits, it is right shifted by 2 bits. Therefore, the exponent corresponding to the high-order tail m2 is e, and the exponent of the low-order tail m3 is e-14.
[0217] Case 2: When the floating-point number A is an unformatted floating-point number, the exponent is normalized and adjusted according to the number of leading zeros; the normalized floating-point number is decomposed into two floating-point numbers of the internal data type.
[0218] For example, when a floating point number A (such as ±0.xxx×2 -126 ) is an unformatted floating point number, according to the IEEE754 specification and the bit width of each part in FP32, the exponent of the floating point number A is 2 -126 , the mantissa is 0.xxx, and there can be 1 to 23 leading zeros. Therefore, the floating point number A is first normalized into a formatted floating point number (such as ±1.xxx×2 N ), and then decompose the normalized floating-point number into two floating-point numbers of internal data types according to the processing method of the above case 1.
[0219] For example, the denormalized floating point number A is a floating point number of FP32 type. Assume that the exponent of floating point number A is -126, the mantissa is 000100000000100000000001, the integer in the mantissa is 0, and there are 3 leading zeros before the first significant digit 1. Therefore, the floating point number A is normalized to the floating point number B: 100000000100000000001000, and the exponent corresponding to the floating point number B is -126-3=-129.
[0220] The floating point number B is disassembled in the manner described in the above case 1. The mantissa of the floating point number B can be disassembled into the high tail m4: 100000000100 and the low tail m5: 000000001000, and the lengths of m4 and m5 are both 12 bits. Accordingly, the exponent corresponding to the high tail m4 is -129. Since the low tail m5 also contains 8 leading zeros, the exponent corresponding to the low tail m5 is -129-12-8=-149.
[0221] Case 3: When the floating-point number A is +0 / -0, the sign bit of the floating-point numbers of the two internal data types after disassembly is 0, and the integer and decimal parts of the mantissa are both 0.
[0222] Case 4: When the floating-point number A is NaN, the floating-point numbers of the two internal data types are all expressed as 0; when the floating-point number A is infinity (±INF), the floating-point numbers of the two internal data types are all expressed as ±MAX.
[0223] like Figure 8 As shown, it is another data type conversion schematic diagram provided in an embodiment of the present application.
[0224] See also Figure 8 It can be seen that the data type of the floating point number A is FP20, the bit width of the sign is 1 bit, the bit width of the exponent is 8 bits, and the memory numbering from high to low is 7-0; the bit width of the mantissa is 24 bits, the hidden bit is Mi, and the remaining memory numbers are 22-0 from high to low.
[0225] FP20 is disassembled and converted into a floating point number A0 of an internal data type. The tail of A0 after conversion is 12 bits and the exponent is 9 bits.
[0226] The exponent of the floating point number A0 is int_exp=fp32_exp-offset-lzd(fp32_man), where fp32_exp is the exponent of the floating point number A before disassembly, offset is the offset value 127 of FP32, and lzd(fp32_man) is used to determine the number of leading zeros in the mantissa of the floating point number A0 after disassembly.
[0227] The mantissa is int_man=rnd_to_12bit(norm(fp32_man)), where rnd_to_12bit(norm(fp32_man)) is used to indicate that the mantissa of the original floating point number A is disassembled into 12 bits. The specific value is the value between the 23rd and 12th bits of the mantissa of the floating point number A before disassembly, which is consistent with the mantissa of FP20 before disassembly.
[0228] The data type of floating-point number A is FP20. The floating-point number A is decomposed into a floating-point number of an internal data type. The specific implementation methods include the following cases.
[0229] It is understandable that the tail of FP20 is 20 bits, and there is no corresponding data storage format in the computer. Therefore, the floating-point number of type FP20 is represented in the computer as FP32, that is, 1-8-23+1.
[0230] Case 1: When floating point number A is a formatted floating point number and is non-zero, the floating point number A is disassembled into a floating point number of an internal data type.
[0231] The exponent of the floating-point number of the internal data type is the exponent value minus the offset value defined by IEEE754 (2 8 -1 -1=127) or other signed number after the offset value.
[0232] In a possible implementation, the first tail is determined by truncation or rounding, and a floating point number of an internal data type is obtained according to the first tail, wherein the length of the first tail is 12 bits. Optionally, the rounding method includes rounding to the nearest integer, etc., which is not limited here.
[0233] For example, Mf[11:0] of the mantissa of the floating point number A is truncated, and Mf[23:12] is retained as the first mantissa, and a floating point number of the internal data type is obtained based on the first mantissa.
[0234] For example, the normalized floating point number A is a floating point number of FP20 type, but is expressed as FP32. Assuming that the exponent of floating point A is e and the mantissa is 10100000000000000000000, the 00000000000 corresponding to the last 12 bits of the mantissa of floating point number A is truncated, and the 101000000000 corresponding to the first 12 bits is retained, and the exponent corresponding to the first 12 bits is e.
[0235] Case 2: When floating-point number A is an unformatted floating-point number, floating-point number A is decomposed into a floating-point number of an internal data type through normalization.
[0236] For example, when a floating point number A (such as ±0.xxx×2 -126 ) is an unformatted floating point number, according to the IEEE754 specification and the bit width of each part in FP32, the exponent of the floating point number A is 2 -126, the mantissa is 0.xxx, and there can be 1 to 23 leading zeros. Therefore, the floating point number A is first normalized so that the integer bit of the first mantissa after normalization is 1, and the exponent corresponding to the first mantissa becomes the original exponent minus the number of leading zeros (i.e. lzd_cnt), i.e. ±0.xxx×2 -126 →±1.xxx×2 -126-lzd_cnt .
[0237] For example, the denormalized floating point number A is a floating point number of type FP20, but is represented as FP32. Assume that the exponent of floating point A is -126, the mantissa is 0001100000000000000000000, the integer in the mantissa is 0, and there are 3 leading zeros before the first significant digit 1.
[0238] Therefore, the floating point number A is normalized to the floating point number B: 1100000000000000000000000, and the exponent corresponding to the floating point number B is -126-3=-129. The floating point number B is disassembled in the manner described in the above case 1. Only the first 12 bits of the mantissa of the floating point number B are retained: 110000000000, and the corresponding exponent is -129.
[0239] Case 3: When the floating-point number A is +0 / -0, the sign bit of the floating-point number of the internal data type after disassembly is 0, and the integer and decimal parts of the mantissa are both 0.
[0240] Case 4: When the floating-point number A is NaN, a floating-point number of an internal data type is always expressed as 0; when the floating-point number A is infinity (±INF), a floating-point number of an internal data type is always expressed as ±MAX.
[0241] like Fig. 9 As shown, it is another data type conversion schematic diagram provided in an embodiment of the present application.
[0242] See also Fig. 9 It can be seen that the data type of the floating point number A is FP16, the bit width of the sign is 1 bit, the bit width of the exponent is 5 bits, and the memory numbering from high to low is 4-0; the bit width of the mantissa is 11 bits, the hidden bit is Mi, and the remaining memory numbers are 9-0 from high to low.
[0243] FP16 is completed and converted into a floating point number A0 of an internal data type. The tail of A0 after conversion is 12 bits and the exponent is 9 bits.
[0244] The exponent of floating point number A0 is int_exp=fp16_exp-offset-lzd(fp16_man), where fp16_exp is the exponent of floating point number A before decomposition, offset is the offset value 15 of FP16, and lzd(fp16_man) is used to determine the number of leading zeros in the mantissa of floating point number A0 after decomposition. The mantissa is int_man=norm(fp16_man), where norm(fp16_man) is the mantissa of the original floating point number A after formatting. The specific values of the 10th to 1st bits in the mantissa of floating point number A0 correspond one-to-one to the 9th to 0th bits of the mantissa of floating point number A before decomposition, and the lowest bit is always 0.
[0245] The data type of the floating point number A is FP16. The floating point number A is completed into a floating point number of the internal data type. The specific implementation methods include the following cases.
[0246] It is understandable that the representation of FP16 is 1-5-10 + 1. The bit width of the exponent and mantissa of FP16 is smaller than the bit width of the exponent and mantissa in the internal data type.
[0247] Case 1: When floating point number A is a formatted floating point number and is non-zero, the floating point number A is completed into a floating point number of the internal data type.
[0248] The exponent of the floating-point number of the internal data type is the exponent value minus the offset value defined by IEEE754 (2 5 -1 -1=15) or other signed number after the offset value.
[0249] Since the bit width of the mantissa of FP16 is smaller than the bit width of the mantissa in the internal data type, a floating-point number of the internal data type can be obtained by padding the low bits with zeros.
[0250] In this way, the integer bit of the mantissa of the floating-point number converted into the internal data type is 1, the decimal part Mf[10:1] corresponds one-to-one with Mf[9:0] in the mantissa of the FP16 original code, and the lowest bit Mf[0] is always 0.
[0251] Exemplarily, the normalized floating-point number A is a floating-point number of the FP16 data type. Assuming that the exponent of the floating-point number A is e and the mantissa is 10100000000, a 0 is added to the lowest bit of the mantissa to obtain the converted mantissa: 101000000000, and the corresponding exponent is e.
[0252] Case 2: When floating-point number A is an unformatted floating-point number, floating-point number A is completed into a floating-point number of an internal data type through normalization.
[0253] For example, when a floating point number A (such as ±0.xxx×2-14 ) is an unformatted floating point number, according to the IEEE754 specification and the bit width of each part in FP16, the exponent of the floating point number A is 2 -14 , the tail is 0.xxx, and there can be 1 to 10 leading zeros.
[0254] Therefore, the floating point number A is first normalized so that the integer bit of the first mantissa after normalization is 1, and the exponent corresponding to the first mantissa becomes the original exponent minus the number of leading zeros (i.e. lzd_cnt), i.e. ±0.xxx×2 -14 →±1.xxx×2 -14-lzd_cnt .
[0255] Case 3: When the floating-point number A is +0 / -0, the sign bit of the floating-point number of the internal data type after completion is 0, and the integer and decimal parts of the mantissa are both 0.
[0256] Case 4: When the floating-point number A is NaN, a floating-point number of an internal data type is always expressed as 0; when the floating-point number A is infinity (±INF), a floating-point number of an internal data type is always expressed as ±MAX.
[0257] like Fig.10 As shown, it is another data type conversion schematic diagram provided in an embodiment of the present application.
[0258] See also Fig.10 It can be seen that the data type of floating point number A is BF16, the bit width of the sign is 1 bit, the bit width of the exponent is 8 bits, and the memory numbering from high to low is 7-0; the bit width of the mantissa is 7 bits, the hidden bit is Mi, and the remaining memory numbers are 6-0 from high to low.
[0259] BF16 is completed and converted into a floating point number A0 of an internal data type. The tail of A0 after conversion is 12 bits and the exponent is 9 bits.
[0260] The exponent of floating point number A0 is int_exp=bf16_exp-offset-lzd(bf16_man), where bf16_exp is the exponent of floating point number A before decomposition, offset is the offset value 127 of BF16, and lzd(bf16_man) is used to determine the number of leading zeros in the mantissa of floating point number A0 after decomposition. The mantissa is int_man=norm(bf16_man), where norm(bf16_man) is the mantissa of the original floating point number A after formatting. The specific values of the 10th to 4th bits in the mantissa of floating point number A0 correspond one-to-one to the 6th to 0th bits of the mantissa of floating point number A before decomposition, and the 3rd to 0th bits are always 0.
[0261] The data type of floating point number A is BF16. The floating point number A is completed into a floating point number of the internal data type. The specific implementation methods include the following cases.
[0262] It is understandable that the representation of BF16 is 1-8-7+1. The bit widths of the exponent and mantissa of BF16 are smaller than the bit widths of the exponent and mantissa in the internal data type.
[0263] Case 1: When floating point number A is a formatted floating point number and is non-zero, the floating point number A is completed into a floating point number of the internal data type.
[0264] The exponent of the floating-point number of the internal data type is the exponent value minus the offset value defined by IEEE754 (2 8 -1 -1=127) or other signed number after the offset value.
[0265] Similar to the above FP16, the bit width of the mantissa of BF16 is smaller than the bit width of the mantissa in the internal data type, and a floating point number of the internal data type is obtained by padding the low bits with zeros.
[0266] In this way, the integer bit of the mantissa of the floating-point number converted into the internal data type is 1, Mf[10:4] in the decimal part corresponds one-to-one with Mf[6:0] in the BF16 original code mantissa, and Mf[3:0] in the decimal part is always 0.
[0267] Exemplarily, the normalized floating point number A is a floating point number of type BF16. Assuming that the exponent of the floating point number A is e and the mantissa is 10100000, three zeros are added to the end of the mantissa to obtain the converted mantissa: 101000000000, and the corresponding exponent is e.
[0268] Case 2: When floating-point number A is an unformatted floating-point number, floating-point number A is completed into a floating-point number of an internal data type through normalization.
[0269] For example, when a floating point number A (such as ±0.xxx×2 -126 ) is an unformatted floating point number, according to the IEEE754 specification and the bit width of each part in BF16, the exponent of the floating point number A is 2 -126 , the tail is 0.xxx, and there can be 1 to 7 leading zeros.
[0270] Therefore, the floating point number A is first normalized so that the integer bit of the first mantissa after normalization is 1, and the exponent corresponding to the first mantissa becomes the original exponent minus the number of leading zeros (i.e. lzd_cnt), i.e. ±0.xxx×2 -126 →±1.xxx×2 -126-lzd_cnt .
[0271] Case 3: When the floating-point number A is +0 / -0, the sign bit of the floating-point number of the internal data type after completion is 0, and the integer and decimal parts of the mantissa are both 0.
[0272] Case 4: When the floating-point number A is NaN, a floating-point number of an internal data type is always expressed as 0; when the floating-point number A is infinity (±INF), a floating-point number of an internal data type is always expressed as ±MAX.
[0273] In this way, floating point numbers of different data types are converted into floating point numbers of a unified internal data type according to the above method, and then operations are performed based on the converted floating point numbers.
[0274] Moreover, the bit width of the exponent of the third floating-point number of the converted third data type and the bit width of the exponent of the fourth floating-point number of the converted third data type are both greater than the bit width of the exponent of the first floating-point number of the first data type and the bit width of the exponent of the second floating-point number of the second data type.
[0275] In some embodiments of the present application, if the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both higher than a third preset value, the first floating-point number of the first data type is decomposed into multiple third floating-point numbers of the third data type, and the second floating-point number of the second data type is decomposed into multiple fourth floating-point numbers of the third data type.
[0276] For example, if the first floating point number A and the second floating point number B are both FP32 floating point numbers, the mantissa of the first floating point number is divided into two parts, A0 and A1, where A1 is the high-order part after disassembly, and A0 is the low-order part after disassembly. The mantissa of the second floating point number is divided into two parts, B0 and B1, where B1 is the high-order part after disassembly, and B0 is the low-order part after disassembly. Moreover, the bit widths of A0, A1, B0 and B1 are all 12 bits.
[0277] In other embodiments of the present application, if the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than a third preset value, the first floating-point number of the first data type is padded to a third floating-point number of the third data type, and the second floating-point number of the second data type is padded to a fourth floating-point number of the third data type.
[0278] For example, if the first floating point number A and the second floating point number B are both FP16 floating point numbers, the mantissa of the first floating point number is padded to A0, and the mantissa of the second floating point number is padded to B0. Moreover, the bit widths of A0 and B0 are both 12 bits.
[0279] In some other embodiments of the present application, if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both higher than a third preset value, the first floating-point number of the first data type is decomposed into multiple third floating-point numbers of the third data type, and the second floating-point number of the second data type is decomposed into multiple fourth floating-point numbers of the third data type.
[0280] For example, if the first floating point number A is an FP32 floating point number and the second floating point number B is an FP20 floating point number, the mantissa of the first floating point number is divided into two parts, A0 and A1, wherein A1 is the high-order part after the decomposition and A0 is the low-order part after the decomposition. The mantissa of the second floating point number is divided into B0. Moreover, the bit widths of A0, A1 and B0 are all 12 bits.
[0281] In some other embodiments of the present application, if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than a third preset value, the first floating-point number of the first data type is padded to a third floating-point number of the third data type, and the second floating-point number of the second data type is padded to a fourth floating-point number of the third data type.
[0282] For example, if the first floating point number A is an FP16 floating point number and the second floating point number B is a BF16 floating point number, the mantissa of the first floating point number is padded to A0 and the mantissa of the second floating point number is padded to B0. Moreover, the bit widths of A0 and B0 are both 12 bits.
[0283] In some other embodiments of the present application, if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is lower than a third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is higher than the third preset value, then the first floating-point number of the first data type is completed into a third floating-point number of the third data type, and the second floating-point number of the second data type is disassembled into multiple fourth floating-point numbers of the third data type.
[0284] For example, if the first floating point number A is an FP16 floating point number and the second floating point number B is an FP32 floating point number, the mantissa of the first floating point number is completed to A0, and the mantissa of the second floating point number is divided into B0 and B1. Among them, B1 is the high-order part after disassembly, and B0 is the low-order part after disassembly. Moreover, the bit widths of A0, B0 and B1 are all 12 bits.
[0285] In some other embodiments of the present application, if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is higher than a third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is lower than the third preset value, then the first floating-point number of the first data type is disassembled into multiple third floating-point numbers of the third data type, and the second floating-point number of the second data type is disassembled and completed into a fourth floating-point number of the third data type.
[0286] S503: Perform calculation according to the third floating-point number and the fourth floating-point number to obtain a calculation result.
[0287] In one possible implementation, an addition operation is performed based on the exponent of the third floating-point number and the exponent of the fourth floating-point number to obtain an exponential addition result; a multiplication operation is performed based on the mantissa of the third floating-point number and the mantissa of the fourth floating-point number to obtain a mantissa product result; and an operation result is obtained based on the exponential addition result, the mantissa product result, and the scalar value.
[0288] In an embodiment of the present application, the operation unit includes a plurality of floating-point multipliers and a plurality of floating-point adders. The plurality of floating-point multipliers are used to perform an XOR calculation according to the sign of the third floating-point number of the converted third data type and the sign of the fourth floating-point number of the converted third data type to obtain a sign XOR result; perform addition calculation on the exponent of the third floating-point number of the converted third data type and the exponent of the fourth floating-point number of the converted third data type to obtain an exponential sum result; perform multiplication calculation on the mantissa of the third floating-point number of the converted third data type and the mantissa of the fourth floating-point number of the converted third data type to obtain a mantissa product result. Subsequently, the sign XOR result, the exponential sum result and the mantissa product result are output to the floating-point adder in the operation unit. The plurality of floating-point adders are used to perform addition calculation on the input mantissa product results to obtain a mantissa sum result, and obtain the operation result according to the mantissa sum result, the sign XOR result, the exponential sum result and the scalar value.
[0289] Exemplarily, based on the above example of S502, if the first floating point number A and the second floating point number B are both FP32 floating point numbers, when processing the FP32 floating point number calculation, the multiplication of the mantissa part of the first floating point number A and the mantissa part of the second floating point number B and the addition of the exponent part can be expressed as Formula 1.
[0290] Formula 1
[0291] A×B=(A1×2 A1_exp +A0×2 A0_exp )×(B1×2 B1_exp +B0×2 B0_exp )
[0292] =(A1×B1)×2 A1_exp+B1_exp+(A1×B0)×2 A1_exp+B0_exp
[0293] +(A0×B1)×2 A0_exp+B1_exp +(A0×B0)×2 A0_exp+B0_exp
[0294] Among them, the mantissa part of the first floating point number A includes A1 and A0, the exponent corresponding to A1 is A1_exp, and the exponent corresponding to A0 is A0_exp; the mantissa part of the second floating point number B includes B1 and B0, the exponent corresponding to B1 is B1_exp, and the exponent corresponding to B0 is B0_exp.
[0295] If the first floating point number A and the second floating point number B are both FP16 floating point numbers, when processing FP16 floating point number calculations, the multiplication of the mantissa part of the first floating point number A and the mantissa part of the second floating point number B and the addition of the exponent part can be expressed as Formula 2.
[0296] Formula 2
[0297] A×B=(A0×2 A0_exp )×(B0×2 B0_exp )
[0298] =(A0×B0)×2 A0_exp+B0_exp
[0299] The mantissa of the first floating point number A includes A0, and the exponent corresponding to A0 is A0_exp; the mantissa of the second floating point number B includes B0, and the exponent corresponding to B0 is B0_exp.
[0300] If the first floating point number A is an FP32 floating point number and the second floating point number B is an FP20 floating point number, when processing FP32 and FP20 floating point number calculations, the multiplication of the mantissa part of the first floating point number A and the mantissa part of the second floating point number B and the addition of the exponent part can be expressed as Formula 3.
[0301] Formula 3
[0302] A×B=(A1×2 A1_exp +A0×2 A0_exp )×(B0×2 B0_exp )
[0303] =(A1×B0)×2 A1_exp+B0_exp +(A0×B0)×2 A0_exp+B0_exp
[0304] The mantissa of the first floating point number A includes A1 and A0, the exponent corresponding to A1 is A1_exp, and the exponent corresponding to A0 is A0_exp; the mantissa of the second floating point number B includes B0, and the exponent corresponding to B0 is B0_exp.
[0305] If the first floating point number A is an FP16 floating point number and the second floating point number B is an FP32 floating point number, when processing FP16 and FP32 floating point number calculations, the multiplication of the mantissa part of the first floating point number A and the mantissa part of the second floating point number B and the addition of the exponent part can be expressed as Formula 4.
[0306] Formula 4
[0307] A×B=(A0×2 A0_exp )×(B1×2 B1_exp +B0×2 B0_exp )
[0308] =(A0×B1)×2 A0_exp+B1_exp +(A0×B0)×2 A0_exp+B0_exp
[0309] The mantissa of the first floating point number A includes A0, and the exponent corresponding to A0 is A0_exp; the mantissa of the second floating point number B includes B1 and B0, and the exponent corresponding to B1 is B1_exp, and the exponent corresponding to B0 is B0_exp.
[0310] Those skilled in the art will appreciate that the method steps described herein are not limited to the order exemplarily shown in the drawings, but may be executed in any other feasible order.
[0311] In an embodiment of the present application, the floating-point number operation method converts the first floating-point number of the first data type into a third floating-point number of the third data type, and converts the second floating-point number of the second data type into a fourth floating-point number of the third data type for the first floating-point number and the second floating-point number after the conversion. The operation is performed according to the converted third floating-point number and the fourth floating-point number to obtain the operation result. Among them, the data type of the first floating-point number is the first data type, the data type of the second floating-point number is the second data type, and the first data type and the second data type are the same or different; the bit width of the mantissa of the third data type is higher than the bit width of the mantissa of the half-precision floating-point number and lower than the bit width of the mantissa of the single-precision floating-point number. For floating-point numbers of different data types, they are uniformly converted into a custom data type, and the operation is performed according to the converted custom data type, which can reduce the power consumption during the operation, is conducive to the rational use of computing performance, and improves the accuracy of the operation result, thereby achieving a relatively balanced effect between accuracy and power consumption.
[0312] like Fig.11 As shown, it is a flow chart of PE performing floating-point operations in an embodiment of the present application.
[0313] Exemplarily, if the first floating-point number A and the second floating-point number B are both FP32-type floating-point numbers, when processing the calculation of FP32-type floating-point numbers, the conversion circuit splits the mantissa of the floating-point number A and converts it into A1 and A0 of the third data type, and splits the mantissa of the floating-point number B and converts it into B1 and B0 of the third data type.
[0314] Among them, A1, A0, B1 and B0 are all 12 bits. The exponent part corresponding to A1 is A1_exp, the exponent part corresponding to A0 is A0_exp, the exponent part corresponding to B1 is B1_exp, and the exponent part corresponding to B0 is B0_exp.
[0315] Each unsigned 12-bit multiplication (MUL) in PE, namely U12, calculates A1*B1, A1*B0, A0*B1 and A0*B0 respectively to obtain multiple unsigned multiplication data, namely the mantissa product result.
[0316] At the same time, the first maximum exponent determination module (which can be described as find_max_exp) obtains the exponent corresponding to each group of mantissas and determines the maximum exponent value; and sends the maximum exponent value to each difference determination module (which can be described as delta).
[0317] For example, the first U12 calculates A1*B1, and the corresponding exponents are A1_exp and B1_exp. The second U12 calculates A1*B0, and the corresponding exponents are A1_exp and B0_exp. The third U12 calculates A0*B1, and the corresponding exponents are A0_exp and B1_exp. The fourth U12 calculates A0*B0, and the corresponding exponents are A0_exp and B0_exp. After find_max_exp obtains the exponents of each group of mantissas, it adds the exponents of each group and determines the maximum exponent value Emax based on the sum of the exponents of each group.
[0318] After find_max_exp determines the maximum exponent value, the maximum exponent value is sent to a second maximum exponent determination module (which may also be described as find_max and delta).
[0319] find_max and delta obtains the scalar value (including initial bias value data and cache value) stored in the accumulator circuit in the operation unit. After obtaining the maximum exponent value sent by find_max_exp, the exponent of the scalar value is compared with the maximum exponent value, and the difference between the two is sent to the mantissa exchange module (also described as mantissa exchange) and the second shift register (described as rshift2). The maximum value of the two is sent to the normalization module (normalization), and the normalization module uses the received data as one of the benchmarks for the exponent value of the final output.
[0320] For example, if the exponent of the scalar value is greater than the maximum exponent value, the exponent of the scalar value is sent to normalization, and the difference between the two is sent to the mantissa exchange and the second shift register.
[0321] After obtaining the maximum exponent value, each delta performs a subtraction operation based on the maximum exponent value and the exponent sum of each group of mantissas to determine the exponent difference between each group of exponent sums and the maximum exponent value. Subsequently, the exponent difference is sent to the first shift register (also described as rshift1).
[0322] For example, each delta is calculated as follows: Emax-(A1_exp+B1_exp)=E0(E0≥0), Emax-(A1_exp+B0_exp)=E1(E1≥0), Emax-(A0_exp+B1_exp)=E2(E2≥0), and Emax-(A0_exp+B0_exp)=E3(E3≥0). Thus, the exponent of each group of mantissas and the exponent difference with the maximum exponent value (such as E0, E1, E2 and E3 mentioned above) are determined in the above manner.
[0323] Each rshift1 right-shifts the mantissa product result according to the exponent difference sent by the corresponding delta to align the decimal point, and sends the data after the decimal point to the first adder (adder1).
[0324] It can be understood that the exponent difference is the difference between the maximum exponent value and the sum of the mantissa exponents of each group, which is not less than 0, so the decimal point is moved to the right when moving.
[0325] For example, if E0 is 2, the decimal point in the mantissa product of A1*B1 is shifted right by two places; if E1 is 0, the decimal point in the mantissa product of A1*B0 is not moved. In this way, each group of mantissa product results is shifted right according to the exponent difference to align the decimal points.
[0326] For each data after the aligned decimal point sent by rshift1, adder1 performs an addition operation through the Wallace tree adder, and sends the mantissa addition result to the mantissa exchange and the second adder (mantissa adder).
[0327] The mantissa accumulator (accum_mantissa) is used to accumulate the mantissa of the scalar value and obtain the scalar value mantissa accumulation result. The scalar value mantissa accumulation result is sent to the mantissa exchange.
[0328] Mantissa exchange compares the mantissa addition result and the mantissa accumulation result of the scalar value according to the acquired data, swaps their positions according to the size of their exponents, and sends the data with the smaller exponent to the second shift register (rshift2).
[0329] The second shift register right-shifts the data with smaller exponent in the mantissa addition result and the scalar value mantissa accumulation result according to the difference between the exponent of the scalar value and the maximum exponent value, and sends the right-shifted data to the mantissa adder.
[0330] Mantissa adder performs an addition operation on the data sent by the second shift register and the data sent by mantissa exchange to obtain a first operation result.
[0331] The leading zero prediction module (also described as lza) is used to predict the number of leading zeros in the first operation result.
[0332] normalization is used to obtain the second operation result by normalization, rounding or other approximate methods according to the first operation result, the number of leading zeros and the maximum exponent sent by find_max and delta.
[0333] The accumulation output module (accum / result:) is used to accumulate the scalar value of the second operation result to obtain the cache value for the next round of calculation or to output the final operation result after the loop operation is completed.
[0334] In the embodiment of the present application, the first adder and the second adder are adders with configurable bit width, and the first shift register and the second shift register are registers with configurable bit width. In this way, the bit width can be selectively retained according to demand during calculation. In the addition stage, an adder / shifter with a larger bit width can be used to compensate for the loss of precision. Alternatively, in some low-precision scenarios, the available bit width of the adder is reduced to reduce the power consumption of the shifter and the adder. In this way, the power consumption and calculation accuracy are balanced.
[0335] like Fig.12, which is a schematic diagram of the structure of U12 provided in an embodiment of the present application.
[0336] Understandably, Fig.12 When the U12 shown is used for calculation, the mantissa is converted into the third data type, the bit width of the mantissa is 12 bits, and the expression range is 0 - 4095. The prior art generally uses a U12*U12 multiplier to calculate data with a bit width of 12 bits.
[0337] When the floating point number type is FP16, the mantissa bit width is 11 bits, and the expression range is 0-2047. When calculating the mantissa, only the U11*U11 multiplier is needed. Therefore, when the data type of the first floating point number and the data type of the second floating point number are not FP32 or FP20, the power consumption of the U12*U12 multiplier is higher than that of the U11*U11 multiplier. Therefore, the implementation of U12*U12 needs to be further optimized.
[0338] In the embodiment of the present application, the calculation of U12*U12 is implemented by a U11*U11 multiplier and a group of 4:2 compressors.
[0339] In the embodiment of the present application, the 12-bit mantissa is decomposed into two parts, U11 and U1. The width of U11 is 11 bits, which is the high 11 bits of the original input data (that is, the data between the 11th and 1st bits), and the width of U1 is 1 bit, which is the low 1 bit of the original input data (that is, the 0th bit). Among them, U1 is only 1 bit, so the specific value of U1 can be 1 or 0.
[0340] Thus, the U12*U12 operation can be expressed as:
[0341] U12*U12=(U11<<1+U1)*(U11<<1+U1)
[0342] =(U11*U11)<<2+[(U11*U1)<<1+(U1*U11)<<1+(U1*U1)]
[0343] In the embodiment of the present application, U11 may be implemented using a signed 12-bit multiplier (multiplication, MUL) (also described as S12).
[0344] Specifically, the data received in U11 is unsigned 11-bit data, which is converted into signed 12-bit data, and the converted signed 12-bit data can be calculated using S12, for example, using a Booth multiplier.
[0345] Specifically, S12*S12 is operated according to the converted signed 12-bit data to obtain a plurality of product results; the plurality of product results are then accumulated and compressed according to a carry save adder (CSA) to obtain two compressed data.
[0346] In this way, the calculation of U11*U11 is completed using the ordinary multiplier S12*S12, the logic resource costs of the two are similar, and S12*S12 can also support the calculation mode of signed integer multiplication.
[0347] It can be understood that the U11*U11 multiplier is an unsigned multiplier that can only multiply positive numbers, while the S12*S12 multiplier is a signed multiplier that can perform positive and negative multiplication in addition to positive multiplication.
[0348] In the embodiment of the present application, since the value of U1 can be 1 or 0, when the value of U1 is 0, the result of U11*U1 is 0; when the value of U1 is 1, the result of U11*U1 is U11. When the value of U1 is 0, the result of U1*U1 is 0; when the value of U1 is 1, the result of U1*U1 is 1.
[0349] Therefore, (U11*U1)<<1 and (U1*U11)<<1 can be understood as a bitwise AND operation between U11 and U1, and (U1*U1) can be understood as a 1-bit carry operation.
[0350] In this way, (U11*U1)<<1+(U1*U11)<<1+(U1*U1) can be understood as the addition of two numbers that can be masked to 0 and a 1-bit carry.
[0351] like Fig.12 As shown, in the embodiment of the present application, U12 includes an S12*S12 multiplier, a 4:2 compressor, a plurality of AND gates and a plurality of multiplexers (MUX).
[0352] Take the multiplication of two mantissas A0 and A1 as an example, the bit width of A0 and A1 is 12 bits.
[0353] A0 is split into A0[11:1] and A0[0], where A0[11:1] is the high 11 bits and A0[0] is the low 1 bit. A1 is split into A1[11:1] and A1[0], where A1[11:1] is the high 11 bits and A1[0] is the low 1 bit.
[0354] In the embodiment of the present application, the S12*S12 multiplier receives input A0[11:1] and A1[11:1], respectively converts them into signed 12-bit data, and calculates 6 values based on the converted data, namely A:PP0, A:PP1, A:PP2, A:PP3, A:PP4 and A:PP5. Then, the accumulated results of the 6 values are compressed by the 6:2CSA compressor to obtain 2 compressed results, namely the first compressed result (also described as A:sum) and the second compressed result (also described as A:carry).
[0355] In the embodiment of the present application, the S12*S12 multiplier sends A:sum to the first multiplexer (also described as MUX1) and the 4:2 compressor. The left port of MUX1 receives A:sum. The S12*S12 multiplier sends A:carry to the second multiplexer (also described as MUX2) and the 4:2 compressor. The left port of MUX2 receives A:carry.
[0356] In the embodiment of the present application, MUX1 sends A:sum to a carry propagation adder (CPA), and MUX2 sends A:carry to the CPA.
[0357] In the embodiment of the present application, AND gate 1 receives A0[11:1] and A1[0] and calculates value 1. AND gate 2 receives A1[11:1] and A0[0] and calculates value 2. AND gate 3 receives A1[0] and A0[0] and calculates value 3.
[0358] In the embodiment of the present application, AND gate 1 sends value1 to the third multiplexer (also described as MUX3), the left port of MUX3 receives value1, and MUX3 sends value1 to the 4:2 compressor. AND gate 2 sends value2 to the fourth multiplexer (also described as MUX4), the left port of MUX4 receives value2, and MUX4 sends value2 to the 4:2 compressor. AND gate 3 sends value3 to the 4:2 compressor.
[0359] In an embodiment of the present application, the 4:2 compressor performs an accumulation operation based on the received multiple data (A:sum, A:carry, value1, value2 and value3), and compresses the accumulation results of the multiple data to obtain two compression results, namely value5 and value6. The 4:2 compressor sends value5 to MUX1, and the right port of MUX1 receives value5. The 4:2 compressor sends value6 to MUX2, and the right port of MUX2 receives value6.
[0360] In the embodiment of the present application, MUX1 and MUX2 respectively accumulate the received data and send the accumulated data to a carry propagate adder (CPA).
[0361] In the embodiment of the present application, the CPA adds the received data to obtain a calculation result.
[0362] It can be understood that the above operation process is the process of performing a product operation on data with a mantissa of 12 bits after disassembly in the embodiment of the present application. That is, when the data types of the first floating point number and the second floating point number are FP20 or FP32, the operation is completed in the above manner.
[0363] However, if the bit width of the mantissa of the floating-point number is less than 12 bits during calculation, the low-bit-width floating-point operation can be completed by using some functional devices. For example, when the data type of the floating-point number is FP16 or BF16, the bit width of the mantissa is equal to or less than 11 bits, so the operation can be completed by using only the U11*U11 multiplier, and according to the above content, the S12*S12 multiplier can implement the U11*U11 operation. Therefore, when the data type of the floating-point number is FP16 or BF16, only the U11*U11 multiplier can be used. Fig.12 The S12*S12 multiplier in the middle dotted box can complete the floating-point operation of this data type.
[0364] Specifically, if the data types of the first floating point number and the second floating point number are FP16 or BF16, the bit width of the mantissa is equal to or less than 11 bits, and the mantissa is directly sent to the S12*S12 multiplier, which calculates and outputs two compressed values. The two compressed values are directly transmitted to the CPA through MUX1 and MUX2 respectively, and the CPA accumulates and outputs the calculation result.
[0365] It is understandable that the bit width of an integer is 8 bits, and the S12*S12 multiplier can also perform integer operations to implement a calculation mode of two signed integer multiplications. Moreover, U12 also includes a 4:2 compressor, which can accumulate multiple data and output 2 compressed values. Based on the above characteristics, U12 can also be combined with an integer multiplier to implement multiple sets of integer multiplication operations.
[0366] Specifically, the right port of MUX3 in U12 is connected to an output terminal of the integer multiplier to receive a calculation result when the integer multiplier calculates the multiplication of two integers; the right port of MUX4 in U12 is connected to another output terminal of the integer multiplier to receive another calculation result when the integer multiplier calculates the multiplication of two integers. MUX3 sends the data received by MUX4 to the 4:2 compressor.
[0367] The S12*S12 multiplier in U12 calculates the 2 calculation results when the other two integers are multiplied, and sends the calculation results to the 4:2 compressor. The 4:2 compressor accumulates and compresses the received data (4 calculation results) into 2 compressed values, and then processes them through CPA to obtain the calculation results. In this way, U12 can realize multiple integer product operations, and the carry supports more operations.
[0368] In this way, the U12 in the embodiment of the present application can reduce the power consumption during calculation on the one hand, and support high-precision (such as FP20 / FP32) multiplication operations on the other hand. Moreover, the 4:2 compressor in U12 can also provide adder functions for other calculations, supporting more calculations.
[0369] The above mainly introduces the floating-point operation method provided by this embodiment from the perspective of a computing device. It can be understood that in order to implement the above functions, the computing device includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the network elements and algorithm steps of each example described in the embodiments disclosed in this document, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0370] The embodiment of the present application can divide the floating-point operation device into functional modules according to the above method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0371] In the case of dividing each functional module into corresponding functional modules, Fig.13 A possible structural diagram of a floating-point operation device involved in an embodiment of the present application is shown. The floating-point operation device may be a PCIe card, a SoC, a processor, and a server including the above hardware, etc.; or the device may be implemented in the form of software and stored in a storage medium.
[0372] like Fig.13 As shown, the floating-point operation device may be the operation unit in the above embodiment, and the floating-point operation device includes a conversion module 1301 and an operation module 1302 .
[0373] The conversion module 1301 is used to obtain a first floating point number and a second floating point number.
[0374] The data type of the first floating-point number is a first data type, the data type of the second floating-point number is a second data type, and the first data type and the second data type are the same or different.
[0375] The conversion module 1301 is further configured to convert a first floating point number of the first data type into a third floating point number of the third data type, and to convert a second floating point number of the second data type into a fourth floating point number of the third data type.
[0376] The bit width of the mantissa of the third data type is greater than the bit width of the mantissa of a half-precision floating-point number and less than the bit width of the mantissa of a single-precision floating-point number.
[0377] The operation module 1302 is used to perform operation according to the third floating-point number and the fourth floating-point number to obtain an operation result.
[0378] It should be understood that the device of the embodiment of the present application can be implemented by an application-specific integrated circuit (ASIC) or a programmable logic device (PLD), and the above-mentioned PLD can be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof.
[0379] It can also be achieved through software Figures 1 to 12 When the floating-point operation method is shown, the device and its various modules may also be software modules.
[0380] In one possible implementation, the third data type includes a sign, an exponent, and a mantissa; wherein the bit width of the sign of the third data type is a first preset value, the bit width of the exponent of the third data type is a second preset value, and the bit width of the mantissa of the third data type is a third preset value.
[0381] In the embodiment of the present application, the first preset value is 1, the second preset value is 9, and the third preset value is 12.
[0382] In one possible implementation, the conversion module 1301 is also used to decompose the first floating-point number of the first data type into multiple third floating-point numbers of the third data type, and to decompose the second floating-point number of the second data type into multiple fourth floating-point numbers and second floating-point numbers of the third data type if the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both higher than a third preset value.
[0383] Alternatively, the conversion module 1301 is also used to complete the first floating-point number of the first data type into a third floating-point number of the third data type, and to complete the second floating-point number of the second data type into a fourth floating-point number of the third data type if the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than a third preset value.
[0384] In another possible implementation, the conversion module 1301 is also used to decompose the first floating-point number of the first data type into multiple third floating-point numbers of the third data type, and to decompose the second floating-point number of the second data type into multiple fourth floating-point numbers of the third data type if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both higher than a third preset value.
[0385] Alternatively, the conversion module 1301 is also used to complete the first floating-point number of the first data type into a third floating-point number of the third data type, and complete the second floating-point number of the second data type into a fourth floating-point number of the third data type if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than a third preset value.
[0386] In another possible implementation, the conversion module 1301 is also used to complete the first floating-point number of the first data type into a third floating-point number of the third data type, and disassemble the second floating-point number of the second data type into multiple fourth floating-point numbers of the third data type if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is lower than a third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is higher than the third preset value.
[0387] Alternatively, the conversion module 1301 is also used to decompose the first floating-point number of the first data type into multiple third floating-point numbers of the third data type, and to decompose the second floating-point number of the second data type into a fourth floating-point number of the third data type if the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is higher than a third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is lower than the third preset value.
[0388] In an embodiment of the present application, the bit width of the exponent of the third floating-point number of the third data type and the bit width of the exponent of the fourth floating-point number of the third data type are both greater than the bit width of the exponent of the first floating-point number of the first data type and the bit width of the exponent of the second floating-point number of the second data type.
[0389] In a possible implementation, the operation module 1302 is further configured to perform an addition operation according to the exponent of the third floating-point number and the exponent of the fourth floating-point number to obtain an exponential addition result.
[0390] In a possible implementation, the operation module 1302 is further configured to perform a multiplication operation according to the mantissa of the third floating-point number and the mantissa of the fourth floating-point number to obtain a mantissa product result.
[0391] In a possible implementation, the operation module 1302 is further configured to obtain an operation result according to the exponential addition result, the mantissa product result, and the scalar value.
[0392] It should also be noted that the floating-point operation device provided in the above embodiment is only illustrated by the division of the above functional modules when calculating floating-point numbers. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the computing device is divided into different functional modules to complete all or part of the functions described above. In addition, the floating-point operation device provided in the above embodiment and the floating-point operation method embodiment belong to the same concept, and the specific implementation process thereof is detailed in the method embodiment, which will not be repeated here.
[0393] A floating-point operation device in an embodiment of the present application is described above from the perspective of a modular functional entity. A floating-point operation device in an embodiment of the present application is described below from the perspective of hardware processing.
[0394] The present application embodiment provides a floating point operation device, the structure of which can be as follows: Figure 1 As shown, the device may specifically be a PCIe card, a SoC, a processor, and a server including the above hardware. Figure 1 The device includes: a memory 101, a processor 102, a communication interface 103 and a bus 104. The communication interface 103 may include an input interface and an output interface.
[0395] Among them, the processor 102 can be configured to perform one or more steps of S501-S503 in the above method embodiment. In some feasible embodiments, the processor 102 may include a FSCU, which can be used to support the processor to perform one or more steps in the above method embodiment. The third data type in the method embodiment of the present application can be stored in the FSCU, or in the memory 101, or stored in a separate register, etc. In practical applications, the FSCU can be an ASIC, an FPGA, or a logic circuit, etc. Of course, the FSCU can also be implemented by software, and the embodiment of the present application does not impose specific restrictions on this.
[0396] It should be noted that the various components of the above-mentioned floating-point operation device provided in the embodiment of the present application are respectively used to implement the functions of the corresponding steps of the above-mentioned method embodiment. Since each step has been described in detail in the above-mentioned method embodiment, it will not be repeated here.
[0397] Various embodiments of the apparatus, modules, and methods described above in this document may be implemented in digital electronic circuit systems, integrated circuit systems, programmable array logic (PAL), programmable logic array (PLA), field programmable gate array (FPGA), erasable programmable logic device (EPLD), electrically erasable programmable logic device (EEPLD), logic cell array (LCA), coarse-grained reconfigurable architecture (CGRA), application specific integrated circuit, application specific standard product (ASSP), system on chip (SOC), complex programmable logic device (CPLD), computer hardware, firmware, software, and / or combinations thereof.
[0398] An embodiment of the present application also provides a chip system, including: a processor, the processor is coupled to a memory, the memory is used to store programs or instructions, when the program or instructions are executed by the processor, the chip system implements the method in any of the above method embodiments.
[0399] Optionally, the processor in the chip system may be one or more. The processor may be implemented by hardware or by software. When implemented by hardware, the processor may be a logic circuit, an integrated circuit, etc. When implemented by software, the processor may be a general-purpose processor implemented by reading software code stored in a memory.
[0400] Optionally, the memory in the chip system may also be one or more. The memory may be integrated with the processor or may be separately arranged with the processor, which is not limited in the embodiments of the present application. Exemplarily, the memory may be a non-transient processor, such as a read-only memory (ROM), which may be integrated with the processor on the same chip or may be arranged on different chips respectively. The embodiments of the present application do not specifically limit the type of memory and the arrangement of the memory and the processor.
[0401] Exemplarily, the chip system can be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), a central processor unit (CPU), a network processor (NP), a digital signal processor (DSP), a microcontroller unit (MCU), a programmable logic device (PLD) or other integrated chips.
[0402] It should be understood that each step in the above method embodiment can be completed by an integrated logic circuit of hardware in a processor or by instructions in the form of software. The method steps disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware processor, or by a combination of hardware and software modules in a processor.
[0403] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. When the computer program is run on a computer, the computer executes the above-mentioned related steps to implement the floating-point operation method in the above-mentioned embodiment.
[0404] The embodiment of the present application also provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute the above-mentioned related steps to implement the floating-point operation method in the above-mentioned embodiment.
[0405] An embodiment of the present application provides a circuit system, which includes a processing circuit, and the processing circuit is configured to execute the above-mentioned related steps to implement the floating-point operation method in the above-mentioned embodiment.
[0406] In addition, an embodiment of the present application further provides a device. The device may be a component or a module, and the device may include one or more processors and a memory connected to each other. The memory is used to store a computer program. When the computer program is executed by one or more processors, the device performs the method for sharing a keyboard and a mouse between multiple devices in the above-mentioned method embodiments.
[0407] Among them, the device, computer-readable storage medium, computer program product or chip provided in the embodiments of the present application are used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.
[0408] The steps of the method or algorithm described in conjunction with the disclosure of the embodiments of the present application can be implemented in a hardware manner, or can be implemented by a processor executing software instructions. The software instructions can be composed of corresponding software modules, and the software modules can be stored in a random access memory (RAM), a flash memory, a read-only memory, an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a register, a hard disk, a mobile hard disk, a compact disc read-only memory (CD-ROM) or any other form of storage medium known in the art. An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and can write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC).
[0409] Through the description of the above implementation methods, those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above functional modules is used as an example. In practical applications, the above functions can be assigned to different functional modules as needed; that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0410] In the several embodiments provided in the present application, it should be understood that the disclosed method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the modules or units is only a logical function division, and there may be other division methods in actual implementation; for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of modules or units, which can be electrical, mechanical or other forms.
[0411] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0412] The above embodiments may be implemented in whole or in part through software, hardware, firmware or any other combination.
[0413] When implemented using software, the above embodiments may be implemented in whole or in part in the form of a computer program product.
[0414] The computer program product includes one or more computer instructions. When the computer program instructions are loaded or executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device.
[0415] The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, Bluetooth, radio frequency identification (RFID), microwave, etc.) means.
[0416] The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or a data center that includes one or more available media. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium. The semiconductor medium may be a solid state drive (SSD).
[0417] The above description of the present disclosure is intended to enable any person of ordinary skill in the art to implement or use the present disclosure. Various modifications of the present disclosure are obvious to those of ordinary skill in the art, and the general principles defined herein may also be applied to other variations without departing from the spirit and scope of the present disclosure. Therefore, the present disclosure is not limited to the examples and designs described herein, but is consistent with the broadest scope of the principles and novel features disclosed herein.
Claims
1. A computing unit, characterized in that: The operation unit includes a conversion circuit and an operation circuit; The conversion circuit is used to obtain a first floating-point number and a second floating-point number; wherein the data type of the first floating-point number is a first data type, the data type of the second floating-point number is a second data type, and the first data type and the second data type are the same or different; The conversion circuit is further configured to convert the first floating-point number of the first data type into a third floating-point number of the third data type, and convert the second floating-point number of the second data type into a fourth floating-point number of the third data type; wherein the bit width of the mantissa of the third data type is greater than the bit width of the mantissa of a half-precision floating-point number and less than the bit width of the mantissa of a single-precision floating-point number; The operation circuit is used to perform operation according to the third floating-point number and the fourth floating-point number to obtain an operation result.
2. The computing unit according to claim 1, characterized in that: The third data type includes a sign, an exponent, and a mantissa; wherein the bit width of the sign of the third data type is a first preset value, the bit width of the exponent of the third data type is a second preset value, and the bit width of the mantissa of the third data type is a third preset value.
3. The computing unit according to claim 1 or 2, characterized in that: The conversion circuit is further configured to, if the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both greater than the third preset value, then disassemble the first floating-point number of the first data type into a plurality of third floating-point numbers of the third data type, and disassemble the second floating-point number of the second data type into a plurality of fourth floating-point numbers of the third data type; or, If the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than the third preset value, then completing the first floating-point number of the first data type into the third floating-point number of the third data type, and completing the second floating-point number of the second data type into the fourth floating-point number of the third data type; or, If the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both greater than the third preset value, then decomposing the first floating-point number of the first data type into a plurality of third floating-point numbers of the third data type, and decomposing the second floating-point number of the second data type into a plurality of fourth floating-point numbers of the third data type; or, If the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than the third preset value, the first floating-point number of the first data type is completed into the third floating-point number of the third data type, and the second floating-point number of the second data type is completed into the fourth floating-point number of the third data type; or, If the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is lower than the third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is higher than the third preset value, the first floating-point number of the first data type is completed into the third floating-point number of the third data type, and the second floating-point number of the second data type is disassembled into a plurality of fourth floating-point numbers of the third data type; or, If the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is higher than the third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is lower than the third preset value, then the first floating-point number of the first data type is disassembled into multiple third floating-point numbers of the third data type, and the second floating-point number of the second data type is disassembled and completed into the fourth floating-point number of the third data type.
4. The computing unit according to claim 1, characterized in that: The bit width of the exponent of the third floating-point number of the third data type and the bit width of the exponent of the fourth floating-point number of the third data type are both greater than the bit width of the exponent of the first floating-point number of the first data type and the bit width of the exponent of the second floating-point number of the second data type.
5. The computing unit according to any one of claims 1 to 4, characterized in that: The operation circuit is further used to perform an addition operation according to the exponent of the third floating-point number and the exponent of the fourth floating-point number to obtain an exponential addition result; The operation circuit is further used to perform a multiplication operation according to the mantissa of the third floating-point number and the mantissa of the fourth floating-point number to obtain a mantissa product result; The operation circuit is also used to obtain an operation result according to the exponential addition result, the mantissa product result and the scalar value.
6. The computing unit according to any one of claims 2 to 5, characterized in that: The first preset value is 1, the second preset value is 9, and the third preset value is 12.
7. A floating point operation method, characterized in that: include: Obtain a first floating-point number and a second floating-point number; wherein the data type of the first floating-point number is a first data type, the data type of the second floating-point number is a second data type, and the first data type and the second data type are the same or different; Converting the first floating-point number of the first data type into a third floating-point number of the third data type, and converting the second floating-point number of the second data type into a fourth floating-point number of the third data type; wherein the bit width of the mantissa of the third data type is greater than the bit width of the mantissa of a half-precision floating-point number and less than the bit width of the mantissa of a single-precision floating-point number; An operation is performed according to the third floating-point number and the fourth floating-point number to obtain an operation result.
8. The method according to claim 7, characterized in that The third data type includes a sign, an exponent, and a mantissa; wherein the bit width of the sign of the third data type is a first preset value, the bit width of the exponent of the third data type is a second preset value, and the bit width of the mantissa of the third data type is a third preset value.
9. The method according to claim 7 or 8, characterized in that: The converting the first floating-point number of the first data type into a third floating-point number of the third data type, and converting the second floating-point number of the second data type into a fourth floating-point number of the third data type, comprises: If the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both greater than the third preset value, then decomposing the first floating-point number of the first data type into a plurality of third floating-point numbers of the third data type, and decomposing the second floating-point number of the second data type into a plurality of fourth floating-point numbers and second floating-point numbers of the third data type; or, If the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than the third preset value, then the first floating-point number of the first data type is completed into the third floating-point number of the third data type, and the second floating-point number of the second data type is completed into the fourth floating-point number of the third data type; or, If the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both greater than the third preset value, then decomposing the first floating-point number of the first data type into a plurality of third floating-point numbers of the third data type, and decomposing the second floating-point number of the second data type into a plurality of fourth floating-point numbers of the third data type; or, If the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than the third preset value, the first floating-point number of the first data type is completed into the third floating-point number of the third data type, and the second floating-point number of the second data type is completed into the fourth floating-point number of the third data type; or, If the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is lower than the third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is higher than the third preset value, the first floating-point number of the first data type is completed into the third floating-point number of the third data type, and the second floating-point number of the second data type is disassembled into a plurality of fourth floating-point numbers of the third data type; or, If the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is higher than the third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is lower than the third preset value, then the first floating-point number of the first data type is disassembled into multiple third floating-point numbers of the third data type, and the second floating-point number of the second data type is disassembled and completed into the fourth floating-point number of the third data type.
10. The method according to claim 7, characterized in that The bit width of the exponent of the third floating-point number of the third data type and the bit width of the exponent of the fourth floating-point number of the third data type are both greater than the bit width of the exponent of the first floating-point number of the first data type and the bit width of the exponent of the second floating-point number of the second data type.
11. The method according to any one of claims 7 to 10, characterized in that: The performing operation according to the third floating-point number and the fourth floating-point number to obtain an operation result includes: Performing an addition operation according to the exponent of the third floating-point number and the exponent of the fourth floating-point number to obtain an exponential addition result; Performing a multiplication operation according to the mantissa of the third floating-point number and the mantissa of the fourth floating-point number to obtain a mantissa product result; An operation result is obtained according to the exponential addition result, the mantissa product result and the scalar value.
12. The method according to any one of claims 7 to 11, characterized in that The first preset value is 1, the second preset value is 9, and the third preset value is 12.
13. A floating point operation device, characterized in that: The device comprises: A conversion module, used to obtain a first floating-point number and a second floating-point number; wherein the data type of the first floating-point number is a first data type, the data type of the second floating-point number is a second data type, and the first data type and the second data type are the same or different; The conversion module is further configured to convert the first floating-point number of the first data type into a third floating-point number of the third data type, and convert the second floating-point number of the second data type into a fourth floating-point number of the third data type; wherein the bit width of the mantissa of the third data type is greater than the bit width of the mantissa of a half-precision floating-point number and less than the bit width of the mantissa of a single-precision floating-point number; The operation module is used to perform operation according to the third floating-point number and the fourth floating-point number to obtain an operation result.
14. The device according to claim 13, characterized in that The third data type includes a sign, an exponent, and a mantissa; wherein the bit width of the sign of the third data type is a first preset value, the bit width of the exponent of the third data type is a second preset value, and the bit width of the mantissa of the third data type is a third preset value.
15. The device according to claim 13 or 14, characterized in that The conversion module is further configured to, if the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both greater than the third preset value, decompose the first floating-point number of the first data type into a plurality of third floating-point numbers of the third data type, and decompose the second floating-point number of the second data type into a plurality of fourth floating-point numbers and second floating-point numbers of the third data type; or, If the first data type is the same as the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than the third preset value, then the first floating-point number of the first data type is completed into the third floating-point number of the third data type, and the second floating-point number of the second data type is completed into the fourth floating-point number of the third data type; or, If the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both greater than the third preset value, then decomposing the first floating-point number of the first data type into a plurality of third floating-point numbers of the third data type, and decomposing the second floating-point number of the second data type into a plurality of fourth floating-point numbers of the third data type; or, If the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type and the bit width of the mantissa of the second floating-point number of the second data type are both lower than the third preset value, the first floating-point number of the first data type is completed into the third floating-point number of the third data type, and the second floating-point number of the second data type is completed into the fourth floating-point number of the third data type; or, If the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is lower than the third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is higher than the third preset value, the first floating-point number of the first data type is completed into the third floating-point number of the third data type, and the second floating-point number of the second data type is disassembled into a plurality of fourth floating-point numbers of the third data type; or, If the first data type is different from the second data type, and the bit width of the mantissa of the first floating-point number of the first data type is higher than the third preset value, and the bit width of the mantissa of the second floating-point number of the second data type is lower than the third preset value, then the first floating-point number of the first data type is disassembled into multiple third floating-point numbers of the third data type, and the second floating-point number of the second data type is disassembled and completed into the fourth floating-point number of the third data type.
16. The device according to claim 13, characterized in that The bit width of the exponent of the third floating-point number of the third data type and the bit width of the exponent of the fourth floating-point number of the third data type are both greater than the bit width of the exponent of the first floating-point number of the first data type and the bit width of the exponent of the second floating-point number of the second data type.
17. The device according to any one of claims 13 to 16, characterized in that The operation module is further used to perform an addition operation according to the exponent of the third floating-point number and the exponent of the fourth floating-point number to obtain an exponential addition result; The operation module is further used to perform a multiplication operation according to the mantissa of the third floating-point number and the mantissa of the fourth floating-point number to obtain a mantissa product result; The operation module is further used to obtain an operation result according to the exponential addition result, the mantissa product result and the scalar value.
18. The device according to any one of claims 13 to 17, characterized in that The first preset value is 1, the second preset value is 9, and the third preset value is 12.
19. A chip, characterized in that: The chip comprises a computing unit, and the computing unit is used to implement the function implemented by the computing unit as claimed in any one of claims 1 to 6.
20. A computing device, characterized in that The computing device comprises a mainboard and a chip as claimed in claim 19, wherein the chip is arranged on the mainboard, and the chip comprises a computing unit, wherein the computing unit is used to implement the function implemented by the computing unit as claimed in any one of claims 1-6.
21. A computer-readable storage medium, characterized in that: The computer-readable storage medium comprises a computer program, and when the computer program is run on a computing device, the computing device is caused to perform the method according to any one of claims 7 to 12.
22. A computer program product, characterized in that When the computer program product is run on a computer, the computer is caused to execute the method according to any one of claims 7 to 12.
Citation Information
Cited By
Processing device, equipment, method and related products thereof
CN115600657A
A processing device, apparatus, method and related products thereof
CN115600657B
Floating-point number processing method and device, equipment, storage medium and program product
CN120653220A
Floating-point number processing method, apparatus, device, storage medium, and program product
CN120653220B
Inverse quantization method of model data, matrix operation method and related equipment
CN120671828A
