WO2022052625A1 - 一种定点与浮点转换器、处理器、方法以及存储介质 - Google Patents
一种定点与浮点转换器、处理器、方法以及存储介质 Download PDFInfo
- Publication number
- WO2022052625A1 WO2022052625A1 PCT/CN2021/106761 CN2021106761W WO2022052625A1 WO 2022052625 A1 WO2022052625 A1 WO 2022052625A1 CN 2021106761 W CN2021106761 W CN 2021106761W WO 2022052625 A1 WO2022052625 A1 WO 2022052625A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- point
- floating
- point data
- value
- fixed
- Prior art date
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F7/00—Methods or arrangements for processing data by operating upon the order or content of the data handled
- G06F7/38—Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation
- G06F7/48—Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation using non-contact-making devices, e.g. tube, solid state device; using unspecified devices
- G06F7/57—Arithmetic logic units [ALU], i.e. arrangements or devices for performing two or more of the operations covered by groups G06F7/483 – G06F7/556 or for performing logical operations
- G06F7/575—Basic arithmetic logic units, i.e. devices selectable to perform either addition, subtraction or one of several logical operations, using, at least partially, the same circuitry
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T1/00—General purpose image data processing
- G06T1/20—Processor architectures; Processor configuration, e.g. pipelining
Definitions
- This application relates to the field of Internet technologies, and in particular to a fixed-point and floating-point converter, a fixed-point and floating-point graphics processor, a fixed-point and floating-point central processing unit, a fixed-point and floating-point conversion method, and a computer Readable storage medium.
- the fixed-point to floating-point processing unit is widely used in computer science, communication, artificial intelligence and other fields.
- Well-known graphics processing unit Graphics Processing Unit, GPU
- central processing unit central processing unit, CPU
- large-scale artificial intelligence Artificial Intelligence, AI chip contains several fixed-point to floating-point processing units, as A fundamental component whose importance is clearly visible.
- the fixed-point to floating-point processing unit needs to set the data format of the fixed-point data, such as pure decimals or pure integers.
- the primary condition for converting fixed-point data to floating-point data is that the fixed-point data is in a specific format. If the format of the fixed-point data Different from the predetermined format, it cannot be converted, and it can be seen that the generality of the existing technology is not good when applied.
- Embodiments of the present application provide a fixed-point and floating-point converter, a fixed-point and floating-point graphics processor, a fixed-point and floating-point central processing unit, a fixed-point and floating-point conversion method, and a computer-readable storage medium, which can improve the versatility of converting fixed-point data to floating-point data.
- an embodiment of the present application provides a fixed-point to floating-point converter, where the fixed-point to floating-point converter includes an input module, a left search module, a right search module, and a floating point module;
- the input module is used to obtain the target fixed-point data, and input the target fixed-point data into the left search module and the right search module respectively;
- the left search module is used to search for integer leading values along the integer direction starting from the decimal point position of the target fixed-point data
- the right search module is used to search for the leading value of the decimal along the decimal direction starting from the decimal point position of the target fixed-point data;
- the floating-point module is used to obtain the first exponent offset value for the integer leading value output by the left search module if the integer leading value is searched by the left search module, according to the sign bit corresponding to the target fixed-point data and the first exponent offset Shift value to generate floating-point data corresponding to target fixed-point data;
- the floating-point module is also used to obtain the second exponent offset value for the decimal leading value output by the right-directed search module if the integer leading value is not searched by the left-directed search module, according to the sign bit and the second index corresponding to the target fixed-point data. Exponential offset value to generate floating-point data corresponding to the target fixed-point data.
- an embodiment of the present application provides a fixed-point to floating-point conversion method, where the method is performed by the above-mentioned fixed-point to floating-point converter, and the method includes:
- the integer leading value search is performed along the integer direction
- the decimal leading value search is performed along the decimal direction
- the left search module searches for an integer leading value, obtain the first index offset value for the integer leading value output by the left search module, and generate the target fixed point according to the sign bit corresponding to the target fixed point data and the first index offset value
- the left search module does not search for an integer leading value, obtain the second exponent offset value for the fractional leading value output by the right search module, and generate the target according to the sign bit corresponding to the target fixed-point data and the second exponent offset value. Floating-point data corresponding to fixed-point data.
- an embodiment of the present application provides a fixed-point to floating-point graphics processor, where the fixed-point to floating-point graphics processor includes the above-mentioned fixed-point and floating-point converter.
- an embodiment of the present application provides a fixed-point to floating-point central processing unit, and the fixed-point to floating-point central processing unit includes the above-mentioned fixed-point and floating-point converter.
- 1a is a schematic structural diagram of a fixed-point to floating-point converter provided by an embodiment of the present application
- FIG. 1b is a schematic structural diagram of a leftward search module provided by an embodiment of the present application.
- 1c is a schematic structural diagram of a right-direction search module provided by an embodiment of the present application.
- FIG. 2 is a schematic structural diagram of a fixed-point to floating-point converter provided by an embodiment of the present application
- Fig. 3a is a conversion schematic diagram of converting fixed-point data into floating-point data provided by an embodiment of the present application
- 3b is a schematic diagram of a scenario of fixed-point data format conversion provided by an embodiment of the present application.
- Fig. 3c is a kind of conversion schematic diagram of converting fixed-point data into floating-point data provided by an embodiment of the present application
- FIG. 5 is a fixed-point to floating-point central processing unit provided by an embodiment of the present application.
- FIG. 6 is a fixed-point and floating-point conversion method provided by an embodiment of the present application.
- Chip refers to a silicon chip containing an integrated circuit, which is small in size and is often an important part of a computer or other electronic equipment.
- Fixed-point number a number with a fixed decimal point, which can represent integers and decimals, such as 5, 2.13.
- Floating-point numbers numbers with non-fixed decimal points, which can represent a wide range of data, including single-precision numbers, double-precision numbers, etc.
- Floating-point numbers use scientific notation to express real numbers, that is, a mantissa (Mantissa) and a base (Base). ), an Exponent, and a sign to represent real numbers.
- 123.45 can be expressed as 1.2345 ⁇ 10 2 in decimal scientific notation, where 1.2345 is the mantissa, 10 is the base, and 2 is the exponent, or 12.345 ⁇ 10, where 12.345 is the mantissa, 10 is the base, and 1 is the exponent.
- Floating-point numbers use exponents to achieve the effect of floating decimal points, so that they can flexibly express a larger range of real numbers.
- the central processing unit (CPU), as the operation and control core of the computer system, is the final execution unit for information processing and program operation.
- GPU Graphics Processing Unit
- display core visual processor
- display chip is a kind of computer specially designed for personal computers, workstations, game consoles and some mobile devices (such as tablet computers, smart phones, etc.) It is a microprocessor that does image and graphics related operations.
- FIG. 1a is a schematic structural diagram of a fixed-point and floating-point converter provided by an embodiment of the present application.
- the fixed-point and floating-point converter may include: an input module 101, a left-direction search module 102, a right-direction search module 103, and a floating-point module 104, wherein,
- the input module 101 is configured to acquire target fixed-point data, and input the target fixed-point data into the left search module and the right search module respectively.
- the target fixed-point data refers to a binary number that does not carry a sign bit
- the binary number may be a pure integer, a pure decimal, or an integer that carries a decimal, such as 10001, 0.111, and 1001.11.
- the decimal number represented by 10001 without the sign bit is 17, and the decimal number -15 can also be represented by the binary number 10001. At this time, the highest 1 in the binary number 10001 indicates that the binary number is negative.
- the left search module 102 is used to search for integer leading values along the integer direction starting from the decimal point position of the target fixed-point data.
- the integer leading value refers to 1 in the highest bit of the integer part.
- the left search module 102 quickly searches to the left (ie, the integer direction) to find the position of the integer leading value, and determines the integer leading value.
- the position information corresponding to the decimal point position of the value relative to the target fixed-point data For example, the target fixed-point data is 1001.11, the left search module 102 searches for the integer leading value to the left, and it can be determined that the integer leading value is located in the thousands place, then the position information of the integer leading value is a left offset of 3.
- the right search module 103 is configured to start from the position of the decimal point of the target fixed-point data, and to search for the leading value of the decimal along the decimal direction.
- the decimal leading value refers to 1 in the highest digit of the decimal part.
- the right search module 103 quickly searches to the right (that is, the decimal direction) to find the position of the decimal leading value, and determines the decimal leading value.
- the position information corresponding to the decimal point position of the value relative to the target fixed-point data For example, the target fixed-point data is 0.011, and the right search module 103 searches for the decimal leading value to the right, and it can be determined that the decimal leading value is located at the percentile, then the position information of the decimal leading value is shifted to the right by 2.
- the floating-point module 104 is configured to obtain the first exponent offset value for the integer leading value output by the left-hand search module if the integer leading value is searched by the left-hand search module, according to the sign bit and the first exponent corresponding to the target fixed-point data Offset value to generate floating-point data corresponding to the target fixed-point data.
- the floating-point module 104 is further configured to obtain the second exponent offset value for the decimal leading value output by the right-direction search module if the integer leading value is not searched by the left-direction search module, according to the sign bit corresponding to the target fixed-point data and the first index value. Two-exponential offset value to generate floating-point data corresponding to the target fixed-point data.
- FIG. 1b is a schematic structural diagram of a left-direction search module provided by an embodiment of the present application.
- the left search module 102 may include a left acquisition unit 1021, a first traversal unit 1022 and a first search unit 1023, wherein,
- the leftward acquisition unit 1021 is used to obtain the leftward search range of the target fixed-point data along the integer direction starting from the decimal point position of the target fixed-point data; the leftward search range includes the leftward initial value, and the leftward initial value refers to the The value closest to the decimal point of the target fixed-point data in the search range.
- first obtain the starting position of the search that is, the decimal point position of the target fixed-point data
- obtain the leftward search range from the left of the starting position For example, the leftward search range of the target fixed-point data 100.001 is 100.
- the first traversing unit 1022 is configured to traverse each leftward numerical value in the leftward search range along the integer direction starting from the leftward starting value.
- the first search unit 1023 is configured to search for an integer leading value according to the left traversal result.
- the leftward search range of the target fixed-point data 100.001 is 100, and the leftward numerical value includes 1, 0, and 0, and each leftward numerical value is compared with the integer leading value.
- a first index offset value is determined, and the first index offset value of the target fixed-point data 100.001 is 2.
- the first index offset value can be determined by traversing each left value.
- the example code of the implementation process of the left acquisition unit 1021, the first traversal unit 1022 and the first search unit 1023 can be found in Table 1:
- data[start1] represents the left starting value
- index represents the integer leading value (ie, 1).
- the leftward traversal result includes a leftward value Z i , i is a positive integer, and i is less than or equal to the total number of leftward values in the leftward search range, and the leftward value Z i includes initial value;
- the first search unit 1023 is specifically configured to determine that the left search range does not include an integer leading value if none of the left values Z i in the left traversal result is equal to the default value; the integer leading value is equal to the default value. For example, if the left search range in the target fixed-point data 0.0011 does not include an integer leading value (ie, 1), the first search unit 1023 may determine that the left search range does not include an integer leading value.
- the first search unit 1023 is specifically configured to, if there is a leftward numerical value Z i equal to a default value in the leftward traversal result, determine that the leftward search range includes an integer leading value, and obtain the leftward position of the leftward numerical value Z i equal to the default value.
- information L i for example, the left search range in the target fixed-point data 100.0011 includes 100, and the hundreds place is 1, then the first search unit 1023 can determine that the left search range includes integer leading values, and obtains the left value Z 3 Left position information (ie, the hundreds position).
- the first search unit 1023 is specifically configured to determine the first exponent offset value according to the left position information farthest from the initial position in the left position information L i ; the initial position is the decimal point position of the target fixed-point data; the target fixed-point data 100.0011
- the offset value of the first exponent is 2, resulting in a floating point number 1.000011*2 2 .
- FIG. 1c is a schematic structural diagram of a right-direction search module provided by an embodiment of the present application.
- the right search module 103 may include a right acquisition unit 1031, a second traversal unit 1032, and a second search unit 1033, wherein,
- the right direction acquisition unit 1031 is used to obtain the right search range of the target fixed point data from the decimal point position of the target fixed point data along the decimal direction; the right search range includes the right start value, and the right start value refers to the right start value. The value closest to the decimal point of the target fixed-point data in the search range.
- the starting position of the search that is, the decimal point position of the target fixed-point data
- the right search range of the target fixed-point data 0.00110 is 00110.
- the second traversing unit 1032 is configured to traverse each right-direction numerical value in the right-direction search range along the decimal direction starting from the right-direction starting numerical value.
- the second search unit 1033 is configured to search for the leading decimal value according to the result of the right-direction traversal.
- the right-direction search range of the target fixed-point data 0.00110 is 00110, and each right-direction value is compared with the decimal leading value, and the second exponent offset value can be determined according to the comparison result.
- the second exponent offset value of the data 0.00110 is -3.
- the second index offset value can be determined by traversing each rightward numerical value.
- Table 2 The example codes of the implementation process of the rightward obtaining unit 1031, the first traversing unit 1032 and the first searching unit 1033 can be found in Table 2:
- data[start2] represents the right starting value
- index represents the decimal leading value (ie 1).
- the rightward traversal result includes a rightward value Y j , where j is a positive integer, and j is less than or equal to the total number of rightward values in the rightward search range, and the rightward value Yj includes a rightward starting value initial value;
- the second search unit 1033 is specifically configured to determine that the right search range does not include the decimal leading value if the right numerical value Y j in the right traversal result is not equal to the default value; the numerical value of the decimal leading value is equal to the default value; for example, The target fixed-point data 1100 does not have a right search range, or the right search range is 0, that is, the leading decimal value (ie, 1) is not included.
- the second search unit 1033 is specifically configured to, if there is a right value Y j equal to the default value in the right traversal result, determine that the right search range includes the decimal leading value, and obtain the right position of the right value Y j equal to the default value Information C j ; the right search range of the target fixed-point data 0.00110 is 00110, and the thousandth and ten thousandths are both 1, then it can be determined that the right search range includes the decimal leading value.
- the second search unit 1033 is specifically configured to determine the second exponent offset value according to the right position information closest to the initial position in the right position information C j ; the initial position is the decimal point position of the target fixed-point data; The numerical value is compared with the leading decimal value, and the second exponent offset value can be determined according to the comparison result.
- the second exponent offset value of the target fixed-point data 0.00110 is -3.
- the fixed-point and floating-point converter includes at least two floating-point precision formats, and the at least two floating-point precision formats include floating-point precision format A n and floating-point precision format A n+1 , where n is a positive integer .
- FIG. 1 c is a schematic structural diagram of a floating-point module provided by an embodiment of the present application.
- the floating-point module 104 may include: a mantissa truncation unit 1041, an exponent encoding unit 1042, and a floating-point generating unit 1043, wherein,
- the mantissa interception unit 1041 is used to obtain the first index offset value for the integer lead value output by the left search module if the left search module searches for an integer leading value, according to the target fixed-point data and the first index offset value, Truncate the first mantissa data for the target fixed-point data.
- the target fixed-point data 100.0011 can be converted into a floating point number 1.000011*2 2
- the first mantissa data is 1.000011. It should be noted that when storing the first mantissa data, the 1 in the single digit will be rounded off by default, only Save 000011.
- the exponent coding unit 1042 is configured to obtain the first exponent offset value for the integer leading value output by the left-hand search module if the integer leading value is searched by the left-hand search module, and obtain the standards corresponding to at least two floating-point precision formats respectively
- the offset value according to the first index offset value and the at least two standard offset values, respectively encodes at least two first target indices for the target fixed-point data.
- the target fixed-point data 100.0011 can be converted into a floating-point number 1.000011*2 2
- the first exponent offset value is 2
- the standard offset value is obtained.
- the standard offset value of a single-precision floating-point number is 127, then the floating-point number 1.000011 is stored *2 When 2 , the offset value actually stored is 127+2, and the first target index obtained by encoding is 10000001.
- This embodiment of the present application can generate at least one floating-point precision format, and when storing, can correspondingly store at least one floating-point number.
- the floating-point generating unit 1043 is configured to respectively generate at least two floating-point data corresponding to the target fixed-point data according to the sign bit corresponding to the target fixed-point data, at least two first target exponents and the first mantissa data; at least two floating-point data Including floating-point data Fn and floating-point data Fn+1 , wherein the floating-point precision format of the floating-point data Fn is the floating-point precision format An, and the floating-point precision format of the floating-point data Fn +1 is the floating-point precision format Precision format An+1 .
- the target fixed-point data 100.0011 can be converted into a floating-point number 1.000011*2 2 , and then according to the above-mentioned first mantissa data and the first target exponent, the binary form of the floating-point number 1.000011*2 2 is stored as 0100000010000110000000000000.
- the mantissa interception unit 1041 is further configured to obtain the second exponent offset value output by the right search module for the decimal leading value if the left search module does not search for an integer leading value, according to the target fixed-point data and the second exponent Offset value, intercept the second mantissa data for the target fixed-point data; for example, for the target fixed-point data 0.00110, the left search module cannot search for integer leading values, but the right search module can output the second exponent offset value (ie- 3), convert it into a floating-point number 1.10*2 -3 , and get the second mantissa data 1.10. Similarly, when storing the second mantissa data, the 1 on the single digit will be discarded by default, and only 10 will be saved.
- the exponent coding unit 1042 is further configured to obtain the second exponent offset value for the decimal leading value output by the right search module if the integer leading value is not searched by the left search module, and obtain at least two floating-point precision formats corresponding to The standard offset value of , according to the second index offset value and the at least two standard offset values, respectively encode at least two second target indices for the target fixed-point data; for example, for the target fixed-point data 0.00110, the left search module searches Less than an integer leading value, but the right search module can output the second exponent offset value (ie -3) to obtain the standard offset value.
- the standard offset value of a single-precision floating point number is 127, then store the floating point number 1.10* When 2-3, the offset value actually stored is 127-3, and the second target index obtained by encoding is 01111100 .
- This embodiment of the present application can generate at least one floating-point precision format, and when storing, can correspondingly store at least one floating-point number.
- the floating-point generating unit 1043 is further configured to generate at least two floating-point data corresponding to the target fixed-point data according to the sign bit, at least two second target exponents, and second mantissa data corresponding to the target fixed-point data; at least two floating-point numbers
- the data includes floating-point data Dn and floating-point data Dn+1 , wherein the floating-point precision format of the floating-point data Dn is the floating-point precision format An, and the floating-point precision format of the floating-point data Dn +1 is the floating-point precision format Point precision format A n+1 .
- the mantissa truncation unit 1041 and the exponent encoding unit 1042 it can be known that the binary form of the floating-point number 1.10*2-3 stored is 00111110010000000000000000000 .
- the fixed-point-to-floating-point converter in the embodiment of the present application is provided with an input module, a left-directed search module, a right-directed search module, and a floating-point module, and the target fixed-point data inside or outside the fixed-point to floating-point converter can be acquired through the input module, Input the target fixed-point data into the above-mentioned left-directed search module and the above-mentioned right-directed search module respectively, and the above-mentioned left-directed search module and right-directed search module are set in parallel, so the target fixed-point data can be simultaneously searched and converted into corresponding Exponential offset value of floating-point data, the specific process can be as follows: the left search module starts from the decimal point position of the target fixed-point data, and searches for integer leading values along the integer direction, and at the same time, the right search module starts from the decimal point position of the target fixed-point data.
- the decimal leading value is searched in the decimal direction; if the left-hand search module searches for an integer leading value, the floating-point module can obtain the first exponent offset value output by the left-hand search module for the integer leading value.
- the sign bit corresponding to the fixed-point data and the first exponent offset value generate floating-point data corresponding to the target fixed-point data; if the left-hand search module does not search for an integer leading value, the floating-point module uses the sign bit and the first index corresponding to the target fixed-point data.
- the second exponent offset value is used to generate floating-point data corresponding to the target fixed-point data.
- the second exponent offset value refers to the exponent offset value for the decimal leading value output by the right search module.
- the index offset value (including the first index offset value and the second index offset value) can be searched in parallel through the above-mentioned left-direction search module and right-direction search module, and the parallel search can improve the acquisition index.
- the speed of the offset value, and the parallel search can satisfy different types of target fixed-point data, which improves the versatility of converting fixed-point data to floating-point data, thereby improving the efficiency of data operations.
- FIG. 2 is a schematic structural diagram of a fixed-point to floating-point converter provided by an embodiment of the present application.
- the fixed-point and floating-point converter may include: a format conversion module 201, an input module 202, a left search module 204, a right search module 205 and a floating point module 206, wherein,
- the format conversion module 201 is used to obtain the fixed-point data to be processed, obtain the initial sign bit of the fixed-point data to be processed, and convert the fixed-point data to be processed that does not include the initial sign bit into binary fixed-point data;
- the format conversion module 201 is further configured to convert the binary fixed-point data according to the initial sign bit, generate target fixed-point data, and determine the initial sign bit as the sign bit corresponding to the target fixed-point data.
- the format conversion module 201 is specifically used to determine the binary fixed-point data as the target fixed-point data if the polarity of the initial sign bit is 0, and is specifically used to complement the binary fixed-point data if the polarity of the initial sign bit is 1. Code processing is performed to obtain binary fixed-point data after complement processing, and the binary fixed-point data after complement processing is determined as target fixed-point data.
- the format conversion module 201 is further specifically configured to receive the abnormally adjusted binary fixed-point data sent by the abnormality adjustment module, and perform conversion processing on the abnormally adjusted binary fixed-point data to generate target fixed-point data.
- the specific process can be as follows: if the polarity of the initial sign bit is 0, the abnormally adjusted binary fixed-point data is determined as the target fixed-point data; if the polarity of the initial sign bit is 1, the abnormally adjusted binary fixed-point data is processed. Complement processing, to obtain binary fixed-point data after the complement processing, and determine the binary fixed-point data after the complement processing as the target fixed-point data.
- FIG. 3 a is a schematic diagram of converting fixed-point data to floating-point data according to an embodiment of the present application.
- the fixed-point data 1011.11 is input into the format conversion module 201, and the format conversion module determines that the sign bit S is 1 (ie, negative) according to the polarity of the fixed-point data 1011.11.
- FIG. 3b is a schematic diagram of a scenario of fixed-point data format conversion provided by an embodiment of the present application.
- D in Figure 3b represents the fixed-point data to be processed
- "1'b0" indicates that the sign bit S is
- "1'b1" indicates that the sign bit S is 1.
- floating-point numbers in different floating-point precision formats may also be input to the format conversion module 201, and the format conversion module 201 may convert the floating-point numbers into an internal general floating-point precision format.
- the input module 202 is configured to acquire target fixed-point data, and input the target fixed-point data into the left search module 204 and the right search module 205 respectively.
- the target fixed-point data refers to a binary number that does not carry a sign bit, and the binary number may be a pure integer, a pure decimal, or an integer that carries a decimal, such as 10001, 0.111, and 1001.11.
- the input module 202 and the format conversion module 201 described above can be combined into one module.
- the left search module 204 is used to search for integer leading values along the integer direction starting from the decimal point position of the target fixed-point data.
- the integer leading value refers to the highest bit 1 of the integer part.
- the format conversion module 201 (here, the input module 201 and the format conversion module 202 are combined into one module, that is, the format conversion module 201), converts the The target fixed-point data 100.01 is input to the left search module 204 and the right search module 205.
- the left search module 204 performs a left-to-decimal shift to the target fixed-point data 100.01 by 2 digits to obtain 1.0001*2 2 , then the order code is added 2.
- the right search module 205 performs a decimal point shift to the right of the target fixed-point data 100.01, which can be shifted by 2 bits to obtain 10001.*2 -2 , then the exponent is subtracted by 2,
- the second exponent offset value may be determined to be equal to -2.
- the right search module 205 is configured to start from the position of the decimal point of the target fixed-point data, and to search for the leading value of the decimal along the decimal direction.
- FIG. 3c is a schematic diagram of converting fixed-point data to floating-point data according to an embodiment of the present application. As shown in Figure 3c, the fixed-point data to be processed is [(1/32)+(1/64)+(1/128)].
- the left search module 204 and the right search module 205 may search for the index offset value (including the above-mentioned first index offset value and second index offset value) of the target fixed-point data in parallel. Search in parallel in each direction, and the speed of obtaining the exponential offset value is greatly improved. It should be understood that the input target fixed-point data has different formats, and the choice of left-direction search and right-direction search can also greatly improve the versatility.
- the floating-point module 206 includes at least two floating-point precision formats, and the at least two floating-point precision formats include floating-point precision format A n and floating-point precision format A n+1 , where n is a positive integer.
- the floating-point module 206 is configured to obtain the first exponent offset value for the integer leading value output by the left-hand search module if the integer leading value is searched by the left-hand search module, according to the sign bit and the first exponent corresponding to the target fixed-point data Offset value to generate floating-point data corresponding to the target fixed-point data.
- the floating-point module 206 is further configured to obtain the second exponent offset value for the fractional leading value output by the right-directed search module if the integer leading value is not searched by the left-directed search module, according to the sign bit and the first index corresponding to the target fixed-point data. Two-exponential offset value to generate floating-point data corresponding to the target fixed-point data.
- the floating-point data mentioned in the embodiments of this application generally refers to standard floating-point data, and the standard floating-point number format is:
- V (-1) S ⁇ M ⁇ 2 E (1)
- S represents the sign bit, which is the same as the sign bit corresponding to the target fixed-point data.
- the embodiments of the present application can support output in any floating-point precision format, including but not limited to formats defined by the Institute of Electrical and Electronics Engineers (IEEE) standards, such as double-precision floating-point, that is, double, float point64 (FP64 ), single-precision floating point, namely FP32, half-precision, namely FP16, etc.; also includes non-standard custom formats, including but not limited to BP16.
- IEEE Institute of Electrical and Electronics Engineers
- the floating-point module 206 may include a parallel generator 2061, a parallel generator 2062, a parallel generator 2063, ..., a parallel generator 206k, where k is a positive integer, a parallel generator 2061, a parallel generator 2062, a parallel
- the generators 2063, . . . , and the parallel generators 206k correspond to different floating-point precision formats. For example, if the floating-point precision format corresponding to the parallel generator 2061 is a single-precision format, the generated floating-point 1 is single-precision floating-point data.
- the single-precision floating-point data is stored in the single-precision data unit 2071 of the floating-point format selection module 207; the floating-point precision format corresponding to the parallel generator 2062 is double-precision format, then the generated floating-point 2 is double-precision floating-point data, and the The double-precision floating-point data is stored in the double-precision data unit 2072 of the floating-point format selection module 207, and the same is true for other parallel generators, which will not be repeated here.
- the target fixed-point data can generate at least one floating-point data.
- a floating-point number is to divide all binary bits of a continuous byte of a specific length into a sign field, an exponent field, and a mantissa field of a specific width.
- the values in the fields are used to represent the sign, The exponent and mantissa, so that the given value can be expressed by the mantissa and the adjustable exponent.
- the embodiments of the present application introduce two basic floating-point formats: single-precision and double-precision.
- the single-precision format has 24 significant digits (that is, the mantissa) precision, occupying a total of 32 bits.
- the mantissa occupies 23 bits; the double-precision format has 53 significant digits (ie, the mantissa) precision.
- the mantissa occupies 52 bits, as shown in Table 3:
- the embodiment of the present application takes the parallel generator 2061 as an example for description, and other parallel generators can generate floating-point numbers in their corresponding formats according to the following process.
- the left search module 204 can transmit the first exponent offset value to the floating point module 206 .
- the floating-point module 206 may include an exponent encoding unit, a mantissa truncating unit, and a floating-point generating unit.
- the exponent encoding unit obtains the first exponent offset value (that is, 2), and the single-precision standard offset value, as shown in Table 1, the single-precision standard offset value is 127, and 129 (2+127) is binary-coded to obtain 1000 0001; the mantissa interception unit intercepts 1.0001*2 2 to obtain the mantissa 1.0001.
- the 1 of the single digit is rounded off, and only the decimal place is stored, that is, 0001.
- the right search module 205 After the right search module 205 obtains the second exponent offset value, it transmits the second exponent offset value to the floating-point module 206, and the exponent encoding unit obtains the second exponent offset value (ie- 5), and after the single-precision standard offset value, perform binary encoding on 122 (-5+127) to obtain 0111 1010; the mantissa interception unit obtains the mantissa 1.11, which is the same as the left search module 204.
- the right search module 205 stores , by default, 1 on the digit is discarded, 11 is stored, and then 0 is added.
- the floating point generation unit obtains the binary 0011111011000000000000000000000 as shown in Figure 3c.
- the fixed-point to floating-point converter may further include an exception adjustment module 203, wherein,
- Abnormal adjustment module 203 for performing data state detection on binary fixed-point data
- the abnormality adjustment module 203 is also used to notify the format conversion module to perform conversion processing on the binary fixed-point data according to the initial symbol bit, and generate target fixed-point data if the data state of the binary fixed-point data is a normal data state;
- the abnormality adjustment module 203 is further configured to perform abnormal adjustment on the binary fixed-point data if the data state of the binary fixed-point data is a data abnormality state, and notify the format conversion module to perform conversion processing on the abnormally adjusted binary fixed-point data according to the initial symbol bit, and generate Target fixed-point data.
- the format conversion module 201 not only transmits the target fixed-point data to the input module 201, but also outputs the target fixed-point data to the abnormality adjustment module 203 to determine whether the target fixed-point data is abnormal.
- the abnormality adjustment module 203 can Exception processing is performed in the exception mode, and the control information is returned to the format conversion module 201 . Recalling the examples in Figure 3a and Figure 3c, when converting decimal to binary, accurate results can be obtained, but in practical applications, when many real numbers are converted to binary, accurate results cannot be obtained, but rounded results.
- the left search module 204 or the right search module 205 inputs the searched exponent offset value to the abnormal adjustment module. 203. If the order code corresponding to the exponent offset value exceeds the maximum positive number that the order code can represent, it is an overflow.
- the floating-point number is a positive number at this time, it is a positive overflow, denoted as + ⁇ , If the floating-point number is negative, it is a negative overflow, recorded as - ⁇ ; if the value of the order code exceeds the minimum negative number that the order code can represent, it is an underflow, and further, if the floating-point number is positive at this time, then It is a positive underflow, or a negative underflow if the floating-point number is negative, which must be rounded.
- Rounding towards - ⁇ (round toward- ⁇ ): It is just the opposite of the rounding method towards + ⁇ . For positive numbers, it is simply rounded; for negative numbers, as long as the extra bits are not all 0, then Advance 1 to the least significant bit of the mantissa.
- the embodiment of the present application can also allow a user to define a rounding method for exception handling.
- the abnormality adjustment module 203 specifies the processing method when an abnormality occurs, including but not limited to the rounding mode and the data interception method, so that the error can be minimized, and more importantly, it can adapt to the requirements of different application scenarios for errors. .
- the fixed-point to floating-point converter may further include a floating-point format selection module 207, wherein,
- the floating-point format selection module 207 is used to obtain a data conversion instruction for target fixed-point data; the data conversion instruction carries a target floating-point precision format, and at least two floating-point precision formats include the target floating-point precision format;
- the floating-point format selection module 207 is further configured to determine target floating-point data from at least two floating-point data according to the target floating-point precision format, and output the target floating-point data; the floating-point precision format of the target floating-point data is the target Floating-point precision format.
- the floating-point and floating-point converter described in this embodiment of the present application can generate at least one kind of floating-point data.
- the single-precision data unit. 2071 stores the single-precision floating-point data corresponding to the target fixed-point data
- the double-precision data unit 2072 stores the double-precision floating-point data corresponding to the target fixed-point data
- other floating-point precision format units also store the corresponding floating-point data, respectively.
- the fixed-point to floating-point converter can output the target floating-point data according to the target floating-point precision format indicated in the data conversion instruction.
- the fixed-point to floating-point converter can perform targeted conversion of the to-be-processed fixed-point data according to the target floating-point precision format, Only target floating-point data corresponding to the target floating-point precision format is generated.
- the fixed-point and floating-point converter in the embodiment of the present application is provided with a format conversion module, an input module, a left search module, a right search module, an exception adjustment module, a floating point module, and a floating point format selection module.
- a format conversion module Process fixed-point data and realize any data format conversion, which can be a general format or a customized private format, to meet the special requirements of customization, and output the floating-point data sign bit result at the same time.
- the output of the format conversion module is respectively input to the left search module and the right search module through the input module.
- the above left search module and right search module are set in parallel, so the target fixed-point data can be searched and converted into corresponding ones.
- Exponential offset value of floating-point data, and the input target fixed-point data has different formats
- selecting left search and right search can also greatly improve the versatility
- the format conversion module can also be connected with the abnormal adjustment module to detect conversion Whether there is any abnormality in the binary number of the , the error can be minimized through the abnormal adjustment module, and more importantly, it can adapt to the error requirements of different application scenarios.
- the above-mentioned left search module (right search module is also possible) can also be combined with The abnormality adjustment module is connected to detect whether there is abnormality in the order number.
- the embodiment of the present application can improve the speed of obtaining the exponential offset value through the parallel search of the above-mentioned left-direction search module and right-direction search module, and can satisfy different types of target fixed-point data, that is, the conversion of fixed-point data to floating-point numbers can be improved.
- the versatility of data can further improve the efficiency of data operations.
- fixed-point and floating-point converters are widely used in computer science, communication, artificial intelligence and other fields.
- the well-known GPU, CPU, Field Programmable Gate Array (FPGA) or large-scale artificial intelligence (Artificial Intelligence, AI) chip contains several fixed-point and floating-point converters, which is a basic components, the importance of which is clearly visible.
- FIG. 4 is a fixed-point to floating-point graphics processor provided by an embodiment of the present application.
- the fixed-point to floating-point graphics processor may include an on-chip/off-chip storage unit 401, a pre-processing module 402, a fixed-point to floating-point general module 403, a floating-point arithmetic unit 404, and a post-processing unit 405, wherein ,
- On-chip/off-chip storage unit 401 for storing fixed-point data to be processed
- the pre-processing module 402 is configured to obtain the to-be-processed fixed-point data stored in the data memory according to the data operation instruction when the data operation instruction for the to-be-processed fixed-point data is obtained, perform data preprocessing on the to-be-processed fixed-point data, and obtain the target fixed-point data ;
- Data operation instructions carry the target floating-point precision format;
- the fixed-point to floating-point general module 403 is used to perform data format conversion on the target fixed-point data transmitted by the first processor, and generate floating-point data corresponding to the target floating-point precision format; wherein, the fixed-point to floating-point converter 403 includes Fig. 1a- Figure 1c and the device described in Figure 2;
- a floating-point operation unit 404 configured to perform floating-point operation on floating-point data, and generate floating-point data after the floating-point operation;
- the post-processing unit 405 is configured to transmit the floating-point data after the floating-point operation to the on-chip/off-chip storage unit 401, so that the on-chip/off-chip storage unit 401 stores the floating-point data after the floating-point operation.
- the data is first extracted from the on-chip/off-chip storage unit 401, and then the pre-processing module 402 performs the following steps: After format conversion, noise reduction and other processing, the fixed-point data is obtained, and then the fixed-point to floating-point conversion is completed by the fixed-point to floating-point general module 403. After conversion, it is sent to the floating-point operation unit 404 to complete various floating-point operations, and finally passes through the post-processing module 405. Write the result back to the on-chip/off-chip memory location.
- the fixed-point to floating-point graphics processor can ensure the calculation accuracy, and also improve the versatility and flexibility for different applications and product requirements.
- FIG. 5 is a fixed-point to floating-point central processing unit provided by an embodiment of the present application.
- the fixed-point to floating-point central processing unit may include an instruction fetch module 501, a decoding module 502, and a fixed-point to floating-point module 503, wherein,
- an instruction fetching module 501 used to obtain an operation instruction
- the decoding module 502 is configured to perform decoding processing on the operation instruction obtained by the instruction fetch module to obtain the decoded operation instruction; the decoded operation instruction is used to represent the floating-point operation on the fixed-point data to be processed;
- the fixed-point to floating-point module 503 is used to obtain the fixed-point data to be processed according to the decoded operation instruction, perform data format conversion on the fixed-point data to be processed, obtain floating-point data corresponding to the fixed-point data to be processed, and perform floating-point operations on the floating-point data ; wherein, the fixed-point to floating-point module includes the devices shown in Fig. 1a-Fig. 1c and Fig. 2 .
- the instruction fetch module of the fixed-point to floating-point central processing unit fetches an instruction, it first passes through the decoding module. Conversion to floating point data.
- the central processing unit including the fixed-point to floating-point module can not only ensure the calculation accuracy, but also improve the versatility and flexibility for different applications and product requirements.
- FIG. 6 is a fixed-point to floating-point conversion method provided by an embodiment of the present application.
- the fixed-point to floating-point conversion method can be performed by the fixed-point to floating-point converters mentioned above in FIG. 1a or FIG. 2 .
- the fixed-point and floating-point conversion method may include the following steps S601-S605:
- Step S601 acquiring target fixed-point data, and inputting the target fixed-point data into the left search module and the right search module respectively.
- the fixed-point data to be processed is obtained, and the fixed-point data to be processed is input into the format conversion module; in the format conversion module, the initial sign bit of the fixed-point data to be processed is obtained, and the fixed-point data to be processed that does not include the initial sign bit is converted into binary Fixed-point data; the binary fixed-point data is converted according to the initial sign bit to generate target fixed-point data, and the initial sign bit is determined as the sign bit corresponding to the target fixed-point data.
- Convert the binary fixed-point data according to the initial sign bit to generate target fixed-point data including: if the polarity of the initial sign bit is 0, then determining the binary fixed-point data as the target fixed-point data, if the polarity of the initial sign bit is 1, Then, perform complement processing on the binary fixed-point data to obtain binary fixed-point data after complement processing, and determine the binary fixed-point data after complement processing as target fixed-point data.
- Step S602 in the left search module, starting from the decimal point position of the target fixed-point data, search for integer leading values along the integer direction.
- the left search range of the target fixed point data is obtained along the integer direction; the left search range includes the left start value, and the left start value refers to the left search range, The value closest to the decimal point of the target fixed-point data; traverse each left value in the left search range from the left start value along the integer direction; search for the integer leading value according to the left traversal result.
- the leftward traversal result includes the leftward value Z i , i is a positive integer, and i is less than or equal to the total number of leftward values in the leftward search range, and the leftward value Z i includes the leftward starting value; If none of the left value Z i in the result is equal to the default value, it is determined that the left search range does not include the integer leading value; the value of the integer leading value is equal to the default value; if there is a left value Z i in the left traversal result, it is equal to the default value , then it is determined that the leftward search range includes an integer leading value , and the leftward position information Li of the leftward value Z i equal to the default value is obtained; The first exponent offset value; the initial position is the decimal point position of the target fixed-point data.
- Step S603 in the right search module, start from the decimal point position of the target fixed-point data, and perform a decimal leading value search along the decimal direction.
- the right search range of the target fixed-point data is obtained along the decimal direction; the right search range includes the right start value, and the right start value refers to the right search range, The value closest to the decimal point of the target fixed-point data; traverse each right-directed value in the right-direction search range from the right-direction starting value in the decimal direction; search for the leading decimal value according to the right-direction traversal result.
- the rightward traversal result includes the rightward value Y j , where j is a positive integer, and j is less than or equal to the total number of rightward values in the rightward search range, and the rightward value Y j includes the rightward starting value; If the right value Y j in the result is not equal to the default value, it is determined that the right search range does not include the decimal leading value; the value of the decimal leading value is equal to the default value; if there is a right value Y j in the right traversal result, it is equal to the default value , then it is determined that the right search range includes the decimal leading value, and the right position information C j of the right value Y j equal to the default value is obtained; according to the right position information C j that is closest to the initial position, determine the Two-exponential offset value; the initial position is the decimal point position of the target fixed-point data.
- Step S604 if the left search module searches for the integer leading value, then obtain the first index offset value for the integer leading value output by the left search module, according to the symbol bit corresponding to the target fixed-point data and the first index offset value, Generate floating-point data corresponding to the target fixed-point data.
- Step S605 if the left search module does not search for an integer leading value, then obtain the second exponent offset value for the fractional leading value output by the right search module, according to the sign bit corresponding to the target fixed-point data and the second exponent offset value. , to generate floating-point data corresponding to the target fixed-point data.
- At least two standard offset values respectively encoding at least two second target exponents for target fixed-point data
- at least two floating-point precision formats include floating-point precision format A n and floating-point precision format A n+1 , where n is positive Integer
- the at least two floating-point data include floating-point data D n and the floating-point data D n+1 , wherein the floating-point precision format of the floating-point data D n is the floating-point precision format A n
- the floating-point precision format of the floating-point data D n+1 is the floating-point precision format A n+1 .
- the data conversion instruction carries the target floating-point precision format, and the at least two floating-point precision formats include the target floating-point precision format; according to the target floating-point precision format, it is determined from at least two floating-point data Target floating-point data, output the target floating-point data; the floating-point precision format of the target floating-point data is the target floating-point precision format.
- step S601 to step S605 is shown in the above-mentioned FIG. 1 a and FIG. 2 , which will not be repeated here.
- the index offset value (including the first index offset value and the second index offset value) can be searched in parallel through the above-mentioned left-direction search module and right-direction search module, and the parallel search can improve the acquisition index.
- the speed of the offset value, and the parallel search can satisfy different types of target fixed-point data, which improves the versatility of converting fixed-point data to floating-point data, thereby improving the efficiency of data operations.
- Embodiments of the present application further provide a computer-readable storage medium, where the computer-readable storage medium stores a computer program, the computer program includes program instructions, and when the program instructions are executed by a processor, implement the fixed point provided by each step in FIG. 6 .
- the computer-readable storage medium stores a computer program
- the computer program includes program instructions, and when the program instructions are executed by a processor, implement the fixed point provided by each step in FIG. 6 .
- the above-mentioned computer-readable storage medium may be the fixed-point-to-floating-point converter provided in any of the foregoing embodiments, or the above-mentioned fixed-point and floating-point conversion graphics processor, or the above-mentioned fixed-point and floating-point conversion
- the internal storage unit of the central processing unit For example the hard disk or memory of a computer device.
- the computer-readable storage medium can also be an external storage device of the computer device, such as a plug-in hard disk, a smart media card (smart media card, SMC), a secure digital (secure digital, SD) card equipped on the computer device, Flash card (flash card), etc.
- the computer-readable storage medium may also include both an internal storage unit of the computer device and an external storage device.
- the computer-readable storage medium is used to store the computer program and other programs and data required by the computer device.
- the computer-readable storage medium can also be used to temporarily store data that has been or will be output.
- each process and/or the schematic structural diagrams of the method flowcharts and/or structural schematic diagrams can be implemented by computer program instructions. or blocks, and combinations of processes and/or blocks in flowcharts and/or block diagrams.
- These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor or other programmable data processing device to produce a machine such that the instructions executed by the processor of the computer or other programmable data processing device produce a function
- These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory result in an article of manufacture comprising instruction means, the instructions
- the apparatus implements the functions specified in one or more of the flowcharts and/or one or more blocks of the structural diagram.
- These computer program instructions can also be loaded on a computer or other programmable data processing device to cause a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process such that The instructions provide steps for implementing the functions specified in one or more blocks of the flowchart and/or block or blocks of the block diagram.
Landscapes
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computational Mathematics (AREA)
- Mathematical Analysis (AREA)
- Mathematical Optimization (AREA)
- Pure & Applied Mathematics (AREA)
- Computing Systems (AREA)
- General Engineering & Computer Science (AREA)
- Complex Calculations (AREA)
Abstract
本申请实施例公开一种定点与浮点转换器、处理器、方法以及存储介质,定点与浮点转换器可以镶嵌于云服务器中,以提高云服务器中定点与浮点的转换速度,其中,输入模块将目标定点数据分别输入左向搜索模块和右向搜索模块;左向搜索模块从目标定点数据的小数点位置开始,沿整数方向进行整数前导值搜索;右向搜索模块从小数点位置开始,沿小数方向进行小数前导值搜索;若左向搜索模块搜索到整数前导值,浮点模块则获取第一指数偏移值,根据目标定点数据的符号位以及第一指数偏移值,生成浮点数据;若未搜索到整数前导值,浮点模块则获取第二指数偏移值,根据符号位以及第二指数偏移值生成浮点数据。
Description
本申请要求于2020年9月8日提交中国专利局、申请号为202010931697.X、发明名称为“一种定点与浮点转换器、处理器、方法以及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本申请涉及互联网技术领域,尤其涉及一种定点与浮点转换器、一种定点与浮点的图形处理器、一种定点与浮点的中央处理器、一种定点与浮点转换方法以及计算机可读存储介质。
发明背景
定点转浮点处理单元作为基本的数据处理单元,被广泛应用于计算机学、通讯、人工智能等多个领域。所熟知的图形处理器(Graphics Processing Unit,GPU)、中央处理器(central processing unit,CPU)、或者大规模人工智能(Artificial Intelligence,AI)芯片里均包含若干个定点转浮点处理单元,作为一个基础的组件,其重要性显然易见。
在现有技术中,定点转浮点处理单元需要设定定点数据的数据格式,例如纯小数或纯整数,则定点数据转浮点数据的首要条件是定点数据为特定格式,若定点数据的格式与预先规定的格式不同,就无法转换,可知应用时,现有技术的通用性不佳。
发明内容
本申请实施例提供了一种定点与浮点转换器、一种定点与浮点的图形处理器、一种定点与浮点的中央处理器、一种定点与浮点转换方法以及计算机可读存储介质,可以提高定点数据转浮点数据的通用性。
一方面,本申请实施例提供了一种定点与浮点转换器,定点与浮点转换器包括输入模块、左向搜索模块、右向搜索模块、浮点模块;
输入模块,用于获取目标定点数据,将目标定点数据分别输入左向搜索模块和右向搜索模块;
左向搜索模块,用于从目标定点数据的小数点位置开始,沿整数方向进行整数前导值搜索;
右向搜索模块,用于从目标定点数据的小数点位置开始,沿小数方向进行小数前导值搜索;
浮点模块,用于若左向搜索模块搜索到整数前导值,则获取左向搜索模块输出的针对整数前导值的第一指数偏移值,根据目标定点数据对应的符号位以及第一指数偏移值,生成目标定点数据对应的浮点数据;
浮点模块,还用于若左向搜索模块未搜索到整数前导值,则获取右向搜索模块输出的针对小数前导值的第二指数偏移值,根据目标定点数据对应的符号位以及第二指数偏移值,生成目标定点数据对应的浮点数据。
另一方面,本申请实施例提供了一种定点与浮点转换方法,该方法由上述的定点与浮点转换器来执行,方法包括:
获取目标定点数据,将目标定点数据输入左向搜索模块和右向搜索模块;
在左向搜索模块中,从目标定点数据的小数点位置开始,沿整数方向进行整数前导值搜索;
在右向搜索模块中,从目标定点数据的小数点位置开始,沿小数方向进行小数前导值搜索;
若左向搜索模块搜索到整数前导值,则获取左向搜索模块输出的针对整数前导值的第一指 数偏移值,根据目标定点数据对应的符号位以及第一指数偏移值,生成目标定点数据对应的浮点数据;
若左向搜索模块未搜索到整数前导值,则获取右向搜索模块输出的针对小数前导值的第二指数偏移值,根据目标定点数据对应的符号位以及第二指数偏移值,生成目标定点数据对应的浮点数据。
再一方面,本申请实施例提供了一种定点转浮点的图形处理器,该定点转浮点的图形处理器中包括有上述的定点与浮点转换器。
再一方面,本申请实施例提供了一种定点转浮点的中央处理器,该定点转浮点的中央处理器包括有上述的定点与浮点转换器。
附图简要说明
为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1a是本申请实施例提供的一种定点与浮点转换器的结构示意图;
图1b是本申请实施例提供的一种左向搜索模块的结构示意图;
图1c是本申请实施例提供的一种右向搜索模块的结构示意图;
图2是本申请实施例提供的一种定点与浮点转换器的结构示意图;
图3a是本申请实施例提供的一种定点数据转换成浮点数据的转换示意图;
图3b是本申请实施例提供的一种定点数据格式转换的场景示意图;
图3c是本申请实施例提供的一种定点数据转换成浮点数据的转换示意图;
图4是本申请实施例提供的一种定点转浮点的图形处理器;
图5是本申请实施例提供的一种定点转浮点的中央处理器;
图6是本申请实施例提供的一种定点与浮点转换方法。
实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
为了便于理解,首先对部分名词进行以下简单解释:
1、芯片:指内含集成电路的硅片,体积很小,常常是计算机或其他电子设备的重要组成部分。
2、定点数:小数点固定的数,可以表示整数,小数,例如5,2.13。
3、浮点数:小数点非固定的数,可以表示的数据范围广,包含单精度数,双精度数等,浮点数利用科学计数法来表达实数,即用一个尾数(Mantissa),一个基数(Base),一个指数(Exponent)以及一个表示正负的符号来表达实数。例如123.45用十进制科学计数法可以表示为1.2345×10
2,其中1.2345为尾数,10为基数,2为指数,还可以表示为12.345×10,其中12.345为尾数,10为基数,1为指数。浮点数利用指数达到了浮动小数点的效果,从而可以灵活地表达更大范围的实数。
4、中央处理器(central processing unit,CPU)作为计算机系统的运算和控制核心,是信息处理、程序运行的最终执行单元。
5、图形处理器(Graphics Processing Unit,GPU),又称显示核心、视觉处理器、显示芯片,是一种专门在个人电脑、工作站、游戏机和一些移动设备(如平板电脑、智能手机等)上做图像和图形相关运算工作的微处理器。
请参见图1a,图1a是本申请实施例提供的一种定点与浮点转换器的结构示意图。如图1a所示,定点与浮点转换器可以包括:输入模块101、左向搜索模块102、右向搜索模块103、浮点模块104,其中,
输入模块101,用于获取目标定点数据,将目标定点数据分别输入左向搜索模块和右向搜索模块。
具体的,目标定点数据是指未携带符号位的二进制数,该二进制数可以是纯整数、纯小数以及携带小数的整数,例如10001、0.111、1001.11。未携带符号位的10001表示的十进制数为17,十进制数-15亦可以用二进制数10001表示,此时,二进制数10001中最高位的1表示该二进制数为负数。
左向搜索模块102,用于从目标定点数据的小数点位置开始,沿整数方向进行整数前导值搜索。
具体的,整数前导值是指整数部分最高位的1,根据输入的目标定点数据的小数点位置,左向搜索模块102向左(即整数方向)快速搜索找到整数前导值的位置,并确定整数前导值相对于目标定点数据的小数点位置所对应的位置信息。例如目标定点数据为1001.11,左向搜索模块102向左搜索整数前导值,可以确定整数前导值位于千位上,那么整数前导值的位置信息为向左偏移3。
右向搜索模块103,用于从目标定点数据的小数点位置开始,沿小数方向进行小数前导值搜索。
具体的,小数前导值是指小数部分最高位的1,根据输入的目标定点数据的小数点位置,右向搜索模块103向右(即小数方向)快速搜索找到小数前导值的位置,并确定小数前导值相对于目标定点数据的小数点位置所对应的位置信息。例如目标定点数据为0.011,右向搜索模块103向右搜索小数前导值,可以确定小数前导值位于百分位上,那么小数前导值的位置信息为向右偏移2。
浮点模块104,用于若左向搜索模块搜索到整数前导值,则获取左向搜索模块输出的针对整数前导值的第一指数偏移值,根据目标定点数据对应的符号位以及第一指数偏移值,生成目标定点数据对应的浮点数据。
浮点模块104,还用于若左向搜索模块未搜索到整数前导值,则获取右向搜索模块输出的针对小数前导值的第二指数偏移值,根据目标定点数据对应的符号位以及第二指数偏移值,生成目标定点数据对应的浮点数据。
在一种实施方式中,请一并参见图1b,图1b是本申请实施例提供的一种左向搜索模块的结构示意图。如图1b所示,左向搜索模块102可以包括左向获取单元1021、第一遍历单元1022以及第一搜索单元1023,其中,
左向获取单元1021,用于从目标定点数据的小数点位置开始,沿整数方向获取目标定点数据的左向搜索范围;左向搜索范围包括左向起始数值,左向起始数值是指在左向搜索范围中,与目标定点数据的小数点距离最近的数值。
具体的,首先获取搜索的起始位置,即目标定点数据的小数点位置,从起始位置的左边得到左向搜索范围,例如目标定点数据100.001的左向搜索范围为100。
第一遍历单元1022,用于从左向起始数值开始沿整数方向,对左向搜索范围内的每个左向数值进行遍历。
第一搜索单元1023,用于根据左向遍历结果搜索整数前导值。
具体的,由左向获取单元1021可知,目标定点数据100.001的左向搜索范围为100,左向数值包括1、0以及0,将每个左向数值与整数前导值进行对比,根据对比结果可以确定第一指数偏移值,目标定点数据100.001的第一指数偏移值为2。
上述可知,遍历每个左向数值,即可确定第一指数偏移值,左向获取单元1021、第一遍历单元1022以及第一搜索单元1023的实现过程的示例代码可以参见表1:
表1
其中,data[start1]表示左向起始数值,index表示整数前导值(即1)。
在一种实施方式中,左向遍历结果包括左向数值Z
i,i为正整数,且i小于或等于左向搜索范围中的左向数值的总数量,左向数值Z
i包括左向起始数值;其中,
第一搜索单元1023,具体用于若左向遍历结果中的左向数值Z
i均不等于默认数值,则确定左向搜索范围不包括整数前导值;整数前导值的数值等于默认数值。例如,目标定点数据0.0011中的左向搜索范围不包括整数前导值(即1),则第一搜索单元1023可以确定左向搜索范围不包括整数前导值。
第一搜索单元1023,具体用于若左向遍历结果中存在左向数值Z
i等于默认数值,则确定左向搜索范围包括整数前导值,获取等于默认数值的左向数值Z
i的左向位置信息L
i;例如,目标定点数据100.0011中的左向搜索范围包括100,且百位上是1,则第一搜索单元1023可以确定左向搜索范围包括整数前导值,获取左向数值Z
3的左向位置信息(即百位位置)。
第一搜索单元1023,具体用于根据左向位置信息L
i中距离初始位置最远的左向位置信息,确定第一指数偏移值;初始位置为目标定点数据的小数点位置;目标定点数据100.0011的第一指数偏移值为2,得到浮点数1.000011*2
2。
在一种实施方式中,请一并参见图1c,图1c是本申请实施例提供的一种右向搜索模块的结构示意图。如图1c所示,右向搜索模块103可以包括右向获取单元1031、第二遍历单元1032以及第二搜索单元1033,其中,
右向获取单元1031,用于从目标定点数据的小数点位置开始,沿小数方向获取目标定点数据的右向搜索范围;右向搜索范围包括右向起始数值,右向起始数值是指在右向搜索范围中,与目标定点数据的小数点距离最近的数值。
具体的,首先获取搜索的起始位置,即目标定点数据的小数点位置,从起始位置的右边得到右向搜索范围,例如目标定点数据0.00110的右向搜索范围为00110。
第二遍历单元1032,用于从右向起始数值开始沿小数方向,对右向搜索范围内的每个右向数值进行遍历。
第二搜索单元1033,用于根据右向遍历结果搜索小数前导值。
具体的,由右向获取单元1031可知,目标定点数据0.00110的右向搜索范围为00110,将每个右向数值与小数前导值进行对比,根据对比结果可以确定第二指数偏移值,目标定点数据0.00110的第二指数偏移值为-3。
上述可知,遍历每个右向数值,即可确定第二指数偏移值,右向获取单元1031、第一遍历单元1032以及第一搜索单元1033的实现过程的示例代码可以参见表2:
表2
其中,data[start2]表示右向起始数值,index表示小数前导值(即1)。
在一种实施方式中,右向遍历结果包括右向数值Y
j,j为正整数,且j小于或等于右向搜 索范围中的右向数值的总数量,右向数值Y
j包括右向起始数值;其中,
第二搜索单元1033,具体用于若右向遍历结果中的右向数值Y
j均不等于默认数值,则确定右向搜索范围不包括小数前导值;小数前导值的数值等于默认数值;例如,目标定点数据1100不存在右向搜索范围,或者说右向搜索范围为0,即不包括小数前导值(即1)。
第二搜索单元1033,具体用于若右向遍历结果中存在右向数值Y
j等于默认数值,则确定右向搜索范围包括小数前导值,获取等于默认数值的右向数值Y
j的右向位置信息C
j;目标定点数据0.00110的右向搜索范围为00110,且千分位以及万分位均为1,则可以确定右向搜索范围包括小数前导值。
第二搜索单元1033,具体用于根据右向位置信息C
j中距离初始位置最近的右向位置信息,确定第二指数偏移值;初始位置为目标定点数据的小数点位置;将每个右向数值与小数前导值进行对比,根据对比结果可以确定第二指数偏移值,目标定点数据0.00110的第二指数偏移值为-3。
在一种实施方式中,定点与浮点转换器包括至少两种浮点精度格式,至少两种浮点精度格式包括浮点精度格式A
n以及浮点精度格式A
n+1,n为正整数。请一并参见图1c,图1c是本申请实施例提供的一种浮点模块的结构示意图。如图1c所示,浮点模块104可以包括:尾数截取单元1041、指数编码单元1042以及浮点生成单元1043,其中,
尾数截取单元1041,用于若左向搜索模块搜索到整数前导值,则获取左向搜索模块输出的针对整数前导值的第一指数偏移值,根据目标定点数据以及第一指数偏移值,截取针对目标定点数据的第一尾数数据。例如,目标定点数据100.0011可以转化为浮点数1.000011*2
2,得到第一尾数数据为1.000011,需要注意的是,在存储第一尾数数据时,会将个位数上的1默认舍去,只保存000011。
指数编码单元1042,用于若左向搜索模块搜索到整数前导值,则获取左向搜索模块输出的针对整数前导值的第一指数偏移值,获取至少两种浮点精度格式分别对应的标准偏移值,根据第一指数偏移值以及至少两个标准偏移值,分别编码针对目标定点数据的至少两个第一目标指数。例如,目标定点数据100.0011可以转化为浮点数1.000011*2
2,得到第一指数偏移值为2,获取标准偏移值,例如单精度浮点数的标准偏移值为127,那么存储浮点数1.000011*2
2时,实际存储的偏移值为127+2,编码得到的第一目标指数为10000001。本申请实施例可以生成至少一种浮点精度格式,存储时,可以对应存储至少一种浮点数。
浮点生成单元1043,用于根据目标定点数据对应的符号位、至少两个第一目标指数以及第一尾数数据,分别生成目标定点数据对应的至少两个浮点数据;至少两个浮点数据包括浮点数据F
n以及浮点数据F
n+1,其中,浮点数据F
n的浮点精度格式为浮点精度格式A
n,浮点数据F
n+1的浮点精度格式为浮点精度格式A
n+1。例如,目标定点数据100.0011可以转化为浮点数1.000011*2
2,再根据上述的第一尾数数据以及第一目标指数,存储浮点数1.000011*2
2的二进制形式为01000000100001100000000000000000。
其中,尾数截取单元1041,还用于若左向搜索模块未搜索到整数前导值,则获取右向搜索模块输出的针对小数前导值的第二指数偏移值,根据目标定点数据以及第二指数偏移值,截取针对目标定点数据的第二尾数数据;例如,对于目标定点数据0.00110,左向搜索模块搜索不到整数前导值,但右向搜索模块可以输出第二指数偏移值(即-3),转化成浮点数1.10*2
-3,得到第二尾数数据1.10,同理,在存储第二尾数数据时,会将个位数上的1默认舍去,只保存10。
指数编码单元1042,还用于若左向搜索模块未搜索到整数前导值,则获取右向搜索模块输出的针对小数前导值的第二指数偏移值,获取至少两种浮点精度格式分别对应的标准偏移值,根据第二指数偏移值以及至少两个标准偏移值,分别编码针对目标定点数据的至少两个第二目标指数;例如,对于目标定点数据0.00110,左向搜索模块搜索不到整数前导值,但右向搜索模块可以输出第二指数偏移值(即-3),获取标准偏移值,例如单精度浮点数的标准偏移值为127,那么存储浮点数1.10*2
-3时,实际存储的偏移值为127-3,编码得到的第二目标指数为01111100。本申请实施例可以生成至少一种浮点精度格式,存储时,可以对应存储至少一种浮点数。
浮点生成单元1043,还用于根据目标定点数据对应的符号位、至少两个第二目标指数以及第二尾数数据,分别生成目标定点数据对应的至少两个浮点数据;至少两个浮点数据包括浮点数据D
n以及浮点数据D
n+1,其中,浮点数据D
n的浮点精度格式为浮点精度格式A
n,浮点数 据D
n+1的浮点精度格式为浮点精度格式A
n+1。由尾数截取单元1041以及指数编码单元1042所述,可知存储浮点数1.10*2
-3的二进制形式为00111110010000000000000000000000。
本申请实施例中的定点与浮点转换器设置有输入模块、左向搜索模块、右向搜索模块、浮点模块,通过输入模块可以获取定点与浮点转换器内部或外部的目标定点数据,将该目标定点数据分别输入上述的左向搜索模块以及上述的右向搜索模块,上述的左向搜索模块以及右向搜索模块是并行设置的,因此可以同时搜索目标定点数据转换成与之对应的浮点数据的指数偏移值,具体过程可以如下:左向搜索模块从目标定点数据的小数点位置开始,沿整数方向进行整数前导值搜索,同时,右向搜索模块从目标定点数据的小数点位置开始,沿小数方向进行小数前导值搜索;若左向搜索模块搜索到整数前导值,那么浮点模块可以获取到左向搜索模块输出的针对整数前导值的第一指数偏移值,则可以根据目标定点数据对应的符号位以及第一指数偏移值,生成目标定点数据对应的浮点数据;若左向搜索模块未搜索到整数前导值,那么浮点模块根据目标定点数据对应的符号位以及第二指数偏移值,生成目标定点数据对应的浮点数据,第二指数偏移值是指右向搜索模块所输出的针对小数前导值的指数偏移值。上述可知,本申请实施例通过上述的左向搜索模块以及右向搜索模块,可以并行搜索指数偏移值(包括第一指数偏移值以及第二指数偏移值),并行搜索可以提高获取指数偏移值的速度,且并行搜索可以满足不同类型的目标定点数据,提高了定点数据转浮点数据的通用性,进而可以提高数据运算的效率。
基于上述的描述,请参见图2,图2是本申请实施例提供的一种定点与浮点转换器的结构示意图。如图2所示,定点与浮点转换器可以包括:格式转换模块201、输入模块202、左向搜索模块204、右向搜索模块205以及浮点模块206,其中,
格式转换模块201,用于获取待处理定点数据,获取待处理定点数据的初始符号位,将未包括初始符号位的待处理定点数据转换为二进制定点数据;
格式转换模块201,还用于根据初始符号位对二进制定点数据进行转换处理,生成目标定点数据,将初始符号位确定为目标定点数据对应的符号位。
格式转换模块201,具体用于若初始符号位的极性为0,则将二进制定点数据确定为目标定点数据,且具体用于若初始符号位的极性为1,则对二进制定点数据进行补码处理,得到补码处理之后的二进制定点数据,将补码处理之后的二进制定点数据确定为目标定点数据。
格式转换模块201,还具体用于接收异常调整模块发送的异常调整后的二进制定点数据,对异常调整后的二进制定点数据进行转换处理,生成目标定点数据。具体过程可以为:若初始符号位的极性为0,则将异常调整后的二进制定点数据确定为目标定点数据,若初始符号位的极性为1,则对异常调整后的二进制定点数据进行补码处理,得到补码处理之后的二进制定点数据,将补码处理之后的二进制定点数据确定为目标定点数据。
将待处理定点数据输入格式转换模块201,实现任意数据格式转换,可以是通用格式或者自定义的私有格式,以满足定制型特殊要求,同时输出浮点数据符号位结果。请一并参见图3a,图3a是本申请实施例提供的一种定点数据转换成浮点数据的转换示意图。如图3a所示,将定点数据1011.11输入格式转换模块201,格式转换模块根据定点数据1011.11的极性,确定符号位S为1(即负),由于待处理定点数据为负,所以对二进制数1011.11进行补码处理,首先获取二进制数1011.11的反码,然后在末位加1得到其对应的补码,然后去除补码之后的二进制数的符号位,如图3a所示,得到去除符号位的目标定点数据100.01。上述过程还可以一并参见图3b,图3b是本申请实施例提供的一种定点数据格式转换的场景示意图。其中,图3b中D表示待处理定点数据,“1’b0”表示符号位S为0,“1’b1”表示符号位S为1。
除此之外,本申请实施例中还可以输入不同浮点精度格式的浮点数至格式转换模块201,格式转换模块201可以将其转换成内部通用的浮点精度格式。
输入模块202,用于获取目标定点数据,将目标定点数据分别输入左向搜索模块204以及右向搜索模块205。
在本申请实施例中,目标定点数据是指未携带符号位的二进制数,该二进制数可以是纯整数、纯小数以及携带小数的整数,例如10001、0.111、1001.11。
可以将输入模块202与上述的格式转换模块201合并成一个模块。
左向搜索模块204,用于从目标定点数据的小数点位置开始,沿整数方向进行整数前导值 搜索。
其中,整数前导值是指整数部分最高位的1,如图3a所示,格式转换模块201(此处是将输入模块201与格式转换模块202合并成一个模块,即格式转换模块201),将目标定点数据100.01输入至左向搜索模块204以及右向搜索模块205,左向搜索模块204对目标定点数据100.01进行小数点左向偏移,偏移2位,得到1.0001*2
2,则阶码加2,可以确定第一指数偏移值等于2;右向搜索模块205对目标定点数据100.01进行小数点右向偏移,可以偏移2位,得到10001.*2
-2,则阶码减2,可以确定第二指数偏移值等于-2。
右向搜索模块205,用于从目标定点数据的小数点位置开始,沿小数方向进行小数前导值搜索。
其中,小数前导值是指小数部分最高位的1,请一并参见图3c,图3c是本申请实施例提供的一种定点数据转换成浮点数据的转换示意图。如图3c所示,待处理定点数据为[(1/32)+(1/64)+(1/128)],首先对其进行符号位的提取以及数制转换,得到符号位S=0,表明待处理定点数据为正数,数制转换为[(1/32)+(1/64)+(1/128)]
10=(0.0000111)
2,由于待处理目标数据的符号位是0,所以可以将0.0000111确定为目标定点数据。格式转换模块将0.0000111输入至左向搜索模块204以及右向搜索模块205,明显地,目标定点数据0.0000111不存在整数前导值;右向搜索模块205对目标定点数据0.0000111进行小数点右向偏移,偏移5位,得到1.11*2
-5,此时阶码减5,可以确定第二指数偏移值等于(-5)。
在本申请实施例中,左向搜索模块204以及右向搜索模块205可以并行搜索目标定点数据的指数偏移值(包括上述的第一指数偏移值以及第二指数偏移值),通过两个方向并行搜索,获取指数偏移值的速度大大提高。需要理解的是,输入的目标定点数据具有不同格式,选择左向搜索和右向搜索,还可以大大提高通用性。
浮点模块206,包括至少两种浮点精度格式,至少两种浮点精度格式包括浮点精度格式A
n以及浮点精度格式A
n+1,n为正整数。
浮点模块206,用于若左向搜索模块搜索到整数前导值,则获取左向搜索模块输出的针对整数前导值的第一指数偏移值,根据目标定点数据对应的符号位以及第一指数偏移值,生成目标定点数据对应的浮点数据。
浮点模块206,还用于若左向搜索模块未搜索到整数前导值,则获取右向搜索模块输出的针对小数前导值的第二指数偏移值,根据目标定点数据对应的符号位以及第二指数偏移值,生成目标定点数据对应的浮点数据。
本申请实施例所说的浮点数据一般是指标准浮点数据,标准浮点数格式为:
V=(-1)
S×M×2
E (1)
其中,S表示符号位,该符号位与目标定点数据对应的符号位相同,当S=0,V为正数,当S=1,V为负数;M表示尾数,E表示阶码。
本申请实施例可以支持任意浮点精度格式输出,包括但不限于电气和电子工程师协会(Institute of Electrical and Electronics Engineers,IEEE)标准定义的格式,例如双精度浮点,即double,float point64(FP64),单精度浮点,即FP32,半精度,即FP16,等等;还包括非标的自定义的格式,包括但不限于BP16。
请再参见图2,浮点模块206可以包括并行生成器2061、并行生成器2062、并行生成器2063、…、并行生成器206k,k为正整数,并行生成器2061、并行生成器2062、并行生成器2063、…、并行生成器206k分别对应不同的浮点精度格式,例如,并行生成器2061对应的浮点精度格式为单精度格式,则生成的浮点1为单精度浮点数据,将单精度浮点数据存储至浮点格式选择模块207的单精度数据单元2071中;并行生成器2062对应的浮点精度格式为双精度格式,则生成的浮点2为双精度浮点数据,将双精度浮点数据存储至浮点格式选择模块207的双精度数据单元2072中,其余并行生成器亦如此,此处不再一一赘述。通过并行生成器2061、并行生成器2062、并行生成器2063、…、并行生成器206k,目标定点数据可以生成至少一个浮点数据。
在IEEE标准中,浮点数是将特定长度的连续字节的所有二进制位分割为特定宽度的符号域、指数域和尾数域,域中的值分别用于表示给定二进制浮点数中的符号、指数和尾数,这样,通过尾数和可以调节的指数就可以表达给定的数值。本申请实施例介绍两种基本的浮点格式:单精度和双精度。其中单精度格式具有24位有效数字(即尾数)精度,总共占用32位,存储时将 整数位中的1舍去,则尾数占23位;双精度格式具有53位有效数字(即尾数)精度,总共占有64位存储时将整数位中的1舍去,则尾数占52位,如表3所示:
表3
假设并行生成器2061对应的浮点精度格式是单精度格式,本申请实施例以并行生成器2061为例进行叙述,其他并行生成器可以按照下述过程生成其对应格式的浮点数。请再参见图3a,左向搜索模块204得到第一指数偏移值后,可以将第一指数偏移值传输至浮点模块206。请再参见图1a,可知浮点模块206可以包括指数编码单元、尾数截取单元以及浮点生成单元。指数编码单元获取第一指数偏移值(即2),以及单精度标准偏移值,如表1所示,单精度标准偏移值为127,对129(2+127)进行二进制编码,得到1000 0001;尾数截取单元对1.0001*2
2进行截取,获取尾数1.0001,存储时,个位数的1被舍去,只存储小数位,即0001,由表1可知,单精度格式的浮点数尾数位占23位,故在0001右侧补0,得到00010000000000000000000,最后浮点生成单元得到如图3a中所示的二进制11000000100010000000000000000000。
同理,请再参见图3c,右向搜索模块205得到第二指数偏移值后,将第二指数偏移值传输至浮点模块206,指数编码单元获取第二指数偏移值(即-5),以及单精度标准偏移值后,对122(-5+127)进行二进制编码,得到0111 1010;尾数截取单元获取尾数1.11,与左向搜索模块204同样,右向搜索模块205存储时,默认舍去个数位上的1,储存11,然后补0,最后浮点生成单元得到如图3c中所示的二进制0011111011000000000000000000000。
在一种实施方式中,定点与浮点转换器还可以包括异常调整模块203,其中,
异常调整模块203,用于对二进制定点数据进行数据状态检测;
异常调整模块203,还用于若二进制定点数据的数据状态为数据正常状态,则通知格式转换模块根据初始符号位对二进制定点数据进行转换处理,生成目标定点数据;
异常调整模块203,还用于若二进制定点数据的数据状态为数据异常状态,则对二进制定点数据进行异常调整,通知格式转换模块根据初始符号位对异常调整后的二进制定点数据进行转换处理,生成目标定点数据。
请再参见图2,格式转换模块201除了将目标定点数据传输至输入模块201,还会将目标定点数据输出到异常调整模块203,以确定目标定点数据是否出现异常,异常调整模块203可以根据输入的异常模式进行异常处理,并把控制信息返回至格式转换模块201。回顾图3a以及图3c的示例,将十进制转换成二进制时,均可以得到精确的结果,而在实际应用时,有很多实数转换成二进制数时,不能得到精确的结果,而是舍入结果,例如(0.1)
10=(0.000110…)
2,但浮点数尾数域的位数是有限的,单精度为23位,双精度为52位,为此,处理方法是持续该过程直到由此得到的尾数足以填满尾数域,之后对多余的位进行舍入。
除了上述数据不精确外,实际应用时,还存在阶码的值是否产生溢出,请再参见图2,左向搜索模块204或者右向搜索模块205将搜索的指数偏移值输入至异常调整模块203,若指数偏移值对应的阶码超过了阶码所能表示的最大正数,则为上溢,进一步,若此时浮点数为正数,则为正上溢,记为+∞,若浮点数为负数,则为负上溢,记为-∞;若阶码的值超过了阶码所能表示的最小负数,则为下溢,进一步,若此时浮点数为正数,则为正下溢,若浮点数为负数,则为负下溢,上述情况必须进行舍入。
本申请实施例提供了四种舍入处理方法:
1、就近舍入(round to neareset):这是标准列出的默认舍入方式,例如Round(1.5)=2,Round(2.5)=2。
2、朝+∞舍入(round toward+∞):对正数来说,只要多余位不为全0,则向尾数最低有效位进1;对负数来说,则是简单地舍去。
3、朝-∞舍入(round toward-∞):与朝+∞舍入方法正好相反,对正数来说,只是简单地舍 去;对负数来说,只要多余位不为全0,则向尾数最低有效位进1。
4、朝0舍入(round toward 0):即简单地截断舍去,而不管多余位是什么值。这种方法实现简单,但容易形成累积误差,且舍入处理后的值总是向下偏差。
除了上述的四种方法,本申请实施例还可以让用户自定义异常处理舍入方式。
上述可知,通过异常调整模块203指定当出现异常时处理方式、包括但不限于舍入模式、数据截取方式,这样可以让误差降到最小,更重要的是能够适配不同应用场景对误差的需求。
在一种实施方式中,定点与浮点转换器还可以包括浮点格式选择模块207,其中,
浮点格式选择模块207,用于获取针对目标定点数据的数据转换指令;数据转换指令携带目标浮点精度格式,至少两种浮点精度格式包括目标浮点精度格式;
浮点格式选择模块207,还用于根据目标浮点精度格式,从至少两个浮点数据中确定目标浮点数据,对目标浮点数据进行输出;目标浮点数据的浮点精度格式为目标浮点精度格式。
由浮点格式选择模块207可知,当获取到待处理定点数据后,本申请实施例所述的定点与浮点转换器可以生成至少一种浮点数据,请再参见图2,单精度数据单元2071存储的是目标定点数据对应的单精度浮点数据,双精度数据单元2072存储的是目标定点数据对应的双精度浮点数据,其他浮点精度格式单元亦分别存储了对应的浮点数据,所以当获取到针对目标定点数据(或待处理定点数据)的数据转换指令时,定点与浮点转换器可以根据数据转换指令中所指示的目标浮点精度格式输出目标浮点数据。
若上述的数据转换指令携带待处理定点数据,以及针对待处理定点数据的目标浮点精度格式,则定点与浮点转换器可以根据目标浮点精度格式,对待处理定点数据进行针对性的转换,只生成与目标浮点精度格式对应的目标浮点数据。
本申请实施例中的定点与浮点转换器设置有格式转换模块、输入模块、左向搜索模块、右向搜索模块、异常调整模块、浮点模块以及浮点格式选择模块,格式转换模块获取待处理定点数据,实现任意数据格式转换,可以是通用格式或者自定义的私有格式,满足定制型特殊要求,同时输出浮点数据符号位结果。格式转换模块的输出通过输入模块分别输入至左向搜索模块以及右向搜索模块,上述的左向搜索模块以及右向搜索模块是并行设置的,因此可以同时搜索目标定点数据转换成与之对应的浮点数据的指数偏移值,且输入的目标定点数据具有的不同格式,选择左向搜索和右向搜索,还可以大大提高通用性;格式转换模块还可以与异常调整模块相连,以检测转换的二进制数是否存在异常,通过异常调整模块可以让误差降到最小,更重要的是能够适配不同应用场景对误差的需求,上述的左向搜索模块(右向搜索模块亦可以)也可以与异常调整模块进行连接,以检测阶码数是否存在异常。上述可知,本申请实施例通过上述的左向搜索模块以及右向搜索模块的并行搜索可以提高获取指数偏移值的速度,且可以满足不同类型的目标定点数据,即提高了定点数据转浮点数据的通用性,进而可以提高数据运算的效率。
定点与浮点转换器作为基本的数据处理单元,被广泛应用于计算机学、通讯、人工智能等多个领域。我们所熟知的GPU、CPU、现场可编程逻辑门阵列(Field Programmable Gate Array,FPGA)或者大规模人工智能(Artificial Intelligence,AI)芯片里均包含若干定点与浮点转换器,它是一个基础的组件,其重要性显然易见。
以人工智能领域为例,伴随着人脸识别、图像分类等新兴技术的快速发展,对计算精度和速度要求日益增大。为了能提高机器学习模型的精度,在训练阶段,一般会采用浮点运算以提高训练的精度和收敛速度,而在推理阶段,一般采用定点计算得到推理的结果,因此需要一套既能支持定点运算,又能支持浮点运算,并且还能灵活的实现相互转换的计算结构。
进一步地,请参见图4,图4是本申请实施例提供的一种定点转浮点的图形处理器。如图4所示,该定点转浮点的图形处理器可以包括片上/片外存储单元401、前处理模块402、定点转浮点通用模块403、浮点运算单元404以及后处理单元405,其中,
片上/片外存储单元401,用于存储待处理定点数据;
前处理模块402,用于当获取到针对待处理定点数据的数据运算指令时,根据数据运算指令获取存储于数据存储器中的待处理定点数据,对待处理定点数据进行数据预处理,得到目标定点数据;数据运算指令携带目标浮点精度格式;
定点转浮点通用模块403,用于对第一处理器传输的目标定点数据进行数据格式转换,生成对应于目标浮点精度格式的浮点数据;其中,定点转浮点器403包括图1a-图1c以及图2所 述的装置;
浮点运算单元404,用于对浮点数据进行浮点运算,生成浮点运算后的浮点数据;
后处理单元405,用于将浮点运算后的浮点数据传输至片上/片外存储单元401,以使片上/片外存储单元401存储浮点运算后的浮点数据。
一般AI芯片内部包括成千上万个以上的浮点运算器,如果当前神经网络算法需要使用浮点模式进行计算,首先从片上/片外存储单元401取出数据,然后经过前处理模块402进行如格式转换、降噪等处理之后得到定点数据,再经过定点转浮点通用模块403完成定点到浮点转换,转换之后送到浮点运算单元404完成各类浮点运算,最后经过后处理模块405把结果写回片上/片外存储单元。
上述可知,定点转浮点的图形处理器可以保证计算精度的同时,还提高了面向不同应用、产品需求的通用性和灵活性。
进一步地,请参见图5,图5是本申请实施例提供的一种定点转浮点的中央处理器。如图5所示,该定点转浮点的中央处理器可以包括取指模块501、译码模块502以及定点转浮点模块503,其中,
取指模块501,用于获取运算指令;
译码模块502,用于对取指模块获取的运算指令进行译码处理,得到译码后的运算指令;译码后的运算指令用于表征对待处理定点数据进行浮点运算;
定点转浮点模块503,用于根据解码后的运算指令获取待处理定点数据,对待处理定点数据进行数据格式转换,得到待处理定点数据对应的浮点数据,并对浮点数据进行浮点运算;其中,定点转浮点模块包括图1a-图1c以及图2的装置。
上述可知,定点转浮点的中央处理器的取指模块取出一条指令时,先经过译码模块,当译码为一条浮点运算的指令时,就会使定点转浮点模块完成从定点数据到浮点数据的转换。包括定点转浮点模块的中央处理器可以在保证计算精度的同时,还提高了面向不同应用、产品需求的通用性以及灵活性。
基于上述定点与浮点转换器的相关描述,本申请实施例提出一种定点与浮点转换方法,请参见图6,图6是本申请实施例提供的一种定点与浮点转换方法,该定点与浮点转换方法可由上述图1a或图2所提及的定点与浮点转换器执行。如图6所示,该定点与浮点转换方法可以包括以下步骤S601-S605:
步骤S601,获取目标定点数据,将目标定点数据分别输入左向搜索模块和右向搜索模块。
具体的,获取待处理定点数据,将待处理定点数据输入格式转换模块;在格式转换模块中,获取待处理定点数据的初始符号位,并将未包括初始符号位的待处理定点数据转换为二进制定点数据;根据初始符号位对二进制定点数据进行转换处理,生成目标定点数据,将初始符号位确定为目标定点数据对应的符号位。
将二进制定点数据输入异常调整模块,在异常调整模块中对二进制定点数据进行数据状态检测;若二进制定点数据的数据状态为数据正常状态,则通知格式转换模块根据初始符号位对二进制定点数据进行转换处理,生成目标定点数据;若二进制定点数据的数据状态为数据异常状态,则对二进制定点数据进行异常调整,通知格式转换模块根据初始符号位对异常调整后的二进制定点数据进行转换处理,生成目标定点数据。
根据初始符号位对二进制定点数据进行转换处理,生成目标定点数据,包括:若初始符号位的极性为0,则将二进制定点数据确定为目标定点数据,若初始符号位的极性为1,则对二进制定点数据进行补码处理,得到补码处理之后的二进制定点数据,将补码处理之后的二进制定点数据确定为目标定点数据。
步骤S602,在左向搜索模块中,从目标定点数据的小数点位置开始,沿整数方向进行整数前导值搜索。
具体的,从目标定点数据的小数点位置开始,沿整数方向获取目标定点数据的左向搜索范围;左向搜索范围包括左向起始数值,左向起始数值是指在左向搜索范围中,与目标定点数据的小数点距离最近的数值;从左向起始数值开始沿整数方向,对左向搜索范围内的每个左向数值进行遍历;根据左向遍历结果搜索整数前导值。左向遍历结果包括左向数值Z
i,i为正整数,且i小于或等于左向搜索范围中的左向数值的总数量,左向数值Z
i包括左向起始数值;若左向 遍历结果中的左向数值Z
i均不等于默认数值,则确定左向搜索范围不包括整数前导值;整数前导值的数值等于默认数值;若左向遍历结果中存在左向数值Z
i等于默认数值,则确定左向搜索范围包括整数前导值,获取等于默认数值的左向数值Z
i的左向位置信息L
i;根据左向位置信息L
i中距离初始位置最远的左向位置信息,确定第一指数偏移值;初始位置为目标定点数据的小数点位置。
步骤S603,在右向搜索模块中,从目标定点数据的小数点位置开始,沿小数方向进行小数前导值搜索。
具体的,从目标定点数据的小数点位置开始,沿小数方向获取目标定点数据的右向搜索范围;右向搜索范围包括右向起始数值,右向起始数值是指在右向搜索范围中,与目标定点数据的小数点距离最近的数值;从右向起始数值开始沿小数方向,对右向搜索范围内的每个右向数值进行遍历;根据右向遍历结果搜索小数前导值。右向遍历结果包括右向数值Y
j,j为正整数,且j小于或等于右向搜索范围中的右向数值的总数量,右向数值Y
j包括右向起始数值;若右向遍历结果中的右向数值Y
j均不等于默认数值,则确定右向搜索范围不包括小数前导值;小数前导值的数值等于默认数值;若右向遍历结果中存在右向数值Y
j等于默认数值,则确定右向搜索范围包括小数前导值,获取等于默认数值的右向数值Y
j的右向位置信息C
j;根据右向位置信息C
j中距离初始位置最近的右向位置信息,确定第二指数偏移值;初始位置为目标定点数据的小数点位置。
步骤S604,若左向搜索模块搜索到整数前导值,则获取左向搜索模块输出的针对整数前导值的第一指数偏移值,根据目标定点数据对应的符号位以及第一指数偏移值,生成目标定点数据对应的浮点数据。
具体的,根据目标定点数据以及第一指数偏移值,截取针对目标定点数据的第一尾数数据;获取至少两种浮点精度格式分别对应的标准偏移值,根据第一指数偏移值以及至少两个标准偏移值,分别编码针对目标定点数据的至少两个第一目标指数;至少两种浮点精度格式包括浮点精度格式A
n以及浮点精度格式A
n+1,n为正整数;根据目标定点数据对应的符号位、至少两个第一目标指数以及第一尾数数据,分别生成目标定点数据对应的至少两个浮点数据;至少两个浮点数据包括浮点数据F
n以及浮点数据F
n+1,其中,浮点数据F
n的浮点精度格式为浮点精度格式A
n,浮点数据F
n+1的浮点精度格式为浮点精度格式A
n+1。
步骤S605,若左向搜索模块未搜索到整数前导值,则获取右向搜索模块输出的针对小数前导值的第二指数偏移值,根据目标定点数据对应的符号位以及第二指数偏移值,生成目标定点数据对应的浮点数据。
具体的,根据目标定点数据以及第二指数偏移值,截取针对目标定点数据的第二尾数数据;获取至少两种浮点精度格式分别对应的标准偏移值,根据第二指数偏移值以及至少两个标准偏移值,分别编码针对目标定点数据的至少两个第二目标指数;至少两种浮点精度格式包括浮点精度格式A
n以及浮点精度格式A
n+1,n为正整数;根据目标定点数据对应的符号位、至少两个第二目标指数以及第二尾数数据,分别生成目标定点数据对应的至少两个浮点数据;至少两个浮点数据包括浮点数据D
n以及浮点数据D
n+1,其中,浮点数据D
n的浮点精度格式为浮点精度格式A
n,浮点数据D
n+1的浮点精度格式为浮点精度格式A
n+1。
获取针对目标定点数据的数据转换指令;数据转换指令携带目标浮点精度格式,至少两种浮点精度格式包括目标浮点精度格式;根据目标浮点精度格式,从至少两个浮点数据中确定目标浮点数据,对目标浮点数据进行输出;目标浮点数据的浮点精度格式为目标浮点精度格式。
其中,步骤S601-步骤S605的具体实现过程请参见上述图1a以及图2,此处不再进行赘述。
上述可知,本申请实施例通过上述的左向搜索模块以及右向搜索模块,可以并行搜索指数偏移值(包括第一指数偏移值以及第二指数偏移值),并行搜索可以提高获取指数偏移值的速度,且并行搜索可以满足不同类型的目标定点数据,提高了定点数据转浮点数据的通用性,进而可以提高数据运算的效率。
本申请实施例还提供一种计算机可读存储介质,该计算机可读存储介质存储有计算机程序,该计算机程序包括程序指令,该程序指令被处理器执行时实现图6中各个步骤所提供的定点与浮点转换方法,具体可参见上述图6各个步骤所提供的实现方式,在此不再赘述。
上述计算机可读存储介质可以是前述任一实施例提供的定点与浮点转换器,或者上述定点与浮点转换的图形处理器,或者上述定点与浮点转换的中央处理器的内部存储单元,例如计算机设备的硬盘或内存。该计算机可读存储介质也可以是该计算机设备的外部存储设备,例如该计算机设备上配备的插接式硬盘,智能存储卡(smart media card,SMC),安全数字(secure digital,SD)卡,闪存卡(flash card)等。进一步地,该计算机可读存储介质还可以既包括该计算机设备的内部存储单元也包括外部存储设备。该计算机可读存储介质用于存储该计算机程序以及该计算机设备所需的其他程序和数据。该计算机可读存储介质还可以用于暂时地存储已经输出或者将要输出的数据。
本申请实施例的说明书和权利要求书及附图中的术语“第一”、“第二”等是用于区别不同对象,而非用于描述特定顺序。此外,术语“包括”以及它们任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或单元的过程、方法、装置、产品或设备没有限定于已列出的步骤或模块,而是还包括没有列出的步骤或模块,或还包括对于这些过程、方法、装置、产品或设备固有的其他步骤单元。
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
本申请实施例提供的方法及相关装置是参照本申请实施例提供的方法流程图和/或结构示意图来描述的,具体可由计算机程序指令实现方法流程图和/或结构示意图的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。这些计算机程序指令可提供到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或结构示意图一个方框或多个方框中指定的功能的装置。这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或结构示意图一个方框或多个方框中指定的功能。这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或结构示意图一个方框或多个方框中指定的功能的步骤。
以上所揭露的仅为本申请较佳实施例而已,当然不能以此来限定本申请之权利范围,因此依本申请权利要求所作的等同变化,仍属本申请所涵盖的范围。
Claims (20)
- 一种定点与浮点转换器,其特征在于,包括输入模块、左向搜索模块、右向搜索模块、浮点模块;所述输入模块,用于获取目标定点数据,将所述目标定点数据分别输入所述左向搜索模块和所述右向搜索模块;所述左向搜索模块,用于从所述目标定点数据的小数点位置开始,沿整数方向进行整数前导值搜索;所述右向搜索模块,用于从所述目标定点数据的小数点位置开始,沿小数方向进行小数前导值搜索;所述浮点模块,用于若所述左向搜索模块搜索到所述整数前导值,则获取所述左向搜索模块输出的针对所述整数前导值的第一指数偏移值,根据所述目标定点数据对应的符号位以及第一指数偏移值,生成所述目标定点数据对应的浮点数据;所述浮点模块,还用于若所述左向搜索模块未搜索到所述整数前导值,则获取所述右向搜索模块输出的针对所述小数前导值的第二指数偏移值,根据所述目标定点数据对应的所述符号位以及第二指数偏移值,生成所述目标定点数据对应的所述浮点数据。
- 根据权利要求1所述的定点与浮点转换器,其特征在于,所述定点与浮点转换器包括至少两种浮点精度格式,所述至少两种浮点精度格式包括浮点精度格式A n以及浮点精度格式A n+1,n为正整数;所述浮点模块包括:尾数截取单元,用于若所述左向搜索模块搜索到所述整数前导值,则获取所述左向搜索模块输出的针对所述整数前导值的第一指数偏移值,根据所述目标定点数据以及所述第一指数偏移值,截取针对所述目标定点数据的第一尾数数据;指数编码单元,用于若所述左向搜索模块搜索到所述整数前导值,则获取所述左向搜索模块输出的针对所述整数前导值的第一指数偏移值,获取所述至少两种浮点精度格式分别对应的标准偏移值,根据所述第一指数偏移值以及至少两个标准偏移值,分别编码针对所述目标定点数据的至少两个第一目标指数;浮点生成单元,用于根据所述目标定点数据对应的符号位、所述至少两个第一目标指数以及所述第一尾数数据,分别生成所述目标定点数据对应的至少两个浮点数据;所述至少两个浮点数据包括浮点数据F n以及浮点数据F n+1,其中,所述浮点数据F n的浮点精度格式为所述浮点精度格式A n,所述浮点数据F n+1的浮点精度格式为所述浮点精度格式A n+1。
- 根据权利要求1所述的定点与浮点转换器,其特征在于,所述定点与浮点转换器包括至少两种浮点精度格式,所述至少两种浮点精度格式包括浮点精度格式A n以及浮点精度格式A n+1,n为正整数;所述浮点模块包括:尾数截取单元,用于若所述左向搜索模块未搜索到所述整数前导值,则获取所述右向搜索模块输出的针对所述小数前导值的第二指数偏移值,根据所述目标定点数据以及所述第二指数偏移值,截取针对所述目标定点数据的第二尾数数据;指数编码单元,用于若所述左向搜索模块未搜索到所述整数前导值,则获取所述右向搜索模块输出的针对所述小数前导值的第二指数偏移值,获取所述至少两种浮点精度格式分别对应的标准偏移值,根据所述第二指数偏移值以及至少两个标准偏移值,分别编码针对所述目标定点数据的至少两个第二目标指数;浮点生成单元,用于根据所述目标定点数据对应的符号位、所述至少两个第二目标指数以及所述第二尾数数据,分别生成所述目标定点数据对应的所述至少两个浮点数据;所述至少两个浮点数据包括浮点数据D n以及浮点数据D n+1,其中,所述浮点数据D n的浮点精度格式为所述浮点精度格式A n,所述浮点数据D n+1的浮点精度格式为所述浮点精度格式A n+1。
- 根据权利要求2或者权利要求3所述的定点与浮点转换器,其特征在于,还包括:浮点格式选择模块,用于获取针对所述目标定点数据的数据转换指令;所述数据转换指令 携带目标浮点精度格式,所述至少两种浮点精度格式包括所述目标浮点精度格式;所述浮点格式选择模块,还用于根据所述目标浮点精度格式,从所述至少两个浮点数据中确定目标浮点数据,对所述目标浮点数据进行输出;所述目标浮点数据的浮点精度格式为所述目标浮点精度格式。
- 根据权利要求1所述的定点与浮点转换器,其特征在于,所述左向搜索模块包括:左向获取单元,用于从所述目标定点数据的小数点位置开始,沿所述整数方向获取所述目标定点数据的左向搜索范围;所述左向搜索范围包括左向起始数值,所述左向起始数值是指在所述左向搜索范围中,与所述目标定点数据的小数点距离最近的数值;第一遍历单元,用于从所述左向起始数值开始沿所述整数方向,对所述左向搜索范围内的每个左向数值进行遍历;第一搜索单元,用于根据左向遍历结果搜索所述整数前导值。
- 根据权利要求5所述的定点与浮点转换器,其特征在于,所述左向遍历结果包括左向数值Z i,i为正整数,且i小于或等于所述左向搜索范围中的左向数值的总数量,所述左向数值Z i包括所述左向起始数值;所述第一搜索单元,具体用于若所述左向遍历结果中的所述左向数值Z i均不等于默认数值,则确定所述左向搜索范围不包括所述整数前导值;所述整数前导值的数值等于所述默认数值;所述第一搜索单元,具体用于若所述左向遍历结果中存在所述左向数值Z i等于所述默认数值,则确定所述左向搜索范围包括所述整数前导值,获取等于所述默认数值的所述左向数值Z i的左向位置信息L i;所述第一搜索单元,具体用于根据所述左向位置信息L i中距离初始位置最远的左向位置信息,确定所述第一指数偏移值;所述初始位置为所述目标定点数据的小数点位置。
- 根据权利要求1所述的定点与浮点转换器,其特征在于,所述右向搜索模块包括:右向获取单元,用于从所述目标定点数据的小数点位置开始,沿所述小数方向获取所述目标定点数据的右向搜索范围;所述右向搜索范围包括右向起始数值,所述右向起始数值是指在所述右向搜索范围中,与所述目标定点数据的小数点距离最近的数值;第二遍历单元,用于从所述右向起始数值开始沿所述小数方向,对所述右向搜索范围内的每个右向数值进行遍历;第二搜索单元,用于根据右向遍历结果搜索所述小数前导值。
- 根据权利要求7所述的定点与浮点转换器,其特征在于,所述右向遍历结果包括右向数值Y j,j为正整数,且j小于或等于所述右向搜索范围中的右向数值的总数量,所述右向数值Y j包括所述右向起始数值;所述第二搜索单元,具体用于若所述右向遍历结果中的所述右向数值Y j均不等于默认数值,则确定所述右向搜索范围不包括所述小数前导值;所述小数前导值的数值等于所述默认数值;所述第二搜索单元,具体用于若所述右向遍历结果中存在所述右向数值Y j等于所述默认数值,则确定所述右向搜索范围包括所述小数前导值,获取等于所述默认数值的所述右向数值Y j的右向位置信息C j;所述第二搜索单元,具体用于根据所述右向位置信息C j中距离初始位置最近的右向位置信息,确定所述第二指数偏移值;所述初始位置为所述目标定点数据的小数点位置。
- 根据权利要求1所述的定点与浮点转换器,其特征在于,还包括:格式转换模块,用于获取待处理定点数据,获取所述待处理定点数据的初始符号位,将未包括所述初始符号位的待处理定点数据转换为二进制定点数据;所述格式转换模块,还用于根据所述初始符号位对所述二进制定点数据进行转换处理,生成所述目标定点数据,将所述初始符号位确定为所述目标定点数据对应的符号位。
- 根据权利要求9所述的定点与浮点转换器,其特征在于,还包括:异常调整模块,用于对所述二进制定点数据进行数据状态检测;所述异常调整模块,还用于若所述二进制定点数据的所述数据状态为数据正常状态,则通知所述格式转换模块根据所述初始符号位对所述二进制定点数据进行转换处理,生成所述目标 定点数据;所述异常调整模块,还用于若所述二进制定点数据的所述数据状态为数据异常状态,则对所述二进制定点数据进行异常调整,通知所述格式转换模块根据所述初始符号位对异常调整后的二进制定点数据进行转换处理,生成所述目标定点数据。
- 根据权利要求9所述的定点与浮点转换器,其特征在于,所述格式转换模块,具体用于若所述初始符号位的极性为0,则将所述二进制定点数据确定为所述目标定点数据,且具体用于若所述初始符号位的极性为1,则对所述二进制定点数据进行补码处理,得到补码处理之后的二进制定点数据,将所述补码处理之后的二进制定点数据确定为所述目标定点数据。
- 一种定点与浮点转换方法,其特征在于,所述方法由权利要求1-11任一项所述的定点与浮点转换器来执行,所述方法包括:获取目标定点数据,将所述目标定点数据分别输入左向搜索模块和右向搜索模块;在所述左向搜索模块中,从所述目标定点数据的小数点位置开始,沿整数方向进行整数前导值搜索;在所述右向搜索模块中,从所述目标定点数据的小数点位置开始,沿小数方向进行小数前导值搜索;若所述左向搜索模块搜索到所述整数前导值,则获取所述左向搜索模块输出的针对所述整数前导值的第一指数偏移值,根据所述目标定点数据对应的符号位以及所述第一指数偏移值,生成所述目标定点数据对应的浮点数据;若所述左向搜索模块未搜索到所述整数前导值,则获取所述右向搜索模块输出的针对所述小数前导值的第二指数偏移值,根据所述目标定点数据对应的所述符号位以及所述第二指数偏移值,生成所述目标定点数据对应的所述浮点数据。
- 根据权12所述的方法,其特征在于,所述根据目标定点数据对应的符号位以及第一指数偏移值,生成目标定点数据对应的浮点数据,包括:根据所述目标定点数据以及所述第一指数偏移值,截取针对所述目标定点数据的第一尾数数据;获取至少两种浮点精度格式分别对应的标准偏移值,根据所述第一指数偏移值以及至少两个标准偏移值,分别编码针对所述目标定点数据的至少两个第一目标指数;至少两种浮点精度格式包括浮点精度格式A n以及浮点精度格式A n+1,n为正整数;根据所述目标定点数据对应的符号位、所述至少两个第一目标指数以及所述第一尾数数据,分别生成所述目标定点数据对应的至少两个浮点数据;所述至少两个浮点数据包括浮点数据F n以及浮点数据F n+1,其中,浮点数据F n的浮点精度格式为浮点精度格式A n,浮点数据F n+1的浮点精度格式为浮点精度格式A n+1。
- 根据权12所述的方法,其特征在于,所述根据目标定点数据对应的符号位以及第二指数偏移值,生成目标定点数据对应的浮点数据,包括:根据所述目标定点数据以及所述第二指数偏移值,截取针对所述目标定点数据的第二尾数数据;获取至少两种浮点精度格式分别对应的标准偏移值,根据所述第二指数偏移值以及至少两个标准偏移值,分别编码针对所述目标定点数据的至少两个第二目标指数;至少两种浮点精度格式包括浮点精度格式A n以及浮点精度格式A n+1,n为正整数;根据所述目标定点数据对应的符号位、所述至少两个第二目标指数以及所述第二尾数数据,分别生成所述目标定点数据对应的至少两个浮点数据;所述至少两个浮点数据包括浮点数据D n以及浮点数据D n+1,其中,浮点数据D n的浮点精度格式为浮点精度格式A n,浮点数据D n+1的浮点精度格式为浮点精度格式A n+1。
- 根据权13或14所述的方法,其特征在于,所述方法还包括:获取针对所述目标定点数据的数据转换指令,其中,所述数据转换指令携带目标浮点精度格式,所述至少两种浮点精度格式包括目标浮点精度格式;根据所述目标浮点精度格式,从所述至少两个浮点数据中确定目标浮点数据,对所述目标浮点数据进行输出;所述目标浮点数据的浮点精度格式为所述目标浮点精度格式。
- 根据权12所述的方法,其特征在于,所述从目标定点数据的小数点位置开始,沿整数方向进行整数前导值搜索,包括:从所述目标定点数据的小数点位置开始,沿所述整数方向获取所述目标定点数据的左向搜索范围;所述左向搜索范围包括左向起始数值,所述左向起始数值是指在所述左向搜索范围中,与所述目标定点数据的小数点距离最近的数值;从所述左向起始数值开始沿所述整数方向,对所述左向搜索范围内的每个左向数值进行遍历;根据左向遍历结果搜索所述整数前导值。
- 根据权16所述的方法,其特征在于,所述左向遍历结果包括左向数值Z i,i为正整数,且i小于或等于所述左向搜索范围中的左向数值的总数量,所述左向数值Z i包括所述左向起始数值;所述根据左向遍历结果搜索整数前导值,包括:若所述左向遍历结果中的所述左向数值Z i均不等于默认数值,则确定所述左向搜索范围不包括所述整数前导值;所述整数前导值的数值等所述于默认数值;若所述左向遍历结果中存在所述左向数值Z i等于所述默认数值,则确定所述左向搜索范围包括所述整数前导值,获取等于所述默认数值的所述左向数值Z i的左向位置信息L i;根据所述左向位置信息L i中距离初始位置最远的左向位置信息,确定所述第一指数偏移值;所述初始位置为所述目标定点数据的小数点位置。
- 一种定点转浮点的图形处理器,其特征在于,包括权利要求1-11任一项所述的定点与浮点转换器。
- 一种定点转浮点的中央处理器,其特征在于,包括权利要求1-11任一项所述的定点与浮点转换器。
- 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质存储有计算机程序,所述计算机程序包括程序指令,所述程序指令被处理器执行时,执行权利要求12-17任一项所述的定点与浮点转换方法的步骤。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010931697.XA CN111796798B (zh) | 2020-09-08 | 2020-09-08 | 一种定点与浮点转换器、处理器、方法以及存储介质 |
CN202010931697.X | 2020-09-08 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2022052625A1 true WO2022052625A1 (zh) | 2022-03-17 |
Family
ID=72834138
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2021/106761 WO2022052625A1 (zh) | 2020-09-08 | 2021-07-16 | 一种定点与浮点转换器、处理器、方法以及存储介质 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN111796798B (zh) |
WO (1) | WO2022052625A1 (zh) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114626489A (zh) * | 2022-05-17 | 2022-06-14 | 深圳比特微电子科技有限公司 | 一种softmax函数定点化实现方法和装置 |
CN114820281A (zh) * | 2022-05-27 | 2022-07-29 | 智绘微电子科技(南京)有限公司 | 数据处理用双通道并行单精度浮点数据格式的加速方法 |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111796798B (zh) * | 2020-09-08 | 2020-12-22 | 腾讯科技(深圳)有限公司 | 一种定点与浮点转换器、处理器、方法以及存储介质 |
CN114265575A (zh) * | 2021-12-31 | 2022-04-01 | 上海阵量智能科技有限公司 | 浮点数处理方法、装置、电子设备及存储介质 |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20100174764A1 (en) * | 2009-01-08 | 2010-07-08 | International Business Machines Corporation | Reuse of rounder for fixed conversion of log instructions |
CN104778026A (zh) * | 2015-04-28 | 2015-07-15 | 浪潮电子信息产业股份有限公司 | 一种带simd的高速数据格式转换部件及转换方法 |
CN107769791A (zh) * | 2016-08-22 | 2018-03-06 | Arm 有限公司 | 用于定点到浮点的转换的装置和方法及2的负幂检测器 |
CN109582355A (zh) * | 2017-09-29 | 2019-04-05 | 英特尔公司 | 定点到浮点转换 |
CN111796798A (zh) * | 2020-09-08 | 2020-10-20 | 腾讯科技(深圳)有限公司 | 一种定点与浮点转换器、处理器、方法以及存储介质 |
Family Cites Families (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP3607107B2 (ja) * | 1998-03-13 | 2005-01-05 | 株式会社東芝 | データ管理装置 |
CN104572018A (zh) * | 2014-12-30 | 2015-04-29 | 杭州中天微系统有限公司 | 一种用于浮点常数生成的装置及方法 |
US10216479B2 (en) * | 2016-12-06 | 2019-02-26 | Arm Limited | Apparatus and method for performing arithmetic operations to accumulate floating-point numbers |
CN109739555B (zh) * | 2019-01-04 | 2023-06-16 | 腾讯科技(深圳)有限公司 | 包括乘累加模块的芯片、终端及控制方法 |
-
2020
- 2020-09-08 CN CN202010931697.XA patent/CN111796798B/zh active Active
-
2021
- 2021-07-16 WO PCT/CN2021/106761 patent/WO2022052625A1/zh active Application Filing
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20100174764A1 (en) * | 2009-01-08 | 2010-07-08 | International Business Machines Corporation | Reuse of rounder for fixed conversion of log instructions |
CN104778026A (zh) * | 2015-04-28 | 2015-07-15 | 浪潮电子信息产业股份有限公司 | 一种带simd的高速数据格式转换部件及转换方法 |
CN107769791A (zh) * | 2016-08-22 | 2018-03-06 | Arm 有限公司 | 用于定点到浮点的转换的装置和方法及2的负幂检测器 |
CN109582355A (zh) * | 2017-09-29 | 2019-04-05 | 英特尔公司 | 定点到浮点转换 |
CN111796798A (zh) * | 2020-09-08 | 2020-10-20 | 腾讯科技(深圳)有限公司 | 一种定点与浮点转换器、处理器、方法以及存储介质 |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114626489A (zh) * | 2022-05-17 | 2022-06-14 | 深圳比特微电子科技有限公司 | 一种softmax函数定点化实现方法和装置 |
CN114820281A (zh) * | 2022-05-27 | 2022-07-29 | 智绘微电子科技(南京)有限公司 | 数据处理用双通道并行单精度浮点数据格式的加速方法 |
Also Published As
Publication number | Publication date |
---|---|
CN111796798B (zh) | 2020-12-22 |
CN111796798A (zh) | 2020-10-20 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2022052625A1 (zh) | 一种定点与浮点转换器、处理器、方法以及存储介质 | |
US11698772B2 (en) | Prepare for shorter precision (round for reround) mode in a decimal floating-point instruction | |
CN111796870B (zh) | 数据格式转换装置、处理器、电子设备及模型运行方法 | |
TWI643124B (zh) | 用於提供資訊處理的裝置、方法及系統 | |
CN112230881A (zh) | 浮点数处理器 | |
Rajaraman | IEEE standard for floating point numbers | |
US8874630B2 (en) | Apparatus and method for converting data between a floating-point number and an integer | |
US20070180004A1 (en) | Apparatus and method for precision binary numbers and numerical operations | |
CN111538473A (zh) | 一种Posit浮点数处理器 | |
CN110888623A (zh) | 数据转换方法、乘法器、加法器、终端设备及存储介质 | |
CN115268832A (zh) | 浮点数取整的方法、装置以及电子设备 | |
CN115906137A (zh) | 用于多方安全计算的数据处理方法及装置 | |
WO2017185203A1 (zh) | 一种用于执行多个浮点数相加的装置及方法 | |
WO2022001722A1 (zh) | 一种用于计算正弦或余弦函数的实现方法及装置 | |
WO2024082674A1 (zh) | 浮点数据精度转换方法和装置 | |
JP2023103419A (ja) | 演算方法、装置、チップ、電子機器及び記憶媒体 | |
KR102228995B1 (ko) | 여러 가지 수치 포맷의 데이터를 갖는, 데이터 베이스화된 함수 모델의 연산을 위한 모델 연산 유닛 및 제어 장치 | |
CN113625990B (zh) | 浮点转定点装置、方法、电子设备及存储介质 | |
CN113377334B (zh) | 一种浮点数据处理方法、装置及存储介质 | |
CN114691082A (zh) | 乘法器电路、芯片、电子设备及计算机可读存储介质 | |
CN112241291B (zh) | 用于指数函数实施的浮点单元 | |
US20040254973A1 (en) | Rounding mode insensitive method and apparatus for integer rounding | |
US20240272871A1 (en) | System and method to accelerate microprocessor operations | |
Vuthaj et al. | From Floats To Posits: A Conversion Framework | |
Malathi et al. | Design of Risc-V Processing Unit Using Posit Number System |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 21865681 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 21865681 Country of ref document: EP Kind code of ref document: A1 |