Data processing method and device and electronic equipment

By semantic comparison of the input and output codes of the compiler's compilation operations performed by the compiler, the compilation operations performed by the compiler are verified, and the problem of difficulty in verifying the accuracy of the compiler's operations in the prior art is solved, and the semantic consistency verification of the code is realized.

CN120122929APending Publication Date: 2025-06-10LENOVO (BEIJING) LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510180468.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-18
Publication Date
2025-06-10

AI Technical Summary

Technical Problem

The prior art is difficult to effectively verify whether the compiler performs accurate during the compilation process, resulting in the possible problems of compilation errors or semantic inconsistencies.

Method used

By obtaining the first code executed by the compiler and the second code output, the two are analyzed separately, the grammar unit sequence is extracted, and semantic comparison is performed to generate operation verification results to determine whether the compilation operation executed by the compiler is accurate.

Benefits of technology

It realizes the accuracy verification of the compiler's compilation operations, ensuring that the code output by the compiler is semantically consistent with the input code, and avoids the problems of compilation errors and semantic inconsistencies.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120122929A_ABST
    Figure CN120122929A_ABST
Patent Text Reader

Abstract

The invention discloses a data processing method and device and electronic equipment, and the method comprises the steps that a first code and a second code are obtained, and a compiler executes compiling operation on the first code to output the second code; the compiling operation is any compiling operation of the compiler in a compiling process; the first code and the second code are analyzed respectively to obtain a first grammar sequence and a second grammar sequence, the first grammar sequence comprises grammar units analyzed from the first code, and the second grammar sequence comprises grammar units analyzed from the second code; the grammar unit represents grammar or lexical in the code; performing semantic comparison on the first grammar sequence and the second grammar sequence to obtain an operation verification result representing whether the first code and the second code are semantically consistent or not; and according to the operation verification result, determining whether the compiler executes the compiling operation accurately.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of data processing, and in particular, to a data processing method, apparatus, and electronic device. Background Art

[0002] With the increasingly wide application of deep learning, the correctness requirements of deep learning models for the compilation operations performed by compilers are also getting higher and higher.

[0003] Therefore, there is an urgent need for a technical solution that can verify whether the compilation operations performed by the compiler are accurate. Summary of the Invention

[0004] In view of this, this application provides a data processing method, apparatus, and electronic device as follows:

[0005] A data processing method includes:

[0006] Obtain a first code and a second code, where the compiler performs a compilation operation on the first code to output the second code; the compilation operation is any compilation operation during the compilation process of the compiler;

[0007] Analyze the first code and the second code respectively to obtain a first grammar sequence and a second grammar sequence. The first grammar sequence includes the grammar units analyzed from the first code, and the second grammar sequence includes the grammar units analyzed from the second code. The grammar units represent the syntax or lexicon in the code;

[0008] Perform a semantic comparison on the first grammar sequence and the second grammar sequence to obtain an operation verification result indicating whether the first code and the second code are semantically consistent;

[0009] Determine whether the compiler performs the compilation operation accurately according to the operation verification result.

[0010] Preferably, for the above method, performing a semantic comparison on the first grammar sequence and the second grammar sequence to obtain an operation verification result indicating whether the first code and the second code are semantically consistent includes:

[0011] Obtain a first semantic set and a second semantic set respectively according to the first grammar sequence and the second grammar sequence. The first semantic set includes the operation semantics corresponding to each grammar unit in the first grammar sequence, and the second semantic set includes the operation semantics corresponding to each grammar unit in the second grammar sequence;

[0012] Perform a semantic comparison on the first semantic set and the second semantic set to obtain the operation verification result.

[0013] Preferably, for the above method, the first semantic set and the second semantic set are semantically compared to obtain an operation verification result, including:

[0014] Construct a semantic consistency proposition according to the first semantic set and the second semantic set;

[0015] Generate a proof sequence code according to the semantic consistency proposition; the proof sequence code includes at least one proof strategy; there is an execution order between the proof strategies;

[0016] Execute the proof sequence code to obtain the truth value result of the semantic consistency proposition;

[0017] Obtain an operation verification result according to whether the truth value result of the proposition is true.

[0018] Preferably, for the above method, the proof strategy includes: a pre-proof lemma;

[0019] Wherein, the pre-proof lemma is used to provide the proof result of the associated proposition corresponding to the semantic consistency proposition before executing the proof sequence code, and the proof result of the associated proposition is used to obtain the truth value result of the proposition.

[0020] Preferably, for the above method, the first semantic set and the second semantic set are obtained respectively according to the first grammar sequence and the second grammar sequence, including:

[0021] In the first dictionary corresponding to the compilation operation, look up the operation semantics corresponding to each grammar unit in the first grammar sequence to obtain the first semantic set;

[0022] In the second dictionary corresponding to the compilation operation, look up the operation semantics corresponding to each grammar unit in the second grammar sequence to obtain the second semantic set;

[0023] Wherein, the first dictionary includes the operation semantics corresponding to each of the multiple grammar units corresponding to the first attribute; the second dictionary includes the operation semantics corresponding to each of the multiple grammar units corresponding to the second attribute; the first attribute is the code attribute of the first code, and the second attribute is the code attribute of the second code.

[0024] Preferably, for the above method, the first grammar sequence is a tree structure; the second grammar sequence is a tree structure;

[0025] Wherein, each node in the tree structure corresponds to the corresponding grammar unit in the grammar sequence.

[0026] Preferably, for the above method, the method further includes:

[0027] Obtain the operation verification result corresponding to each of the compilation operations performed by the compiler to implement the compilation task;

[0028] Determine whether the compiler is accurate according to the operation verification result corresponding to each of the compilation operations.

[0029] In the above method, preferably, after determining that the compiler performs the compilation operation inaccurately, the method further includes:

[0030] In response to the compilation operation being a code conversion operation, output a prompt message characterizing a compilation error, and / or, trigger the compiler to re-execute the compilation operation;

[0031] In response to the compilation operation being a code optimization operation, trigger the compiler to execute the next compilation operation.

[0032] A data processing device includes:

[0033] A code acquisition unit, configured to acquire a first code and a second code, and the compiler performs a compilation operation on the first code to output the second code; the compilation operation is any compilation operation during the compilation process of the compiler;

[0034] A grammar analysis unit, configured to analyze the first code and the second code respectively to obtain a first grammar sequence and a second grammar sequence, the first grammar sequence includes the grammar units analyzed from the first code, and the second grammar sequence includes the grammar units analyzed from the second code, and the grammar unit represents the syntax or lexeme in the code;

[0035] A semantic comparison unit, configured to perform semantic comparison on the first grammar sequence and the second grammar sequence to obtain an operation verification result characterizing whether the first code and the second code are semantically consistent;

[0036] A compilation determination unit, configured to determine whether the compiler performs the compilation operation accurately according to the operation verification result.

[0037] An electronic device includes:

[0038] A memory, configured to store a computer program and the data generated by the running of the computer program;

[0039] A processor, configured to execute the computer program to implement:

[0040] Acquire a first code and a second code, and the compiler performs a compilation operation on the first code to output the second code; the compilation operation is any compilation operation during the compilation process of the compiler;

[0041] Analyze the first code and the second code respectively to obtain a first grammar sequence and a second grammar sequence. The first grammar sequence includes the grammar units analyzed from the first code, and the second grammar sequence includes the grammar units analyzed from the second code. The grammar units represent the syntax or morphology in the code.

[0042] Perform semantic comparison on the first grammar sequence and the second grammar sequence to obtain an operation verification result indicating whether the first code and the second code are semantically consistent.

[0043] Determine whether the compiler executes the compilation operation accurately according to the operation verification result.

[0044] A computer device / system, comprising: a memory, a processor, and a computer program stored on the memory. The processor executes the computer program to implement the data processing method described in any one of the above.

[0045] A computer-readable storage medium, on which a computer program / instructions are stored. When the computer program / instructions are executed by a processor, the data processing method described in any one of the above is implemented.

[0046] A computer program product, comprising computer program / instructions. When the computer program / instructions are executed by a processor, the data processing method described in any one of the above is implemented.

[0047] As can be seen from the above technical solutions, in a data processing method, device, and electronic device disclosed in this application, by obtaining the first code input by the compiler for any compilation operation and the second code output, analyzing the first code and the second code respectively to obtain the analyzed grammar units, and accordingly performing semantic comparison on the grammar units analyzed from the first code and the second code respectively to obtain an operation verification result indicating whether the first code and the second code are semantically consistent, and finally determining whether the compiler executes the compilation operation accurately according to the operation verification result. It can be seen that in this application, by performing semantic comparison on the code input by the compiler for any compilation operation and the output code, whether the compilation operation is accurate is characterized by whether the input code and the output code are semantically consistent. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] To more clearly illustrate the technical solutions of the embodiments of this application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of this application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0049] Figure 1A flowchart for implementing a data processing method provided by an embodiment of this application;

[0050] Figure 2 An example diagram of the first code input and the second code output when the compiler in an embodiment of this application performs a compilation operation;

[0051] Figure 3 An example diagram in which the first grammar sequence is represented by an abstract syntax tree 1 in an embodiment of this application;

[0052] Figure 4 An example diagram in which the second grammar sequence is represented by an abstract syntax tree 2 in an embodiment of this application;

[0053] Figure 5 A partial flowchart of a data processing method provided by an embodiment of this application;

[0054] Figure 6 Another partial flowchart of a data processing method provided by an embodiment of this application;

[0055] Figure 7 Another partial flowchart of a data processing method provided by an embodiment of this application;

[0056] Figure 8 Another flowchart of a data processing method provided by an embodiment of this application;

[0057] Figure 9 A structural schematic diagram of a data processing device provided by an embodiment of this application;

[0058] Figure 10 Another structural schematic diagram of a data processing device provided by an embodiment of this application;

[0059] Figure 11 Another structural schematic diagram of a data processing device provided by an embodiment of this application;

[0060] Figure 12 A structural schematic diagram of an electronic device provided by an embodiment of this application;

[0061] Figure 13 A flowchart showing the process of the compiler of the Triton language performing a compilation operation in an embodiment of this application;

[0062] Figure 14 A process framework diagram for implementing semantic consistency verification in an embodiment of this application. Detailed implementation manners

[0063] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.

[0064] Reference Figure 1 , which is a flowchart of the implementation of a data processing method provided by an embodiment of the present application. This method can be applied to an electronic device capable of data processing, such as an electronic device capable of running a compiler, or an electronic device connected to a running device capable of running a compiler. The technical solution in this embodiment is mainly used to verify whether the compilation operation performed by the compiler is accurate.

[0065] Specifically, the method in this embodiment may include the following steps:

[0066] Step 101: Obtain a first code and a second code.

[0067] Among them, the compiler performs a compilation operation on the first code and outputs the second code. The compilation operation is any compilation operation during the compilation process of the compiler.

[0068] Specifically, in this embodiment, for any compilation operation performed by the compiler, when the compilation operation is executed, the first code input to the compiler and the second code output from the compiler are obtained.

[0069] It should be noted that the compilation of the source code by the compiler may include one or more compilation operations. As Figure 2 shown, after the compiler sequentially performs these compilation operations on the source code, the compilation result is output. For each compilation operation, the code output by the previous compilation operation is used as the input code and input to the compiler. The compiler outputs the compiled code, and then uses it as the input code for the next compilation operation and inputs it to the compiler. Correspondingly, for each compilation operation, the code input to the compiler is recorded as the first code, and the code output by the compiler after performing the compilation operation on the first code is recorded as the second code. In this embodiment, the corresponding first code and second code can be obtained for each compilation operation respectively.

[0070] Taking the compilation operation of the compiler compiling the first code Triton DSL to the second code Triton IR as an example, the first code is the code of add_kernel, and the first code is used to perform vector addition, as follows:

[0071]

[0072] The second code is the code output after the compiler compiles the code of add_kernel, as follows:

[0073] %3 = tt.splat %1

[0074] %4 = arith.addi %3, %2

[0075] %5 = tt.splat %arg0

[0076] %6 = tt.addptr %5, %4

[0077] %7 = tt.load %6

[0078] %8 = tt.splat %arg1

[0079] %9 = tt.addptr %8, %4

[0080] %10 = tt.load %9

[0081] %11 = arith.addf %7, %10

[0082] %12 = tt.splat %arg2

[0083] %13 = tt.addptr %12, %4

[0084] tt.store %13, %11

[0085] tt.return

[0086] }

[0087] Step 102: Analyze the first code and the second code respectively to obtain the first grammar sequence and the second grammar sequence.

[0088] Among them, the first grammar sequence includes the grammar units analyzed from the first code, and the second grammar sequence includes the grammar units analyzed from the second code. The grammar units represent the syntax or morphology in the code.

[0089] Specifically, in this embodiment, the lexical and syntactic analysis can be performed on the first code and the second code respectively to analyze the lexicon and syntax in the first code and the lexicon and syntax in the second code. The lexicon and syntax in the first code are represented by corresponding grammar units respectively, and the lexicon and syntax in the second code are represented by corresponding grammar units respectively, thereby obtaining the first grammar sequence and the second grammar sequence.

[0090] In one implementation, the first grammar sequence can be a list structure, and the grammar units in the first grammar sequence are arranged in the order before and after in the first code; the second grammar sequence can be a list structure, and the grammar units in the second grammar sequence are arranged in the order before and after in the second code.

[0091] In another implementation, the first grammar sequence is a tree structure, and the grammar units in the first grammar sequence are arranged according to their logical relationships in the first code. Each node in the tree structure corresponds to the corresponding grammar unit in the grammar sequence. As Figure 3 shown, it is the abstract syntax tree 1 corresponding to the first grammar sequence obtained by analyzing the code of add_kernel. Each node in the abstract syntax tree 1 corresponds to the corresponding grammar unit in the first grammar sequence.

[0092] The second grammar sequence is a tree structure, and the grammar units in the second grammar sequence are arranged according to their logical relationships in the second code. Each node in the tree structure corresponds to the corresponding grammar unit in the grammar sequence. As Figure 4 shown, it is the abstract syntax tree 2 corresponding to the second grammar sequence obtained after analyzing the code obtained after compiling the code of add_kernel. Each node in the abstract syntax tree 2 corresponds to the corresponding grammar unit in the second grammar sequence.

[0093] Step 103: Semantically compare the first grammar sequence and the second grammar sequence to obtain an operation verification result indicating whether the first code and the second code are semantically consistent.

[0094] In one implementation, in this embodiment, the operation semantics implemented by the first code and the second code can be compared through the grammar units in the first grammar sequence and the grammar units in the second grammar sequence to obtain an operation verification result, and the operation verification result indicates whether the first code and the second code are semantically consistent.

[0095] Step 104: Determine whether the compiler executes the compilation operation accurately according to the operation verification result.

[0096] Among them, when the operation verification result indicates that the first code and the second code are semantically consistent, it is determined that the compiler executes the compilation operation accurately; when the operation verification result indicates that the first code and the second code are semantically inconsistent, it is determined that the compiler executes the compilation operation inaccurately.

[0097] As can be seen from the above technical solution, in a data processing method provided by an embodiment of the present application, by obtaining the first code input by the compiler for any compilation operation and the second code output, analyzing the first code and the second code respectively to obtain the analyzed grammar units, and accordingly performing semantic comparison on the grammar units analyzed from the first code and the second code respectively to obtain an operation verification result indicating whether the first code and the second code are semantically consistent, and finally determining whether the compiler's compilation operation is accurate according to the operation verification result. It can be seen that in this embodiment, by performing semantic comparison on the code input by the compiler for any compilation operation and the output code, it is characterized whether the compilation operation is accurate by whether the input code and the output code are semantically consistent.

[0098] In one implementation, when obtaining the operation verification result in step 103, it can be implemented in the following manner, such as Figure 5 shown in

[0099] Step 501: Obtain a first semantic set and a second semantic set respectively according to the first grammar sequence and the second grammar sequence.

[0100] Among them, the first semantic set includes the operation semantics corresponding to each grammar unit in the first grammar sequence, and the second semantic set includes the operation semantics corresponding to each grammar unit in the second grammar sequence.

[0101] In one implementation, when obtaining the first semantic set in step 501, the operation semantics corresponding to each grammar unit in the first grammar sequence can be searched in the first dictionary corresponding to the compilation operation to obtain the first semantic set.

[0102] Among them, the first dictionary includes the operation semantics corresponding to each of the multiple grammar units corresponding to the first attribute. The first attribute is the code attribute of the first code, such as the code attribute of Triton DSL.

[0103] For example, the implementation code of the first dictionary corresponding to the code attribute of Triton DSL is as follows:

[0104] (*get_program_id is an operation unique to the Triton language, used to return the unique identifier ID of the current thread in the specified dimension in parallel computing. This formal definition means that for a given parallel computing context parallel_context, if dim is a valid dimension in the process space pid_space, then the output pid is the unique process ID pid in the specified dimension dim.*)

[0105]

[0106] (*Different from conventional languages, most variables and operations in Triton language are of tensor type. The definitions of mathematical operations on tensors are Tltensoradd and Tltensormult, which means that for all indices i defined by the shape, T_res[i] = T1[i] + T2[i] holds.*)

[0107]

[0108]

[0109] (*Triton also supports the calculation of tensors and scalars, and the result is that the value of the scalar is added to all elements in the tensor.*)

[0110]

[0111] (*arange returns a tensor containing all values between integers a and b.*)

[0112]

[0113]

[0114] In one implementation, when obtaining the second semantic set in step 501, the operation semantics corresponding to each grammar unit in the second grammar sequence can be searched in the second dictionary corresponding to the compilation operation to obtain the second semantic set.

[0115] Among them, the second dictionary includes the operation semantics corresponding to each of the multiple grammar units corresponding to the second attribute. The second attribute is the code attribute of the second code, such as the code attribute of Triton IR.

[0116] For example, the implementation code of the second dictionary corresponding to the code attribute of Triton IR is as follows:

[0117]

[0118]

[0119]

[0120] (*There is no operation for tensor and scalar operations in Triton. The scalar needs to be extended (splat) to a tensor and then tensor operations are performed.*)

[0121]

[0122]

[0123] Based on this, the first semantic set corresponding to the code of Triton DSL is as follows:

[0124]

[0125] Based on this, the second semantic set corresponding to the code of Triton IR is as follows:

[0126]

[0127]

[0128] Step 502: Compare the semantics of the first semantic set and the second semantic set to obtain an operation verification result.

[0129] In one implementation, in step 502, the operation semantics of the first semantic set and the second semantic set are compared for semantic consistency. When the operation semantics in the first semantic set and the operation semantics in the second semantic set satisfy the semantic consistency condition, an operation verification result indicating that the semantics of the first code and the second code are consistent is obtained; when the operation semantics in the first semantic set and the operation semantics in the second semantic set do not satisfy the semantic consistency condition, an operation verification result indicating that the semantics of the first code and the second code are inconsistent is obtained.

[0130] Among them, the semantic consistency condition can be: the semantic similarity between the operation semantics in the first semantic set and the operation semantics in the second semantic set is greater than or equal to the similarity threshold.

[0131] In another implementation, when obtaining the operation verification result in step 502, it can be achieved through the following method, as Figure 6 shown in

[0132] Step 601: Construct a semantic consistency proposition according to the first semantic set and the second semantic set.

[0133] Among them, in this embodiment, a proposition can be created for the first semantic set and the second semantic set to obtain a proposition for verifying whether the first semantic set and the second semantic set are semantically consistent, that is, a semantic consistency proposition.

[0134] For example, when constructing a proposition for the semantic sets corresponding to the code of Triton DSL and the code of Triton IR respectively, the code of the semantic consistency proposition is as follows:

[0135] Lemma tl_add_kernel_equiv:

[0136] forall x_ptr y_ptr output_ptr n_elements BLOCK_SIZE1 mem1

[0137] %arg_0%arg_1%arg_3%arg_4BLOCK_SIZE2 mem2,

[0138] exists mem1'mem2',

[0139] x_ptr = %arg_0 / \ y_ptr = %arg_1 / \ output_ptr = %arg_3 / \

[0140] n_elements = %arg_4 / \ BLOCK_SIZE1 = BLOCK_SIZE2 / \ mem1 = mem2->

[0141] eval_tl_add_kernel x_ptr y_ptr output_ptr n_elements BLOCK_SIZE1mem1mem1'->

[0142] eval_tir_add_kernel%arg_0%arg_1%arg_2%arg_3BLOCK_SIZE2mem2 mem2'->

[0143] mem1' = mem2'.

[0144] Step 602: Generate proof sequence code according to the semantic consistency proposition.

[0145] Among them, the proof sequence code includes at least one proof strategy. There is an execution order among the proof strategies.

[0146] In one implementation, the proof strategy may include: a proof lemma that provides a corresponding proof result during the execution of the proof sequence;

[0147] In another implementation, the proof strategy may include: a pre-proof lemma; the pre-proof lemma is used to provide the proof result of the associated proposition corresponding to the semantic consistency proposition before executing the proof sequence code, and the proof result of the associated proposition is used to obtain the true or false result of the proposition.

[0148] For example, construct a proof sequence code based on the semantic consistency proposition corresponding to the code of Triton DSL and the code of Triton IR as follows:

[0149]

[0150] Among them, Unfold eval_tl_add_kernel and eapply tensorAddScalar_Tensoradd_equiv, etc. are for proving lemmas. Among them, tensorAddScalar_Tensoradd_equiv is a lemma to be pre-proved, as follows:

[0151]

[0152] specialize(H_eval_Tl idx).

[0153] destruct(tensor_get T1 idx)as[v1|]eqn:H_get_T1.

[0154] specialize(H_eval_Tir_splat idx).

[0155] apply H_eval_Tir_splat in H_splat_idx.

[0156] destruct H_splat_idx as[a_scalar_idx_eq].

[0157] rewrite a_scalar_idx_eq in*.

[0158] specialize(H_eval_Tir_Tensoradd idx).

[0159] eauto.

[0160] Qed.

[0161] Step 603: Execute the proof sequence code to obtain the true or false result of the semantic consistency proposition.

[0162] For example, execute the proof sequence code corresponding to the above code based on Triton DSL and the code of Triton IR. The execution result of the proof sequence code is the true or false result of the semantic consistency proposition.

[0163] Step 604: Obtain the operation verification result according to whether the true or false result of the proposition is true.

[0164] Among them, when the true or false result of the proposition is true, the operation verification result indicates that the semantics between the first code and the second code are consistent; when the true or false result of the proposition is false, the operation verification result indicates that the semantics between the first code and the second code are inconsistent.

[0165] In one implementation, the method in this embodiment may further include the following processing procedures, as Figure 7 shown in

[0166] Step 701: Obtain the operation verification result corresponding to each compilation operation performed by the compiler to implement the compilation task.

[0167] Among them, the obtaining method of the operation verification result corresponding to each compilation operation performed by the compiler to implement the compilation task may refer to the obtaining method Figure 1 shown.

[0168] Step 702: Determine whether the compiler is accurate according to the operation verification result corresponding to each compilation operation.

[0169] Among them, when the operation verification result corresponding to each compilation operation indicates that the compiler performs the compilation operation accurately, it is determined that the compiler is accurate; when there is an operation verification result corresponding to any compilation operation that indicates that the compiler performs the compilation operation inaccurately, it is determined that the compiler is inaccurate.

[0170] Taking the Figure 2 compilation process shown as an example, the compiler needs to perform 4 compilation operations to implement the compilation task. If the compiler performs these 4 compilation operations accurately, it is determined that the compiler is accurate; if the compiler performs any one of these compilation operations inaccurately, it is determined that the compiler is inaccurate.

[0171] In one implementation, when it is determined in step 104 that the compiler performs the compilation operation inaccurately, this embodiment may further include the following steps, as Figure 8 shown in

[0172] Step 105: Determine the operation type of the compilation operation. If the compilation operation is of the operation type of code conversion operation, execute step 106; if the compilation operation is of the operation type of code optimization operation, execute step 107.

[0173] Among them, the code conversion operation is used to perform code conversion on the input code; the code optimization operation is used to perform code optimization on the input code.

[0174] Step 106: In response to the compilation operation being a code conversion operation, output a prompt message indicating a compilation error, and / or trigger the compiler to re-execute the compilation operation.

[0175] Among them, the prompt message may be: "Compilation error", and the prompt message is used to prompt the user that an error occurs when the compiler performs the current compilation operation, and please check it in time.

[0176] Step 107: In response to the compilation operation being a code optimization operation, trigger the compiler to execute the next compilation operation.

[0177] It can be seen that in this embodiment, during the process of the compiler implementing any compilation task, it is possible to verify whether any compilation operation performed by the compiler is accurate. When it is verified that the compilation operation performed by the compiler is inaccurate, the user can be reminded in a timely manner. Further, the compiler can be triggered to re - execute the compilation operation at least once. When the number of times of repeatedly executing the compilation operation reaches a certain threshold, only the user is reminded and the compilation operation is no longer re - executed.

[0178] Reference Figure 9 , is a schematic structural diagram of a data processing device provided by an embodiment of the present application. This device can be applied to an electronic device capable of data processing, such as an electronic device capable of running a compiler, or an electronic device connected to a running device capable of running a compiler. The technical solution in this embodiment is mainly used to verify whether the compilation operation performed by the compiler is accurate.

[0179] Specifically, the device in this embodiment may include the following units:

[0180] A code acquisition unit 901, configured to acquire a first code and a second code, where the compiler performs a compilation operation on the first code to output the second code; the compilation operation is any compilation operation during the compilation process of the compiler;

[0181] A grammar analysis unit 902, configured to analyze the first code and the second code respectively to obtain a first grammar sequence and a second grammar sequence. The first grammar sequence includes the grammar units analyzed from the first code, and the second grammar sequence includes the grammar units analyzed from the second code. The grammar unit represents the syntax or lexeme in the code;

[0182] A semantic comparison unit 903, configured to perform a semantic comparison on the first grammar sequence and the second grammar sequence to obtain an operation verification result indicating whether the first code and the second code are semantically consistent;

[0183] A compilation determination unit 904, configured to determine whether the compiler performs the compilation operation accurately according to the operation verification result.

[0184] As can be seen from the above technical solution, in a data processing device provided by an embodiment of the present application, by obtaining a first code input by a compiler for any compilation operation and a second code output, analyzing the first code and the second code respectively to obtain the analyzed grammar units, and accordingly performing semantic comparison on the grammar units analyzed from the first code and the second code respectively to obtain an operation verification result indicating whether the first code and the second code are semantically consistent, and finally determining whether the compiler performs the compilation operation accurately according to the operation verification result. It can be seen that in this embodiment, by performing semantic comparison on the code input by the compiler for any compilation operation and the output code, whether the compilation operation is accurately performed is characterized by whether the input code and the output code are semantically consistent.

[0185] In one implementation, the semantic comparison unit 903 is specifically configured to: respectively obtain a first semantic set and a second semantic set according to the first grammar sequence and the second grammar sequence, where the first semantic set includes the operation semantics corresponding to each grammar unit in the first grammar sequence, and the second semantic set includes the operation semantics corresponding to each grammar unit in the second grammar sequence; perform semantic comparison on the first semantic set and the second semantic set to obtain an operation verification result.

[0186] In one implementation, when the semantic comparison unit 903 performs semantic comparison on the first semantic set and the second semantic set to obtain an operation verification result, it is specifically configured to: construct a semantic consistency proposition according to the first semantic set and the second semantic set; generate a proof sequence code according to the semantic consistency proposition; the proof sequence code includes at least one proof strategy; there is an execution order between the proof strategies; execute the proof sequence code to obtain a proposition true / false result of the semantic consistency proposition; obtain an operation verification result according to whether the proposition true / false result is true.

[0187] Among them, the proof strategy includes: a pre-proof lemma; the pre-proof lemma is used to provide a proof result of an associated proposition corresponding to the semantic consistency proposition before executing the proof sequence code, and the proof result of the associated proposition is used to obtain the proposition true / false result.

[0188] In one implementation, when the semantic comparison unit 903 obtains the first semantic set and the second semantic set according to the first grammar sequence and the second grammar sequence respectively, it is specifically configured to: look up the operation semantics corresponding to each grammar unit in the first grammar sequence in the first dictionary corresponding to the compilation operation to obtain the first semantic set; look up the operation semantics corresponding to each grammar unit in the second grammar sequence in the second dictionary corresponding to the compilation operation to obtain the second semantic set; wherein, the first dictionary includes the operation semantics corresponding to each of the multiple grammar units corresponding to the first attribute; the second dictionary includes the operation semantics corresponding to each of the multiple grammar units corresponding to the second attribute; the first attribute is the code attribute of the first code, and the second attribute is the code attribute of the second code.

[0189] In one implementation, the first grammar sequence is a tree structure; the second grammar sequence is a tree structure; wherein, each node in the tree structure corresponds to the corresponding grammar unit in the grammar sequence.

[0190] In one implementation, the device in this embodiment may further include the following units, as Figure 10 shown in

[0191] The result determination unit 905 is configured to obtain the operation verification result corresponding to each compilation operation performed by the compiler to implement the compilation task; and determine whether the compiler is accurate according to the operation verification result corresponding to each compilation operation.

[0192] In one implementation, the device in this embodiment may further include the following units, as Figure 11 shown in

[0193] The error handling unit 906 is configured to, after the compilation determination unit 904 determines that the compiler performs the compilation operation inaccurately, in response to the compilation operation being a code conversion operation, output a prompt message characterizing the compilation error, and / or trigger the compiler to re-perform the compilation operation; in response to the compilation operation being a code optimization operation, trigger the compiler to perform the next compilation operation.

[0194] It should be noted that the specific implementation manners of the units in this embodiment may refer to the corresponding contents in the foregoing, and will not be elaborated herein.

[0195] Refer to Figure 12 , which is a schematic structural diagram of an electronic device provided by an embodiment of the present application. The electronic device may include the following structures:

[0196] The memory 1201 is used to store a computer program and the data generated by the running of the computer program;

[0197] A processor 1202 for executing the computer program to implement:

[0198] Obtain a first code and a second code, where the compiler performs a compilation operation on the first code to output the second code; the compilation operation is any compilation operation during the compilation process of the compiler;

[0199] Analyze the first code and the second code respectively to obtain a first grammar sequence and a second grammar sequence. The first grammar sequence includes the grammar units analyzed from the first code, and the second grammar sequence includes the grammar units analyzed from the second code. The grammar units represent the syntax or lexical rules in the code;

[0200] Perform a semantic comparison on the first grammar sequence and the second grammar sequence to obtain an operation verification result indicating whether the first code and the second code are semantically consistent;

[0201] Determine whether the compiler performs the compilation operation accurately according to the operation verification result.

[0202] As can be seen from the above technical solution, in an electronic device provided in an embodiment of the present application, by obtaining the first code input by the compiler during any compilation operation and the second code output, analyzing the first code and the second code respectively to obtain the analyzed grammar units, and accordingly performing a semantic comparison on the grammar units analyzed from the first code and the second code respectively to obtain an operation verification result indicating whether the first code and the second code are semantically consistent, and finally determining whether the compiler performs the compilation operation accurately according to the operation verification result. It can be seen that in the present application, by performing a semantic comparison on the code input by the compiler during any compilation operation and the output code, whether the input code and the output code are semantically consistent is used to represent whether the compilation operation is accurate.

[0203] Taking the compiler used by the deep learning model as an example, the technical solution of the present application will be described in detail below:

[0204] Aiming at the general lack of correctness in the compilers used by current deep learning models, the present application proposes a Coq-based trusted compilation method, which can be used for any compilation language. Based on semantic confirmation technology, the present application extracts the semantics of each intermediate representation (i.e., the first code and the second code) generated during each compilation operation in the compilation process, and proves the semantic consistency. If the proof is passed, the compilation operation (pass) is correct. If all passes pass the proof, the entire compilation process is correct, that is, the semantics of the output program (i.e., the second code) and the source program (i.e., the first code) are consistent.

[0205] Taking the Triton language as an example, asFigure 13 As shown, the compilation process of the Triton language includes: compiling Triton DSL into Triton IR (Intermediate Representation), compiling Triton IR into TritonGPUIR, compiling TritonGPUIR into LLVM IR, compiling LLVM IR into PTX, and compiling PTX into CUBIN. In this application, semantic consistency verification is performed on the input code and the output code for each compilation operation in this compilation process. For example, semantic consistency verification is performed on the part from Triton DSL to LLVMIR. During compilation, semantic consistency verification is performed on the input code and output code for each compilation pass (a compilation operation, the conversion between intermediate representations) and optimization pass (a compilation operation, the optimization within the intermediate representation) in this process. For example, the conversion pass1 from Triton DSL to Triton IR, the optimization pass1 for Triton IR, the conversion pass2 from Triton IR to TritonGPU IR, the optimization pass2 for TritonGPU IR, the conversion pass3 from TritonGPU IR to LLVM IR, and the optimization pass3 for LLVM IR, etc. If all passes are proven to be semantically consistent, then the entire compilation process is correct. If the proof fails, different results will be generated according to the type of the pass: if it is an obsolete compilation pass, a compilation error will be returned; if it is an optimization pass, the optimization will be skipped.

[0206] The process framework for semantic consistency verification is as Figure 14 shown:

[0207] Step 1401: By performing syntax and lexical analysis on the input program and output program of this pass, the corresponding grammar unit sequences are obtained, that is, the first grammar sequence and the second grammar sequence in the previous text;

[0208] Step 1402: According to the predefined operation semantics of the grammar units (that is, the first dictionary and the second dictionary in the previous text), combined with the grammar unit sequences, the operation semantics of the source program (that is, the first code) and the target program (that is, the second code) are obtained;

[0209] Step 1403: According to the defined operation semantics of the source program and the target program, semantic consistency propositions are generated;

[0210] Step 1404: Automatically prove the semantic equivalence of the generated semantic consistency propositions. This proof generates a proof sequence (that is, the proof sequence code in the previous text) by automatically applying pre-proof lemmas and proof strategies in Coq.

[0211] All of the above definitions and proofs are completed in the Coq proof assistant. Coq can provide a formal language for writing mathematical definitions, executable algorithms, and theorems, and supports semi-interactive development of machine-checked proofs. Thus, by executing the proof sequences 1 to n corresponding to each compilation operation through Coq, the proof result can be obtained.

[0212] The previous example gave a compilation verification example for the add_kernel code, as well as the method and specific process for proving the semantic consistency in the conversion process from Triton DSL to TritonIR. Based on this method, the semantic preservation of a pass during compilation can be proven. Further, since the relation of semantic equivalence is transitive, for a compiler with multiple intermediate processes, if each process maintains semantic consistency, then the entire compilation process also maintains semantic consistency, that is, the compilation is correct. At the same time, for any program, the above method can be used to automatically determine semantic consistency.

[0213] Therefore, this embodiment implements a trustworthy compilation method for the Triton language based on the Coq theorem prover. That is, during compilation, the input and output of each pass in this process are automatically verified for semantic consistency. If all verifications pass, the compiler outputs a target program with strict semantic preservation, as well as proof sequences for reference. Otherwise, a compilation error is returned, or the optimization with errors is skipped.

[0214] In summary, the technical solution of this application has the following advantages:

[0215] 1. Reduce code errors and vulnerabilities: A compiler verified through formal methods can significantly reduce or even eliminate code vulnerabilities introduced by the compiler. This can not only reduce the number of times developers need to fix errors and vulnerabilities, improving overall development efficiency, but also enhance code security.

[0216] 2. Enhance semantic preservation: In the field of deep learning, the accuracy and performance of models are crucial. Any semantic change may have a significant impact on the output results of the model. A compiler verified through formal methods, since the generated target code is strictly semantically equivalent to the source code logically, effectively avoids the decline in model performance caused by semantic loss during compilation.

[0217] 3. Reduce testing costs and time: The code generated by deep learning compilers often requires a large amount of testing work to discover and fix due to various possible errors and vulnerabilities. Using a compiler verified through formal methods can greatly reduce the number of errors and vulnerabilities in the subsequent testing process, thereby significantly reducing the time costs of testing and error correction.

[0218] 4. Applicable to high-reliability fields: The formal verification-based deep learning compiler can be applied to fields with extremely high requirements for security and reliability, such as aerospace, medical, and finance.

[0219] In this specification, each embodiment is described in a progressive manner. The key point of each embodiment is to illustrate the differences from other embodiments. For the same or similar parts among the embodiments, reference can be made to each other. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple. For the relevant parts, reference can be made to the description in the method section.

[0220] Those skilled in the art can further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in this article can be implemented by electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered as exceeding the scope of this application.

[0221] The steps of the methods or algorithms described in combination with the embodiments disclosed in this article can be directly implemented by hardware, software modules executed by a processor, or a combination of both. The software modules can be placed in a random access memory (RAM), memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium well-known in the technical field.

[0222] The above description of the disclosed embodiments enables those skilled in the art to implement or use this application. Various modifications to these embodiments will be obvious to those skilled in the art. The general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application will not be limited to these embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A data processing method, comprising: Obtaining a first code and a second code, and the compiler compiling the first code to output the second code; The compiling operation is any compiling operation of the compiler during the compiling process; Analyze the first code and the second code respectively to obtain a first grammar sequence and a second grammar sequence, wherein the first grammar sequence includes grammar units analyzed from the first code, and the second grammar sequence includes grammar units analyzed from the second code, wherein the grammar units represent syntax or lexical meaning in the code; Performing a semantic comparison on the first grammar sequence and the second grammar sequence to obtain an operation verification result indicating whether the first code and the second code are semantically consistent; According to the operation verification result, it is determined whether the compiler performs the compilation operation accurately.

2. According to the method of claim 1, performing semantic comparison on the first grammar sequence and the second grammar sequence to obtain an operation verification result indicating whether the first code and the second code are semantically consistent, comprising: Obtaining a first semantic set and a second semantic set according to the first grammar sequence and the second grammar sequence respectively, wherein the first semantic set includes operational semantics corresponding to each grammar unit in the first grammar sequence, and the second semantic set includes operational semantics corresponding to each grammar unit in the second grammar sequence; The first semantic set and the second semantic set are semantically compared to obtain an operation verification result.

3. The method according to claim 2, performing semantic comparison on the first semantic set and the second semantic set to obtain an operation verification result, comprising: constructing a semantic consistency proposition according to the first semantic set and the second semantic set; According to the semantic consistency proposition, a proof sequence code is generated; The certification sequence code includes at least one certification strategy; the certification strategies have an execution order; Executing the proof sequence code to obtain a truth or falsehood result of the semantic consistency proposition; The operation verification result is obtained according to whether the truth or false result of the proposition is true.

4. The method according to claim 3, wherein the certification strategy comprises: Pre-proof of lemmas; The pre-proof lemma is used to provide the proof result of the associated proposition corresponding to the semantic consistency proposition before executing the proof sequence code, and the proof result of the associated proposition is used to obtain the truth or falsity result of the proposition.

5. The method according to claim 2, obtaining a first semantic set and a second semantic set according to the first grammatical sequence and the second grammatical sequence respectively, comprising: In a first dictionary corresponding to the compilation operation, searching for the operational semantics corresponding to each grammatical unit in the first grammar sequence to obtain a first semantic set; In a second dictionary corresponding to the compiling operation, searching for the operational semantics corresponding to each grammar unit in the second grammar sequence to obtain a second semantic set; Among them, the first dictionary includes operational semantics corresponding to multiple grammar units corresponding to the first attribute; the second dictionary includes operational semantics corresponding to multiple grammar units corresponding to the second attribute; the first attribute is the code attribute of the first code, and the second attribute is the code attribute of the second code.

6. The method according to claim 2, wherein the first grammar sequence is a tree structure; the second grammar sequence is a tree structure; in, Each node in the tree structure corresponds to a corresponding grammar unit in the grammar sequence.

7. The method according to claim 1 or 2, further comprising: Obtaining an operation verification result corresponding to each of the compilation operations performed by the compiler to implement the compilation task; Whether the compiler is accurate is determined according to the operation verification result corresponding to each of the compilation operations.

8. The method according to claim 1 or 2, after determining that the compiler performs the compiling operation inaccurately, the method further comprises: In response to the compiling operation being a code conversion operation, outputting prompt information indicating a compiling error, and / or triggering the compiler to re-execute the compiling operation; In response to the compiling operation being a code optimization operation, triggering the compiler to execute a next compiling operation.

9. A data processing device, comprising: A code obtaining unit, used for obtaining a first code and a second code, wherein a compiler performs a compiling operation on the first code and outputs the second code; The compiling operation is any compiling operation of the compiler during the compiling process; a grammar analysis unit, configured to analyze the first code and the second code respectively to obtain a first grammar sequence and a second grammar sequence, wherein the first grammar sequence includes grammar units analyzed from the first code, and the second grammar sequence includes grammar units analyzed from the second code, wherein the grammar units represent syntax or lexical meaning in the code; A semantic comparison unit, configured to perform a semantic comparison on the first grammar sequence and the second grammar sequence to obtain an operation verification result indicating whether the first code and the second code are semantically consistent; The compiling determination unit is used to determine whether the compiler performs the compiling operation accurately according to the operation verification result.

10. An electronic device comprising: A memory, used to store a computer program and data generated by the execution of the computer program; A processor, configured to execute the computer program to implement: A first code and a second code are obtained, and a compiler performs a compiling operation on the first code to output the second code; the compiling operation is any compiling operation performed by the compiler during the compiling process; Analyze the first code and the second code respectively to obtain a first grammar sequence and a second grammar sequence, wherein the first grammar sequence includes grammar units analyzed from the first code, and the second grammar sequence includes grammar units analyzed from the second code, wherein the grammar units represent syntax or lexical meaning in the code; Performing a semantic comparison on the first grammar sequence and the second grammar sequence to obtain an operation verification result indicating whether the first code and the second code are semantically consistent; According to the operation verification result, it is determined whether the compiler performs the compilation operation accurately.