Method and device for executing program code, computing equipment and storage medium

By replacing the high-precision calculation code in the program code to call the calculation function in the function library, the problem of manual modification of the code is solved to reduce the calculation accuracy and low efficiency, and the calculation accuracy is achieved automatically, which improves the modification efficiency and reduces the probability of errors.

CN119718325AActive Publication Date: 2025-03-28HUAWEI TECH CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202311286793.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-09-28
Publication Date
2025-03-28
Estimated Expiration
2043-09-28

AI Technical Summary

Technical Problem

In the prior art, reducing the calculation accuracy requires technicians to manually modify the program code, which is inefficient and prone to errors.

Method used

By obtaining the program code, determining the code that performs high-precision calculations, and replacing them with calling the calculation functions in the function library, the reduction of high-precision calculations is achieved.

Benefits of technology

It can reduce calculation accuracy, improve modification efficiency, reduce error probability, and support the accuracy of custom floating point numbers without manually modifying the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718325A_ABST
    Figure CN119718325A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a program code execution method and device, computing equipment and a storage medium, and the method comprises the steps: obtaining a first program code, and determining a code for executing first precision calculation in the first program code; a calculation function used for converting the first precision calculation into second precision calculation and executing the second precision calculation in the function library is determined, and the first precision corresponding to the calculation variable of the first precision calculation is higher than the second precision corresponding to the calculation variable of the second precision calculation. And replacing the code for executing the first precision calculation in the first program code with the code for calling the calculation function to obtain a second program code. And executing the second program code to obtain an execution result of the second program code. By adopting the application, the code of the first precision calculation included in the program code can be automatically identified, and the first precision calculation is reduced to the second precision calculation by calling the calculation function, so that the efficiency of modifying the calculation precision of the program code can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, apparatus, computing device and storage medium for executing program code. Background Art

[0002] With the end of Moore's Law, the traditional technical route of improving computing performance by relying on process improvements is no longer applicable. Currently, reducing computing precision has become one of the technical routes to improve computing performance.

[0003] In the related art, reducing the calculation accuracy requires technicians to manually modify the calculation accuracy in the program code, which requires a large amount of modification and is prone to errors. Summary of the invention

[0004] The embodiments of the present application provide a method, apparatus, computing device, and storage medium for executing program code, which can improve the efficiency of modifying the calculation accuracy of program code. The corresponding technical solutions are as follows:

[0005] In a first aspect, a method for executing a program code is provided, which can be executed by a computing device, the method comprising: obtaining a first program code, and determining a code in the first program code that performs a first precision calculation. Determining a calculation function in a function library that is used to convert a first precision calculation into a second precision calculation and perform the second precision calculation, wherein a first precision corresponding to a calculation variable of the first precision calculation is higher than a second precision corresponding to a calculation variable of the second precision calculation. Replacing the code in the first program code that performs the first precision calculation with a code that calls the calculation function to obtain a second program code. Executing the second program code to obtain an execution result of the second program code.

[0006] In the scheme shown in the present application, before executing the first program code, the code for executing the first precision calculation in the first program code can be determined, and then the code for executing the first precision calculation is replaced by the code for calling the calculation function to obtain the second program code. Since the called calculation function is a function in the function library that reduces the first precision calculation to the second precision calculation, the second program code is the first program code after reducing the calculation accuracy. Therefore, by adopting the scheme provided by the present application, the calculation accuracy of the program code can be reduced without the need for the technician to manually modify the program code, thereby improving the efficiency of modifying the program code and reducing the error probability of modifying the program code.

[0007] In one achievable manner, the above-mentioned conversion of the first precision calculation into the second precision calculation and execution of the second precision calculation includes: converting the calculation variables of the first precision in the first precision calculation into the calculation variables of the second precision. Executing the calculation of the same calculation category as the first precision calculation on the calculation variables of the second precision. In this way, the calculation function can reduce the calculation accuracy of the program code by reducing the accuracy of the calculation variables, and then executing the calculation of the same calculation category as before the accuracy reduction on the calculation variables, which can avoid the technicians from manually modifying the program code.

[0008] In one achievable manner, the calculation function is further used to convert the calculation result corresponding to the second precision calculation from the second precision to the first precision. In this way, the precision of the calculation variable in the calculation process is reduced without reducing the precision of the calculation result, which can avoid the adaptive modification of other program codes that apply the calculation result and reduce the modification amount of the program code.

[0009] In one achievable manner, the above-mentioned determination of the code for executing the first precision calculation in the first program code includes: determining the first function specified by the user. Identifying the code for executing the first precision calculation included in the first function in the first program code, or identifying the code for executing the first precision calculation included in the first function and the second function called by the first function in the first program code. In this way, the solution provided by the present application can reduce the calculation precision corresponding to the specified function or the specified program area, and can improve the flexibility of reducing the calculation precision of the first program code.

[0010] In an achievable manner, the above-mentioned identification of the code for executing the first precision calculation included in the first function and the second function called by the first function in the first program code includes: if there is a third function that calls the second function and the third function is not called by the first function, then a clone function corresponding to the second function is established, and the clone function has the same content as the second function but a different function name. The code for calling the second function in the first function is modified to be a code for calling the clone function, and the code for executing the first precision calculation in the first function and the clone function is identified.

[0011] In the scheme shown in the present application, by establishing a clone function corresponding to the second function, the code of the first function calling the second function is modified to call the clone function, and then the calculation accuracy in the clone function is reduced. This can avoid modifying the execution code corresponding to the first precision calculation, affecting the execution of other functions that have not reduced the calculation accuracy, and can improve the stability of program code execution.

[0012] In an implementable manner, the calculation variable is a floating point number, and converting the calculation variable of the first precision in the first precision calculation into the calculation variable of the second precision includes: obtaining a first digit X corresponding to the exponent bit and a second digit Y corresponding to the mantissa bit in the floating point number of the second precision specified by the user. Based on X, the exponent bit of the calculation variable of the second precision is determined, and based on Y, the mantissa bit of the calculation variable of the second precision is determined.

[0013] In the solution provided by the present application, the user can specify the first digit of the exponent bit and the second digit of the mantissa bit corresponding to the second precision floating-point number. Since the numerical precisions corresponding to the exponent bits and mantissa bits of different digits are different, the solution shown in the present application can realize the second precision of the custom floating-point number. The precision of the custom floating-point number can provide a finer-grained calculation precision, and then the second precision that can meet the calculation precision requirements and improve the calculation efficiency can be determined at the finer-grained calculation precision.

[0014] In an implementable manner, based on X, determining the exponent bits of the computational variable of the second precision includes: if the value represented by the exponent bits of the computational variable of the first precision is within the range of values ​​that can be represented by the exponent bits of the X bits, then determining the value represented by the exponent bits of the computational variable of the first precision as the value represented by the exponent bits of the computational variable of the second precision. If the value represented by the exponent bits of the computational variable of the first precision is greater than the maximum value that can be represented by the exponent bits of the X bits, then determining the maximum value that can be represented by the exponent bits of the X bits as the value represented by the exponent bits of the computational variable of the second precision. If the value represented by the exponent bits of the computational variable of the first precision is less than the minimum value that can be represented by the exponent bits of the X bits, then determining the minimum value that can be represented by the exponent bits of the X bits as the value represented by the exponent bits of the computational variable of the first precision.

[0015] In the solution provided by the present application, after determining the first digit X corresponding to the exponent bit of the second precision, the exponent bit of the calculation variable of the second precision can be determined according to whether the value represented by the exponent bit of the calculation variable of the first precision is within the numerical range that the exponent bit of the X bit can represent. If it is not within the corresponding numerical range, the exponent bit of the calculation variable of the second precision can be determined according to the maximum value or the minimum value that the exponent bit of the X bit can represent, thereby reducing the numerical error caused by the calculation precision.

[0016] In an implementable manner, based on Y, determining the mantissa of the calculation variable of the second precision includes: if the value represented by the mantissa of the calculation variable of the first precision is within the range of values ​​that can be represented by the mantissa of the Y position, then determining the value represented by the mantissa of the calculation variable of the first precision as the value represented by the mantissa of the calculation variable of the second precision. If the value represented by the mantissa of the calculation variable of the first precision is greater than the maximum value that can be represented by the mantissa of the Y position, then determining the maximum value that can be represented by the mantissa of the Y position as the value represented by the mantissa of the calculation variable of the second precision. If the value represented by the mantissa of the calculation variable of the first precision is less than the minimum value that can be represented by the mantissa of the Y position, then determining the minimum value that can be represented by the mantissa of the Y position as the value represented by the mantissa of the calculation variable of the second precision.

[0017] In the solution provided by the present application, after determining the second digit Y corresponding to the mantissa of the calculation variable of the second precision, the mantissa of the calculation variable of the second precision can be determined according to whether the value represented by the mantissa of the calculation variable of the first precision is within the numerical range that the mantissa of the Y position can represent. If it is not within the corresponding numerical range, the mantissa of the calculation variable of the second precision can be determined according to the maximum value or the minimum value that the mantissa of the Y position can represent, thereby reducing the numerical error caused by the calculation accuracy.

[0018] In a second aspect, a device for executing program code is provided, the device comprising:

[0019] The acquisition module is used to acquire the first program code.

[0020] A determination module is used to determine the code in the first program code that executes the first precision calculation; determine the calculation function in the function library that is used to convert the first precision calculation into the second precision calculation and execute the second precision calculation, wherein the first precision corresponding to the calculation variable of the first precision calculation is higher than the second precision corresponding to the calculation variable of the second precision calculation.

[0021] The replacement module is used to replace the code for executing the first precision calculation in the first program code with the code for calling the calculation function to obtain the second program code.

[0022] The execution module is used to execute the second program code and obtain the execution result of the second program code.

[0023] In one achievable manner, the determination module is used to: convert calculation variables of first precision in first precision calculation into calculation variables of second precision; and perform calculations of the same calculation category as the first precision calculation on the calculation variables of the second precision.

[0024] In one implementable manner, the calculation function is further used to convert a calculation result corresponding to the second precision calculation from the second precision to the first precision.

[0025] In one achievable manner, the determination module is used to: determine a first function specified by a user, identify a code included in the first function in a first program code that performs a first precision calculation, or identify a code included in the first function and a second function called by the first function in the first program code that performs a first precision calculation.

[0026] In one achievable manner, the determining module is used to: if there is a third function that calls the second function and the third function is not called by the first function, then establish a clone function corresponding to the second function, the clone function having the same content as the second function but a different function name. Modify the code in the first function for calling the second function to the code for calling the clone function. Identify the code in the first function and the clone function that performs the first precision calculation.

[0027] In an implementable manner, the determination module is used to: obtain a first digit X corresponding to the exponent bit and a second digit Y corresponding to the mantissa bit in the second precision floating point number specified by the user. Based on X, the exponent bit of the calculation variable of the second precision is determined, and based on Y, the mantissa bit of the calculation variable of the second precision is determined.

[0028] In an implementable manner, the determination module is used to: if the value represented by the exponent bit of the calculation variable of the first precision is within the range of values ​​that can be represented by the exponent bit of the X bit, then the value represented by the exponent bit of the calculation variable of the first precision is determined as the value represented by the exponent bit of the calculation variable of the second precision. If the value represented by the exponent bit of the calculation variable of the first precision is greater than the maximum value that can be represented by the exponent bit of the X bit, then the maximum value that can be represented by the exponent bit of the X bit is determined as the value represented by the exponent bit of the calculation variable of the second precision. If the value represented by the exponent bit of the calculation variable of the first precision is less than the minimum value that can be represented by the exponent bit of the X bit, then the minimum value that can be represented by the exponent bit of the X bit is determined as the value represented by the exponent bit of the calculation variable of the first precision.

[0029] In an implementable manner, the determination module is used to: if the value represented by the mantissa of the calculation variable of the first precision is within the range of values ​​that can be represented by the mantissa of the Y position, then the value represented by the mantissa of the calculation variable of the first precision is determined as the value represented by the mantissa of the calculation variable of the second precision. If the value represented by the mantissa of the calculation variable of the first precision is greater than the maximum value that can be represented by the mantissa of the Y position, then the maximum value that can be represented by the mantissa of the Y position is determined as the value represented by the mantissa of the calculation variable of the second precision. If the value represented by the mantissa of the calculation variable of the first precision is less than the minimum value that can be represented by the mantissa of the Y position, then the minimum value that can be represented by the mantissa of the Y position is determined as the value represented by the mantissa of the calculation variable of the second precision.

[0030] In a third aspect, a computing device is provided, comprising a processor and a memory, wherein the processor is used to execute instructions stored in the memory so that the computing device performs a method as described in the first aspect and / or any achievable manner included in the first aspect.

[0031] According to a fourth aspect, a computer program product comprising instructions is provided. When the instructions are executed by a computing device, the computing device executes the method as described in the first aspect and / or any achievable manner included in the first aspect.

[0032] In a fifth aspect, a computer-readable storage medium is provided, comprising computer program instructions. When the computer program instructions are executed by a computing device, the computing device may execute the method as described in the first aspect and / or any achievable manner included in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] Figure 1 It is a structural diagram of a 32-bit floating point format provided in an embodiment of the present application;

[0034] Figure 2 It is a structural diagram of a computing device for executing a method for program code provided in an embodiment of the present application;

[0035] Figure 3 is a flow chart of a method for executing program code provided by an embodiment of the present application;

[0036] Figure 4 is an exemplary program call graph provided in an embodiment of the present application;

[0037] Figure 5 is an exemplary program call graph provided in an embodiment of the present application;

[0038] Figure 6 It is a schematic diagram of the structure of a custom floating-point number provided in an embodiment of the present application;

[0039] Figure 7 It is a schematic diagram of the structure of a device for executing program code provided in an embodiment of the present application. DETAILED DESCRIPTION

[0040] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0041] The following is an introduction to the professional terms or concepts that may be involved in the embodiments of the present application:

[0042] Floating point format: A way to approximate real numbers, using fixed sign bits, exponent bits, and mantissa bits to approximate a real number. For example, under the IEEE754 standard, a 32-bit real number R = (-1) sign *1.mantissa*2 exp-127 , where sign is the exponent, mantissa is the mantissa, and exp is the exponent. Figure 1 is a schematic diagram of a 32-bit floating point format provided in an embodiment of the present application, such as Figure 1 As shown, in the 32-bit floating point format data, the first 23 bits are the mantissa bits, the 24th to 31st bits are the exponent bits, and the 32nd bit is the sign bit.

[0043] Floating-point precision: Computer programs use floating-point format to represent real numbers. The representation range of the exponent bits and mantissa bits of the corresponding format is called floating-point precision.

[0044] According to the floating point precision, floating point numbers can be generally divided into double precision floating point type (FP64), single precision floating point type (FP32), half precision floating point type (FP16), etc. Among them, FP64 is also called double, with 1 sign bit, 11 exponent bits, and 52 mantissa bits. FP32 is also called float, with 1 sign bit, 8 exponent bits, and 23 mantissa bits. FP16, with 1 sign bit, 5 exponent bits, and 10 mantissa bits.

[0045] Sign bit: The bit in the floating-point format used to indicate the sign of a real number.

[0046] Exponent bits: The number of bits in a floating-point format used to represent the range of the exponent of a real number.

[0047] Mantissa bits: The number of bits used in floating-point format to represent the significant digits of a real number.

[0048] Program area: refers to the program code that starts and ends when the program is running. The program code can include one or more functions.

[0049] With the end of Moore's Law, the traditional technical route of improving computing performance by improving process is no longer applicable. Recently, reducing computing precision has become one of the technical routes to improve computing performance. Currently, there are many computing products that support low precision, which have achieved significant results in accelerated computing. For example, some GPUs can support high performance computing (HPC) general computing precision FP64, AI training commonly used precision FP32, and other various precisions FP16, BF16, FP8, INT8, etc.

[0050] High-precision calculation may refer to the floating point type of the variable to be calculated being a high-precision floating point type, such as FP64, FP32, etc. Low-precision calculation may refer to the floating point type of the variable to be calculated being a low-precision floating point type, such as FP16, INT8, etc. In the embodiment of the present application, the calculation accuracy is relative, for example, FP32 is low-precision relative to FP64, and FP32 is high-precision relative to FP16.

[0051] At present, the method of reducing calculation accuracy is mainly for technicians to modify the program code involving high-precision calculations, and modify the high-precision calculation code included in the program code to a low-precision calculation code. For example, the addition calculation code of double-precision floating-point numbers is modified to the addition calculation code of single-precision floating-point numbers. However, the code volume of general HPC calculation programs and AI programs is huge, and the reference relationship between functions is complex. Manual modification of program code is inefficient and prone to errors.

[0052] Table 1 below is a schematic diagram of an exemplary modification of the calculation accuracy in the program code provided in an embodiment of the present application:

[0053] Table 1

[0054]

[0055] As can be seen from Table 1, the calculation precision in functions funcC and funcB is modified in the modified code by forcibly converting the variable "x" from double type to float type.

[0056] Modifying the calculation accuracy can improve the execution efficiency of the program code, but it will also lead to an increase in the calculation error. It is possible that the calculation result after modifying the calculation accuracy cannot meet the calculation requirements. For example, after reducing the calculation accuracy of the training AI model, the accuracy of the AI ​​model may not reach the required accuracy threshold. Therefore, technicians may need to successively reduce the high-precision calculations in the program code to calculations of different precisions, and determine the final calculation accuracy based on whether the results corresponding to the calculations of each precision meet the calculation requirements. This requires technicians to repeatedly modify the calculation accuracy in the program code, resulting in lower modification efficiency and a higher probability of modification errors.

[0057] An embodiment of the present application provides a method for executing program code, which can automatically identify high-precision calculation codes included in the program code and replace the high-precision calculation codes with low-precision calculation codes, thereby improving the efficiency of modifying the calculation accuracy of the program code. Figure 2 Schematic diagram of the structure of a computing device for executing a program code provided in an embodiment of the present application. Figure 2 As shown, the computing device 200 may include: a bus 202, a processor 204, a memory 206, and the optional computing device 200 may also include a communication interface 208. The processor 204, the memory 206 and the communication interface 208 communicate through the bus 202. The computing device 200 may be a server or a terminal device. It should be understood that the present application does not limit the number of processors and memories in the computing device 200. The computing device 200 may be a device for running a model, a terminal or a server. When the computing device 200 is a terminal, the computing device 200 includes but is not limited to a desktop computer, a mobile phone, a notebook, a tablet computer, etc. When the computing device 200 is a server, the computing device 200 may be a separate server, or a server cluster composed of multiple servers, or may be a physical machine, or may be a virtual machine, a container, etc. virtualized by virtual technology.

[0058] The bus 202 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 2 The bus 202 is represented by only one line, but it does not mean that there is only one bus or one type of bus. The bus 202 may include a path for transmitting information between various components of the computing device 200 (eg, the memory 206, the processor 204, and the communication interface 208).

[0059] The processor 204 may include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP). The processor 204 may further include a computing unit that supports different precision calculations.

[0060] The memory 206 may include a volatile memory, such as a random access memory (RAM). The memory 206 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD) or a solid state drive (SSD). The above memories may all be referred to as global memories. The memory 206 stores executable instructions, and the processor 204 can implement a method for executing program code provided in an embodiment of the present application by executing the instructions stored in the memory 206.

[0061] The communication interface 208 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the computing device 200 and other devices or a communication network.

[0062] Figure 3 is a flow chart of a method for executing program code provided by an embodiment of the present application. The method for executing program code can be performed by the above Figure 2 The computing device shown executes, Figure 3 As shown, the method includes:

[0063] Step 301: Obtain a first program code.

[0064] The first program code may be any program code that needs to reduce the calculation accuracy, for example, it may be an HPC calculation code, an AI model operation, training code, etc. The first program code may include calculations of one accuracy or calculations of multiple accuracy.

[0065] In one example, steps 301 to 305 provided in an embodiment of the present application may be set as a plug-in added to a program compiler. The first program code obtained in step 301 may be a program to be compiled in a program compiler. The plug-in may provide a configuration function, and the user may specify the first precision calculation that needs to be reduced in the first program code in the configuration function, for example, specifying the type of the calculation variable in the first precision calculation in the configuration function, such as double type, float type, or INT8 type, etc. In addition, the user may also specify the type of the calculation variable after reducing the precision in the configuration function.

[0066] Step 302: Determine the code in the first program code that performs the first precision calculation.

[0067] In implementation, the code for executing the first precision calculation in the first program code can be identified based on the first precision of the calculation variables in the first precision calculation. The code for executing the first precision calculation includes calculation variables and result variables, as well as symbols for performing calculation operations on the result variables, such as "+", "-", "*", etc. The calculation variables included in the code for executing the first precision calculation belong to the calculation variables of the first precision. The calculation category corresponding to executing the first precision calculation is the calculation category to which the calculation operation performed on the calculation variables in the code for executing the first precision calculation belongs, such as addition, subtraction or multiplication, etc.

[0068] In one example, the calculation variables belonging to the first precision can be determined in the source code of the first program code, and then the calculation code involved in the calculation variables (i.e., the code for performing the first precision calculation) can be determined, and the calculation variables, result variables, and corresponding calculation categories included in the code for performing the first precision calculation can also be determined. For example, in the function funcC shown in Table 1 above, the calculation variables of "x=x*y" are x and y, the result variable is x, and the calculation category is multiplication. In another example, the compiler can first compile the first program code to obtain the intermediate representation code corresponding to the first program code. In the intermediate representation code, each line of calculation code can include an identifier of the corresponding calculation category, and the code for performing the first precision calculation can be identified in the intermediate representation code based on the identifier. Among them, multiple lines of code for performing the first precision calculation can be identified in the first program code, and each line of code for performing the first precision calculation can correspond to a calculation category.

[0069] Step 303: determine a calculation function in the function library for converting a first precision calculation into a second precision calculation and performing the second precision calculation, wherein a first precision corresponding to a calculation variable of the first precision calculation is higher than a second precision corresponding to a calculation variable of the second precision calculation.

[0070] In implementation, calculation functions that convert various high-precision calculations into low-precision calculations can be added to the function library. In addition, in the function library, there can also be multiple calculation functions corresponding to the same high-precision calculation, and the multiple calculation functions respectively correspond to the same high-precision calculation converted into different low-precision calculations. In one example, the function name corresponding to the calculation function that converts the first-precision calculation into the second-precision calculation in the function library can be determined based on the calculation category corresponding to the first-precision calculation and the first precision of the calculation variable. For example, the correspondence between the calculation category, precision and each function name in the function library can be set, and then the calculation category and the function name corresponding to the first precision can be found in the correspondence.

[0071] Step 304: Replace the code for executing the first precision calculation in the first program code with the code for calling the calculation function to obtain the second program code.

[0072] After determining the function name of the calculation function, a calling code for calling the calculation function can be generated according to the function name and the variable names corresponding to the calculation variables and the result variables in the first precision calculation, and then the code for calling the calculation function can be generated. For example, the code for calling the calculation function can be generated according to the structure of "result variable = function name (calculation variable, calculation variable)".

[0073] In one example, the function library may include:

[0074] Addition operation:

[0075] doubledoubleadd(double x,double y);

[0076] float floatadd(float x, float y);

[0077] Subtraction operation:

[0078] doubledoublesub(double x,double y);

[0079] float floatsub(float x, float y);

[0080] Multiplication operation:

[0081] doubledoublemul(double x,double y);

[0082] float floatmul(float x,double y).

[0083] Among them, doubleadd is a function used to convert double-precision addition into other low-precision additions, and floatadd is a function used to convert single-precision addition into other low-precision additions. doublesub is a function used to convert double-precision subtraction into other low-precision subtractions, and floatsub is a function used to convert single-precision subtraction into other low-precision subtractions. doublemul is a function used to convert double-precision multiplication into other low-precision multiplications, and floatmul is a function used to convert single-precision multiplication into other low-precision multiplications.

[0084] Take the code for performing the first precision calculation in the source code as "A=B*C" as an example, where the variables "A", "B" and "C" are double type variables respectively. If the code for performing the first precision calculation in the source code is replaced, the code for calling the calculation function can be "A=doublemul(B, C)". If the code for performing the first precision calculation in the middle layer code corresponding to the source code is replaced, the code for performing the first precision calculation can be "%8=fmul double%7,%6", and the code for calling the calculation function can be "%8=call double@doublemul(%7,%6)".

[0085] The calculation function can be used to convert the calculation variable corresponding to the first precision calculation from the first precision to the second precision, and then perform the calculation operation of the same calculation category as the first precision calculation on the calculation variable of the second precision. The second precision of the conversion can be specified in advance by the user in the configuration function, for example, it can be FP16, IN8, etc.

[0086] After obtaining the code for calling the calculation function corresponding to each line of code for executing the first precision calculation in the first program code, the code for executing the first precision calculation can be replaced with the corresponding code for calling the calculation function to obtain the second program code.

[0087] Step 305: execute the second program code to obtain an execution result of the second program code.

[0088] After obtaining the second program code, the program compiler can execute the second program code. When the code for the original first precision calculation is executed, since the code for the first precision calculation is replaced by the code for calling the calculation function, the first precision calculation that needs to be executed can be converted into the second precision calculation through the calculation function, thereby reducing the calculation accuracy to improve the execution efficiency of the code. In one example, after obtaining the execution result corresponding to the second program code, it can be determined whether the execution result after reducing the calculation accuracy meets the calculation requirements. If the calculation requirements are not met, the second precision can be adjusted, and then the above steps 301-305 are executed again, thereby obtaining a calculation accuracy that can meet the calculation requirements and improve the calculation efficiency.

[0089] In an embodiment of the present application, before executing the first program code, it is possible to determine the code for executing the first precision calculation in the first program code, and then replace the code for executing the first precision calculation with the code for calling the calculation function to obtain the second program code. Since the calculation function called is a function in the function library that reduces the first precision calculation to the second precision calculation, the second program code is the first program code after reducing the calculation accuracy. Therefore, the scheme provided by the present application is adopted, and the calculation accuracy of the program code can be reduced without the need for the technician to manually modify the program code, thereby improving the modification efficiency of the program code and reducing the error probability of modifying the program code.

[0090] In the embodiment of the present application, a configuration function is also provided, which can be the configuration function in the above steps 301-305. In the configuration function, the user also specifies the program range in the first program code that needs to reduce the calculation accuracy and the format of the floating point number of the second precision. The following is an exemplary example of the configuration function:

[0091]

[0092] Among them, entry_func represents the entry function for high-precision calculation code identification. type indicates whether only the entry function is replaced with low-precision calculation or the program area corresponding to the entry function is replaced with low-precision calculation. For example, when type=0, it indicates that only the entry function is replaced with low-precision calculation. When type=1, it indicates that the program area corresponding to the entry function is replaced with low-precision calculation. double_exp specifies the first digit of the corresponding floating-point exponent after the high-precision calculation of double type is converted to low-precision calculation. double_mantissa indicates the second digit of the corresponding floating-point mantissa after the high-precision calculation of double type is converted to low-precision calculation. Similarly, the relevant configuration items of float_exp and float_mantissa are similar.

[0093] The following is an introduction to a method for specifying a range in which the calculation accuracy needs to be reduced in the first program code provided in an embodiment of the present application:

[0094] In implementation, the function name of the entry function specified by the user in the configuration function can be obtained, and the entry function can be called the first function. After determining the function name of the first function, the function name of the first function can be searched in the first program code. After finding the function name of the first function, the first function can be used as the starting point for reducing the calculation accuracy, and then the code included in the first program code for performing the first precision calculation can be determined. If the user only specifies to replace the high-precision calculation in the first function in the configuration function, only the code included in the first function for performing the first precision calculation can be determined. If the user specifies to replace the high-precision calculation in the program area corresponding to the first function in the configuration function, the code included in the program area corresponding to the first function for performing the first precision calculation can be determined. Among them, the first function can be a function in the first program code with a large amount of calculation and / or a low requirement for the corresponding calculation accuracy. In this way, only the calculation accuracy of the first function or the program area corresponding to the first function is reduced, which can improve the execution efficiency of the program code without affecting the overall calculation accuracy of the program code.

[0095] In one example, the program area corresponding to the first function may be determined according to a program call graph corresponding to the first program code. Figure 4 is an exemplary program call graph provided in the embodiment of the present application. Figure 4 It can be seen that function funcA directly calls functions funcB and funcC, and indirectly calls funcD, funcE and funcF through funcB and funcC. A function directly or indirectly called by the first function can be called a second function, and the first function and the second function constitute the program area corresponding to the first function.

[0096] In another example, when a high-precision calculation in a program area corresponding to a first function is replaced, if there is a third function that calls a second function and the third function is not called by the first function, a clone function corresponding to the second function is established, and the clone function has the same content as the second function but a different function name. The code in the first function for calling the second function is modified to be a code for calling the clone function.

[0097] In the program code, a function can call multiple other functions, and can also be called by multiple other functions. Figure 4It can be seen that funcE is called by both funcC and funcB. When funcC is determined to be the first function and the high-precision calculation in the program area corresponding to the first function needs to be replaced, the program area corresponding to the first function includes funcC, funcE and funcF. However, since funcE is also in the program area corresponding to funcB, directly replacing the code of the first precision calculation in funcE may affect the program area corresponding to funcB. Therefore, in an embodiment of the present application, when the high-precision calculation in the program area corresponding to the first function needs to be replaced, it can be determined whether the second function in the program area is also called by the third function of other program areas. If the existing second function is still called by the third function of other program areas, a clone function corresponding to the second function can be established. That is, the second function is copied in the first program code, and the function name of the second function after the copy is modified to obtain the clone function corresponding to the second function. After the clone function corresponding to the second function is established, the code of the first function directly or indirectly referencing the second function can be modified to the code of the clone function corresponding to the second function. That is, the function name corresponding to the second function in the code directly or indirectly referencing the second function of the first function is modified to the function name of the clone function.

[0098] Figure 5 It is an exemplary program call graph provided in an embodiment of the present application. Figure 5 Yes Figure 4 The function call graph is obtained by cloning funcE in . Among them, funcE_clone is the clone function corresponding to funcE. Figure 5 It can be seen that the program area corresponding to funcC includes funcC, funcF and funcE_clone. In this way, replacing the high-precision calculation in the program area corresponding to funcC will not affect the execution of other program areas, so the stability of the execution program can be improved.

[0099] The following is an introduction to the format of a custom low-precision floating-point number provided in an embodiment of the present application:

[0100] In implementation, the first digit X corresponding to the exponent bit and the second digit Y corresponding to the mantissa bit in the second precision floating-point number specified by the user in the configuration function can be obtained, wherein X is less than the number of digits of the exponent bit of the calculation variable of the first precision, and Y is less than the number of digits of the mantissa bit of the calculation variable of the first precision.

[0101] Based on X, the exponent bits of the second precision calculation variable can be determined, including:

[0102] 1. If the value represented by the exponent bit of the computational variable of the first precision is within the range of values ​​that can be represented by the exponent bit of the X bit, the value represented by the exponent bit of the computational variable of the first precision is determined as the value represented by the exponent bit of the computational variable of the second precision.

[0103] If the value represented by the exponent of the computational variable of the first precision is within the range of values ​​that can be represented by the exponent of the X-bit, the value represented by the exponent of the computational variable of the first precision can be converted to be represented by the exponent of the X-bit, and the converted exponent is the exponent of the computational variable of the second precision. The conversion of the value represented by the exponent of the computational variable of the first precision to be represented by the exponent of the X-bit belongs to the prior art and will not be described in detail in the implementation of this application.

[0104] 2. If the value represented by the exponent of the computation variable of the first precision is greater than the maximum value that can be represented by the exponent of the X bits, the maximum value that can be represented by the exponent of the X bits is determined as the value represented by the exponent of the computation variable of the second precision.

[0105] If the value represented by the exponent of the first precision is greater than the maximum value that can be represented by the exponent of the X-bit, it means that the value represented by the exponent of the calculation variable of the first precision is no longer within the range of values ​​that can be represented by the exponent of the X-bit, and exceeds the maximum value that can be represented by the exponent of the X-bit. Therefore, the maximum value represented by the exponent of the X-bit can be determined as the exponent of the calculation variable of the second precision. This can reduce the error caused by the conversion of the precision of the floating point number to a certain extent.

[0106] 3. If the value represented by the exponent of the computation variable of the first precision is smaller than the minimum value that can be represented by the exponent of the X bits, the minimum value that can be represented by the exponent of the X bits is determined as the value represented by the exponent of the computation variable of the first precision.

[0107] If the value represented by the exponent of the first precision is less than the minimum value that can be represented by the exponent of the X-bit, it means that the value represented by the exponent of the calculation variable of the first precision is no longer within the range of values ​​that can be represented by the exponent of the X-bit, and is less than the minimum value that can be represented by the exponent of the X-bit. Therefore, the minimum value represented by the exponent of the X-bit can be determined as the exponent of the calculation variable of the second precision. This can reduce the error caused by the conversion of the precision of the floating point number to a certain extent.

[0108] Based on Y, the mantissa of the second precision calculation variable can be determined, including:

[0109] 1. If the value represented by the mantissa of the calculation variable of the first precision is within the range of values ​​that can be represented by the mantissa of the Y position, the value represented by the mantissa of the calculation variable of the first precision is determined as the value represented by the mantissa of the calculation variable of the second precision.

[0110] If the value represented by the mantissa of the calculation variable of the first precision is within the range of values ​​that can be represented by the mantissa of the Y position, the value represented by the mantissa of the calculation variable of the first precision can be converted to the mantissa represented by the Y position, and the mantissa obtained after the conversion is the mantissa of the calculation variable of the second precision. Among them, the conversion of the value represented by the mantissa of the calculation variable of the first precision to the mantissa represented by the Y position belongs to the prior art and will not be described in detail in the implementation of this application.

[0111] 2. If the value represented by the mantissa of the calculation variable of the first precision is greater than the maximum value that can be represented by the mantissa of the Y position, the maximum value that can be represented by the mantissa of the Y position is determined as the value represented by the mantissa of the calculation variable of the second precision.

[0112] If the value represented by the mantissa of the first precision is greater than the maximum value that can be represented by the mantissa of the Y position, it means that the value represented by the mantissa of the calculation variable of the first precision is no longer within the range of values ​​that can be represented by the mantissa of the Y position, and exceeds the maximum value that can be represented by the mantissa of the Y position. Therefore, the maximum value represented by the mantissa of the Y position can be determined as the mantissa of the calculation variable of the second precision. In this way, the error caused by the conversion of the precision of the floating point number can be reduced to a certain extent.

[0113] 3. If the value represented by the mantissa of the calculation variable of the first precision is smaller than the minimum value that can be represented by the mantissa of the Y position, the minimum value that can be represented by the mantissa of the Y position is determined as the value represented by the mantissa of the calculation variable of the second precision.

[0114] If the value represented by the mantissa of the first precision is less than the minimum value that can be represented by the mantissa of the Y position, it means that the value represented by the mantissa of the calculation variable of the first precision is no longer within the range of values ​​that can be represented by the mantissa of the Y position, and is less than the minimum value that can be represented by the mantissa of the Y position. Therefore, the minimum value represented by the mantissa of the Y position can be determined as the mantissa of the calculation variable of the second precision. In this way, the error caused by the conversion of the precision of the floating point number can be reduced to a certain extent.

[0115] Figure 6 Schematic diagram of a custom floating point number structure provided by the embodiment of the present application. Figure 6As shown, X=5, Y=10. In this way, the exponent bits of the float type floating point number are reduced to 5 bits, and the mantissa bits are reduced to 10 bits, so that a 32-bit floating point number can be converted into a 16-bit floating point number. This reduces the precision of the floating point number and can improve the efficiency of floating point calculations.

[0116] In the embodiment of the present application, the user can specify the first digit of the exponent and the second digit of the mantissa in the low-precision floating-point number, and different digits of the exponent and mantissa correspond to different numerical precisions. Therefore, the present application can provide more fine-grained low-precision calculations, so that in a variety of fine-grained low-precision calculations, a floating-point number in a low-precision format that can meet the calculation accuracy requirements and improve the calculation efficiency can be determined.

[0117] In the calculation function provided in the embodiment of the present application, after converting the calculation variable of the first precision into the calculation variable of the second precision, the calculation function can perform the calculation operation of the same calculation category as the calculation variable of the first precision on the calculation variable of the second precision to obtain the calculation result. After obtaining the calculation result, the calculation function is also used to convert the calculation result from the second precision to the first precision, for example, by filling zeros, the calculation result of the second precision can be converted into the calculation result of the first precision. In this way, after modifying the code for performing the first precision calculation in the first function, the calculation result obtained after the first function is run is still the first precision. For other functions that call the first function, the calculation results obtained after other functions call the first function are still the first precision, so there is no need to adapt to modify the code of other functions, and the amount of code modification can be reduced.

[0118] Figure 7 1 is a structural diagram of a device for executing program code provided in an embodiment of the present application. The device can be implemented as part or all of the device through software, hardware, or a combination of both. The device provided in an embodiment of the present application can implement the embodiment of the present application. Figure 3 The process described above, the device includes: an acquisition module 710, a determination module 720, a replacement module 730 and an execution module 740, wherein:

[0119] The acquisition module 710 is used to acquire the first program code, which can be specifically used to implement the acquisition function of step 301 and execute the implicit steps included in step 301.

[0120] Determination module 720 is used to determine the code that executes the first precision calculation in the first program code; determine the calculation function in the function library that is used to convert the first precision calculation into the second precision calculation and perform the second precision calculation, wherein the first precision corresponding to the calculation variable of the first precision calculation is higher than the second precision corresponding to the calculation variable of the second precision calculation, which can be specifically used to implement the determination function of step 302 and step 303 and execute the implicit steps contained in step 302 and step 303.

[0121] The replacement module 730 is used to replace the code for executing the first precision calculation in the first program code with the code for calling the calculation function to obtain the second program code, which can be specifically used to implement the replacement function of step 304 and execute the implicit steps included in step 304.

[0122] The execution module 740 is used to execute the second program code to obtain the execution result of the second program code, which can be specifically used to implement the execution function of step 305 and the implicit steps included in the execution step 305.

[0123] In one achievable manner, the determination module 720 is used to: convert a calculation variable of the first precision in the first precision calculation into a calculation variable of the second precision; and perform a calculation of the same calculation category as the first precision calculation on the calculation variable of the second precision.

[0124] In one implementable manner, the calculation function is further used to convert a calculation result corresponding to the second precision calculation from the second precision to the first precision.

[0125] In an implementable manner, the determination module 720 is used to: determine the first function specified by the user, identify the code for executing the first precision calculation included in the first function in the first program code, or identify the code for executing the first precision calculation included in the first function and the second function called by the first function in the first program code.

[0126] In one achievable manner, the determination module 720 is used to: if there is a third function that calls the second function and the third function is not called by the first function, then establish a clone function corresponding to the second function, the clone function having the same content as the second function but a different function name. Modify the code in the first function for calling the second function to the code for calling the clone function. Identify the code for performing the first precision calculation in the first function and the clone function.

[0127] In an implementable manner, the determination module 720 is used to obtain a first digit X corresponding to the exponent bit and a second digit Y corresponding to the mantissa bit in the second precision floating-point number specified by the user. Based on X, the exponent bit of the calculation variable of the second precision is determined, and based on Y, the mantissa bit of the calculation variable of the second precision is determined.

[0128] In an implementable manner, the determination module 720 is used to: if the value represented by the exponent bit of the calculation variable of the first precision is within the range of values ​​that can be represented by the exponent bit of the X bit, then the value represented by the exponent bit of the calculation variable of the first precision is determined as the value represented by the exponent bit of the calculation variable of the second precision. If the value represented by the exponent bit of the calculation variable of the first precision is greater than the maximum value that can be represented by the exponent bit of the X bit, then the maximum value that can be represented by the exponent bit of the X bit is determined as the value represented by the exponent bit of the calculation variable of the second precision. If the value represented by the exponent bit of the calculation variable of the first precision is less than the minimum value that can be represented by the exponent bit of the X bit, then the minimum value that can be represented by the exponent bit of the X bit is determined as the value represented by the exponent bit of the calculation variable of the first precision.

[0129] In an implementable manner, the determination module 720 is used to: if the value represented by the mantissa of the calculation variable of the first precision is within the range of values ​​that can be represented by the mantissa of the Y position, then the value represented by the mantissa of the calculation variable of the first precision is determined as the value represented by the mantissa of the calculation variable of the second precision. If the value represented by the mantissa of the calculation variable of the first precision is greater than the maximum value that can be represented by the mantissa of the Y position, then the maximum value that can be represented by the mantissa of the Y position is determined as the value represented by the mantissa of the calculation variable of the second precision. If the value represented by the mantissa of the calculation variable of the first precision is less than the minimum value that can be represented by the mantissa of the Y position, then the minimum value that can be represented by the mantissa of the Y position is determined as the value represented by the mantissa of the calculation variable of the second precision.

[0130] The division of modules in the embodiments of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. In addition, each functional module in each embodiment of the present application may be integrated into a processor, or may exist physically separately, or two or more modules may be integrated into one module. The above-mentioned integrated modules may be implemented in the form of hardware or in the form of software functional modules.

[0131] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a server or terminal, the process or function described in the embodiment of the present application is generated in whole or in part. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a server or terminal or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (such as a floppy disk, a hard disk and a tape, etc.), an optical medium (such as a digital video disk (digital video disk, DVD), etc.), or a semiconductor medium (such as a solid-state hard disk, etc.).

[0132] In the above-mentioned embodiment, the words such as term "first", "second" are used to distinguish the same item or similar item with basically the same effect and function. It should be understood that there is no logical or temporal dependency between "first" and "second", and the quantity and execution order are not limited. It should also be understood that although the following description uses the terms first, second, etc. to describe various elements, these elements should not be limited by the terms. These terms are only used to distinguish one element from another element. For example, without departing from the scope of various examples, the first function can be referred to as the second function, and similarly, the second function can be referred to as the first function. The first function and the second function can both be collectively referred to as functions, and in some cases, can be separate and different functions. The meaning of the term "at least one" in this application refers to one or more, and the meaning of the term "multiple" in this application refers to two or more.

[0133] The above description is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A method for executing a program code, characterized in that: The method comprises: obtaining a first program code; Determine a code in the first program code that performs a first precision calculation; Determine a calculation function in a function library for converting the first precision calculation into a second precision calculation and performing the second precision calculation, wherein a first precision corresponding to a calculation variable of the first precision calculation is higher than a second precision corresponding to a calculation variable of the second precision calculation; Replacing the code in the first program code that executes the first precision calculation with the code that calls the calculation function to obtain a second program code; Execute the second program code to obtain an execution result of the second program code.

2. The method according to claim 1, characterized in that The converting the first precision calculation into the second precision calculation and performing the second precision calculation comprises: Converting the calculation variables of the first precision in the first precision calculation into the calculation variables of the second precision; A calculation of the same calculation category as the first precision calculation is performed on the calculation variable of the second precision.

3. The method according to claim 1 or 2, characterized in that: The calculation function is further used to convert a calculation result corresponding to the second precision calculation from the second precision to the first precision.

4. The method according to any one of claims 1 to 3, characterized in that: The determining of the code in the first program code that performs the first precision calculation includes: determining a first function specified by a user; identifying code included in the first function in the first program code for performing the first precision calculation, or, Identify code in the first program code that performs the first-precision calculation and that is included in the first function and a second function called by the first function.

5. The method according to claim 4, characterized in that The step of identifying the first function in the first program code and the code for performing the first precision calculation included in the second function called by the first function includes: If there is a third function that calls the second function and the third function has not been called by the first function, then creating a clone function corresponding to the second function, where the clone function has the same content as the second function but a different function name; Modify the code in the first function for calling the second function into the code for calling the clone function; Code in the first function and the cloned function that performs the first precision calculation is identified.

6. The method according to any one of claims 2 to 5, characterized in that: The calculation variable is a floating point number, and converting the calculation variable of the first precision in the first precision calculation into the calculation variable of the second precision includes: Obtain a first digit X corresponding to the exponent bit and a second digit Y corresponding to the mantissa bit in the floating-point number of the second precision specified by the user; Based on the X, determine the exponent bits of the calculation variable of the second precision; Based on the Y, the mantissa bits of the calculation variable of the second precision are determined.

7. The method according to claim 6, characterized in that The step of determining the exponent bits of the calculation variable of the second precision based on X comprises: If the value represented by the exponent bit of the computation variable of the first precision is within the range of values ​​that can be represented by the exponent bit of the X bit, then the value represented by the exponent bit of the computation variable of the first precision is determined as the value represented by the exponent bit of the computation variable of the second precision; If the value represented by the exponent bit of the computation variable of the first precision is greater than the maximum value that can be represented by the exponent bit of the X bits, the maximum value that can be represented by the exponent bit of the X bits is determined as the value represented by the exponent bit of the computation variable of the second precision; If the value represented by the exponent bits of the computation variable of the first precision is smaller than the minimum value that can be represented by the exponent bits of the X bits, the minimum value that can be represented by the exponent bits of the X bits is determined as the value represented by the exponent bits of the computation variable of the first precision.

8. The method according to claim 6, characterized in that The step of determining the mantissa of the calculation variable of the second precision based on the Y comprises: If the value represented by the mantissa of the calculation variable of the first precision is within the range of values ​​that can be represented by the mantissa of the Y position, the value represented by the mantissa of the calculation variable of the first precision is determined as the value represented by the mantissa of the calculation variable of the second precision; If the value represented by the mantissa of the calculation variable of the first precision is greater than the maximum value that can be represented by the mantissa of the Y position, the maximum value that can be represented by the mantissa of the Y position is determined as the value represented by the mantissa of the calculation variable of the second precision; If the value represented by the mantissa of the calculation variable of the first precision is smaller than the minimum value that can be represented by the mantissa of the Y position, the minimum value that can be represented by the mantissa of the Y position is determined as the value represented by the mantissa of the calculation variable of the second precision.

9. A device for executing program code, characterized in that: The device comprises: An acquisition module, used for acquiring a first program code; a determination module, configured to determine a code in the first program code that performs a first precision calculation; and to determine a calculation function in a function library that is used to convert the first precision calculation into a second precision calculation and perform the second precision calculation, wherein a first precision corresponding to a calculation variable of the first precision calculation is higher than a second precision corresponding to a calculation variable of the second precision calculation; A replacement module, used for replacing the code that executes the first precision calculation in the first program code with the code that calls the calculation function to obtain a second program code; An execution module is used to execute the second program code to obtain an execution result of the second program code.

10. The device according to claim 9, characterized in that Identify modules for: Converting the calculation variables of the first precision in the first precision calculation into the calculation variables of the second precision; A calculation of the same calculation category as the first precision calculation is performed on the calculation variable of the second precision.

11. The device according to claim 9 or 10, characterized in that The calculation function is further used to convert a calculation result corresponding to the second precision calculation from the second precision to the first precision.

12. The device according to any one of claims 9 to 11, characterized in that The determining module is used to: determining a first function specified by a user; identifying code included in the first function in the first program code for performing the first precision calculation, or, Identify code in the first program code that performs the first-precision calculation and that is included in the first function and a second function called by the first function.

13. The device according to claim 12, characterized in that The determining module is used to: If there is a third function that calls the second function and the third function has not been called by the first function, then creating a clone function corresponding to the second function, where the clone function has the same content as the second function but a different function name; Modify the code in the first function for calling the second function into the code for calling the clone function; Code in the first function and the cloned function that performs the first precision calculation is identified.

14. The method according to any one of claims 11 to 13, characterized in that: The determining module is used to: Obtain a first digit X corresponding to the exponent bit and a second digit Y corresponding to the mantissa bit in the floating-point number of the second precision specified by the user; Based on the X, determine the exponent bits of the calculation variable of the second precision; Based on the Y, the mantissa bits of the calculation variable of the second precision are determined.

15. The device according to claim 14, characterized in that The determining module is used to: If the value represented by the exponent bit of the computation variable of the first precision is within the range of values ​​that can be represented by the exponent bit of the X bit, then the value represented by the exponent bit of the computation variable of the first precision is determined as the value represented by the exponent bit of the computation variable of the second precision; If the value represented by the exponent bit of the computation variable of the first precision is greater than the maximum value that can be represented by the exponent bit of the X bits, the maximum value that can be represented by the exponent bit of the X bits is determined as the value represented by the exponent bit of the computation variable of the second precision; If the value represented by the exponent bits of the computation variable of the first precision is smaller than the minimum value that can be represented by the exponent bits of the X bits, the minimum value that can be represented by the exponent bits of the X bits is determined as the value represented by the exponent bits of the computation variable of the first precision.

16. The device according to claim 14, characterized in that The determining module is used to: If the value represented by the mantissa of the calculation variable of the first precision is within the range of values ​​that can be represented by the mantissa of the Y position, the value represented by the mantissa of the calculation variable of the first precision is determined as the value represented by the mantissa of the calculation variable of the second precision; If the value represented by the mantissa of the calculation variable of the first precision is greater than the maximum value that can be represented by the mantissa of the Y position, the maximum value that can be represented by the mantissa of the Y position is determined as the value represented by the mantissa of the calculation variable of the second precision; If the value represented by the mantissa of the calculation variable of the first precision is smaller than the minimum value that can be represented by the mantissa of the Y position, the minimum value that can be represented by the mantissa of the Y position is determined as the value represented by the mantissa of the calculation variable of the second precision.

17. A computing device, characterized in that The computing device comprises a processor and a memory, wherein the processor is configured to execute instructions stored in the memory, so that the computing device executes the method according to any one of claims 1 to 8.

18. A computer program product comprising instructions, characterized in that When the instructions are executed by a computing device, the computing device is caused to perform the method according to any one of claims 1 to 8.

19. A computer-readable storage medium, characterized in that: The method comprises computer program instructions. When the computer program instructions are executed by a computing device, the computing device performs the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Data processing method and device based on neural network

    CN106570559A

  • Parallel computing method based on manual vectorization

    CN110673877A

  • Acceleration of shader programs by compiler precision selection

    CN113924547A

  • Program rewriting apparatus, storage medium, and program rewriting method

    CN113934433A

  • Mixed precision floating point multiplication device and mixed precision floating point number processing method

    CN116795324A