Floating point function calculation table lookup device
By designing a floating-point number function operation table lookup calculation device, using bit arrangement and table lookup technology, the problems of low efficiency and accuracy loss of special mathematical operations in multi-core parallel operation systems are solved, and efficient and accurate special operations are achieved.
Patent Information
- Application Number
- CN202011191656.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-30
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2040-10-30
AI Technical Summary
In multi-core parallel computing systems, it is difficult for the prior art to effectively implement a variety of special mathematical operations, and accuracy is easily lost during recursive approximation.
A floating-point number function operation lookup table calculation device is designed, including a bit arrangement unit, a first lookup unit group and a calculation unit. The bit arrangement or format conversion of floating-point input data through the bit arrangement unit to generate multiple bit blocks; then, the first group of table lookup units uses these bit blocks as indexes to search tables to obtain multiple table lookup results; finally, the calculation unit calculates these table lookup results and obtains the final calculation results.
It realizes efficient execution of a variety of special mathematical operations on a multi-core parallel computing system, reducing the risk of accuracy loss in the recurrence approximation process, and reducing the CPU resources required for special operations.
Smart Images

Figure CN114442993B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a floating point function operation table lookup calculation device. Background Art
[0002] In the past, special mathematical operations required the use of Taylor expansion, CORDIC algorithm, approximation algorithm, or quantization to int8 operations.
[0003] The CORDIC (Coordinate Rotation Digital Computer) algorithm is a method for evaluating multiple mathematical functions through iteration. It can solve trigonometric functions, hyperbolic functions, and plane rotation problems. The CORDIC algorithm uses iterative approximation methods to calculate the value of special functions through addition / subtraction and shift operations, which greatly facilitates computer implementation.
[0004] However, it is not easy to create multiple unique algorithms on a multi-core parallel computing system, and it is also easy to lose accuracy in the recursive approximation process.
[0005] Therefore, the present invention proposes a floating point function operation table lookup calculation device in order to realize various special operation expressions. Summary of the invention
[0006] According to an example of the present invention, a floating-point function operation table lookup calculation device is proposed, comprising: a bit arrangement unit, receiving a floating-point input data, performing bit arrangement or format conversion on the floating-point input data to generate a plurality of bit blocks; a first table lookup unit group, receiving the plurality of bit blocks, performing table lookup with the plurality of bit blocks as indexes to obtain a plurality of table lookup results; and an operation unit, operating on the plurality of table lookup results of the first table lookup unit group to obtain an operation result.
[0007] The present invention is described in detail below with reference to the accompanying drawings and specific embodiments, but is not intended to limit the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] Figure 1 The figure is a functional block diagram of a floating point function operation table lookup computing device according to an embodiment of the present invention.
[0009] Figures 2 to 4 Schematic diagrams showing various operations of the floating-point function operation table lookup computing device according to an embodiment of the present invention.
[0010] Figure 5A Displays a graph of the trigonometric function arctan.
[0011] Figure 5B and Figure 5CA diagram showing the relationship between indexes and table lookup results of two table lookup units according to an embodiment of the present invention. DETAILED DESCRIPTION
[0012] The technical terms in this specification refer to the customary terms in the technical field. If some terms are explained or defined in this specification, the interpretation of these terms shall be based on the explanation or definition in this specification. Each embodiment of the present invention has one or more technical features. Under the premise of possible implementation, a person with ordinary knowledge in the technical field can selectively implement some or all of the technical features in any embodiment, or selectively combine some or all of the technical features in these embodiments.
[0013] The structural principle and working principle of the present invention are described in detail below in conjunction with the accompanying drawings:
[0014] Please refer to Figure 1 , which is a functional block diagram of a computing device (floating point function operation table lookup computing device) according to an embodiment of the present invention. The computing device 100 according to an embodiment of the present invention comprises: a bit arrangement unit 110, a first table lookup unit 120, a second table lookup unit 130, a third table lookup unit 140 and an operation unit 150.
[0015] In the embodiment of the present invention, the floating point input data FP includes, for example but not limited to, two formats: TF32 (TensorFloat-32) and Bfloat16 (brain floating point). The format TF32 is 19 bits, including multiple bit groups, for example: 1 bit sign S1, 8 bits exponent E1 and 10 bits mantissa M1. The format Bfloat16 is 16 bits, including multiple bit groups, for example: 1 bit sign S2, 8 bits exponent E2 and 7 bits mantissa M2.
[0016] The bit arrangement unit 110 receives the floating point input data FP, and performs bit arrangement or format conversion on the floating point input data FP to generate a first bit block FP_1, a second bit block FP_2, and a third bit block FP_3. The first bit block FP_1, the second bit block FP_2, and the third bit block FP_3 are respectively input to the first table lookup unit 120, the second table lookup unit 130, and the third table lookup unit 140. The first table lookup unit 120, the second table lookup unit 130, and the third table lookup unit 140 can be collectively referred to as a first table lookup unit group.
[0017] The first table lookup unit 120 uses the first bit block FP_1 as an index and performs a table lookup to obtain a first floating point number FP_1 ′ (ie, a table lookup result).
[0018] The second table lookup unit 130 uses the second bit block FP_2 as an index and performs a table lookup to obtain a second floating point number FP_2′.
[0019] The third table lookup unit 140 uses the third bit block FP_3 as an index and obtains a third floating point number FP_3′ after performing a table lookup.
[0020] The operation unit 150 operates the first floating point number FP_1', the second floating point number FP_2' and the third floating point number FP_3' to obtain an operation result OUT. The operation performed by the operation unit 150 is, for example but not limited to, at least one of addition, subtraction, multiplication, division, table lookup, or any combination thereof.
[0021] To better understand the operating principle of the computing device 100 of the embodiment of the present invention, please refer to Figures 2 to 4 . Figures 2 to 4 Schematic diagrams showing various operations of the computing device 100 according to an embodiment of the present invention. Figure 2 A schematic diagram showing the operation of the computing device 100 performing a reciprocal operation according to an embodiment of the present invention. Figure 3 A schematic diagram showing the operation of the computing device 100 performing a reciprocal square root operation according to an embodiment of the present invention. Figure 4 A schematic diagram showing the operation of the computing device 100 performing trigonometric function arctan according to an embodiment of the present invention.
[0022] Figure 2 A schematic diagram showing the operation of the computing device 100 of an embodiment of the present invention for performing a reciprocal operation. Figure 2 In the example, the floating point input data FP is described using the format of Bfloat16, but the present invention is not limited thereto.
[0023] At Figure 2 In the calculation, the calculation is to obtain -1.25*2 21 The reciprocal of, -1.25*2 21 If it is expressed in Bfloat16 format, it is as follows: -1.25*2 21 =1100101000100000 (16 bits), wherein the 1-bit sign S2 is 1, the 8-bit exponent E2 is 10010100, and the 7-bit fraction M2 is 0100000.
[0024] After the bit arrangement or format conversion by the bit arrangement unit 110 , the bit arrangement unit 110 generates a first bit block FP_1 , a second bit block FP_2 , and a third bit block FP_3 . It is assumed that the first bit block FP_1 is empty.
[0025] How to generate the second bit block FP_2 and the third bit block FP_3 will be described below.
[0026] The second bit block FP_2 includes 16 bits, of which 7 bits are dummy bits D1 (0000000), and the other 9 bits are a combination of a 1-bit sign S2 and an 8-bit exponent E2 (110010100).
[0027] The third bit block FP_3 includes 16 bits, of which 9 bits are redundant bits D2 (000000000) and the other 7 bits are fractional bits M2 (0100000).
[0028] The second bit block FP_2 and the third bit block FP_3 are input to the second look-up table unit 130 and the third look-up table unit 140 respectively.
[0029] The second table lookup unit 130 uses the second bit block FP_2 as an index to perform table lookup. An example of the second table lookup unit 130 is shown below, but the present invention is not limited thereto:
[0030] The second table lookup unit 130:
[0031] index Table Lookup Results 0 unlimited 1 <![CDATA[2 126 ]]> 2 <![CDATA[2 125 ]]> … 404 <![CDATA[-2 -21 ]]> … …
[0032] Since the second bit block FP_2 is 0000000110010100=404, after looking up the table, we can get -2 -21 That is to say, the table lookup result of the second table lookup unit 130 is the inverse of the second bit block FP_2.
[0033] Similarly, the third table lookup unit 140 uses the third bit block FP_3 as an index to perform table lookup. An example of the third table lookup unit 140 is shown below, but it should be understood that the present invention is not limited thereto:
[0034] The third table lookup unit 140:
[0035] index Table Lookup Results 0 1 1 0.9921875 2 0.984375 … 32 0.8 … …
[0036] Since the third bit block FP_2 is 0000000000100000=32, 0.8 can be obtained after table lookup. In other words, the table lookup result of the third table lookup unit 140 is the inverse of the third bit block FP_3.
[0037] The operation unit 150 performs an operation (herein, multiplication is used for illustration) on the table lookup result of the second table lookup unit 130 and the table lookup result of the third table lookup unit 140. Therefore, the operation result OUT=(-2 -21 )*0.8=0.8*(-2 -21 )=-1.6*(2 -22 ).
[0038] Figure 3A schematic diagram showing the operation of the computing device 100 of an embodiment of the present invention for performing a reciprocal square root operation. Figure 3 In the example, the floating point input data FP is described in the format of Bfloat16, but it should be understood that the present invention is not limited thereto.
[0039] At Figure 3 In the calculation, the calculation is to obtain 1.25*2 21 The reciprocal square root of is 1.25*2 21 If it is expressed in Bfloat16 format, it is as follows: 1.25*2 21 =0100101000100000 (16 bits), wherein the 1-bit sign S2 is 0, the 8-bit exponent E2 is 10010100, and the 7-bit fraction M2 is 0100000.
[0040] After the bit arrangement or format conversion by the bit arrangement unit 110 , the bit arrangement unit 110 generates a first bit block FP_1 , a second bit block FP_2 , and a third bit block FP_3 . It is assumed that the first bit block FP_1 is empty.
[0041] How to generate the second bit block FP_2 and the third bit block FP_3 will be described below. When generating the second bit block FP_2 and the third bit block FP_3, the exponent E2 is shifted, and the details will be described below.
[0042] The second bit block FP_2 includes 16 bits, of which 8 bits are redundant bits D3 (00000000), and the other 8 bits are a combination of a 1-bit symbol S2 and a 7-bit exponent E2" (01001010), wherein the 7-bit exponent E2" (1001010) is the first 7 bits of the 8-bit exponent E2 (10010100).
[0043] The third bit block FP_3 includes 16 bits, of which 8 bits are redundant bits D4 (00000000), and the other 8 bits are a combination of a 1-bit exponent E2' and a 7-bit fraction M2 (00100000), wherein the 1-bit exponent E2' (0) is the last bit of the 8-bit exponent E2 (10010100).
[0044] The second bit block FP_2 and the third bit block FP_3 are input to the second look-up table unit 130 and the third look-up table unit 140 respectively.
[0045] The second table lookup unit 130 uses the second bit block FP_2 as an index to perform table lookup. An example of the second table lookup unit 130 is shown below, but it should be understood that the present invention is not limited thereto:
[0046] The second table lookup unit 130:
[0047]
[0048]
[0049] Since the second bit block FP_2 is 0000000010010100=74, we can get 2 -10 The table lookup result of the second table lookup unit 130 is the reciprocal square root of the second bit block FP_2.
[0050] Similarly, the third table lookup unit 140 uses the third bit block FP_3 as an index to perform table lookup. An example of the third table lookup unit 140 is shown below, but it should be understood that the present invention is not limited thereto:
[0051] The third table lookup unit 140:
[0052] index Table Lookup Results 0 0.70703125 1 0.703125 2 0.703125 … 32 0.6328125 … …
[0053] Since the third bit block FP_2 is 0000000000100000=32, 0.6328125 can be obtained after table lookup. In other words, the table lookup result of the third table lookup unit 140 is the reciprocal square root of the third bit block FP_3.
[0054] The operation unit 150 performs an operation (herein, multiplication is used for illustration) on the table lookup result of the second table lookup unit 130 and the table lookup result of the third table lookup unit 140. Therefore, the operation result OUT=(2 -10 )*0.6328125=1.265625*(2 -11 ).
[0055] Figure 4 A schematic diagram showing the operation of the computing device 100 of an embodiment of the present invention to obtain the trigonometric function arctan. Figure 4 In the example, the floating point input data FP is described in the format of Bfloat16, but it should be understood that the present invention is not limited thereto.
[0056] At Figure 4 The calculation is to find 1.25*2 2 The trigonometric function arctan result is 1.25*2 2 If it is expressed in Bfloat16 format, it is as follows: 1.25*2 2 =0100000010100000 (16 bits), wherein the 1-bit sign S2 is 0, the 8-bit exponent E2 is 10000001, and the 7-bit fraction M2 is 0100000.
[0057] When calculating the result of the trigonometric function arctan, first calculate its reciprocal (the reason will be explained below). As for how to calculate the reciprocal, please refer to the above embodiment and will not be described in detail here. It is worth mentioning that Figure 4 The second bit block FP_2 includes 16 bits, of which 7 bits are redundant bits D5 (0000000), and the third bit block FP_3 includes 16 bits, of which 9 bits are redundant bits D6 (000000000). 1.25*2 2 The reciprocal of is 1.6*2 -3 .
[0058] exist Figure 4 In the embodiment, the operation unit 150 includes a multiplication unit 151, a comparator 152, a multiplication unit 153, a quantization unit 154, a fourth table lookup unit 155 and a fifth table lookup unit 156. The fourth table lookup unit 155 and the fifth table lookup unit 156 can be collectively referred to as a second table lookup unit group.
[0059] The multiplication unit 151 is used for multiplying the table lookup result of the second table lookup unit 130 and the table lookup result of the third table lookup unit 140 to obtain a first multiplication result.
[0060] The comparator 152 compares the floating point input data FP with its inverse result to obtain a comparison result. In a possible example, the comparison result is the smaller of the floating point input data FP and its inverse result. In this example, the floating point input data FP is 1.25*2 2 The reciprocal result is 1.6*2 -3 , so the comparator 152 outputs the inverse result (1.6*2 -3 ).
[0061] The multiplication unit 153 multiplies the comparison result of the comparator 152 by a constant to obtain a second multiplication result. For example but not limited to, the constant is 100. In the above example, the second multiplication result is 100*(1.6*2 -3 )=20.
[0062] The quantization unit 154 quantizes the second multiplication result of the multiplication unit 153 to an integer operation to obtain a quantization result. If the quantization result of the quantization unit 154 is less than or equal to 1, the fourth table lookup unit 155 performs a table lookup using the quantization result of the quantization unit 154 as an index. If the quantization result of the quantization unit 154 is greater than 1, the fifth table lookup unit 156 performs a table lookup using the quantization result of the quantization unit 154 as an index.
[0063] In this example, since the operation result of the quantization unit 154 is greater than 1, the fifth table lookup unit 156 performs table lookup. Similarly, the fifth table lookup unit 156 performs table lookup using the operation result of the quantization unit 154 as an index. An example of the fourth table lookup unit 155 and the fifth table lookup unit 156 is shown below, but it should be understood that the present invention is not limited thereto:
[0064] The fourth table lookup unit 155:
[0065]
[0066]
[0067] The fifth table lookup unit 156:
[0068] index Table Lookup Results 0 90 … ... 20 78.5 100 45 … …
[0069] The result of the table lookup performed by the fifth table lookup unit 156 using the operation result (20) of the quantization unit 154 as an index is 78.5, so the operation result OUT = 78.5. That is, the result of the trigonometric function arctan (1.25*22) is 78.5.
[0070] Figure 5A Displays a graph of the trigonometric function arctan. Figure 5B A diagram showing the relationship between the index of the fourth table lookup unit 155 and the table lookup result. Figure 5C A diagram showing the relationship between the index of the fifth table lookup unit 156 and the table lookup result.
[0071] like Figure 5A As shown, the value (y value) of the trigonometric function arctan slowly saturates. When x is less than 1, the value (y value) of the trigonometric function arctan presents a linear relationship; when x is greater than 1, the value (y value) of the trigonometric function arctan presents a reciprocal relationship.
[0072] Therefore, in the embodiment of the present invention, when designing the fourth table lookup unit 155, the index of the fourth table lookup unit 155 and the table lookup result can be regarded as presenting a linear relationship, such as Figure 5B When designing the fifth table lookup unit 156, the index of the fifth table lookup unit 156 and the table lookup result can be considered to present a nonlinear relationship (or, the inverse of the index of the fifth table lookup unit 156 (1 / x) and the table lookup result can be considered to present a linear relationship), as shown in FIG. Figure 5C shown.
[0073] Therefore, in the embodiment of the present invention, the smaller of the floating point input data FP and its reciprocal is first found, and then the smaller of the floating point input data FP and its reciprocal is used as a basis for subsequent operations to find the result of the trigonometric function arctan by looking up a table.
[0074] The embodiments of the present invention may be applied to various fields, such as but not limited to computer vision applications, AI training, and AI inference.
[0075] In addition, the embodiments of the present invention can achieve special operations without the need for a CPU, thereby significantly reducing the cost required for special operations.
[0076] The embodiment of the present invention may be suitable for a multi-core parallel computing system.
[0077] Of course, the present invention may have many other embodiments. Without departing from the spirit and essence of the present invention, those skilled in the art may make various corresponding changes and modifications based on the present invention, but these corresponding changes and modifications should all fall within the scope of protection of the claims attached to the present invention.
Claims
1. A floating point function calculation table lookup computing device, characterized in that: include: A bit arrangement unit receives a floating point input data and performs bit arrangement or format conversion on the floating point input data to generate a plurality of bit blocks; a first table lookup unit group, receiving the plurality of bit blocks, and performing a table lookup using the plurality of bit blocks as indexes to obtain a plurality of table lookup results; as well as A computing unit, which computes the plurality of table lookup results of the first table lookup unit group to obtain a computing result; wherein the computing unit specifically comprises: a first multiplication unit for multiplying the plurality of table lookup results of the first table lookup unit group to obtain a first multiplication result; a comparator, comparing the first multiplication result with the floating point input data to output a comparison result; a second multiplication unit, multiplying the comparison result of the comparator by a constant to obtain a second multiplication result; a quantization unit, quantizing the second multiplication result of the second multiplication unit to an integer operation to obtain a quantization result; and A second table lookup unit group uses the quantization result of the quantization unit as an index to perform table lookup to obtain the operation result.
2. floating point number function operation table look-up computing device as claimed in claim 1, it is characterized in that, The floating point input data includes various formats.
3. floating point number function operation table look-up computing device as claimed in claim 1, it is characterized in that, The formats of the floating point input data include tensor float32 and 16-bit brain float.
4. floating point number function operation table look-up computing device as claimed in claim 1, it is characterized in that, The operations performed by the operation unit include at least one of the following or any combination thereof: addition, subtraction, multiplication, division, and table lookup.
5. floating point number function operation table look-up computing device as claimed in claim 1, it is characterized in that, The floating point input data includes a plurality of bit groups, and at least one bit block of the plurality of bit blocks includes: a plurality of redundant bits and the plurality of bit groups of the floating point input data.
6. floating point number function operation table look-up computing device as claimed in claim 1, it is characterized in that, The comparison result of the comparator is a smaller one between the first multiplication result and the floating point input data.
7. floating point number function operation table look-up computing device as claimed in claim 1, it is characterized in that, According to whether the quantization result of the quantization unit is less than or equal to 1, one of the table lookup units is selected from the second table lookup unit group to perform table lookup using the quantization result of the quantization unit as an index to obtain the operation result.
Citation Information
Patent Citations
High-speed floating-point division unit based on table look-up
CN104615404A