Floating point number processing device, method, electronic device, storage medium and chip
By extending the sign bits of the to-process floating point number to the target bit width and accumulating the order operator, the delay and data loss caused by normalization in floating point accumulation operation are solved, and the operation accuracy and efficiency are improved.
Patent Information
- Application Number
- CN202111667694.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-31
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2041-12-31
AI Technical Summary
The frequent normalization processing in floating-point number accumulation operation results in increased delay and power consumption, and the normalization processing causes data loss, reducing operation accuracy.
By expanding the sign bit of the floating point number to the target bit width, the number of normalization processing is reduced, and the expansion floating point number is directly accumulated. The order operator is used to align and accumulate the exponents to avoid the normalization of intermediate results.
It reduces the delay and power consumption of the floating-point number accumulation process, improves the calculation accuracy, reduces data loss, and improves the accuracy of the target floating-point number.
Smart Images

Figure CN114296682B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of integrated circuit technology, and in particular to a floating point number processing device, method, electronic device, storage medium and chip. Background Art
[0002] With the continuous development of semiconductor technology, computer architecture, and processor design architecture, processors are becoming more powerful and more complex. Among them, floating-point operations are a type of calculation in the processor that has many steps, large delays, and high power consumption, which has a great impact on the performance indicators of the processor.
[0003] Therefore, it is particularly important to propose a method to optimize the floating-point number processing process. Summary of the invention
[0004] In view of this, the present disclosure at least provides a floating-point number processing device, method, electronic device, storage medium and chip.
[0005] In a first aspect, the present disclosure provides a floating point number processing device, the device comprising: a selector and an adder; wherein the adder is connected to the selector;
[0006] The selector is used to expand the sign bit of each of the plurality of floating-point numbers to be processed to a target bit width, so as to obtain a plurality of expanded floating-point numbers; wherein the target bit width matches the total number of the floating-point numbers to be processed;
[0007] The adder is used to accumulate the multiple expanded floating-point numbers to obtain a target floating-point number.
[0008] In order to ensure the accuracy of the floating-point number accumulation process and meet the bit width requirements of the intermediate floating-point numbers obtained after the addition operation, the selector can be used to expand the sign bit of each floating-point number to be processed to the target bit width, and multiple expanded floating-point numbers can be obtained, thereby realizing the expansion of the bit width of the floating-point numbers to be processed. As a result, in the process of accumulating multiple expanded floating-point numbers, it is not necessary to normalize the intermediate floating-point numbers obtained in the accumulation process, which reduces the number of normalization processes and reduces the delay and power consumption of the chip in processing the accumulation process of multiple expanded floating-point numbers. At the same time, after reducing the number of normalization processes, the data loss problem caused by the normalization process can be alleviated, and the accuracy of the target floating-point number is improved.
[0009] In a possible implementation manner, the device further includes: a comparator; the comparator is connected to the adder;
[0010] The adder is further used to input the target floating-point number into the comparator;
[0011] The comparator is used to perform normalization processing on the target floating-point number to obtain a target processing result, wherein the format of the target processing result matches a preset format.
[0012] During implementation, during the accumulation process of multiple expanded floating-point numbers, there is no need to normalize the intermediate floating-point numbers obtained in the accumulation process; and after the target floating-point number is accumulated, the target floating-point number can be normalized once to obtain the target processing result, thereby reducing the number of normalization processes and reducing the delay and power consumption of the target chip in the accumulation process of multiple floating-point numbers; at the same time, it can alleviate the data loss problem caused by the normalization process and improve the accuracy of the target processing result.
[0013] In a possible implementation manner, the device further includes: an octave operator, the octave operator is connected to the adder and the selector respectively; the octave operator includes a subtractor and a shifter;
[0014] The subtractor is used to determine a target difference between an initial exponent of each expanded floating point number and a target exponent; wherein the target exponent is determined based on the initial exponents of the plurality of expanded floating point numbers;
[0015] The shifter is used for aligning the initial exponent of each extended floating-point number to the target exponent, and right-shifting the mantissa of the extended floating-point number based on the target difference corresponding to the extended floating-point number to obtain a processed floating-point number; and inputting the processed floating-point number into the adder;
[0016] The adder is used to accumulate the mantissas of the multiple processed floating-point numbers to obtain a target floating-point number.
[0017] In a possible implementation manner, the selector, when expanding the sign bit of each of the acquired multiple floating-point numbers to be processed to the target bit width to obtain multiple expanded floating-point numbers, is used to: select two floating-point numbers to be processed from the multiple floating-point numbers to be processed, and expand the sign bits of the two floating-point numbers to be processed to the target bit width to obtain two expanded floating-point numbers;
[0018] The subtractor is used to use the initial exponent of the first floating point number of the two expanded floating point numbers as the target exponent; determine a first difference between the target exponent and the initial exponent of the second floating point number of the two expanded floating point numbers; wherein the initial exponent of the first floating point number is greater than the initial exponent of the second floating point number;
[0019] The shifter is used to align the initial exponent of the second floating-point number to the target exponent; and based on the first difference, right-shift the mantissa of the second floating-point number to obtain a processed second floating-point number; and input the first floating-point number and the processed second floating-point number into the adder;
[0020] The adder is used to perform addition processing on the first floating-point number and the processed second floating-point number to obtain an intermediate floating-point number.
[0021] In a possible implementation manner, the device further includes: a first register; the first register is respectively connected to the adder and the subtractor of the rank operator;
[0022] The adder is used to input the obtained intermediate floating-point number into the first register;
[0023] The first register is used to store the intermediate floating-point number and the target floating-point number sent by the adder, and to send the intermediate floating-point number to the subtractor.
[0024] In a possible implementation manner, the device further includes a second register; the second register is connected to the subtractor;
[0025] The second register is used to store a target index; and send the target index to the subtractor of the counter-order module.
[0026] In a possible implementation manner, the selector is further used to: select a floating-point number to be processed from the floating-point numbers to be processed that have not been selected; and extend the sign bit of the selected floating-point number to be processed to the target bit width to obtain an extended floating-point number corresponding to the selected floating-point number to be processed;
[0027] In response to the selected initial exponent of the expanded floating-point number corresponding to the floating-point number to be processed being greater than the target exponent stored in the second register, the selected initial exponent of the expanded floating-point number corresponding to the floating-point number to be processed is used as a new target exponent, and the second register is updated using the new target exponent; the second register is further used to send the new target exponent to the subtractor;
[0028] The subtractor is configured to determine a second difference between the exponent of the intermediate floating point number and the target exponent based on the received new target exponent;
[0029] The shifter is used to align the exponent of the intermediate floating-point number to the target exponent, and based on the second difference, right-shift the mantissa of the intermediate floating-point number to obtain a processed intermediate floating-point number; and send the processed intermediate floating-point number and the selected extended floating-point number corresponding to the floating-point number to be processed to the adder;
[0030] The adder is used to perform addition processing on the mantissa of the intermediate floating-point number and the mantissa of the extended floating-point number corresponding to the selected floating-point number to be processed to obtain a new intermediate floating-point number; and send the new intermediate floating-point number to the first register; and use the intermediate floating-point number obtained after the last addition processing as the target floating-point number, and send the target floating-point number to the first register.
[0031] In a possible implementation manner, the comparator, when performing normalization processing on the target floating-point number to obtain a target processing result, is used to:
[0032] The target floating-point number is normalized by using one or more of a shifting method, a truncation method, and a rounding method to obtain a target processing result.
[0033] In a possible implementation, the target bit width is determined based on an initial bit width of an initial mantissa included in the plurality of floating-point numbers to be processed and a total number of the plurality of floating-point numbers to be processed.
[0034] In a second aspect, the present disclosure provides a floating point number processing method, comprising:
[0035] Obtaining a plurality of floating point numbers to be processed for operation in a target chip;
[0036] Extending the sign bit of each of the floating-point numbers to be processed to a target bit width to obtain a plurality of extended floating-point numbers; wherein the target bit width matches the total number of the floating-point numbers to be processed;
[0037] The multiple expanded floating-point numbers are accumulated in the target chip to obtain a target floating-point number.
[0038] In the above method, in order to ensure the accuracy of the floating-point number accumulation process and meet the bit width requirements of the intermediate floating-point numbers obtained after the addition operation, the sign bit of each floating-point number to be processed can be expanded to the target bit width to obtain multiple expanded floating-point numbers, thereby realizing the expansion of the bit width of the floating-point numbers to be processed. As a result, in the process of accumulating multiple expanded floating-point numbers in the target chip, it is not necessary to perform normalization processing on the intermediate floating-point numbers obtained in the accumulation process, thereby reducing the number of normalization processing times and reducing the delay and power consumption of the target chip in processing the accumulation process of multiple expanded floating-point numbers. At the same time, after reducing the number of normalization processing times, the data loss problem caused by the normalization processing can be alleviated, and the accuracy of the target floating-point number is improved.
[0039] In a possible implementation manner, after obtaining the target floating point number, the method further includes:
[0040] The target floating-point number is normalized to obtain a target processing result, wherein a format of the target processing result matches a preset format.
[0041] During implementation, during the accumulation process of multiple expanded floating-point numbers, there is no need to normalize the intermediate floating-point numbers obtained in the accumulation process; and after the target floating-point number is accumulated, the target floating-point number can be normalized once to obtain the target processing result, thereby reducing the number of normalization processes and reducing the delay and power consumption of the target chip in the accumulation process of multiple floating-point numbers; at the same time, it can alleviate the data loss problem caused by the normalization process and improve the accuracy of the target processing result.
[0042] In a possible implementation manner, the target bit width is determined according to the following steps:
[0043] Determining, based on initial bit widths of initial mantissas included in the plurality of floating-point numbers to be processed, adjusted bit widths corresponding to the plurality of floating-point numbers to be processed;
[0044] The target bit width is determined based on the adjusted bit width and the total number of the floating-point numbers to be processed.
[0045] In the above implementation, the target bit width is determined more accurately based on the adjusted bit width and the total number of floating-point numbers to be processed, and the sign bit of the floating-point numbers to be processed is subsequently extended to the target bit width. After obtaining multiple extended floating-point numbers, the bit width of the extended floating-point numbers can meet the bit width requirement of the accumulation processing, and there is no need to normalize the intermediate floating-point numbers obtained in the accumulation processing.
[0046] In a possible implementation manner, the step of extending the sign bit of each of the floating-point numbers to be processed to a target bit width to obtain a plurality of extended floating-point numbers includes:
[0047] Select two floating-point numbers to be processed from a plurality of floating-point numbers to be processed, and extend the sign bits of the two floating-point numbers to be processed to a target bit width to obtain two extended floating-point numbers;
[0048] The step of accumulating the plurality of expanded floating-point numbers in the target chip to obtain a target floating-point number comprises:
[0049] The two expanded floating-point numbers are used as two current floating-point numbers, and the two current floating-point numbers are added in the target chip to obtain an intermediate floating-point number;
[0050] Select a floating-point number to be processed from the floating-point numbers to be processed that have not been selected; and expand the sign bit of the selected floating-point number to be processed to the target bit width to obtain an expanded floating-point number corresponding to the selected floating-point number to be processed;
[0051] The expanded floating-point number corresponding to the selected floating-point number to be processed and the intermediate floating-point number are used as two updated current floating-point numbers, and the process returns to the step of adding the two current floating-point numbers in the target chip to obtain the intermediate floating-point number, until each of the plurality of floating-point numbers to be processed has been added;
[0052] The intermediate floating-point number obtained after the last addition process is used as the target floating-point number.
[0053] Here, multiple floating-point numbers to be processed can be accumulated multiple times to obtain a target floating-point number, and there is no need to normalize the generated intermediate floating-point numbers during the accumulation process, which alleviates the data loss problem caused by normalizing the intermediate floating-point numbers and ensures the accuracy of the intermediate floating-point numbers, thereby making the accuracy of the obtained target floating-point number higher.
[0054] In a possible implementation manner, the adding of the two current floating-point numbers in the target chip to obtain an intermediate floating-point number includes:
[0055] In the target chip, the initial exponent of the first floating point number of the two current floating point numbers is aligned to the initial exponent of the second floating point number; and the mantissa of the first floating point number is right-shifted by a target number of bits to obtain a first floating point number after order processing; wherein, of the two floating point numbers, the initial exponent of the first floating point number is smaller than the initial exponent of the second floating point number; and the target number of bits is the difference between the initial exponent of the second floating point number and the initial exponent of the first floating point number;
[0056] The first floating-point number after the order processing is added to the second floating-point number in the target chip to obtain an intermediate floating-point number.
[0057] In a possible implementation manner, the normalizing the target floating-point number to obtain a target processing result includes:
[0058] The target floating-point number is normalized by using one or more of a shifting method, a truncation method, and a rounding method to obtain a target processing result.
[0059] Here, one or more of the shifting method, the truncation method, and the rounding method may be used to flexibly normalize the target floating-point number to obtain the target processing result.
[0060] The effects of the following devices, electronic devices, etc. are described in the description of the above method and will not be repeated here.
[0061] In a third aspect, the present disclosure provides a chip, comprising: the chip comprises the floating point number processing device according to the first aspect or any one of the embodiments, and a memory;
[0062] The memory is used to store a plurality of floating-point numbers to be processed and to be calculated;
[0063] The floating point number processing device is used to process the multiple floating point numbers to be processed to obtain a target floating point number.
[0064] In a fourth aspect, the present disclosure provides a floating point number processing device, comprising:
[0065] An acquisition module, used for acquiring a plurality of floating-point numbers to be processed for operation in a target chip;
[0066] An expansion module, used for expanding the sign bit of each of the floating-point numbers to be processed to a target bit width, to obtain a plurality of expanded floating-point numbers; wherein the target bit width matches the total number of the floating-point numbers to be processed;
[0067] The first processing module is used to perform accumulation processing on the multiple expanded floating-point numbers in the target chip to obtain a target floating-point number.
[0068] In a possible implementation manner, after obtaining the target floating point number, the device further includes:
[0069] The second processing module is used to perform normalization processing on the target floating-point number to obtain a target processing result, wherein the format of the target processing result matches a preset format.
[0070] In a possible implementation manner, the expansion module is used to determine the target bit width according to the following steps:
[0071] Determining, based on initial bit widths of initial mantissas included in the plurality of floating-point numbers to be processed, adjusted bit widths corresponding to the plurality of floating-point numbers to be processed;
[0072] The target bit width is determined based on the adjusted bit width and the total number of the floating-point numbers to be processed.
[0073] In a possible implementation manner, the expansion module, when expanding the sign bit of each of the floating-point numbers to be processed to a target bit width to obtain a plurality of expanded floating-point numbers, is used to:
[0074] Select two floating-point numbers to be processed from a plurality of floating-point numbers to be processed, and extend the sign bits of the two floating-point numbers to be processed to a target bit width to obtain two extended floating-point numbers;
[0075] The first processing module, when performing accumulation processing on the multiple expanded floating-point numbers in the target chip to obtain a target floating-point number, is used to:
[0076] The two expanded floating-point numbers are used as two current floating-point numbers, and the two current floating-point numbers are added in the target chip to obtain an intermediate floating-point number;
[0077] Select a floating-point number to be processed from the floating-point numbers to be processed that have not been selected; and expand the sign bit of the selected floating-point number to be processed to the target bit width to obtain an expanded floating-point number corresponding to the selected floating-point number to be processed;
[0078] The expanded floating-point number corresponding to the selected floating-point number to be processed and the intermediate floating-point number are used as two updated current floating-point numbers, and the process returns to the step of adding the two current floating-point numbers in the target chip to obtain the intermediate floating-point number, until each of the plurality of floating-point numbers to be processed has been added;
[0079] The intermediate floating-point number obtained after the last addition process is used as the target floating-point number.
[0080] In a possible implementation manner, the first processing module, when performing addition processing on the two current floating-point numbers in the target chip to obtain an intermediate floating-point number, is used to:
[0081] In the target chip, the initial exponent of the first floating point number of the two current floating point numbers is aligned to the initial exponent of the second floating point number; and the mantissa of the first floating point number is right-shifted by a target number of bits to obtain a first floating point number after order processing; wherein, of the two floating point numbers, the initial exponent of the first floating point number is smaller than the initial exponent of the second floating point number; and the target number of bits is the difference between the initial exponent of the second floating point number and the initial exponent of the first floating point number;
[0082] The first floating-point number after the order processing is added to the second floating-point number in the target chip to obtain an intermediate floating-point number.
[0083] In a possible implementation manner, when the second processing module performs normalization processing on the target floating-point number to obtain a target processing result, it is configured to:
[0084] The target floating-point number is normalized by using one or more of a shifting method, a truncation method, and a rounding method to obtain a target processing result.
[0085] In a fifth aspect, the present disclosure provides an electronic device, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate through the bus, and when the machine-readable instructions are executed by the processor, the steps of the floating-point processing method described in the second aspect or any embodiment are performed; or, a chip as described in the third aspect.
[0086] In a sixth aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the floating-point number processing method as described in the second aspect or any one of the embodiments are executed.
[0087] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0088] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following is a brief introduction to the drawings required for use in the embodiments. The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can also be obtained based on these drawings without creative work.
[0089] Figure 1 A schematic flow chart of a floating point number processing method provided by an embodiment of the present disclosure is shown;
[0090] Figure 2 A schematic diagram of the architecture of a floating point number processing device provided by an embodiment of the present disclosure is shown;
[0091] Figure 3 A schematic diagram of the architecture of another floating point number processing device provided by an embodiment of the present disclosure is shown;
[0092] Figure 4 A schematic diagram of the architecture of a chip provided by an embodiment of the present disclosure is shown;
[0093] Figure 5 A schematic diagram of the architecture of a floating point number processing device provided by an embodiment of the present disclosure is shown;
[0094] Figure 6 A schematic structural diagram of an electronic device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0095] In order to make the purpose, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.
[0096] With the continuous development of semiconductor technology, computer architecture, and processor design architecture, processors are becoming more powerful and more complex. Among them, floating-point operations are a type of calculation in the processor that has many steps, large delays, and high power consumption, which has a great impact on the performance indicators of the processor.
[0097] Accumulation is a common floating-point operation method. Generally, in the accumulation operation of multiple floating-point numbers, two floating-point numbers can be accumulated first to obtain an intermediate result, and the intermediate result can be normalized. Then the normalized intermediate result is accumulated with the next floating-point number until the accumulation operation is completed to obtain the target result: However, the method of normalizing the intermediate result after each accumulation causes the power consumption and delay of the processor performing the floating-point accumulation operation to be large. At the same time, since normalization processing will cause data loss, each time the intermediate result is normalized, the accuracy of the intermediate result after normalization processing will be reduced, and then when the target result is obtained after multiple accumulation operations, the accuracy of the target result is low.
[0098] In order to alleviate the above problems, an embodiment of the present disclosure provides a floating point number processing method.
[0099] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0100] To facilitate understanding of the embodiments of the present disclosure, a floating-point number processing method disclosed in the embodiments of the present disclosure is first introduced in detail. The execution subject of the floating-point number processing method provided in the embodiments of the present disclosure is generally a chip with a certain computing power, such as a processor, which may include a central processing unit (CPU), a graphics processing unit (GPU), a tensor processing unit (TPU), an embedded neural network processor (Neural-network Processing Unit, NPU), etc. In some possible implementations, the floating-point number processing method can be implemented by a processor calling a computer-readable instruction stored in a memory.
[0101] See also Figure 1 FIG. 1 is a flow chart of a floating point number processing method provided by an embodiment of the present disclosure, wherein the method includes S101-S103, wherein:
[0102] S101, obtaining a plurality of floating-point numbers to be processed and operated in a target chip;
[0103] S102, extending the sign bit of each of the floating-point numbers to be processed to a target bit width, to obtain a plurality of extended floating-point numbers; wherein the target bit width matches the total number of the floating-point numbers to be processed;
[0104] S103, performing accumulation processing on the multiple expanded floating-point numbers in the target chip to obtain a target floating-point number.
[0105] In the above method, in order to ensure the accuracy of the floating-point number accumulation process and meet the bit width requirements of the intermediate floating-point numbers obtained after the addition operation, the sign bit of each floating-point number to be processed can be expanded to the target bit width to obtain multiple expanded floating-point numbers, thereby realizing the expansion of the bit width of the floating-point numbers to be processed. As a result, in the process of accumulating multiple expanded floating-point numbers in the target chip, it is not necessary to perform normalization processing on the intermediate floating-point numbers obtained in the accumulation process, thereby reducing the number of normalization processing times and reducing the delay and power consumption of the target chip in processing the accumulation process of multiple expanded floating-point numbers. At the same time, after reducing the number of normalization processing times, the data loss problem caused by the normalization processing can be alleviated, and the accuracy of the target floating-point number is improved.
[0106] S101 to S103 are described in detail below.
[0107] In S101, the target chip may be any chip that needs to perform floating point operations, such as a CPU, GPU, NPU, etc. A floating point number generally includes a sign bit, a mantissa, and an exponent. For example, a floating point number (0.3) 10 =(0011 11101001 1001 1001 1001 1001 1010)2, where sign bit: Sa=0, exponent: Ea=011 1110 1, mantissa: Ma=1.001 1001 1001 1001 1001 1010.
[0108] In S102, it is considered that when a plurality of floating-point numbers are added, the plurality of floating-point numbers added are subjected to rank processing, and then the mantissas containing the sign bit of the plurality of floating-point numbers after the rank processing are subjected to sum processing. When the mantissas containing the sign bit of the plurality of floating-point numbers are added, the bit width of the sum value obtained after the sum is greater than or equal to the bit width of the mantissa containing the sign bit of each floating-point number before the sum. For example, if the bit width of the mantissa containing the sign bit of floating-point number 1 is 12, and the bit width of the mantissa containing the sign bit of floating-point number 2 is 13, then the bit width after the sum of floating-point number 1 and floating-point number 2 may be 14.
[0109] In order to ensure the accuracy of the floating-point number obtained after the addition and meet the bit width requirement of the sum value obtained after the addition operation, the sign bit of each floating-point number to be processed can be expanded. The expanded bit width can be a target bit width. The target bit width can be a bit width value set by a user, and the target bit width is greater than the initial bit width corresponding to the mantissa of any floating-point number to be processed. Alternatively, the target bit width can also be determined according to the initial bit width corresponding to the mantissa of each floating-point number to be processed and the total number of floating-point numbers to be processed.
[0110] During implementation, the target bit width can be determined, and the sign bit of each floating point number to be processed can be extended to the target bit width to obtain an extended floating point number. For example, in the above case, the sign bit: Sa = 0, and the extended sign bit can be: Sa = 0000.
[0111] In an optional implementation, the target bit width is determined according to the following steps: determining an adjusted bit width corresponding to the multiple floating-point numbers to be processed based on an initial bit width of an initial mantissa included in the multiple floating-point numbers to be processed; and determining the target bit width based on the adjusted bit width and the total number of the floating-point numbers to be processed.
[0112] During implementation, the initial bit width of the initial mantissa of each floating-point number to be processed can be determined, and the adjusted bit width can be determined based on the initial bit widths of multiple initial mantissas. The adjusted bit width can be the maximum value among the multiple initial bit widths, or any integer greater than the maximum value. The following description is made by taking the adjusted bit width as the maximum bit width among the multiple initial bit widths as an example.
[0113] For example, if the number of floating-point numbers to be processed is 5, the maximum bit width among the initial bit widths of the 5 initial mantissas is determined, and the maximum bit width is determined as the adjusted bit width. The target bit width is then determined based on the adjusted bit width and the total number of floating-point numbers to be processed; that is, based on the maximum bit width, the number of overflow bits of the sum is determined according to the total number of floating-point numbers to be processed and the base of the floating-point numbers to be processed, and the target bit width is then determined based on the overflow bit and the maximum bit width. For example, the target bit width can be: n+log a m, where n is the adjusted bit width, m is the total number of floating-point numbers to be processed, and a is the number system of the floating-point numbers to be processed. For example, when a=2, it means that the floating-point numbers to be processed are binary numbers.
[0114] Among them, in n+log a If the value of m is a decimal, it can be rounded up to get the target bit width. a When m=12+log25=14.32, it is determined that the target bit width can be 15. If the floating point number to be processed is: a=(0.3) 10 =0 011 11101 100 1100 1100 1100 1100 1101, where 0 is the sign bit, 011 1110 1 is the initial exponent, and 100 11001100 1100 1100 1101 is the initial mantissa. After extending the sign bit of the floating-point number to be processed to the target bit width, the floating-point number to be processed can be: 0000 011 1110 1 100 1100 1100 1100 1101.
[0115] In the above implementation, the target bit width is determined more accurately based on the adjusted bit width and the total number of floating-point numbers to be processed, and the sign bit of the floating-point numbers to be processed is subsequently extended to the target bit width. After obtaining multiple extended floating-point numbers, the bit width of the extended floating-point numbers can meet the bit width requirement of the accumulation processing, and there is no need to normalize the intermediate floating-point numbers obtained in the accumulation processing.
[0116] In S103, multiple extended floating-point numbers can be subjected to rank processing so that the initial exponents of the multiple extended floating-point numbers are consistent, and then the initial mantissas of the multiple extended floating-point numbers after the rank processing are accumulated to obtain a target floating-point number. During implementation, the rank processing may include: determining the target exponents corresponding to the multiple extended floating-point numbers, for example, the target exponent may be the maximum exponent among the initial exponents corresponding to the multiple extended floating-point numbers, aligning the initial exponent of each extended floating-point number to the target exponent, and right-shifting the mantissa of the extended floating-point number by x bits to obtain the extended floating-point number after the rank processing. Wherein, x is a positive integer, and the value of x is the difference between the target exponent and the initial exponent of the extended floating-point number.
[0117] During implementation, two of the multiple extended floating-point numbers may be accumulated first, and the obtained intermediate floating-point number may be accumulated with the next extended floating-point number until each extended floating-point number is accumulated to obtain the target floating-point number.
[0118] In an optional implementation, in S102, extending the sign bit of each of the floating-point numbers to be processed to the target bit width to obtain multiple extended floating-point numbers may include: selecting two floating-point numbers to be processed from the multiple floating-point numbers to be processed, extending the sign bits of the two floating-point numbers to be processed to the target bit width, and obtaining two extended floating-point numbers.
[0119] During implementation, two floating-point numbers to be processed can be randomly selected from multiple floating-point numbers to be processed, or a processing order of multiple floating-point numbers to be processed can be set, and two floating-point numbers to be processed can be selected according to the processing order; then the sign bits of the selected two floating-point numbers to be processed are extended to the target bit width to obtain two extended floating-point numbers.
[0120] After obtaining the two extended floating point numbers, S103 may include:
[0121] S1031, taking the two expanded floating-point numbers as two current floating-point numbers, and performing addition processing on the two current floating-point numbers in the target chip to obtain an intermediate floating-point number;
[0122] S1032, selecting a floating-point number to be processed from the floating-point numbers to be processed that have not been selected; and extending the sign bit of the selected floating-point number to be processed to the target bit width to obtain an extended floating-point number corresponding to the selected floating-point number to be processed;
[0123] S1033, using the expanded floating-point number corresponding to the selected floating-point number to be processed and the intermediate floating-point number as two updated current floating-point numbers, and returning to the step of adding the two current floating-point numbers in the target chip to obtain the intermediate floating-point number, until each of the plurality of floating-point numbers to be processed has been added;
[0124] S1034, taking the intermediate floating-point number obtained after the last addition process as the target floating-point number.
[0125] In S1031, the two expanded floating-point numbers may be used as two current floating-point numbers, and the two current floating-point numbers may be added in the target chip to obtain an intermediate floating-point number.
[0126] In an optional implementation manner, the adding of the two current floating-point numbers in the target chip to obtain an intermediate floating-point number may include:
[0127] Step A1, in the target chip, aligning the initial exponent of the first floating-point number of the two current floating-point numbers to the initial exponent of the second floating-point number; and right-shifting the mantissa of the first floating-point number by a target number of bits to obtain a first floating-point number after order processing; wherein, of the two floating-point numbers, the initial exponent of the first floating-point number is smaller than the initial exponent of the second floating-point number; and the target number of bits is the difference between the initial exponent of the second floating-point number and the initial exponent of the first floating-point number;
[0128] Step A2: Add the first floating-point number after the order processing and the second floating-point number in the target chip to obtain an intermediate floating-point number.
[0129] During implementation, the first floating point number may be the floating point number with the smaller initial exponent of the two current floating point numbers; the second floating point number may be the floating point number with the larger initial exponent of the two current floating point numbers. Before adding the two current floating point numbers, the first floating point number may be subjected to rank processing to obtain the rank-processed first floating point number, so that the exponent of the rank-processed first floating point number is consistent with the initial exponent of the second floating point number.
[0130] The process of aligning the first floating point number may include: aligning the initial exponent of the first floating point number to the initial exponent of the second floating point number in the target chip, and right-shifting the initial mantissa of the first floating point number by a target number of bits, the target number of bits being the difference between the initial exponent of the second floating point number and the initial exponent of the first floating point number. For example, if the initial exponent of the first floating point number is 10 and the initial exponent of the second floating point number is 15, the initial exponent of the first floating point number is aligned to 15, and the initial mantissa of the first floating point number is right-shifted by 5 bits to obtain the first floating point number after aligning the order, that is, the exponent of the first floating point number after aligning the order is 15.
[0131] Then, in the target chip, the mantissa of the first floating-point number after the order processing is performed and the initial mantissa of the second floating-point number are added together to obtain an intermediate floating-point number.
[0132] In S1032, after obtaining the intermediate floating-point number, a floating-point number to be processed can be selected from the floating-point numbers to be processed that have not been selected, and the selected floating-point number to be processed can be a randomly selected floating-point number to be processed, or a floating-point number to be processed selected according to the processing order. Then, the sign bit of the selected floating-point number to be processed is extended to the target bit width to obtain an extended floating-point number corresponding to the selected floating-point number to be processed.
[0133] In S1033, the expanded floating-point number and the intermediate floating-point number corresponding to the selected floating-point number to be processed can be used as the two updated current floating-point numbers, and the process returns to step S1031 until each of the multiple floating-point numbers to be processed has been summed.
[0134] In S1034, the intermediate floating-point number obtained after the last addition process may be used as the target floating-point number.
[0135] Here, multiple floating-point numbers to be processed can be accumulated multiple times to obtain a target floating-point number. Since the sign bit of each floating-point number to be processed is extended to the target bit width before the floating-point numbers to be processed are accumulated, the mantissa bit width of the intermediate floating-point numbers obtained during the accumulation process will not exceed the target bit width. Therefore, there is no need to normalize the generated intermediate floating-point numbers during the accumulation process, which alleviates the problem of data loss caused by normalizing the intermediate floating-point numbers and ensures the accuracy of the intermediate floating-point numbers, thereby making the accuracy of the obtained target floating-point number higher.
[0136] In a possible implementation manner, after obtaining the target floating-point number, the method further includes: performing normalization processing on the target floating-point number to obtain a target processing result, wherein a format of the target processing result matches a preset format.
[0137] During implementation, during the accumulation process of multiple expanded floating-point numbers, there is no need to normalize the intermediate floating-point numbers obtained in the accumulation process; and after the target floating-point number is accumulated, the target floating-point number can be normalized once to obtain the target processing result, thereby reducing the number of normalization processes and reducing the delay and power consumption of the target chip in the accumulation process of multiple floating-point numbers; at the same time, it can alleviate the data loss problem caused by the normalization process and improve the accuracy of the target processing result.
[0138] In order to ensure the uniqueness of floating-point number representation in the target chip, floating-point numbers are stored in a normalized form in the target chip. Therefore, after accumulating a plurality of floating-point numbers to be processed to obtain a target floating-point number, the obtained target floating-point number can be normalized to obtain a target processing result, and the format of the target processing result matches a preset format. The preset format can be determined based on a set floating-point number standard.
[0139] In an optional implementation, the normalizing the target floating-point number to obtain the target processing result may include: normalizing the target floating-point number to obtain the target processing result using one or more of a shifting method, a truncation method, and a rounding method.
[0140] During implementation, the target floating-point number may be normalized using one or more of a shifting method, a truncation method, and a rounding method to obtain a target processing result. The shifting method may include left shifting, right shifting, etc.; the truncation method may be a method of deleting data exceeding a specific number of bits, etc. The target processing result may be a normalized floating-point number.
[0141] Here, one or more of the shifting method, the truncation method, and the rounding method may be used to flexibly normalize the target floating-point number to obtain the target processing result.
[0142] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.
[0143] Based on the same concept, the present disclosure also provides a floating point number processing device, see Figure 2 , which is a schematic diagram of the architecture of a floating point number processing device provided by an embodiment of the present disclosure, comprising: a selector 201 and an adder 202; wherein the adder 202 is connected to the selector 201;
[0144] The selector 201 is used to expand the sign bit of each of the plurality of floating-point numbers to be processed to a target bit width, so as to obtain a plurality of expanded floating-point numbers; wherein the target bit width matches the total number of the floating-point numbers to be processed;
[0145] The adder 202 is used to accumulate the multiple expanded floating-point numbers to obtain a target floating-point number.
[0146] In order to ensure the accuracy of the floating-point number accumulation process and meet the bit width requirements of the intermediate floating-point numbers obtained after the addition operation, the selector can be used to expand the sign bit of each floating-point number to be processed to the target bit width, and multiple expanded floating-point numbers can be obtained, thereby realizing the expansion of the bit width of the floating-point numbers to be processed. As a result, in the process of accumulating multiple expanded floating-point numbers, it is not necessary to normalize the intermediate floating-point numbers obtained in the accumulation process, which reduces the number of normalization processes and reduces the delay and power consumption of the chip in processing the accumulation process of multiple expanded floating-point numbers. At the same time, after reducing the number of normalization processes, the data loss problem caused by the normalization process can be alleviated, and the accuracy of the target floating-point number is improved.
[0147] In one possible implementation, see Figure 3 As shown, the device further includes: a comparator 203; the comparator 203 is connected to the adder 202;
[0148] The adder 202 is further used to input the target floating point number into the comparator;
[0149] The comparator 203 is used to perform normalization processing on the target floating-point number to obtain a target processing result, wherein the format of the target processing result matches a preset format.
[0150] During implementation, during the accumulation process of multiple expanded floating-point numbers, there is no need to normalize the intermediate floating-point numbers obtained in the accumulation process; and after the target floating-point number is accumulated, the target floating-point number can be normalized once to obtain the target processing result, thereby reducing the number of normalization processes and reducing the delay and power consumption of the target chip in the accumulation process of multiple floating-point numbers; at the same time, it can alleviate the data loss problem caused by the normalization process and improve the accuracy of the target processing result.
[0151] In a possible implementation manner, the device further includes: an octave operator 204, the octave operator 204 is connected to the adder 202 and the selector 201 respectively; the octave operator includes a subtractor 241 and a shifter 242;
[0152] The subtractor 241 is used to determine a target difference between an initial exponent of each expanded floating point number and a target exponent; wherein the target exponent is determined based on the initial exponents of the multiple expanded floating point numbers;
[0153] The shifter 242 is used for aligning the initial exponent of each extended floating-point number to the target exponent, and right-shifting the mantissa of the extended floating-point number based on the target difference corresponding to the extended floating-point number to obtain a processed floating-point number; and inputting the processed floating-point number into the adder;
[0154] The adder 202 is used to accumulate the mantissas of the multiple processed floating-point numbers to obtain a target floating-point number.
[0155] In a possible implementation manner, the selector 201, when expanding the sign bit of each of the acquired multiple floating-point numbers to be processed to the target bit width to obtain multiple expanded floating-point numbers, is used to: select two floating-point numbers to be processed from the multiple floating-point numbers to be processed, and expand the sign bits of the two floating-point numbers to be processed to the target bit width to obtain two expanded floating-point numbers;
[0156] The subtractor 241 is used to use the initial exponent of the first floating point number of the two expanded floating point numbers as the target exponent; determine a first difference between the target exponent and the initial exponent of the second floating point number of the two expanded floating point numbers; wherein the initial exponent of the first floating point number is greater than the initial exponent of the second floating point number;
[0157] The shifter 242 is used to align the initial exponent of the second floating-point number to the target exponent; and based on the first difference, right-shift the mantissa of the second floating-point number to obtain a processed second floating-point number; and input the first floating-point number and the processed second floating-point number into the adder;
[0158] The adder 202 is used to perform addition processing on the first floating-point number and the processed second floating-point number to obtain an intermediate floating-point number.
[0159] In a possible implementation manner, the device further includes: a first register 205; the first register 205 is respectively connected to the adder 202 and the subtractor 241 of the rank operator;
[0160] The adder 202 is used to input the obtained intermediate floating-point number into the first register 205;
[0161] The first register 205 is used to store the intermediate floating-point number and the target floating-point number sent by the adder, and send the intermediate floating-point number to the subtractor 241 .
[0162] In a possible implementation manner, the device further includes a second register 206; the second register 206 is connected to the subtractor 241;
[0163] The second register 206 is used to store a target index and send the target index to the subtractor 241 of the counter-order module.
[0164] In a possible implementation manner, the selector 201 is further used to: select a floating-point number to be processed from the floating-point numbers to be processed that have not been selected; and extend the sign bit of the selected floating-point number to be processed to the target bit width to obtain an extended floating-point number corresponding to the selected floating-point number to be processed;
[0165] In response to the selected initial exponent of the expanded floating-point number corresponding to the floating-point number to be processed being greater than the target exponent stored in the second register, the selected initial exponent of the expanded floating-point number corresponding to the floating-point number to be processed is used as a new target exponent, and the second register is updated using the new target exponent; the second register 206 is further used to send the new target exponent to the subtractor;
[0166] The subtractor 241 is used to determine a second difference between the exponent of the intermediate floating point number and the target exponent based on the received new target exponent;
[0167] The shifter 242 is used to align the exponent of the intermediate floating-point number to the target exponent, and right-shift the mantissa of the intermediate floating-point number based on the second difference to obtain a processed intermediate floating-point number; and send the processed intermediate floating-point number and the selected extended floating-point number corresponding to the floating-point number to be processed to the adder 202;
[0168] The adder 202 is used to add the mantissa of the intermediate floating-point number and the mantissa of the extended floating-point number corresponding to the selected floating-point number to be processed to obtain a new intermediate floating-point number; and send the new intermediate floating-point number to the first register; and use the intermediate floating-point number obtained after the last addition process as the target floating-point number, and send the target floating-point number to the first register 205.
[0169] In a possible implementation manner, the comparator 203, when performing normalization processing on the target floating-point number to obtain a target processing result, is used to:
[0170] The target floating-point number is normalized by using one or more of a shifting method, a truncation method, and a rounding method to obtain a target processing result.
[0171] In a possible implementation, the target bit width is determined based on an initial bit width of an initial mantissa included in the plurality of floating-point numbers to be processed and a total number of the plurality of floating-point numbers to be processed.
[0172] The bit widths of the adder and the first register are at least the target bit width. The bit width of the second register can be the maximum value among the exponent bit widths of the initial exponents included in the plurality of floating-point numbers to be processed; that is, the exponent bit width of the initial exponent of each floating-point number to be processed can be determined among the plurality of floating-point numbers to be processed, and the maximum value among the plurality of exponent bit widths can be determined as the bit width of the second register.
[0173] Combination Figure 3 , the floating point number processing method proposed in the above embodiment is exemplified. Assuming that the multiple floating point numbers to be processed include a1, a2, a3, a4, and a5, the floating point number processing method may include:
[0174] Step 1: Input two floating-point numbers (a1 and a2) to be processed for accumulation operation into the selector, and the selector expands the sign bits of the two floating-point numbers to be processed to the target bit width to obtain two expanded floating-point numbers. The two expanded floating-point numbers are then input into the order operator.
[0175] Step 2: The order operator performs order processing on the two extended floating-point numbers to obtain two extended floating-point numbers with aligned exponents, and inputs the two extended floating-point numbers with aligned exponents into the adder. The maximum exponent of the initial exponents included in the two extended floating-point numbers is used as the target exponent, and the target exponent is stored in the second register.
[0176] During implementation, the subtractor in the order operator determines the target difference between the initial exponent of the first floating-point number and the target exponent; the shifter can align the initial exponent of the first floating-point number to the target exponent, and right-shift the mantissa of the first floating-point number by the target number of bits to obtain the first floating-point number after order processing. The exponents of the first floating-point number and the second floating-point number after order processing are consistent. Among them, in the two expanded floating-point numbers, the initial exponent of the first floating-point number is less than the initial exponent of the second floating-point number; the target number of bits is the target difference between the initial exponent (target exponent) of the second floating-point number and the initial exponent of the first floating-point number. Here, the initial exponent of the second floating-point number can be stored in the second register as the target exponent.
[0177] Step 3: The adder performs a sum operation on the mantissas of the two extended floating-point numbers with aligned exponents to obtain an intermediate floating-point number; and stores the intermediate floating-point number in the first register.
[0178] Step 4: Input the floating point number a3 to be processed into the selector, and the selector expands the sign bit of the floating point number a3 to be processed to the target bit width to obtain the expanded floating point number. The expanded floating point number is input into the order operator. And the first register inputs the intermediate floating point number into the order operator.
[0179] Step 5: The order operator performs order processing on the extended floating point number and the intermediate floating point number corresponding to the floating point number to be processed a3 to obtain two extended floating point numbers with aligned exponents, and inputs the two extended floating point numbers with aligned exponents into the adder.
[0180] During implementation, the size between the initial exponent in the expanded floating-point number corresponding to the floating-point number to be processed a3 and the exponent of the intermediate floating-point number (i.e., the target exponent stored in the second register) is determined. If the initial exponent in the expanded floating-point number is smaller than the exponent of the intermediate floating-point number, the initial exponent of the expanded floating-point number is aligned to the exponent of the intermediate floating-point number, and the mantissa of the expanded floating-point number is right-shifted by the target number of bits (i.e., the difference between the exponents of the intermediate floating-point number and the expanded floating-point number) to obtain the expanded floating-point number after the order processing. The exponents of the expanded floating-point number after the order processing are consistent with those of the intermediate floating-point number.
[0181] If the initial exponent of the expanded floating-point number is greater than the exponent of the intermediate floating-point number, the initial exponent of the intermediate floating-point number is aligned to the exponent of the expanded floating-point number, and the mantissa of the intermediate floating-point number is right-shifted by the target number of bits (i.e., the difference between the exponents of the expanded floating-point number and the intermediate floating-point number) to obtain the aligned intermediate floating-point number. The aligned intermediate floating-point number and the expanded floating-point number are two expanded floating-point numbers with aligned exponents.
[0182] When the initial exponent of the expanded floating-point number is the same as the exponent of the intermediate floating-point number, there is no need to perform order processing, and the adder directly adds the mantissa of the expanded floating-point number to the mantissa of the intermediate floating-point number to obtain the intermediate floating-point number.
[0183] Step 6: When the initial exponent in the expanded floating point number corresponding to the floating point number a3 to be processed is greater than the exponent of the intermediate floating point number, the initial exponent in the expanded floating point number can be used as the updated target exponent, and the updated target exponent is updated to the second register.
[0184] Step 7: The adder performs a sum operation on the mantissas of the two extended floating-point numbers with aligned exponents to obtain an intermediate floating-point number; and stores the intermediate floating-point number in the first register.
[0185] Obtain the floating-point numbers a4 and a5 to be processed respectively, and repeat steps 4 to 7 for the obtained floating-point numbers a4 and a5 to be processed respectively, to obtain the target floating-point number after the accumulation of a1, a2, a3, a4, and a5.
[0186] Step 8: After obtaining the target floating point number, the first register may input the target floating point number into the comparator. The comparator performs normalization processing on the target floating point number to obtain a target processing result, wherein the format of the target processing result matches the preset format.
[0187] Based on the same concept, the present disclosure provides a chip, see Figure 4 As shown, the chip includes: a floating point number processing device 401 as described in any of the above embodiments, and a memory 402;
[0188] The memory 402 is used to store a plurality of floating point numbers to be processed;
[0189] The floating point number processing device 401 is used to process the multiple floating point numbers to be processed to obtain a target floating point number.
[0190] Based on the same concept, the present disclosure also provides a floating point number processing device, see Figure 5 As shown, it is a schematic diagram of the architecture of the floating point number processing device provided by the embodiment of the present disclosure, including an acquisition module 501, an expansion module 502, and a first processing module 503. Specifically:
[0191] An acquisition module 501 is used to acquire a plurality of floating point numbers to be processed and operated in a target chip;
[0192] An expansion module 502 is used to expand the sign bit of each of the floating-point numbers to be processed to a target bit width to obtain a plurality of expanded floating-point numbers; wherein the target bit width matches the total number of the floating-point numbers to be processed;
[0193] The first processing module 503 is used to perform accumulation processing on the multiple expanded floating-point numbers in the target chip to obtain a target floating-point number.
[0194] In a possible implementation manner, after obtaining the target floating point number, the device further includes:
[0195] The second processing module 504 is used to perform normalization processing on the target floating-point number to obtain a target processing result, wherein the format of the target processing result matches a preset format.
[0196] In a possible implementation manner, the expansion module 502 is configured to determine the target bit width according to the following steps:
[0197] Determining, based on initial bit widths of initial mantissas included in the plurality of floating-point numbers to be processed, adjusted bit widths corresponding to the plurality of floating-point numbers to be processed;
[0198] The target bit width is determined based on the adjusted bit width and the total number of the floating-point numbers to be processed.
[0199] In a possible implementation manner, the expansion module 502, when expanding the sign bit of each of the floating-point numbers to be processed to the target bit width to obtain a plurality of expanded floating-point numbers, is used to:
[0200] Select two floating-point numbers to be processed from a plurality of floating-point numbers to be processed, and extend the sign bits of the two floating-point numbers to be processed to a target bit width to obtain two extended floating-point numbers;
[0201] The first processing module 503, when performing accumulation processing on the multiple expanded floating-point numbers in the target chip to obtain a target floating-point number, is used to:
[0202] The two expanded floating-point numbers are used as two current floating-point numbers, and the two current floating-point numbers are added in the target chip to obtain an intermediate floating-point number;
[0203] Select a floating-point number to be processed from the floating-point numbers to be processed that have not been selected; and expand the sign bit of the selected floating-point number to be processed to the target bit width to obtain an expanded floating-point number corresponding to the selected floating-point number to be processed;
[0204] The expanded floating-point number corresponding to the selected floating-point number to be processed and the intermediate floating-point number are used as two updated current floating-point numbers, and the process returns to the step of adding the two current floating-point numbers in the target chip to obtain the intermediate floating-point number, until each of the plurality of floating-point numbers to be processed has been added;
[0205] The intermediate floating-point number obtained after the last addition process is used as the target floating-point number.
[0206] In a possible implementation manner, the first processing module 503, when performing addition processing on the two current floating-point numbers in the target chip to obtain an intermediate floating-point number, is used to:
[0207] In the target chip, the initial exponent of the first floating point number of the two current floating point numbers is aligned to the initial exponent of the second floating point number; and the mantissa of the first floating point number is right-shifted by a target number of bits to obtain a first floating point number after order processing; wherein, of the two floating point numbers, the initial exponent of the first floating point number is smaller than the initial exponent of the second floating point number; and the target number of bits is the difference between the initial exponent of the second floating point number and the initial exponent of the first floating point number;
[0208] The first floating-point number after the order processing is added to the second floating-point number in the target chip to obtain an intermediate floating-point number.
[0209] In a possible implementation manner, when the second processing module 504 performs normalization processing on the target floating-point number to obtain a target processing result, it is configured to:
[0210] The target floating-point number is normalized by using one or more of a shifting method, a truncation method, and a rounding method to obtain a target processing result.
[0211] In some embodiments, the functions or templates contained in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.
[0212] Based on the same technical concept, the embodiment of the present disclosure also provides an electronic device. Figure 6 As shown, it is a schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure, including a processor 601, a memory 602, and a bus 603. Among them, the memory 602 is used to store execution instructions, including a memory 6021 and an external memory 6022; the memory 6021 here is also called an internal memory, which is used to temporarily store the operation data in the processor 601, and the data exchanged with the external memory 6022 such as a hard disk. The processor 601 exchanges data with the external memory 6022 through the memory 6021. When the electronic device 600 is running, the processor 601 communicates with the memory 602 through the bus 603, so that the processor 601 executes the following instructions:
[0213] Obtaining a plurality of floating point numbers to be processed for operation in a target chip;
[0214] Extending the sign bit of each of the floating-point numbers to be processed to a target bit width to obtain a plurality of extended floating-point numbers; wherein the target bit width matches the total number of the floating-point numbers to be processed;
[0215] The multiple expanded floating-point numbers are accumulated in the target chip to obtain a target floating-point number.
[0216] Among them, the specific processing flow of the processor 601 can refer to the records of the above-mentioned method embodiment, which will not be repeated here.
[0217] In addition, the embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the floating-point number processing method described in the above method embodiment are executed. The storage medium can be a volatile or non-volatile computer-readable storage medium.
[0218] The present disclosure also provides a computer program product that carries a program code. The program code includes instructions that can be used to execute the steps of the floating-point number processing method described in the above method embodiment. For details, please refer to the above method embodiment, which will not be repeated here.
[0219] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is implemented as a computer storage medium. In another optional embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).
[0220] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the above-described devices and devices can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed devices, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0221] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0222] In addition, each functional unit in each embodiment of the present disclosure 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.
[0223] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0224] The above are only specific embodiments of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present disclosure, which should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A floating point number processing device, characterized in that: The device comprises: a selector and an adder; wherein the adder is connected to the selector; The selector is used to expand the sign bit of each of the multiple floating-point numbers to be processed to the target bit width, so as to obtain multiple expanded floating-point numbers; wherein the target bit width matches the total number of the floating-point numbers to be processed; the target bit width is determined based on the initial bit width of the initial mantissa included in the multiple floating-point numbers to be processed and the total number of the multiple floating-point numbers to be processed; the determination process of the target bit width includes: determining the adjustment bit width corresponding to the multiple floating-point numbers to be processed based on the initial bit width of the initial mantissa included in the multiple floating-point numbers to be processed; determining the overflow bit number of the sum value according to the total number of the floating-point numbers to be processed and the base of the floating-point numbers to be processed; and then determining the target bit width according to the overflow bit number and the adjustment bit width; The adder is used to accumulate the multiple expanded floating-point numbers to obtain a target floating-point number.
2. The device according to claim 1, characterized in that The device further comprises: a comparator; the comparator is connected to the adder; The adder is further used to input the target floating point number into the comparator; The comparator is used to perform normalization processing on the target floating-point number to obtain a target processing result, wherein the format of the target processing result matches a preset format.
3. The device according to claim 1 or 2, characterized in that: The device further comprises: a cascade operator, the cascade operator being connected to the adder and the selector respectively; the cascade operator comprising a subtractor and a shifter; The subtractor is used to determine a target difference between an initial exponent of each expanded floating point number and a target exponent; wherein the target exponent is determined based on the initial exponents of the plurality of expanded floating point numbers; The shifter is used for aligning the initial exponent of each extended floating-point number to the target exponent, and right-shifting the mantissa of the extended floating-point number based on the target difference corresponding to the extended floating-point number to obtain a processed floating-point number; and inputting the processed floating-point number into the adder; The adder is used to accumulate the mantissas of the multiple processed floating-point numbers to obtain a target floating-point number.
4. The device according to claim 3, characterized in that The selector, when expanding the sign bit of each of the plurality of floating-point numbers to be processed to the target bit width to obtain a plurality of expanded floating-point numbers, is used to: select two floating-point numbers to be processed from the plurality of floating-point numbers to be processed, expand the sign bits of the two floating-point numbers to be processed to the target bit width to obtain two expanded floating-point numbers; The subtractor is used to use the initial exponent of the first floating point number of the two expanded floating point numbers as the target exponent; Determine a first difference between the target exponent and an initial exponent of a second floating point number of the two expanded floating point numbers; wherein the initial exponent of the first floating point number is greater than the initial exponent of the second floating point number; The shifter is used to align the initial exponent of the second floating-point number to the target exponent; and based on the first difference, right-shift the mantissa of the second floating-point number to obtain a processed second floating-point number; and input the first floating-point number and the processed second floating-point number into the adder; The adder is used to perform addition processing on the first floating-point number and the processed second floating-point number to obtain an intermediate floating-point number.
5. The device according to claim 4, characterized in that The device further comprises: a first register; the first register is respectively connected to the adder and the subtractor of the order operator; The adder is used to input the obtained intermediate floating-point number into the first register; The first register is used to store the intermediate floating-point number and the target floating-point number sent by the adder, and to send the intermediate floating-point number to the subtractor.
6. The device according to claim 5, characterized in that The device further includes a second register; the second register is connected to the subtractor; The second register is used to store a target index; and send the target index to the subtractor of the scalar operator.
7. The device according to claim 6, characterized in that The selector is further used to: select a floating-point number to be processed from the floating-point numbers to be processed that have not been selected; and expand the sign bit of the selected floating-point number to be processed to the target bit width to obtain an expanded floating-point number corresponding to the selected floating-point number to be processed; In response to the selected initial exponent of the expanded floating-point number corresponding to the floating-point number to be processed being greater than the target exponent stored in the second register, the selected initial exponent of the expanded floating-point number corresponding to the floating-point number to be processed is used as a new target exponent, and the second register is updated using the new target exponent; the second register is further used to send the new target exponent to the subtractor; The subtractor is configured to determine a second difference between the exponent of the intermediate floating point number and the target exponent based on the received new target exponent; The shifter is used to align the exponent of the intermediate floating-point number to the target exponent, and right-shift the mantissa of the intermediate floating-point number based on the second difference to obtain a processed intermediate floating-point number; and sending the processed intermediate floating-point number and the selected expanded floating-point number corresponding to the floating-point number to be processed to the adder; The adder is used to perform addition processing on the mantissa of the intermediate floating-point number and the mantissa of the extended floating-point number corresponding to the selected floating-point number to be processed to obtain a new intermediate floating-point number; and send the new intermediate floating-point number to the first register; and use the intermediate floating-point number obtained after the last addition processing as the target floating-point number, and send the target floating-point number to the first register.
8. The device according to claim 2, characterized in that The comparator, when performing normalization processing on the target floating-point number to obtain a target processing result, is used to: The target floating-point number is normalized by using one or more of a shifting method, a truncation method, and a rounding method to obtain a target processing result.
9. A floating point number processing method, characterized in that: include: Acquire multiple floating-point numbers to be processed for operation in the target chip; The sign bit of each of the floating-point numbers to be processed is extended to a target bit width to obtain a plurality of extended floating-point numbers; wherein the target bit width matches the total number of the floating-point numbers to be processed; the target bit width is determined based on the initial bit width of the initial mantissa included in the plurality of floating-point numbers to be processed and the total number of the plurality of floating-point numbers to be processed; the process of determining the target bit width comprises: determining the adjustment bit width corresponding to the plurality of floating-point numbers to be processed based on the initial bit width of the initial mantissa included in the plurality of floating-point numbers to be processed; determining the number of overflow bits of the sum value according to the total number of the floating-point numbers to be processed and the base of the floating-point numbers to be processed; and then determining the target bit width according to the number of overflow bits and the adjustment bit width; The multiple expanded floating-point numbers are accumulated in the target chip to obtain a target floating-point number.
10. A chip, characterized in that: include: The chip comprises the floating point number processing device according to any one of claims 1 to 8, and a memory; The memory is used to store a plurality of floating-point numbers to be processed and to be calculated; The floating point number processing device is used to process the multiple floating point numbers to be processed to obtain a target floating point number.
11. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the floating-point number processing method according to claim 9 are performed; Or, the chip as claimed in claim 10.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the floating-point number processing method as claimed in claim 9 are executed.
