Mixing precision error analysis method and system based on instant protocol

By constructing the error propagation matrix and using forward differential and error source aggregation technology, the problems of large space-time overhead and insufficient error accuracy in mixed accuracy error analysis are solved, and lightweight and scalable error analysis is realized, which improves program performance and accuracy.

CN120407367APending Publication Date: 2025-08-01INST OF COMPUTING TECH CHINESE ACAD OF SCI
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510489535.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2025-02-17
Filing Date
2025-04-18
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

The existing hybrid accuracy error analysis methods have problems such as large space-time overhead, poor scalability and insufficient error accuracy, which leads to the inability to effectively optimize program performance and power consumption.

Method used

Using a hybrid accuracy error analysis method based on real-time regulations, the error propagation matrix is constructed, and forward differential and error source aggregation technology is used to reduce the calculation amount and space requirements and improve the accuracy of error analysis.

Benefits of technology

It effectively reduces the spatial complexity and time overhead of error analysis, improves the accuracy of error analysis, and provides a lightweight and scalable error analysis solution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407367A_ABST
    Figure CN120407367A_ABST
Patent Text Reader

Abstract

The invention discloses a mixed precision error analysis method and system based on instant reduction, and the method comprises the steps: inputting a to-be-analyzed code region, constructing and initializing an error propagation matrix EPM, and aggregating any group of error sources into an error source group through a column mapping function; the method comprises the following steps: for a current instruction in operation, spreading an error of a source operand of the current instruction to an error vector of a target operand based on a forward differential error analysis method and an error source aggregation instant reduction method; calculating a result value of the current instruction under the mixed precision configuration, and calculating a truncation error of the current instruction according to the result value under the mixed precision configuration; all code instructions are traversed, and finally the error contribution of each input error source to the program output variable is obtained. According to the method, mixing precision error analysis can be carried out on a scientific calculation program lightly and efficiently, and accurate error sensitivity information is provided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to program analysis and optimization methods, and particularly to a mixed-precision error analysis method and system based on immediate reduction. Background Art

[0002] Currently, mixed-precision optimization is a method that can significantly optimize program performance and power consumption. However, developing mixed-precision programs is very difficult because using mixed-precision optimization will reduce program accuracy. When developers adopt mixed-precision optimization, they need to ensure that the accuracy of the program can meet a given error threshold, which requires developers to have an in-depth understanding of the program and a background in floating-point error analysis, greatly limiting the application of mixed-precision optimization.

[0003] Therefore, the automatic error analysis technology for mixed precision has received extensive attention. It can automatically analyze the floating-point errors of each error source in the program and provide the error sensitivity information of the program. Based on this information, a mixed-precision program that meets the error threshold can be further developed.

[0004] Existing methods are based on automatic differentiation for mixed-precision error analysis. Among them, ADAPT is a dynamic error sensitivity analysis tool that uses algorithmic automatic differentiation (support for reverse differentiation) to estimate the final output error caused by reducing the precision of variables. However, the main problem of ADAPT is that the space and time overhead for error analysis is relatively large, and the scalability is relatively poor. It can only run very small inputs, otherwise the huge space expansion rate will cause the tool to be unable to load at all.

[0005] The following are the disadvantages of the existing technology:

[0006] 1) Lack of a lightweight and scalable mixed-precision error analysis method: Dynamic mixed-precision error analysis often calculates the rounding error of variables under reduced precision based on the first-order Taylor series approximation. According to the first-order Taylor series approximation, the input variables of program segment P and the local truncation errors corresponding to each dynamic instance of each assignment statement (each execution of the statement at runtime is represented as a dynamic instance) will be propagated through differentiation. When performing error analysis, it is necessary to calculate the first-order differentials of all these dynamic instances. Since the number of inputs of the differential tree is extremely large, far greater than the number of outputs, the calculation of the first-order differential can only adopt the reverse method. This results in an excessive space overhead for the error analysis algorithm, with a space complexity of O(T), where T is the number of dynamic instructions in the original program. Since the T value of general scientific computing programs is extremely large, the memory expansion of error analysis is huge, often leading to memory overflow. As a result, users have to reduce the input of the application to control the memory requirements of error analysis. Although the system can adopt a technique that combines recomputation and recursive checkpointing to balance the analysis time and memory requirements, the optimal placement of checkpointing is an NP-hard problem and requires user assistance, which not only brings implementation complexity but also additional time overhead.

[0007] To enable the error analysis algorithm to adapt to actual scientific computing programs, it is very important to propose a lightweight and scalable error analysis algorithm.

[0008] 2) Inability to improve the analysis accuracy of mixed-precision error analysis: Existing mixed-precision error analysis algorithms based on automatic differentiation all face the problem of insufficient accuracy in error estimation. The main reason for this problem is that the truncation error of each instance only considers the error introduced after converting the current instance to a lower precision, while ignoring its impact on other error sources in the same error source group. Existing mixed-precision error analysis algorithms adopt an independent analysis method for single-instruction instances, ignoring the impact of data dependencies between instructions on local errors. As the instruction dependence chain grows, its accuracy will deviate further and further from the actual error, and even show an order-of-magnitude difference. This may lead to the unavailability of its analysis results, that is, seriously affecting subsequent precision allocation and making it difficult to find an effective mixed-precision configuration. Therefore, it is necessary to improve the accuracy of error analysis.

[0009] In summary, the above defects not only lead to relatively large space and time overheads and poor scalability in error analysis, but also the error accuracy will deviate further and further from the actual error.

[0010] Therefore, there is an urgent need to propose a lightweight and scalable mixed-precision error analysis algorithm to improve the analysis accuracy of mixed-precision error analysis. Summary of the Invention

[0011] To solve the problems of large space-time overhead and poor scalability in error analysis in the above-mentioned existing technologies, and the problem that the error accuracy will deviate more and more from the actual error, a hybrid-precision error analysis method based on immediate reduction is proposed.

[0012] In a first aspect, an embodiment of the present application provides a hybrid-precision error analysis method based on immediate reduction, and the method includes:

[0013] Input a code region to be analyzed, and construct and initialize an error propagation matrix EPM according to the input variable set of the code region. The error propagation matrix EPM is used to store the error vectors of each floating-point statement in the code region;

[0014] Use a column mapping function and a row mapping function to map the floating-point statements in the code region to the index numbers of any column or any row of the error propagation matrix respectively, and aggregate any group of error sources into an error source group through the column mapping function;

[0015] For the current instruction during the operation of the code region, based on the error analysis method of forward differentiation and the immediate reduction method of error source aggregation, propagate the error of the source operand of the current instruction to the error vector of the destination operand;

[0016] Based on the error vector of the destination operand, calculate the result value under the hybrid-precision configuration of the current instruction, and calculate the truncation error of the current instruction according to the result value under the hybrid-precision configuration;

[0017] Execute all instructions in the code region and accompany the execution of the error analysis method to finally obtain the error contribution of each input error source to the program output variable.

[0018] In a specific embodiment of the present invention, the above-mentioned construction and initialization of the error propagation matrix further includes:

[0019] Initialize the error propagation matrix; wherein, the number of rows of the error propagation matrix is the number of floating-point statements in the code region, and the number of columns of the error propagation matrix is the number of clusters of floating-point statements grouped by the assigned variables;

[0020] Use the column mapping function to map the floating-point statements in the code region to the index numbers of any column of the error propagation matrix, and use the row mapping function to map the floating-point statements in the code region to the index numbers of any row of the error propagation matrix.

[0021] In a specific embodiment of the present invention, the above-mentioned for the current instruction during the operation of the code region, based on the error analysis method of forward differentiation and the immediate reduction method of error source aggregation, propagating the error of the source operand of the current instruction to the error vector of the destination operand further includes:

[0022] Based on the error propagation of forward differentiation, calculate the partial differentials of the output of the current instruction with respect to each source operand of the current instruction, multiply the partial differentials by the error vectors of the respective source operands to obtain all product values;

[0023] Perform immediate reduction on the error vectors, sum all the product values, and propagate the sum value to the error vector of the destination operand of the current instruction.

[0024] In a specific embodiment of the present invention, based on the error vector of the destination operand, calculate the result value under the mixed precision configuration of the current instruction, and calculate the truncation error of the current instruction according to the result value under the mixed precision configuration. It further includes:

[0025] Calculate the truncation error of the current instruction. Aggregate the error sources of each source operand into an error source group through a column mapping function, and calculate the total error estimate value;

[0026] Sum the calculation result of the current instruction and the error estimate value to calculate the result value of the current instruction under the mixed precision configuration;

[0027] Calculate the truncation error based on the result value of the current instruction under the mixed precision configuration.

[0028] In a second aspect, an embodiment of the present application provides a mixed precision error analysis system based on immediate reduction, which adopts the above-mentioned mixed precision error analysis method based on immediate reduction. The system includes:

[0029] Initialization module: used to input a code region to be analyzed, construct and initialize an error propagation matrix EPM according to the input variable set of the code region. The error propagation matrix EPM is used to store the error vectors of each floating-point statement in the code region;

[0030] Error source aggregation module: used to map the floating-point statements in the code region to the index numbers of any column or any row of the error propagation matrix respectively by using a column mapping function and a row mapping function, and aggregate any group of error sources into an error source group through the column mapping function;

[0031] Error propagation module: For the current instruction during the operation of the code region, based on the error analysis method of forward differentiation and the immediate reduction method of error source aggregation, propagate the errors of the source operands of the current instruction to the error vector of the destination operand;

[0032] Truncation error calculation module: Based on the error vector of the destination operand, calculate the result value of the current instruction under the mixed precision configuration, and calculate the truncation error of the current instruction according to the result value under the mixed precision configuration;

[0033] Error contribution output module: Execute all instructions in the code region and perform the error analysis method, and finally obtain the error contribution of each input error source to the program output variable.

[0034] In a specific embodiment of the present invention, the above initialization module further includes:

[0035] Initialize the error propagation matrix; wherein, the number of rows of the error propagation matrix is the number of floating-point statements in the code region, and the number of columns of the error propagation matrix is the number of clusters of floating-point statements grouped by the assigned variables.

[0036] Use the column mapping function to map the floating-point statements in the code region to the index number of any column of the error propagation matrix, and use the row mapping function to map the floating-point statements in the code region to the index number of any row of the error propagation matrix.

[0037] In a specific embodiment of the present invention, the above error propagation module further includes:

[0038] Based on the error propagation of forward differentiation, calculate the partial derivatives of the output of the current instruction with respect to each source operand of the current instruction, multiply the partial derivatives by the error vectors of the respective source operands, and obtain all product values.

[0039] Perform immediate reduction on the error vectors, sum all the product values, and propagate the sum value to the error vector of the destination operand of the current instruction.

[0040] In a specific embodiment of the present invention, the above truncation error calculation module further includes:

[0041] Calculate the truncation error of the current instruction, aggregate the error sources of each source operand into an error source group through the column mapping function, and calculate the total error estimate value.

[0042] Sum the calculation result of the current instruction and the error estimate value, and calculate the result value of the current instruction under the mixed precision configuration.

[0043] Calculate the truncation error based on the result value of the current instruction under the mixed precision configuration.

[0044] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the steps of the above-mentioned mixed-precision error analysis method based on immediate reduction are implemented.

[0045] In a fourth aspect, an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the steps of the above-mentioned mixed-precision error analysis method based on immediate reduction are implemented.

[0046] Compared with the related existing technologies, it has the following outstanding beneficial effects:

[0047] 1) Based on the error analysis based on forward differentiation, the present method further proposes an on-the-fly reduction method based on error source aggregation to optimize it. The present method allows the user to specify the error source aggregation method between scalar variables and then reduces the errors within the same error source group at runtime, which can significantly reduce the computational complexity and space requirements of the error analysis.

[0048] 2) By combining immediate reduction with error source aggregation, the error analysis algorithm of the present invention effectively controls the computational complexity of forward differentiation. Compared with existing error analysis techniques based on reverse differentiation, it can significantly reduce space complexity and generally outperform existing mixed-precision error analysis techniques.

[0049] 3) The method of the present invention proposes a new method for calculating truncation error. When calculating the error introduced by reducing the current instance to a lower precision, the influence of the errors of other instances in the error source group on the value of the instance variable is considered, thereby effectively improving the accuracy of error analysis.

[0050] 4) Based on the characteristics of error source aggregation and independent analysis of individual error source groups, this method can obtain the actual value of each fixed point under the corresponding mixed-precision configuration during execution. Based on this value, the new truncation error calculation method can consider the impact of error propagation between instructions within the error source group, improving the accuracy of error analysis. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0052] Figure 1 Schematic diagram of the mixed-precision error analysis method based on real-time reduction of the present invention;

[0053] Figure 2 Schematic diagram of error analysis of Simpsons in an embodiment of the present invention;

[0054] Figure 3 Schematic diagram of error analysis of one-dimensional Jacobi iteration according to an embodiment of the present invention;

[0055] Figure 4 Schematic diagram of a mixed-precision error analysis system based on real-time reduction according to an embodiment of the present invention;

[0056] Figure 5 Schematic diagram of computer hardware of the present invention. DETAILED DESCRIPTION

[0057] In the present invention, "at least one" means one or more, and "a plurality" means two or more. "At least one of the following" or a similar expression means any combination of these items, including any combination of single items or plural items. For example, at least one of a, b, or c can represent: a, b, c, a - b, a - c, b - c, or a - b - c, where a, b, and c can be single or plural.

[0058] It should also be understood that the term "and / or" in this document is merely a description of the association relationship between associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. Here, A and B can be singular or plural. Additionally, the character " / " in this document generally represents an "or" relationship between the associated objects before and after, but it may also represent an "and / or" relationship, which can be specifically understood with reference to the context before and after.

[0059] It should also be understood that in various embodiments of the present invention, the magnitudes of the sequence numbers of the above - mentioned processes do not imply the order of execution. The order of execution of each process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.

[0060] In several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division. In actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces. The indirect coupling or communication connection of the device or unit can be in an electrical, mechanical, or other form.

[0061] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0062] In addition, in each embodiment of the present invention, the functional units can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit.

[0063] When the above-mentioned functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs that can store program codes.

[0064] To make the above features and effects of the present invention more clearly and understandably described, specific embodiments are hereinafter given and detailed descriptions are made in conjunction with the accompanying drawings of the specification. This specification discloses one or more embodiments including the features of the present invention. The disclosed embodiments are only for illustrative purposes. The protection scope of the present invention is not limited to the disclosed embodiments, and the present invention is defined by the appended claims.

[0065] The following is a system embodiment corresponding to the above method embodiment, and this embodiment can be implemented in cooperation with the above embodiment. The relevant technical details mentioned in the above embodiment are still valid in this embodiment. To avoid repetition, they are not described herein again. Correspondingly, the relevant technical details mentioned in this embodiment can also be applied to the above embodiment.

[0066] The method of the present invention aims to propose a hybrid-precision error analysis algorithm based on immediate reduction. The present invention explores for the first time the use of forward differentiation for program error analysis. The advantage of forward differentiation is that it does not require storing all intermediate data, so the space complexity is much smaller than that of forward differentiation. However, in the scenario of hybrid-precision error analysis, the computational complexity of forward differentiation is unacceptable. However, the present invention discovers that in actual hybrid-precision tuning, developers generally allocate precision as a whole for variables. For example, an entire array or a certain region in the array (each element in the array is an error source) is allocated as low precision, rather than customizing different precision schemes for each element in the array one by one. Even if the tool gives error information at the single-instruction instance level, the tool still needs to post-process them - reduce and sum them up for the convenience of users.

[0067] According to this specific requirement, based on the error analysis of forward differentiation, the present invention further proposes an immediate reduction method based on error source aggregation to optimize it. The method of the present invention allows users to specify the error source aggregation method between scalar variables, and then reduce the errors within the same error source group at runtime, which can significantly reduce the computational complexity and space requirements of error analysis.

[0068] By combining immediate reduction and error source aggregation, the error analysis algorithm of the present invention effectively controls the computational complexity of forward differentiation. Compared with the existing error analysis techniques based on reverse differentiation, it can greatly reduce the space complexity, and the performance is generally better than the existing mixed-precision error analysis techniques.

[0069] Furthermore, the method of the present invention proposes a method for calculating truncation error under mixed-precision analysis. The method of the present invention proposes a new method for calculating truncation error. When calculating the error introduced by reducing the current instance to a low precision, the method of the present invention will consider the influence of the errors of other instances within the error source group on the variable values of this instance, thereby effectively improving the accuracy of error analysis.

[0070] Based on the characteristics of error source aggregation and independent analysis of a single error source group, the actual value of each constant point under the corresponding mixed-precision configuration can be obtained during execution. Based on this value, the new method for calculating truncation error can consider the influence of error propagation between instructions within the error source group, and improve the accuracy of error analysis.

[0071] Embodiment 1

[0072] As Figure 1 shown, the embodiment of the present application provides a mixed-precision error analysis method based on immediate reduction, and the method includes:

[0073] Step 101: Input a code region to be analyzed, and construct and initialize an error propagation matrix EPM according to the input variable set of the code region. The error propagation matrix EPM is used to store the error vectors of each floating-point statement in the code region;

[0074] Step 102: Use the column mapping function and the row mapping function to map the floating-point statements in the code region to the index numbers of any column or any row of the error propagation matrix respectively, and aggregate any group of error sources into an error source group through the column mapping function;

[0075] Step 103: For the current instruction during the operation of the code region, based on the error analysis method of forward differentiation and the immediate reduction method of error source aggregation, propagate the error of the source operand of the current instruction to the error vector of the destination operand;

[0076] Step 104: Calculate the result value under the mixed-precision configuration of the current instruction based on the error vector of the destination operand, and calculate the truncation error of the current instruction according to the result value under the mixed-precision configuration.

[0077] Step 105: Execute all the instructions in the code region and execute the above error analysis method to finally obtain the error contribution of each input error source to the program output variable.

[0078] In a specific embodiment of the present invention, in the above step 101, constructing and initializing the error propagation matrix further includes:

[0079] Initialize the error propagation matrix; wherein, the number of rows of the error propagation matrix is the number of error source groups in the code region, and the number of columns of the error propagation matrix is the number of groups obtained by clustering floating-point statements according to the assigned variables.

[0080] Use the column mapping function to map the floating-point statements in the code region to the index number of any column of the error propagation matrix, and use the row mapping function to map the floating-point statements in the code region to the index number of any row of the error propagation matrix.

[0081] In a specific embodiment of the present invention, in the above step 103, for the current instruction during the operation of the code region, based on the error analysis method of forward differentiation and the immediate reduction method of error source aggregation, propagating the error of the source operand of the current instruction to the error vector of the destination operand further includes:

[0082] Based on the error propagation of forward differentiation, calculate the partial derivative of the output of the current instruction with respect to each source operand of the current instruction, multiply the partial derivative by the error vector of each source operand respectively to obtain all product values;

[0083] Immediately reduce the error vector, sum all the product values, and propagate the sum value to the error vector of the destination operand of the current instruction.

[0084] In a specific embodiment of the present invention, in the above step 104, calculating the result value under the mixed-precision configuration of the current instruction based on the error vector of the destination operand, and calculating the truncation error of the current instruction according to the result value under the mixed-precision configuration further includes:

[0085] Calculate the truncation error of the current instruction, aggregate the error sources of each source operand into an error source group through the column mapping function, and calculate the total error estimate value;

[0086] Sum the calculation result of the current instruction and the error estimate value to calculate the result value of the current instruction under the mixed-precision configuration;

[0087] Calculate the truncation error based on the result value of the current instruction under the mixed-precision configuration.

[0088] The method of the embodiments of the present application will be described in detail below in conjunction with specific embodiments:

[0089] In a specific embodiment of the present invention, for a scientific computing program, a user hopes to perform mixed-precision error analysis on a hot region in the program (i.e., the code region that occupies the most time in the program), such as the main loop body in the program, to obtain the sensitivity information of each input error source to the program output variable.

[0090] The mixed-precision error analysis algorithm based on immediate reduction includes: when the floating-point instructions of the original program are executed, the following error analysis algorithm will be executed accordingly. The definition of trunc_error(v) is related to the low-precision data type. When the low-precision is float, trunc_error(v) = v - (float)v.

[0091]

[0092] In the above error analysis algorithm, the two mapping functions colMap and rowMap are established by the runtime system when the user registers variables in P, and belong to the input of this algorithm.

[0093] Row mapping function rowMap: Each scalar program variable (single data element) corresponds to an EPM row, that is, different elements of the array correspond to different EPM rows. Since each floating-point constant statement has a variable to be constant, this mapping function also assigns each floating-point constant statement to a certain EPM row.

[0094] Column mapping function colMap: Although each constant statement is an error source, overly detailed error information is often not helpful for precision allocation and will bring huge computational complexity. This algorithm introduces the concept of error source groups, that is, variables are grouped through colMap, and then constant statements are grouped. Simply put, each array in P can be aggregated into an error source group, and the user can also aggregate any group of error sources into an error source group according to expert knowledge or through graph community discovery algorithms, etc.

[0095] Among them, column mapping colMap (that is, error source aggregation) is the basis of immediate reduction. The introduction of error source groups enables errors from different scalar constant points to be reduced and summed to the same error term.

[0096] Lines 1 to 4 of the algorithm are the initialization of the EPM matrix at the entrance of the code region P. In addition to initializing the matrix to all 0, it is then to calculate the truncation errors generated when all input variables are converted from high precision to low precision and store them in the EPM matrix.

[0097] During error analysis, the update of EPM and the floating-point assignment statements of the original program are executed concurrently, which exactly reflects that the forward differential method is adopted in the present invention. For the currently executed instruction t, the error update can be divided into two steps. The first step is the error propagation based on forward differentiation, corresponding to steps 5-9 of the runtime algorithm. Among them, represents the partial derivative of the output r of the floating-point instruction with respect to the input operand x i , which is multiplied by the error vector EPM[src i of the source operand and then propagated to the error vector EPM[des] of the destination operand. Line 9 is the reduction summation, which also reflects the characteristic of immediate reduction of the error vector.

[0098] The second step is to calculate the truncation error of the current instruction t, corresponding to steps 10-13 of the algorithm. In line 12, the calculation result of the current instruction and the error estimate value EPM[des][eid] are summed (here, eid represents a group of error sources containing several assignment instructions. For the current instruction t, eid = colMap(t)), and the result value mixpVal of the instruction t in this mixed-precision configuration can be obtained when reducing the precision of all assignment statements in the eid error source group. The key point 2 of this algorithm is to calculate the truncation error based on mixpVal, which is the key for the accuracy analysis of this algorithm to be much higher than other algorithms, because this error model can capture the error influence of other dynamic instruction instances in the eid error source group on the current instruction t. By capturing this error influence, the accuracy of error analysis is significantly improved.

[0099] Specific implementation case one of the application scenario of the method of the present invention

[0100] The following uses the Simpsons program without arrays to demonstrate the runtime error analysis process of the present invention. Table 1 shows its code, and this program calculates the definite integral of the function sin(x*pi) in the interval [0,1] using the iterative method.

[0101]

[0102] Table 1 Simpsons example

[0103] The corresponding error analysis process of the present invention is as Figure 2As shown in the figure, the matrix in the figure is the EPM matrix during error analysis. Let EPM[x] represent the row vector corresponding to variable x in the matrix, and EPM[x][x] represent the error contribution corresponding to variable x in this row vector. The symbols in the EPM matrix in the figure all represent a certain error contribution. In particular, let Δi represent the truncation error generated by a certain floating-point statement, and let ai, bi, ci, and di represent other error contributions, which are generated after the truncation error is amplified by the differential coefficient. In addition, the EPM elements modified in the current step are represented in red.

[0104] First, since there are no floating-point input variables in this program, during the EPM initialization phase, the system simply sets the EPM matrix to all 0s.

[0105] When the Init function assigns initial values to 4 variables, the right-side expressions do not contain floating-point variables. The EPM update only involves truncation errors, which are accumulated into the corresponding columns of the EPM row, and the remaining positions are initialized to 0.

[0106] For each statement in loop i: The right-side expressions of these statements contain floating-point variables. The EPM error update needs to be divided into two stages: 1) Propagation of the error vectors of the operands; 2) Introduction of the truncation error of the current statement.

[0107] Consider the typical statement s1 = s1 + 4.0 * sin(x * pi) in loop i: Its right-side value expression contains three floating-point variables s1, x, and pi. First, propagate the row vectors of the EPM matrix corresponding to these three variables (represented by EPM[s1], EPM[x], and EPM[pi]), and they will be multiplied by the corresponding partial derivatives Then add them together, and then update the row vector corresponding to the current statement in the EPM. After that, it is also necessary to calculate the truncation error of the current statement. First, add the calculation result s1 + 4.0 * sin(x * pi) of the current instruction and EPM[s1][s1] to obtain the actual value mixpVal under the mixed-precision configuration, calculate its truncation error, and accumulate it to EPM[s1][s1].

[0108] The above error update of the EPM will accompany the execution of each floating-point statement in the program. When the program executes to the return statement, the analysis ends. At this time, the row vector EPM[s1] of variable s1 can be output, which is the error contribution of each variable in this program to s1.

[0109] Specific implementation case two of the application scenario of the method of the present invention

[0110] This example is a Jacobi iteration program mainly for array access. The Jacobi iteration method is a classic algorithm for solving linear equations. For the convenience of demonstration, we choose 1D Jacobi and only show 3 iterations. Here N = 2, that is, each array contains 4 elements, and 2 non-boundary elements are updated each time. Table 2 shows the pseudocode of Jacobi iteration. In the initialization phase, there are two loops. The first loop initializes the entire a array, and the second loop initializes the boundary elements of the b array.

[0111]

[0112] Table 2 Jacobi Iteration Example

[0113] The corresponding error analysis process and the evolution update of the EPM matrix are as Figure 3 shown. Figure 3 The representation method of Figure 2 is similar to that of Figure 2 except that each floating-point scalar variable in Figure 3 will be mapped to a certain column in the EPM, but all floating-point variables within the same array in Figure 3 will be mapped to the same row in the EPM, which avoids the expansion of the EPM matrix.

[0114] This program segment has no input variables, so the EPM is only initialized to 0

[0115] Loop1 and loop2 are used to initialize arrays a and b: Since there are no other floating-point variables on the right side of these assignment statements, these statements only generate truncation errors and there is no process of error vector transmission. Their truncation errors are stored in the corresponding columns. Of course, since the errors of b[0] and a[0] are exactly the same, we use the same mathematical symbols in the figure.

[0116] Loop3 updates the b array with the a array: When executing the floating-point statement b[1] = f(a[0], a[1], a[2]), first, error propagation and summation are performed on the three input operands. At this time, new non-zero terms appear in the first column of the sumv vector, but the second column is still 0. In the truncation error calculation stage, a non-zero error term is obtained according to mixpVal. Since this statement assigns a value to b[1], the truncation error is stored in the second column. Now, both columns in the error vector of b[1] are non-zero and newly written. We represent the newly modified values in the current step in red. Similarly, the assignment of b[2] also brings red changes in the error vector.

[0117] Loop4 updates the a array with the b array: When executing the floating-point statement a[1] = f(b[0], b[1], b[2]), first, error propagation and summation are performed on the three input operands, and both columns of sumv are non-zero. Then, truncation error calculation is performed. Since this statement assigns a value to a, the truncation error corresponds to the first column, and at this time, the first column is still being updated. The values of the elements in the new error vector use new symbols, indicating that the values are different from those before overwriting and also different from the vectors of the source operands. Similarly, the assignment statement of a[2] can be analyzed.

[0118] Loop5 still updates the b array with the a array: The situation is similar to loop4, where both columns of the error vectors of b[1] and b[2] are not 0 and the values are different from before.

[0119] At this time, the EPM matrix stores the values of the error vectors when each variable is assigned a value for the last time.

[0120] In summary, the method of the present invention can perform mixed-precision error analysis on scientific computing programs in a lightweight and efficient manner and provide accurate error sensitivity information. Compared with the prior art with a time complexity of O(mT) and a space complexity of O(T), the space complexity of the algorithm proposed by the present invention is lower, only O(nS), and the time complexity is similar, O(nT). Here, T is the number of dynamic instructions of the original program, S is the space complexity of the original program, n is the number of error sources, and m is the complexity constant of reverse automatic differentiation. By aggregating error sources and making full use of the parallelism of forward differentiation, the actual analysis performance is also higher than that of existing algorithms in most test programs. In addition, through the improvement of the truncation error calculation method, the error estimation accuracy of the present invention is much higher than that of existing error analysis algorithms.

[0121] Embodiment 2

[0122] As Figure 4 shown, the embodiment of the present application provides a mixed-precision error analysis system based on immediate reduction, which adopts the mixed-precision error analysis method based on immediate reduction as described above. The system includes:

[0123] Initialization module 201: It is used to input a code area to be analyzed, construct and initialize an error propagation matrix EPM according to the input variable set of the code area, and the error propagation matrix EPM is used to store the error vectors of each floating-point statement in the code area;

[0124] Error source aggregation module 202: It is used to map the floating-point statements in the code area to the index numbers of any column or any row of the error propagation matrix by using a column mapping function and a row mapping function respectively, and aggregate any group of error sources into an error source group through the column mapping function;

[0125] Error propagation module 203: For the current instruction during the operation of the code area, based on the error analysis method of forward differentiation and the immediate reduction method of error source aggregation, propagate the error of the source operand of the current instruction to the error vector of the destination operand;

[0126] Truncation error calculation module 204: Based on the error vector of the destination operand, calculate the result value under the mixed precision configuration of the current instruction, and calculate the truncation error of the current instruction according to the result value under the mixed precision configuration;

[0127] Error contribution output module 205: Execute all instructions in the code area, and execute the above error analysis method to finally obtain the error contribution of each input error source to the program output variable.

[0128] In a specific embodiment of the present invention, the above initialization module 201 further includes:

[0129] Initialize the error propagation matrix; wherein, the number of rows of the error propagation matrix is the number of floating-point statements in the code area, and the number of columns of the error propagation matrix is the number of clusters of floating-point statements according to the variables to be assigned values;

[0130] Map the floating-point statements in the code area to the index numbers of any column of the error propagation matrix by using a column mapping function, and map the floating-point statements in the code area to the index numbers of any row of the error propagation matrix by using a row mapping function.

[0131] In a specific embodiment of the present invention, the above error propagation module 203 further includes:

[0132] Based on the error propagation of forward differentiation, calculate the partial derivatives of the output of the current instruction with respect to each source operand of the current instruction, multiply the partial derivatives by the error vectors of the respective source operands respectively to obtain all product values;

[0133] Immediately reduce the error vectors, sum all the product values, and propagate the sum value to the error vector of the destination operand of the current instruction.

[0134] In a specific embodiment of the present invention, the truncation error calculation module 204 further includes:

[0135] Calculate the truncation error of the current instruction, aggregate the error sources of each source operand into an error source group through a column mapping function, and calculate the total error estimate value;

[0136] Sum the calculation result of the current instruction and the error estimate value to calculate the result value of the current instruction under the mixed precision configuration;

[0137] Calculate the truncation error based on the result value of the current instruction under the mixed precision configuration.

[0138] Embodiment III

[0139] The embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the steps of the above-mentioned mixed precision error analysis method based on immediate reduction are implemented.

[0140] Embodiment IV

[0141] The embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the steps of the above-mentioned mixed precision error analysis method based on immediate reduction are implemented.

[0142] In addition, the mixed precision error analysis method based on immediate reduction described in Figure 1 the embodiment of the present application can be implemented by an electronic device, such as a computer device. Figure 5 FIG. is a schematic hardware structure diagram of a computer device according to an embodiment of the present application.

[0143] In some of these embodiments, the computer device may further include a communication interface 83 and a bus 80. Among them, as Figure 5 shown, the processor 81, the memory 82, and the communication interface 83 are connected through the bus 80 and complete communication with each other.

[0144] Specifically, the above-mentioned processor 81 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application.

[0145] The memory 82 may be used to store or cache various data files required for processing and / or communication, as well as possible computer program instructions executed by the processor 81.

[0146] The processor 81 reads and executes the computer program instructions stored in the memory 82 to implement any one of the above-described embodiments of the hybrid precision error analysis method based on immediate specifications.

[0147] The technical features of the above-described embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope described in this specification.

[0148] The above-described embodiments merely represent several implementation manners of the present application, and the description thereof is relatively specific and detailed, but it should not be construed as a limitation on the scope of the invention patent. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the appended claims.

Claims

1. A method for analyzing mixed-precision errors based on immediate reduction, characterized in that The method includes: Input a code region to be analyzed, and construct and initialize an error propagation matrix EPM according to the input variable set of the code region. The error propagation matrix EPM is used to store the error vectors of each floating-point statement in the code region; Use a column mapping function and a row mapping function to map the floating-point statements in the code region to the index numbers of any column or any row of the error propagation matrix respectively. Aggregate any set of error sources into an error source group through the column mapping function; For the current instruction during the execution of the code region, based on the forward-differential error analysis method and the immediate reduction method of error source aggregation, propagate the error of the source operand of the current instruction to the error vector of the destination operand; Based on the error vector of the destination operand, calculate the result value under the mixed-precision configuration of the current instruction, and calculate the truncation error of the current instruction according to the result value under the mixed-precision configuration; Execute all instructions in the code region and accompany the execution of the error analysis method to finally obtain the error contribution of each input error source to the program output variable.

2. The method for hybrid precision error analysis based on instant specification according to claim 1, wherein The constructing and initializing the error propagation matrix further includes: Initialize the error propagation matrix; wherein, the number of rows of the error propagation matrix is the number of floating-point statements in the code region, and the number of columns of the error propagation matrix is the number of clusters of floating-point statements grouped by the assigned variables; Use the column mapping function to map the floating-point statements in the code region to the index number of any column of the error propagation matrix, and use the row mapping function to map the floating-point statements in the code region to the index number of any row of the error propagation matrix.

3. The method for analyzing the mixed-precision error based on instant specification according to claim 1, wherein For the current instruction during the execution of the code region, based on the forward-differential error analysis method and the immediate reduction method of error source aggregation, propagating the error of the source operand of the current instruction to the error vector of the destination operand further includes: Based on the forward-differential error propagation, calculate the partial derivatives of the output of the current instruction with respect to each source operand of the current instruction, multiply the partial derivatives by the error vectors of the respective source operands respectively to obtain all product values; Immediately reduce the error vectors, sum all the product values, and propagate the sum value to the error vector of the destination operand of the current instruction.

4. The method for analyzing the mixed-precision error based on the instant specification according to claim 1, wherein Based on the error vector of the destination operand, calculating the result value under the mixed-precision configuration of the current instruction, and calculating the truncation error of the current instruction according to the result value under the mixed-precision configuration further includes: Aggregate the error sources of each source operand into an error source group through the column mapping function to obtain a total error estimate value; Sum the calculation result of the current instruction and the error estimate value to calculate the result value of the current instruction under the mixed-precision configuration; Calculate the truncation error based on the result value of the current instruction under the mixed-precision configuration.

5. A hybrid precision error analysis system based on immediate reduction, adopting the method for hybrid precision error analysis based on immediate reduction as described in any one of claims 1-4, characterized in that, The system includes: An initialization module: used to input a code region to be analyzed, and construct and initialize an error propagation matrix EPM according to the input variable set of the code region. The error propagation matrix EPM is used to store the error vectors of each floating-point statement in the code region; Error source aggregation module: It is used to map the floating-point statements in the code region to the index numbers of any column or any row of the error propagation matrix by using a column mapping function and a row mapping function respectively, and aggregate any group of error sources into an error source group through the column mapping function; Error propagation module: For the current instruction during the operation of the code region, based on the error analysis method of forward differentiation and the immediate reduction method of error source aggregation, propagate the error of the source operand of the current instruction to the error vector of the destination operand; Truncation error calculation module: Based on the error vector of the destination operand, calculate the result value under the mixed precision configuration of the current instruction, and calculate the truncation error of the current instruction according to the result value under the mixed precision configuration; Error contribution output module: Execute all the instructions in the code region and accompany the execution of the error analysis method to finally obtain the error contribution of each input error source to the program output variable.

6. The method for analyzing mixed-precision errors based on immediate reduction according to claim 5, wherein The initialization module further includes: Initialize the error propagation matrix; wherein, the number of rows of the error propagation matrix is the number of floating-point statements in the code region, and the number of columns of the error propagation matrix is the number of clusters of floating-point statements according to the assigned variables; Use the column mapping function to map the floating-point statements in the code region to the index number of any column of the error propagation matrix, and use the row mapping function to map the floating-point statements in the code region to the index number of any row of the error propagation matrix.

7. The method for analyzing the mixed-precision error based on immediate reduction according to claim 5, characterized in that The error propagation module further includes: Based on the error propagation of forward differentiation, calculate the partial derivatives of the output of the current instruction with respect to each source operand of the current instruction, multiply the partial derivatives by the error vectors of each source operand respectively to obtain all product values; Immediately reduce the error vectors, sum all the product values, and propagate the sum value to the error vector of the destination operand of the current instruction.

8. The method for analyzing the mixed-precision error based on the instant specification according to claim 5, wherein The truncation error calculation module further includes: Aggregate the error sources of each source operand into an error source group through the column mapping function to obtain the total error estimate value of the error source group; Sum the calculation result of the current instruction and the error estimate value to calculate the result value of the current instruction under the mixed precision configuration; Calculate the truncation error based on the result value of the current instruction under the mixed precision configuration.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by a processor, it implements the steps of the immediate reduction-based mixed-precision error analysis method described in any one of claims 1-4.

10. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the immediate reduction-based mixed-precision error analysis method described in any one of claims 1 to 4.

Citation Information

Cited By

  • Optimization method and device for protocol calculation, computer equipment, readable storage medium and program product

    CN121029240A

  • Adaptive precision floating point multiply-accumulate operation device and method, medium, terminal and program product

    CN121523637A