Floating point unit for exponential function implementation

By using two fully pipelined instructions and a segmented linear mapping function in a floating-point unit, the problem of exponential calculation is solved and the cost of energy is high, and efficient exponential calculation is realized, suitable for neural networks and machine learning algorithms.

CN112241291BActive Publication Date: 2024-11-08INTERNATIONAL BUSINESS MACHINE CORPORATION
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010690694.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2019-07-18
Filing Date
2020-07-17
Publication Date
2024-11-08
Estimated Expiration
2040-07-17

AI Technical Summary

Technical Problem

In the prior art, exponential calculations are time-consuming and energy-cost in neural networks and machine learning algorithms, especially in deep neural networks and other calculations, resulting in computing resource-intensive and inefficient.

Method used

By using two fully pipelined instructions in a floating point unit to calculate the exponential function, first multiply the input operand with a predetermined constant value, convert it into an integer representation, and then use a segmented linear mapping function to calculate the mantis digit of the exponential result, significantly reducing Calculation steps.

Benefits of technology

The same accuracy as traditional methods are achieved, while significantly reducing computation time and energy costs, at least the number of instructions and delays are reduced, suitable for machine learning assignments of different precisions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112241291B_ABST
    Figure CN112241291B_ABST
Patent Text Reader

Abstract

A computer-implemented method, system, and computer program product for performing exponential calculations in a floating point unit including an estimation block using only two fully pipelined instructions. The method includes calculating an intermediate value y' by multiplying an input operand by a predetermined constant value. The input operand is received in floating point representation. The method also includes calculating an exponential result of the input operand by running a fused instruction. The fused instruction includes converting the intermediate value y' into an integer representation z represented by v most significant bits (MSBs) and w least significant bits (LSBs). The fused instruction also includes determining exponent bits of the exponential result based on the v MSBs in the integer representation z. The method also includes determining mantissa bits of the exponential result based on the w LSBs in the integer representation z using a predetermined number of segments according to a piecewise linear mapping function.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates generally to computer technology and, more particularly, to a floating point unit that provides improved exponential calculations with at least state-of-the-art accuracy while significantly reducing computation time and energy costs. Background Art

[0002] Neural network calculations and other machine learning algorithms often use exponential (e.g., exp(); or exponentiation) functions to perform one or more operations that require nonlinear functions. For example, among other uses, activation functions and probability distributions used in neural network models use exponential functions. For example, machine learning calculations, such as deep neural networks (DNNs), convolutional neural networks (CNNs), and recurrent neural networks (RNNs), rely heavily on exponential calculations in softmax, sigmoid, hyperbolic functions, etc. Therefore, most of the time spent on neural simulations is actually spent on exponential calculations. Summary of the Invention

[0003] According to one or more embodiments of the present invention, a computer-implemented method is described for calculating an exponential calculation using only two fully-pipelined instructions using a floating-point unit including an estimation block. The computer-implemented method includes calculating an intermediate value y' by multiplying an input operand by a predetermined constant value. The input operand is received in floating-point representation. The method also includes calculating an exponential result for the input operand by executing a fused instruction. The fused instruction includes converting the intermediate value y' into an integer representation z represented by v most significant bits (MSBs) and w least significant bits (LSBs). The fused instruction also includes determining exponent bits of the exponential result based on the v MSBs in the integer representation z. The method also includes determining mantissa bits of the exponential result based on the w LSBs in the integer representation z using a predetermined number of segments according to a piecewise linear mapping function.

[0004] According to one or more embodiments of the present invention, a system includes a processor and a floating point unit communicatively coupled to the processor. The floating point unit includes an estimation block that performs a method for fast exponential calculation using only two fully pipelined instructions. The method includes calculating an intermediate value y' by multiplying an input operand with a predetermined constant value. The input operand is received in floating point representation. The method also includes calculating an exponential result of the input operand by running a fusion instruction. The fusion instruction includes converting the intermediate value y' into an integer representation z represented by v most significant bits (MSBs) and w least significant bits (LSBs). The fusion instruction also includes determining an exponent bit of the exponent result based on the v MSBs in the integer representation z. The method also includes determining a mantissa bit of the exponent result according to a piecewise linear mapping function based on the w LSBs in the integer representation z using a predetermined number of segments.

[0005] According to one or more embodiments of the present invention, a system includes a neural network and a floating-point unit coupled to the neural network. The floating-point unit calculates one or more mathematical operations instructed by the neural network. The mathematical operations include an exponential function, wherein the exponential function is calculated using a method for performing fast exponential calculations using only two fully pipelined instructions. The method includes calculating an intermediate value y' by multiplying an input operand by a predetermined constant value. The input operand is received in floating-point representation. The method also includes calculating an exponential result for the input operand by executing a fused instruction. The fused instruction includes converting the intermediate value y' into an integer representation z represented by v most significant bits (MSBs) and w least significant bits (LSBs). The fused instruction also includes determining exponent bits of the exponential result based on the v MSBs of the integer representation z. The method also includes determining mantissa bits of the exponential result based on the w LSBs of the integer representation z using a predetermined number of segments according to a piecewise linear mapping function.

[0006] The above features may also be provided at least by a system, a computer program product, and a machine, among other types of implementations.

[0007] Additional technical features and benefits are achieved through the technology of the present invention. Various embodiments and aspects of the present invention are described in detail herein and are considered to be part of the claimed subject matter. For a better understanding, please refer to the detailed description and drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0008] The details to which the proprietary rights described herein are particularly pointed out and distinctly claimed are in the claims. The foregoing and other features and advantages of the embodiments of the present invention will become apparent from the following detailed description taken in conjunction with the accompanying drawings, in which:

[0009] Figure 1 depicts a flow chart of a method for calculating an exponential function according to one or more embodiments of the present invention;

[0010] Figure 2 depicts a visualization of an approximation of a decimal for a base-2 input according to one or more embodiments of the present invention;

[0011] Figure 3 depicts a block diagram of a floating point unit for performing exponential implementations according to one or more embodiments of the present invention;

[0012] Figure 4 Depicts a block diagram of an estimator module that calculates an estimated index for an input value according to one or more embodiments of the present invention;

[0013] Figure 5 A block diagram depicting a segment selection logic block that determines which piecewise mapping segment to select according to one or more embodiments of the present invention; and

[0014] Figure 6 Depicted is a block diagram of a neural network system using a floating point unit, in accordance with one or more embodiments of the present invention.

[0015] The diagrams described herein are illustrative. Without departing from the spirit of the present invention, many variations may be made to the diagrams or operations described therein. For example, actions may be performed in a different order, or actions may be added, deleted, or modified. In addition, the term "coupled" and its variants describe a communication path between two elements and do not imply a direct connection between the elements or the absence of an intermediate element / connection between them. All of these variations are considered part of the specification.

[0016] In the drawings and the following detailed description of the disclosed embodiments, the various elements shown in the drawings have two or three digit reference numerals. With few exceptions, the leftmost digit(s) of each reference numeral corresponds to the figure in which the element is first shown. DETAILED DESCRIPTION

[0017] Various embodiments of the present invention are described herein with reference to the accompanying drawings. Without departing from the scope of the present invention, alternative embodiments of the present invention may be devised. Various connections and positional relationships (e.g., above, below, adjacent, etc.) are described below and in the accompanying drawings between elements. These connections and / or positional relationships may be direct or indirect, unless otherwise specified, and the present invention is not intended to be limited in this respect. Therefore, the coupling of an entity may refer to direct or indirect coupling, and the positional relationship between the entities may be a direct or indirect positional relationship. In addition, the various tasks and process steps described herein may be incorporated into a more comprehensive program or process with additional steps or functions not described in detail herein.

[0018] The following definitions and abbreviations will be used to interpret the claims and description. As used herein, the terms "comprises," "comprising," "having," "containing," or any other variations thereof are intended to cover a non-exclusive inclusion. For example, a composition, mixture, process, method, article, or apparatus that comprises a list of elements is not necessarily limited to only those elements but may include other elements not expressly listed or inherent to such composition, mixture, process, method, article, or apparatus.

[0019] Additionally, the term "exemplary" is used herein to mean "serving as an example, instance, or illustration." Any embodiment or design described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments or designs. The terms "at least one" and "one or more" may be understood to include any integer greater than or equal to 1, i.e., 1, 2, 3, 4, etc. The term "plurality" may be understood to include any integer greater than or equal to 2, i.e., 2, 3, 4, 5, etc. The term "connected" may include both indirect and direct "connections."

[0020] The terms "about," "substantially," "approximately," and variations thereof are intended to include the degree of error associated with measurement of a particular quantity based on the equipment available at the time the application is filed. For example, "about" may include a range of 8% or 5% or 2% of a given value.

[0021] For the sake of brevity, conventional techniques related to making and using various aspects of the present invention may or may not be described in detail herein. In particular, various aspects of computing systems and specific computer programs for implementing the various technical features described herein are well known. Therefore, for the sake of brevity, many conventional implementation details are briefly mentioned herein or omitted entirely, without providing well-known system and / or process details.

[0022] As mentioned above, various computer algorithms, such as machine learning calculations (e.g., DNN, CNN, and RNN), rely heavily on exponential calculations (exp()) in their softmax, sigmoid, hyperbolic functions, etc. For example, the sigmoid function includes the following calculations:

[0023]

[0024] The softmax function includes the following calculations:

[0025]

[0026] Similarly, various other nonlinear calculations often use exponential calculations, and such nonlinear calculations are used in several popular algorithms. However, typical computers are integer machines and can only represent real numbers using complex codes. The most popular code for representing real numbers is called the IEEE floating-point standard. Most floating-point numbers that a computer can represent are only approximations. One challenge in programming with floating-point values ​​is ensuring that the approximations lead to reasonable results. Small differences in the approximations can cause the final result to be substantially inaccurate. In addition, because mathematical operations using floating-point numbers are computationally intensive, the microprocessor in a computer typically includes a chip called a floating point unit (FPU) that is specifically designed to perform floating-point arithmetic. The FPU is also called a math coprocessor and a digital coprocessor. The FPU can be part of the microprocessor chip itself, or a separate chip coupled to the microprocessor. One of the common functions that the FPU estimates based on instructions is the exponential calculation function.

[0027] Typically, exponential calculations are performed using a math library and a function call (e.g., exp(a)) to calculate the exponential using the provided parameters. The exponential calculation functions provided by typical computer math libraries are highly accurate, but computationally expensive and slow. A typical exponential function implementation combines the results by looking up instructions + Taylor expansion + instructions. It requires a series of computer instructions (e.g., 14 instructions) to achieve appropriate accuracy using existing technology and existing floating-point unit hardware. Therefore, neural network calculations typically spend a lot of time running instructions for performing exponential calculations. In addition to the amount of time required, the energy cost, and the computing resources busy running these instructions, there is also a technical problem.

[0028] In the case of machine learning algorithms, an approximation of the exponential function may be sufficient, such as for typical neural computing purposes. This is particularly useful when the input format of the machine learning algorithm has low precision (such as 16 bits). Performing such an approximation can save time. Recognizing this, many existing software packages typically use linear interpolation to approximate the exponential function using a lookup table.

[0029] Turning now to an overview of various aspects of the present invention, embodiments of the present invention address the above-mentioned shortcomings in the prior art by providing a computing system configured to facilitate the use of a hardware implementation for computing an exponential function, which provides an accurate computation of the exponential function that can achieve the accuracy of standard machine learning tasks such as ImageNet classification while significantly reducing computation time and energy costs. Using an FPU according to one or more embodiments of the present invention provides at least the same level of accuracy as a baseline high-precision implementation at the task level. For example, in the case of a neural network for classifying images, the number / proportion of images correctly labeled using the FPU must match (or exceed) the baseline implementation (not using an FPU according to one or more embodiments of the present invention). In addition, implementations according to one or more embodiments of the present invention are customized for machine learning tasks of various precisions and can be verified on a hardware simulation platform. Therefore, one or more embodiments of the present invention solve the technical challenges described herein and provide practical applications for improving the performance of computers (particularly floating point units (or other arithmetic units)) by providing a hardware implementation for computing an exponential function. Based on the description herein, other advantages provided by one or more embodiments of the present invention will be apparent to those skilled in the art.

[0030] Figure 1 A flow chart of a method 100 for calculating an exponential function according to one or more embodiments of the present invention is depicted. Method 100 includes executing two instructions to calculate an exponential function. The first instruction 102 multiplies an input by a constant. The input is a floating-point input. Furthermore, the second instruction 104 includes a floating-point to integer calculation followed by a piecewise linear function calculation (addition of three terms), wherein only a single lookup is used to access the constant, which is one of the three terms in the sum.

[0031] The method 100 includes receiving an input value X for which an exponent is to be calculated at 110. The input X is received in floating point representation (i.e., represented as fx). In addition, the method 100 includes converting from base e to base 2 at 120 and applying a predetermined scaling. This operation can be represented as:

[0032] e x =2 y →y=x / ln2→y′=x*2 m / ln2

[0033] Here, m is a predetermined constant. According to one or more embodiments of the present invention, m is pre-configured to be 11. In order to use the floating point unit to calculate y' in the above expression, y' can be calculated by a floating point (FP) multiplication instruction using operand x and 2048 / ln(2). In order to perform the above calculation, the value FA=float(2 11 / ln(2)), where m=11, and y' can be calculated by executing the FP multiplication instruction y'=FA*fx. The obtained y' is a floating point value.

[0034] The method 100 further includes, at 130, performing a shift by p bits and a two's complement operation on the negative input, with the value y' as input. This operation converts y' into an integer z, i.e., a p-bit integer (i.e., comprising p bits). In addition, the p bits of z are divided into two parts, a first part v, consisting of the most significant bits of z, and a second part w, consisting of the m least significant bits of z. It should be noted that using 2 m Scaling the input operand (at 120) helps to make the integer z include m decimal places of the intermediate value y, represented by the quantity w. In addition, to obtain the exponent of the input operand x, we need to calculate 2 by the following calculation as shown y :

[0035]

[0036]

[0037] Here, 2 v Can be used as the exponent value of a floating-point number representing the result of an exponential calculation, and 2 (0.w) Represents a value in the range [1, 2), similar to the mantissa 1.f of a floating-point number. Note that "m" is the same value used in the previous operation, for example, m = 11.

[0038] It should be noted that the IEEE 754 format for floating point numbers consists of three fields: the sign bit, the biased exponent, and the fraction. The following example illustrates the meaning of each. The decimal number 0.15625 represented in binary is 10 is 0.001012 (i.e., 1 / 8 + 1 / 32). (The subscript indicates the base of the value.) Similar to scientific notation, in which a value is written with a single non-zero digit to the left of the decimal point, this value can be rewritten so that it has a single 1 digit to the left of the "binary point." This shift of the bits left by three places is compensated for by multiplying by the appropriate power of 2: 0.001012 = 1.012 × 2 -3 .

[0039] In this example, the decimal is .012 and the exponent is -3. Therefore, the three fields in the IEEE 754 representation of this number are:

[0040] 1. Sign = 0, because the value is positive (1 indicates negative);

[0041] 2. Bias exponent = -3 + "bias". In single precision, the bias is 127, so the bias exponent in this example is 124; in double precision, the bias is 1023, so the bias exponent in this example is 1020; and

[0042] 3. Decimal = .01000…2.

[0043] According to the IEEE 754 standard, a bias is added to the exponent to obtain the final result. It should be noted that while the IEEE 754 standard is described herein, in one or more embodiments of the present invention, a different standard may be used without exceeding the scope of the technical features described herein. In 16-bit floating point representation, the format is assumed to have an implicit leading bit with a value of 1 unless the exponent field is stored as all zeros. Therefore, only 9 bits of significand appear in the memory format, but the total precision is 10 bits. In IEEE 754 parlance, there are 9 bits of significand, but 10 bits of significand precision (log10(2 10 )≈3.010 decimal digits, or 4 digits ± slightly less than 5 units of the last digit). It should be understood that although the description of one or more embodiments of the present invention uses a 16-bit precision format, other floating point representations may be used in other embodiments of the present invention.

[0044] refer to Figure 1 The method 100 further comprises, at 140, calculating 2 v The MSBn bits are used to calculate the integer of the input to base 2, and the bias is added to the result to obtain the exponent bits.

[0045] Furthermore, to calculate the decimal of a base-2 input, method 100 includes computing an approximation 1.f via a piecewise linear function: mi*(0.w)+ci, where i is a predetermined number of segments, such as 6. In one or more embodiments of the present invention, the approximation function is customized so that the multiplication (mi*(0.w)) can be replaced by a 2-way addition. This saves computational resources because multiplications are more computationally intensive than additions.

[0046] Figure 2A visualization of an approximation of a decimal for a base 2 input according to one or more embodiments of the present invention is depicted. As shown, in the case of m=11, the range of possible decimal values ​​based on the 4 MSBs of the decimal is divided into a predetermined number of segments, in this case 6. The approximation can be looked up in a table including the values ​​of the depicted graph 200. It can be seen that the approximation on curve 220 may not be exactly equal to the 2 on curve 210. (0.w) value. However, this approximation is sufficient to use the resulting exponential value in machine learning algorithms and other types of applications. The endpoints are exact, making the function continuous even across binades. A binade is a set of binary floating-point values ​​that all have the same sign and exponent. A binade attribute is a member of the same binade as the value, but with a single-digit significand. For example, consider the value x of 21.5, which is stored as 1.34375*2^4, where ^ represents exponentiation. Therefore, x.binade equals 1.0*2^4, or 16.0.

[0047] In method 100, at 150, a lookup table is generated for a piecewise linear approximation using a predetermined number of segments, and a linear approximation is calculated for the fractional digits to obtain the mantissa digits of the exponential result. In existing solutions, for each binade / exponent value, the fractional digit is obtained by a single linear function: A*f+B. In one or more embodiments of the present invention, a piecewise linear approximation is performed: that is, for each binade, the fractional equation is composed of multiple linear segments, wherein a predetermined number of linear segments (such as Figure 2 6 of ). The piecewise linear approximation provides a better approximation of the fractional part.

[0048] Furthermore, in method 100, an out-of-range check is performed on the y' value to determine whether overflow, underflow, or any special case has occurred, such as an input of zero, positive / negative infinity, not-a-number (NaN), or any other special case provided by a floating-point standard such as IEEE 754. In this case, at 160, the corresponding result can be forced into the output of the exponential specified by the floating-point standard. The exponential function causes the floating-point unit to operate only when the input is within a predetermined range, due to the range of floating-point numbers that the floating-point unit can represent. Therefore, the method includes checking for out-of-range scenarios and providing a mathematically acceptable value when such a situation is detected. For example, when the input x is a very large negative number, then mathematically, the result of exp(x) is very close to zero. Therefore, method 100 delivers zero when it is detected that the input value is below a predetermined value. Similarly, when the input value is within any other such specified range, the predetermined output of the exponential function is provided.

[0049] At 170 , the results from the special case determination, the exponent determination, and the mantissa bit determination are combined to determine a final output of the exponent value for the received input x. The result is then output at 180 .

[0050] Figure 3 A block diagram of a floating point unit for performing an exponential implementation according to one or more embodiments of the present invention is depicted. The floating point unit 300 can be part of a central processing unit or a coprocessor in a computing device. The floating point unit 300 can include modules such as a carry save adder (CSA) 330, an adder 335, a leading zero anticipator (LZA) 340, a normalizer 345, and various other modules. These blocks help perform floating point operations such as addition, multiplication, etc. after shifting the bits in the operands to align the bits according to the exponent / weight.

[0051] The floating point unit 300 includes an unpacking module 310 that unpacks the input floating point value (fx) provided to the exponential function. Unpacking determines the sign, biased exponent portion, and fractional portion of the input operand(s) typically accessed from registers. In addition, the floating point unit 300 includes a multiplier 315, a shifter 325, and an exponent shifter 320, which together are used to scale the input (fx) by calculating y'=FA*fx, as described herein ( Figure 1 , 120). In one or more embodiments of the invention, the multiplication and the shift are performed in parallel.

[0052] It should be noted that the scaling is done in floating point representation (not integer), followed by a floating point to integer conversion by pre-calculating FA = float(2^m / ln(2)), and then calculating the scaling Y = FA*fx still in floating point representation. Performing the scaling in floating point representation results in less rounding error than performing the floating point to integer conversion first and then performing the scaling.

[0053] In addition, the product from multiplier 315 may include a carry bit and a product bit vector, both of which are fed to CSA 330. CSA 330 also receives the output from aligner 325. The two outputs of CSA 330 are passed through a conventional adder 335. To represent the output of adder 335 in floating point form, normalizer 345 shifts the bits to represent the result in a sign, exponent, and mantissa format. For example, normalizer 345 shifts the bits to remove leading zeros that can be counted by LZA 340. LZA 340 can operate in parallel with adder 335.

[0054] Round and pack module 350 receives a floating point result from one or more operations performed by floating point unit 300. In one or more examples, the floating point result may have more bits than the input operands of floating point unit 300.

[0055] In the event that the floating point unit receives an instruction to compute the exponent of an input operand (fx), the aligner 325 computes the value z as previously described, where z=vw, where v represents the n MSBs of y' and w represents the m LSBs of y', where y'=FA*fx. Figure 3 In the blocks shown, for purposes of explanation, w is shown as the least significant 11 bits of z, while v is the remaining bits of z. It should be noted that while the example scenarios described herein use the aforementioned number of bits for w and v (and other predetermined values), in other embodiments of the present invention, these values ​​may be different.

[0056] The w bits are input to an estimator module 365 which computes the mantissa portion of the exponent result, which in this case is a 9-bit fractional value of the exponent result.The estimator module 365 also receives the sign bit of the input operand.

[0057] The v bits are input to an out of range module 360, which determines whether the input operands fall within a predetermined range for which a specific exponent result will be output. The out of range module 360 ​​also receives the sign bit of the input operands. The out of range module 360 ​​detects whether the input operands fall within a specific predetermined range and, if so, provides a corresponding predetermined output value as the exponent value result. The output is forwarded to the rounding and packing module 350.

[0058] The exponent logic module 370 , which calculates the exponent bits of the exponent result, also receives v bits. The exponent bits are forwarded to the rounding and packing module 350 .

[0059] Thus, the round and pack module 350 receives the fractional bits (mantissa) from the estimator module 365, the exponent bits from the exponent multiplexer 370, and the result from the overrange module 360. If the overrange module 360 ​​indicates that the input operand is a special case, the exponent bits and the mantissa bits are ignored, and the special predetermined result from the overrange module 360 ​​is output as the exponent result. Otherwise, the round and pack module 350 uses the calculated exponent bits and mantissa bits to provide the exponent result in floating point representation.

[0060] Exponent logic module 370 also receives a bias signal from estimator module 365. The bias signal indicates whether to add a bias value or a "bias + 1" value when generating the exponential result from the mantissa and exponent bits. If the result is the next binade, the "bias + 1" value is added; otherwise, the bias value is added.

[0061] Figure 4 A block diagram of an estimator module that calculates an estimated exponent of an input value in accordance with one or more embodiments of the present invention is depicted. The estimator module 365 facilitates calculating an approximation 1.f via a piecewise linear function: mi*(0.w)+ci, where i is a predetermined number of segments. To perform this, the estimator module 365 receives w bits of z. As previously described, in this example scenario, w comprises m=11 bits, and the use of i=6 segments to perform the piecewise linear mapping is also considered. Thus, the block diagram shows a 6:1 multiplexer being used. In other embodiments where a different number of segments are used for the piecewise linear mapping, the multiplexer will be different. The value of c is a predetermined constant.

[0062] The estimator module 365 calculates the fractional portion of the exponential result, which is forwarded to the rounding and packing module 350. The estimator module 365 also forwards a bias signal indicating a bias value that will be combined with the fractional portion to calculate the final exponential result.

[0063] The estimator module 365 includes a segment selection logic block 410 that provides a selection signal to a multiplexer 415 to select one of a predetermined (i=6) segment. The multiplexer 415 outputs an approximate fractional value based on the selected segment to the CSA 440. In addition, the CSA 440 receives w bits in order to calculate the term mi*(0.w) from the above expression using the output of the multiplexer 415.

[0064] The select signal for the segment is also provided to multiplexer 420. Multiplexer 420 calculates the ci term from the expression using predetermined constants and the selected segment. The output of multiplexer 420 is also provided to CSA 440.

[0065] Furthermore, the estimator module 365 includes a deviation signal calculator 430 that receives a sign bit and w bits. The deviation signal calculator 430 determines whether a binade boundary is crossed for the input operand. If so, the deviation signal is set to indicate that a "bias + 1" value is to be added when calculating the final exponential result. Otherwise, the deviation signal indicates that only the deviation is to be added when calculating the exponential result. It should be noted that the output of the adder 450 is a 12-bit value representing the mantissa bits of the exponential result. However, to accommodate a 16-bit floating-point representation, the output of the exponential result must be formatted with 1 sign bit, 6 exponent bits, and 9 mantissa bits. Therefore, the output of the estimator module 365 will have 9 decimal places for the mantissa bits. Therefore, the estimator module 365 uses rounding, such as a round nearest up (RNU) rounding mode. This affects how the deviation signal is calculated, as rounding results in an increase in the exponent. For example, the following situation may occur: if the value is negative and close enough to the upper boundary of the binade interval, and if the mantissa of the approximated result is close to 2.0, and due to rounding, it is rounded to 2.0. In this case, the exponent must be increased. Therefore, in one or more embodiments of the present invention, the deviation signal is calculated as: deviation signal = and_reduce(w(10:1)).

[0066] The error signal calculator 430 also calculates the correction bit (C b ). The mathematical representation of the calculations performed by the estimator module 365 can be summarized as follows:

[0067]

[0068] The correction bit δ(1) is set to 1 if:

[0069]

[0070] Here, when the sign bit input to the deviation signal calculator 430 is 1, neg=1.

[0071] Adder 450 adds the correction bits and the output of CSA 440, which includes a carry bit and a sum bit vector, to generate the mantissa of the exponential result. Estimator module 365 outputs the mantissa bits (9 bits in this case) and a bias signal.

[0072] Figure 5 A block diagram of a segment selection logic block that determines which segment map segment to select according to one or more embodiments of the present invention is depicted. The segment selection logic block 410 includes a NOT gate 510 that outputs b=not(w). Based on the combination of bits in b and w, one of the corresponding predetermined segments is selected as an approximation of the fractional part. For example, in Figure 5 In the example shown, 11b(10:2) indicates that if the first two leading bits in bits (10-2) of b are 11, the value of the first segment is output. These segments (e.g., Figure 2 ) are mapped to w bits accordingly and are selected based on the w bits.

[0073] Figure 6 A block diagram of a neural network system using a floating point unit according to one or more embodiments of the present invention is depicted. The neural network system 610 may implement an artificial neural network such as a DNN, a CNN, or any other machine learning algorithm including computing an exponential function. In one or more examples, the neural network system 610 may include a floating point unit 300 as an integral part of one or more processors. Alternatively or additionally, the neural network system 610 may include a floating point unit 300 as a co-processor. It should be noted that while Figure 6 A single floating point unit 300 is depicted in FIG, but in one or more embodiments of the invention, neural network system 610 may use multiple floating point units 300 in parallel.

[0074] The neural network system 610 sends one or more instructions to the floating point unit to perform a corresponding mathematical operation on one or more floating point operands. One of the instructions may include calculating the exponent of an input operand that is a floating point representation. In this case, the floating point unit 300 uses the estimator module 365 and other modules described herein to estimate the exponent result and provide the output to the neural network system 610.

[0075] Thus, one or more embodiments of the present invention provide techniques for computing exponential functions, hardware implementations thereof, and use scenarios in machine learning tasks. One or more embodiments of the present invention have comparable accuracy to existing solutions using 16-bit precision, with at least a 7x reduction in instruction count and latency. One or more embodiments of the present invention can be implemented with only two fully pipelined instructions that use the hardware modules described herein. The first instruction is a multiplication by a constant. The second instruction is a floating point to integer calculation followed by a piecewise linear function calculation (addition of 3 terms), where only a lookup is used to obtain the constant that is one of the 3 terms.

[0076] As described herein, the above operations facilitate improved exponent estimation. This improvement includes improvements in speed and computational resources used, since the exponential function computation uses only two fully pipelined instructions to (1) transform the input from base "e" to base 2 and scale it by a power of 2; and (2) obtain the mantissa bits of the output via a piecewise linear function and a 3-way addition, which are then combined with the exponent bits to obtain the final result.

[0077] In addition, the exponential function calculation is customized for machine learning jobs of different precisions and verified on a hardware simulation platform.

[0078] At any possible level of technical detail combination, the present invention may be a system, method and / or computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present invention.

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

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

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

[0082] Various aspects of the present invention are described herein with reference to flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present invention. It should be understood that each block of the flowcharts and / or block diagrams, and combinations of blocks in the flowcharts and / or block diagrams, can be implemented by computer-readable program instructions.

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

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

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

[0086] While various embodiments of the present invention have been described above, the foregoing description is intended to be illustrative, non-exhaustive, and not limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is selected to best explain the principles of the embodiments, their practical applications, or technical improvements to existing technologies, or to enable others skilled in the art to understand the embodiments described herein.

Claims

1. A computer-implemented method for performing exponential calculations using only two fully pipelined instructions using a floating point unit including an estimation block, the computer-implemented method comprising: calculating an intermediate value y' by multiplying an input operand received in floating point representation by a predetermined constant value; and The exponential result of the input operand is calculated by executing a fused instruction, the fused instruction comprising: Convert the intermediate value y' to an integer representation z represented by v most significant bits (MSBs) and w least significant bits (LSBs); determining exponent bits of the exponent result based on the v MSBs of the integer representation z; and The mantissa bits of the exponential result are determined according to a piecewise linear mapping function using a predetermined number of segments based on the w LSBs in the integer representation z.

2. The computer-implemented method of claim 1 , wherein: The input operand is multiplied by a predetermined constant 2^m / ln2, where m is a predetermined value.

3. The computer-implemented method of claim 2, wherein: m is configured according to the processor's floating-point to integer conversion precision.

4. The computer-implemented method of claim 1 , wherein: Determining the mantissa bits includes mapping the w LSBs to [2^(w)-1] using the piecewise linear mapping function.

5. The computer-implemented method of claim 4, wherein: The piecewise linear mapping function is performed using a 3-way addition, and one operand in the 3-way addition is a shifted version of the input.

6. The computer-implemented method of claim 4, wherein: In response to the input operand being a negative value, the piecewise linear mapping includes only a 1's complement operation on a fractional portion of the input operand.

7. The computer-implemented method of claim 5, wherein: The 3-way addition also includes adding a bias value.

8. A system comprising: processor; and A floating point unit communicatively coupled to the processor, the floating point unit comprising an estimation block that performs the method according to any one of claims 1 to 7 for fast exponential calculation using only two fully pipelined instructions.

9. A computer system comprising a model of the method execution steps according to any one of claims 1 to 7.

10. A computer program product having a computer readable program code executable by one or more computer processors to perform the method according to any one of claims 1 to 7.

11. A system comprising: A floating point unit configured to calculate one or more mathematical operations in response to receipt of one or more instructions, the mathematical operations comprising an exponential function, wherein the exponential function is calculated by performing a method comprising: calculating an intermediate value y' by multiplying an input operand received in floating point representation by a predetermined constant value; The exponential result of the input operand is calculated by running a fused instruction on the intermediate value y', the fused instruction comprising: Convert the intermediate value y' to an integer representation z represented by v most significant bits (MSBs) and w least significant bits (LSBs); determining exponent bits of the exponent result based on the v MSBs of the integer representation z; and determining the mantissa bits of the exponential result according to a piecewise linear mapping function using a predetermined number of segments based on the w LSBs in the integer representation z; and The floating point unit is configured to return the exponent result to the floating point unit in response to the one or more instructions.

12. The system according to claim 11, wherein: The input operand is multiplied by a predetermined constant 2^m / ln2, where m is a predetermined value.

13. The system according to claim 11, wherein: Determining the mantissa bits includes mapping the w LSBs to [2^(w)-1] using the piecewise linear mapping function.

14. The system according to claim 13, wherein: The piecewise linear mapping function is performed using a 3-way addition, and one operand in the 3-way addition is a shifted version of the input.

15. The system of claim 13, wherein: In response to the input operand being a negative value, the piecewise linear mapping includes only a 1's complement operation on a fractional portion of the input operand.

16. The system of claim 14, wherein: The 3-way addition also includes adding a bias value.