Artificial intelligence-based automatic tuning for compiler

Through the compiler automatic tuning method based on artificial intelligence, the optimal optimization sequence is generated using the intelligent model, which solves the problem of the inoptimal combination of existing compiler optimization options, and achieves the effect of improving operational efficiency and reducing resource consumption.

WO2025060917A1PCT designated stage expired Publication Date: 2025-03-27ZHEJIANG LAB
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/117726
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-09-18
Filing Date
2024-09-09
Publication Date
2025-03-27

AI Technical Summary

Technical Problem

The default optimization option combination provided by existing compilers is often not the optimal solution, resulting in low operational efficiency and waste of resources.

Method used

The compiler automatic tuning method based on artificial intelligence is adopted to extract the sample program features through the intelligent model, generate multiple optimization sequences, and compile and run these sequences through the compiler to record the actual running time. Adjust the probability of the agent model outputting each optimized sequence according to the running time, optimize the training of the agent model to ensure that it outputs the optimal optimized sequence.

Benefits of technology

Generate the optimal optimization sequence through the agent model, significantly improve the operation efficiency of the program, reduce resource consumption, and ensure effective prediction of various types of programs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024117726_27032025_PF_FP_ABST
    Figure CN2024117726_27032025_PF_FP_ABST
Patent Text Reader

Abstract

An artificial intelligence-based automatic tuning method for a compiler. The method comprises: inputting a sample program into an agent model to be trained so as to obtain multiple optimization sequences; on the basis of each optimization sequence, compiling and running the sample program by means of a compiler to obtain the actual running time; and on the basis of the actual running time, adjusting the probability of the agent model outputting each optimization sequence, such that the trained agent model can output an optimal optimization sequence, and the compiler uses the optimal optimization sequence to compile and optimize a program to be run.
Need to check novelty before this filing date? Find Prior Art

Description

AI-based automatic compiler tuning Technical Field

[0001] This specification relates to the field of computer technology, and in particular to automatic compiler tuning based on artificial intelligence. Background Art

[0002] A compiler is a program that translates a source program written in a high-level programming language into an equivalent machine language format. During the compilation process, the compiler optimizes the program, making it run faster and use fewer resources while ensuring semantic equivalence.

[0003] Currently, compilers can provide general optimization option combinations. After selecting an optimization option combination, the compiler can enable each optimization option in the optimization option combination during program execution to optimize program execution.

[0004] However, the default combination of optimization options is often not the optimal optimization solution, which makes it impossible to guarantee that the compiler will execute the program through the optimal optimization solution, resulting in low operating efficiency and waste of resources.

[0005] Summary of the Invention

[0006] The embodiments of this specification provide automatic compiler tuning based on artificial intelligence to improve the problems existing in the above-mentioned prior art.

[0007] The embodiments of this specification adopt the following technical solutions:

[0008] This specification provides an artificial intelligence-based compiler automatic tuning method, including:

[0009] Inputting a sample program into an agent model to be trained so that the agent model extracts features from the sample program and obtains a plurality of optimization sequences based on the extracted feature information, wherein each optimization sequence corresponds to an optimization option combination, and the optimization option combination represents the on / off status of each optimization option among the plurality of optimization options;

[0010] For each of the optimization sequences, compile and run the sample program using the compiler according to the optimization sequence to obtain an actual running time corresponding to the optimization sequence;

[0011] For a first optimization sequence and a second optimization sequence, where the first optimization sequence and the second optimization sequence are any two optimization sequences among the plurality of optimization sequences, and the actual running time corresponding to the first optimization sequence is shorter than the actual running time corresponding to the second optimization sequence, the agent model is trained with a probability that the agent model outputs the first optimization sequence being greater than a probability that the agent model outputs the second optimization sequence as an optimization goal;

[0012] Inputting the program to be run into the trained agent model to obtain an optimized sequence corresponding to the program to be run;

[0013] The program to be run is executed by the compiler according to the optimization sequence corresponding to the program to be run.

[0014] Optionally, obtaining the multiple optimized sequences according to the extracted feature information specifically includes:

[0015] Predicting the on / off information of all optimization options of each optimization sequence based on the extracted feature information to obtain the optimization sequence; and

[0016] Determine the probability of the optimization sequence based on the switch probability of each optimization option;

[0017] Among them, predicting the switch information of all optimization options of each optimization sequence based on the extracted feature information includes: for the optimization sequence, encoding the feature information corresponding to the sample program and the predicted switch information of the first N-1 optimization options through the encoding layer of the intelligent agent model to obtain the encoded feature information, inputting the encoded feature information into the decoding layer of the intelligent agent model to predict the switch probability of the Nth optimization option through the decoding layer, and the switch probability of the optimization option is used to indicate the probability of whether the optimization option is turned on; according to the switch probability of the Nth optimization option, obtaining the switch information of the Nth optimization option, wherein the switch information of the optimization option is used to indicate whether the optimization option is turned on; until the switch information of all optimization options is predicted, the optimization sequence is obtained; wherein N is a positive integer not less than 1.

[0018] Optionally, the agent model is trained with the probability that the agent model outputs the first optimized sequence being greater than the probability that the agent model outputs the second optimized sequence as an optimization goal, specifically comprising:

[0019] After completing each round of training for the agent model, determining whether a preset number of iterations has been reached;

[0020] If so, the training of the agent model is completed;

[0021] If not, the sample program is input into the intelligent agent model so that the intelligent agent model extracts features of the sample program, and based on the extracted feature information, retrieves multiple optimization sequences, and trains the intelligent agent model according to the actual running time corresponding to the retrieved multiple optimization sequences.

[0022] Optionally, inputting the program to be run into a trained agent model to obtain an optimized sequence corresponding to the program to be run specifically includes:

[0023] Determining, in the training set, sample programs that belong to the same program category as the program to be run as reference programs, and determining a proportion of the reference programs in the training set;

[0024] If the proportion is higher than the preset proportion, the step of inputting the program to be run into the trained agent model to obtain an optimized sequence corresponding to the program to be run is executed;

[0025] If the proportion is lower than the preset proportion, the program to be run is used as a sample program to train the agent model, and the optimization sequence corresponding to the program to be run is determined based on the agent model trained with the program to be run.

[0026] This specification provides an artificial intelligence-based compiler automatic tuning device, comprising:

[0027] a feature extraction module, configured to input a sample program into the agent model to be trained, so that the agent model extracts features from the sample program and obtains a plurality of optimization sequences based on the extracted feature information, wherein each optimization sequence corresponds to an optimization option combination, and the optimization option combination represents the on / off status of each optimization option among the plurality of optimization options;

[0028] a running module, configured to compile and run the sample program using the compiler according to each optimization sequence to obtain an actual running time corresponding to the optimization sequence;

[0029] a training module configured to train the agent model with a probability that the agent model outputs the first optimization sequence greater than a probability that the agent model outputs the second optimization sequence, with respect to a first optimization sequence and a second optimization sequence, wherein the first optimization sequence and the second optimization sequence are any two optimization sequences among the plurality of optimization sequences and the actual running time corresponding to the first optimization sequence is shorter than the actual running time corresponding to the second optimization sequence;

[0030] The application module is used to input the program to be run into the trained intelligent agent model to obtain an optimized sequence corresponding to the program to be run; and execute the program to be run through the compiler according to the optimized sequence corresponding to the program to be run.

[0031] Optionally, the agent model includes an encoding layer and a decoding layer; the feature extraction module is specifically used to predict the switching information of all optimization options of each optimization sequence based on the extracted feature information to obtain the optimization sequence; and determine the probability of the optimization sequence based on the switching probability of each optimization option; wherein, when the switching information of all optimization options of each optimization sequence is predicted based on the extracted feature information, the feature extraction module is specifically used to: for the optimization sequence, through the encoding layer of the agent model, the feature information corresponding to the sample program and the predicted first N-1 optimization options are The switching information of the Nth optimization option is encoded to obtain encoded feature information; the encoded feature information is input into the decoding layer of the intelligent agent model to predict the switching probability of the Nth optimization option through the decoding layer, and the switching probability of the optimization option is used to indicate the probability of whether the optimization option is turned on; according to the switching probability of the Nth optimization option, the switching information of the Nth optimization option is obtained, wherein the switching information of the optimization option is used to indicate whether the optimization option is turned on; until the switching information of all optimization options is predicted, the optimization sequence is obtained; wherein N is a positive integer not less than 1.

[0032] Optionally, the training module is specifically used to determine whether a preset number of iterations has been reached after completing each round of training for the intelligent agent model; if so, the training of the intelligent agent model is terminated; if not, the sample program is input into the intelligent agent model so that the intelligent agent model extracts features of the sample program, and based on the extracted feature information, retrieves multiple optimization sequences, and trains the intelligent agent model according to the actual running time corresponding to the retrieved multiple optimization sequences.

[0033] Optionally, the application module is specifically used to determine a sample program in the training set that belongs to the same program category as the program to be run as a reference program, and determine the proportion of the reference program in the training set; if the proportion is higher than a preset proportion, the program to be run is input into the trained intelligent agent model to obtain an optimized sequence corresponding to the program to be run; if the proportion is lower than the preset proportion, the program to be run is used as a sample program to train the intelligent agent model, and the optimized sequence corresponding to the program to be run is determined based on the intelligent agent model trained with the program to be run.

[0034] This specification provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the above-mentioned artificial intelligence-based compiler automatic tuning method.

[0035] This specification provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the above-mentioned method for automatic compiler tuning based on artificial intelligence is implemented.

[0036] At least one of the above technical solutions adopted in the embodiments of this specification can achieve the following beneficial effects:

[0037] In the embodiments of this specification, a sample program is first input into the agent model to be trained, and multiple optimization sequences are obtained based on the characteristic information of the sample program. For each optimization sequence, a compiler compiles and runs the sample program to obtain the actual runtime. For any two optimization sequences, the agent model is trained with the probability that the agent model outputs an optimization sequence with a shorter actual runtime being greater than the probability that the agent model outputs an optimization sequence with a longer actual runtime, thereby obtaining a trained agent model. When the agent model is applied, the program to be run is input into the trained agent model, so that the trained agent model outputs the optimal optimization sequence for the program to be run. The compiler then executes the program to be run using the optimal optimization sequence.

[0038] In this method, a sample program is input into the intelligent agent model to be trained to obtain multiple optimization sequences. The sample program is compiled and run by a compiler according to the multiple optimization sequences. The running time is obtained through actual running to adjust the probability of the intelligent agent model outputting each optimization sequence, so that the intelligent agent model can learn the potential optimization capabilities of various optimization sequences for other programs during the training process, thereby ensuring that the trained intelligent agent model can obtain the optimal optimization sequence according to the feature information of the program to be run, and the compiler executes the program to be run according to the optimal optimization sequence, which will greatly improve the running efficiency of the program to be run and significantly reduce the resource consumption when running the program to be run. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The drawings described herein are used to provide a further understanding of this specification and constitute a part of this specification. The exemplary embodiments and descriptions of this specification are used to explain this specification and do not constitute an improper limitation of this specification. In the drawings:

[0040] FIG1 is a flow chart of an automatic compiler tuning method based on artificial intelligence provided in an embodiment of this specification;

[0041] FIG2 is a schematic diagram of a training process of the method provided in an embodiment of this specification;

[0042] FIG3 is a schematic diagram of the structure of an automatic compiler tuning device based on artificial intelligence provided in an embodiment of this specification;

[0043] FIG4 is a schematic diagram of the structure of an electronic device provided in an embodiment of this specification. DETAILED DESCRIPTION

[0044] To make the objectives, technical solutions, and advantages of this specification more clear, the following will clearly and completely describe the technical solutions of this specification in conjunction with the specific embodiments of this specification and the corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without making any creative efforts are within the scope of protection of this specification.

[0045] The technical solutions provided by the embodiments of this specification are described in detail below with reference to the accompanying drawings.

[0046] FIG1 is a flow chart of an automatic compiler tuning method based on artificial intelligence provided in an embodiment of this specification, which includes the following steps S100 - S110 .

[0047] S100: Obtain a sample program.

[0048] In practical applications, compilers often have numerous optimization options that facilitate program execution. For example, in the GNU Compiler Collection (GCC) in the GNU operating system, enabling the -fdce optimization option causes the compiler to perform dead code elimination.

[0049] However, due to the large number of optimization options, compiler users may not even understand the function of each optimization option. At the same time, different optimization options often interact with each other, making it difficult for compiler users to determine whether to enable or disable an optimization option to make the compiled code run faster or use fewer resources.

[0050] To address the above issues, compilers currently generally provide general optimization option combinations, such as the different optimization option combinations -O1, -O2, and -O3 in GCC. The compiler selects the optimization option combination according to the user's needs and uses the optimization option combination to execute the program.

[0051] However, the default combination of optimization options is often not the optimal optimization solution. Therefore, this method cannot guarantee that the compiler will execute the program through the optimal optimization solution, resulting in low operating efficiency and waste of resources.

[0052] In order to solve the above problems, in the embodiments of this specification, the agent-based model (ABM) is first trained using a sample program. The sample program is input into the agent model to obtain various optimization sequences. The compiler compiles and runs the sample program according to each optimization sequence to obtain the actual running time, and the optimal running time is obtained based on this. The optimization sequence corresponding to the optimal running time is used as the optimal optimization sequence. Then, the agent model training is guided according to the optimal optimization sequence, so that the trained agent model can output the optimal optimization sequence according to the feature information of the program. In this way, the compiler uses the optimal optimization sequence to execute the program, which will maximize the performance of the program, thereby improving the operating efficiency and reducing resource waste to a certain extent.

[0053] The AI-based automatic compiler tuning method provided in this specification can be executed by a terminal device such as a desktop computer or laptop computer, or by a server. For ease of description, the AI-based automatic compiler tuning method provided in this specification will be described using a terminal device as an example.

[0054] Next, the terminal device needs to train the intelligent agent model first.

[0055] Specifically, in the embodiments of this specification, a terminal device obtains a sample program. The sample program mentioned here may be a program selected manually. It should be noted that, in order for the agent model to accurately predict various types of programs, a training set containing numerous sample programs may be obtained during the actual training process. This training set may include sample programs of various types.

[0056] In this way, after training the intelligent agent model through this training set, the intelligent agent model can learn the characteristics of various types of programs. Therefore, in practical applications, the intelligent agent model can give the corresponding optimal optimization sequence for various types of programs, thereby ensuring that the compiler can significantly improve the efficiency of program operation when running various types of programs.

[0057] S102: Input the sample program into the intelligent agent model to be trained so that the intelligent agent model extracts features of the sample program and obtains multiple optimization sequences based on the extracted feature information, wherein each optimization sequence corresponds to an optimization option combination, and the optimization option combination represents the on / off status of each optimization option.

[0058] In the embodiment of this specification, the terminal device inputs the sample program into the intelligent agent model to be trained, so that the intelligent agent model extracts features of the sample program and obtains various optimization sequences based on the extracted feature information.

[0059] Feature information is used to characterize the characteristics of a program. After a sample program is fed into the agent model to be trained, the agent model analyzes the features of the entire sample program through methods such as semantic and syntactic analysis, extracting the feature information needed to predict the optimal sequence for that sample program.

[0060] In this specification, the dimension of feature information can be determined according to actual needs. For example, taking static features as an example, the extracted feature information can be used to reflect the arithmetic instructions and instruction cycle information used by the sample program.

[0061] In this specification, the agent model can have various forms. For example, the above-mentioned agent model can further include an encoding layer and a decoding layer. In this case, after the terminal device inputs the sample program into the agent model to be trained and obtains feature information, the feature information of the sample program is first input into the encoding layer of the agent model to encode the feature information of the sample program through the encoding layer, and the encoding vector is output after passing through the multi-layer neural network in the encoding layer. Then, the encoding vector is input into the decoding layer of the agent model. The decoding layer uses a recurrent neural network to predict the switching probability of the first optimization option based on the input feature vector, and obtains the switching information of the first optimization option based on the switching probability. The switching information mentioned here is used to reflect the switching status of the first optimization option, that is, whether the first optimization option is turned on or off.

[0062] Then, when predicting the switching probability and switching situation of the second optimization option, the predicted switching information of the first optimization option and the characteristic information of the sample program are input into the encoding layer of the intelligent agent model, encoded through the multi-layer neural network of the encoding layer, and the encoding vector is output. The encoding vector is then input into the decoding layer of the intelligent agent model to predict the switching probability and switching information of the second optimization option.

[0063] Similarly, after the terminal device actually inputs the sample program into the intelligent agent model to be trained, the intelligent agent model will encode the feature information corresponding to the sample program and the predicted on / off information of the first N-1 optimization options through the encoding layer to obtain encoded feature information. The encoded feature information is then input into the decoding layer to predict the on / off probability of the Nth optimization option through the decoding layer. Based on the on / off probability of the Nth optimization option, the on / off information of the Nth optimization option is obtained, and the on / off information of the Nth optimization option is obtained. This process continues until the on / off information of all optimization options is predicted, thereby obtaining an optimization sequence. Here, N is a positive integer not less than 1.

[0064] Through the above approach, the agent model can predict multiple optimization sequences. At the same time, for any optimization sequence, the probability of the agent model outputting the optimization sequence can be determined based on the on / off probabilities of each optimization option in the optimization sequence.

[0065] The following example illustrates the probability of outputting an optimized sequence for the agent model. Here, the probability of outputting an optimized sequence is defined as Among them, X represents the optimization sequence, p(X|code) represents the probability that the agent model can obtain the optimization sequence, and p(x i |x 0:i-1 ,code) is the probability of whether one of the optimization options in the optimization sequence is turned on, that is, the probability of the corresponding optimization option being turned on is determined by sampling the 0-1 distribution of the optimization option. It is the product of the probabilities of whether all optimization options are turned on or not. Based on this, the intelligent agent model can obtain the probability value of outputting the optimization sequence.

[0066] S104: For each optimization sequence, compile and run the sample program using a compiler according to the optimization sequence to obtain an actual running time corresponding to the optimization sequence.

[0067] After obtaining the optimization sequences output by the agent model in the above manner, it is necessary to clearly determine which optimization sequences can significantly improve the execution efficiency of the program. Therefore, in this specification, the terminal device can use a compiler to run the sample program according to the optimization sequences output by the agent model.

[0068] That is, for each optimization sequence output by the agent model, the compiler can use the on / off combinations of the optimization options in the optimization sequence to execute the sample program. While the compiler is executing the sample program, the terminal device can monitor the runtime of the sample program and thereby determine the time the compiler spent executing the sample program according to the optimization sequence, i.e., the actual runtime corresponding to the optimization sequence.

[0069] S106: For the first optimization sequence and the second optimization sequence, the first optimization sequence and the second optimization sequence are any two optimization sequences among the multiple optimization sequences, and the actual running time corresponding to the first optimization sequence is shorter than the actual running time corresponding to the second optimization sequence, and the probability that the intelligent agent model outputs the first optimization sequence is greater than the probability that the intelligent agent model outputs the second optimization sequence is used as an optimization goal, and the intelligent agent model is trained.

[0070] After running the above sample program according to each optimization sequence through the compiler, the actual running time corresponding to each optimization sequence and the probability of the intelligent agent model outputting each optimization sequence can be obtained.

[0071] To ensure that the trained agent model can output the optimal optimization sequence, the agent model can be trained with the goal of increasing the probability that the agent model will output the optimized sequence as the actual runtime of the optimized sequence decreases. This allows the agent model to learn the potential optimization capabilities of various optimization sequences for sample programs during training, ultimately ensuring that the trained agent model can output the optimal optimization sequence for the sample program—the one with the shortest runtime.

[0072] That is to say, for any two optimization sequences output by the agent model, the agent model is actually trained with the optimization goal that the probability that the agent model outputs the optimization sequence with a shorter actual running time is greater than the probability that the agent model outputs the optimization sequence with a longer actual running time.

[0073] FIG2 is a schematic diagram of the training process of the method provided in the embodiment of this specification.

[0074] First, the agent model parameters are initialized and the number of iterations is set. In each iteration after initialization, the terminal device uses a policy gradient algorithm to update the agent model parameters based on the probabilities of each optimization sequence output by the agent model in the previous iteration and the actual runtime of the compiler after compiling and running the sample program using each optimization sequence. This results in an updated agent model.

[0075] The terminal device can then determine whether the preset number of iterations has been reached. If it is determined that the preset number of iterations has not been reached, the updated agent model can be used to perform feature extraction on the sample program to obtain the optimization sequences output by the current iteration round, i.e., the newly obtained optimization sequences. Since the parameters of the agent model may be updated compared to the agent model of the previous iteration round, the optimization sequences output by the agent model of the current iteration round may differ from the optimization sequences output by the agent model of the previous iteration round.

[0076] Furthermore, for each optimization sequence outputted in the current iteration round, the compiler uses these optimization sequences to run the sample program, thereby determining the time consumed by the compiler to execute the sample program according to each optimization sequence, that is, the actual running time corresponding to each optimization sequence.

[0077] The terminal device then uses a policy gradient algorithm to update the parameters of the agent model based on the probabilities of each optimization sequence output by the agent model and the actual runtime of the compiler after compiling and running the sample program using each optimization sequence. This results in an updated agent model for the current iteration. This process continues until the preset number of iterations is reached, or the model parameters of the agent model have converged to within a preset range. This means that the agent model training is complete, resulting in a trained agent model.

[0078] In this specification, the model training process can be performed by defining a loss function, which can be defined as J(θ|code)=E X~p(﹒|code) f(X|code), where E X~p(﹒|code) f(X|code) actually indicates a negative correlation: the shorter the actual runtime of the optimized sequence, the higher the probability that the agent model will output that optimized sequence. Conversely, the longer the actual runtime of the optimized sequence, the lower the probability that the agent model will output that optimized sequence. Therefore, it can be understood that the agent model is trained in the expectation that the trained agent model will satisfy this negative correlation. θ represents the parameters of the agent model, and f(X|code) refers to the runtime obtained by the compiler compiling and running the sample program according to the optimized sequence X output by the agent model. Indicates the probability of the optimized sequence X appearing.

[0079] In addition, the above loss function can be approximated by using the Monte Carlo algorithm, that is, Among them, b(code) represents the preset running time threshold. After a round of iteration, the shorter the running time of the optimization sequence compared with the running time threshold, the greater the probability that the intelligent model will output the optimization sequence. That is, The larger the value, the greater the The larger the value is. The longer the running time of the optimization sequence is compared with the running time threshold, the smaller the probability value of the optimization sequence output by the intelligent agent model should be. The smaller it is, the The smaller the value.

[0080] From this, we can see that in the above training process, the agent model can actually be trained with the loss function minimized as the optimization goal. In other words, the above process can be understood as optimizing the parameters of the agent model by increasing the probability that the agent model outputs the optimization sequence with the shortest running time, and by reducing the probability that the agent model outputs the optimization sequence with a longer running time.

[0081] As can be seen from the above formula, the terminal device updates the parameters of the intelligent agent model through the above loss function. In fact, it is hoped that the loss value of the loss function is as small as possible, that is, it is hoped that the probability that the intelligent agent model can output an optimization sequence with a shorter actual running time is as large as possible. This can ensure that the trained intelligent agent model can output the optimal optimization sequence.

[0082] The agent model quantifies the probability of each optimization option occurring and its on / off state. The terminal device outputs the probability of each optimization sequence based on its actual run time and the agent model. The agent model parameters are then updated using a loss function. The agent model parameters are then optimized through continuous iteration. In this way, a trained agent model can output the optimal optimization sequence for the program to be run.

[0083] S108: Inputting the program to be run into the trained agent model to obtain an optimization sequence corresponding to the program to be run, thereby executing the program to be run through the compiler according to the optimization sequence corresponding to the program to be run.

[0084] After training the agent model in the above manner, the trained agent model can be deployed in real-world applications. In the embodiments of this specification, for a program to be run, the feature information of the program to be run can be input into the trained agent model, which can then output an optimized sequence corresponding to the program to be run. Since the agent model has already completed the above training, it can be assumed that the output of the trained agent model is the optimal optimized sequence.

[0085] The terminal device can execute the program to be run according to the optimization sequence output by the trained agent model. Specifically, the optimization sequence output by the agent model is fed to the compiler, which then adjusts the on / off states of various optimization options according to the optimization sequence before running the program. The compiler then executes the program to be run.

[0086] Of course, since the proportion of sample programs of different types in the training set used during training varies, the trained agent model's predictive power for different types of programs also varies. To ensure that the agent model can output an accurate optimization sequence, in this specification, the terminal device can first determine the program type of the program to be run. Then, from the training set used during the model training phase, it can identify sample programs of that type as reference programs, and determine the proportion of the reference programs in the training set.

[0087] If the percentage is lower than the preset percentage, it indicates that the sample programs of this program type account for a small proportion in the training set, resulting in the trained agent model being unable to make good predictions for these sample programs. Therefore, the program to be run can be used as a sample program and the agent model can be further trained using the above method. The trained agent model can then be used to determine the optimal sequence for the program to be run.

[0088] If the percentage is determined to be at least the preset percentage, this indicates that the sample programs of this type account for a large proportion in the training set, and the trained agent model is able to make good predictions for sample programs of this type. Therefore, the feature information of the program to be run can be directly input into the agent model to obtain an optimized sequence for the program to be run.

[0089] S110: Executing the program to be run through the compiler according to the optimization sequence corresponding to the program to be run.

[0090] In the embodiments of this specification, the compiler executes the program to be run according to the switch combination of each optimization option in the optimal optimization sequence obtained according to the above content. As can be seen from the above method, the sample program is input into the intelligent agent model to obtain each optimization sequence, and the compiler compiles and runs the sample program according to each optimization sequence. The runtime is obtained through actual operation to adjust the probability corresponding to each optimization sequence output by the intelligent agent model, so that the intelligent agent model can learn the potential optimization capabilities of various optimization sequences for the sample program during the training process, thereby ensuring that the trained intelligent agent model can obtain the optimal optimization sequence based on the feature information of the program to be run. The compiler executes the program to be run according to the optimal optimization sequence, which will maximize the program's operating efficiency and significantly reduce resource consumption when running the program.

[0091] Furthermore, since the training set used in the training phase contains various types of sample programs, it can be ensured that the trained intelligent agent model can effectively predict various types of programs, thereby increasing the application scope of the intelligent agent model.

[0092] The above is an artificial intelligence-based compiler automatic tuning method provided in the embodiments of this specification. Based on the same idea, this specification also provides corresponding devices, storage media and electronic devices.

[0093] FIG3 is a schematic structural diagram of an artificial intelligence-based compiler automatic tuning device provided in an embodiment of this specification. The device includes the following modules 301 - 305 .

[0094] The acquisition module 301 is used to acquire a sample program.

[0095] Feature extraction module 302 is configured to input the sample program into the agent model to be trained, so that the agent model extracts features from the sample program and, based on the extracted features, generates multiple optimization sequences. Each optimization sequence corresponds to a combination of optimization options, each of which represents the on / off state of each optimization option.

[0096] The running module 303 is configured to compile and run the sample program using a compiler according to each optimization sequence to obtain an actual running time corresponding to the optimization sequence.

[0097] The training module 304 is used to train the intelligent agent model with the probability that the intelligent agent model outputs the first optimization sequence greater than the probability that the intelligent agent model outputs the second optimization sequence, for a first optimization sequence and a second optimization sequence, where the first optimization sequence and the second optimization sequence are any two optimization sequences among the multiple optimization sequences, and the actual running time corresponding to the first optimization sequence is shorter than the actual running time corresponding to the second optimization sequence.

[0098] The application module 305 is used to input the program to be run into the trained agent model to obtain an optimization sequence corresponding to the program to be run; and execute the program to be run through the compiler according to the optimization sequence corresponding to the program to be run.

[0099] Optionally, the agent model includes an encoding layer and a decoding layer;

[0100] The feature extraction module 302 is specifically configured to: predict the on / off information of all optimization options of each optimization sequence based on the extracted feature information to obtain the optimization sequence; and determine the probability of the optimization sequence based on the on / off probability of each optimization option. When predicting the on / off information of all optimization options of each optimization sequence based on the extracted feature information, the feature extraction module 302 is specifically configured to: encode the feature information corresponding to the sample program and the predicted on / off information of the first N-1 optimization options through the encoding layer of the agent model for the optimization sequence to obtain encoded feature information; input the encoded feature information into the decoding layer of the agent model to predict the on / off probability of the Nth optimization option through the decoding layer, wherein the on / off probability of the optimization option is used to indicate the probability of whether the optimization option is turned on; obtain the on / off information of the Nth optimization option based on the on / off probability of the Nth optimization option, wherein the on / off information of the optimization option is used to indicate whether the optimization option is turned on; and until the on / off information of all optimization options is predicted, the optimization sequence is obtained; wherein N is a positive integer not less than 1.

[0101] Optionally, the training module 304 is specifically configured to determine whether a preset iteration round has been reached after completing each round of training for the agent model.

[0102] If yes, training of the agent model is completed. If no, a sample program is input into the agent model so that the agent model extracts features from the sample program, and based on the extracted feature information, multiple optimization sequences are retrieved, and the agent model is trained based on the actual running times corresponding to the multiple optimized sequences.

[0103] Optionally, the application module 305 is specifically used to determine, in the training set used in the model training stage, a sample program that belongs to the same program category as the program to be run as a reference program, and determine the proportion of the reference program in the training set; if the proportion is higher than a preset proportion, the program to be run is input into the trained intelligent agent model to obtain an optimized sequence corresponding to the program to be run; if it is determined that the proportion is lower than the preset proportion, the program to be run is used as a sample program to train the intelligent agent model, and the optimized sequence corresponding to the program to be run is determined based on the intelligent agent model trained with the program to be run.

[0104] This specification also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it can be used to execute the artificial intelligence-based compiler automatic tuning method provided in Figure 1 above.

[0105] Based on the AI-based automatic compiler tuning method shown in FIG1 , the embodiments of this specification also provide a schematic diagram of the structure of an electronic device shown in FIG4 . As shown in FIG4 , at the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and may also include hardware required for other services. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to implement the AI-based automatic compiler tuning method described in FIG1 .

[0106] Of course, in addition to software implementation, this specification does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0107] In the 1990s, technological improvements could be clearly distinguished as either hardware improvements (for example, improvements to circuit structures like diodes, transistors, and switches) or software improvements (improvements to process flows). However, with the advancement of technology, many process flow improvements today can now be considered direct improvements to hardware circuit structures. Designers almost always create the corresponding hardware circuit structure by programming the improved process flow into the hardware circuit. Therefore, it cannot be said that a process flow improvement cannot be implemented using hardware modules. For example, a programmable logic device (PLD), such as a field programmable gate array (FPGA), is an integrated circuit whose logical function is determined by user programming. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to hire a chip manufacturer to design and manufacture a dedicated integrated circuit chip. Moreover, nowadays, instead of manually fabricating integrated circuit chips, this programming is mostly done using "logic compiler" software. This is similar to the software compiler used when developing programs. Before compilation, the original code must also be written in a specific programming language, called a hardware description language (HDL). There is not just one HDL, but many, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used are VHDL (Very-High-Speed ​​Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art will also understand that by simply programming the method flow in one of these hardware description languages ​​and then programming it into an integrated circuit, a hardware circuit that implements the logic method flow can be easily obtained.

[0108] The controller can be implemented in any suitable manner. For example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also know that in addition to implementing the controller in a purely computer-readable program code format, the controller can be implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, such a controller can be considered a hardware component, and the devices included therein for implementing various functions can also be considered as structures within the hardware component. Or even, the devices for implementing various functions can be considered as both software modules that implement the method and structures within the hardware component.

[0109] The systems, devices, modules, or units described in the above embodiments may be implemented by computer chips or entities, or by products having certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.

[0110] For the convenience of description, the above devices are described as being divided into various units according to their functions. Of course, when implementing this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.

[0111] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0112] This specification is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of this specification. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0113] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0114] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0115] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0116] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

[0117] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0118] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.

[0119] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems, or computer program products. Thus, this specification may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0120] This specification may be described in the general context of computer-executable instructions, such as program modules, executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, and the like that perform specific tasks or implement specific abstract data types. This specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media, including storage devices.

[0121] The various embodiments in this specification are described in a progressive manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the system embodiments are generally similar to the method embodiments, so the description is relatively simple. For relevant parts, refer to the description of the method embodiments.

[0122] The foregoing is merely an example of the present invention and is not intended to limit the present invention. Various modifications and variations are possible for those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention are intended to be included within the scope of the claims of the present invention.

Claims

1. A compiler automatic tuning method based on artificial intelligence, characterized in that: include: Inputting the sample program into the intelligent agent model to be trained, so that the intelligent agent model extracts features of the sample program, and obtains multiple optimization sequences according to the extracted feature information, wherein each of the optimization sequences corresponds to an optimization option combination, and the optimization option combination represents the switch status of each optimization option among the multiple optimization options; For each of the optimization sequences, the sample program is compiled and run by the compiler according to the optimization sequence to obtain an actual running time corresponding to the optimization sequence; For a first optimization sequence and a second optimization sequence, the first optimization sequence and the second optimization sequence are any two optimization sequences among the multiple optimization sequences, and the actual running time corresponding to the first optimization sequence is shorter than the actual running time corresponding to the second optimization sequence, taking the probability that the agent model outputs the first optimization sequence as a greater probability than the probability that the agent model outputs the second optimization sequence as an optimization goal, training the agent model; Inputting the program to be run into the trained agent model to obtain an optimized sequence corresponding to the program to be run; The program to be run is executed by the compiler according to the optimization sequence corresponding to the program to be run.

2. The method according to claim 1, characterized in that According to the extracted feature information, the multiple optimization sequences are obtained, specifically including: Predicting the switch information of all optimization options of each optimization sequence according to the extracted feature information to obtain the optimization sequence; and According to the switching probability of each optimization option, the probability of the optimization sequence is determined; Among them, predicting the switch information of all optimization options of each optimization sequence according to the extracted feature information to obtain the optimization sequence includes: For the optimization sequence, encoding the feature information corresponding to the sample program and the switch information of the predicted first N-1 optimization options through the encoding layer of the agent model to obtain encoded feature information; Inputting the encoded feature information into a decoding layer of the agent model to predict the switch probability of the Nth optimization option through the decoding layer, where the switch probability of the optimization option is used to indicate the probability of whether the optimization option is turned on; Obtaining switch information of the Nth optimization option according to the switch probability of the Nth optimization option, wherein the switch information of the optimization option is used to indicate whether the optimization option is turned on; Until the switch information of all optimization options is predicted, the optimization sequence is obtained; Wherein, N is a positive integer not less than 1.

3. The method according to claim 1, characterized in that The optimization objective is that the probability that the agent model outputs the first optimization sequence is greater than the probability that the agent model outputs the second optimization sequence, and the agent model is trained, specifically comprising: After completing each round of training for the agent model, determining whether a preset number of iterations has been reached; If so, the training of the intelligent agent model is completed; If not, the sample program is input into the intelligent agent model so that the intelligent agent model extracts features from the sample program, and based on the extracted feature information, retrieves multiple optimization sequences, and trains the intelligent agent model according to the actual running times corresponding to the retrieved multiple optimization sequences.

4. The method according to claim 1, characterized in that Inputting the program to be run into the trained agent model to obtain an optimized sequence corresponding to the program to be run, specifically including: Determine in the training set sample programs that belong to the same program category as the program to be run as reference programs, and determine the proportion of the reference programs in the training set; If the proportion is higher than the preset proportion, the step of inputting the program to be run into the trained agent model to obtain an optimized sequence corresponding to the program to be run is executed; If the proportion is lower than the preset proportion, the program to be run is used as a sample program to train the agent model, and the optimization sequence corresponding to the program to be run is determined based on the agent model trained with the program to be run.

5. An automatic compiler tuning device based on artificial intelligence, characterized in that: include: A feature extraction module, used for inputting a sample program into the intelligent agent model to be trained, so that the intelligent agent model extracts features of the sample program, and obtains a plurality of optimization sequences according to the extracted feature information, wherein each of the optimization sequences corresponds to an optimization option combination, and the optimization option combination represents the switch status of each optimization option among the plurality of optimization options; A running module, used for compiling and running the sample program through the compiler according to each optimization sequence to obtain an actual running time corresponding to the optimization sequence; a training module, configured to train the agent model with a probability that the agent model outputs the first optimization sequence greater than a probability that the agent model outputs the second optimization sequence, for a first optimization sequence and a second optimization sequence, wherein the first optimization sequence and the second optimization sequence are any two optimization sequences among the plurality of optimization sequences, and the actual running time corresponding to the first optimization sequence is shorter than the actual running time corresponding to the second optimization sequence, taking as an optimization target a probability that the agent model outputs the first optimization sequence greater than a probability that the agent model outputs the second optimization sequence; The application module is used to input the program to be run into the trained agent model to obtain the optimization sequence corresponding to the program to be run; according to the optimization sequence corresponding to the program to be run, the compiler is used to execute the Program to be run.

6. The device according to claim 5, characterized in that The agent model includes an encoding layer and a decoding layer; the feature extraction module is specifically used for: Predicting the switch information of all optimization options of each optimization sequence according to the extracted feature information to obtain the optimization sequence; and According to the switching probability of each optimization option, the probability of the optimization sequence is determined; When the switch information of all optimization options of each optimization sequence is predicted according to the extracted feature information to obtain the optimization sequence, the feature extraction module is specifically used for: For the optimization sequence, encoding the feature information corresponding to the sample program and the predicted switch information of the first N-1 optimization options through the encoding layer of the agent model to obtain encoded feature information; Inputting the encoded feature information into the decoding layer of the agent model to predict the switch probability of the Nth optimization option through the decoding layer, where the switch probability of the optimization option is used to indicate the probability of whether the optimization option is turned on; Obtaining switch information of the Nth optimization option according to the switch probability of the Nth optimization option, wherein the switch information of the optimization option is used to indicate whether the optimization option is turned on; Until the switch information of all optimization options is predicted, the optimization sequence is obtained; Wherein, N is a positive integer not less than 1.

7. The device according to claim 5, characterized in that The training module is specifically used to determine whether a preset number of iterations has been reached after completing each round of training for the agent model; If so, the training of the intelligent agent model is completed; If not, the sample program is input into the intelligent agent model so that the intelligent agent model extracts features from the sample program, and based on the extracted feature information, retrieves multiple optimization sequences, and trains the intelligent agent model according to the actual running times corresponding to the retrieved multiple optimization sequences.

8. The device according to claim 5, characterized in that The application module is specifically used to determine, in a training set, sample programs that belong to the same program category as the program to be run as reference programs, and determine the proportion of the reference programs in the training set; If the proportion is higher than the preset proportion, the program to be run is input into the trained agent model to obtain an optimized sequence corresponding to the program to be run; If the proportion is lower than the preset proportion, the program to be run is used as a sample program to train the agent model, and the program to be run is determined according to the agent model trained with the program to be run. The corresponding optimized sequence.

9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Optimization method and device for game agent training, terminal device and storage medium

    CN109663359A

  • Compiler optimization option recommendation method based on Bayesian optimization

    CN113407185A

  • Automatic compiler tuning method and device based on artificial intelligence

    CN116931955A

  • Optimized compilation using an auto-tuned compiler as a service

    US20170123773A1