Data processing method, device, computing device, graphics processor and storage medium

By shifting the mantissa of the intermediate calculation result, the approximate bit of the rounding operation becomes the lowest bit of the mantissa, which solves the problem in the prior art that the rounding operation needs to judge multiple sticky bits, and improves the calculation efficiency and hardware Resource utilization.

CN117762375BActive Publication Date: 2024-10-29MOORE THREADS TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311790497.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-22
Publication Date
2024-10-29
Estimated Expiration
2043-12-22

AI Technical Summary

Technical Problem

The existing technology needs to determine two different types of sticky bits during rounding operations in floating-point calculations, which increases the burden on hardware resources and reduces calculation efficiency, especially when multiple target formats are supported.

Method used

The mantissa of the intermediate calculation result is shifted through a shifter, so that the approximate bit of the rounding operation becomes the lowest bit of the mantissa, and the sticky bit is located outside the lowest bit, so that only the sticky bit in one case needs to be processed. There is no need to choose reserved bits, approximate bits, and sticky bits based on the target floating point format.

Benefits of technology

The rounding operation of the computing unit is simplified, the computing efficiency is improved, hardware resources and computing time are saved, and the processing speed is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117762375B_ABST
    Figure CN117762375B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a data processing method, device, computing device, graphics processor and storage medium. The method is used for a computing unit, and the computing unit includes a computing unit and a shifter. The method includes: the shifter obtains an intermediate calculation result output by the computing unit, and the intermediate calculation result is a floating point number; the shifter performs shift processing on the mantissa of the intermediate calculation result, and outputs a target calculation result. The lowest bit of the mantissa in the target calculation result is an approximate bit corresponding to the rounding operation, and the approximate bit is used by the computing unit to round the target calculation result. According to the embodiment of the present application, the processing pressure of the computing unit can be reduced, the processing speed can be increased, the computing efficiency of the computing unit can be improved, and the computing resources and computing time of the hardware can be saved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of processor technology, and in particular to a data processing method, device, computing device, graphics processor, and storage medium. Background Art

[0002] At present, the floating point calculations in mainstream computer chips all follow the corresponding standards, such as the IEEE754 standard. Regardless of whether the calculation result is a normalized number, the calculation result must be output in the format specified by the standard. Usually, during the calculation process, it is very likely to get a floating point calculation result that does not conform to the standard format, so it needs to be processed to get a calculation result that conforms to the standard format.

[0003] According to the traditional method, the sticky bit corresponding to the rounding operation may appear within the range of the mantissa of the calculation result, or it may appear outside the range of the mantissa of the calculation result. In this way, the operation unit needs to judge two different sticky bits when performing rounding operations. And if the calculation unit supports floating-point calculation results of multiple target formats at the same time, the result obtained by the traditional method may have the guard bit, round bit and sticky bit of the mantissa appear in different positions. In this way, the operation unit needs to select according to the target format before performing the rounding operation, which increases the burden of hardware resources and reduces the working efficiency of the hardware. Therefore, a new method is urgently needed to save hardware computing resources and computing time. Summary of the invention

[0004] In view of this, the present disclosure proposes a data processing method, device, computing device, graphics processor and storage medium.

[0005] According to one aspect of the present disclosure, a data processing method is provided. The method may be used in a computing unit, the computing unit including an operation unit and a shifter, and the method may include:

[0006] The shifter obtains the intermediate calculation result output by the operation unit, and the intermediate calculation result is a floating point number;

[0007] The shifter shifts the mantissa of the intermediate calculation result and outputs the target calculation result. The lowest bit of the mantissa in the target calculation result is the approximate bit corresponding to the rounding operation, and the approximate bit is used by the operation unit to round the target calculation result.

[0008] In a possible implementation, the shifter performs a shift process on the mantissa of the intermediate calculation result and outputs the target calculation result, including:

[0009] The shifter determines a target number of bits for shifting the mantissa of the intermediate calculation result based on a first number of bits for shifting the mantissa of the intermediate calculation result to the left / right and a second number of bits for shifting the mantissa of the intermediate calculation result to the right;

[0010] The shifter shifts the mantissa of the intermediate calculation result based on the target number of bits and outputs the target calculation result.

[0011] In a possible implementation, the second bit number is determined based on a difference between a mantissa bit width of the intermediate calculation result and a mantissa bit width of the target floating point number format.

[0012] In one possible implementation, when the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the number of leading zeros in the mantissa of the intermediate calculation result is not less than the minimum value of the exponent of the target floating-point number format, the first digit is determined based on the number of leading zeros in the mantissa of the intermediate calculation result.

[0013] In one possible implementation, when the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the number of leading zeros in the mantissa of the intermediate calculation result is less than the minimum value of the exponent in the target floating-point number format, the first digit is determined based on the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the minimum value of the exponent in the target floating-point number format.

[0014] In a possible implementation, the shifter determines the target number of bits for shifting the mantissa of the intermediate calculation result based on the first number of bits for shifting the mantissa of the intermediate calculation result to the left / right and the second number of bits for shifting the mantissa of the intermediate calculation result to the right, including:

[0015] The shifter determines the target number of bits to shift the mantissa of the intermediate calculation result based on the difference between the first digit and the second digit.

[0016] In a possible implementation, the shifter performs a shift process on the mantissa of the intermediate calculation result based on the target number of bits and outputs the target calculation result, including:

[0017] If the target number of bits is not less than zero, the shifter shifts the mantissa of the intermediate calculation result to the left by the target number of bits and outputs the target calculation result; otherwise,

[0018] When the target number of bits is less than zero, the shifter shifts the mantissa of the intermediate calculation result to the right by the absolute value of the target number of bits and outputs the target calculation result.

[0019] In a possible implementation, when the mantissa of the intermediate calculation result is shifted to the left, the sticky bit corresponding to the rounding operation is zero;

[0020] When the mantissa of an intermediate calculation result is shifted to the right, the sticky bit corresponding to the rounding operation is the portion shifted to the right.

[0021] In a possible implementation, the target floating point number format is a format specified by the IEEE754 standard.

[0022] In a possible implementation, the computing unit includes an arithmetic logic unit ALU of a graphics processor GPU.

[0023] According to another aspect of the present disclosure, a computing device is provided. The computing device may include:

[0024] A shifter is used to obtain the intermediate calculation result output by the operation unit, the intermediate calculation result is a floating point number, shift the mantissa of the intermediate calculation result, and output the target calculation result. The lowest bit of the mantissa in the target calculation result is the approximate bit corresponding to the rounding operation;

[0025] The calculation unit is used to output intermediate calculation results and round off the target calculation results.

[0026] In a possible implementation, the mantissa of the intermediate calculation result is shifted to output the target calculation result, including:

[0027] Determining a target number of bits for shifting the mantissa of the intermediate calculation result based on a first number of bits for shifting the mantissa of the intermediate calculation result to the left / right and a second number of bits for shifting the mantissa of the intermediate calculation result to the right;

[0028] Based on the target number of bits, the mantissa of the intermediate calculation result is shifted and the target calculation result is output.

[0029] In a possible implementation, the second bit number is determined based on a difference between a mantissa bit width of the intermediate calculation result and a mantissa bit width of the target floating point number format.

[0030] In one possible implementation, when the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the number of leading zeros in the mantissa of the intermediate calculation result is not less than the minimum value of the exponent of the target floating-point number format, the first digit is determined based on the number of leading zeros in the mantissa of the intermediate calculation result.

[0031] In one possible implementation, when the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the number of leading zeros in the mantissa of the intermediate calculation result is less than the minimum value of the exponent in the target floating-point number format, the first digit is determined based on the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the minimum value of the exponent in the target floating-point number format.

[0032] In a possible implementation, determining a target number of bits for shifting the mantissa of the intermediate calculation result based on a first number of bits for shifting the mantissa of the intermediate calculation result to the left or right and a second number of bits for shifting the mantissa of the intermediate calculation result to the right includes:

[0033] Based on the difference between the first digit and the second digit, the target number of bits to shift the mantissa of the intermediate calculation result is determined.

[0034] In a possible implementation, based on the target number of bits, the mantissa of the intermediate calculation result is shifted to output the target calculation result, including:

[0035] If the target number of digits is not less than zero, the mantissa of the intermediate calculation result is moved leftward by the target number of digits and the target calculation result is output; otherwise,

[0036] When the target number of digits is less than zero, the mantissa of the intermediate calculation result is shifted rightward by the absolute value of the target number of digits, and the target calculation result is output.

[0037] In a possible implementation, when the mantissa of the intermediate calculation result is shifted to the left, the sticky bit corresponding to the rounding operation is zero;

[0038] When the mantissa of an intermediate calculation result is shifted to the right, the sticky bit corresponding to the rounding operation is the portion shifted to the right.

[0039] In a possible implementation, the target floating point number format is a format specified by the IEEE754 standard.

[0040] In a possible implementation, the computing unit includes an arithmetic logic unit ALU of a graphics processor GPU.

[0041] According to another aspect of the present disclosure, a graphics processor is provided, comprising: the computing device as described above.

[0042] According to another aspect of the present disclosure, there is provided a data processing device, comprising: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to implement the above method when executing the instructions stored in the memory.

[0043] According to another aspect of the present disclosure, a non-volatile computer-readable storage medium is provided, on which computer program instructions are stored, wherein the computer program instructions implement the above method when executed by a processor.

[0044] According to another aspect of the present disclosure, a computer program product is provided, comprising a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code, and when the computer-readable code runs in a processor of a data processing device, the processor in the data processing device executes the above method.

[0045] According to an embodiment of the present application, after the shifter performs shift processing on the mantissa of the intermediate calculation result output by the obtained operation unit, the lowest bit of the mantissa in the target calculation result is the approximate bit corresponding to the rounding operation. At this time, the sticky bit is outside the lowest bit, so that the operation unit only needs to process the sticky bit in one case when rounding the target calculation result, and there is no need to select the reserved bit, approximate bit and sticky bit from different positions according to the target floating-point number format, and can be directly extracted. By improving the working mode of the shifter and the improvement of the cooperation mode between the shifter and the operation unit, the processing pressure of the operation unit is reduced, the processing speed is increased, the computing efficiency of the operation unit is improved, and the computing resources and computing time of the hardware are saved.

[0046] Further features and aspects of the present disclosure will become apparent from the following detailed description of exemplary embodiments with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate exemplary embodiments, features, and aspects of the disclosure and, together with the description, serve to explain the principles of the disclosure.

[0048] Figure 1 A schematic diagram of performing a shift operation is shown.

[0049] Figure 2 Another schematic diagram of performing a bit shift operation is shown.

[0050] Figure 3 Diagram showing different floating point number formats.

[0051] Figure 4 A structural diagram of a computing unit according to an embodiment of the present application is shown.

[0052] Figure 5 A flow chart of a data processing method according to an embodiment of the present application is shown.

[0053] Figure 6 A flow chart of a data processing method according to an embodiment of the present application is shown.

[0054] Figure 7 A schematic diagram showing a left shift of the mantissa of an intermediate calculation result according to an embodiment of the present application is shown.

[0055] Figure 8A schematic diagram showing right shifting of the mantissa of an intermediate calculation result according to an embodiment of the present application is shown.

[0056] Fig. 9 A structural diagram of a computing device according to an embodiment of the present application is shown.

[0057] Fig.10 It is a block diagram of a device 1900 for data processing according to an exemplary embodiment. DETAILED DESCRIPTION

[0058] Various exemplary embodiments, features and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise specified.

[0059] The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.

[0060] In addition, in order to better illustrate the present disclosure, numerous specific details are given in the following specific embodiments. It should be understood by those skilled in the art that the present disclosure can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present disclosure.

[0061] At present, the floating point calculations in mainstream computer chips all follow the corresponding standards, such as the IEEE754 standard. Regardless of whether the calculation result is a normalized number, the calculation result must be output in the format specified by the standard. Usually, during the calculation process, it is very likely to obtain a floating point calculation result that does not conform to the standard format. Therefore, it needs to be processed to obtain a calculation result that conforms to the standard format.

[0062] One example can be found in Figure 1 , showing a schematic diagram of a bit shift operation. Figure 1As shown, in the process of floating-point multiplication and addition, after the multiplication and addition of the mantissa (as shown in the figure, mat0*mat1+mat2), the mantissa result is a mantissa with several 0s in the high position, and the traditional method of processing such a result is to shift the result to the left, shift the first 1 that appears in the high position to the highest position of the calculation result, and then take out the valid bit required by the standard (the output part shown in the figure) from the high position according to the target floating-point format, and extract the guard bit, round bit and sticky bit for rounding operation, so as to finally obtain the mantissa of the normalized floating-point result that meets the requirements of the standard. At this time, the sticky bit of the rounding operation appears within the range of the mantissa of the calculation result.

[0063] Another example can be seen in Figure 2 , showing another schematic diagram of performing a shift operation. Figure 2 As shown, the absolute value of the floating point calculation result may be smaller than the normalized representation range specified in the IEEE754 standard format. For example, the highest bit of the mantissa after the multiplication and addition calculation in the figure is 1, but because the exponent is smaller than the minimum exponent value of the target floating point format, the traditional method for processing such a result is to shift the mantissa right, thereby adjusting the exponent to the minimum value of the target floating point format. Thereafter, the mantissa of the target floating point format is taken out from the first section of the obtained mantissa result (the output part shown in the figure), and the reserved bit, the approximate bit and the sticky bit are extracted for rounding operation, so as to finally obtain the mantissa of the non-normalized floating point result that meets the standard requirements. At this time, a part of the sticky bit of the rounding operation may appear outside the range of the mantissa of the calculation result.

[0064] According to the above conventional method, the sticky bit corresponding to the rounding operation may appear within the range of the calculation result mantissa or outside the range of the calculation result mantissa. In this way, the operation unit needs to judge two different sticky bits when performing rounding operations.

[0065] If the computing unit supports floating-point calculation results in multiple target formats at the same time, the results obtained by traditional processing may have the reserved bits, approximate bits, and sticky bits of the mantissa appear in different positions, see Figure 3 , showing schematic diagrams of different floating point formats. Figure 3 As shown in the figure, if the computing unit supports multiple target floating point formats at the same time, the reserved bits, approximate bits, and sticky bits corresponding to rounding operations in different formats may appear in different positions. In this way, the computing unit needs to select according to the target format before performing rounding operations, which increases the burden on hardware resources and reduces the work efficiency of the hardware. Therefore, a new method is urgently needed to save hardware computing resources and computing time.

[0066] In view of this, the embodiments of the present application provide a data processing method, device, computing device, graphics processor and storage medium. The method of the embodiments of the present application enables the shifter to shift the mantissa of the intermediate calculation result output by the obtained operation unit, and the lowest bit of the mantissa in the target calculation result is the approximate bit corresponding to the rounding operation. At this time, the sticky bit is outside the lowest bit, so that the operation unit only needs to process the sticky bit in one case when rounding the target calculation result, and there is no need to select the reserved bit, approximate bit and sticky bit from different positions according to the target floating point format, and can be directly extracted. Through the improvement of the working mode of the shifter and the improvement of the cooperation mode between the shifter and the operation unit, the processing pressure of the operation unit is reduced, the processing speed is increased, the calculation efficiency of the operation unit is improved, and the calculation resources and calculation time of the hardware are saved.

[0067] Figure 4 FIG. 2 shows a structural diagram of a computing unit according to an embodiment of the present application. Figure 4 As shown, the method of the embodiment of the present application can be used in a computing unit 400, which can be an arithmetic logic unit (ALU) included in any processor such as a graphics processing unit (GPU) or a central processing unit (CPU).

[0068] The calculation unit may include a calculation unit 401 and a shifter 402. The calculation unit may include an arithmetic operation unit (such as an adder, a multiplier, etc.) and a logic operation unit, which may be used to perform corresponding calculation operations, output intermediate calculation results, and perform rounding operations on data; the shifter may be used to perform shift operations on data.

[0069] Optionally, the computing unit may also include other sub-units, such as registers, etc., which is not limited in this application.

[0070] The following Figure 4 Based on the illustrated computing unit structure, the data processing method of the embodiment of the present application is introduced.

[0071] Figure 5 FIG. 1 is a flow chart showing a data processing method according to an embodiment of the present application. The data processing method may be used in a computing unit, which may include a computing unit and a shifter, such as Figure 5 As shown, the method may include:

[0072] Step S501: The shifter obtains the intermediate calculation result output by the operation unit.

[0073] An example of a shifter can be found in Figure 4The shifter 402 in FIG. 4 is an example of an operation unit. Figure 4 The operation unit 401 in .

[0074] The intermediate calculation result is a floating point number. For example, it can be a multiplication result output by a multiplier of an operation unit. The intermediate calculation result can be a floating point number that does not meet the standard format requirements. Therefore, the mantissa of the intermediate calculation result can be processed by a shifter so that the mantissa of the intermediate calculation result meets the mantissa of the standard format.

[0075] Step S502: The shifter performs shift processing on the mantissa of the intermediate calculation result and outputs the target calculation result.

[0076] After the shifter shifts the mantissa of the intermediate calculation result, the lowest bit of the mantissa in the target calculation result is the approximate bit corresponding to the rounding operation, and the approximate bit is the bit after the reserved bit, indicating the highest bit discarded during the rounding operation. The reserved bit can represent the lowest bit retained in the mantissa part.

[0077] The target calculation result output by the shift processing may be a result that complies with a predetermined standard, for example, the IEEE754 standard. Complying with the predetermined standard may mean that the output target calculation result can be represented by a format specified by the predetermined standard. For example, under the IEEE754 standard, the value of the target calculation result output after the shift processing can be represented by a sign bit (sign) × an exponent term (exponent) × a mantissa part (mantissa).

[0078] Approximate bits can be used by the operation unit to perform rounding operations on the target calculation result. By making the lowest bit of the mantissa in the output target calculation result the approximate bit corresponding to the rounding operation, and the approximate bit is the last bit of the reserved bit, and the sticky bit is the last p bits of the approximate bit (p is an integer, determined according to the mantissa bit width of the intermediate calculation result), that is, since the approximate bit is determined, the reserved bit and sticky bit corresponding to the rounding operation are fixed, so that the operation unit does not need to consider different target floating-point formats (such as the different mantissa lengths of single-precision and double-precision floating-point numbers), and directly extracts the reserved bit, approximate bit and sticky bit from the corresponding position for rounding operations. For different operation units and operation tasks, the accuracy requirements for rounding are different, and the way to perform rounding operations can be determined based on the prior art. Among them, the approximate bit can be used to determine whether to carry to the reserved bit.

[0079] According to an embodiment of the present application, after the shifter performs shift processing on the mantissa of the intermediate calculation result output by the obtained operation unit, the lowest bit of the mantissa in the target calculation result is the approximate bit corresponding to the rounding operation. At this time, the sticky bit is outside the lowest bit, so that the operation unit only needs to process the sticky bit in one case when rounding the target calculation result, and there is no need to select the reserved bit, approximate bit and sticky bit from different positions according to the target floating-point number format, and can be directly extracted, thereby improving the computing efficiency of the operation unit and saving hardware computing resources and computing time.

[0080] The following is a detailed introduction to the way in which the shifter shifts the mantissa of the intermediate calculation result. In order to make the lowest bit of the mantissa after the shift processing the approximate bit corresponding to the rounding operation, the number of bits of the mantissa to be shifted can be comprehensively determined based on the first bit of the mantissa to be shifted left / right and the second bit of the mantissa to be shifted right. Figure 6 , shows a flow chart of a data processing method according to an embodiment of the present application. Figure 6 As shown, step S502 may include:

[0081] Step S601, the shifter determines the target number of bits for shifting the mantissa of the intermediate calculation result based on the first number of bits for shifting the mantissa of the intermediate calculation result to the left / right and the second number of bits for shifting the mantissa of the intermediate calculation result to the right.

[0082] It should be noted that in S601, the order of determining the first digit and the second digit is not fixed. The first digit to which the decimal of the intermediate calculation result is moved to the left / right can be determined first, and then the second digit to which the decimal of the intermediate calculation result is moved to the right can be determined. The second digit can also be determined first, and then the first digit can be determined. This application does not impose any restrictions on this.

[0083] Since there are two possible situations for the intermediate calculation results, please refer to Figure 1 and Figure 2 In the first case, the mantissa of the intermediate calculation result is a mantissa with several 0s in the high digits, but the number of leading zeros in the mantissa of the intermediate calculation result is not less than the minimum exponent value of the target floating-point format; in the second case, the number of leading zeros in the mantissa of the intermediate calculation result is less than the minimum exponent value of the target floating-point format. Therefore, the first digit of the mantissa to be shifted left / right can be calculated for these two different cases.

[0084] Wherein, when the first digit is not less than 0, it can be determined that the mantissa of the intermediate calculation result is moved to the left; when the first digit is less than 0, it can be determined that the mantissa of the intermediate calculation result is moved to the right.

[0085] Optionally, when the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the number of leading zeros in the mantissa of the intermediate calculation result is not less than the minimum value of the exponent of the target floating-point number format, the first digit can be determined based on the number of leading zeros in the mantissa of the intermediate calculation result.

[0086] Taking the target floating point format as the normalized floating point format under the IEEE754 standard as an example, the intermediate calculation result is not less than the minimum value that can be represented by the normalized floating point format under the IEEE754 standard.

[0087] Among them, the number of leading zeros in the mantissa of the intermediate calculation result (which may be referred to as z) may refer to the number of 0s before the most significant 1 in the mantissa, the minimum exponent value of the target floating-point number format (which may be referred to as exp_min) may be determined according to different target floating-point number formats, and the minimum exponent value may also be used to determine the minimum value of a floating-point number that can be represented in the form of an exponent. The target floating-point number format may be a format specified by the IEEE 754 standard. For example, under the IEEE 754 standard, the target floating-point number format may include a single-precision floating-point number and a double-precision floating-point number. For a single-precision floating-point number, the minimum exponent value is -126, and for a double-precision floating-point number, the minimum exponent value is -1022. The minimum exponent value may be the binary bit width when the minimum exponent value is represented in binary, for example, the exponent bit width for a double-precision floating-point number is 11.

[0088] When the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the number of leading zeros in the mantissa of the intermediate calculation result is less than the minimum value of the exponent in the target floating-point number format, the first digit can be determined based on the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the minimum value of the exponent in the target floating-point number format.

[0089] Taking the target floating point format as the normalized floating point format under the IEEE754 standard as an example, that is to say, at this time, the intermediate calculation result is smaller than the minimum value that can be represented by the normalized floating point format under the IEEE754 standard.

[0090] The exponent corresponding to the highest bit of the mantissa of the intermediate calculation result may refer to the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result when it is not processed (may be referred to as exp).

[0091] For the intermediate calculation results in two different cases, the second digit may be determined based on the difference between the mantissa bit width of the intermediate calculation result and the mantissa bit width of the target floating-point number format.

[0092] Among them, the mantissa bit width of the intermediate calculation result (which may be called n) may refer to the bit width of the mantissa of the intermediate calculation result when it is not processed; the mantissa bit width of the target floating-point number format (which may be called m) may be determined in advance, for example, for single-precision floating-point numbers, the mantissa bit width may be 23 bits, and for double-precision floating-point numbers, the mantissa bit width may be 52 bits.

[0093] Step S602: The shifter shifts the mantissa of the intermediate calculation result based on the target number of bits and outputs the target calculation result.

[0094] The shifter can determine the target number of bits for shifting the mantissa of the intermediate calculation result based on the difference between the first number and the second number, as described below.

[0095] When the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the number of leading zeros in the mantissa of the intermediate calculation result is not less than the minimum exponent of the target floating-point format, i.e., exp - z ≥ exp_min, a calculation method for the target number of bits can be seen in formula (1):

[0096] shf_val = z - n + m + 2 Formula (1)

[0097] Among them, shf_val can represent the target number of bits, z represents the number of leading zeros in the mantissa of the intermediate calculation result, n represents the mantissa bit width of the intermediate calculation result, and m represents the mantissa bit width of the target floating-point format. The first number is z, and the second number is n - m - 2.

[0098] When the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the number of leading zeros in the mantissa of the intermediate calculation result is less than the minimum exponent of the target floating-point format, i.e., exp - z < exp_min, a calculation method for the target number of bits can be seen in formula (2):

[0099] shf_val = exp - exp_min - n + m + 2 Formula (2)

[0100] Among them, exp represents the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result, and exp_min represents the minimum exponent of the target floating-point format. The first number is exp - exp_min, and the second number is n - m - 2.

[0101] Optionally, this step S602 may include:

[0102] When the target number of bits is not less than zero, i.e., shf_val ≥ 0, the shifter shifts the mantissa of the intermediate calculation result to the left by the target number of bits, that is, shifts the mantissa of the intermediate calculation result to the left by shf_val bits and outputs the target calculation result; otherwise, when the target number of bits is less than zero, i.e., shf_val < 0, the shifter shifts the mantissa of the intermediate calculation result to the right by the absolute value of the target number of bits, that is, shifts the mantissa of the intermediate calculation result to the right by -shf_val bits and outputs the target calculation result.

[0103] In the case where the mantissa of the intermediate calculation result is shifted to the left, the sticky bit corresponding to the rounding operation is zero. Figure 7 , showing a schematic diagram of left shifting the mantissa of an intermediate calculation result according to an embodiment of the present application. Figure 7 As shown, when the mantissa of the intermediate calculation result is shifted to the left, the lowest bit of the mantissa after the shift operation is the approximate bit, and the output part of the mantissa is as shown in the figure, which is the last bit of the highest bit after the shift to the reserved bit, and the approximate bit is the last bit of the output part. At this time, there is no sticky bit.

[0104] When the mantissa of an intermediate calculation result is shifted to the right, the sticky bit corresponding to the rounding operation is the part that is shifted to the right. Figure 8 , showing a schematic diagram of right shifting the mantissa of an intermediate calculation result according to an embodiment of the present application. Figure 8 As shown, when the mantissa of the intermediate calculation result is shifted to the right, the lowest bit of the mantissa after the shift operation is the approximate bit, and the output part of the mantissa is shown in the figure, which is the last bit of the highest bit after the shift to the reserved bit, the approximate bit is the last bit of the output part, and the sticky bit is all the bits after the approximate bit.

[0105] based on Figure 7 and Figure 8 It can be seen that after the shift processing is performed based on the method of the embodiment of the present application, the sticky bits are all outside the lowest bit of the calculation window (corresponding to the mantissa part). In this way, when the subsequent operation unit performs rounding operations, there is no need to consider whether the sticky bit is within the calculation window, thereby improving the calculation efficiency of the operation unit.

[0106] Therefore, the subsequent operation unit can directly extract the approximate bit and perform rounding operation on the mantissa of the target calculation result based on the approximate bit, so that the result of the rounding operation can meet the requirements of the subsequent operation. In this process, there is no need to consider different target floating point formats, which saves the calculation time and computing resources of the operation unit.

[0107] Fig. 9 FIG. 1 shows a structural diagram of a computing device according to an embodiment of the present application. Fig. 9 As shown, the computing device may include:

[0108] The shifter 901 is used to obtain the intermediate calculation result output by the operation unit, the intermediate calculation result is a floating point number, shift the mantissa of the intermediate calculation result, and output the target calculation result. The lowest bit of the mantissa in the target calculation result is the approximate bit corresponding to the rounding operation;

[0109] The calculation unit 902 is used to output the intermediate calculation result and perform rounding operation on the target calculation result.

[0110] In a possible implementation, the mantissa of the intermediate calculation result is shifted to output the target calculation result, including:

[0111] Determining a target number of bits for shifting the mantissa of the intermediate calculation result based on a first number of bits for shifting the mantissa of the intermediate calculation result to the left / right and a second number of bits for shifting the mantissa of the intermediate calculation result to the right;

[0112] Based on the target number of bits, the mantissa of the intermediate calculation result is shifted and the target calculation result is output.

[0113] In a possible implementation, the second bit number is determined based on a difference between a mantissa bit width of the intermediate calculation result and a mantissa bit width of the target floating point number format.

[0114] In one possible implementation, when the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the number of leading zeros in the mantissa of the intermediate calculation result is not less than the minimum value of the exponent of the target floating-point number format, the first digit is determined based on the number of leading zeros in the mantissa of the intermediate calculation result.

[0115] In one possible implementation, when the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the number of leading zeros in the mantissa of the intermediate calculation result is less than the minimum value of the exponent in the target floating-point number format, the first digit is determined based on the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the minimum value of the exponent in the target floating-point number format.

[0116] In a possible implementation, determining a target number of bits for shifting the mantissa of the intermediate calculation result based on a first number of bits for shifting the mantissa of the intermediate calculation result to the left or right and a second number of bits for shifting the mantissa of the intermediate calculation result to the right includes:

[0117] Based on the difference between the first digit and the second digit, the target number of bits to shift the mantissa of the intermediate calculation result is determined.

[0118] In a possible implementation, based on the target number of bits, the mantissa of the intermediate calculation result is shifted to output the target calculation result, including:

[0119] If the target number of digits is not less than zero, the mantissa of the intermediate calculation result is moved leftward by the target number of digits and the target calculation result is output; otherwise,

[0120] When the target number of digits is less than zero, the mantissa of the intermediate calculation result is shifted rightward by the absolute value of the target number of digits, and the target calculation result is output.

[0121] In a possible implementation, when the mantissa of the intermediate calculation result is shifted to the left, the sticky bit corresponding to the rounding operation is zero;

[0122] When the mantissa of an intermediate calculation result is shifted to the right, the sticky bit corresponding to the rounding operation is the portion shifted to the right.

[0123] In a possible implementation, the target floating point number format is a format specified by the IEEE754 standard.

[0124] In a possible implementation, the computing unit includes an arithmetic logic unit ALU of a graphics processor GPU.

[0125] According to an embodiment of the present application, after the shifter performs shift processing on the mantissa of the intermediate calculation result output by the obtained operation unit, the lowest bit of the mantissa in the target calculation result is the approximate bit corresponding to the rounding operation. At this time, the sticky bit is outside the lowest bit, so that the operation unit only needs to process the sticky bit in one case when rounding the target calculation result, and there is no need to select the reserved bit, approximate bit and sticky bit from different positions according to the target floating-point number format, and can be directly extracted. By improving the working mode of the shifter and the improvement of the cooperation mode between the shifter and the operation unit, the processing pressure of the operation unit is reduced, the processing speed is increased, the computing efficiency of the operation unit is improved, and the computing resources and computing time of the hardware are saved.

[0126] In some embodiments, the functions or modules included 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.

[0127] The disclosed embodiment further provides a graphics processor, including: the computing device as described above.

[0128] The embodiment of the present disclosure also provides a computer-readable storage medium on which computer program instructions are stored, and the computer program instructions implement the above method when executed by a processor. The computer-readable storage medium can be a volatile or non-volatile computer-readable storage medium.

[0129] An embodiment of the present disclosure further proposes a data processing device, comprising: a processor; a memory for storing instructions executable by the processor; wherein the processor is configured to implement the above method when executing the instructions stored in the memory.

[0130] The embodiment of the present disclosure also provides a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of a data processing device, the processor in the data processing device executes the above method.

[0131] Fig.101 is a block diagram of a device 1900 for data processing according to an exemplary embodiment. For example, the device 1900 may be provided as a server or a terminal device, and the computing unit of the present application may be deployed on the server or the terminal device. Fig.10 , the apparatus 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions, such as an application, that can be executed by the processing component 1922. The application stored in the memory 1932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1922 is configured to execute instructions to perform the above method.

[0132] The device 1900 may also include a power supply component 1926 configured to perform power management of the device 1900, a wired or wireless network interface 1950 configured to connect the device 1900 to a network, and an input / output interface 1958 (I / O interface). The device 1900 may operate based on an operating system stored in the memory 1932, such as Windows Server 2000. TM , MacOS X TM , Unix TM ,Linux TM , FreeBSD TM or similar.

[0133] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions, which can be executed by the processing component 1922 of the device 1900 to perform the above method.

[0134] The present disclosure may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present disclosure.

[0135] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples of computer-readable storage media (a non-exhaustive list) include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the foregoing. As used herein, a computer-readable storage medium is not to be interpreted as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.

[0136] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.

[0137] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.

[0138] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.

[0139] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0140] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0141] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.

[0142] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

Claims

1. A data processing method, characterized in that: The method is used for a computing unit, the computing unit includes an operation unit and a shifter, and the method includes: The shifter obtains the intermediate calculation result output by the operation unit, wherein the intermediate calculation result is a floating point number; The shifter performs shift processing on the mantissa of the intermediate calculation result and outputs a target calculation result, wherein the lowest bit of the mantissa in the target calculation result is an approximate bit corresponding to a rounding operation, and the sticky bit corresponding to the rounding operation is outside the lowest bit of the mantissa, and the approximate bit is used by the operation unit to perform the rounding operation on the target calculation result.

2. The method according to claim 1, characterized in that The shifter performs shift processing on the mantissa of the intermediate calculation result and outputs the target calculation result, including: The shifter determines a target number of bits for shifting the mantissa of the intermediate calculation result based on a first number of bits for shifting the mantissa of the intermediate calculation result to the left or right and a second number of bits for shifting the mantissa of the intermediate calculation result to the right, wherein the first number of bits is determined based on a difference between the number of leading zeros in the mantissa of the intermediate calculation result or an exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and a minimum value of an exponent in a target floating-point number format; The shifter performs shift processing on the mantissa of the intermediate calculation result based on the target number of bits, and outputs the target calculation result.

3. The method according to claim 2, characterized in that The second number of bits is determined based on a difference between a mantissa bit width of the intermediate calculation result and a mantissa bit width of a target floating point number format.

4. The method according to claim 2, characterized in that: When the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the number of leading zeros in the mantissa of the intermediate calculation result is not less than the minimum value of the exponent of the target floating-point number format, the first bit number is determined based on the number of leading zeros in the mantissa of the intermediate calculation result.

5. The method according to claim 2, characterized in that: In the case where the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the number of leading zeros in the mantissa of the intermediate calculation result is less than the minimum value of the exponent in the target floating-point number format, the first bit is determined based on the difference between the exponent corresponding to the highest bit of the mantissa of the intermediate calculation result and the minimum value of the exponent in the target floating-point number format.

6. The method according to claim 2, characterized in that The shifter determines a target number of bits for shifting the mantissa of the intermediate calculation result based on a first number of bits for shifting the mantissa of the intermediate calculation result to the left / right and a second number of bits for shifting the mantissa of the intermediate calculation result to the right, including: The shifter determines a target number of bits for shifting the mantissa of the intermediate calculation result based on a difference between the first number of bits and the second number of bits.

7. The method according to claim 2, characterized in that The shifter performs shift processing on the mantissa of the intermediate calculation result based on the target number of bits and outputs the target calculation result, including: If the target number of bits is not less than zero, the shifter shifts the mantissa of the intermediate calculation result to the left by the target number of bits and outputs the target calculation result; otherwise, When the target number of bits is less than zero, the shifter shifts the mantissa of the intermediate calculation result rightward by the absolute value of the target number of bits, and outputs the target calculation result.

8. The method according to claim 1, characterized in that In the case where the mantissa of the intermediate calculation result is shifted to the left, the sticky bit corresponding to the rounding operation is zero; When the mantissa of the intermediate calculation result is shifted to the right, the sticky bit corresponding to the rounding operation is the part shifted out to the right.

9. The method according to claim 3, characterized in that: The target floating point number format is a format specified by the IEEE754 standard.

10. The method according to claim 1, characterized in that The computing unit includes an arithmetic logic unit ALU of a graphics processing unit GPU.

11. A computing device, characterized in that: The computing device comprises: A shifter, used for obtaining an intermediate calculation result outputted by the operation unit, the intermediate calculation result being a floating point number, performing shift processing on the mantissa of the intermediate calculation result, and outputting a target calculation result, wherein the lowest bit of the mantissa in the target calculation result is an approximate bit corresponding to the rounding operation, and the sticky bit corresponding to the rounding operation is outside the lowest bit of the mantissa; The computing unit is used to output the intermediate calculation result and perform the rounding operation on the target calculation result.

12. A graphics processor, characterized in that: include: The computing device of claim 11.

13. A data processing device, characterized in that: include: processor; a memory for storing processor-executable instructions; Wherein, the processor is configured to implement the method described in any one of claims 1 to 10 when executing the instructions stored in the memory.

14. A non-volatile computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 10 is implemented.

Citation Information

Patent Citations

  • 5-grade stream line structure of floating point multiplier adder integrated unit

    CN101174200A

  • Floating-point adder

    CN102855117A