Data processing method and device, processor, electronic equipment and storage medium
By converting the mantissa part of the floating point number into an integer type for multiplication, and combining it with the shift processing of the exponent part, the problem of precision error in the multiplication of floating point numbers and integers is solved, the calculation accuracy is improved and the scaling error is avoided. It is suitable for applications that do not support Scenarios for high-precision floating-point number multiplication.
Patent Information
- Application Number
- CN202410725616.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-05
- Publication Date
- 2024-10-11
AI Technical Summary
The existing technology has precision errors in floating point and integer multiplication calculations, especially in bilinear interpolation operations such as the Resize operator in deep learning models, resulting in scaling errors, and many artificial intelligence chips do not support high-precision floating point multiplication. .
By converting the mantissa part of the floating point number into an integer type, using the intermediate operands of multiple integer types to perform integer multiplication, the mantissa multiplication result is obtained, and the exponent part is shifted to generate a higher precision floating point multiplication result.
It reduces the precision error of integer and floating-point multiplication, improves the calculation accuracy, especially avoids scaling errors in applications such as the Resize operator, and simulates high-precision multiplication in processors that do not support high-precision floating-point multiplication.
Smart Images

Figure CN118760415A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure relate to a data processing method, a data processing apparatus, a processor, an electronic device, and a non-transitory computer-readable storage medium. Background Art
[0002] Floating point (FP) is mainly used to represent decimals, and usually consists of three parts, namely the sign bit, the exponent part, and the mantissa part. The exponent part can also be called the exponent part. For example, a floating point number V can usually be expressed as follows:
[0003] V=(-1)s×M×25
[0004] Among them, the sign bit s can be 1 bit, which determines whether the floating-point number V is a negative number or a positive number; M represents the mantissa part, which can include multiple bits, which is a binary decimal form, defining the precision of the floating-point number; E represents the exponent (also called the exponent value), which is used to weight the floating-point number, reflects the position of the decimal point in the floating-point number V, and defines the value range of the floating-point number. Summary of the invention
[0005] At least one embodiment of the present disclosure provides a data processing method, comprising: receiving a first source operand and a second source operand as input parameters, wherein the type of the first source operand is a floating point type, and the type of the second source operand is a first integer type; using multiple first intermediate operands of the second integer type to represent the mantissa part of the first source operand; using at least one second intermediate operand of the second integer type to represent the second source operand; performing integer multiplication of the second integer type on the multiple first intermediate operands and the at least one second intermediate operand in pairs to obtain multiple integer multiplication results, wherein each integer multiplication result is the second integer type, and each integer product result is the product of a first intermediate operand and a second intermediate operand; obtaining a mantissa multiplication result based on the multiple integer multiplication results; and obtaining a destination operand as an output parameter based on the mantissa multiplication result.
[0006] For example, in the data processing method provided by at least one embodiment of the present disclosure, a plurality of first intermediate operands of a second integer type are used to represent the mantissa part of the first source operand, including: filling the hidden bits in the mantissa part of the first source operand to obtain a valid mantissa part; dividing the valid mantissa part into a plurality of continuous first segments, wherein each first segment includes a plurality of continuous bits in the valid mantissa part, and the plurality of first segments correspond one-to-one to the plurality of first intermediate operands; for each first segment, using P bits in the first segment as the 1st to Pth bits in the corresponding first intermediate operand to obtain the first intermediate operand corresponding to the first segment, wherein the 1st bit in the first intermediate operand is the lowest bit, and P is a positive integer greater than 1.
[0007] For example, in the data processing method provided by at least one embodiment of the present disclosure, the second source operand is represented by at least one second intermediate operand of the second integer type, including: in response to using one second intermediate operand to represent the second source operand, converting the second source operand into the second integer type as the second intermediate operand; in response to using multiple second intermediate operands to represent the second source operand: dividing the second source operand into multiple continuous second segments, wherein each second segment includes multiple continuous bits in the second source operand, and the multiple second segments correspond one-to-one to the multiple second intermediate operands; for each second segment, using Q bits in the second segment as the 1st to Qth bits in the corresponding second intermediate operand to obtain the second intermediate operand corresponding to the second segment, wherein the 1st bit in the second intermediate operand is the lowest bit, and Q is a positive integer greater than 1.
[0008] For example, in the data processing method provided by at least one embodiment of the present disclosure, the destination operand is represented by three independent integer parameters, and the three independent integer parameters include a first integer parameter representing the mantissa part of the destination operand, a second integer parameter representing the sign bit of the destination operand, and a third integer parameter representing the exponent part of the destination operand. According to the mantissa multiplication result, the destination operand as the output parameter is obtained, including: directly using the mantissa multiplication result as the first integer parameter; determining the second integer parameter according to the sign bit of the first source operand and the sign bit of the second operand; and using the exponent part of the first source operand as the third integer parameter.
[0009] For example, in the data processing method provided in at least one embodiment of the present disclosure, the destination operand is a floating-point number, and according to the mantissa multiplication result, the destination operand as the output parameter is obtained, including: determining the mantissa part and the exponent part of the destination operand according to the mantissa multiplication result; determining the sign bit of the destination operand according to the sign bit of the first source operand and the sign bit of the second source operand.
[0010] For example, in the data processing method provided by at least one embodiment of the present disclosure, the mantissa part and the exponent part of the destination operand are determined according to the mantissa multiplication result, including: determining a valid part from the mantissa multiplication result, wherein the starting point of the valid part is the first 1 appearing in the mantissa multiplication result along a preset direction, and the preset direction is the direction from high bits to low bits in the mantissa multiplication result; determining a mantissa intermediate result according to the valid part, wherein the bit width of the mantissa intermediate result is less than or equal to L; shifting the mantissa intermediate result according to the exponent part of the first source operand to obtain the mantissa part and the exponent part of the destination operand.
[0011] For example, in the data processing method provided by at least one embodiment of the present disclosure, the end point of the valid part is the last 1 that appears in the mantissa multiplication result along the preset direction, or the end point of the valid part is the lowest bit in the mantissa multiplication result, and the mantissa intermediate result is determined based on the valid part, including: rounding the valid part according to a preset rounding rule to obtain the mantissa intermediate result.
[0012] For example, in the data processing method provided in at least one embodiment of the present disclosure, the effective part is rounded according to a preset rounding rule to obtain the mantissa intermediate result, including: in response to the length N of the effective part being less than or equal to L, directly taking the effective part as the mantissa intermediate result; in response to the length N of the effective part being greater than L, determining the mantissa intermediate result according to the L+1th bit in the effective part, wherein when the length N of the effective part is greater than L, the bit width of the mantissa intermediate result is equal to L, the highest bit in the effective part is taken as the 1st bit, and the L+1th bit in the effective part is the L+1th bit starting from the 1st bit along the preset direction.
[0013] For example, in the data processing method provided in at least one embodiment of the present disclosure, the intermediate result of the mantissa is determined according to the L+1th bit in the effective part, including: in response to the L+1th bit in the effective part being the first value, discarding the L+1th bit to the Nth bit in the effective part, and taking the 1st bit to the Lth bit in the effective part as the intermediate result of the mantissa; in response to the L+1th bit in the effective part being the second value, and at least one bit among the L+2th bit to the Nth bit in the effective part is not the first value, discarding the L+1th bit to the Nth bit in the effective part, and performing a carry operation on the Lth bit of the effective part to obtain the intermediate result of the mantissa; in response to the L+1th bit in the effective part being the second value, and the L+2th bit to the Nth bit in the effective part are all the first value, determining the intermediate result of the mantissa according to the Lth bit of the effective part.
[0014] For example, in the data processing method provided by at least one embodiment of the present disclosure, determining the valid part from the mantissa multiplication result includes: starting from the starting point, continuously selecting up to L bits from the mantissa multiplication result along the preset direction as the valid part; determining the mantissa intermediate result according to the valid part includes: taking the valid part as the mantissa intermediate result.
[0015] For example, in the data processing method provided in at least one embodiment of the present disclosure, the destination operand is the product of the first source operand and the second source operand, and the shift processing includes shifting the mantissa intermediate result according to the value of the exponent part of the first source operand.
[0016] For example, in the data processing method provided by at least one embodiment of the present disclosure, the destination operand is the rounding result after further rounding operation is performed on the product result of the first source operand and the second source operand, and in response to the rounding operation instruction, a floor operation is performed on the product result, and the shift processing includes shifting the mantissa intermediate result according to the numerical value of the exponent part of the first source operand.
[0017] For example, in the data processing method provided by at least one embodiment of the present disclosure, the destination operand is the rounding result after further rounding operation is performed on the product result of the first source operand and the second source operand, and in response to the rounding operation instruction, a rounding-up operation is performed on the product result, and the shift processing includes: shifting the mantissa intermediate result according to the numerical value of the exponent part of the first source operand to obtain the shift result and the overflow mantissa part generated by the shift; in response to the overflow mantissa part being the first value, obtaining the mantissa part and the exponent part of the destination operand according to the shift result; in response to the overflow mantissa part not being all the first value, performing a carry operation on the shift result and obtaining the mantissa part and the exponent part of the destination operand according to the carry result.
[0018] For example, in the data processing method provided by at least one embodiment of the present disclosure, the sign bit of the destination operand is determined according to the sign bit of the first source operand and the sign bit of the second operand, including: in response to the sign bit of the first source operand and the sign bit of the second source operand being the same, determining the sign bit of the destination operand to be a positive sign bit, wherein the positive sign bit indicates that the destination operand is a positive number; in response to the sign bit of the first source operand and the sign bit of the second source operand being different, determining the sign bit of the destination operand to be a negative sign bit, wherein the negative sign bit indicates that the destination operand is a negative number.
[0019] For example, in the data processing method provided by at least one embodiment of the present disclosure, each first intermediate operand represents part of the bits in the mantissa part of the first source operand, different first intermediate operands represent different bits in the first source operand, each second intermediate operand represents at least part of the bits in the second source operand, the bit width of the second integer type is greater than the sum of the maximum bit width of the first intermediate operand and the maximum bit width of the second intermediate operand, the maximum bit width of the first intermediate operand is the number of bits of the first source operand represented by the first intermediate operand representing the most bits among the multiple first intermediate operands, and the maximum bit width of the second intermediate operand is the number of bits of the second source operand represented by the second intermediate operand representing the most bits among the at least one second intermediate operand.
[0020] At least one embodiment of the present disclosure provides a data processing method, comprising: receiving a data processing instruction indicating to perform at least floating-point and integer multiplication, wherein the data processing instruction comprises a first source operand and a second source operand as input parameters, and a destination operand as an output parameter, the type of the first source operand is a floating-point type, and the type of the second source operand is a first integer type; after parsing the data processing instruction, using an operation unit to execute the data processing instruction, wherein using the operation unit to execute the data processing instruction comprises: using a plurality of first intermediate operands of a second integer type to represent a mantissa portion of the first source operand; using at least one second intermediate operand of the second integer type to represent the second source operand; performing integer multiplication of the second integer type on the plurality of first intermediate operands and the at least one second intermediate operand in pairs to obtain a plurality of integer multiplication results, wherein each integer multiplication result is of the second integer type, and each integer multiplication result is the product of a first intermediate operand and a second intermediate operand; obtaining a mantissa multiplication result according to the plurality of integer multiplication results; and obtaining a destination operand as an output parameter according to the mantissa multiplication result.
[0021] At least one embodiment of the present disclosure provides a processor, including an instruction parsing unit and an operation unit, wherein the instruction parsing unit is used to receive and parse the data processing instruction, wherein the data processing instruction includes a first source operand and a second source operand as input parameters, and a destination operand as an output parameter, the first source operand is a floating point type, and the second source operand is a first integer type, and the operation unit executes the data processing instruction after the instruction parsing unit parses the data processing instruction, wherein the operation unit executes the data processing instruction, including performing the following operations: using a plurality of first source operands of the first type to execute the data processing instruction; A first intermediate operand of two integer types represents the mantissa part of the first source operand; the second source operand is represented by using at least one second intermediate operand of the second integer type; integer multiplication of the second integer type is performed on the multiple first intermediate operands and the at least one second intermediate operand in pairs to obtain multiple integer multiplication results, wherein each integer multiplication result is of the second integer type and each integer multiplication result is the product of a first intermediate operand and a second intermediate operand; a mantissa multiplication result is obtained based on the multiple integer multiplication results; and a destination operand as an output parameter is obtained based on the mantissa multiplication result.
[0022] At least one embodiment of the present disclosure provides a data processing device, comprising: an acquisition module, configured to receive a first source operand and a second source operand as input parameters, wherein the type of the first source operand is a floating point type, and the type of the second source operand is a first integer type; a first conversion module, configured to use multiple first intermediate operands of the second integer type to represent the mantissa part of the first source operand; a second conversion module, configured to use at least one second intermediate operand of the second integer type to represent the second source operand; a multiplication calculation module, configured to perform integer multiplication of the second integer type on the multiple first intermediate operands and the at least one second intermediate operand in pairs to obtain multiple integer multiplication results, and obtain a mantissa multiplication result based on the multiple integer multiplication results, wherein each integer multiplication result is of the second integer type and each integer multiplication result is the product of a first intermediate operand and a second intermediate operand; an output module, configured to obtain a destination operand as an output parameter based on the mantissa multiplication result.
[0023] At least one embodiment of the present disclosure provides an electronic device, comprising: a memory, which non-transitorily stores computer-executable instructions; and a processor, which is configured to execute the computer-executable instructions, wherein the computer-executable instructions, when executed by the processor, implement the data processing method according to any embodiment of the present disclosure.
[0024] At least one embodiment of the present disclosure provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, the data processing method according to any embodiment of the present disclosure is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings of the embodiments will be briefly introduced below. Obviously, the drawings in the following description only relate to some embodiments of the present disclosure, but are not intended to limit the present disclosure.
[0026] Figure 1 The process of scaling the image by the Resize operator;
[0027] Figure 2 A schematic flow chart of a data processing method provided for at least one embodiment of the present disclosure;
[0028] Figure 3A A schematic diagram of the relationship between a first source operand and a first intermediate operand provided for at least one embodiment of the present disclosure;
[0029] Figure 3BA schematic diagram of the relationship between a second source operand and a second intermediate operand provided for at least one embodiment of the present disclosure;
[0030] Figure 4A and Figure 4B A schematic diagram of an effective part provided for at least one embodiment of the present disclosure;
[0031] Figure 5 A schematic flow chart of a data processing method provided for at least one embodiment of the present disclosure;
[0032] Figure 6 A schematic block diagram of a data processing device provided for at least one embodiment of the present disclosure;
[0033] Figure 7 A schematic structural diagram of a processor provided for at least one embodiment of the present disclosure;
[0034] Figure 8 A schematic block diagram of an electronic device provided in accordance with an embodiment of the present disclosure;
[0035] Fig. 9 A schematic diagram of a non-transitory computer-readable storage medium provided for at least one embodiment of the present disclosure. DETAILED DESCRIPTION
[0036] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution of the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings of the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the described embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0037] Unless otherwise defined, the technical terms or scientific terms used in the present disclosure should be understood by people with ordinary skills in the field to which the present disclosure belongs. The "first", "second" and similar words used in the present disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprise" and similar words mean that the elements or objects appearing in front of the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly. In order to keep the following description of the embodiments of the present disclosure clear and concise, the present disclosure omits the detailed description of some known functions and known components.
[0038] Traditional floating-point numbers generally include three formats, namely, half-precision floating-point numbers (FP16), single-precision floating-point numbers (FP32), and double-precision floating-point numbers (FP64), and their exponent parts and mantissa parts have different numbers of bits.
[0039] AI (Artificial Intelligence) accelerators have been widely used in deep learning model training. For the common convolution operations in deep learning models, special optimizations have been made in the design of software and hardware to accelerate calculations. For example, a variety of floating-point data formats have been optimized and developed for fields such as artificial intelligence or deep learning, such as BF16 (brain floating point 16, bit width is 16 bits), BF24 (brain floating point 24, bit width is 24 bits), TF32 (Tensor Float 32, bit width is 19 bits), etc. These data formats can greatly reduce computing processing, especially the computing resources and power consumption required for matrix multiplication or convolution multiplication operations. In addition, the processor also supports some conventional floating-point types, such as half-precision floating point (FP16, bit width is 16 bits) or single-precision floating point (FP32, bit width is 32 bits).
[0040] Table 1 below shows the data formats of several floating point precision types.
[0041] Table 1 Data format
[0042] Data Format Total number of bits Sign bit Index part The tail part Significant digit width FP32 32 1 8 23 24 FP64 64 1 11 52 53 BF16 16 1 8 7 8 BF24 24 1 8 15 16
[0043] As shown in Table 1, for the floating point precision type FP32, the total number of bits is 32 bits, including 1 sign bit, the exponent part (also known as the exponent code) includes 8 bits, the mantissa part includes 23 bits, and the mantissa effective bit width is 23+1=24 bits. For FP64, the total number of bits is 64 bits, including 1 sign bit, the exponent part (also known as the exponent code) includes 11 bits, the mantissa part includes 52 bits, and the mantissa effective bit width is 52+1=53 bits. For BF16, the total number of bits is 16 bits, including 1 sign bit, the exponent part (also known as the exponent code) includes 8 bits, the mantissa part includes 7 bits, and the mantissa effective bit width is 7+1=8 bits. For BF24, the total number of bits is 24 bits, including 1 sign bit, the exponent part (also known as the exponent code) includes 8 bits, the mantissa part includes 15 bits, and the mantissa effective bit width is 15+1=16 bits.
[0044] In order to represent the most effective data bits in the mantissa and make the floating-point number have a fixed representation, the encoding of the floating-point number should adopt certain specifications, which stipulate that the mantissa part is given as a pure decimal, and the absolute value of the mantissa should be greater than or equal to 1 / R (usually 2) and less than or equal to 1, that is, the first digit after the decimal point is not zero. Floating-point numbers that do not meet this requirement can be made to meet this specification by modifying the exponent and moving the mantissa at the same time. Therefore, for a normalized floating-point number, the highest bit of its mantissa part is 1, and the number of its mantissa effective bits is the number of mantissa bits plus 1. For example, for a single-precision floating-point number, its mantissa part includes 23 bits, its mantissa effective bits are 24 bits, and the highest bit is 1.
[0045] The Resize operator is a common operator used to resize input data by interpolation method to obtain output data of desired size.
[0046] In PyTorch, the Resize operator is a function in the torchvision library, which is mainly used to adjust the size of an image. It accepts two main parameters: size and interpolation. The size parameter specifies the size of the target image, which can be an integer or a tuple; the interpolation parameter is used to specify the interpolation method, which defaults to bilinear interpolation.
[0047] In the field of deep learning, TensorRT is a performance-optimized deep learning inference engine, in which the Resize operator plays an important role in image processing and model deployment. It processes the input data using an interpolation algorithm to achieve image scaling and cropping.
[0048] Common interpolation methods include nearest neighbor interpolation, bilinear interpolation, bicubic interpolation, etc. The choice of these interpolation methods will affect the performance of the Resize operator and the quality of the output image.
[0049] Take the Resize operator in bilinear interpolation mode as an example. Figure 1 This section describes the process of using the Resize operator to scale an image.
[0050] like Figure 1 The bilinear interpolation diagram shown in FIG. 1 corresponds a pixel point D in the scaled image to the image before scaling according to the scaling relationship. The point found is usually not an integer pixel point (i.e., a position falling between 4 pixels), such as Figure 1 As shown in point S.
[0051] The bilinear interpolation mode defines the value of point S as Figure 1The result of bilinear interpolation of the four points P11, P12, P21 and P22 around the middle point S. First, linearly interpolate P11 and P21 to get Q1, linearly interpolate P12 and P22 to get Q2, and then linearly interpolate Q1 and Q2 to get the value of S, that is:
[0052] D(x D ,y D )=S(x,y)=Q1·(y2-y)+Q2·(y-y1)
[0053] =(P 11 ·(x2-x)+P 21 ·(x-x1))·(y2-y)+(P 12 ·(x2-x)
[0054] +P 22 ·(x-x1))·(y-y1)
[0055] in,
[0056] Here, floor(*) represents the floor function, X frac Represents the scaling ratio, that is, the size of the image after scaling divided by the size of the image before scaling, x D Indicates the coordinates of the element on the image before scaling.
[0057] Obviously, the accuracy of the Resize operator depends mainly on whether the calculation of the linear interpolation coordinates is accurate, and the accuracy of the interpolation coordinates depends on the X frac ·x D , that is, the data precision used in the multiplication calculation of floating-point numbers and integers.
[0058] Many current artificial intelligence chips usually do not support FP64 high-precision floating-point numbers. Bilinear interpolation generally uses FP32 floating-point multiplication, that is: X frac Using FP32 type, x D Convert the integer to FP32 type, and then frac and x D Perform FP32 multiplication to get the result x, and finally round down the result x to get x1. This calculation method will produce scaling errors due to insufficient precision. This is because the calculation results of floating-point numbers are very similar due to precision errors, but they will be very different after rounding operations such as rounding down, resulting in large scaling errors.
[0059] At least one embodiment of the present disclosure provides a data processing method, a processor, an electronic device, and a non-transitory computer-readable storage medium. The data processing method includes: receiving a first source operand and a second source operand as input parameters, wherein the type of the first source operand is a floating point type, and the type of the second source operand is a first integer type; using multiple first intermediate operands of the second integer type to represent the mantissa part of the first source operand; using at least one second intermediate operand of the second integer type to represent the second source operand; performing integer multiplication of the second integer type on multiple first intermediate operands and at least one second intermediate operand in pairs to obtain multiple integer multiplication results, wherein each integer multiplication result is a second integer type, and each integer product result is the product of a first intermediate operand and a second intermediate operand; obtaining a mantissa multiplication result according to the multiple integer multiplication results; obtaining a destination operand as an output parameter according to the mantissa multiplication result.
[0060] In at least one embodiment, the method can simulate high-precision integer and floating-point multiplication, improve calculation accuracy, reduce the precision error of integer and floating-point multiplication, improve the accuracy of operators applying the method, such as the Resize operator, and avoid scaling errors.
[0061] The embodiments of the present disclosure are described in detail below with reference to the accompanying drawings, but the present disclosure is not limited to these specific embodiments.
[0062] Figure 2 A schematic flowchart of a data processing method provided for at least one embodiment of the present disclosure.
[0063] like Figure 2 As shown, the data processing method provided by at least one embodiment of the present disclosure includes steps S101 to S106.
[0064] In step S101 , a first source operand and a second source operand are received as input parameters.
[0065] For example, the type of the first source operand is a floating point type, and the type of the second source operand is a first integer type.
[0066] For example, the first source operand and the second source operand may be input parameters provided by an instruction or microinstruction.
[0067] For example, the first source operand and the second source operand may be intermediate parameters in a data processing process, such as intermediate parameters generated during an instruction execution process.
[0068] Depending on different application fields, the first source operand and the second source operand may have different physical meanings.
[0069] For example, in the field of speech processing, the first source operand and the second source operand can be any parameters used, input, or generated in tasks such as feature extraction, speech enhancement, and speech recognition that require floating-point and integer multiplication, such as speech feature vectors, filtering parameters, etc.
[0070] For example, in the field of image processing, the first source operand and the second source operand may be any parameters that require floating point and integer multiplication and are used, input, or generated in tasks such as image preprocessing, feature extraction, image segmentation, and target detection, such as image feature vectors, various edge detection operators (such as Sobel operator, Canny operator, Prewitt operator, etc.), image filtering operators (such as Gaussian filtering, median filtering, bilateral filtering, etc.), morphological operators (such as corrosion, expansion, opening operation, closing operation, etc.), etc. For example, in a specific example, the first source operand may be the X in the Resize operator. frac , indicating the scaling ratio, the second source operand can be x in the Resize operator D , which represents the coordinates of the element on the image before scaling.
[0071] For example, in the field of text processing, the first source operand and the second source operand can be any parameters that require floating-point and integer multiplication, such as the semantic feature vector of the text, used, input, or generated in tasks such as text classification, sentiment analysis, and text generation.
[0072] For example, in the field of video processing, the first source operand and the second source operand may be parameters in the image processing field as described above, or parameters used, inputted, or generated by methods specific to the video processing field, such as an optical flow operator (used to estimate motion between video frames) and a target tracking operator (used to track a specific target in a video).
[0073] Of course, the present disclosure is not limited to this. For other application scenarios or fields, as long as multiplication calculations of floating-point numbers and integers are required, the data processing method described in at least one embodiment of the present disclosure can be applied, and will not be described in detail here.
[0074] In step S102 , a plurality of first intermediate operands of a second integer type are used to represent a mantissa portion of a first source operand.
[0075] For example, in order to use as many bits as possible to calculate the mantissa multiplication result, and the mantissa multiplication process does not consider the influence of the sign bit, the second integer type can be set to an unsigned integer.
[0076] For example, step S102 may include: filling the hidden bits in the mantissa part of the first source operand to obtain the effective mantissa part; dividing the effective mantissa part into a plurality of continuous first segments, wherein each first segment includes a plurality of continuous bits in the effective mantissa part, and the plurality of first segments correspond one-to-one to the plurality of first intermediate operands; for each first segment, using the P bits in the first segment as the 1st to the Pth bits in the corresponding first intermediate operand to obtain the first intermediate operand corresponding to the first segment, wherein the 1st bit in the first intermediate operand is the lowest bit, and P is a positive integer greater than 1.
[0077] For normalized floating-point numbers, the highest bit of the mantissa is always 1, so in order to represent the most valid data bits in the mantissa, it is usually hidden, also called a hidden bit.
[0078] For example, for a normalized floating-point number, at least the hidden bits of the mantissa are filled in the padding operation, that is, a 1 is added before the highest bit of the mantissa of the input parameter.
[0079] For example, each first intermediate operand represents some bits in the mantissa part of the first source operand, different first intermediate operands represent different bits in the first source operand, and all first intermediate operands are equivalent to being used together to encode the mantissa part of the first source operand.
[0080] Figure 3A A schematic diagram of the relationship between a first source operand and a first intermediate operand provided for at least one embodiment of the present disclosure.
[0081] like Figure 3A As shown, first, the mantissa part (L-1 bits) of the first source operand is padded with hidden bits to obtain the effective mantissa part, as shown in Figure 3A As shown, the most significant bit of the effective mantissa part is 1. For convenience of explanation, it is assumed that the Pth bit in the effective mantissa part is 1, but the present disclosure is not limited thereto.
[0082] Afterwards, the effective mantissa is divided into a continuous first segment, such as Figure 3A The first segments 1, ..., and the first segments a shown, where a is a positive integer greater than 1.
[0083] The bit widths of the a first segments may be the same or different. For example, taking the first source operand as FP64, its effective mantissa portion includes 53 bits and can be divided into 2 first segments, one of which includes 30 bits and the other includes 23 bits.
[0084] For example, Figure 3A As shown, the first segment 1 includes the 1st to the Pth bits in the effective mantissa part, ..., and the first segment a includes the mth to the Lth bits in the effective mantissa part. Here, m is a positive integer.
[0085] For example, taking the first segment 1 as an example, the P bits in the first segment 1 are used as the 1st to Pth bits in the corresponding first intermediate operand 1 to obtain the first intermediate operand 1 corresponding to the first segment 1. Specifically, the 1st bit of the first segment 1 is used as the 1st bit of the first intermediate operand 1, the 2nd bit of the first segment 1 is used as the 2nd bit of the first intermediate operand 1, ..., the Pth bit of the first segment 1 is used as the Pth bit of the first intermediate operand 1, and the P+1th bit to the highest bit of the first intermediate operand are all 0, thereby obtaining the first intermediate operand 1. Here, the 1st bit of the effective mantissa part is the lowest bit, and the Pth bit of the effective mantissa part is the Pth bit in the direction from the low bit to the high bit.
[0086] Similarly, other first intermediate operands corresponding to the first segments may be used, for example, the first intermediate operand a corresponding to the first segment a.
[0087] In step S103 , a second source operand is represented by using at least one second intermediate operand of a second integer type.
[0088] For example, each second intermediate operand represents at least part of the bits in the second source operand. For example, when a plurality of second intermediate operands are used to represent the second source operand, each second intermediate operand represents part of the bits in the mantissa of the second source operand, different second intermediate operands represent different bits in the second source operand, and all second intermediate operands are equivalent to being used together to encode the second source operand.
[0089] For example, step S103 may include: in response to using one second intermediate operand to represent the second source operand, converting the second source operand to a second integer type as the second intermediate operand; in response to using multiple second intermediate operands to represent the second source operand: dividing the second source operand into multiple continuous second segments, wherein each second segment includes multiple continuous bits in the second source operand, and the multiple second segments correspond one-to-one to the multiple second intermediate operands; for each second segment, using Q bits in the second segment as the 1st to Qth bits in the corresponding second intermediate operand to obtain the second intermediate operand corresponding to the second segment, wherein the 1st bit in the second intermediate operand is the lowest bit, and Q is a positive integer greater than 1.
[0090] Figure 3B A schematic diagram of the relationship between a second source operand and a second intermediate operand provided for at least one embodiment of the present disclosure.
[0091] Figure 3BThe case where a plurality of second intermediate operands are used to represent the second source operand is shown in FIG. When one second intermediate operand is used to represent the second source operand, the second source operand is converted into a second integer type to be used as the second intermediate operand, which will not be described in detail here.
[0092] For example, when the second source operand is an unsigned integer, the bit width of the second source operand is V; when the second source operand is a signed integer, the bit width of the second source operand is V+1. Figure 3B The part excluding the sign bit is shown in FIG.
[0093] like Figure 3B As shown, the second source operand is divided into b consecutive second segments, such as Figure 3B The second segments 1, ..., and second segments b shown in the figure, where b is a positive integer greater than or equal to 1.
[0094] The bit widths of the b second segments may be the same or different.
[0095] For example, Figure 3B As shown, the second segment 1 includes the 1st bit to the Qth bit in the second source operand, ..., and the second segment b includes the nth bit to the Vth bit in the second source operand. Here, n is a positive integer. For convenience of explanation, it is assumed that the Qth bit in the second source operand is 1, but the present disclosure is not limited to this.
[0096] For example, taking the second segment 1 as an example, the Q bits in the second segment 1 are used as the 1st to Qth bits in the corresponding first intermediate operand 1 to obtain the second intermediate operand 1 corresponding to the second segment 1. Specifically, the 1st bit of the second segment 1 is used as the 1st bit of the second intermediate operand 1, the 2nd bit of the second segment 1 is used as the 2nd bit of the second intermediate operand 1, ..., the Qth bit of the second segment 1 is used as the Qth bit of the second intermediate operand 1, and the Q+1th bit to the highest bit of the second intermediate operand are all 0, thereby obtaining the second intermediate operand 1. Here, the 1st bit of the second source operand is the lowest bit, and the Qth bit of the second source operand is the Qth bit in the direction from the low bit to the high bit.
[0097] Similarly, other second intermediate operands corresponding to the second segments, such as the second intermediate operand b corresponding to the second segment b, are not described in detail here.
[0098] For example, the bit width of the second integer type is greater than the sum of the maximum bit width of the first intermediate operand and the maximum bit width of the second intermediate operand.
[0099] Here, the maximum bit width of the first intermediate operand is the number of bits of the first source operand represented by the first intermediate operand representing the most bits among the plurality of first intermediate operands. For example, the plurality of first segments correspond one-to-one to the plurality of first intermediate operands, and the maximum bit width of the first intermediate operand may be the number of bits of the longest first segment among the plurality of first segments.
[0100] The maximum bit width of the second intermediate operand is the number of bits of the second source operand represented by the second intermediate operand representing the most bits in at least one second intermediate operand. For example, when one second intermediate operand is used to represent the second source operand, the maximum bit width of the second intermediate operand is the bit width of the second intermediate operand itself. When multiple second intermediate operands are used to represent the second source operand, the second segment corresponds to the multiple second intermediate operands one-to-one, and the maximum bit width of the second intermediate operand can be the number of bits of the longest second segment among the multiple second segments.
[0101] For example, in a specific example, the second integer type may be UINT64, whose bit width is 64. The second source operand is UINT32 (32-bit unsigned integer), and the first source operand is FP64. Since the result of Uint64 multiplication of 32 bits and 31 bits does not exceed 64 bits, two first intermediate operands may be used to represent the mantissa portion of the first source operand, wherein one first intermediate operand represents the 1st to 23rd bits of the effective mantissa portion of the first source operand, and the other first intermediate operand represents the 24th to 53rd bits of the effective mantissa portion of the first source operand.
[0102] Thus, the floating-point and integer multiplication of the first source operand and the second source operand is converted into the multiplication of the first intermediate operand and the second intermediate operand.
[0103] In step S104, integer multiplication of the second integer type is performed on the plurality of first intermediate operands and the at least one second intermediate operand in pairs to obtain a plurality of integer multiplication results.
[0104] Each integer multiplication result is of the second integer type, and each integer product result is the product of a first intermediate operand and a second intermediate operand.
[0105] For example, in step S104, since the first intermediate operand is of the second integer type and the second intermediate operand is also of the second integer type, integer multiplication of the second integer type can be directly performed on the first intermediate operand and the second intermediate operand to obtain a mantissa multiplication result, which is also of the second integer type.
[0106] For example, the integer multiplication of the first intermediate operand and the second intermediate operand may be performed using a multiplier of the second integer type, such as a U-bit multiplier, where U is a positive integer and the bit width of the second integer type.
[0107] In step S105, a mantissa multiplication result is obtained according to the plurality of integer multiplication results, and the value E of the exponent part of the first source operand is increased or decreased accordingly to avoid overflow of the mantissa multiplication result.
[0108] For example, step S105 may include: determining the number of shift bits corresponding to each integer multiplication result; shifting each integer multiplication result according to the number of shift bits corresponding to each integer multiplication result to obtain a shifted integer multiplication result; and adding multiple shifted integer multiplication results corresponding to the multiple integer multiplication results to obtain a mantissa multiplication result.
[0109] For example, the number of shift bits corresponding to each integer multiplication result is the sum of the number of shift bits corresponding to the first intermediate operand and the second intermediate operand used to obtain the integer multiplication result.
[0110] For example, if the first segment corresponding to the first intermediate operand includes the lowest bit of the first source operand, the number of shifts corresponding to the first intermediate operand is 0. For example, if the first segment corresponding to the first intermediate operand does not include the lowest bit of the first source operand, the number of shifts corresponding to the first intermediate operand is determined according to the position of the lowest bit of the first segment in the first source operand.
[0111] Similarly, if the second segment corresponding to the second intermediate operand includes the lowest bit of the second source operand, the number of shifts corresponding to the second intermediate operand is 0. For example, if the second segment corresponding to the second intermediate operand does not include the lowest bit of the second source operand, the number of shifts corresponding to the second intermediate operand is determined according to the position of the lowest bit of the second segment in the second source operand.
[0112] For example, the mantissa multiplication result is of the second integer type.
[0113] For example, the first source operand may be represented by the first intermediate operand hFrac and the first intermediate operand lFrac, and the second source operand may be represented by the second intermediate operand x D1 and the second intermediate operand x D2 Indicates that the mantissa multiplication result = hFrac × x D1 ×2 hExe ×2 xExe1 +hFrac×x D2 ×2 hExe ×2 xExe2 +lFrac×x D1 ×2 lExe ×2 xExe1+lFrac×x D2 ×2 lExe ×2 xExe2 Here, hExe represents the number of shifts corresponding to the first intermediate operand hFrac, lExe represents the number of shifts corresponding to the first intermediate operand lFrac, and xExe1 represents the number of shifts corresponding to the first intermediate operand x D1 The corresponding number of shifts, xExe2 represents the first intermediate operand x D2 The corresponding number of shift bits.
[0114] The mantissa multiplication result reflects the relative magnitude of the product of the first source operand and the second source operand.
[0115] In step S106, the destination operand is obtained according to the mantissa multiplication result.
[0116] For example, the precision type of the destination operand is the same as the precision type of the first source operand, for example, the first source operand is FP64, and the type of the destination operand is also FP64. For example, the type of the destination operand is the same as the type of the first source operand, for example, both are floating point numbers, but the precision of the destination operand can be higher than the precision of the first source operand, for example, the mantissa significant bit width of the destination operand is greater than the mantissa significant bit width of the first source operand.
[0117] For example, a processor or chip cannot support FP64 multiplication and may not even be able to support the FP64 precision format. That is, it is very likely that in a processor or chip that applies the data processing method provided by at least one embodiment of the present disclosure, the destination operand cannot be directly represented in a high-precision floating-point format. At this time, the destination operand can be represented by three independent integer parameters, and the three independent integer parameters include a first integer parameter representing the mantissa part of the destination operand, a second integer parameter representing the sign bit of the destination operand, and a third integer parameter representing the exponent part of the destination operand.
[0118] For example, in this embodiment, step S106 may include: using the mantissa multiplication result directly as the first integer parameter; determining the second integer parameter according to the sign bit of the first source operand and the sign bit of the second operand; and using the exponent part of the first source operand as the third integer parameter.
[0119] Thus, three integers can be used to represent a multiplication result with higher precision, thereby enabling the processor or chip to support multiplication calculations of floating-point numbers and integers with higher precision.
[0120] For example, the first source operand and the second source operand may both be positive numbers. For example, in the Resize operator, the first source operand is X. frac , which is a positive floating point number, the second source operand is, for example, x D, which is a positive integer, the sign bit can be ignored at this time, and the default destination operand sign bit is a positive sign bit.
[0121] Of course, the present disclosure is not limited to this. The first source operand can be a positive number or a negative number, and the second source operand can also be a positive number or a negative number. In this case, the sign bit of the multiplication result (for example, the destination operand) can be obtained based on the sign bit of the first source operand and the sign bit of the second source operand.
[0122] For example, determining the second integer parameter based on the sign bit of the first source operand and the sign bit of the second operand may include: in response to the sign bit of the first source operand and the sign bit of the second source operand being the same, determining the second integer parameter to be a first preset value, wherein the first preset value indicates that the destination operand is a positive number; in response to the sign bit of the first source operand and the sign bit of the second source operand being different, determining the second integer parameter to be a second preset value, wherein the second preset value indicates that the destination operand is a negative number.
[0123] For example, the first preset value may be 0, and the second preset value may be 1.
[0124] For example, in some embodiments, the destination operand is a normalized floating point number, such as a processor or chip that supports floating point numbers of the destination operand precision. In this case, the mantissa multiplication result representing the relative size of the multiplication result needs to be converted to a standard floating point format.
[0125] For example, in this embodiment, step S106 may include: determining the mantissa part and the exponent part of the destination operand according to the mantissa multiplication result; and determining the sign bit of the destination operand according to the sign bit of the first source operand and the sign bit of the second source operand.
[0126] For example, determining the mantissa part and the exponent part of the destination operand based on the mantissa multiplication result may include: determining the valid part from the mantissa multiplication result, wherein the starting point of the valid part is the first 1 appearing in the mantissa multiplication result along a preset direction, and the preset direction is the direction from high bits to low bits in the mantissa multiplication result; determining the mantissa intermediate result based on the valid part, wherein the bit width of the mantissa intermediate result is less than or equal to L; shifting the mantissa intermediate result according to the exponent part of the first source operand to obtain the mantissa part and the exponent part of the destination operand.
[0127] For example, there are the following three embodiments for determining the mantissa part and the exponent part of the destination operand.
[0128] For example, in some embodiments, determining the valid part from the mantissa multiplication result may include: starting from the starting point, continuously selecting at most L bits from the mantissa multiplication result along a preset direction as the valid part.
[0129] For example, in an embodiment, determining the mantissa intermediate result according to the valid part may include: using the valid part as the mantissa intermediate result.
[0130] For example, in this embodiment, up to L bits are selected from the mantissa multiplication result starting from the starting point as the mantissa intermediate result, and the remaining part is discarded. The implementation method is relatively simple.
[0131] For example, when the number of bits between the starting point and the lowest bit of the mantissa multiplication result is greater than or equal to L, L bits are selected continuously starting from the starting point as the mantissa intermediate result.
[0132] For example, when the number of bits from the starting point to the lowest bit of the mantissa multiplication result is less than L, for example, L', where L' is a positive integer and less than L, then L' bits are selected continuously from the starting point as the mantissa intermediate result.
[0133] Figure 4A A schematic diagram of an effective portion provided for at least one embodiment of the present disclosure.
[0134] For example, in other embodiments, Figure 4A As shown, the starting point of the effective part is the first 1 that appears in the mantissa multiplication result along the direction from high to low in the mantissa multiplication result, and the end point is the last 1 that appears in the mantissa multiplication result along the preset direction.
[0135] For example, in this embodiment, determining the mantissa intermediate result according to the valid part may include: performing a rounding operation on the valid part according to a preset rounding rule to obtain the mantissa intermediate result.
[0136] Since higher-order 0s have no effect on precision, selecting the effective part from the mantissa multiplication result first can more accurately obtain the part that has a substantial impact on precision; further, since the length of the effective part is not necessarily equal to L, when the length of the effective part is greater than L, the effective part is converted into an L-bit mantissa intermediate result through rounding operation, which can more accurately represent the mantissa part of the floating-point product result, and the mantissa intermediate result is closer to the mantissa multiplication result.
[0137] For example, in at least one embodiment of the present disclosure, in response to the length N of the effective part being less than or equal to L, the effective part is directly used as the mantissa intermediate result, wherein N is a positive integer greater than 1; in response to the length N of the effective part being greater than L, the mantissa intermediate result is determined according to the L+1th bit in the effective part, wherein when the length N of the effective part is greater than L, the bit width of the mantissa intermediate result is equal to L, the highest bit in the effective part is used as the 1st bit, and the L+1th bit in the effective part is the L+1th bit starting from the 1st bit along the preset direction.
[0138] For example, in at least one embodiment of the present disclosure, determining the intermediate result of the mantissa based on the L+1th bit in the effective part may include: in response to the L+1th bit being the first value, discarding the L+1th to Nth bits of the effective part, and taking the 1st to Lth bits in the effective part as the intermediate result of the mantissa; in response to the L+1th bit being the second value, and at least one bit from the L+2th to Nth bits of the effective part is not the first value, discarding the L+1th to Nth bits of the effective part, and performing a carry operation on the Lth bit of the effective part to obtain the intermediate result of the mantissa; in response to the L+1th bit being the second value, and the L+2th to Nth bits of the effective part are all the first value, determining the intermediate result of the mantissa based on the Lth bit of the effective part.
[0139] For example, determining the intermediate result of the mantissa based on the Lth bit of the effective part may include: in response to the Lth bit of the effective part being a first value, taking the 1st to Lth bits in the effective part as the intermediate result of the mantissa; in response to the Lth bit of the effective part being a second value, discarding the L+1th to Nth bits of the effective part, and performing a carry operation on the Lth bit of the effective part to obtain the intermediate result of the mantissa.
[0140] The length N of the valid part is the number of bits of the valid part including the start point and the end point.
[0141] For example, the preset rounding rule may stipulate that when N is less than or equal to L, the effective part can be directly used as the intermediate result of the mantissa; when N is greater than L, the effective part is rounded according to the L+1th bit in the effective part to obtain the intermediate result of the mantissa.
[0142] For example, the first value may be 0 and the second value may be 1.
[0143] For example, the preset rounding rule may stipulate that, when N is greater than L, if the L+1th bit is 0, the L+1th to Nth bits of the effective part are discarded, and the 1st to Lth bits in the effective part are used as the intermediate result of the mantissa; if the L+1th bit is 1, since the Nth bit must be 1, at least one bit from the L+2th to Nth bits of the effective part must be 1, then the L+1th to Nth bits of the effective part are discarded, and a carry operation is performed on the Lth bit, that is, 1 is added to the Lth bit to obtain the intermediate result of the mantissa.
[0144] Of course, the preset rounding rule can be set as needed. The present disclosure is not limited to the use of the rounding rules described in the above embodiment, which will not be described one by one here.
[0145] Figure 4B A schematic diagram of an effective portion provided for at least one embodiment of the present disclosure.
[0146] For example, in other embodiments, Figure 4BAs shown, the starting point of the effective part is the first 1 that appears in the mantissa multiplication result from the high bit to the low bit in the mantissa multiplication result, and the end point is the lowest bit in the mantissa multiplication result.
[0147] For example, in this embodiment, determining the mantissa intermediate result according to the valid part may include: performing a rounding operation on the valid part according to a preset rounding rule to obtain the mantissa intermediate result.
[0148] Similar to the above embodiment, since higher-order 0s have no effect on precision, selecting the effective part from the mantissa multiplication result first can more accurately obtain the part that has a substantial impact on precision; further, since the length of the effective part is not necessarily equal to L, the effective part is converted into an L-bit mantissa intermediate result through rounding operation to more accurately represent the mantissa part of the floating-point product result.
[0149] For example, the preset rounding rule may stipulate that when the L+1th bit of the effective part is 0, the L+1th bit to the Nth bit of the effective part is discarded, and the 1st bit to the Lth bit in the effective part is used as the intermediate result of the mantissa; when the L+1th bit of the effective part is 1, if any bit from the L+2th bit to the Nth bit of the effective part is 1 at this time, a carry operation is performed, that is, 1 is added to the Lth bit, and the intermediate result of the mantissa is obtained. If the L+2th bit to the Nth bit of the effective part are all 0 and the Lth bit is 0 at this time, the L+1th bit to the Nth bit of the effective part are discarded, and the 1st bit to the Lth bit in the effective part are used as the intermediate result of the mantissa. If the L+2th bit to the Nth bit of the effective part are all 0 and the Lth bit is 1 at this time, the L+1th bit to the Nth bit of the effective part are discarded, and the 1st bit to the Lth bit in the effective part are used as the intermediate result of the mantissa.
[0150] For more information about “rounding the valid part according to the preset rounding rule to obtain the intermediate result of the mantissa”, please refer to the relevant description of the above embodiment, which will not be repeated here.
[0151] For example, in some embodiments, the destination operand is the product of the first source operand and the second source operand.
[0152] For example, in this embodiment, the mantissa intermediate result is shifted according to the exponent part of the first source operand to obtain the mantissa part and the exponent part of the destination operand, which may include: shifting the mantissa intermediate result according to the value of the exponent part of the first source operand to obtain the mantissa part and the exponent part of the destination operand.
[0153] For example, shifting the mantissa intermediate result according to the value E of the exponent part of the first source operand is equivalent to multiplying the mantissa intermediate result by 2 E The shifted result is normalized to obtain the mantissa and exponent of the destination operand.
[0154] For example, in some embodiments, the destination operand is the rounded result after further rounding operation is performed on the product result of the first source operand and the second source operand, for example, the rounding operation indicates to perform a floor operation on the product result. For example, the first source operand can be the scaling factor X in the Resize operator. frac , the second source operand can be the coordinate x of the element on the image before scaling in the Resize operator D , the rounding operation is floor(x) performed on the product result.
[0155] For example, in this embodiment, the mantissa intermediate result is shifted according to the exponent part of the first source operand to obtain the mantissa part and the exponent part of the destination operand, which may include: shifting the mantissa intermediate result according to the value of the exponent part of the first source operand to obtain the mantissa part and the exponent part of the destination operand.
[0156] For the floor operation, when the value E of the exponent part is greater than 0, the intermediate result of the mantissa is enlarged, and the overflow mantissa will not appear; when the value E of the exponent part is less than 0, some bits may become the overflow mantissa (the least significant bit of the mantissa flows out from the right end of the mantissa field), but because it is a floor operation, these overflow mantissa parts are also discarded, so they have no effect on the accuracy. Therefore, when the further rounding operation is a floor operation, no additional operation is required for the product result of the first source operand and the second source operand.
[0157] For example, in some embodiments, the destination operand is a rounded result after a further rounding operation is performed on a product result of a first source operand and a second source operand, for example, the rounding operation indicates to perform a round-up operation on the product result.
[0158] For example, in this embodiment, the mantissa intermediate result is shifted according to the exponent part of the first source operand to obtain the mantissa part and the exponent part of the destination operand, which may include: shifting the mantissa intermediate result according to the value of the exponent part of the first source operand to obtain the shift result and the overflow mantissa part generated by the shift; in response to the overflow mantissa parts being all the first value, obtaining the mantissa part and the exponent part of the destination operand according to the shift result; in response to the overflow mantissa parts not being all the first value, performing a carry operation on the shift result and obtaining the mantissa part and the exponent part of the destination operand according to the carry result.
[0159] For the rounding up operation, when the value E of the exponent part is greater than 0, the intermediate result of the mantissa is enlarged, and the overflow mantissa will not appear. Therefore, the mantissa and exponent of the destination operand can be obtained according to the shift result, for example, the mantissa and exponent of the destination operand are obtained by normalizing the shift result. When the value E of the exponent part is less than 0, some bits may become the overflow mantissa (the least significant bit of the mantissa flows out from the right end of the mantissa domain). If the overflow mantissa, that is, the bits flowing out from the right end of the mantissa domain are all 0, the mantissa and exponent of the destination operand can be obtained according to the shift result, for example, the mantissa and exponent of the destination operand are obtained by normalizing the shift result; if the overflow mantissa is not all 0, a carry operation is performed on the shift result, for example, 1 is added to the lowest bit of the shift result and the mantissa and exponent of the destination operand are obtained according to the carry result.
[0160] Of course, in addition to rounding up and rounding down operations, other rounding operations can also be set, such as rounding to the nearest integer, rounding to zero, mean rounding, etc. Those skilled in the art can set them as needed, and the present disclosure does not make specific restrictions on this.
[0161] In order to avoid overflow of the mantissa multiplication result, the value E of the exponent part of the first source operand can also be adjusted according to the number of shift bits corresponding to the integer multiplication result, and the shift processing is performed according to the adjusted value E of the exponent part of the first source operand.
[0162] For example, shifting the mantissa intermediate result according to the exponent part of the first source operand to obtain the mantissa part and the exponent part of the destination operand can include: determining the maximum value of the shift bit numbers corresponding to multiple integer multiplication results; adjusting the exponent part of the first source operand according to the maximum value; shifting the mantissa intermediate result according to the adjusted exponent part of the first source operand to obtain the mantissa part and the exponent part of the destination operand.
[0163] For example, determining the sign bit of the destination operand based on the sign bit of the first source operand and the sign bit of the second operand may include: in response to the sign bit of the first source operand and the sign bit of the second source operand being the same, determining the sign bit of the destination operand to be a positive sign bit, wherein the positive sign bit indicates that the destination operand is a positive number; in response to the sign bit of the first source operand and the sign bit of the second source operand being different, determining the sign bit of the destination operand to be a negative sign bit, wherein the negative sign bit indicates that the destination operand is a negative number.
[0164] For example, a positive sign bit can be represented by 0 and a negative sign bit can be represented by 1.
[0165] In at least one embodiment of the present disclosure, the multiplication of floating-point numbers and integers is converted to the multiplication of integers and integers. Specifically, the mantissa part of the floating-point number is converted to an integer and the integer multiplication is performed with the integer, so that as many mantissa digits as possible can be retained, the calculation accuracy can be improved, the precision error of integer and floating-point multiplication can be reduced, the accuracy of operators applying the method, such as the Resize operator, can be improved, and scaling errors can be avoided. For example, in some processors or chips that do not support high-precision floating-point numbers or high-precision floating-point multiplication, the data processing method provided by at least one embodiment of the present disclosure can be used to perform high-precision floating-point multiplication.
[0166] The following takes the case where the type of the first source operand is FP64, the type of the second source operand is UINT32 (32-bit unsigned integer), and the second integer type is UINT64 as an example to specifically illustrate the execution process of the data processing method provided by at least one embodiment of the present disclosure.
[0167] As mentioned above, the effective bit width of the mantissa part of FP64 is 53. Two first intermediate operands are used to represent the mantissa part of the first source operand, and one second intermediate operand is used to represent the second source operand. The first intermediate operand lFrac represents the 1st to 23rd bits of the effective mantissa part of the first source operand, and the first intermediate operand hFrac represents the 24th to 53rd bits of the effective mantissa part of the first source operand.
[0168] First, referring to step S101, a first source operand and a second source operand are received. For example, the first source operand may be a scaling factor X in a Resize operator. frac , the second source operand can be the coordinate x of the element on the image before scaling in the Resize operator D .
[0169] Afterwards, referring to step S102 , two first intermediate operands of type UINT64 are used to represent the mantissa portion of the first source operand. Specifically, the hidden bits in the mantissa part of the first source operand can be filled first to obtain the effective mantissa part; then the effective mantissa part is divided into two first segments, the first segment 1 includes the 1st to 23rd bits of the effective mantissa part, and the first segment 2 includes the 24th to 53rd bits of the effective mantissa part; then, the 23 bits of the first segment 1 are used as the 1st to 23rd bits of the first intermediate operand lFrac, for example, the lowest bit (1st bit) of the first segment 1 is used as the lowest bit (1st bit) of the first intermediate operand lFrac, and the 2nd bit of the first segment 1 is used as the 2nd bit of the first intermediate operand lFrac, and so on; the 30 bits of the first segment 2 are used as the 1st to 30th bits of the first intermediate operand hFrac, for example, the lowest bit (1st bit) of the first segment 2 is used as the lowest bit (1st bit) of the first intermediate operand hFrac, and the 2nd bit of the first segment 2 is used as the 2nd bit of the first intermediate operand hFrac, and so on.
[0170] Referring to step S103 , the second source operand is converted from UINT32 type to UINT64 type.
[0171] Referring to step S104, UINT64 multiplication is performed on the first intermediate operand and the second intermediate operand in pairs to obtain an integer multiplication result lFrac×x D And the integer multiplication result hFrac×x D .
[0172] Referring to step S105, a mantissa multiplication result n is obtained according to the multiple integer multiplication results. The mantissa multiplication result n is also of UINT64 type.
[0173] For example, the mantissa multiplication result n = lFrac × x D ×2 lExe +hFrac×x D ×2 hExe , here, lExe=0, hExe=23.
[0174] Referring to step S106, the mantissa multiplication result n represents the relative size of the mantissa part, and some rounding, shifting and other operations need to be performed on it to obtain the absolute size of the product result of the first source operand and the second source operand.
[0175] For example, firstly, the effective part can be determined from the mantissa multiplication result n, and then the mantissa intermediate result can be determined according to the effective part. Specifically, any one of the above three implementation modes can be adopted.
[0176] Here, we take the starting point of the valid part as the first 1 appearing in the preset direction in the mantissa multiplication result n, and the end point of the valid part as the lowest bit of the mantissa multiplication result n as an example to illustrate the process of obtaining the mantissa intermediate result.
[0177] Table 2 shows the preset rounding rules for converting the effective part into the mantissa intermediate result provided by at least one embodiment of the present disclosure.
[0178] Table 2 Preset rounding rules
[0179]
[0180]
[0181] As shown in Table 2, the preset rounding rule stipulates that if the length N of the effective part is less than or equal to 53, the effective part is directly used as the intermediate result of the mantissa. The preset rounding rule also stipulates that if the length N of the effective part is greater than 53, when the 54th bit is 0, the 54th to the Nth bit of the effective part are discarded and the first 53 bits are retained as the intermediate result of the mantissa; when the 54th bit is 1 and the 55th to the Nth bit are not all 0, the first 53 bits of the effective part are retained and the 53th bit is added by 1 as the intermediate result of the mantissa; when the 54th bit is 1 and the 55th to the Nth bit are all 0, if the 53rd bit is 0, the 54th to the Nth bit of the effective part are discarded and the first 53 bits are retained as the intermediate result of the mantissa, and if the 53rd bit is 1, the first 53 bits of the effective part are retained and the 53th bit is added by 1 as the intermediate result of the mantissa.
[0182] After obtaining the mantissa intermediate result, the mantissa intermediate result is shifted according to the exponent part of the first source operand to obtain the mantissa part and the exponent part of the destination operand.
[0183] For example, the mantissa intermediate result is shifted according to the value E of the exponent part of the first source operand to obtain the mantissa part and the exponent part of the destination operand. For example, as described above, the mantissa intermediate result can be shifted according to the value E of the exponent part of the adjusted first source operand to obtain the mantissa part and the exponent part of the destination operand.
[0184] For the specific shift processing process, reference may be made to the relevant description of the aforementioned embodiment, and repeated parts will not be repeated here.
[0185] In addition, if the first source operand and the second source operand are not restricted to positive integers, the sign bit of the destination operand needs to be determined based on the sign bit of the first source operand and the sign bit of the second operand. The specific process is as described above and will not be repeated here.
[0186] Therefore, through the above process, UINT64 multiplication can be used to simulate FP64 multiplication in software, to achieve high-precision multiplication, reduce the precision error of integer and floating-point multiplication, improve the accuracy of operators that apply this method, such as the Resize operator, and avoid scaling errors.
[0187] The data processing method provided by at least one embodiment of the present disclosure can be applied to different systems or devices, such as Figure 8 The electronic device 500 shown. The electronic device 500 can be a terminal, such as a mobile phone terminal, a tablet computer, a laptop computer, an AR device, a VR device, a vehicle terminal, etc., and can also be a server, etc. The data processing method provided in at least one embodiment of the present disclosure can be applied to the electronic device 500 involving CPU, high performance computing (High Performance Computing, HPC for short) and artificial intelligence (Artificial Intelligence, AI) and other scenarios related to floating point and integer multiplication, such as scalar calculation units, vector calculation units, matrix calculation units and tensor calculation units. Of course, the present disclosure is not limited to this, and any scenario, device, apparatus, etc. involving floating point and integer multiplication can adopt the data processing method provided by at least one embodiment of the present disclosure.
[0188] For example, refer to Figure 8 The electronic device 500 shown, when implementing the data processing method provided by at least one embodiment of the present disclosure, the processing device 501 performs various appropriate actions and processes according to the non-temporary computer-readable instructions stored in the memory to implement the data processing method. For example, the first source operand and the second source operand are stored in a memory, such as a register, a cache or a memory. When floating-point and integer multiplication is required, the first source operand and the second source operand are read from the memory, and the processing device 501 performs floating-point and integer multiplication and other processes on the first source operand and the second source operand according to the data processing method described in at least one embodiment of the present disclosure to obtain the destination operand. The destination operand can be transferred to the corresponding operator for use again, or transferred to the memory for storage.
[0189] At least one embodiment of the present disclosure further provides a data processing method. Figure 5 A schematic flowchart of a data processing method provided for at least one embodiment of the present disclosure.
[0190] like Figure 5 As shown, the data processing method provided by at least one embodiment of the present disclosure includes steps S201-S202.
[0191] For example, in step S201, a data processing instruction instructing to perform at least floating point and integer multiplication is received.
[0192] For example, a data processing instruction includes a first source operand and a second source operand as input parameters, and a destination operand as an output parameter.
[0193] For example, the type of the first source operand is a floating point type, and the type of the second source operand is a first integer type.
[0194] For example, the data processing instruction may be used to perform only the calculation of floating point number and integer multiplication, and in this case the destination operand is the product result of the first source operand and the second source operand.
[0195] For example, in addition to performing the calculation of floating-point number and integer multiplication, the data processing instruction may also be superimposed with other operations, such as further calculation operations, such as rounding operations, on the multiplication result of floating-point number and integer multiplication.
[0196] For example, the data processing instruction may further perform a rounding operation on the multiplication result of the floating point number and the integer multiplication, and use the result after the rounding operation as the destination operand.
[0197] Of course, the data processing instructions may also include more or other computing operations, and the present disclosure does not impose specific limitations on this.
[0198] For example, the data processing instruction may be a machine instruction, or the data processing instruction may be a microinstruction. For example, the data processing instruction may be an instruction or microinstruction for performing multiplication of floating point numbers and integers. For example, the data processing instruction may be the Resize operator as described above, which performs floor(X frac ·x D ) microinstructions for operations.
[0199] For example, the first source operand is a tensor of a floating point number or a floating point precision type, such as FP32, FP64, etc. For example, the second source operand is an integer or an integer tensor, such as UINT32, UINT64, etc.
[0200] The types of the first source operand and the second source operand can be set as needed, and the present disclosure does not impose any specific limitation on this.
[0201] In step S202, after parsing the data processing instruction, the data processing instruction is executed using the operation unit.
[0202] For example, after receiving a data processing instruction, the processor parses the data processing instruction, such as decoding the data processing instruction, generates a microinstruction and sends the microinstruction to an instruction allocation unit; the instruction allocation unit sends the microinstruction to a corresponding scheduling queue according to the microinstruction category; in response to the microinstruction, when the first source operand and the second source operand (all or the required part) are prepared, the operation unit reads the data and executes the relevant operations of the data processing instruction.
[0203] For example, the operation unit may include hardware involved in executing data processing instructions, such as a multiplier, a register, a queue, an ALU (Arithmetic Logic Unit), etc.
[0204] For example, step S202 may include: using multiple first intermediate operands of the second integer type to represent the mantissa part of the first source operand; using at least one second intermediate operand of the second integer type to represent the second source operand; performing integer multiplication of the second integer type on the multiple first intermediate operands and at least one second intermediate operand in pairs to obtain multiple integer multiplication results, wherein each integer multiplication result is of the second integer type, and each integer product result is the product of a first intermediate operand and a second intermediate operand; obtaining a mantissa multiplication result based on the multiple integer multiplication results; and obtaining a destination operand as an output parameter based on the mantissa multiplication result.
[0205] Regarding "using a plurality of first intermediate operands of the second integer type to represent the mantissa portion of the first source operand", reference may be made to the relevant contents of the aforementioned step S102, which will not be repeated here.
[0206] Regarding “using at least one second intermediate operand of a second integer type to represent a second source operand”, reference may be made to the relevant contents of the aforementioned step S103 , which will not be described in detail here.
[0207] Regarding “performing integer multiplication of the second integer type on multiple first intermediate operands and at least one second intermediate operand in pairs to obtain multiple integer multiplication results”, reference may be made to the relevant content of the aforementioned step S104, which will not be repeated here.
[0208] Regarding “obtaining a mantissa multiplication result based on multiple integer multiplication results”, reference may be made to the relevant content of the aforementioned step S105, which will not be repeated here.
[0209] Regarding "obtaining a destination operand as an output parameter based on the mantissa multiplication result", reference may be made to the relevant contents of the aforementioned step S106, which will not be repeated here.
[0210] The data processing method provided in at least one embodiment of the present disclosure can achieve technical effects similar to those of the aforementioned data processing method, and the repeated parts will not be repeated.
[0211] At least one embodiment of the present disclosure further provides a data processing device. Figure 6 A schematic block diagram of a data processing device provided for at least one embodiment of the present disclosure.
[0212] like Figure 6 As shown, the data processing device 300 includes an acquisition module 301 , a first conversion module 302 , a second conversion module 303 , a multiplication calculation module 304 and an output module 305 .
[0213] For example, the acquisition module 301 is configured to receive a first source operand and a second source operand as input parameters. For example, the type of the first source operand is a floating point type, and the type of the second source operand is a first integer type.
[0214] For example, the first conversion module 302 is configured to represent the mantissa portion of the first source operand using a plurality of first intermediate operands of the second integer type.
[0215] For example, the second conversion module 303 is configured to represent the second source operand using at least one second intermediate operand of a second integer type.
[0216] For example, the multiplication calculation module 304 is configured to perform integer multiplication of the second integer type on multiple first intermediate operands and at least one second intermediate operand in pairs to obtain multiple integer multiplication results, and obtain a mantissa multiplication result based on the multiple integer multiplication results.
[0217] For example, each integer multiplication result is of the second integer type, and each integer multiplication result is the product of a first intermediate operand and a second intermediate operand.
[0218] For example, the output module 305 is configured to obtain a destination operand as an output parameter according to the mantissa multiplication result.
[0219] For example, the destination operand can be directly output from the data processing device 300 and transmitted to other components that need to use the output parameter, such as a storage device or other computing device.
[0220] For example, the acquisition module 301, the first conversion module 302, the second conversion module 303, the multiplication calculation module 304 and the output module 305 include codes and programs stored in the memory. The acquisition module 301, the first conversion module 302, the second conversion module 303, the multiplication calculation module 304 and the output module 305 are implemented as a central processing unit (CPU) or other forms of processing units with data processing capabilities and / or instruction execution capabilities. The processing unit can be a general-purpose processor, and can also be a single-chip microcomputer, a microprocessor, a digital signal processor, a dedicated image processing chip, or a field programmable logic array, etc. The acquisition module 301, the first conversion module 302, the second conversion module 303, the multiplication calculation module 304 and the output module 305 execute the code and program to implement some or all of the functions of the acquisition module 301, the first conversion module 302, the second conversion module 303, the multiplication calculation module 304 and the output module 305 as described above. For example, the acquisition module 301, the first conversion module 302, the second conversion module 303, the multiplication calculation module 304 and the output module 305 can be a circuit board or a combination of multiple circuit boards, which are used to implement the functions described above. In the embodiment of the present application, the circuit board or the combination of multiple circuit boards may include: (1) one or more processors; (2) one or more non-temporary memories connected to the processor; and (3) firmware stored in the memory that can be executed by the processor.
[0221] It should be noted that the acquisition module 301 can be used to implement Figure 2 In step S101 shown in FIG. 1 , the first conversion module 302 may be used to implement Figure 2 In step S102, the second conversion module 303 can be used to implement Figure 2 In step S103, the multiplication calculation module 304 can be used to implement Figure 2 In step S104 and step S105 shown in FIG. 1 , the output module 305 can be used to implement Figure 2 Step S106 shown. Therefore, for the specific description of the functions that can be implemented by the acquisition module 301, the first conversion module 302, the second conversion module 303, the multiplication calculation module 304 and the output module 305, reference can be made to the relevant description of steps S101 to S106 in the embodiment of the above-mentioned data processing method, and the repeated parts will not be repeated. In addition, the data processing device 300 can achieve technical effects similar to those of the above-mentioned data processing method, which will not be repeated here.
[0222] It should be noted that in at least one embodiment of the present disclosure, the data processing device 300 may include more or fewer circuits or units, and the connection relationship between the various circuits or units is not limited and can be determined according to actual needs. The specific configuration of each circuit or unit is not limited and can be composed of analog devices according to circuit principles, or can be composed of digital chips, or in other applicable ways.
[0223] For example, the data processing device 300 may be implemented in hardware, software, or a combination of hardware and software, and the present disclosure does not impose any specific limitations on this.
[0224] The data processing method provided by at least one embodiment of the present disclosure can achieve a technical effect similar to the data processing method described above, and will not be described in detail here.
[0225] Figure 7 A schematic structural diagram of a processor provided in at least one embodiment of the present disclosure. Figure 7 As shown, the processor 400 includes an instruction parsing unit 401 and an operation unit 402 .
[0226] For example, the instruction parsing unit 401 is used to receive and parse data processing instructions.
[0227] For example, the data processing instruction includes a first source operand and a second source operand as input parameters, and a destination operand as an output parameter, the type of the first source operand is a floating point type, and the type of the second source operand is a first integer type.
[0228] For example, the operation unit 402 executes the data processing instruction after the instruction parsing unit parses the data processing instruction.
[0229] For example, when the operation unit 402 executes a data processing instruction, it includes performing the following operations: using multiple first intermediate operands of the second integer type to represent the mantissa part of the first source operand; using at least one second intermediate operand of the second integer type to represent the second source operand; performing integer multiplication of the second integer type on the multiple first intermediate operands and at least one second intermediate operand in pairs to obtain multiple integer multiplication results, wherein each integer multiplication result is of the second integer type, and each integer product result is the product of a first intermediate operand and a second intermediate operand; obtaining a mantissa multiplication result based on the multiple integer multiplication results; and obtaining a destination operand as an output parameter based on the mantissa multiplication result.
[0230] Specifically, when the upper-layer software based on the processor (for example, AI applications, HPC applications, and scientific computing applications, etc.) can send data processing instructions for computing processing to the processor (for example, CPU or GPU) through a uniformly encapsulated function library, the data processing instruction can carry a first source operand and a second source operand as input parameters; when the processor receives the data processing instruction, the instruction parsing unit 401 parses the data processing instruction to obtain the first source operand and the second source operand as input parameters, and the processor schedules the operation unit to perform the data processing task for the first source operand and the second source operand as input parameters. For example, after parsing the data processing instruction, the processor can store the first source operand and the second source operand in the data processing instruction into a register or memory, so that when the operation unit 402 performs computing processing, it can obtain the input parameters from the register or memory.
[0231] Regarding the specific process of using the operation unit 402 to execute the data processing instruction, reference may be made to steps S102 to S106 in the aforementioned data processing method, and the repeated parts will not be repeated here.
[0232] Figure 8 The following is a schematic block diagram of an electronic device provided by an embodiment of the present disclosure. Figure 8 As shown, the electronic device 500 is suitable for implementing the data processing method provided by the embodiment of the present disclosure. It should be noted that Figure 8 The components of the electronic device 500 shown are merely exemplary and non-limiting. The electronic device 500 may also have other components according to actual application requirements.
[0233] like Figure 8 As shown, the electronic device 500 may include a processing device (eg, a central processing unit, a graphics processing unit, etc.) 501, which may perform various appropriate actions and processes according to non-transitory computer-readable instructions stored in a memory to implement various functions.
[0234] For example, when the computer readable instructions are executed by the processing device 501, one or more steps in the data processing method described in any of the above embodiments may be executed. It should be noted that for a detailed description of the processing process of the data processing method, reference may be made to the relevant description in the above data processing method embodiments.
[0235] For example, the memory may include any combination of one or more computer program products, and the computer program product may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) 503 and / or cache memory (cache), etc. For example, computer-readable instructions may be loaded from storage device 508 into random access memory (RAM) 503 to run computer-readable instructions. Non-volatile memory may include, for example, read-only memory (ROM) 502, hard disk, erasable programmable read-only memory (EPROM), portable compact disk read-only memory (CD-ROM), USB memory, flash memory, etc. Various applications and various data, such as style images, and various data used and / or generated by applications, etc., may also be stored in the computer-readable storage medium.
[0236] For example, the processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0237] Typically, the following devices may be connected to the I / O interface 505: an input device 506 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 508 including, for example, a magnetic tape, a hard disk, a flash memory, etc.; and a communication device 509. The communication device 509 may allow the electronic device 500 to communicate with other electronic devices wirelessly or by wire to exchange data. Although Figure 8 An electronic device 500 having various devices is shown, but it should be understood that it is not required to implement or have all the devices shown, and the electronic device 500 may alternatively implement or have more or fewer devices. For example, the processing device 501 can control other components in the electronic device 500 to perform the desired functions. The processing device 501 can be a device with data processing capabilities and / or program execution capabilities such as a central processing unit (CPU), a tensor processing unit (TPU) or a graphics processing unit GPU. The central processing unit (CPU) can be an X86, ARM, RISC-V architecture, etc. The GPU can be directly integrated into the SOC, directly integrated into the motherboard, or built into the north bridge chip of the motherboard.
[0238] Fig. 9 A schematic diagram of a non-transitory computer-readable storage medium provided for at least one embodiment of the present disclosure. Fig. 9As shown, the storage medium 600 may be a non-transitory computer-readable storage medium, and one or more computer-readable instructions 601 may be non-transitory stored on the storage medium 600. For example, when the computer-readable instructions 601 are executed by a processor, one or more steps in the data processing method described above may be executed.
[0239] For example, the storage medium 600 may be applied to the electronic device 500 described above. For example, the storage medium 600 may include a storage device 508 in the electronic device 500 .
[0240] For example, the storage device may include any combination of one or more computer program products, and the computer program product may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and / or cache memory (cache), etc. Non-volatile memory may include, for example, read-only memory (ROM), hard disk, erasable programmable read-only memory (EPROM), portable compact disk read-only memory (CD-ROM), USB memory, flash memory, etc. One or more computer-readable instructions may be stored on the computer-readable storage medium, and the processor may execute the computer-readable instructions to implement various functions of the processor. Various applications and various data may also be stored in the storage medium.
[0241] For example, the storage medium may include a memory card of a smart phone, a storage component of a tablet computer, a hard disk of a personal computer, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a portable compact disk read-only memory (CD-ROM), flash memory, or any combination of the above storage media, or other applicable storage media.
[0242] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession 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 square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0243] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of a unit does not, in some cases, constitute a limitation on the unit itself.
[0244] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0245] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0246] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0247] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
[0248] There are a few points to note about this disclosure:
[0249] (1) The drawings of the embodiments of the present disclosure only relate to the structures related to the embodiments of the present disclosure, and other structures may refer to the general design.
[0250] (2) In the absence of conflict, the embodiments of the present disclosure and the features therein may be combined with each other to obtain new embodiments.
[0251] The above description is only a specific implementation of the present disclosure, but the protection scope of the present disclosure is not limited thereto. The protection scope of the present disclosure shall be based on the protection scope of the claims.
Claims
1. A data processing method, comprising: Receiving a first source operand and a second source operand as input parameters, wherein the type of the first source operand is a floating point number type and the type of the second source operand is a first integer type; representing a mantissa portion of the first source operand using a plurality of first intermediate operands of a second integer type; representing the second source operand using at least one second intermediate operand of the second integer type; Performing integer multiplication of the second integer type on the plurality of first intermediate operands and the at least one second intermediate operand in pairs to obtain a plurality of integer multiplication results, wherein each integer multiplication result is of the second integer type, and each integer product result is a product of a first intermediate operand and a second intermediate operand; Obtaining a mantissa multiplication result according to the multiple integer multiplication results; According to the mantissa multiplication result, a destination operand as an output parameter is obtained.
2. The data processing method according to claim 1, wherein: Representing a mantissa portion of the first source operand using a plurality of first intermediate operands of a second integer type includes: Filling the hidden bits in the mantissa part of the first source operand to obtain a valid mantissa part; Dividing the effective mantissa portion into a plurality of consecutive first segments, wherein each first segment includes a plurality of consecutive bits in the effective mantissa portion, and the plurality of first segments correspond one-to-one to the plurality of first intermediate operands; For each first segment, P bits in the first segment are used as the 1st to Pth bits in the corresponding first intermediate operand to obtain the first intermediate operand corresponding to the first segment, wherein the 1st bit in the first intermediate operand is the lowest bit, and P is a positive integer greater than 1.
3. The data processing method according to claim 1, wherein: Representing the second source operand using at least one second intermediate operand of the second integer type comprises: In response to representing the second source operand using a second intermediate operand, converting the second source operand to the second integer type as the second intermediate operand; In response to representing the second source operand using a plurality of second intermediate operands: Divide the second source operand into a plurality of consecutive second segments, wherein each second segment includes a plurality of consecutive bits in the second source operand, and the plurality of second segments correspond one-to-one to the plurality of second intermediate operands; For each second segment, Q bits in the second segment are used as the 1st to Qth bits in the corresponding second intermediate operand to obtain the second intermediate operand corresponding to the second segment, wherein the 1st bit in the second intermediate operand is the lowest bit, and Q is a positive integer greater than 1.
4. The data processing method according to claim 1, wherein: The destination operand is represented by three independent integer parameters, the three independent integer parameters including a first integer parameter representing a mantissa portion of the destination operand, a second integer parameter representing a sign bit of the destination operand, and a third integer parameter representing an exponent portion of the destination operand, According to the mantissa multiplication result, a destination operand as an output parameter is obtained, including: Using the mantissa multiplication result directly as the first integer parameter; Determining the second integer parameter according to the sign bit of the first source operand and the sign bit of the second source operand; The exponent portion of the first source operand is used as the third integer parameter.
5. The data processing method according to claim 1, wherein: The destination operand is a floating point number, According to the mantissa multiplication result, a destination operand as an output parameter is obtained, including: Determining a mantissa part and an exponent part of the destination operand according to the mantissa multiplication result; The sign bit of the destination operand is determined according to the sign bit of the first source operand and the sign bit of the second operand.
6. The data processing method according to claim 5, wherein: Determining a mantissa part and an exponent part of the destination operand according to the mantissa multiplication result includes: Determine a valid part from the mantissa multiplication result, wherein the starting point of the valid part is the first 1 that appears in the mantissa multiplication result along a preset direction, and the preset direction is the direction from high to low bits in the mantissa multiplication result; Determine a mantissa intermediate result according to the effective part, wherein a bit width of the mantissa intermediate result is less than or equal to a mantissa effective bit width L of the first source operand, where L is a positive integer; The mantissa intermediate result is shifted according to the exponent part of the first source operand to obtain the mantissa part and the exponent part of the destination operand.
7. The data processing method according to claim 6, wherein: The end point of the effective part is the last 1 that appears in the mantissa multiplication result along the preset direction, or the end point of the effective part is the lowest bit in the mantissa multiplication result, Determining a mantissa intermediate result according to the valid part includes: The effective part is rounded according to a preset rounding rule to obtain the intermediate result of the mantissa.
8. The data processing method according to claim 7, wherein: The effective part is rounded according to a preset rounding rule to obtain the intermediate result of the mantissa, including: In response to the length N of the effective part being less than or equal to L, directly using the effective part as the mantissa intermediate result; In response to the length N of the effective part being greater than L, the mantissa intermediate result is determined according to the L+1th bit in the effective part, wherein when the length N of the effective part is greater than L, the bit width of the mantissa intermediate result is equal to L, the highest bit in the effective part is taken as the 1st bit, and the L+1th bit in the effective part is the L+1th bit starting from the 1st bit along the preset direction.
9. The data processing method according to claim 8, wherein: Determining the mantissa intermediate result according to the L+1th bit in the effective part includes: In response to the L+1th bit in the effective part being the first value, discarding the L+1th bit to the Nth bit in the effective part, and using the 1st bit to the Lth bit in the effective part as the mantissa intermediate result; In response to the L+1th bit in the effective part being the second value, and at least one bit among the L+2th bit to the Nth bit of the effective part being not the first value, discarding the L+1th bit to the Nth bit of the effective part, and performing a carry operation on the Lth bit of the effective part to obtain the mantissa intermediate result; In response to the L+1th bit in the effective part being the second value, and the L+2th bit to the Nth bit of the effective part being the first value, the mantissa intermediate result is determined according to the Lth bit of the effective part.
10. The data processing method according to claim 6, wherein: Determining a significant portion from the mantissa multiplication result comprises: Starting from the starting point, continuously selecting at most L bits from the mantissa multiplication result along the preset direction as the valid part; Determining a mantissa intermediate result according to the valid part includes: The effective part is taken as the mantissa intermediate result.
11. The data processing method according to claim 6, wherein: The destination operand is the product of the first source operand and the second source operand, The shift processing includes shifting the mantissa intermediate result according to the value of the exponent portion of the first source operand.
12. The data processing method according to claim 6, wherein: The destination operand is a rounding result after further rounding operation is performed on the product result of the first source operand and the second source operand, In response to the rounding operation indicating to perform a floor operation on the product result, the shifting process includes shifting the mantissa intermediate result according to a value of an exponent part of the first source operand.
13. The data processing method according to claim 6, wherein: The destination operand is a rounding result after further rounding operation is performed on the product result of the first source operand and the second source operand, In response to the rounding operation instruction, performing a rounding operation on the product result, the shifting process includes: Shifting the mantissa intermediate result according to the value of the exponent part of the first source operand to obtain a shift result and an overflow mantissa part generated by the shift; In response to the overflow mantissa parts being all the first value, obtaining the mantissa part and the exponent part of the destination operand according to the shift result; In response to the overflow mantissa part not being entirely the first value, a carry operation is performed on the shift result and a mantissa part and an exponent part of the destination operand are obtained according to the carry result.
14. The data processing method according to claim 5, wherein: Determining the sign bit of the destination operand according to the sign bit of the first source operand and the sign bit of the second operand includes: In response to the sign bit of the first source operand being the same as the sign bit of the second source operand, determining that the sign bit of the destination operand is a positive sign bit, wherein the positive sign bit indicates that the destination operand is a positive number; In response to the sign bit of the first source operand being different from the sign bit of the second source operand, the sign bit of the destination operand is determined to be a negative sign bit, wherein the negative sign bit indicates that the destination operand is a negative number.
15. The data processing method according to any one of claims 1 to 14, wherein: Each first intermediate operand represents some bits in the mantissa of the first source operand, and different first intermediate operands represent different bits in the first source operand. Each second intermediate operand represents at least some of the bits in the second source operand, the bit width of the second integer type is greater than the sum of the maximum bit width of the first intermediate operand and the maximum bit width of the second intermediate operand, The maximum bit width of the first intermediate operand is the number of bits of the first source operand represented by the first intermediate operand representing the most bits among the multiple first intermediate operands. The maximum bit width of the second intermediate operand is the number of bits of the second source operand represented by the second intermediate operand representing the most bits among the at least one second intermediate operand.
16. A data processing method, comprising: receiving a data processing instruction instructing to perform at least a floating point number and an integer multiplication, wherein the data processing instruction includes a first source operand and a second source operand as input parameters, and a destination operand as an output parameter, the first source operand being of a floating point number type, and the second source operand being of a first integer type, After parsing the data processing instruction, executing the data processing instruction using a computing unit, Wherein, using the computing unit to execute the data processing instruction includes: representing a mantissa portion of the first source operand using a plurality of first intermediate operands of a second integer type; representing the second source operand using at least one second intermediate operand of the second integer type; Performing integer multiplication of the second integer type on the plurality of first intermediate operands and the at least one second intermediate operand in pairs to obtain a plurality of integer multiplication results, wherein each integer multiplication result is of the second integer type and each integer multiplication result is a product of a first intermediate operand and a second intermediate operand; Obtaining a mantissa multiplication result according to the multiple integer multiplication results; The destination operand is obtained according to the mantissa multiplication result.
17. A processor, comprising an instruction parsing unit and an operation unit, wherein: The instruction parsing unit is used to receive and parse a data processing instruction, wherein the data processing instruction includes a first source operand and a second source operand as input parameters, and a destination operand as an output parameter, the first source operand is a floating point type, the second source operand is a first integer type, The computing unit executes the data processing instruction after the instruction parsing unit parses the data processing instruction. The computing unit executes the data processing instruction, including performing the following operations: representing a mantissa portion of the first source operand using a plurality of first intermediate operands of a second integer type; representing the second source operand using at least one second intermediate operand of the second integer type; Performing integer multiplication of the second integer type on the plurality of first intermediate operands and the at least one second intermediate operand in pairs to obtain a plurality of integer multiplication results, wherein each integer multiplication result is of the second integer type and each integer multiplication result is a product of a first intermediate operand and a second intermediate operand; Obtaining a mantissa multiplication result according to the multiple integer multiplication results; The destination operand is obtained according to the mantissa multiplication result.
18. A data processing device, comprising: An acquisition module is configured to receive a first source operand and a second source operand as input parameters, wherein the type of the first source operand is a floating point type, and the type of the second source operand is a first integer type; a first conversion module configured to represent a mantissa portion of the first source operand using a plurality of first intermediate operands of a second integer type; a second conversion module configured to represent the second source operand using at least one second intermediate operand of the second integer type; a multiplication calculation module, configured to perform integer multiplication of the second integer type on the plurality of first intermediate operands and the at least one second intermediate operand in pairs to obtain a plurality of integer multiplication results, and obtain a mantissa multiplication result according to the plurality of integer multiplication results, wherein each integer multiplication result is of the second integer type and each integer multiplication result is a product of a first intermediate operand and a second intermediate operand; The output module is configured to obtain a destination operand as an output parameter according to the mantissa multiplication result.
19. An electronic device comprising: A memory non-transitorily stores computer executable instructions; a processor configured to execute the computer executable instructions, Wherein, when the computer executable instructions are executed by the processor, the data processing method according to any one of claims 1-16 is implemented.
20. A non-transitory computer-readable storage medium, wherein: The non-transitory computer-readable storage medium stores computer-executable instructions, When the computer executable instructions are executed by a processor, the data processing method according to any one of claims 1 to 16 is implemented.
