A configurable transcendental function vector computing device

By designing a configurable transcendental function vector calculation device and using a lookup table for linear fitting, the problem of low calculation efficiency for input data above 8 bits is solved, and high-precision and efficient transcendental function calculations are achieved, which is suitable for neural network reasoning scenarios and complex Support multiple data types using lookup tables.

CN118378000BActive Publication Date: 2024-09-17安徽芯纪元科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410827057.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-25
Publication Date
2024-09-17
Estimated Expiration
2044-06-25

AI Technical Summary

Technical Problem

It is difficult for the existing technology to efficiently calculate input data of more than 8 bits for high-precision calculation of transcendental functions. The direct look-up table method has the problem of too large look-up table or loss of accuracy.

Method used

A configurable transcendental function vector calculation device is designed, including a vector operator, data input temporary storage module, state control module, configuration module and storage controller. It performs linear fitting through a lookup table and supports 8bit fixed point and 16/32bit. Floating point arithmetic uses configuration modules and software to load data in lookup tables to achieve calculations of various transcendental functions.

Benefits of technology

It realizes high-precision calculation of transcendental functions in neural networks, improves calculation efficiency, and is suitable for efficient neural network reasoning scenarios. It also reuses lookup tables to support 8-bit fixed-point and 16/32-bit floating-point calculations, saving on-chip area.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118378000B
    Figure CN118378000B
Patent Text Reader

Abstract

The invention relates to transcendental function calculation, and in particular to a configurable transcendental function vector calculation device. The transcendental function vector calculation unit comprises a vector operator, which completes vector addition, subtraction, multiplication and vector logic operations according to configuration information of a configuration module. When performing transcendental function calculation, each vector operator simultaneously performs 256 8-bit fixed-point operations or 64 16 / 32-bit floating-point operations; a state control module receives control signals from other modules and outputs the internal operation state of the transcendental function vector calculation unit to other modules; and a configuration module is used to configure the calculation mode and calculation type of the transcendental function vector calculation unit. The technical solution provided by the invention can effectively overcome the defect of the prior art that the efficient calculation of transcendental functions cannot be performed on input data of more than 8 bits.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to transcendental function calculation, and in particular to a configurable transcendental function vector calculation device. Background Art

[0002] A transcendental function is a function that cannot be expressed using a finite number of arithmetic operations and algebraic operations. The calculation of transcendental functions is often involved in deep learning models. Functions such as sigmoid, tanh, and softmax are all commonly used activation functions.

[0003] In modern general-purpose processors, numerical approximation methods are often used to obtain approximate values ​​of transcendental functions. This method requires a large number of iterations and other calculations, which is time-consuming and inefficient. In dedicated artificial intelligence accelerators, direct table lookup methods are usually used to calculate transcendental functions, but they are generally only applicable to low-precision calculation processes of 8 bits or less. For input data with higher bit widths, the use of direct table lookup methods has very obvious disadvantages, resulting in larger lookup tables or greater precision loss. Summary of the invention

[0004] In view of the above-mentioned shortcomings of the prior art, the present invention provides a configurable transcendental function vector calculation device, which can effectively overcome the defect of the prior art that it cannot efficiently calculate transcendental functions for input data of more than 8 bits.

[0005] To achieve the above objectives, the present invention is implemented through the following technical solutions:

[0006] A configurable transcendental function vector calculation device comprises a transcendental function vector calculation unit, a first data input temporary storage module, a second data input temporary storage module, a data output temporary storage module, a state control module, a configuration module and a storage controller;

[0007] The transcendental function vector calculation unit includes a vector operator. The vector operator completes vector addition, subtraction, multiplication and vector logic operations according to the configuration information of the configuration module. When performing transcendental function calculations, each vector operator performs 256 8-bit fixed-point operations at the same time, or 64 16 / 32-bit floating-point operations at the same time;

[0008] The first data input temporary storage module or the second data input temporary storage module is used as a data input object of the transcendental function vector calculation unit;

[0009] A data output temporary storage module, serving as a data output object of a transcendental function vector calculation unit;

[0010] A state control module receives control signals from other modules and outputs the internal operation state of the transcendental function vector calculation unit to other modules;

[0011] A configuration module, used to configure the calculation mode and calculation type of the transcendental function vector calculation unit;

[0012] The storage controller is used for the first data input temporary storage module, the second data input temporary storage module and the data output temporary storage module to interact with the external memory and load the data in the lookup table in the vector operator.

[0013] Preferably, the bit widths of the first data input temporary storage module, the second data input temporary storage module and the data output temporary storage module are all 2048 bits, the data input bit width of each of the vector operators is 2048 bits, and the data output bit width is 2048 bits;

[0014] Each of the vector operators includes a 256*256*8-bit lookup table, which is shared in 8-bit fixed-point operations and 16 / 32-bit floating-point operations. The lookup table can be used to perform 256 8-bit transcendental function operations at the same time, or 64 16 / 32-bit floating-point transcendental function operations at the same time. The storage controller calculates the data in the corresponding lookup table in advance according to the transcendental function and the input data type, and loads the data;

[0015] Among them, the input data types of 8-bit fixed-point operations include UINT8 and INT8, which represent two types of quantization of neural network data. UINT8 represents 8-bit asymmetric quantization, and INT8 represents 8-bit symmetric quantization. For 8-bit fixed-point operations, the data in the lookup table is calculated by the quantization parameters of the layer and the specific transcendental function, and the data is completely uncertain.

[0016] The input data types for 16 / 32-bit floating-point operations include FP16 / BFLOAT16 / FP32.

[0017] Preferably, the 8-bit fixed-point operation includes:

[0018] When the data type is a floating point number, use the following formula to convert it to the corresponding UINT8 quantized value qf:

[0019] (1),

[0020] Where f is the input floating point value, qf is the UINT8 quantized value corresponding to the input floating point value f, Scale is the quantization parameter scaling factor, and Zp is the quantization zero point value;

[0021] Using the direct table lookup method, the UINT8 quantized value qf is used as the input data. The relationship between the input data qf and the corresponding output data qy' is expressed as follows:

[0022] (2),

[0023] in, is a transcendental function, Scale f is the input quantization parameter scaling factor, Zp f Quantize the zero value for the input, Scale y’ is the output quantization parameter scaling factor, Zp y’ Quantize the zero value for the output;

[0024] When the data type is a floating point number, the quantization zero point value Zp in formula (1) is set to 0 to convert it into the corresponding INT8 quantization value, and the input quantization zero point value Zp in formula (2) is f , output quantization zero value Zp y’ Set them all to 0 to get the relationship between the INT8 quantization value and the corresponding output data;

[0025] Therefore, for input data types of UINT8 and INT8, since both the input data and the output data are 8 bits, the corresponding output data can be obtained by using a direct table lookup method, without the need for real-time calculation using the above formula.

[0026] Preferably, the transcendental function vector calculation unit includes a pre-processing module, a fitting module and a post-processing module;

[0027] The preprocessing module expands the data, performs scaling processing on the input data, handles exception values, takes the sign bit, exponent bit and mantissa bit, and quantizes them into integers and decimals;

[0028] The fitting module sets the lookup table and performs linear fitting based on the lookup table;

[0029] The post-processing module processes the exponential value, the tail value and the fitting value to obtain the output data.

[0030] Preferably, the fitting module sets a lookup table and performs linear fitting according to the lookup table, including:

[0031] Assume that the data range for linear fitting is (0,1), and take 256 control points within this data range. Each control point index is represented by 8 bits. The lookup table stores the index value corresponding to the control point index. The index value includes the control point x k The corresponding function value y k , and the control point x k 、x k+1 The corresponding function values ​​y k ,y k+1 The difference between k+1 -y k ;

[0032] Assume that the input data x is located at the control point x k 、x k+1 Between, and the control point x k 、x k+1 The distance between the input data x and the control point x is 1. k If the distance between is t, the linear fitting of the input data x to obtain the output data y is expressed as follows:

[0033] (3),

[0034] The index value corresponding to each control point index is stored in 32 bits, and the first 16 bits store the function value y. k , the last 16 bits store the difference y between the function values k+1 -y k .

[0035] Preferably, the 16 / 32 bit floating point operation includes:

[0036] When the transcendental function is a natural exponential function:

[0037] Take 256 control points in (-1,1), set the control point indexes corresponding to the control points 0 to 127 in (0,1), and set the control point indexes corresponding to the control points 128 to 255 in (-1,0). The index value corresponding to each control point index includes the natural exponential function value of the product of the control point and In2, and the difference between the function values ​​corresponding to the two control points;

[0038] The floating point number f' can be represented in the computer using the following formula:

[0039] (4),

[0040] Among them, E is the true exponent value, F is the mantissa value, sign represents the sign, sign=0 represents the floating point number f' is a positive number, sign=1 represents the floating point number f' is a negative number;

[0041] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x, and multiply it by the floating point number 1 / In2 to obtain the intermediate number x';

[0042] Align the decimal point of the middle number x' to the decimal point of the decimal to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary;

[0043] Take the sign bit and the first seven bits of M, a total of eight bits to form the table index, and get the corresponding index value. The t value takes the 8th to 24th bits of M and is processed into a decimal between 0 and 1. According to formula (3), the corresponding fitting value z is obtained;

[0044] If the input data x is positive, then add the true exponential value Ez of the fitted value z to K; if the input data x is negative, then subtract the true exponential value Ez of the fitted value z from K to obtain the output data Y corresponding to the input data X / input data x under the natural exponential function;

[0045] When the transcendental function is a natural logarithmic function:

[0046] Take 256 control points in [1,2). The index value corresponding to each control point index includes the natural logarithm function value of the control point and the difference between the function values ​​corresponding to two control points.

[0047] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x. According to the floating point expression formula of formula (4), take the first 8 bits of F as the table index to obtain the corresponding index value. The t value takes the 9th to 24th bits of F and is processed into a decimal between 0 and 1. According to formula (3), obtain the corresponding fitting value z.

[0048] By adding the product of the fitting value z, the true exponential value Ex of the input data x and In2, we can get the output data Y corresponding to the input data X / input data x under the natural logarithm function.

[0049] Preferably, the 16 / 32 bit floating point operation includes:

[0050] When the transcendental function is a reciprocal function:

[0051] Take 256 control points in [1,2). The index value corresponding to each control point index includes the reciprocal value of the control point and the difference between the function values ​​corresponding to the two control points.

[0052] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x. According to the floating point expression formula of formula (4), take the first 8 bits of F as the table index to obtain the corresponding index value. The t value takes the 9th to 24th bits of F and is processed into a decimal between 0 and 1. According to formula (3), obtain the corresponding fitting value z.

[0053] The actual exponential value Ez of the fitting value z and the actual exponential value Ex of the input data x are added after being negative as the final exponential value of the fitting value z, and the sign bit of the fitting value z is processed to be the same as the sign bit of the input data x, so that the output data Y corresponding to the input data X / input data x under the reciprocal function can be obtained;

[0054] When the transcendental function is a root function:

[0055] Take 256 control points in [1,2). The index value corresponding to each control point index includes the square root value of the control point and the difference between the function values ​​corresponding to the two control points.

[0056] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x. According to the floating point expression formula of formula (4), take the first 8 bits of F as the table index to obtain the corresponding index value. The t value takes the 9th to 24th bits of F and is processed into a decimal between 0 and 1. According to formula (3), obtain the corresponding fitting value z.

[0057] If the true exponential value Ex of the input data x is an even number, then the true exponential value Ez of the fitted value z needs to be added with Ex / 2; if the true exponential value Ex of the input data x is an odd number, then the true exponential value Ez of the fitted value z needs to be multiplied by , add the exponential of the result and then add (Ex-1) / 2 to get the output data Y corresponding to the input data X / input data x under the root function.

[0058] Preferably, the 16 / 32 bit floating point operation includes:

[0059] When the transcendental function is a sin function:

[0060] Take 256 control points in [0,1), and the index value corresponding to each control point index includes the control point and The sin function value of the product and the difference between the function values ​​corresponding to the two control points;

[0061] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x and multiply the floating point number Get the middle number x1';

[0062] Align the decimal point of the middle number x1' to the decimal point of the decimal point to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary;

[0063] Take the last two digits of K. If the last two digits are 0, the input data x is in the first quadrant; if the last two digits are 1, the input data x is in the second quadrant; if the last two digits are 2, the input data x is in the third quadrant; if the last two digits are 3, the input data x is in the fourth quadrant;

[0064] Take the first eight bits of M and combine them with the quadrant number where the input data x is located to get the table lookup index. If the input data x is located in the first / third quadrant, use the first eight bits of M as the table lookup index; if the input data x is located in the second / fourth quadrant, invert the first eight bits of M as the table lookup index; after obtaining the table lookup index, obtain the corresponding index value according to the table lookup index;

[0065] The t value is taken from 9 to 24 bits of M. If the input data x is in the first / third quadrant, it is directly processed as a decimal between 0 and 1; if the input data x is in the second / fourth quadrant, t is inverted and then processed as a decimal between 0 and 1. The corresponding fitting value z is obtained according to formula (3);

[0066] If the input data x is in the first / second quadrant, the fitting value z is used as the intermediate result; if the input data x is in the third / fourth quadrant, the fitting value z is negated as the intermediate result; after obtaining the intermediate result, if the input data x is a negative number, the intermediate result is negated again, and the output data Y corresponding to the input data X / input data x under the sin function can be obtained;

[0067] When the transcendental function is a cosine function:

[0068] Take 256 control points in [0,1), and the index value corresponding to each control point index includes the control point and The cosine function value of the product and the difference between the function values ​​corresponding to the two control points;

[0069] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x and multiply the floating point number Get the middle number x1';

[0070] Align the decimal point of the middle number x1' to the decimal point of the decimal point to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary;

[0071] Take the last two digits of K. If the last two digits are 0, the input data x is in the first quadrant; if the last two digits are 1, the input data x is in the second quadrant; if the last two digits are 2, the input data x is in the third quadrant; if the last two digits are 3, the input data x is in the fourth quadrant;

[0072] Take the first eight bits of M and combine them with the quadrant number where the input data x is located to get the table lookup index. If the input data x is located in the first / third quadrant, use the first eight bits of M as the table lookup index; if the input data x is located in the second / fourth quadrant, invert the first eight bits of M as the table lookup index; after obtaining the table lookup index, obtain the corresponding index value according to the table lookup index;

[0073] The t value is taken from 9 to 24 bits of M. If the input data x is in the first / third quadrant, it is directly processed as a decimal between 0 and 1; if the input data x is in the second / fourth quadrant, t is inverted and then processed as a decimal between 0 and 1. The corresponding fitting value z is obtained according to formula (3);

[0074] If the input data x is in the first / fourth quadrant, the fitted value z is used as the output data Y; if the input data x is in the second / third quadrant, the fitted value z is negative as the output data Y, and the output data Y corresponding to the input data X / input data x under the cosine function can be obtained;

[0075] When the transcendental function is a tanh function:

[0076] Take 256 control points in [0,8), and the index value corresponding to each control point index includes the tanh function value of the control point and the difference between the function values ​​corresponding to two control points;

[0077] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x;

[0078] Align the decimal point of the input data x to the decimal point of the decimal point to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary;

[0079] Take the last three digits of K and the first five digits of M to form a lookup table index and get the corresponding index value. The t value takes the 6th to 24th digits of M and is processed into a decimal between 0 and 1. According to formula (3), the corresponding fitting value z is obtained.

[0080] By processing the sign bit of the fitting value z to be the same as the sign bit of the input data x, the output data Y corresponding to the input data X / input data x under the tanh function can be obtained.

[0081] Preferably, the 16 / 32 bit floating point operation includes:

[0082] When the transcendental function is a Sigmoid function:

[0083] Take 256 control points in [0,16). The index value corresponding to each control point index includes the Sigmoid function value of the control point and the difference between the function values ​​corresponding to two control points.

[0084] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x;

[0085] Align the decimal point of the input data x to the decimal point of the decimal point to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary;

[0086] Take the last four bits of K and the first four bits of M to form a lookup table index and get the corresponding index value. The t value takes the 5th to 24th bits of M and is processed into a decimal between 0 and 1. According to formula (3), the corresponding fitting value z is obtained.

[0087] If the input data x is positive, the fitted value z is used as the output data Y; if the output data Y is negative, 1-z is used as the output data Y, and the output data Y corresponding to the input data X / input data x under the Sigmoid function can be obtained;

[0088] When the transcendental function is an erf function:

[0089] Take 256 control points in [0,4), and the index value corresponding to each control point index includes the erf function value of the control point and the difference between the function values ​​corresponding to the two control points;

[0090] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x;

[0091] Align the decimal point of the input data x to the decimal point of the decimal point to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary;

[0092] Take the last two digits of K and the first six digits of M to form a table lookup index and get the corresponding index value. The t value takes the 7th to 24th digits of M and is processed into a decimal between 0 and 1. According to formula (3), the corresponding fitting value z is obtained.

[0093] The sign bit of the fitting value z is processed to be the same as the sign bit of the input data x, and the output data Y corresponding to the input data X / input data x under the erf function can be obtained;

[0094] Among them, when calculating the S-type curve functions including the above-mentioned Sigmoid function, erf function, and tanh function, 16 / 32-bit floating-point operations can calculate S-type curve functions of various shapes by loading different lookup table contents through software and combining hardware-solidified pre-processing and post-processing circuits.

[0095] Preferably, the function value and the difference between the function values ​​are stored in FP16 format, and after the index value is obtained by table lookup, it is processed into FP32 format;

[0096] Alternatively, the function value and the difference between the function values ​​are stored in WFP16 format. For the function value, the sign bit is discarded, 4 bits are used to store the exponent, 12 bits are used to store the mantissa, the offset value of the exponent is 14, and the index value is obtained by looking up the table and processed into FP32 format; for the difference between the function values, 1 bit is used to store the sign bit, 4 bits are used to store the exponent, and 11 bits are used to store the mantissa, the offset value of the exponent is 15, and the index value is obtained by looking up the table and processed into FP32 format;

[0097] Alternatively, the function value and the difference between the function values ​​are stored in the FIXED16 fixed-point format. For the function value, assuming that the exponent bit is C and the mantissa bit is D, a 1 is added to the left side of the mantissa to obtain a 24-bit mantissa, and then it is right-shifted by abs(C) bits, and the upper 16 bits are stored; for the difference between the function values, assuming that the exponent bit is Q and the mantissa bit is R, a 1 is added to the left side of the mantissa to obtain a 24-bit mantissa, and then it is right-shifted by abs(Q)-6 bits, and the upper 16 bits are stored. When the FIXED16 fixed-point format is used for storage, the subsequent fitting calculation also needs to be changed to fixed-point operation.

[0098] Compared with the prior art, the configurable transcendental function vector calculation device provided by the present invention has the following beneficial effects:

[0099] 1) Supports the input of transcendental function data in neural network into transcendental function vector calculation unit in 8-bit fixed-point or 16 / 32-bit floating-point format for parallel calculation, thus achieving high-precision calculation of neural network;

[0100] 2) The transcendental function is calculated using the fitting method. When the FP16 calculation accuracy of the neural network is fully met, only simple addition and multiplication operations are required to obtain the output data. This is very suitable for efficient neural network reasoning scenarios. When calculating floating-point transcendental functions, the fitting calculation process is effectively accelerated by cleverly designing the table index and residual multiplier, combined with the fixed-point calculation of the internal fitting process;

[0101] 3) Using the configuration function of the configuration module and the instructions of the software to load the data in the lookup table, the data is loaded into the vector operator, and by selecting the type of transcendental function, various transcendental functions can be calculated for various input data types;

[0102] 4) 8-bit fixed-point operations and 16 / 32-bit floating-point operations share a large lookup table, which effectively reuses the on-chip area. By reusing the lookup table, both 8-bit fixed-point and 16 / 32-bit floating-point transcendental function calculations can be supported. BRIEF DESCRIPTION OF THE DRAWINGS

[0103] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0104] Figure 1 It is a schematic diagram of the system of the present invention;

[0105] Figure 2Schematic diagram of the combination of the lookup table when performing fixed-point calculation of the 8-bit activation function;

[0106] Figure 3 A schematic diagram of the combination of lookup tables for 16-bit floating-point calculations;

[0107] Figure 4 A schematic diagram of the combination of lookup tables for 32-bit floating-point calculations;

[0108] Figure 5 It is a schematic diagram of linear fitting performed by the fitting module in the present invention;

[0109] Figure 6 It is a schematic diagram of using three formats to store index values ​​in the present invention. DETAILED DESCRIPTION

[0110] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0111] A configurable transcendental function vector computing device, such as Figure 1 As shown, it includes a transcendental function vector calculation unit, a first data input temporary storage module, a second data input temporary storage module, a data output temporary storage module, a state control module, a configuration module and a storage controller;

[0112] The transcendental function vector calculation unit includes a vector operator. The vector operator completes vector addition, subtraction, multiplication and vector logic operations according to the configuration information of the configuration module. When performing transcendental function calculations, each vector operator performs 256 8-bit fixed-point operations at the same time, or 64 16 / 32-bit floating-point operations at the same time;

[0113] The first data input temporary storage module or the second data input temporary storage module is used as a data input object of the transcendental function vector calculation unit;

[0114] A data output temporary storage module, serving as a data output object of a transcendental function vector calculation unit;

[0115] A state control module receives control signals from other modules and outputs the internal operation state of the transcendental function vector calculation unit to other modules;

[0116] A configuration module, used to configure the calculation mode and calculation type of the transcendental function vector calculation unit;

[0117] The storage controller is used for the first data input temporary storage module, the second data input temporary storage module and the data output temporary storage module to interact with the external memory and load the data in the lookup table in the vector operator.

[0118] In the technical solution of the present application, the bit widths of the first data input temporary storage module, the second data input temporary storage module and the data output temporary storage module are all 2048 bits, the data input bit width of each vector operator is 2048 bits, and the data output bit width is 2048 bits;

[0119] Each vector operator contains a 256*256*8-bit lookup table, which is shared between 8-bit fixed-point operations and 16 / 32-bit floating-point operations (such as Figures 2 to 4 As shown), the lookup table can be used to perform 256 8-bit transcendental function operations simultaneously, or 64 16 / 32-bit floating-point transcendental function operations simultaneously. The storage controller calculates the data in the corresponding lookup table in advance according to the transcendental function and the input data type, and loads it;

[0120] Among them, the input data types of 8-bit fixed-point operations include UINT8 and INT8, which represent two types of quantization of neural network data. UINT8 represents 8-bit asymmetric quantization, and INT8 represents 8-bit symmetric quantization. For 8-bit fixed-point operations, the data in the lookup table is calculated by the quantization parameters of the layer and the specific transcendental function, and the data is completely uncertain.

[0121] The input data types for 16 / 32-bit floating-point operations include FP16 / BFLOAT16 / FP32.

[0122] ①8-bit fixed-point operations, including:

[0123] When the data type is a floating point number, use the following formula to convert it to the corresponding UINT8 quantized value qf:

[0124] (1),

[0125] Where f is the input floating point value, qf is the UINT8 quantized value corresponding to the input floating point value f, Scale is the quantization parameter scaling factor, and Zp is the quantization zero point value;

[0126] Using the direct table lookup method, the UINT8 quantized value qf is used as the input data. The relationship between the input data qf and the corresponding output data qy' is expressed as follows:

[0127] (2),

[0128] in, is a transcendental function, Scale f is the input quantization parameter scaling factor, Zp f Quantize the zero value for the input, Scale y’ is the output quantization parameter scaling factor, Zp y’ Quantize the zero value for the output;

[0129] When the data type is a floating point number, the quantization zero point value Zp in formula (1) is set to 0 to convert it into the corresponding INT8 quantization value, and the input quantization zero point value Zp in formula (2) is f , output quantization zero value Zp y’ By setting them all to 0, we can get the relationship between the INT8 quantization value and the corresponding output data.

[0130] Therefore, for input data types of UINT8 and INT8, since both the input data and the output data are 8 bits, the corresponding output data can be obtained by using a direct table lookup method, without the need for real-time calculation using the above formula.

[0131] In the technical solution of the present application, the transcendental function vector calculation unit includes a pre-processing module, a fitting module and a post-processing module;

[0132] The preprocessing module expands the data, performs scaling processing on the input data, handles exception values, takes the sign bit, exponent bit and mantissa bit, and quantizes them into integers and decimals;

[0133] The fitting module sets the lookup table and performs linear fitting based on the lookup table;

[0134] The post-processing module processes the exponential value, the tail value and the fitting value to obtain the output data.

[0135] Specifically, the fitting module sets a lookup table and performs linear fitting according to the lookup table, including:

[0136] Assume that the data range for linear fitting is (0,1), and take 256 control points within this data range. Each control point index is represented by 8 bits. The lookup table stores the index value corresponding to the control point index. The index value includes the control point x k The corresponding function value y k , and the control point x k 、x k+1 The corresponding function values ​​y k ,y k+1 The difference between k+1 -y k ;

[0137] like Figure 5 As shown, assuming that the input data x is located at the control point x k 、x k+1Between, and the control point x k 、x k+1 The distance between the input data x and the control point x is 1. k If the distance between is t, the linear fitting of the input data x to obtain the output data y is expressed as follows:

[0138] (3),

[0139] The index value corresponding to each control point index is stored in 32 bits, and the first 16 bits store the function value y. k , the last 16 bits store the difference y between the function values k+1 -y k .

[0140] The above technical solution explains the t value as follows:

[0141] When the transcendental function is a natural logarithm function, the mantissa has a total of 23 bits. The first 8 bits are used as the table index, and the remaining 15 bits are used as t. At this time, t can be regarded as a decimal between 0 and 1 (when performing floating-point calculations, it is converted into a decimal represented in FP32 format), that is, the distance between the previous control point. The same applies to other transcendental functions.

[0142] If the data type stored in the lookup table is a fixed-point number, the fitting process directly performs fixed-point calculations. When the transcendental function is a natural logarithm function, take out the difference between the 15-bit mantissa and the 16-bit function value, multiply it and shift it right by 5 bits, shift the 16-bit function value left by 16 bits to expand it to 32 bits, add the two together to get a 32-bit fixed-point number, and then convert it to a floating-point number in FP32 format as the fitting value, and then post-process it with the transcendental function. The remaining mantissa of each transcendental function is different, so the number of right shifts after multiplying the difference between t and the function value is also different. Table 1 shows the length of the t value of each transcendental function and the corresponding number of right shifts for fixed-point calculations:

[0143] Table 1 The length of t value of each transcendental function and the corresponding fixed-point calculation right shift number table

[0144] Transcendental Function Types t value length Fixed-point calculation right shift number Exponential function 16 6 Logarithmic function 15 5 Root function 15 5 Reciprocal function 15 5 tanh 18 8 Sigmoid 19 9 erf 17 7 sin 15 5 cos 15 5

[0145] ②16 / 32bit floating point operations, including:

[0146] 1) When the transcendental function is a natural exponential function:

[0147] Take 256 control points in (-1,1), set the control point indexes corresponding to the control points 0 to 127 in (0,1), and set the control point indexes corresponding to the control points 128 to 255 in (-1,0). The index value corresponding to each control point index includes the natural exponential function value of the product of the control point and In2, and the difference between the function values ​​corresponding to the two control points;

[0148] The floating point number f' can be represented in the computer using the following formula:

[0149] (4),

[0150] Among them, E is the true exponent value, F is the mantissa value, sign represents the sign, sign=0 represents the floating point number f' is a positive number, sign=1 represents the floating point number f' is a negative number;

[0151] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x, and multiply it by the floating point number 1 / In2 to obtain the intermediate number x';

[0152] Align the decimal point of the middle number x' to the decimal point of the decimal to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary;

[0153] Take the sign bit and the first seven bits of M, a total of eight bits to form the table index, and get the corresponding index value. The t value takes the 8th to 24th bits of M and is processed into a decimal between 0 and 1. According to formula (3), the corresponding fitting value z is obtained;

[0154] If the input data x is positive, then add the true exponential value Ez of the fitted value z to K; if the input data x is negative, then subtract the true exponential value Ez of the fitted value z from K to obtain the output data Y corresponding to the input data X / input data x under the natural exponential function;

[0155] 2) When the transcendental function is a natural logarithmic function:

[0156] Take 256 control points in [1,2). The index value corresponding to each control point index includes the natural logarithm function value of the control point and the difference between the function values ​​corresponding to two control points.

[0157] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x. According to the floating point expression formula of formula (4), take the first 8 bits of F as the table index to obtain the corresponding index value. The t value takes the 9th to 24th bits of F and is processed into a decimal between 0 and 1. According to formula (3), obtain the corresponding fitting value z.

[0158] Add the product of the fitting value z, the true exponential value Ex of the input data x and In2 to obtain the output data Y corresponding to the input data X / input data x under the natural logarithm function;

[0159] 3) When the transcendental function is a reciprocal function:

[0160] Take 256 control points in [1,2). The index value corresponding to each control point index includes the reciprocal value of the control point and the difference between the function values ​​corresponding to the two control points.

[0161] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x. According to the floating point expression formula of formula (4), take the first 8 bits of F as the table index to obtain the corresponding index value. The t value takes the 9th to 24th bits of F and is processed into a decimal between 0 and 1. According to formula (3), obtain the corresponding fitting value z.

[0162] The actual exponential value Ez of the fitting value z and the actual exponential value Ex of the input data x are added after being negative as the final exponential value of the fitting value z, and the sign bit of the fitting value z is processed to be the same as the sign bit of the input data x, so that the output data Y corresponding to the input data X / input data x under the reciprocal function can be obtained;

[0163] 4) When the transcendental function is a root function:

[0164] Take 256 control points in [1,2). The index value corresponding to each control point index includes the square root value of the control point and the difference between the function values ​​corresponding to the two control points.

[0165] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x. According to the floating point expression formula of formula (4), take the first 8 bits of F as the table index to obtain the corresponding index value. The t value takes the 9th to 24th bits of F and is processed into a decimal between 0 and 1. According to formula (3), obtain the corresponding fitting value z.

[0166] If the true exponential value Ex of the input data x is an even number, then the true exponential value Ez of the fitted value z needs to be added with Ex / 2; if the true exponential value Ex of the input data x is an odd number, then the true exponential value Ez of the fitted value z needs to be multiplied by , add the exponential of the result and (Ex-1) / 2 to get the output data Y corresponding to the input data X / input data x under the root function;

[0167] 5) When the transcendental function is a sin function:

[0168] Take 256 control points in [0,1), and the index value corresponding to each control point index includes the control point and The sin function value of the product and the difference between the function values ​​corresponding to the two control points;

[0169] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x and multiply the floating point number Get the middle number x1';

[0170] Align the decimal point of the middle number x1' to the decimal point of the decimal point to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary;

[0171] Take the last two digits of K. If the last two digits are 0, the input data x is in the first quadrant; if the last two digits are 1, the input data x is in the second quadrant; if the last two digits are 2, the input data x is in the third quadrant; if the last two digits are 3, the input data x is in the fourth quadrant;

[0172] Take the first eight bits of M and combine them with the quadrant number where the input data x is located to get the table lookup index. If the input data x is located in the first / third quadrant, use the first eight bits of M as the table lookup index; if the input data x is located in the second / fourth quadrant, invert the first eight bits of M as the table lookup index; after obtaining the table lookup index, obtain the corresponding index value according to the table lookup index;

[0173] The t value is taken from 9 to 24 bits of M. If the input data x is in the first / third quadrant, it is directly processed as a decimal between 0 and 1; if the input data x is in the second / fourth quadrant, t is inverted and then processed as a decimal between 0 and 1. The corresponding fitting value z is obtained according to formula (3);

[0174] If the input data x is in the first / second quadrant, the fitting value z is used as the intermediate result; if the input data x is in the third / fourth quadrant, the fitting value z is negated as the intermediate result; after obtaining the intermediate result, if the input data x is a negative number, the intermediate result is negated again, and the output data Y corresponding to the input data X / input data x under the sin function can be obtained;

[0175] 6) When the transcendental function is a cosine function:

[0176] Take 256 control points in [0,1), and the index value corresponding to each control point index includes the control point and The cosine function value of the product and the difference between the function values ​​corresponding to the two control points;

[0177] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x and multiply the floating point number Get the middle number x1';

[0178] Align the decimal point of the middle number x1' to the decimal point of the decimal point to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary;

[0179] Take the last two digits of K. If the last two digits are 0, the input data x is in the first quadrant; if the last two digits are 1, the input data x is in the second quadrant; if the last two digits are 2, the input data x is in the third quadrant; if the last two digits are 3, the input data x is in the fourth quadrant;

[0180] Take the first eight bits of M and combine them with the quadrant number where the input data x is located to get the table lookup index. If the input data x is located in the first / third quadrant, use the first eight bits of M as the table lookup index; if the input data x is located in the second / fourth quadrant, invert the first eight bits of M as the table lookup index; after obtaining the table lookup index, obtain the corresponding index value according to the table lookup index;

[0181] The t value is taken from 9 to 24 bits of M. If the input data x is in the first / third quadrant, it is directly processed as a decimal between 0 and 1; if the input data x is in the second / fourth quadrant, t is inverted and then processed as a decimal between 0 and 1. The corresponding fitting value z is obtained according to formula (3);

[0182] If the input data x is in the first / fourth quadrant, the fitted value z is used as the output data Y; if the input data x is in the second / third quadrant, the fitted value z is negative as the output data Y, and the output data Y corresponding to the input data X / input data x under the cosine function can be obtained;

[0183] 7) When the transcendental function is a tanh function:

[0184] Take 256 control points in [0,8), and the index value corresponding to each control point index includes the tanh function value of the control point and the difference between the function values ​​corresponding to two control points;

[0185] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x;

[0186] Align the decimal point of the input data x to the decimal point of the decimal point to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary;

[0187] Take the last three digits of K and the first five digits of M to form a lookup table index and get the corresponding index value. The t value takes the 6th to 24th digits of M and is processed into a decimal between 0 and 1. According to formula (3), the corresponding fitting value z is obtained.

[0188] The sign bit of the fitting value z is processed to be the same as the sign bit of the input data x, and the output data Y corresponding to the input data X / input data x under the tanh function can be obtained;

[0189] 8) When the transcendental function is a Sigmoid function:

[0190] Take 256 control points in [0,16). The index value corresponding to each control point index includes the Sigmoid function value of the control point and the difference between the function values ​​corresponding to two control points.

[0191] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x;

[0192] Align the decimal point of the input data x to the decimal point of the decimal point to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary;

[0193] Take the last four bits of K and the first four bits of M to form a lookup table index and get the corresponding index value. The t value takes the 5th to 24th bits of M and is processed into a decimal between 0 and 1. According to formula (3), the corresponding fitting value z is obtained.

[0194] If the input data x is positive, the fitted value z is used as the output data Y; if the output data Y is negative, 1-z is used as the output data Y, and the output data Y corresponding to the input data X / input data x under the Sigmoid function can be obtained;

[0195] 9) When the transcendental function is an erf function:

[0196] Take 256 control points in [0,4), and the index value corresponding to each control point index includes the erf function value of the control point and the difference between the function values ​​corresponding to the two control points;

[0197] Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x;

[0198] Align the decimal point of the input data x to the decimal point of the decimal point to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary;

[0199] Take the last two digits of K and the first six digits of M to form a table lookup index and get the corresponding index value. The t value takes the 7th to 24th digits of M and is processed into a decimal between 0 and 1. According to formula (3), the corresponding fitting value z is obtained.

[0200] By processing the sign bit of the fitting value z to be the same as the sign bit of the input data x, the output data Y corresponding to the input data X / input data x under the erf function can be obtained.

[0201] Among them, when calculating the S-type curve functions including the above-mentioned Sigmoid function, erf function, and tanh function, 16 / 32-bit floating-point operations can calculate S-type curve functions of various shapes by loading different lookup table contents through software and combining hardware-solidified pre-processing and post-processing circuits.

[0202] In the technical solution of this application, if Figure 6 As shown, the function value and the difference between the function values ​​are stored in FP16 format, and the index value is processed into FP32 format after the table is looked up to obtain the index value.

[0203] Or, to increase storage precision, such as Figure 6 As shown, the difference between the function values ​​and the function values ​​can also be stored in WFP16 format. For the function value, the sign bit is discarded, 4 bits are used to store the exponent, 12 bits are used to store the mantissa, the exponent offset value is 14, and the index value is processed into FP32 format after the table is looked up; for the difference between the function values, 1 bit is used to store the sign bit, 4 bits are used to store the exponent, and 11 bits are used to store the mantissa, the exponent offset value is 15, and the index value is processed into FP32 format after the table is looked up.

[0204] Or, to increase storage precision, such as Figure 6 As shown, the difference between the function values ​​and the function values ​​can also be stored in the FIXED16 fixed-point format. For the function value, assuming that the exponent bit is C and the mantissa bit is D, add a 1 to the left of the mantissa to get a 24-bit mantissa, then right shift abs(C) bits, and take the upper 16 bits for storage; for the difference between the function values, assuming that the exponent bit is Q and the mantissa bit is R, add a 1 to the left of the mantissa to get a 24-bit mantissa, then right shift abs(Q)-6 bits, and take the upper 16 bits for storage. When the FIXED16 fixed-point format is used for storage, the subsequent fitting calculation also needs to be changed to fixed-point operation.

[0205] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements will not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A configurable transcendental function vector computing device, Features: It includes a transcendental function vector calculation unit, a first data input temporary storage module, a second data input temporary storage module, a data output temporary storage module, a state control module, a configuration module and a storage controller; The transcendental function vector calculation unit includes a vector operator. The vector operator completes vector addition, subtraction, multiplication and vector logic operations according to the configuration information of the configuration module. When performing transcendental function calculations, each vector operator performs 256 8-bit fixed-point operations at the same time, or 64 16 / 32-bit floating-point operations at the same time; The first data input temporary storage module or the second data input temporary storage module is used as a data input object of the transcendental function vector calculation unit; A data output temporary storage module, serving as a data output object of a transcendental function vector calculation unit; A state control module receives control signals from other modules and outputs the internal operation state of the transcendental function vector calculation unit to other modules; A configuration module, used to configure the calculation mode and calculation type of the transcendental function vector calculation unit; A storage controller, used for the first data input temporary storage module, the second data input temporary storage module and the data output temporary storage module to interact with the external memory and load the data in the lookup table in the vector operator; The transcendental function vector calculation unit includes a pre-processing module, a fitting module and a post-processing module; The preprocessing module expands the data, performs scaling processing on the input data, handles exception values, takes the sign bit, exponent bit and mantissa bit, and quantizes them into integers and decimals; The fitting module sets the lookup table and performs linear fitting based on the lookup table; The post-processing module processes the exponential value, the tail value and the fitting value to obtain the output data; The fitting module sets a lookup table and performs linear fitting according to the lookup table, including: Assume that the data range for linear fitting is (0,1), and take 256 control points within this data range. Each control point index is represented by 8 bits. The lookup table stores the index value corresponding to the control point index. The index value includes the control point x k The corresponding function value y k , and the control point x k 、x k+1 The corresponding function values ​​y k ,y k+1 The difference between k+1 -y k ; Assume that the input data x is located at the control point x k 、x k+1 Between, and the control point x k 、x k+1 The distance between the input data x and the control point x is 1. k If the distance between is t, the linear fitting of the input data x to obtain the output data y is expressed as follows: (3), The index value corresponding to each control point index is stored in 32 bits, and the first 16 bits store the function value y. k , the last 16 bits store the difference y between the function values k+1 -y k .

2. The configurable transcendental function vector computing device according to claim 1, Features: The bit widths of the first data input temporary storage module, the second data input temporary storage module and the data output temporary storage module are all 2048 bits, the data input bit width of each of the vector operators is 2048 bits, and the data output bit width is 2048 bits; Each of the vector operators includes a 256*256*8-bit lookup table, which is shared in 8-bit fixed-point operations and 16 / 32-bit floating-point operations. The lookup table can be used to perform 256 8-bit transcendental function operations at the same time, or 64 16 / 32-bit floating-point transcendental function operations at the same time. The storage controller calculates the data in the corresponding lookup table in advance according to the transcendental function and the input data type, and loads the data; Among them, the input data types of 8-bit fixed-point operations include UINT8 and INT8, which represent two types of quantization of neural network data. UINT8 represents 8-bit asymmetric quantization, and INT8 represents 8-bit symmetric quantization. For 8-bit fixed-point operations, the data in the lookup table is calculated by the quantization parameters of the neural network layer and the specific transcendental function, and the data is completely uncertain. The input data types for 16 / 32-bit floating-point operations include FP16 / BFLOAT16 / FP32.

3. The configurable transcendental function vector calculation device according to claim 2, Features: The 8-bit fixed-point operation includes: When the data type is a floating point number, use the following formula to convert it to the corresponding UINT8 quantized value qf: (1), Where f is the input floating point value, qf is the UINT8 quantized value corresponding to the input floating point value f, Scale is the quantization parameter scaling factor, and Zp is the quantization zero point value; Using the direct table lookup method, the UINT8 quantized value qf is used as the input data. The relationship between the input data qf and the corresponding output data qy' is expressed as follows: (2), in, is a transcendental function, Scale f is the input quantization parameter scaling factor, Zp f Quantize the zero value for the input, Scale y’ is the output quantization parameter scaling factor, Zp y’ Quantize the zero value for the output; When the data type is a floating point number, the quantization zero point value Zp in formula (1) is set to 0 to convert it into the corresponding INT8 quantization value, and the input quantization zero point value Zp in formula (2) is f , output quantization zero value Zp y’ By setting them all to 0, we can get the relationship between the INT8 quantization value and the corresponding output data; Therefore, for input data types of UINT8 and INT8, since both the input data and the output data are 8 bits, the corresponding output data can be obtained by using the direct table lookup method, without the need for real-time calculation using formula (2).

4. The configurable transcendental function vector computing device according to claim 1, Features: The 16 / 32bit floating point operations include: When the transcendental function is a natural exponential function: Take 256 control points in (-1,1), set the control point indexes corresponding to the control points 0 to 127 in (0,1), and set the control point indexes corresponding to the control points 128 to 255 in (-1,0). The index value corresponding to each control point index includes the natural exponential function value of the product of the control point and In2, and the difference between the function values ​​corresponding to the two control points; The floating point number f' can be represented in the computer using the following formula: (4), Among them, E is the true exponent value, F is the mantissa value, sign represents the sign, sign=0 represents the floating point number f' is a positive number, sign=1 represents the floating point number f' is a negative number; Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x, and multiply it by the floating point number 1 / In2 to obtain the intermediate number x'; Align the decimal point of the middle number x' to the decimal point of the decimal to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary; Take the sign bit and the first seven bits of M, a total of eight bits to form the table index, and get the corresponding index value. The t value takes the 8th to 24th bits of M and is processed into a decimal between 0 and 1. According to formula (3), the corresponding fitting value z is obtained; If the input data x is positive, then add the true exponential value Ez of the fitted value z to K; if the input data x is negative, then subtract the true exponential value Ez of the fitted value z from K to obtain the output data Y corresponding to the input data X / input data x under the natural exponential function; When the transcendental function is a natural logarithmic function: Take 256 control points in [1,2). The index value corresponding to each control point index includes the natural logarithm function value of the control point and the difference between the function values ​​corresponding to two control points. Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x. According to the floating point expression formula of formula (4), take the first 8 bits of F as the table index to obtain the corresponding index value. The t value takes the 9th to 24th bits of F and is processed into a decimal between 0 and 1. According to formula (3), obtain the corresponding fitting value z. By adding the product of the fitting value z, the true exponential value Ex of the input data x and In2, we can get the output data Y corresponding to the input data X / input data x under the natural logarithm function.

5. The configurable transcendental function vector computing device according to claim 4, Features: The 16 / 32bit floating point operations include: When the transcendental function is a reciprocal function: Take 256 control points in [1,2). The index value corresponding to each control point index includes the reciprocal value of the control point and the difference between the function values ​​corresponding to the two control points. Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x. According to the floating point number expression formula of formula (4), take the first 8 bits of F as the table lookup index, take the 9th to 24th bits of F as the value of t, and process it into a decimal between 0 and 1. According to formula (3), get the corresponding fitting value z. The actual exponential value Ez of the fitting value z and the actual exponential value Ex of the input data x are added after being negative as the final exponential value of the fitting value z, and the sign bit of the fitting value z is processed to be the same as the sign bit of the input data x, so that the output data Y corresponding to the input data X / input data x under the reciprocal function can be obtained; When the transcendental function is a root function: Take 256 control points in [1,2). The index value corresponding to each control point index includes the square root value of the control point and the difference between the function values ​​corresponding to the two control points. Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x. According to the floating point expression formula of formula (4), take the first 8 bits of F as the table index to obtain the corresponding index value. The t value takes the 9th to 24th bits of F and is processed into a decimal between 0 and 1. According to formula (3), obtain the corresponding fitting value z. If the true exponential value Ex of the input data x is an even number, then the true exponential value Ez of the fitted value z needs to be added with Ex / 2; if the true exponential value Ex of the input data x is an odd number, then the true exponential value Ez of the fitted value z needs to be multiplied by , add the exponential of the result and then add (Ex-1) / 2 to get the output data Y corresponding to the input data X / input data x under the root function.

6. The configurable transcendental function vector computing device according to claim 1, Features: The 16 / 32bit floating point operations include: When the transcendental function is a sin function: Take 256 control points in [0,1), and the index value corresponding to each control point index includes the control point and The sin function value of the product and the difference between the function values ​​corresponding to the two control points; Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x and multiply the floating point number Get the middle number x 1 '; The middle number x 1 ' is aligned to the decimal point of the decimal number to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary; Take the last two digits of K. If the last two digits are 0, the input data x is in the first quadrant; if the last two digits are 1, the input data x is in the second quadrant; if the last two digits are 2, the input data x is in the third quadrant; if the last two digits are 3, the input data x is in the fourth quadrant; Take the first eight bits of M and combine them with the quadrant number where the input data x is located to get the table lookup index. If the input data x is located in the first / third quadrant, use the first eight bits of M as the table lookup index; if the input data x is located in the second / fourth quadrant, invert the first eight bits of M as the table lookup index; after obtaining the table lookup index, obtain the corresponding index value according to the table lookup index; The t value is taken from 9 to 24 bits of M. If the input data x is in the first / third quadrant, it is directly processed as a decimal between 0 and 1; if the input data x is in the second / fourth quadrant, t is inverted and then processed as a decimal between 0 and 1. The corresponding fitting value z is obtained according to formula (3); If the input data x is in the first / second quadrant, the fitting value z is used as the intermediate result; if the input data x is in the third / fourth quadrant, the fitting value z is negated as the intermediate result; after obtaining the intermediate result, if the input data x is a negative number, the intermediate result is negated again, and the output data Y corresponding to the input data X / input data x under the sin function can be obtained; When the transcendental function is a cosine function: Take 256 control points in [0,1), and the index value corresponding to each control point index includes the control point and The cosine function value of the product and the difference between the function values ​​corresponding to the two control points; Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x and multiply the floating point number Get the middle number x 1 '; The middle number x 1 ' is aligned to the decimal point of the decimal number to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary; Take the last two digits of K. If the last two digits are 0, the input data x is in the first quadrant; if the last two digits are 1, the input data x is in the second quadrant; if the last two digits are 2, the input data x is in the third quadrant; if the last two digits are 3, the input data x is in the fourth quadrant; Take the first eight bits of M and combine them with the quadrant number where the input data x is located to get the table lookup index. If the input data x is located in the first / third quadrant, use the first eight bits of M as the table lookup index; if the input data x is located in the second / fourth quadrant, invert the first eight bits of M as the table lookup index; after obtaining the table lookup index, obtain the corresponding index value according to the table lookup index; The t value is taken from 9 to 24 bits of M. If the input data x is in the first / third quadrant, it is directly processed as a decimal between 0 and 1; if the input data x is in the second / fourth quadrant, t is inverted and then processed as a decimal between 0 and 1. The corresponding fitting value z is obtained according to formula (3); If the input data x is in the first / fourth quadrant, the fitted value z is used as the output data Y; if the input data x is in the second / third quadrant, the fitted value z is negative as the output data Y, and the output data Y corresponding to the input data X / input data x under the cosine function can be obtained; When the transcendental function is a tanh function: Take 256 control points in [0,8), and the index value corresponding to each control point index includes the tanh function value of the control point and the difference between the function values ​​corresponding to two control points; Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x; Align the decimal point of the input data x to the decimal point of the decimal point to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary; Take the last three digits of K and the first five digits of M to form a lookup table index and get the corresponding index value. The t value takes the 6th to 24th digits of M and is processed into a decimal between 0 and 1. According to formula (3), the corresponding fitting value z is obtained. By processing the sign bit of the fitting value z to be the same as the sign bit of the input data x, the output data Y corresponding to the input data X / input data x under the tanh function can be obtained.

7. The configurable transcendental function vector calculation device according to claim 1, Features: The 16 / 32bit floating point operations include: When the transcendental function is a Sigmoid function: Take 256 control points in [0,16). The index value corresponding to each control point index includes the Sigmoid function value of the control point and the difference between the function values ​​corresponding to two control points. Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x; Align the decimal point of the input data x to the decimal point of the decimal point to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary; Take the last four bits of K and the first four bits of M to form a lookup table index and get the corresponding index value. The t value takes the 5th to 24th bits of M and is processed into a decimal between 0 and 1. According to formula (3), the corresponding fitting value z is obtained. If the input data x is positive, the fitted value z is used as the output data Y; if the output data Y is negative, 1-z is used as the output data Y, and the output data Y corresponding to the input data X / input data x under the Sigmoid function can be obtained; When the transcendental function is an erf function: Take 256 control points in [0,4), and the index value corresponding to each control point index includes the erf function value of the control point and the difference between the function values ​​corresponding to the two control points; Convert the input data X of FP16 / BFLOAT16 floating point number to FP32 floating point number input data x; Align the decimal point of the input data x to the decimal point of the decimal point to obtain data in the form of KM, where K is the integer digit in binary and M is the decimal digit in binary; Take the last two digits of K and the first six digits of M to form a table lookup index and get the corresponding index value. The t value takes the 7th to 24th digits of M and is processed into a decimal between 0 and 1. According to formula (3), the corresponding fitting value z is obtained. The sign bit of the fitting value z is processed to be the same as the sign bit of the input data x, and the output data Y corresponding to the input data X / input data x under the erf function can be obtained; Among them, when calculating the S-type curve functions including the above-mentioned Sigmoid function, erf function, and tanh function, 16 / 32-bit floating-point operations can calculate S-type curve functions of various shapes by loading different lookup table contents through software and combining hardware-solidified pre-processing and post-processing circuits.

8. The configurable transcendental function vector calculation device according to any one of claims 1, 4, 5, 6, and 7, Features: The function value and the difference between the function values ​​are stored in FP16 format, and after the index value is obtained by looking up the table, it is processed into FP32 format; Alternatively, the function value and the difference between the function values ​​are stored in WFP16 format. For the function value, the sign bit is discarded, 4 bits are used to store the exponent, 12 bits are used to store the mantissa, the offset value of the exponent is 14, and the index value is obtained by looking up the table and processed into FP32 format; for the difference between the function values, 1 bit is used to store the sign bit, 4 bits are used to store the exponent, and 11 bits are used to store the mantissa, the offset value of the exponent is 15, and the index value is obtained by looking up the table and processed into FP32 format; Alternatively, the function value and the difference between the function values ​​are stored in the FIXED16 fixed-point format. For the function value, assuming that the exponent bit is C and the mantissa bit is D, a 1 is added to the left side of the mantissa to obtain a 24-bit mantissa, and then it is right-shifted by abs(C) bits, and the upper 16 bits are stored; for the difference between the function values, assuming that the exponent bit is Q and the mantissa bit is R, a 1 is added to the left side of the mantissa to obtain a 24-bit mantissa, and then it is right-shifted by abs(Q)-6 bits, and the upper 16 bits are stored. When the FIXED16 fixed-point format is used for storage, the subsequent fitting calculation also needs to be changed to fixed-point operation.