A floating-point number processing method and apparatus

By processing the exponent and mantissa of floating-point numbers as integers respectively and using integer ALU calculations, the problem of high complexity of existing hardware accelerators in processing high-precision floating-point numbers is solved, and efficient floating-point number calculations are achieved.

CN116700666BActive Publication Date: 2024-08-23XIANGDIXIAN COMPUTING TECH (CHONGQING) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210174714.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-24
Publication Date
2024-08-23
Estimated Expiration
2042-02-24

AI Technical Summary

Technical Problem

When existing hardware accelerators perform floating-point addition or multiplication calculations, they need to design multi-precision ALUs, which increases the hardware design complexity and development cycle, and cannot directly process high-precision floating-point numbers.

Method used

The central processor identifies the floating point number to be executed, generates processing instructions, processes the exponent and mantissa of the floating point number as integers, uses the integer ALU to perform calculations, and finally combines them to obtain the calculation result of the floating point number.

Benefits of technology

It reduces the hardware design complexity and research and development cycle, realizes addition and multiplication calculations of high-precision floating point numbers, and improves calculation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116700666B
    Figure CN116700666B
Patent Text Reader

Abstract

The present disclosure provides a floating-point number processing method, comprising: a central processing unit identifies two floating-point numbers to be subjected to a predetermined calculation, generates a processing instruction based on the identification result, and sends the generated processing instruction to a hardware accelerator; the hardware accelerator uses the exponents of the two floating-point numbers as integers to perform processing corresponding to the predetermined calculation according to the processing instruction to obtain an exponent processing result; uses the mantissas of the two floating-point numbers as integers to perform processing corresponding to the predetermined calculation to obtain a mantissa processing result; and obtains a result of the two floating-point numbers executing the predetermined calculation according to the mantissa processing result and the exponent processing result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a floating point number processing method and device. Background Art

[0002] In order to meet the needs of various applications, hardware accelerators need to be able to perform addition or multiplication of floating-point numbers. However, the hardware accelerators currently on the market usually only have ALUs (arithmetic logic units) that can calculate partial precision floating-point numbers, or ALUs that can calculate integers. If you want the hardware accelerator to perform addition or multiplication of floating-point numbers with full precision, you need to design and develop ALUs for calculating floating-point numbers with various precisions. This method increases the complexity of hardware design and also requires a longer R&D cycle. Summary of the invention

[0003] In view of the above technical problems, the present disclosure provides a floating point number processing method and device, and the technical solution is as follows.

[0004] According to a first aspect of the present disclosure, a floating point number processing method is provided, comprising:

[0005] The central processing unit identifies two floating point numbers to be used for a predetermined calculation, generates a processing instruction based on the identification result, and sends the generated processing instruction to the hardware accelerator;

[0006] The hardware accelerator performs the following according to the processing instructions:

[0007] Taking the exponents of the two floating point numbers as integers and performing processing corresponding to the predetermined calculation, obtaining an exponential processing result;

[0008] The mantissas of the two floating point numbers are treated as integers and processed corresponding to the predetermined calculation to obtain a mantissa processing result;

[0009] The result of executing the predetermined calculation on the two floating-point numbers is obtained according to the mantissa processing result and the exponent processing result.

[0010] In one embodiment, the central processing unit identifies two floating-point numbers to be used for a predetermined calculation, and generates processing instructions based on the identification result. Specifically, the two floating-point numbers to be used for a predetermined calculation are identified, and for each floating-point number, a preprocessing method for its mantissa and exponent and a method for processing the preprocessing result are determined, and processing instructions are generated for the two determined processing methods.

[0011] In one embodiment, the predetermined calculation is a multiplication calculation; and the exponents of the two floating-point numbers are respectively treated as integers to perform processing corresponding to the predetermined calculation to obtain an exponential processing result, including:

[0012] Performing preprocessing of splitting or converting the exponent of each floating point number to obtain a preprocessing result that meets the calculation requirements of the integer ALU to be called; calling the integer arithmetic logic unit ALU to add the preprocessing results of the exponents of the two floating point numbers to obtain an exponent processing result;

[0013] The processing of the mantissas of the two floating point numbers as integers corresponding to the predetermined calculation to obtain mantissa processing results includes:

[0014] The mantissa of each floating point number is preprocessed by splitting or converting to obtain a preprocessing result that meets the calculation requirements of the integer ALU to be called; the integer arithmetic logic unit ALU is called to multiply the preprocessing results of the mantissas of the two floating point numbers to obtain a mantissa processing result.

[0015] In one embodiment, the predetermined calculation is an addition calculation;

[0016] The exponents of the two floating point numbers are respectively treated as integers to perform processing corresponding to the predetermined calculation to obtain exponential processing results, including:

[0017] For the two floating-point numbers, calling an integer arithmetic logic unit ALU to compare the exponents of the two floating-point numbers, determining the floating-point number with a smaller exponent as the first floating-point number, and determining the floating-point number with a larger exponent as the second floating-point number;

[0018] Preprocessing the exponent of the first floating point number to adjust it to the exponent of the second floating point number, and determining the adjusted exponent as the exponent processing result;

[0019] The processing of the mantissas of the two floating point numbers as integers corresponding to the predetermined calculation to obtain mantissa processing results includes:

[0020] shifting the mantissa of the first floating point number according to the adjustment of the exponent of the first floating point number;

[0021] The mantissa of the first floating-point number after the shift and the mantissa of the second floating-point number are respectively preprocessed by splitting or converting to obtain preprocessing results that meet the calculation requirements of the integer ALU to be called; the integer arithmetic logic unit ALU is called to add the preprocessing results of the two mantissas to obtain the mantissa processing result.

[0022] In one embodiment, obtaining the result of executing the predetermined calculation on the two floating-point numbers according to the mantissa processing result and the exponent processing result includes:

[0023] The mantissa processing result is used as the mantissa of a result of executing the predetermined calculation on the two floating-point numbers, and the exponent processing result is used as the exponent of a result of executing the predetermined calculation on the two floating-point numbers.

[0024] According to a second aspect of an embodiment of the present disclosure, there is provided a floating point number processing device, including a central processing unit and a hardware accelerator;

[0025] The central processing unit is used to identify two floating point numbers to be used for performing a predetermined calculation, generate a processing instruction based on the identification result, and send the generated processing instruction and the two floating point numbers to the hardware accelerator;

[0026] A hardware accelerator, for executing according to the processing instruction:

[0027] Taking the exponents of the two floating point numbers as integers and performing processing corresponding to the predetermined calculation, obtaining an exponential processing result;

[0028] The mantissas of the two floating point numbers are treated as integers and processed corresponding to the predetermined calculation to obtain a mantissa processing result;

[0029] The result of executing the predetermined calculation on the two floating-point numbers is obtained according to the mantissa processing result and the exponent processing result.

[0030] In one embodiment, the central processing unit is configured to identify two floating point numbers to be used for performing predetermined calculations, determine a preprocessing method for the mantissa and exponent of each floating point number, and a method for processing the preprocessing result, and generate processing instructions for the two determined processing methods.

[0031] In one embodiment, the predetermined calculation is a multiplication calculation;

[0032] The hardware accelerator is specifically used to pre-process the exponent of each floating point number by splitting or converting it, so as to obtain a pre-processing result that meets the calculation requirements of the integer ALU to be called; and to call the integer arithmetic logic unit ALU to add the pre-processing results of the exponents of the two floating point numbers, so as to obtain an exponent processing result.

[0033] In one embodiment, the hardware accelerator is specifically used to pre-process the mantissa of each floating-point number by splitting or converting it to obtain a pre-processing result that meets the calculation requirements of the integer ALU to be called; and call the integer arithmetic logic unit ALU to multiply the pre-processing results of the mantissas of the two floating-point numbers to obtain a mantissa processing result.

[0034] In one embodiment, the predetermined calculation is an addition calculation;

[0035] The hardware accelerator is specifically used to call an integer arithmetic logic unit ALU to compare the exponents of the two floating-point numbers, determine the floating-point number with a smaller exponent as a first floating-point number, and determine the floating-point number with a larger exponent as a second floating-point number; pre-process the exponent of the first floating-point number, adjust it to the exponent of the second floating-point number, and determine the adjusted exponent as the exponent processing result.

[0036] In one embodiment, the hardware accelerator is specifically used to shift the mantissa of the first floating-point number according to the adjustment of the exponent of the first floating-point number; pre-process the mantissa of the shifted first floating-point number and the mantissa of the second floating-point number by splitting or converting them respectively to obtain pre-processing results that meet the calculation requirements of the integer ALU to be called; and call the integer arithmetic logic unit ALU to add the pre-processing results of the two mantissas to obtain a mantissa processing result.

[0037] In one embodiment, the hardware accelerator is specifically configured to use the mantissa processing result as the mantissa of a result of executing the predetermined calculation on the two floating-point numbers, and use the exponent processing result as the exponent of a result of executing the predetermined calculation on the two floating-point numbers.

[0038] According to a third aspect of an embodiment of the present disclosure, there is provided an electronic device, comprising the above-mentioned floating-point number processing device.

[0039] According to a fourth aspect of an embodiment of the present disclosure, a hardware accelerator is provided, including:

[0040] A memory, used to store processing instructions sent by the central processing unit;

[0041] A controller that reads processing instructions from memory to execute:

[0042] The exponents of the two floating-point numbers are processed as integers corresponding to the predetermined calculation to obtain an exponent processing result; the mantissas of the two floating-point numbers are processed as integers corresponding to the predetermined calculation to obtain a mantissa processing result; and the result of executing the predetermined calculation on the two floating-point numbers is obtained based on the mantissa processing result and the exponent processing result.

[0043] According to a fifth aspect of an embodiment of the present disclosure, a central processing unit is provided, including:

[0044] A memory for storing a processing program;

[0045] The controller is used to read the processing program to execute: identifying two floating-point numbers to be used for a predetermined calculation, generating a processing instruction based on the identification result, and sending the generated processing instruction to the hardware accelerator so that the hardware accelerator uses the exponents of the two floating-point numbers as integers to perform processing corresponding to the predetermined calculation to obtain an exponent processing result; uses the mantissas of the two floating-point numbers as integers to perform processing corresponding to the predetermined calculation to obtain a mantissa processing result; and obtains a result of the two floating-point numbers executing the predetermined calculation based on the mantissa processing result and the exponent processing result.

[0046] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. The drawings described herein are used to provide a further understanding of the present disclosure and constitute a part of the present disclosure. The schematic embodiments of the present disclosure and their descriptions are used to explain the present disclosure and do not constitute an improper limitation on the present disclosure. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.

[0048] Figure 1 A schematic diagram of a single-precision floating-point number composition according to an embodiment of the present disclosure;

[0049] Figure 2 A schematic diagram of the structure of a device for determining a square root of a floating point number according to an embodiment of the present disclosure;

[0050] Figure 3 A schematic diagram of preprocessing a floating point number mantissa according to an embodiment of the present disclosure;

[0051] Figure 4 It is another schematic diagram of preprocessing the mantissa of a floating point number according to an embodiment of the present disclosure;

[0052] Figure 5 A schematic flow chart of a floating point number processing method according to an embodiment of the present disclosure;

[0053] Figure 6 A logic diagram of a floating point number processing method according to an embodiment of the present disclosure;

[0054] Figure 7 The figure is a schematic diagram of the structure of a hardware accelerator according to an embodiment of the present disclosure. DETAILED DESCRIPTION

[0055] In order to make the technical solutions and advantages in the embodiments of the present disclosure more clear, the technical solutions and advantages in the embodiments of the present disclosure will be further described in detail with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. It should be noted that the embodiments in the present disclosure and the features in the embodiments can be combined with each other in the absence of conflict. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in the field should fall within the scope of protection.

[0056] The terms used in this disclosure are only for describing specific embodiments, not for limiting the scope of protection of the application. In this disclosure, unless the context clearly indicates other meanings, the singular forms of "a", "the" and "the" used also include plural forms. It should also be understood that the term "and / or" used in this article includes any or all possible combinations of multiple associated items listed.

[0057] It should be understood that, although the terms "first", "second", etc. may be used in the present disclosure to describe various information, these information should not be limited by these terms. These terms are only used to distinguish one type of information from another type of information. For example, without departing from the scope of the present disclosure, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the words "if, for example" as used herein may be interpreted as "at the time of" or "when" or "in response to determination". It should also be understood that the terms "include" and / or "include" used herein specify the existence of the stated features, integers, steps, operations, units and / or components, without excluding the existence or addition of one or more other features, integers, steps, operations, units, components and / or combinations thereof. It should also be mentioned that in some alternative implementations, the functions / actions mentioned may occur in an order different from that indicated in the accompanying drawings. For example, depending on the functions / actions involved, the two figures shown in succession may actually be executed substantially simultaneously or may sometimes be executed in the opposite order.

[0058] Technologies such as graphics processing and machine learning are constantly being updated and updated. As a result, these technologies have placed increasingly higher computing requirements on computer devices, and the computing pressure on the central processing unit (CPU) in computer devices has also increased. Therefore, the industry currently uses hardware accelerators to share the computing pressure of the central processing unit. A hardware accelerator can be understood as a hardware product specifically used for computing. It receives instructions from the central processing unit, performs corresponding calculations based on the instructions, and returns the calculation results to the central processing unit. Common hardware accelerators include GPU (Graphics Processing Unit), TBU (Tensor Processing Unit), etc., which are not limited in this disclosure.

[0059] In hardware accelerators, multiple arithmetic and logic units (ALUs) are usually pre-configured in hardware form, that is, combinational logic circuits that implement multiple sets of arithmetic and logic operations, referred to as ALUs, for calculations on different data. Among them, one ALU can only be used to process calculations on a certain type of data. For example, an ALU used to calculate single-precision floating-point numbers cannot calculate double-precision floating-point numbers, and an ALU used to calculate integers cannot calculate floating-point numbers.

[0060] As described above, in order to meet various application requirements, such as the pursuit of more extreme rendering images, the hardware accelerator is currently required to have the ability to perform multiplication or addition calculations on floating-point numbers (such as 64-bit floating-point numbers), that is, it is necessary to calculate the product of two floating-point numbers or calculate the sum of two floating-point numbers. However, the hardware accelerators currently on the market usually only have ALUs that can calculate some floating-point numbers, especially ALUs that can only calculate low-precision floating-point numbers (such as floating-point numbers with precision lower than 64 bits) and ALUs that can calculate integers. If you want to achieve multiplication or addition calculations on high-precision floating-point numbers, you need to develop hardware, that is, you need to design and develop ALUs for addition and multiplication calculations on high-precision floating-point numbers. This method increases the complexity of hardware design and also increases the product development cycle.

[0061] In order to solve the above problems, the present disclosure proposes that a central processing unit identifies two floating-point numbers to be calculated, and generates a processing instruction based on the identification result and sends it to a hardware accelerator. The hardware accelerator can calculate and process the mantissa and exponent of the floating-point number as integers according to the processing instruction, respectively, to obtain a mantissa processing result and an exponent processing result, and obtain the result of executing the predetermined calculation on the two floating-point numbers based on the mantissa processing result and the exponent processing result.

[0062] In order to facilitate the description of the technical solution in the present disclosure, the floating point number is first explained below:

[0063] Floating point numbers are a digital representation method that can be used to express various real numbers. In the development of computer systems, many methods have been proposed to express real numbers, such as fixed-point numbers relative to floating point numbers. In this expression method, the decimal point is fixed at a certain position in the middle of all the digits of the real number. For example, currency can be expressed in this way, such as 99.00 or 00.99 can be used to express currency with two decimal places. However, since the position of the decimal point is fixed in fixed-point numbers, it is not conducive to expressing extremely large or extremely small numbers. Therefore, most computer systems currently use floating point numbers to express real numbers.

[0064] In floating point numbers, a mantissa, a base, an exponent, and a sign are used to represent real numbers. For example, 121.1 can be expressed as 1.211*10 2 , where 1.211 is the mantissa, 10 is the base, and 2 is the exponent. Floating-point numbers use the exponent to express the effect of a floating decimal point, thereby being able to express a wider range of real numbers.

[0065] Since the numerical expressions in computers are based on binary, the base of floating point numbers in computers is 2 by default. In addition, the number of digits in the mantissa is called the precision of the floating point number. For example, the floating point number 1.001101×2 4 The precision is 7.

[0066] IEEE (Institute of Electrical and Electronics Engineers) specifies a variety of floating-point formats, including single-precision floating-point numbers, double-precision floating-point numbers, and extended double-precision floating-point numbers. Among them, single-precision floating-point numbers are 32 bits, that is, a single-precision floating-point number needs to occupy 32 consecutive bits, of which the sign occupies 1 bit, the exponent occupies 8 bits, the mantissa occupies 23 bits, and there is an implicit bit. Double-precision floating-point numbers are 64 bits, of which the sign occupies 1 bit, the exponent occupies 11 bits, the mantissa occupies 52 bits, and there is an implicit bit. Extended double-precision floating-point numbers are 80 bits, of which the sign occupies 1 bit, the exponent occupies 15 bits, and the mantissa occupies 64 bits. The IEEE754 standard stipulates that a real number V can be expressed as: V = (-1) s ×M×2 E , where S is the sign, which can be 0 to indicate that the floating point number is positive, or 1 to indicate that the floating point number is negative, M is the mantissa, and E is the exponent.

[0067] like Figure 1As shown, it is a schematic diagram of a single-precision floating-point number (32-bit floating-point number) stored in a computer, wherein the single-precision floating-point number occupies a total of 32 bits (4 bytes) in the computer, wherein the continuous 32 bits are divided into three domains, including: a sign domain, an exponent domain, and a mantissa domain, wherein the stored values ​​are respectively used to represent the sign, exponent, and mantissa of a given single-precision floating-point number, so a given numerical value can be expressed by the mantissa and the adjustable exponent.

[0068] like Figure 1 As shown in the figure, the sign field is 1 bit wide, 0 represents positive, and 1 represents negative. The exponent is also called the exponent code, and the exponent field is 8 bits wide. The storage value is 0-255. In order to deal with negative numbers, the actual exponent needs to be added with a bias value as the value stored in the exponent field. The bias value is 2 (指数位数-1) -1, the bias value for single precision is 2 (8-1) -1=127, so the value in the exponent field is the actual value of the exponent plus 127. Therefore, the actual value that can be represented by this 8-bit exponent is -127 to 128. For example, the actual exponent value of single precision 0 will be stored as 127 in the exponent field; while 64 stored in the exponent field represents the actual exponent value -63.

[0069] The mantissa field width is 23 bits, including 23 decimal places to the right of the decimal point, that is, the decimal part of the mantissa. The mantissa also includes a hidden integer bit, that is, the integer part of the mantissa. Therefore, although only 23 decimal places of the mantissa are stored, the total precision of the mantissa is 24 bits.

[0070] Similarly, a double-precision floating point number (64-bit floating point number) takes up 64 bits (8 bytes) when stored in a computer, of which the continuous 64 bits are divided into three fields, including: 1 bit for the sign, 11 bits for the exponent, and 52 bits for the mantissa. Based on the above, we can see that floating point numbers of different precisions are stored in different forms in the computer.

[0071] In order to make the technical solutions and advantages of the embodiments of the present disclosure more clearly understood, the exemplary embodiments of the present disclosure are further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than an exhaustive list of all the embodiments. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.

[0072] like Figure 2 , which is a schematic diagram of the structure of a floating point number processing device proposed in the present disclosure, including a central processing unit CPU 210 and a hardware accelerator 220 .

[0073] After the central processing unit obtains two floating-point numbers to be used for a predetermined calculation, it can identify the two floating-point numbers, wherein the two floating-point numbers are floating-point numbers of the same precision, and specifically are floating-point numbers that the hardware accelerator does not have the ability to directly process. For example, current hardware accelerators usually have an FP16 (16-bit floating-point number) ALU and an integer ALU, that is, the hardware accelerator can perform calculations on FP16 and integers, and the two floating-point numbers to be used for the predetermined calculation are both FP64, that is, 64-bit floating-point numbers, and the hardware accelerator cannot directly identify and calculate 64-bit floating-point numbers.

[0074] Therefore, in this step, after obtaining the two floating-point numbers to be calculated, the CPU identifies the two floating-point numbers, generates a processing instruction based on the identification result and the type of the predetermined calculation, and sends the generated processing instruction to the hardware accelerator. Generally, the CPU can identify floating-point numbers of various precisions compared to the hardware accelerator, so it can identify the precision type of the two floating-point numbers and the size of the floating-point numbers.

[0075] In this step, after the central processing unit identifies two floating-point numbers, it can determine the preprocessing method for the mantissa and exponent of each floating-point number and the method for further processing the preprocessing results based on the preset software processing logic, and compile the two determined processing methods into hardware processing instructions that can be executed by the hardware accelerator.

[0076] Specifically, the central processing unit may identify the mantissa field, the exponent field and the sign field of the two floating point numbers, and determine the preprocessing method for the mantissa and the exponent of each floating point number according to the type of calculation.

[0077] The following describes the preprocessing method of floating-point numbers determined by the central processing unit, with the predetermined calculation type being multiplication. The two floating-point numbers are both FP64, i.e., 64-bit floating-point numbers, as an example, with a mantissa of 52 bits and an exponent of 11 bits. Unless otherwise specified, the following description uses 64-bit floating-point numbers as an example.

[0078] When the type of the predetermined calculation is a multiplication calculation:

[0079] The preprocessing method determined by the central processing unit for the mantissa of each floating point number can be: splitting or converting the mantissa of each floating point number to obtain a preprocessing result that meets the calculation requirements of the integer ALU to be called, wherein the preprocessing result is an integer.

[0080] Specifically, the CPU may determine the specific method of splitting or converting the mantissa according to the type of integer ALU to be called by the hardware accelerator, so that the integer ALU can be called subsequently to perform calculation processing on the preprocessing result, that is, the obtained integer.

[0081] It is understandable that the central processing unit may know the types of all integer ALUs possessed by the hardware accelerator, and may use any integer ALU possessed by the hardware accelerator as an ALU to be called subsequently.

[0082] For example, if the subsequent hardware accelerator uses the INT32 ALU, that is, the 32-bit integer ALU to calculate the preprocessing results, since the mantissa of the floating-point number is 52 bits (64-bit floating-point number), the INT32 ALU cannot be directly called to calculate the mantissa. Therefore, the central processing unit determines that the mantissa of the floating-point number needs to be split, that is, the 52-bit mantissa is split into two 32-bit integers.

[0083] For example, the mantissa of a floating point number is:

[0084] 1111_0101_1010_1101_1110_1110_1110_1111_1110_0000_1111_1110_1110.

[0085] It can be split into (1110_1110_1111_1110_0000_1111_1110_1110) and (0000_0000_0000_1111_0101_1010_1101_1110), that is, the last 32 bits of the mantissa are an integer split out, and the first 20 bits of the mantissa (52-32) are another integer split out, and 12 0s are added in front of it to form a 32-bit integer, and the split preprocessing results are stored. Figure 3 As shown, it is a schematic diagram of the above splitting process, that is, the mantissa of the floating point number is split into two 32-bit integers respectively.

[0086] If the INT64 ALU, that is, the 64-bit integer ALU is used to calculate the preprocessing results subsequently, since the mantissa of the floating-point number is 52 bits, the INT64 ALU can directly calculate the 64-bit integer. Therefore, the central processing unit determines that the mantissa does not need to be split, but directly converts the mantissa into an integer that meets the calculation requirements of the integer ALU.

[0087] Continuing with the above example, the floating point number mantissa is:

[0088] 1111_0101_1010_1101_1110_1110_1110_1111_1110_0000_1111_1110_1110.

[0089] This can be transformed into:

[0090] 0000_0000_0000_1111_0101_1010_1101_1110_1110_1110_1111_1110_0000_1111_1110_1110, that is, convert it into a 64-bit integer.

[0091] like Figure 4 As shown in FIG. 1 , it is a schematic diagram of the above conversion process, that is, the mantissa of the floating point number is taken as the last 52 bits of the 64-bit integer, and 12 bits of 0 are added in front of it.

[0092] In addition, it should be noted that, since floating-point numbers also have signs, the signs can also be carried in the preprocessing results of the corresponding mantissas.

[0093] The above is a preprocessing method determined by the CPU for the mantissa of each floating point number when the predetermined calculation is multiplication. The following describes a preprocessing method determined by the CPU for the exponent of each floating point number:

[0094] The exponent of each floating point number is split or transformed to obtain a preprocessing result that meets the calculation requirements of the integer ALU to be called, wherein the preprocessing result is an integer.

[0095] Specifically, the central processing unit may determine a specific way to split or transform the exponent according to the type of integer ALU to be called by the hardware accelerator, so that the integer ALU can be called subsequently to perform calculation processing on the preprocessing result.

[0096] The processing method for the exponent of each floating point number is similar to the processing method for the mantissa. For example, the exponent of FP64 is 11 bits. If the INT8 integer ALU is subsequently called to calculate the exponent, the exponent bits of FP64 need to be split into two 8-bit integers. For example, the exponent is 1111_0101_101, which can be split into two integers, 1010_1101 and 0000_0111. If the integer ALU with more than 11 bits is subsequently called for calculation, the exponent bits of FP64 do not need to be split, but need to be converted into an integer that meets the calculation requirements of the integer ALU. The specific splitting and conversion process can refer to the above processing of the mantissa, which will not be repeated here.

[0097] The above content is the preprocessing method determined by the central processing unit for the mantissa and exponent of each floating-point number when the predetermined calculation is multiplication. In addition, in addition to determining the preprocessing method, the central processing unit also needs to determine the method in which the hardware accelerator further processes the preprocessing result. After determining the two types of processing methods, the central processing unit generates hardware processing instructions that can be executed by the hardware accelerator based on the two types of processing methods, and sends the hardware processing instructions and the two floating-point numbers to be performed for the predetermined calculation to the memory of the hardware accelerator, such as RAM, and the hardware accelerator executes the processing instruction.

[0098] Based on this processing instruction, the hardware accelerator can perform:

[0099] Splitting or converting the exponent of each floating point number to obtain a preprocessing result that meets the calculation requirements of the integer ALU to be called; calling the integer arithmetic logic unit ALU to add the preprocessing results of the exponents of the two floating point numbers to obtain an exponent processing result;

[0100] The mantissa of each floating point number is split or converted to obtain a preprocessing result that meets the calculation requirements of the integer ALU to be called; the integer arithmetic logic unit ALU is called to multiply the preprocessing results of the mantissas of the two floating point numbers to obtain a mantissa processing result;

[0101] The result of executing the predetermined calculation on the two floating-point numbers is obtained according to the mantissa processing result and the exponent processing result.

[0102] The way in which the hardware accelerator preprocesses the mantissa and exponent of each floating point number can be referred to above and will not be described in detail here. In the above, the preprocessing method determined by the central processing unit is the preprocessing method to be performed by the hardware accelerator.

[0103] The hardware accelerator calls the integer arithmetic logic unit ALU to calculate the preprocessing results, as follows:

[0104] Since for floating point numbers, multiplication means adding the exponents and multiplying the mantissas.

[0105] Therefore, the preprocessed results of the mantissas of the two floating-point numbers can be multiplied.

[0106] Take two floating point numbers as a*2 c and b*2 d For example, the mantissas of the two floating point numbers are a and b respectively. In the preprocessing process, if the mantissas of the two floating point numbers are converted, the conversion is the same as the above Figure 4As described above, if the preprocessing results after the conversion are a' and b', where a' and b' are both integers, the integer multiplication arithmetic logic unit ALU can be called to multiply a' and b'.

[0107] In addition, in the preprocessing process, if the mantissas of two floating point numbers are split, such as splitting a into a1 and a2, and splitting b into b1 and b2, then a=(a1*2 X +a2), b=(b1*2 X +b2), where a2 is the value of the last x digits of a, and a1 is the value of a excluding the last x digits.

[0108] Continuing with the above example, if a is:

[0109] 1111_0101_1010_1101_1110_1110_1110_1111_1110_0000_1111_1110_1110, split it into two 32-bit integers, that is, x=32, that is, split it into:

[0110] 1110_1110_1111_1110_0000_1111_1110_1110,

[0111] and 0000_0000_0000_1111_0101_1010_1101_1110.

[0112] Among them, 1110_1110_1111_1110_0000_1111_1110_1110 are the last 32 bits of a, that is, a2, and 0000_0000_0000_1111_0101_1010_1101_1110 are the first 20 bits of a excluding the last 32 bits.

[0113] That is, a=(a1*2 32 +a2), similarly, b=(b1*2 32 +b2), you can call the integer arithmetic logic unit ALU pair (a1*2 32 +a2) and (b1*2 32 +b2) to perform multiplication.

[0114] That is, calculate a1*2 32 *b1*2 32 +a1*2 32 *b2+a2*b1*2 32 +a2*b2.

[0115] Among them, a1, a2, b1 and b2 are all integers, so the multiplication calculations and addition calculations involved above can be calculated and processed using the integer multiplication ALU and the integer addition ALU, and finally the mantissa processing result, such as W, is obtained.

[0116] It can be understood that, since the preprocessing result also carries a sign, the mantissa processing result also carries a sign.

[0117] The above is the process of calculating the preprocessing results of the mantissas of two floating-point numbers. The following describes the process of calculating the preprocessing results of the exponents of two floating-point numbers:

[0118] Since for floating point numbers, multiplication means adding the exponents and multiplying the mantissas.

[0119] Therefore, the preprocessed results of the exponents of two floating point numbers can be added. For example, if the exponents of the two floating point numbers are c and d, the exponents of the two floating point numbers are converted into c' and d' after preprocessing, wherein c' and d' are both integers, and therefore, the integer arithmetic logic unit ALU can be used to add c' and d'.

[0120] In addition, if the index is split, such as splitting c into c1 and c2, and splitting d into d1 and d2, then c = (c1*2 Y +c2), d=(d1*2 Y +d2), where c2 is the value of the last Y bits of c, and c2 is the value of c without the last Y bits. Using the above example, if c is: 1111_0101_101, it is split into two 8-bit integers, that is, Y=8, that is, split into:

[0121] 1010_1101, and 0000_0111.

[0122] Among them, 0000_0111 is the last 8 bits of c, that is, c2, and 0000_0111 is the first 3 bits of c excluding the last 8 bits.

[0123] That is, c=(c1*2 8 +c2), similarly, d=(d1*2 8 +d2), we can use the integer arithmetic logic unit ALU to (c1*2 8 +c2) and (d1*2 8 +d2) for addition.

[0124] That is, calculate c1*2 8 +c2+d1*2 8 +d2.

[0125] Among them, c1, c2, d1 and d2 are all integers, so the multiplication calculations and addition calculations involved above can be calculated and processed using the integer multiplication ALU and the integer addition ALU, and finally an exponential processing result, such as Z, is obtained.

[0126] After obtaining the mantissa processing result and the exponent processing result, the result of executing the predetermined calculation on the two floating point numbers can be obtained according to the mantissa processing result and the exponent processing result. The mantissa processing result and the exponent processing result can be converted into a floating point number format, such as Figure 1 The storage format of the floating-point numbers shown in the figure is combined to obtain the result of multiplication calculation for two floating-point numbers, that is, the mantissa processing result is used as the mantissa of the predetermined calculation result of the two floating-point numbers, and the exponent processing result is used as the exponent of the predetermined calculation result of the two floating-point numbers. Using the above example, the two floating-point numbers are a*2 c and b*2 d The final result is W*2 Z , which is a*2 c With b*2 d The result of multiplication.

[0127] The above describes the method executed by the CPU and the hardware accelerator when the predetermined calculation is multiplication. The following describes the method executed by the CPU and the hardware accelerator when the predetermined calculation is addition:

[0128] When the type of the scheduled calculation is an addition calculation:

[0129] The CPU may preprocess the exponent of each floating point number by:

[0130] For the two floating-point numbers, an integer arithmetic logic unit ALU is called to compare the exponents of the two floating-point numbers, the floating-point number with the smaller exponent is determined as the first floating-point number, and the floating-point number with the larger exponent is determined as the second floating-point number; the exponent of the first floating-point number is adjusted to the exponent of the second floating-point number.

[0131] Using the above example, the two floating point numbers are a*2 c and b*2 d , the integer ALU can be called to compare c and d to determine the size relationship between c and d. It can be understood that although English letters are used to represent the exponents of the two floating point numbers, they are actually binary numbers. English letters are used here just to make it clear. In this step, the exponents of the two floating point numbers are respectively regarded as integers, and the integer ALU can be called to compare the sizes of the two exponents. For example, after comparing c and d, it is found that c is smaller than d, then a*2 is determined. c is the first floating point number, b*2 d is the second floating point number, and a*2c Convert to a*2 d .

[0132] The preprocessing method of the central processor for determining the mantissa of each floating point number can be:

[0133] shifting the mantissa of the first floating point number according to the adjustment of the exponent of the first floating point number;

[0134] The shifted mantissa and the mantissa of the second floating-point number are preprocessed by splitting or converting, respectively, to obtain a preprocessing result that meets the calculation requirements of the integer ALU to be called, and the preprocessing result is an integer.

[0135] Specifically, since the exponent of the first floating-point number is converted, in order to ensure that the value of the first floating-point number remains unchanged, the mantissa of the first floating-point number needs to be shifted, that is, the mantissa of the first floating-point number is reduced by the same multiple (the mantissa is shifted right by the corresponding number of bits, a corresponding number of 0s are added before the highest bit of the mantissa, and then the last corresponding number of bits of the original mantissa is directly discarded, and the number of bits discarded is the same as the number of bits shifted, so that the number of bits of the mantissa remains unchanged).

[0136] Continuing with the above example, the first floating point number is a*2 c Since the exponent c is converted into d, a needs to be shifted to become a'. After obtaining a', the central processing unit can determine the specific way to split or convert the mantissa according to the type of integer ALU to be called by the hardware accelerator, so that the integer ALU can be called later to perform calculation processing on the preprocessing result, that is, the obtained integer.

[0137] Continuing with the above example, if both floating-point numbers are 64-bit floating-point numbers and their mantissas are both 52 bits, if the subsequent hardware accelerator uses the INT32 ALU, that is, uses the 32-bit integer ALU to calculate the preprocessing results, since the mantissa of the floating-point number is 52 bits (64-bit floating-point number), it is impossible to directly call the INT32 ALU as an integer for calculation. Therefore, the central processing unit determines that the mantissa of the floating-point number needs to be split, that is, the 52-bit mantissa is split into two 32-bit integers.

[0138] For example, the mantissa of the second floating point number or the mantissa of the first floating point number is shifted to obtain a':

[0139] 1111_0101_1010_1101_1110_1110_1110_1111_1110_0000_1111_1110_1110.

[0140] It can be split into (1110_1110_1111_1110_0000_1111_1110_1110) and (0000_0000_0000_1111_0101_1010_1101_1110), that is, the last 32 bits of the mantissa are an integer split out, and the first 20 bits of the mantissa (52-32) are another integer split out, and 12 zeros are added in front of it to form a 32-bit integer.

[0141] If the INT64 ALU is subsequently used, that is, the 64-bit integer ALU is used to calculate the preprocessing result, since the mantissa of the floating point number is 52 bits, the INT64 ALU can directly calculate the 64-bit integer, therefore, the central processing unit determines that the mantissa does not need to be split, but directly converts the mantissa into an integer that meets the calculation requirements of the integer ALU. That is, in this step, the splitting and conversion of the mantissa can refer to the above-mentioned method when the predetermined calculation is multiplication, which will not be repeated here. Similarly, the sign of the floating point number is also carried in the preprocessing result for the mantissa.

[0142] The above content is the preprocessing method determined by the central processing unit for the mantissa and exponent of each floating-point number when the predetermined calculation is addition. In addition, in addition to determining the preprocessing method, the central processing unit also needs to determine the method in which the hardware accelerator performs calculation processing on the preprocessing result. After determining the two types of processing methods, the central processing unit generates hardware processing instructions that can be executed by the hardware accelerator based on the two types of processing methods, and sends the hardware processing instructions and the two floating-point numbers to be performed for the predetermined calculation to the memory of the hardware accelerator, such as RAM, and the hardware accelerator executes the processing instruction.

[0143] After the hardware accelerator reads instructions and data from the local RAM, it can perform the following processing:

[0144] For the two floating-point numbers, calling an integer arithmetic logic unit ALU to compare the exponents of the two floating-point numbers, determining the floating-point number with a smaller exponent as a first floating-point number, and determining the floating-point number with a larger exponent as a second floating-point number; adjusting the exponent of the first floating-point number to the exponent of the second floating-point number, and determining the adjusted exponent as the exponent processing result;

[0145] shifting the mantissa of the first floating point number according to the adjustment of the exponent of the first floating point number;

[0146] The shifted mantissa and the mantissa of the second floating-point number are preprocessed by splitting or converting respectively to obtain preprocessing results that meet the calculation requirements of the integer ALU to be called; the integer arithmetic logic unit ALU is called to add the preprocessing results of the two mantissas to obtain the mantissa processing result.

[0147] The result of executing the predetermined calculation on the two floating-point numbers is obtained according to the mantissa processing result and the exponent processing result.

[0148] The way in which the hardware accelerator preprocesses the mantissa and exponent of each floating-point number can be referred to above and will not be described in detail here.

[0149] The process of calling the integer arithmetic logic unit ALU to calculate the preprocessing result is as follows:

[0150] Since for floating point numbers, addition means aligning the exponents and adding the mantissas. Using the above example, the first floating point number after preprocessing is a'*2 d , the second floating point number is b*2 d , that is, the exponent of the first floating-point number is adjusted to the exponent of the second floating-point number. Therefore, the exponent d of the second floating-point number can be directly used as the final exponent processing result, for example, Z.

[0151] For the mantissa, if a' or b is converted, since the preprocessing results after the conversion are all integers, the integer arithmetic logic unit ALU can be used directly to add the preprocessing results.

[0152] In addition, if the mantissa is split, such as splitting a' into a1' and a2', and splitting b into b1 and b2, then a'=(a1'*2 X +a2'), b=(b1*2 X +b2), where a2' is the value of a' up to the last x digits, and a1' is the value of a' excluding the last x digits.

[0153] Continuing with the above example, if a' is:

[0154] 1111_0101_1010_1101_1110_1110_1110_1111_1110_0000_1111_1110_1110, split it into two 32-bit integers, that is, x=32, that is, split into:

[0155] 1110_1110_1111_1110_0000_1111_1110_1110,

[0156] and 0000_0000_0000_1111_0101_1010_1101_1110.

[0157] Among them, 1110_1110_1111_1110_0000_1111_1110_1110 is the last 32 bits of a', that is, a2', and 0000_0000_0000_1111_0101_1010_1101_1110 is the first 20 bits of a' excluding the last 32 bits, that is, a1'.

[0158] That is, a'=(a1'*2 32 +a2'), similarly, b=(b1*2 32 +b2), you can call the integer arithmetic logic unit ALU pair (a1'*2 32 +a2') and (b1*2 32 +b2) to add.

[0159] That is, calculate a1'*2 32 +a2'+b1*2 32 +b2.

[0160] Among them, a1', a2', b1 and b2 are all integers, so the multiplication and addition calculations involved above can be calculated and processed by integer multiplication ALU and integer addition ALU, and finally the mantissa processing result is obtained, for example, W. It can be understood that since the preprocessing result also carries a sign, the mantissa processing result also carries a sign.

[0161] After obtaining the mantissa processing result and the exponent processing result, the result of executing the predetermined calculation on the two floating point numbers is obtained according to the mantissa processing result and the exponent processing result. The mantissa processing result and the exponent processing result can be processed in the format of floating point numbers, that is, Figure 1 The storage format of the floating-point numbers shown in the figure is combined to obtain the result of multiplication calculation for two floating-point numbers, that is, the mantissa processing result is used as the mantissa of the predetermined calculation result of the two floating-point numbers, and the exponent calculation result is used as the exponent of the predetermined calculation result of the two floating-point numbers. Using the above example, the two floating-point numbers are a*2 c and b*2 d The final result is W*2 d , which is a*2 c and b*2 d The sum of .

[0162] It is understandable that, although the above examples are all based on 64-bit floating point numbers, the floating point numbers can be any floating point numbers that the hardware accelerator does not have the ability to directly process, and those skilled in the art can flexibly use them to deal with practical problems based on the content disclosed in this disclosure. For example, the two floating point numbers can be extended double-precision floating point numbers or floating point numbers of other precisions, etc. The fact that the above floating point numbers are 64-bit floating point numbers should not be a limitation to the present disclosure.

[0163] Based on the above description, if Figure 5 As shown, the present disclosure proposes a floating point number processing method, which is executed by a hardware accelerator and includes:

[0164] S501, treating the exponents of the two floating-point numbers as integers respectively and performing processing corresponding to a predetermined calculation to obtain an exponential processing result;

[0165] S502, treating the mantissas of the two floating-point numbers as integers respectively and performing processing corresponding to a predetermined calculation to obtain a mantissa processing result;

[0166] In these two steps, when the predetermined calculation is multiplication, the mantissas and exponents of the two floating-point numbers are split or converted for preprocessing respectively, the preprocessing result obtained is an integer, and the integer ALU is called to add the exponent preprocessing results to obtain the exponent processing result, and the mantissa preprocessing results are multiplied to obtain the mantissa processing result. When the predetermined calculation is addition, during preprocessing, the exponents of the two floating-point numbers are compared as integers, the smaller exponent is adjusted to the larger exponent, and the adjusted exponent is determined to be the exponent processing result, the mantissa of the floating-point numbers adjusted for the exponent is shifted during preprocessing, and the mantissas of the two floating-point numbers are split or converted respectively, and the integer ALU is called to add the mantissa preprocessing results to obtain the mantissa processing result. The specific content can refer to the content described above, which will not be described in detail here.

[0167] S503: Obtain a result of executing the predetermined calculation on the two floating-point numbers according to the mantissa processing result and the exponent processing result.

[0168] In this step, specifically, the mantissa processing result may be used as the mantissa of the predetermined calculation results of the two floating-point numbers, and the exponent processing result may be used as the exponent of the predetermined calculation results of the two floating-point numbers.

[0169] With the above scheme, the central processing unit identifies the two floating-point numbers to be calculated and generates processing instructions. The hardware accelerator adjusts the calculation of the two floating-point numbers into the calculation of the exponent and the calculation of the mantissa according to the processing instructions, that is, the exponent and the mantissa are both calculated and processed as integers. Therefore, the local existing integer ALU can be called to calculate the addition or product of the two floating-point numbers. There is no need to develop the hardware of the floating-point ALU, thereby greatly reducing the complexity of hardware design and not requiring a long research and development cycle.

[0170] like Figure 6As shown, it is a logical schematic diagram of the central processing unit and the hardware accelerator executed by the present disclosure. After the central processing unit CPU recognizes two floating-point numbers, it determines the processing preprocessing method based on the software processing logic, and the subsequent processing method of the preprocessing result, generates the instructions that the hardware accelerator needs to execute, compiles them into the hardware instruction format supported by the hardware accelerator through the compiler, and writes the compiled instructions and two floating-point numbers into the memory of the hardware accelerator, such as RAM (Random Access Memory). After the hardware accelerator reads the instructions and data from the local RAM, it can parse the instructions and call the integer ALU to execute the above process, and finally obtain the sum or product of the two floating-point numbers.

[0171] like Figure 2 As shown, the present disclosure also provides a device for determining the square root of a floating-point number, including a central processing unit CPU210 and a hardware accelerator 220; in some usage scenarios, the product form of the electronic device is embodied as a graphics card; in other usage scenarios, the product form of the electronic device is embodied as a CPU motherboard.

[0172] The central processor 210 is used to identify two floating-point numbers to be used for performing a predetermined calculation, generate a processing instruction based on the identification result, and send the generated processing instruction and the two floating-point numbers to the hardware accelerator;

[0173] The hardware accelerator 220 is configured to execute, according to the processing instruction:

[0174] Taking the exponents of the two floating point numbers as integers and performing processing corresponding to the predetermined calculation, obtaining an exponential processing result;

[0175] The mantissas of the two floating point numbers are treated as integers and processed corresponding to the predetermined calculation to obtain a mantissa processing result;

[0176] The result of executing the predetermined calculation on the two floating-point numbers is obtained according to the mantissa processing result and the exponent processing result.

[0177] In one embodiment, the central processor 210 is configured to identify two floating-point numbers to be used for performing a predetermined calculation, determine a preprocessing method for the mantissa and exponent of each floating-point number, and a method for processing the preprocessing result, and generate processing instructions for the two determined processing methods.

[0178] In one embodiment, the predetermined calculation is a multiplication calculation; the hardware accelerator 220 is specifically used to preprocess the exponent of each floating-point number by splitting or converting it, and obtain a preprocessing result that meets the calculation requirements of the integer ALU to be called; and the integer arithmetic logic unit ALU is called to add the preprocessing results of the exponents of the two floating-point numbers to obtain an exponent processing result.

[0179] In this embodiment, the hardware accelerator 220 is specifically used to pre-process the mantissa of each floating-point number by splitting or converting it to obtain a pre-processing result that meets the calculation requirements of the integer ALU to be called; call the integer arithmetic logic unit ALU to multiply the pre-processing results of the mantissas of the two floating-point numbers to obtain a mantissa processing result.

[0180] In one embodiment, the predetermined calculation is an addition calculation;

[0181] The hardware accelerator 220 is specifically used to call an integer arithmetic logic unit ALU to compare the exponents of the two floating-point numbers, determine the floating-point number with a smaller exponent as the first floating-point number, and determine the floating-point number with a larger exponent as the second floating-point number;

[0182] The exponent of the first floating point number is preprocessed to be adjusted to the exponent of the second floating point number, and the adjusted exponent is determined as the exponent processing result.

[0183] In this embodiment, the hardware accelerator 220 is specifically used to shift the mantissa of the first floating-point number according to the adjustment of the exponent of the first floating-point number; pre-process the mantissa of the shifted first floating-point number and the mantissa of the second floating-point number by splitting or converting them respectively to obtain pre-processing results that meet the calculation requirements of the integer ALU to be called; call the integer arithmetic logic unit ALU to add the pre-processing results of the two mantissas to obtain the mantissa processing result.

[0184] In one embodiment, the hardware accelerator 220 is specifically configured to use the mantissa processing result as the mantissa of a result of executing the predetermined calculation on the two floating-point numbers, and use the exponent processing result as the exponent of a result of executing the predetermined calculation on the two floating-point numbers.

[0185] The disclosed embodiments also provide an electronic device, which includes the above-mentioned electronic device. In some usage scenarios, the product form of the electronic device is a portable electronic device, such as a smart phone, a tablet computer, a VR device, etc.; in some usage scenarios, the product form of the electronic device is a personal computer, a game console, a workstation, a server, etc.

[0186] The present disclosure also provides a central processing unit, including:

[0187] A memory for storing a processing program;

[0188] The controller is used to read the processing program to execute: identifying two floating-point numbers to be used for a predetermined calculation, generating a processing instruction based on the identification result, and sending the generated processing instruction to the hardware accelerator so that the hardware accelerator uses the exponents of the two floating-point numbers as integers to perform processing corresponding to the predetermined calculation to obtain an exponent processing result; uses the mantissas of the two floating-point numbers as integers to perform processing corresponding to the predetermined calculation to obtain a mantissa processing result; and obtains a result of the two floating-point numbers executing the predetermined calculation based on the mantissa processing result and the exponent processing result.

[0189] The present disclosure also provides a hardware accelerator, including:

[0190] A memory, used to store processing instructions sent by the central processing unit;

[0191] A controller that reads processing instructions from memory to execute:

[0192] Taking the exponents of the two floating point numbers as integers and performing processing corresponding to the predetermined calculation, obtaining an exponential processing result;

[0193] The mantissas of the two floating point numbers are treated as integers and processed corresponding to the predetermined calculation to obtain a mantissa processing result;

[0194] The result of executing the predetermined calculation on the two floating-point numbers is obtained according to the mantissa processing result and the exponent processing result.

[0195] In a specific embodiment, the hardware accelerator described in the present disclosure may be a GPU, such as Figure 7 As shown, it at least includes:

[0196] GPU core is used to process commands, such as drawing commands, and executes the image rendering pipeline according to the drawing commands. Among them, the GPU core mainly includes a computing unit, which is used to execute shader compiled instructions. It is a programmable module composed of a large number of ALUs; Cache (memory), which is used to cache GPU core data to reduce memory access; controller (not shown in the figure). In addition, the GPU core also has a variety of functional modules, such as rasterization (a fixed stage of the 3D rendering pipeline), Tilling (slicing a frame in the TBR and TBDR GPU architecture), cropping (a fixed stage of the 3D rendering pipeline, cropping out the primitives outside the observation range or not displayed on the back), post-processing (scaling, cropping, rotating, etc. of the drawn image), etc.

[0197] General DMA is used to perform data movement between host memory and GPU graphics card memory. For example, for 3D drawing, general DMA moves vertex data from host memory to GPU graphics card memory.

[0198] On-chip network, used for data exchange between masters and slaves on the SOC;

[0199] The application processor is used to schedule tasks of various modules on the SOC. For example, after the GPU renders a frame, it notifies the application processor, and the application processor then starts the display controller to display the image drawn by the GPU on the screen.

[0200] PCIe controller is used to communicate with the host, implement PCIe protocol, and connect GPU graphics card to the host through PCIe interface. Graphics API and graphics card driver are running on the host;

[0201] Memory controller, used to connect memory devices and save data on SOC;

[0202] Display controller, used to control the output of the frame buffer in the memory to the display via the display interface (HDMI, DP, etc.);

[0203] Video decoder, used to decode the encoded video on the host hard disk into a displayable picture.

[0204] The video encoder is used to encode the original video code stream on the host hard disk into a specified format and return it to the host.

[0205] As shown in the figure, the host is the central processing unit. After generating the processing instruction, it sends the instruction to the memory in the GPU chip GPUcore. The controller in the GPU core executes the above processing flow according to the processing instruction, obtains the result of executing the predetermined calculation on the two floating-point numbers, and returns the result to the host.

[0206] Although the preferred embodiments of the present disclosure have been described above, those skilled in the art may make additional changes and modifications to these embodiments once they are aware of the basic creative concepts. Therefore, the attached claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present disclosure, and those skilled in the art, without departing from the spirit and scope of the present disclosure, should also be regarded as the scope of protection of the embodiments of the present disclosure.

Claims

1. A floating point number processing method, comprising: The central processing unit identifies two floating-point numbers to be used for a predetermined calculation, determines a preprocessing method for a mantissa and an exponent of each floating-point number, and a method for processing a preprocessing result, generates processing instructions for the two determined processing methods, and sends the generated processing instructions to the hardware accelerator; The predetermined calculation is a multiplication calculation or an addition calculation; wherein the preprocessing method for the mantissa of each floating-point number includes: splitting or converting the mantissa of each floating-point number into an integer that meets the calculation requirements of any integer ALU owned by the hardware accelerator; the preprocessing method for the exponent of each floating-point number includes: splitting or converting the exponent of each floating-point number into an integer that meets the calculation requirements of any integer ALU owned by the hardware accelerator; The hardware accelerator performs the following according to the processing instructions: Calling a locally owned integer ALU to process the exponents of the two floating-point numbers as integers corresponding to the predetermined calculation to obtain an exponential processing result; Invoke the locally owned integer ALU to process the mantissas of the two floating-point numbers as integers corresponding to the predetermined calculation, and obtain a mantissa processing result; The result of executing the predetermined calculation on the two floating-point numbers is obtained according to the mantissa processing result and the exponent processing result.

2. The method according to claim 1, wherein the predetermined calculation is a multiplication calculation; The exponents of the two floating point numbers are respectively treated as integers to perform processing corresponding to the predetermined calculation to obtain exponential processing results, including: Perform preprocessing of splitting or converting the exponent of each floating point number to obtain a preprocessing result that meets the calculation requirements of the integer ALU to be called; The integer arithmetic logic unit ALU is called to add the preprocessing results of the exponents of the two floating point numbers to obtain an exponential processing result.

3. The method according to claim 2, wherein the mantissas of the two floating point numbers are respectively treated as integers to perform processing corresponding to the predetermined calculation to obtain mantissa processing results, comprising: The mantissa of each floating point number is preprocessed by splitting or converting to obtain a preprocessing result that meets the calculation requirements of the integer ALU to be called; The integer arithmetic logic unit ALU is called to multiply the preprocessing results of the mantissas of the two floating-point numbers to obtain a mantissa processing result.

4. The method according to claim 1, wherein the predetermined calculation is an addition calculation; The exponents of the two floating point numbers are respectively treated as integers to perform processing corresponding to the predetermined calculation to obtain exponential processing results, including: For the two floating-point numbers, calling an integer arithmetic logic unit ALU to compare the exponents of the two floating-point numbers, determining the floating-point number with a smaller exponent as the first floating-point number, and determining the floating-point number with a larger exponent as the second floating-point number; The exponent of the first floating point number is preprocessed to be adjusted to the exponent of the second floating point number, and the adjusted exponent is determined as the exponent processing result.

5. The method according to claim 4, wherein the mantissas of the two floating point numbers are respectively treated as integers to perform processing corresponding to the predetermined calculation to obtain mantissa processing results, comprising: shifting the mantissa of the first floating point number according to the adjustment of the exponent of the first floating point number; The mantissa of the first floating-point number after the shift and the mantissa of the second floating-point number are preprocessed by splitting or converting, respectively, to obtain preprocessing results that meet the calculation requirements of the integer ALU to be called; The integer arithmetic logic unit ALU is called to add the preprocessing results of the two mantissas to obtain a mantissa processing result.

6. The method according to claim 1, wherein obtaining the result of executing the predetermined calculation on the two floating-point numbers according to the mantissa processing result and the exponent processing result comprises: The mantissa processing result is used as the mantissa of a result of executing the predetermined calculation on the two floating-point numbers, and the exponent processing result is used as the exponent of a result of executing the predetermined calculation on the two floating-point numbers.

7. A floating point number processing device, comprising a central processing unit and a hardware accelerator; The central processing unit is used to identify two floating-point numbers to be used for a predetermined calculation, determine a preprocessing method for a mantissa and an exponent of each floating-point number, and a method for processing a preprocessing result, generate a processing instruction for the two determined processing methods, and send the generated processing instruction and the two floating-point numbers to the hardware accelerator; The predetermined calculation is a multiplication calculation or an addition calculation; wherein, The preprocessing method for the mantissa of each floating point number includes: splitting or converting the mantissa of each floating point number into an integer that meets the calculation requirements of any integer ALU owned by the hardware accelerator; the preprocessing method for the exponent of each floating point number includes: splitting or converting the exponent of each floating point number into an integer that meets the calculation requirements of any integer ALU owned by the hardware accelerator; A hardware accelerator, for executing according to the processing instruction: Calling a locally owned integer ALU to process the exponents of the two floating-point numbers as integers corresponding to the predetermined calculation to obtain an exponential processing result; Invoke the locally owned integer ALU to process the mantissas of the two floating-point numbers as integers corresponding to the predetermined calculation, and obtain a mantissa processing result; The result of executing the predetermined calculation on the two floating-point numbers is obtained according to the mantissa processing result and the exponent processing result.

8. The device according to claim 7, wherein the predetermined calculation is a multiplication calculation; The hardware accelerator is specifically used to pre-process the exponent of each floating point number by splitting or converting it, so as to obtain a pre-processing result that meets the calculation requirements of the integer ALU to be called; and to call the integer arithmetic logic unit ALU to add the pre-processing results of the exponents of the two floating point numbers, so as to obtain an exponent processing result.

9. The device according to claim 8, The hardware accelerator is specifically used to pre-process the mantissa of each floating point number by splitting or converting it, and obtain a pre-processing result that meets the calculation requirements of the integer ALU to be called; call the integer arithmetic logic unit ALU to multiply the pre-processing results of the mantissas of the two floating point numbers, and obtain a mantissa processing result.

10. The device according to claim 7, wherein the predetermined calculation is an addition calculation; The hardware accelerator is specifically used to call an integer arithmetic logic unit ALU to compare the exponents of the two floating-point numbers, determine the floating-point number with a smaller exponent as the first floating-point number, and determine the floating-point number with a larger exponent as the second floating-point number; The exponent of the first floating point number is preprocessed to be adjusted to the exponent of the second floating point number, and the adjusted exponent is determined as the exponent processing result.

11. The device according to claim 10, The hardware accelerator is specifically used to shift the mantissa of the first floating-point number according to the adjustment of the exponent of the first floating-point number; pre-process the mantissa of the shifted first floating-point number and the mantissa of the second floating-point number by splitting or converting them respectively to obtain pre-processing results that meet the calculation requirements of the integer ALU to be called; and call the integer arithmetic logic unit ALU to add the pre-processing results of the two mantissas to obtain the mantissa processing result.

12. The device according to claim 7, The hardware accelerator is specifically used to use the mantissa processing result as the mantissa of the result of the predetermined calculation performed on the two floating-point numbers, and use the exponent processing result as the exponent of the result of the predetermined calculation performed on the two floating-point numbers.

13. An electronic device comprising the device according to any one of claims 7 to 12.

14. A hardware accelerator, comprising: A memory, for storing processing instructions sent by a central processing unit, wherein the processing instructions are generated by the central processing unit to identify two floating-point numbers to be used for a predetermined calculation, determine a preprocessing method for a mantissa and an exponent of each floating-point number, and a method for processing a preprocessing result, and are generated for the two determined processing methods; The predetermined calculation is a multiplication calculation or an addition calculation; wherein the preprocessing method for the mantissa of each floating-point number includes: splitting or converting the mantissa of each floating-point number into an integer that meets the calculation requirements of any integer ALU owned by the hardware accelerator; the preprocessing method for the exponent of each floating-point number includes: splitting or converting the exponent of each floating-point number into an integer that meets the calculation requirements of any integer ALU owned by the hardware accelerator; A controller that reads processing instructions from memory to execute: The locally owned integer ALU is called to process the exponents of the two floating-point numbers as integers corresponding to the predetermined calculation to obtain an exponent processing result; the locally owned integer ALU is called to process the mantissas of the two floating-point numbers as integers corresponding to the predetermined calculation to obtain a mantissa processing result; and the result of executing the predetermined calculation on the two floating-point numbers is obtained based on the mantissa processing result and the exponent processing result.

15. A central processing unit, comprising: A memory for storing a processing program; The controller is used to read the processing program to perform: identifying two floating-point numbers to be subjected to a predetermined calculation, determining, for each floating-point number, a preprocessing method for its mantissa and exponent, and a method for processing the preprocessing result, generating processing instructions for the determined two types of processing methods, and sending the generated processing instructions to the hardware accelerator, so that the hardware accelerator calls a locally owned integer ALU to process the exponents of the two floating-point numbers as integers corresponding to the predetermined calculation to obtain an exponent processing result, calls a locally owned integer ALU to process the mantissas of the two floating-point numbers as integers corresponding to the predetermined calculation to obtain a mantissa processing result, and obtains a result of the two floating-point numbers executing the predetermined calculation according to the mantissa processing result and the exponent processing result; The predetermined calculation is a multiplication calculation or an addition calculation; wherein the preprocessing method for the mantissa of each floating-point number includes: splitting or converting the mantissa of each floating-point number into an integer that meets the calculation requirements of any integer ALU owned by the hardware accelerator; the preprocessing method for the exponent of each floating-point number includes: splitting or converting the exponent of each floating-point number into an integer that meets the calculation requirements of any integer ALU owned by the hardware accelerator.