A floating point number processing method and device

By adjusting high-precision floating-point numbers to low-precision floating-point numbers and using Newton's iteration method, the problem that existing hardware accelerators cannot efficiently calculate high-precision floating-point numbers is solved, efficient high-precision calculations are achieved, and hardware design complexity and research and development cycles are reduced. .

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

Patent Information

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

AI Technical Summary

Technical Problem

Existing hardware accelerators can usually only process low-precision floating-point numbers or integers, and cannot efficiently calculate high-precision floating-point numbers. This leads to the need to develop a special ALU when high-precision calculations are required, which increases the complexity of hardware design and the development cycle.

Method used

Obtain high-precision floating-point numbers through the central processor, adjust their precision to low-precision floating-point numbers, use the ALU corresponding to the low-precision floating-point numbers for processing, and use the Newton iteration method to determine the square root or square root reciprocal of the high-precision floating-point numbers, avoiding the need for high-precision floating-point numbers. Direct development of precision ALU.

Benefits of technology

It meets the requirements for high-precision floating-point number calculations, reduces hardware design complexity and research and development cycles, and improves computing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116700663B
    Figure CN116700663B
Patent Text Reader

Abstract

The present disclosure provides a floating-point number processing method and device, the method comprising: a central processing unit obtains a first-precision floating-point number, generates a processing instruction based on the first-precision floating-point number, and sends the processing instruction to a hardware accelerator; the hardware accelerator executes, based on the received processing instruction: adjusting the first-precision floating-point number to obtain a second-precision floating-point number; wherein the precision of the first-precision floating-point number is greater than the precision of the second-precision floating-point number; using an arithmetic logic unit ALU corresponding to the second-precision floating-point number, processing the second-precision floating-point number to obtain a processing result corresponding to the second-precision floating-point number; determining a Newton iteration initial value according to the processing result, and calling a local integer arithmetic logic unit ALU to simulate the Newton iteration method to determine the square root or the inverse square root of the first-precision floating-point number.
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] At present, in order to meet various application requirements, such as pursuing more extreme rendering images, hardware accelerators are required to have the ability to calculate high-precision floating-point numbers.

[0003] However, the hardware accelerators currently on the market usually only have ALU units for calculating low-precision floating-point numbers, or ALU units for calculating integers. If you want to calculate high-precision floating-point numbers, you need to develop hardware, that is, you need to design and develop an ALU for calculating high-precision floating-point numbers. This method increases the complexity of hardware design and also requires a longer R&D cycle. Summary of the invention

[0004] 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.

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

[0006] The central processing unit obtains a first precision floating point number, generates a processing instruction based on the first precision floating point number, and sends the processing instruction to the hardware accelerator;

[0007] Based on the processing instructions received, the hardware accelerator performs:

[0008] Adjusting the first precision floating point number to obtain a second precision floating point number; wherein the precision of the first precision floating point number is greater than the precision of the second precision floating point number;

[0009] Using an arithmetic logic unit ALU corresponding to the second precision floating-point number, processing the second precision floating-point number to obtain a processing result corresponding to the second precision floating-point number;

[0010] The initial value of the Newton iteration is determined according to the processing result, and the local integer arithmetic logic unit ALU is called to simulate the Newton iteration method to determine the square root or the inverse square root of the first precision floating point number.

[0011] In one embodiment, the using an arithmetic logic unit ALU corresponding to the second precision floating point number to process the second precision floating point number to obtain a processing result corresponding to the second precision floating point number includes:

[0012] Using a square root arithmetic logic unit ALU corresponding to the second precision floating point number, the second precision floating point number is processed to obtain a square root of the second precision floating point number;

[0013] The method of determining the initial value of the Newton iteration according to the processing result, and calling the local integer arithmetic logic unit ALU to simulate the Newton iteration method to determine the square root or the inverse square root of the first precision floating point number includes:

[0014] The initial value of Newton iteration is determined according to the square root of the second precision floating point number, and the local integer arithmetic logic unit ALU is called to simulate the Newton iteration method to determine the square root of the first precision floating point number.

[0015] In one embodiment, the method further includes: the hardware accelerator processes the square root of the first precision floating point number using an integer division arithmetic logic unit ALU to obtain the inverse square root of the first precision floating point number.

[0016] In one embodiment, adjusting the first precision floating point number to obtain the second precision floating point number includes:

[0017] The mantissa of the first precision floating-point number is intercepted to obtain a first mantissa that meets the mantissa bit width requirement of the second precision floating-point number;

[0018] The exponent of the first precision floating point number is split to obtain a first exponent that meets the exponent range requirement of the second precision floating point number.

[0019] In one embodiment, splitting the exponent of the first precision floating point number includes: splitting the exponent of the first precision floating point number into a first exponent and adding a second exponent; wherein the first exponent meets the exponent range requirement of the second precision floating point number, and the second exponent is an even number.

[0020] In one embodiment, determining the Newton iteration initial value according to the square root of the second precision floating point number, and calling the local arithmetic logic unit ALU to simulate the Newton iteration method to determine the square root of the first precision floating point number include:

[0021] The mantissa of the square root of the second precision floating point number is used as the initial value of the iteration;

[0022] The following steps are executed repeatedly until the preset stop condition is reached:

[0023] Determine the quotient of the mantissa of the first precision floating point number and the current iteration value, and update the iteration value to the average value of the quotient and the current iteration value;

[0024] After the loop ends, the product of the current iteration value, the first value and the second value is used as the square root of the first precision floating-point number; wherein the first value is the result of the power raised to the exponent of the square root of the second precision floating-point number with a base of 2, and the second value is the result of the power raised to the exponent of half of the second exponent with a base of 2.

[0025] In one embodiment, determining the quotient of the mantissa of the first precision floating point number and the current iteration value includes:

[0026] Determine the quotient of the first precision floating point number mantissa and the current iteration value using the integer division ALU;

[0027] The step of determining the iteration value as an average value of the quotient and the current iteration value includes:

[0028] An integer addition ALU is used to determine the sum of the quotient and the current iteration value, and an integer division ALU or a shift ALU is used to process the sum to obtain an average value of the quotient and the current iteration value.

[0029] In one embodiment, determining the Newton iteration initial value according to the square root of the second precision floating point number, and calling the local arithmetic logic unit ALU to simulate the Newton iteration method to determine the square root of the first precision floating point number include:

[0030] The product of the integer value corresponding to the square root of the second precision floating-point number and the second value is used as the iteration initial value; wherein the second value is the result of raising the second value to a power of 2 with half of the second exponent as the exponent; the integer value corresponding to the second precision floating-point number is the product of the mantissa of the second precision floating-point number and a fourth value, wherein the fourth value is the result of raising the second value to a power of 2 with the exponent of the second precision floating-point number as the exponent;

[0031] The following steps are executed repeatedly until the preset stop condition is reached:

[0032] Determine the quotient of the integer value corresponding to the first precision floating-point number and the current iteration value, and update the iteration value to the average of the quotient and the current iteration value; the integer value corresponding to the first precision floating-point number is the product of the mantissa of the first precision floating-point number and a third value, and the third value is a power result with 2 as the base and the exponent of the first precision floating-point number as the exponent;

[0033] After the loop ends, the current iteration value is taken as the square root of the first-precision floating-point number.

[0034] 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;

[0035] The central processing unit is configured to obtain a first precision floating point number, determine the precision of the first precision floating point number, generate a processing instruction based on the precision, and send the processing instruction to the hardware accelerator;

[0036] Hardware accelerators for executing, based on received processing instructions:

[0037] Adjusting the first precision floating point number to obtain a second precision floating point number; wherein the precision of the first precision floating point number is greater than the precision of the second precision floating point number;

[0038] Using an arithmetic logic unit ALU corresponding to the second precision floating-point number, processing the second precision floating-point number to obtain a processing result corresponding to the second precision floating-point number;

[0039] The initial value of the Newton iteration is determined according to the processing result, and the local integer arithmetic logic unit ALU is called to simulate the Newton iteration method to determine the square root or the inverse square root of the first precision floating point number.

[0040] In one embodiment, the hardware accelerator is specifically used to process the second precision floating point number using a square root arithmetic logic unit ALU corresponding to the second precision floating point number to obtain the square root of the second precision floating point number;

[0041] The initial value of Newton iteration is determined according to the square root of the second precision floating point number, and the local integer arithmetic logic unit ALU is called to simulate the Newton iteration method to determine the square root of the first precision floating point number.

[0042] In one embodiment, the hardware accelerator is further used to process the square root of the first precision floating point number using an integer division arithmetic logic unit ALU to obtain the inverse square root of the first precision floating point number.

[0043] In one embodiment, the hardware accelerator is specifically used to intercept the mantissa of the first precision floating-point number to obtain a first mantissa that meets the mantissa bit width requirement of the second precision floating-point number; and split the exponent of the first precision floating-point number to obtain a first exponent that meets the exponent range requirement of the second precision floating-point number.

[0044] In one embodiment, the hardware accelerator is specifically used to split the exponent of the first precision floating point number into a first exponent and a second exponent, wherein the first exponent meets the exponent range requirement of the second precision floating point number, and the second exponent is an even number.

[0045] In one embodiment, the hardware accelerator is specifically configured to use the mantissa of the square root of the second precision floating point number as an iteration initial value;

[0046] The following steps are executed repeatedly until the preset stop condition is reached:

[0047] Determine the quotient of the mantissa of the first precision floating point number and the current iteration value, and update the iteration value to the average value of the quotient and the current iteration value;

[0048] After the loop ends, the product of the current iteration value, the first value and the second value is used as the square root of the first precision floating-point number; wherein the first value is the result of the power raised to the exponent of the square root of the second precision floating-point number with a base of 2, and the second value is the result of the power raised to the exponent of half of the second exponent with a base of 2.

[0049] In one embodiment, the hardware accelerator is specifically used to determine the quotient of the mantissa of a first precision floating point number and a current iteration value using an integer division ALU; determine the sum of the quotient and the current iteration value using an integer addition ALU, and process the sum using an integer division ALU or a shift ALU to obtain an average value of the quotient and the current iteration value.

[0050] In one embodiment, the hardware accelerator is specifically used to use the product of the integer value corresponding to the square root of the second precision floating-point number and the second value as the iteration initial value; wherein the second value is a power result with 2 as the base and half of the second exponent as the exponent; the integer value corresponding to the second precision floating-point number is the product of the mantissa of the second precision floating-point number and a fourth value, and the fourth value is a power result with 2 as the base and the exponent of the second precision floating-point number as the exponent;

[0051] The following steps are executed repeatedly until the preset stop condition is reached:

[0052] Determine the quotient of the integer value corresponding to the first precision floating-point number and the current iteration value, and update the iteration value to the average of the quotient and the current iteration value; the integer value corresponding to the first precision floating-point number is the product of the mantissa of the first precision floating-point number and a third value, and the third value is a power result with 2 as the base and the exponent of the first precision floating-point number as the exponent;

[0053] After the loop ends, the current iteration value is taken as the square root of the first-precision floating-point number.

[0054] 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.

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

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

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

[0058] Adjusting the first precision floating point number to obtain a second precision floating point number; wherein the precision of the first precision floating point number is greater than the precision of the second precision floating point number;

[0059] Using a square root arithmetic logic unit ALU corresponding to the second precision floating point number, the second precision floating point number is processed to obtain a square root of the second precision floating point number;

[0060] The initial value of Newton iteration is determined according to the square root of the second precision floating point number, and the local integer arithmetic logic unit ALU is called to simulate the Newton iteration method to determine the square root of the first precision floating point number.

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

[0062] A memory for storing a processing program;

[0063] The controller is used to read the processing program to execute: obtaining a first precision floating-point number, determining the precision of the first precision floating-point number, generating a processing instruction based on the precision, and sending the processing instruction to a hardware accelerator, so that the hardware accelerator adjusts the first precision floating-point number to obtain a second precision floating-point number, the precision of the first precision floating-point number is greater than the precision of the second precision floating-point number, using a square root arithmetic logic unit ALU corresponding to the second precision floating-point number to process the second precision floating-point number to obtain the square root of the second precision floating-point number, determining a Newton iteration initial value according to the square root of the second precision floating-point number, and calling a local integer arithmetic logic unit ALU to simulate the Newton iteration method to determine the square root of the first precision floating-point number.

[0064] 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

[0065] 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.

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

[0067] Figure 2 A schematic diagram of double-precision floating-point number composition according to an embodiment of the present disclosure;

[0068] Figure 3 A structural schematic diagram of a floating point number processing device according to an embodiment of the present disclosure;

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

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

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

[0072] 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.

[0073] 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.

[0074] 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.

[0075] 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.

[0076] 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 calculating different data. Among them, one ALU can only be used to process the calculation of a certain type of data. For example, an ALU used to calculate single-precision floating-point numbers cannot calculate double-precision floating-point numbers. Similarly, an ALU used to calculate double-precision floating-point numbers cannot calculate single-precision floating-point numbers.

[0077] As described above, in order to meet various application requirements, such as the pursuit of more extreme rendering images, hardware accelerators are currently required to have the ability to calculate high-precision floating-point numbers (such as 64-bit floating-point numbers). However, the hardware accelerators currently on the market usually only have ALUs that calculate low-precision (such as less than 64 bits) floating-point numbers, or ALUs that calculate integers. If you want to calculate high-precision floating-point numbers, such as calculating the square root or the inverse of the square root of a high-precision floating-point number, you need to develop hardware, that is, you need to design and develop an ALU for calculating the square root of a high-precision floating-point number, and an ALU for calculating the inverse of the square root of a high-precision floating-point number. This method increases the complexity of hardware design and also increases the product development cycle.

[0078] In order to solve the above problems, the present disclosure proposes that a central processing unit identifies a high-precision floating-point number and determines the precision type of the high-precision floating-point number, and determines a processing instruction based on the identified precision type, adjusts the high-precision floating-point number to a low-precision floating-point number, and then a hardware accelerator can use an ALU corresponding to the low-precision floating-point number to process the obtained low-precision floating-point number, determine the initial value of the Newton iteration with the obtained processing result, and use the Newton iteration method to determine the square root or the inverse square root of the high-precision floating-point number.

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

[0080] 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.

[0081] 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.

[0082] 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.

[0083] 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.

[0084] 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.

[0085] like Figure 1 As shown, the sign field width is 1 bit, 0 represents positive, and 1 represents negative.

[0086] The exponent is also called the exponent code. The exponent field has a width of 8 bits. 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.

[0087] 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.

[0088] like Figure 2 As shown, it is a schematic diagram of double-precision floating point numbers (64-bit floating point numbers) stored in a computer, wherein the double-precision floating point number occupies a total of 64 bits (8 bytes) in the computer, wherein the continuous 64 bits are divided into three domains, including: the sign occupies 1 bit, the exponent occupies 11 bits, and the mantissa occupies 52 bits. According to the above content, it can be seen that floating point numbers of different precisions are stored in different forms in the computer.

[0089] 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.

[0090] like Figure 3 , 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 310 and a hardware accelerator 320 .

[0091] Based on this device, after the central processing unit obtains the first-precision floating-point number to be processed, it can identify the precision of the first-precision floating-point number. It can be understood that, under normal circumstances, the central processing unit can recognize floating-point numbers of various precisions compared to the hardware accelerator, so it can recognize the precision type of high-precision floating-point numbers and the size of the floating-point numbers, and generate processing instructions based on the recognition results.

[0092] When generating a processing instruction based on the first precision floating point number, specifically, the generated processing instruction includes adjusting the first precision floating point number to the second precision floating point number, and subsequently performing a Newton iterative calculation based on the second precision floating point number.

[0093] The second precision floating point number is specifically a floating point number that the hardware accelerator can directly calculate, so that the hardware accelerator can identify and calculate the second precision floating point number. Continuing with the above example, if the hardware accelerator has an ALU of FP16 (16-bit floating point number) and an ALU of FP32 (32-bit floating point number), the second precision floating point number can be a 16-bit floating point number or a 32-bit floating point number, and the central processing unit can determine the specific processing instructions according to the ALU possessed by the hardware accelerator, and the precision type and size of the first precision floating point number. It can be understood that different processing instructions will be generated based on different precision types and different sizes of first precision floating point numbers. For ease of description, unless otherwise specified, the following examples are given with the first precision floating point number being a 64-bit floating point number and the second precision floating point number being a 32-bit floating point number.

[0094] In this step, after the central processing unit identifies the first precision floating point number, it can determine a processing method for the first precision floating point number based on a preset software processing logic, and compile the processing method into a hardware processing instruction that can be executed by the hardware accelerator.

[0095] Specifically, the central processing unit may identify the mantissa field and the exponent field of the first precision floating point number, and determine different processing methods for the mantissa and the exponent of the first precision floating point number respectively.

[0096] The processing method for the mantissa of the first precision floating-point number can be: truncate the mantissa of the first precision floating-point number to obtain a first mantissa that meets the mantissa bit width requirement of the second precision floating-point number; for example, the first precision floating-point number is a 64-bit floating-point number, and its mantissa bit width is 52 bits, and the second precision floating-point number is a 32-bit floating-point number, and its mantissa bit width is 23 bits. Therefore, the first mantissa can be obtained by truncating 23 bits of the mantissa backwards starting from the highest bit of the mantissa of the first precision floating-point number, and the first mantissa is the mantissa of the second precision floating-point number.

[0097] For example, the mantissa of a 64-bit floating point number is:

[0098] 1111_0101_1010_1101_1110_1110_1110_1111_1110_0000_1111_1110_1110. The first digit is 1111_0101_1010_1101_1110_111.

[0099] The exponent of the first precision floating point number may be processed by splitting the exponent to obtain a first exponent that meets the exponent range requirement of the second precision floating point number.

[0100] Specifically, the exponent of the first precision floating point number may be split into a first exponent and a second exponent, wherein the first exponent meets the exponent range requirement of the second precision floating point number and the second exponent is an even number. The first exponent is the exponent of the second precision floating point number.

[0101] Since the exponent representation range of high-precision floating-point numbers is larger than that of low-precision floating-point numbers, the exponent of the first-precision floating-point number may not be within the exponent expression range of the second-precision floating-point number. It is necessary to first determine whether the exponent of the first-precision floating-point number is within the exponent range of the second-precision floating-point number.

[0102] For example, the exponent range of a 64-bit floating-point number is [-1023, 1024], while the exponent range of a 32-bit floating-point number is [-127, 128]. Since the IEEE standard stipulates that the value in the exponent field is the actual value of the exponent plus the bias, if the value of the first-precision floating-point number in the exponent field is e, the actual value of the exponent of the first-precision floating-point number is e-1023 (the bias is 1023 for 64-bit floating-point numbers). It is further necessary to determine whether e-1023 belongs to [-127, 128]. If so, e-1023 is directly determined as the actual value of the first exponent. Similarly, due to the requirements of the IEEE standard, the first exponent stored in the exponent field of the second-precision floating-point number is determined to be e-1203+127 (the bias is 127 for 32-bit floating-point numbers). In this step, if the exponent of the first precision floating point number is within the exponent range of the second precision floating point number, it can be understood that the exponent of the first precision floating point number is split into a first exponent and a second exponent, wherein the second exponent is specifically 0.

[0103] When the exponent of the first precision floating-point number is not within the exponent range of the second precision floating-point number, it is necessary to ensure that the split first exponent is within the exponent range of the second precision floating-point number and the second exponent is a non-zero even number.

[0104] Using the above example, the actual value of the exponent of the first-precision floating-point number is e-1023. If it is not in [-127, 128], the exponent is split into X+Y, where the first exponent X is a number in the range of [-127, 128] and can be represented by 8 bits. X+127 is the value in the exponent field of the second-precision floating-point number, and the second exponent Y is specifically an even number. The specific reason for splitting into even numbers can be referred to below, which will not be described in detail here.

[0105] In this step, when the central processor determines X and Y, a specific implementation method may be as follows:

[0106]

[0107]

[0108] That is, if the actual value of the exponent of the first precision floating point number is e-1023 and is greater than 128, it is determined whether e-1023 is an odd number or an even number. If it is an even number, X is 128 and Y is e-1023-128; if it is an odd number, X is 127 and Y is e-1023-127.

[0109] In addition, if e-1023 is less than -127, determine whether e-1023 is an odd number or an even number. If it is an even number, X is -126 and Y is e-1023+126; if it is an odd number, X is -127 and Y is e-1023+127.

[0110] It is understandable that the above splitting process is only a specific implementation method, and the first mantissa and the second mantissa can also be obtained based on other splitting methods, so that the first mantissa meets the exponent range requirement of the second precision floating point number and the second exponent is an even number.

[0111] In this step, after determining the processing method for the first precision floating point number, the central processing unit can generate a hardware processing instruction that can be executed by the hardware accelerator, and send the processing instruction and the first precision floating point number to the memory of the hardware accelerator, such as RAM, and the hardware accelerator performs processing based on the received instruction.

[0112] like Figure 5The above is a logical diagram of the central processing unit and the hardware accelerator executed by the present disclosure. After the central processing unit CPU recognizes the high-precision 64-bit floating point number, it determines the processing method for the exponent and the mantissa based on the software processing logic, and the subsequent processing method for the second-precision floating point number, 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 the first-precision floating point number 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 executes the following Figure 4 The method shown. Figure 4 The figure shows a flow chart of a floating point number processing method proposed in the present disclosure, which is executed by a hardware accelerator and includes:

[0113] S401, adjusting a first precision floating point number to obtain a second precision floating point number; wherein the precision of the first precision floating point number is greater than the precision of the second precision floating point number;

[0114] In this step, the hardware accelerator processes the first precision floating point number based on the processing instruction sent by the central processing unit. The processing method can refer to the above description, such as splitting the exponent and truncating the mantissa, which will not be repeated here.

[0115] The hardware accelerator processes the mantissa and the exponent of the first precision floating point number respectively according to the instruction, and obtains the first mantissa and the first exponent, thereby obtaining the second precision floating point number.

[0116] Using the above example, the first mantissa is 1111_0101_1010_1101_1110_111, and the first exponent X is 2. X , then the second precision floating point number is 1111_0101_1010_1101_1110_111*2 X , wherein it can be understood that the second precision floating point number is specifically stored in the computer in the form of a standard floating point number, and the aforementioned combination form is only shown for the convenience of illustration and description.

[0117] S402, using an arithmetic logic unit ALU corresponding to the second precision floating-point number, processing the second precision floating-point number to obtain a processing result corresponding to the second precision floating-point number;

[0118] Since the second precision floating point number is a floating point number that can be directly calculated and processed by the hardware accelerator, the hardware accelerator can use the local arithmetic logic unit ALU corresponding to the second precision floating point number to process the second precision floating point number and obtain the processing result. For example, if the square root reciprocal arithmetic logic unit ALU corresponding to the second precision floating point number is used to calculate the second precision floating point number, the square root reciprocal of the second precision floating point number will be obtained; if the square root arithmetic logic unit ALU corresponding to the second precision floating point number is used to calculate the second precision floating point number, the square root of the second precision floating point number will be obtained. That is, the processing result obtained above can be the square root or the reciprocal square root of the second precision floating point number. For example, the local 32-bit floating point number square root reciprocal ALU or square root ALU is used to calculate and process the 32-bit floating point number (second precision floating point number), and the reciprocal square root or square root is a*2 b , which is stored in the computer as a floating point number, and is shown in the above format only for the convenience of explanation.

[0119] S403, determining the initial value of Newton iteration according to the processing result, calling the local integer arithmetic logic unit ALU to simulate Newton iteration method to determine the square root or the inverse square root of the first precision floating point number.

[0120] The Newton iteration method is also called the Newton-Raphson method. The idea is to use the linear approximation of the tangent line to solve the polynomial. For details, please refer to the relevant technology, which will not be described in detail in this disclosure.

[0121] In this step, if the processing result is the square root of the second precision floating-point number, the Newton iteration initial value is determined by using the square root of the second precision floating-point number, and the square root of the first precision floating-point number can be determined by simulating the Newton iteration method; similarly, if the processing result is the reciprocal square root of the second precision floating-point number, the Newton iteration initial value is determined by using the reciprocal square root of the second precision floating-point number, and the square root of the first precision floating-point number can be determined by simulating the Newton iteration method. The specific content of this step can be referred to below and will not be described in detail here.

[0122] After determining the square root of the first precision floating point number, the integer division ALU may be used to determine the reciprocal square root of the first precision floating point number; similarly, after determining the reciprocal square root of the first precision floating point number, the integer division ALU may be used to determine the square root of the first precision floating point number.

[0123] By adopting the above method, there is no need to carry out hardware development of the ALU for high-precision floating-point numbers. Instead, the square root or the inverse square root of the high-precision floating-point number can be obtained by using the existing ALU of the hardware accelerator. At the same time, the processing result corresponding to the second-precision floating-point number is used as a reference for the initial value of the Newton iteration, rather than using a random value as the initial value of the iteration. This can make the initial value of the iteration more likely to be closer to the final value, greatly reduce the number of iterations, and improve computing efficiency.

[0124] The process in S403 is described in detail below:

[0125] In the related art, the Newton iteration formula is x n+1 =x n -f(x n ) / f′(x n ), where f(x n ) is the formula for calculating the reciprocal of the square root, that is, f(x) = 1 / x 2 -y, where y is the value to be calculated for the reciprocal square root, and x is the reciprocal square root of y; or, f(x n ) is the formula for calculating square root, that is, f(x) = x 2 -y, where y is the value to be calculated and x is the square root of y. n ) is the result of taking the derivative of f(x).

[0126] For Newton's iteration formula for finding the inverse of the square root, f(x) = 1 / x 2 -y,f′(x n )=-2x -3 , f(x) and f′(x n ) into the Newton iteration formula x n+1 =x n -f(x n ) / f′(x n ), that is, we get x n+1 =1.5x n -0.5yx n 3 .

[0127] For Newton's iteration formula for square roots, f(x) = x 2 -y,f′(x n )=2x, replace f(x) with f′(x n ) into the Newton iteration formula x n+1 =x n -f(x n ) / f′(x n ), that is, we get x n+1 =(x n +y / x n ) / 2.

[0128] That is, the Newton iteration method first determines an initial value x0 for the iteration, and then starts the iteration. After each iteration, the value x n+1 X n The square root reciprocal or square root closer to y can be output after reaching the preset stop condition, which can be x after iteration. n+1 With x n The difference is less than a preset value, etc., which is not limited in the present disclosure.

[0129] Taking the processing result obtained in S402 as the square root of the second precision floating-point number as an example, the process of determining the iteration initial value according to the square root of the second precision floating-point number and determining the square root of the first precision floating-point number by simulating the Newton iteration method in S403 is described below:

[0130] A feasible implementation method is:

[0131] The mantissa of the square root of the second precision floating point number may be used as the initial value of the iteration;

[0132] The following steps are executed repeatedly until the preset stop condition is reached:

[0133] Determine the quotient of the mantissa of the first precision floating point number and the current iteration value, and update the iteration value to the average value of the quotient and the current iteration value;

[0134] After the loop ends, the product of the current iteration value, the first value and the second value is used as the square root of the first precision floating-point number; wherein the first value is the result of the power raised to the exponent of the square root of the second precision floating-point number with a base of 2, and the second value is the result of the power raised to the exponent of half of the second exponent with a base of 2.

[0135] For example, using the above example, if the square root of the second precision floating point number is a*2 b , the second index is Y, then the first value is 2 b , the second value is 2 -Y / 2 It can be understood that, since Y is an integer, the hardware accelerator can use the integer ALU to calculate -Y / 2, and since Y is an even number, -Y / 2 is also an integer. The second value may be calculated when the second exponent is obtained, or the second value may be calculated when the second value is needed for calculation. Similarly, the first value may be calculated when the square root of the second precision floating point number is obtained, or the first value may be calculated in this step. This is not limited in the present embodiment.

[0136] If the first precision floating point number is c*2 d, then the mantissa a of the square root of the second precision floating-point number is used as the initial value of Newton iteration, that is, x0=a, and the quotient of the mantissa c of the first precision floating-point number and the current iteration value x is determined, and the value of the iteration value x is updated to the average value x=(x+c / x) / 2 of the quotient and the current iteration value; the local ALU is used to simulate the Newton iteration method for finding the inverse of the square root to iterate and obtain the output value, that is, simulate the above x=(x+c / x) / 2, and iterate. After the iteration, the output value is Z, and then Z*2 is determined. b *2 -Y / 2 The square root of a first-precision floating-point number.

[0137] In this implementation, the mantissa of the square root of the second precision floating-point number is used as the initial value of the Newton iteration, and the mantissa of the first precision floating-point number is used as the target value. Since the mantissa of the square root of the second precision floating-point number and the mantissa of the first precision floating-point number are both integers, the hardware accelerator can use the local integer ALU to perform the above iterative calculation process. n+1 =(x n +y / x n ) / 2, the multiplication, addition, and division involved can all be implemented by integer multiplication ALU, integer addition ALU, and integer division ALU. In addition, by using the mantissa of the square root of the second precision floating-point number as the iteration initial value, compared with randomly selecting the iteration initial value, the number of iterations can be greatly reduced, and the iteration result can be converged as quickly as possible, with a higher overall processing efficiency.

[0138] Another possible implementation is:

[0139] The product of the integer value corresponding to the square root of the second precision floating-point number and the second value is used as the iteration initial value; wherein the second value is the result of raising the second value to a power of 2 with half of the second exponent as the exponent; the integer value corresponding to the second precision floating-point number is the product of the mantissa of the second precision floating-point number and a fourth value, wherein the fourth value is the result of raising the second value to a power of 2 with the exponent of the second precision floating-point number as the exponent;

[0140] The following steps are executed repeatedly until the preset stop condition is reached:

[0141] Determine the quotient of the integer value corresponding to the first precision floating-point number and the current iteration value, and update the iteration value to the average of the quotient and the current iteration value; the integer value corresponding to the first precision floating-point number is the product of the mantissa of the first precision floating-point number and a third value, and the third value is a power result with 2 as the base and the exponent of the first precision floating-point number as the exponent;

[0142] After the loop ends, the current iteration value is taken as the square root of the first-precision floating-point number.

[0143] For example, using the above example, if the square root of the second precision floating point number is a*2 b , the second index is Y, then the second value is 2 -Y / 2 , the square root of the second precision floating point number a*2 b The corresponding integer value is used as the initial value of Newton iteration. The square root of the second precision floating point number is stored in floating point format. The local integer ALU can be called to calculate its integer value, that is, first calculate the power result with 2 as the base and the exponent of the second precision floating point number as the exponent, that is, determine 2 b The value of is the fourth value, and then the product a*2 of the fourth value and the mantissa of the second precision floating point number is determined. b The value is the integer value corresponding to the square root of the second-precision floating-point number.

[0144] If the first precision floating point number is c*2 d , the local integer ALU can be called to calculate the integer value corresponding to the first precision floating point number, that is, first calculate the power result with 2 as the base and the exponent of the first precision floating point number as the exponent, that is, determine 2 d The value of is the third value, and then the product c*2 of the third value and the mantissa of the first precision floating point number is determined. d The value is the integer value corresponding to the square root of the first-precision floating-point number.

[0145] After determining the integer value corresponding to the square root of the first precision floating point number and the integer value corresponding to the square root of the second precision floating point number, Newton iteration can be performed. The product of the integer value corresponding to the square root of the second precision floating point number and the second value can be used as the iteration initial value x0, that is, x0 = a*2 b *2 -Y / 2 . Determine the integer value c*2 corresponding to the first precision floating point number d The quotient of the quotient and the current iteration value x, and the iteration value x is updated to the average value of the quotient and the current iteration value x = (x + (c * 2 d ) / x) / 2; use the local ALU to simulate the Newton iteration method for finding the inverse of the square root to iterate and obtain the output value, that is, simulate the above x=(x+c / x) / 2, and iterate. After the iteration, the output value is Z, then Z is determined to be the square root of the first precision floating point number.

[0146] In this implementation, the product of the integer value corresponding to the square root of the second precision floating-point number and the second value is used as the iteration initial value, and the integer value corresponding to the first precision floating-point number is used as the target value. Since both values ​​are integers, the hardware accelerator can use the local integer ALU to perform the above iterative calculation process. n+1 =(x n +y / x n) / 2, the multiplication, addition, and division involved can all be implemented by integer multiplication ALU, integer addition ALU, and integer division ALU. In addition, by using the square root of the second precision floating-point number as a reference for the iteration initial value, compared with randomly selecting the iteration initial value, the number of iterations can be greatly reduced, and the iteration results can be converged as quickly as possible, with a higher overall processing efficiency.

[0147] Both of the above two specific implementations can obtain the square root of the first precision floating point number through Newton iteration, and the hardware accelerator can use the integer division ALU to process the square root of the first precision floating point number to obtain the inverse square root of the first precision floating point number.

[0148] It can be understood that in the above two specific implementations, the square root of the first precision floating point number is first calculated, and then the reciprocal square root of the first precision floating point number is obtained based on the square root of the first precision floating point number. Alternatively, the reciprocal square root of the first precision floating point number is first calculated, and then the square root of the first precision floating point number is obtained based on the reciprocal square root of the first precision floating point number.

[0149] The following takes the case where the processing result obtained in S402 is the inverse square root of the second precision floating-point number as an example to illustrate the process of determining the iteration initial value according to the inverse square root of the second precision floating-point number and determining the inverse square root of the first precision floating-point number by simulating the Newton iteration method in S403:

[0150] A feasible implementation method is:

[0151] The mantissa of the reciprocal square root of the second precision floating-point number is used as the initial value of Newton's iteration, and the mantissa of the first precision floating-point number is used as the target value. The Newton's iteration method for simulating the reciprocal square root is iterated to obtain an output value; the product of the output value, the first value and the second value is used as the reciprocal square root of the first precision floating-point number, wherein the first value is a power result with 2 as the base and the exponent of the reciprocal square root of the second precision floating-point number as the exponent, and the second value is a power result with 2 as the base and the opposite of half of the second exponent as the exponent.

[0152] Continuing with the above example, the reciprocal square root of the second precision floating point number is a*2 b , the second index is Y, then the second value is 2 -Y / 2 It is understandable that, since Y is an integer, the hardware accelerator can use the integer ALU to calculate -Y / 2. If the first precision floating point number is c*2 d , then a is used as the initial value x0 of Newton iteration, c is used as the target value y, and the local ALU is used to simulate the Newton iteration method for finding the inverse of the square root to iterate and obtain the output value, that is, to simulate the above x n+1 =1.5x n -0.5yxn 3 , iterate, for example, after the iteration, the output value is Z, then determine Z*2 b *2 -Y / 2 The reciprocal square root of a first-precision floating-point number.

[0153] In this implementation, the mantissa of the inverse square root of the second precision floating-point number is used as the initial value of Newton iteration, and the mantissa of the first precision floating-point number is used as the target value. Since the mantissa of the inverse square root of the second precision floating-point number and the mantissa of the first precision floating-point number are both integers, the hardware accelerator can use the local integer ALU to perform the above iterative calculation process. n+1 =1.5x n -0.5yx n 3 When calculating, the multiplication and addition involved can be implemented by integer multiplication ALU and integer addition ALU. In addition, using the mantissa of the second precision floating point number as the iteration initial value can greatly reduce the number of iterations compared to randomly selecting the iteration initial value, and can make the iteration result converge as quickly as possible, with higher overall processing efficiency.

[0154] Another possible implementation is:

[0155] The product of the integer value corresponding to the inverse square root of the second precision floating-point number and the second value is used as the initial value of Newton's iteration, the integer value corresponding to the first precision floating-point number is used as the target value, and the Newton's iteration method for finding the inverse square root is simulated to iterate to obtain the output value; the output value is used as the inverse square root of the first precision floating-point number.

[0156] Using the above example, for example, the reciprocal square root of a second precision floating point number is a*2 b , the second value is 2 -Y / 2 , then a*2 b *2 -Y / 2 As the initial value of Newton iteration, when calculating the product of the inverse square root of the second precision floating-point number and the second value, it is necessary to determine the integer value of the inverse square root of the second precision floating-point number, and use the integer ALU to process the integer value of the inverse square root of the second precision floating-point number and the second value to obtain the product. The calculations involved in the process of obtaining the integer value of the inverse square root of the second precision floating-point number can all be processed by the integer ALU.

[0157] The integer value corresponding to the first precision floating point number is taken as the target value y, and the Newton iteration method for finding the inverse of the square root is simulated by the local ALU to iterate and obtain the output value, that is, to simulate the above x n+1 =1.5x n -0.5yx n 3, iterate, for example, after the iteration, the output value is Z, then Z is determined to be the inverse square root of the first precision floating point number. In this embodiment, the local integer ALU can be used to obtain the integer value corresponding to the first precision floating point number.

[0158] In this implementation, the product of the integer value corresponding to the inverse of the square root of the second precision floating-point number and the second value is used as the initial value of the Newton iteration, and the integer value corresponding to the first precision floating-point number is used as the target value. Since the product and the integer value corresponding to the first precision floating-point number are both integers, the hardware accelerator can use the local integer ALU to perform the above iterative calculation process. If you need to implement the form x n+1 =1.5x n -0.5yx n 3 When calculating, the multiplication and addition involved can be implemented by integer multiplication ALU and integer addition ALU. In addition, the product of the integer value corresponding to the inverse square root of the second precision floating point number and the inverse square root of the second value is used as the iteration initial value. Compared with randomly selecting the iteration initial value, the number of iterations can be greatly reduced, and the iteration result can be converged as quickly as possible, with high overall processing efficiency.

[0159] Both of the above two specific implementations can obtain the inverse square root of the first precision floating point number through Newton iteration, and the hardware accelerator can use the integer division ALU to process the inverse square root of the first precision floating point number to obtain the square root of the first precision floating point number.

[0160] In the above four specific implementations, it is necessary to calculate and use half of the second exponent. Therefore, when splitting the exponent of the first precision floating point number, it is necessary to ensure that the split second exponent is an even number.

[0161] like Figure 5 As shown, when the hardware accelerator performs processing based on the Newton iteration method, it can specifically call a variety of existing local ALUs to perform calculations, thereby simulating the implementation of the Newton iteration method. Figure 5 The second precision floating point number square root reciprocal ALU, second precision floating point number square root ALU, integer addition ALU, integer multiplication ALU, and integer division ALU shown are merely examples of ALUs in currently common hardware accelerators, and currently common hardware accelerators often also have other ALUs.

[0162] It is understandable that, although the above examples are all based on the first precision floating point number being a 64-bit floating point number and the second precision floating point number being a 32-bit floating point number, the second precision floating point number can be a floating point number that any hardware accelerator has the direct processing capability, and the first precision floating point number can be a floating point number that any hardware accelerator does not have the processing capability and the precision is higher than the second precision. Those skilled in the art can flexibly apply it to deal with practical problems according to the content disclosed in this disclosure. For example, the first precision floating point number can be an extended double precision floating point number, the second precision floating point number can be a 16-bit floating point number, and so on. The above first precision floating point number being a 64-bit floating point number and the second precision floating point number being a 32-bit floating point number should not be a limitation to the present disclosure.

[0163] By adopting the above method, there is no need to carry out hardware development of the ALU for high-precision floating-point numbers. Instead, the square root of the high-precision floating-point number and the inverse of the square root of the high-precision floating-point number can be obtained by using the existing ALU of the hardware accelerator. At the same time, the square root of the second-precision floating-point number or the inverse of the square root of the second-precision floating-point number is used as a reference for the initial value of the Newton iteration, rather than using a random value as the initial value of the iteration. This can make the initial value of the iteration more likely to be closer to the final value, greatly reduce the number of iterations, and improve computing efficiency.

[0164] like Figure 3 As shown, corresponding to the aforementioned method for determining a floating point number, the present disclosure further provides a device for determining a floating point number, characterized in that it includes a central processing unit CPU 310 and a hardware accelerator 320;

[0165] The central processor 310 is used to obtain a first precision floating point number, determine the precision of the first precision floating point number, generate a processing instruction based on the precision, and send the processing instruction to the hardware accelerator;

[0166] The hardware accelerator 320 is configured to execute, based on the received processing instruction:

[0167] Adjusting the first precision floating point number to obtain a second precision floating point number; wherein the precision of the first precision floating point number is greater than the precision of the second precision floating point number;

[0168] Using an arithmetic logic unit ALU corresponding to the second precision floating-point number, processing the second precision floating-point number to obtain a processing result corresponding to the second precision floating-point number;

[0169] The initial value of the Newton iteration is determined according to the processing result, and the local integer arithmetic logic unit ALU is called to simulate the Newton iteration method to determine the square root or the inverse square root of the first precision floating point number.

[0170] In one embodiment, the hardware accelerator 320 is specifically configured to process the second precision floating point number using a square root arithmetic logic unit ALU corresponding to the second precision floating point number to obtain a square root of the second precision floating point number;

[0171] The initial value of Newton iteration is determined according to the square root of the second precision floating point number, and the local integer arithmetic logic unit ALU is called to simulate the Newton iteration method to determine the square root of the first precision floating point number.

[0172] In one embodiment, the hardware accelerator 320 is further configured to process the square root of the first precision floating point number using an integer division arithmetic logic unit ALU to obtain the inverse square root of the first precision floating point number.

[0173] In one embodiment, the hardware accelerator 320 is specifically used to intercept the mantissa of the first precision floating-point number to obtain a first mantissa that meets the mantissa bit width requirement of the second precision floating-point number; and split the exponent of the first precision floating-point number to obtain a first exponent that meets the exponent range requirement of the second precision floating-point number.

[0174] In one embodiment, the hardware accelerator 320 is specifically configured to split the exponent of the first precision floating point number into a first exponent and a second exponent, wherein the first exponent meets the exponent range requirement of the second precision floating point number, and the second exponent is an even number.

[0175] In one embodiment, the hardware accelerator 320 is specifically configured to use the mantissa of the square root of the second precision floating point number as an iteration initial value;

[0176] The following steps are executed repeatedly until the preset stop condition is reached:

[0177] Determine the quotient of the mantissa of the first precision floating point number and the current iteration value, and update the iteration value to the average value of the quotient and the current iteration value;

[0178] After the loop ends, the product of the current iteration value, the first value and the second value is used as the square root of the first precision floating-point number; wherein the first value is the result of the power raised to the exponent of the square root of the second precision floating-point number with a base of 2, and the second value is the result of the power raised to the exponent of half of the second exponent with a base of 2.

[0179] In one embodiment, the hardware accelerator 320 is specifically used to determine the quotient of the mantissa of the first precision floating point number and the current iteration value using an integer division ALU; determine the sum of the quotient and the current iteration value using an integer addition ALU, and process the sum using an integer division ALU or a shift ALU to obtain an average value of the quotient and the current iteration value.

[0180] In one embodiment, the hardware accelerator 320 is specifically used to use the product of the integer value corresponding to the square root of the second precision floating-point number and the second value as the iteration initial value; wherein the second value is a power result with 2 as the base and half of the second exponent as the exponent; the integer value corresponding to the second precision floating-point number is the product of the mantissa of the second precision floating-point number and a fourth value, and the fourth value is a power result with 2 as the base and the exponent of the second precision floating-point number as the exponent;

[0181] The following steps are executed repeatedly until the preset stop condition is reached:

[0182] Determine the quotient of the integer value corresponding to the first precision floating-point number and the current iteration value, and update the iteration value to the average of the quotient and the current iteration value; the integer value corresponding to the first precision floating-point number is the product of the mantissa of the first precision floating-point number and a third value, and the third value is a power result with 2 as the base and the exponent of the first precision floating-point number as the exponent;

[0183] After the loop ends, the current iteration value is taken as the square root of the first-precision floating-point number.

[0184] The disclosed embodiment also provides an electronic device, which includes the above floating-point number processing 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.

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

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

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

[0188] Adjusting the first precision floating point number to obtain a second precision floating point number; wherein the precision of the first precision floating point number is greater than the precision of the second precision floating point number;

[0189] Using a square root arithmetic logic unit ALU corresponding to the second precision floating point number, the second precision floating point number is processed to obtain a square root of the second precision floating point number;

[0190] The initial value of Newton iteration is determined according to the square root of the second precision floating point number, and the local integer arithmetic logic unit ALU is called to simulate the Newton iteration method to determine the square root of the first precision floating point number.

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

[0192] A memory for storing a processing program;

[0193] The controller is used to read the processing program to execute: obtaining a first precision floating-point number, determining the precision of the first precision floating-point number, generating a processing instruction based on the precision, and sending the processing instruction to a hardware accelerator, so that the hardware accelerator adjusts the first precision floating-point number to obtain a second precision floating-point number, the precision of the first precision floating-point number is greater than the precision of the second precision floating-point number, using a square root arithmetic logic unit ALU corresponding to the second precision floating-point number to process the second precision floating-point number to obtain the square root of the second precision floating-point number, determining a Newton iteration initial value according to the square root of the second precision floating-point number, and calling a local integer arithmetic logic unit ALU to simulate the Newton iteration method to determine the square root of the first precision floating-point number.

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

[0195] 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.

[0196] 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.

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

[0198] 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.

[0199] 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;

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

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

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

[0203] 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.

[0204] As shown in the figure, the host is the central processing unit. After generating a 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 processing result, and returns the processing result to the host.

[0205] 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 obtains a first precision floating point number, generates a processing instruction based on the first precision floating point number, and sends the processing instruction to the hardware accelerator; Based on the processing instructions received, the hardware accelerator performs: The mantissa of the first precision floating-point number is intercepted to obtain a first mantissa that meets the mantissa bit width requirement of the second precision floating-point number as the mantissa of the second precision floating-point number; the exponent of the first precision floating-point number is split into a first exponent and a second exponent, and the exponents are added; wherein the first exponent meets the exponent range requirement of the second precision floating-point number as the exponent of the second precision floating-point number, and the second exponent is an even number; the precision of the first precision floating-point number is greater than the precision of the second precision floating-point number; Using an arithmetic logic unit ALU corresponding to the second precision floating-point number, processing the second precision floating-point number to obtain a processing result corresponding to the second precision floating-point number; Determine the initial value of Newton iteration according to the processing result, call the local integer arithmetic logic unit ALU to simulate Newton iteration method to determine the square root or the reciprocal of the square root of the first precision floating point number; wherein the initial value of Newton iteration includes at least: the mantissa of the square root of the second precision floating point number, the product of the integer value corresponding to the square root of the second precision floating point number and the second value; wherein the second value is the result of exponentiation with 2 as the base and half of the second exponent as the exponent; the integer value corresponding to the second precision floating point number is the product of the mantissa of the second precision floating point number and a fourth value, and the fourth value is the result of exponentiation with 2 as the base and the exponent of the second precision floating point number as the exponent.

2. The method according to claim 1, wherein the processing of the second precision floating point number by using an arithmetic logic unit ALU corresponding to the second precision floating point number to obtain a processing result corresponding to the second precision floating point number comprises: Using a square root arithmetic logic unit ALU corresponding to the second precision floating point number, the second precision floating point number is processed to obtain a square root of the second precision floating point number; The method of determining the initial value of the Newton iteration according to the processing result, and calling the local integer arithmetic logic unit ALU to simulate the Newton iteration method to determine the square root or the inverse square root of the first precision floating point number includes: The initial value of Newton iteration is determined according to the square root of the second precision floating point number, and the local integer arithmetic logic unit ALU is called to simulate the Newton iteration method to determine the square root of the first precision floating point number.

3. The method according to claim 2, further comprising: The hardware accelerator processes the square root of the first precision floating point number using an integer division arithmetic logic unit ALU to obtain the inverse square root of the first precision floating point number.

4. The method according to claim 2, wherein determining the Newton iteration initial value according to the square root of the second precision floating point number, and calling a local integer arithmetic logic unit ALU to simulate the Newton iteration method to determine the square root of the first precision floating point number, comprises: The mantissa of the square root of the second precision floating point number is used as the initial value of the iteration; The following steps are executed repeatedly until the preset stop condition is reached: Determine the quotient of the mantissa of the first precision floating point number and the current iteration value, and update the iteration value to the average value of the quotient and the current iteration value; After the loop ends, the product of the current iteration value, the first value and the second value is used as the square root of the first precision floating-point number; wherein the first value is the result of the power raised to the exponent of the square root of the second precision floating-point number with a base of 2, and the second value is the result of the power raised to the exponent of half of the second exponent with a base of 2.

5. The method according to claim 4, wherein determining the quotient of the mantissa of the first precision floating point number and the current iteration value comprises: Determine the quotient of the first precision floating point number mantissa and the current iteration value using the integer division ALU; The updating of the iteration value to an average value of the quotient and the current iteration value includes: An integer addition ALU is used to determine the sum of the quotient and the current iteration value, and an integer division ALU or a shift ALU is used to process the sum to obtain an average value of the quotient and the current iteration value.

6. The method according to claim 2, wherein determining the Newton iteration initial value according to the square root of the second precision floating point number, and calling a local integer arithmetic logic unit ALU to simulate the Newton iteration method to determine the square root of the first precision floating point number comprises: The product of the integer value corresponding to the square root of the second precision floating-point number and the second value is used as the iteration initial value; wherein the second value is the result of raising the second value to a power of 2 with half of the second exponent as the exponent; the integer value corresponding to the second precision floating-point number is the product of the mantissa of the second precision floating-point number and a fourth value, wherein the fourth value is the result of raising the second value to a power of 2 with the exponent of the second precision floating-point number as the exponent; The following steps are executed repeatedly until the preset stop condition is reached: Determine the quotient of the integer value corresponding to the first precision floating-point number and the current iteration value, and update the iteration value to the average of the quotient and the current iteration value; the integer value corresponding to the first precision floating-point number is the product of the mantissa of the first precision floating-point number and a third value, and the third value is a power result with 2 as the base and the exponent of the first precision floating-point number as the exponent; After the loop ends, the current iteration value is taken as the square root of the first-precision floating-point number.

7. A floating point number processing device, comprising: Includes central processing unit and hardware accelerator; The central processing unit is configured to obtain a first precision floating point number, determine the precision of the first precision floating point number, generate a processing instruction based on the precision, and send the processing instruction to the hardware accelerator; Hardware accelerators for executing, based on received processing instructions: The mantissa of the first precision floating-point number is intercepted to obtain a first mantissa that meets the mantissa bit width requirement of the second precision floating-point number; the exponent of the first precision floating-point number is split into a first exponent and a second exponent, and the first exponent is added; wherein the first exponent meets the exponent range requirement of the second precision floating-point number, and the second exponent is an even number; the precision of the first precision floating-point number is greater than the precision of the second precision floating-point number; Using an arithmetic logic unit ALU corresponding to the second precision floating-point number, processing the second precision floating-point number to obtain a processing result corresponding to the second precision floating-point number; Determine the initial value of Newton iteration according to the processing result, call the local integer arithmetic logic unit ALU to simulate Newton iteration method to determine the square root or the reciprocal of the square root of the first precision floating point number; wherein the initial value of Newton iteration includes at least: the mantissa of the square root of the second precision floating point number, the product of the integer value corresponding to the square root of the second precision floating point number and the second value; wherein the second value is the result of exponentiation with 2 as the base and half of the second exponent as the exponent; the integer value corresponding to the second precision floating point number is the product of the mantissa of the second precision floating point number and a fourth value, and the fourth value is the result of exponentiation with 2 as the base and the exponent of the second precision floating point number as the exponent.

8. The device according to claim 7, The hardware accelerator is specifically used to process the second precision floating point number by using a square root arithmetic logic unit ALU corresponding to the second precision floating point number to obtain the square root of the second precision floating point number; The initial value of Newton iteration is determined according to the square root of the second precision floating point number, and the local integer arithmetic logic unit ALU is called to simulate the Newton iteration method to determine the square root of the first precision floating point number.

9. The device according to claim 8, The hardware accelerator is further used to process the square root of the first precision floating point number using an integer division arithmetic logic unit ALU to obtain the inverse square root of the first precision floating point number.

10. The device according to claim 8, The hardware accelerator is specifically configured to use the mantissa of the square root of the second precision floating point number as an iteration initial value; The following steps are executed repeatedly until the preset stop condition is reached: Determine the quotient of the mantissa of the first precision floating point number and the current iteration value, and update the iteration value to the average value of the quotient and the current iteration value; After the loop ends, the product of the current iteration value, the first value, and the second value is used as the square root of the first precision floating point number; wherein, The first value is a result of raising the square root of the second precision floating point number to a power of 2, and the second value is a result of raising the square root of the second precision floating point number to a power of 2, and the second value is a result of raising the square root of the second precision floating point number to a power of half of the second precision floating point number.

11. The device according to claim 10, The hardware accelerator is specifically used to use an integer division ALU to determine the quotient of a first precision floating point number and a current iteration value; use an integer addition ALU to determine the sum of the quotient and the current iteration value, and use an integer division ALU or a shift ALU to process the sum to obtain an average value of the quotient and the current iteration value.

12. The device according to claim 8, The hardware accelerator is specifically used to use the product of the integer value corresponding to the square root of the second precision floating point number and the second value as the iteration initial value; wherein, The second value is the result of raising the base 2 to the power of half the second exponent; The integer value corresponding to the second precision floating-point number is the product of the mantissa of the second precision floating-point number and a fourth value, where the fourth value is a power result with 2 as the base and the exponent of the second precision floating-point number as the exponent; The following steps are executed repeatedly until the preset stop condition is reached: Determine the quotient of the integer value corresponding to the first precision floating-point number and the current iteration value, and update the iteration value to the average of the quotient and the current iteration value; the integer value corresponding to the first precision floating-point number is the product of the mantissa of the first precision floating-point number and a third value, and the third value is a power result with 2 as the base and the exponent of the first precision floating-point number as the exponent; After the loop ends, the current iteration value is taken as the square root of the first-precision floating-point number.

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

14. A hardware accelerator, comprising: A memory, used to store processing instructions sent by the central processing unit; A controller that reads processing instructions from memory to execute: The mantissa of the first precision floating-point number is intercepted to obtain a first mantissa that meets the mantissa bit width requirement of the second precision floating-point number; the exponent of the first precision floating-point number is split into a first exponent and a second exponent, and the first exponent is added; wherein the first exponent meets the exponent range requirement of the second precision floating-point number, and the second exponent is an even number; the precision of the first precision floating-point number is greater than the precision of the second precision floating-point number; Using a square root arithmetic logic unit ALU corresponding to the second precision floating point number, the second precision floating point number is processed to obtain a square root of the second precision floating point number; Determine the initial value of Newton iteration according to the square root of the second precision floating-point number, and call the local integer arithmetic logic unit ALU to simulate the Newton iteration method to determine the square root of the first precision floating-point number; wherein the initial value of Newton iteration includes at least: the mantissa of the square root of the second precision floating-point number, the product of the integer value corresponding to the square root of the second precision floating-point number and the second value; wherein the second value is a power result with 2 as the base and half of the second exponent as the exponent; the integer value corresponding to the second precision floating-point number is the product of the mantissa of the second precision floating-point number and a fourth value, and the fourth value is a power result with 2 as the base and the exponent of the second precision floating-point number as the exponent.

15. A central processing unit, comprising: A memory for storing a processing program; The controller is used to read the processing program to execute: obtaining a first precision floating-point number, determining the precision of the first precision floating-point number, generating a processing instruction based on the precision, and sending the processing instruction to a hardware accelerator, so that the hardware accelerator intercepts the mantissa of the first precision floating-point number to obtain a first mantissa that meets the mantissa bit width requirement of the second precision floating-point number; splitting the exponent of the first precision floating-point number into a first exponent and a second exponent, wherein the first exponent meets the exponent range requirement of the second precision floating-point number, and the second exponent is an even number; the precision of the first precision floating-point number is greater than the precision of the second precision floating-point number; using a square root arithmetic logic unit ALU corresponding to the second precision floating-point number to perform square root calculation on the second precision floating-point number; The method comprises the following steps: processing the floating-point number to obtain the square root of the second-precision floating-point number, determining the initial value of Newton iteration according to the square root of the second-precision floating-point number, and calling the local integer arithmetic logic unit ALU to simulate the Newton iteration method to determine the square root of the first-precision floating-point number; wherein the initial value of Newton iteration includes at least: the mantissa of the square root of the second-precision floating-point number, the product of the integer value corresponding to the square root of the second-precision floating-point number and the second value; wherein the second value is a power result with 2 as the base and half of the second exponent as the exponent; the integer value corresponding to the second-precision floating-point number is the product of the mantissa of the second-precision floating-point number and a fourth value, and the fourth value is a power result with 2 as the base and the exponent of the second-precision floating-point number as the exponent.