Model training method and apparatus, automatic compiler tuning method and apparatus, and electronic device

Through model training and automatic tuning methods, the compiler's optimization sequence is analyzed and optimized, and the problem of inefficient compilation in the existing technology is solved, and more efficient compiler automatic tuning is achieved.

WO2025051122A1PCT designated stage expired Publication Date: 2025-03-13ZHEJIANG LAB

Patent Information

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

AI Technical Summary

Technical Problem

In the case of a large number of optimization options and complex interactions, existing compilers have difficulty accurately determining the minimum time-consuming tuning strategy, resulting in inaccurate compilation efficiency.

Method used

Using the model training method, by obtaining and analyzing multiple optimization sequences of the target program by the compiler, using neighborhood search algorithms and prediction models, we gradually search for optimization sequences with smaller running times, and build training samples to train prediction models to achieve automatic tuning.

Benefits of technology

It improves the efficiency and accuracy of the compiler's automatic tuning, and can accurately determine the tuning strategy with the least time-consuming, which significantly improves the efficiency of program compilation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024116619_13032025_PF_FP_ABST
    Figure CN2024116619_13032025_PF_FP_ABST
Patent Text Reader

Abstract

A model training method and apparatus, an automatic compiler tuning method and apparatus, and an electronic device. The model training method comprises: obtaining a plurality of optimization sequences for a compiler to compile a target program; randomly determining an initial optimization sequence from among the plurality of optimization sequences as a current optimization sequence for a first iteration, wherein the current optimization sequence corresponds to a current sample point in a search space, and determining a first running time for compiling the target program on the basis of the current optimization sequence; generating a neighboring sample point of the current sample point, and determining a second running time for compiling the target program on the basis of an optimization sequence corresponding to the neighboring sample point; determining whether the first running time is longer than the second running time, and if yes, determining the neighboring sample point as a current sample point of a next iteration; after a specified number of iterations is reached, determining a plurality of candidate optimization sequences having a running time shorter than a preset time, and constructing a training sample on the basis of the plurality of candidate optimization sequences; and training a prediction model by using the constructed training sample.
Need to check novelty before this filing date? Find Prior Art

Description

Model training method and device, compiler automatic tuning method and device, and electronic device Technical Field

[0001] This specification relates to the field of computer technology, and in particular to a model training method and apparatus, a compiler automatic tuning method and apparatus, a computer-readable storage medium, and an electronic device. Background Art

[0002] A compiler is a program that translates a source program written in a high-level programming language into an equivalent target program in machine language format. During the compilation process, the compiler optimizes the translated program, ensuring faster execution and fewer resource usage while maintaining semantic equivalence. Typical compilers often have many optimization options, each of which can be enabled or disabled.

[0003] Due to the large number of optimization options, compiler users may not even understand the function of each optimization option. Moreover, different optimization options often interact with each other, making it difficult for users to determine whether a specific optimization option should be enabled or disabled to shorten the runtime of the compiled target code or reduce the use of hardware resources.

[0004] Therefore, how to accurately determine the compiler tuning strategy that consumes the least time and improve the efficiency of program compilation is an urgent problem to be solved.

[0005] Summary of the Invention

[0006] This specification provides a model training method and device, a compiler automatic tuning method and device, a computer-readable storage medium, and an electronic device to improve the above-mentioned problems existing in the prior art.

[0007] This manual adopts the following technical solutions:

[0008] This manual provides a model training method, including:

[0009] Acquire multiple optimization sequences when the compiler compiles the target program, wherein each optimization sequence corresponds to an optimization option combination;

[0010] Determining a current optimization sequence, wherein an initial optimization sequence is randomly determined from the multiple optimization sequences as the current optimization sequence for a first iteration, wherein the current optimization sequence corresponds to a current sample point in the search space; determining a runtime for compiling the target program according to the current optimization sequence as a first runtime;

[0011] generating neighborhood sample points of the current sample point, and determining a runtime for compiling the target program according to an optimization sequence corresponding to the neighborhood sample points as a second runtime;

[0012] Determine whether the first running time is greater than the second running time, and if so, use the neighborhood sample point as the current sample point for the next iteration;

[0013] After reaching the specified number of iterations, determining several candidate optimization sequences whose running time is less than a preset time, and constructing training samples based on the several candidate optimization sequences;

[0014] Inputting the training samples into a prediction model to be trained, so as to determine a prediction optimization sequence when compiling the target program through the prediction model;

[0015] The prediction model is trained with the training objective of minimizing the deviation between the predicted optimization sequence and the candidate optimization sequence with the smallest running time.

[0016] Optionally, the method further includes obtaining the target program, specifically including: determining a program set; and obtaining each target program in the program set.

[0017] Optionally, a benchmark test suite is employed to determine the set of programs.

[0018] Constructing training samples based on the candidate optimization sequences specifically includes: for each candidate optimization sequence, extracting features from the target program and / or the program compiled by the candidate optimization sequence to obtain input features; and constructing training samples corresponding to the candidate optimization sequence based on the input features and the runtime of compiling the target program by the candidate optimization sequence.

[0019] Optionally, the input feature includes at least one of arithmetic instructions, loop information, memory operations, and parallel information corresponding to the target program.

[0020] Optionally, generating neighborhood sample points of the current sample point specifically includes:

[0021] If the target program has been compiled according to the optimization sequence corresponding to the newly generated neighborhood sample point, the neighborhood sample points are regenerated until neighborhood sample points corresponding to the optimization sequence that has not been compiled are generated as neighborhood sample points of the current sample point.

[0022] Optionally, the optimization sequence corresponding to the current sample point and the optimization sequence corresponding to the neighborhood sample point have one different optimization option.

[0023] This document provides a compiler automatic tuning method, including:

[0024] receiving a compilation request for a program to be compiled;

[0025] Inputting the program to be compiled into a prediction model to determine, by means of the prediction model, an optimal optimization sequence when compiling the program to be compiled by a target compiler, wherein the prediction model is obtained by training using the above-mentioned model training method;

[0026] Execute each optimization option corresponding to the optimal optimization sequence;

[0027] The target compiler is used to compile the program to be compiled according to the optimization options.

[0028] This specification provides a model training device, including:

[0029] An acquisition module is configured to acquire multiple optimization sequences when the compiler compiles the target program, wherein each of the optimization sequences corresponds to a combination of optimization options;

[0030] a determination module, configured to determine a current optimization sequence, wherein an initial optimization sequence is randomly determined from the multiple optimization sequences as the current optimization sequence for a first iteration, wherein the current optimization sequence corresponds to a current sample point in a search space, and to determine a runtime for compiling the target program according to the current optimization sequence as a first runtime;

[0031] a generating module, generating neighborhood sample points of the current sample point, and determining a runtime for compiling the target program according to an optimization sequence corresponding to the neighborhood sample points as a second runtime;

[0032] a judgment module, determining whether the first running time is greater than the second running time, and if so, using the neighborhood sample point as the current sample point for the next iteration;

[0033] A construction module, after reaching a specified number of iterations, determines a number of candidate optimization sequences whose running time is less than a preset time, and constructs training samples based on the number of candidate optimization sequences;

[0034] An input module inputs the training sample into a prediction model to be trained, so as to determine a prediction optimization sequence when compiling the target program through the prediction model;

[0035] The training module trains the prediction model with the goal of minimizing the deviation between the predicted optimization sequence and the candidate optimization sequence with the smallest running time.

[0036] This specification provides a compiler automatic tuning device, including:

[0037] A receiving module receives a compilation request for a program to be compiled;

[0038] a determination module, inputting the program to be compiled into a prediction model to determine, by means of the prediction model, an optimal optimization sequence when the program to be compiled is compiled by a target compiler, wherein the prediction model is obtained by training using the above-mentioned model training method;

[0039] An execution module, executing each optimization option corresponding to the optimal optimization sequence;

[0040] A compiling module compiles the program to be compiled according to the optimization options through the target compiler.

[0041] 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 model training or compiler automatic tuning method.

[0042] This specification provides an electronic device, including 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 model training or compiler automatic tuning method is implemented.

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

[0044] In the model training method provided in this specification, a target program is obtained, and each optimization sequence when the compiler compiles the target program is determined; a current optimization sequence is determined, and a first running time for compiling the target program according to the current optimization sequence is determined; a neighborhood sample point is generated, and a second running time for compiling the target program according to the optimization sequence corresponding to the neighborhood sample point is determined; it is judged whether the first running time is greater than the second running time, and if so, the neighborhood sample point is used as the current sample point for the next round of iteration; after reaching a specified number of iterations, a number of candidate optimization sequences whose running time is less than a preset time are determined, and a training sample is constructed according to each candidate optimization sequence; and a prediction model is trained using the constructed training samples.

[0045] As can be seen from the above method, this solution can gradually search for optimized sequences with shorter runtimes during prediction model training, thereby generating training samples for training the prediction model. Because the optimized sequences are screened to a certain extent, inaccurate data is eliminated, effectively improving the training efficiency and accuracy of the prediction model. In practical applications, this approach requires only inputting the program to be compiled into the model to accurately determine the optimization strategy with the shortest runtime, thereby improving program compilation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] 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:

[0047] FIG1 is a flow chart of a model training method provided in this specification;

[0048] FIG2 is a schematic diagram of an iterative compilation process based on a neighborhood search algorithm provided in this specification;

[0049] FIG3 is a schematic diagram of a process for constructing a training sample set provided in this specification;

[0050] FIG4 is a flow chart of a compiler automatic tuning method provided in this specification;

[0051] FIG5 is a schematic diagram of a compilation process of a program provided in this specification;

[0052] FIG6 is a schematic diagram of a model training device provided in this specification;

[0053] FIG7 is a schematic diagram of a compiler automatic tuning device provided in this specification;

[0054] FIG8 is a schematic diagram of an electronic device provided in this specification corresponding to FIG1 or FIG4 . DETAILED DESCRIPTION

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

[0056] A typical automatic tuning approach begins by defining an optimization space (i.e., search space) and employing a machine learning model as the cost function. In each iteration, a search algorithm based on the cost function is used to search the optimization space. The source program is compiled according to the resulting optimization sequence (an optimization sequence is a combination of optimization options). The compiled executable is run on the hardware to obtain the runtime, which is then added to the training dataset. The cost function model is then updated based on the expanded training dataset. This iterative process continues, ultimately outputting the optimal optimization sequence that minimizes the runtime.

[0057] During this process, a large number of optimization sequences need to be collected to compile and execute the source program. The entire process is time-consuming, resulting in a long tuning time and very high hardware resource consumption.

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

[0059] FIG1 is a flow chart of a model training method provided in this specification, which includes the following steps:

[0060] S101: Acquire multiple optimization sequences when a compiler compiles a target program, wherein each optimization sequence corresponds to an optimization option combination.

[0061] This solution can be divided into a training phase and an application phase. The purpose of the training phase is to train the prediction model. In this specification, the execution entity used to implement the model training method can be a designated device such as a server. For ease of description, this specification uses a server as an example to illustrate the model training method provided herein, but the execution entity is not limited to a server.

[0062] The server can obtain the target program. Specifically, the server first selects a program collection, for example, using benchmark suites commonly used in compiler optimization experiments, such as cBench and Polybench. Then, for each target program in the collection, the server uses an iterative compilation method to collect training samples.

[0063] Specifically, for each target program, a search space is constructed, which is the set of all feasible optimization sequences, where an optimization sequence refers to a combination of optimization options.

[0064] In actual applications, the compiler may have different combinations of optimization options, which are not specifically limited in this specification.

[0065] Assume that the compiler has multiple optimization options, and the value of each optimization option is 0 or 1. For example, for a compiler that contains three optimization options (such as -fcompare-elim, -ftree-forwprop, and -fipa-reference), a possible preferred sequence is (0, 0, 1). At the same time, it is not difficult to obtain that the number of all possible optimization sequences is 2 to the power of 3, a total of 8, that is, the search space size of the program is 8. Then, the search space is searched using a search algorithm. Specifically, the search algorithm can adopt a meta-heuristic algorithm such as neighborhood search or simulated annealing, genetic algorithm, etc. The following describes the model training method provided in this specification using the neighborhood search algorithm as an example.

[0066] S102: Determine a current optimization sequence, wherein an initial optimization sequence is randomly determined from the multiple optimization sequences as the current optimization sequence at the first iteration, wherein the current optimization sequence corresponds to a current sample point in the search space, and determine a runtime for compiling the target program according to the current optimization sequence as a first runtime.

[0067] S103: Generate neighborhood sample points of the current sample point, and determine the runtime required to compile the target program according to the optimization sequence corresponding to the neighborhood sample points as a second runtime.

[0068] S104: Determine whether the first running time is greater than the second running time. If so, use the neighborhood sample point as the current sample point for the next iteration.

[0069] S105: After reaching the specified number of iterations, determine a number of candidate optimization sequences whose running time is less than a preset time, and construct training samples based on the several candidate optimization sequences.

[0070] For ease of understanding, this specification provides a schematic diagram of an iterative compilation process based on a neighborhood search algorithm, as shown in FIG2 .

[0071] FIG2 is a schematic diagram of an iterative compilation process based on a neighborhood search algorithm provided in this specification.

[0072] First, the server can randomly generate initial sample points in the search space, i.e., the initial optimization sequence. The target program is then compiled and executed on the hardware based on the initial optimization sequence, obtaining the corresponding runtime as the first runtime. The current sample point and the first runtime are the initial sample point and runtime, respectively.

[0073] Generate neighborhood sample points for the current sample point (initial optimization sequence) in the search space. If the target program has been compiled based on the optimization sequence corresponding to the newly generated neighborhood sample point, regenerate neighborhood sample points until a neighborhood sample point corresponding to an optimization sequence that has not been compiled is generated as the neighborhood sample point of the current sample point.

[0074] In this specification, various methods can be used to generate the aforementioned neighborhood sample points. In one approach, if the optimization sequence corresponding to the current sample point differs from the optimization sequence corresponding to the neighboring sample point by one optimization option, the neighborhood sample generation rule is as follows: randomly select one optimization option for transformation. For example, assuming there are three optimization options and the current optimization sequence is (0, 0, 1), then (1, 0, 1) and (0, 1, 1) are both its neighborhood samples; however, (1, 1, 1) is not its neighborhood sample because two optimization options differ.

[0075] For the neighborhood sample points of the current sample point, the server may compile the target program according to the optimization sequence corresponding to the neighborhood sample points and execute the target program on the hardware to obtain the corresponding running time as the second running time.

[0076] The server can then compare the running time corresponding to the neighboring sample point and the current sample point. If the running time corresponding to the neighboring sample point is better than the current sample point (the second running time is less than the first running time), the current sample point and the first running time are updated to the neighboring sample point and its running time. Otherwise, the current sample point is not updated.

[0077] The server may perform several iterations according to the above process until a specified number of iterations is reached. The server may select several optimization sequences whose running time is less than a preset time as candidate optimization sequences.

[0078] The server can then construct training samples based on the target program and each candidate optimization sequence. During this process, the server can extract features from the intermediate representation (IR) generated during the compilation process to obtain input features. For each candidate optimization sequence, the server can extract features from the target program and / or the program compiled using the candidate optimization sequence to obtain input features. Based on the input features and the runtime of compiling the target program using the candidate optimization sequence, the server constructs a training sample corresponding to the candidate optimization sequence.

[0079] Specifically, the server can extract features only for the target program or only for the program compiled with the optimized sequence. Of course, it can also extract features for both the target program and the program compiled with the optimized sequence at the same time, and fuse the two extracted features.

[0080] It should be noted that the purpose of feature extraction is to represent the program in a form that can be recognized by the machine learning model. The selection of program features is diverse, such as arithmetic instructions, loop information, memory operations, parallel information, etc. The form of training samples is as follows (feature i ,label i ), where feature i It can represent the features extracted from the target program after the optimized sequence is compiled and / or the features corresponding to the target program that has not been compiled. i The suffix i represents the number of candidate optimization sequences. After the sample is constructed, it is added to the training dataset. For ease of understanding, a schematic diagram of the training sample set construction process is provided in this specification, as shown in Figure 3.

[0081] FIG3 is a schematic diagram of a process for constructing a training sample set provided in this specification.

[0082] Among them, for each source program (target program), the server can determine multiple tuning paths (candidate optimization sequences) through the above method, and then generate training samples corresponding to the source program.

[0083] After the training dataset is built, the server can train the prediction model. The prediction model can use a gradient boosting tree model such as Xgboost or a neural network model.

[0084] S106: Inputting the training samples into the prediction model to be trained, so as to determine the prediction optimization sequence when compiling the target program through the prediction model.

[0085] S107: The prediction model is trained with minimizing the deviation between the predicted optimization sequence and the candidate optimization sequence with the minimum running time as a training goal.

[0086] During the model training process, the server may input the training samples into the prediction model to be trained, so as to determine the prediction optimization sequence when compiling the target program through the prediction model.

[0087] The server may first predict the running time of the target program after compiling it according to different optimization sequences through a prediction model, and then select the predicted optimization sequence.

[0088] The server can then train the prediction model with the training goal of minimizing the deviation between the predicted optimization sequence and the candidate optimization sequence with the smallest actual running time.

[0089] Alternatively, the server can simply predict the runtime for each training sample, then train the prediction model with the goal of minimizing the deviation between the predicted runtime and the actual runtime. Based on the prediction results, the server can determine the optimal sequence with the lowest runtime. The loss function used for regression tasks can be the mean squared error loss.

[0090] After the prediction model is trained, the server can deploy it to perform subsequent compiler automatic tuning tasks.

[0091] The following describes a compiler automatic tuning method provided in this specification from the perspective of practical application.

[0092] FIG4 is a flow chart of a compiler automatic tuning method provided in this specification, which includes the following steps:

[0093] S401: Receive a compilation request for a program to be compiled.

[0094] S402: Inputting the program to be compiled into a prediction model to determine the optimal optimization sequence when the program to be compiled is compiled by a target compiler through the prediction model, wherein the prediction model is obtained by training using the above-mentioned model training method.

[0095] S403: Execute each optimization option corresponding to the optimal optimization sequence.

[0096] S404: Compiling the program to be compiled according to the optimization options using the target compiler.

[0097] In actual applications, the server can input the program to be compiled into the above-mentioned prediction model. Using this prediction model, the server can determine the optimization sequence with the shortest runtime from among the obtained optimization sequences, which is then used as the optimal optimization sequence. The server then executes the optimization options corresponding to the optimal optimization sequence, compiling the program to be compiled using the target compiler according to the optimization options. For ease of understanding, this specification provides a schematic diagram of the program compilation process, as shown in Figure 5.

[0098] FIG5 is a schematic diagram of the compilation process of a program provided in this specification.

[0099] The server can first initialize the prediction model to the above model, then define a search space. Using the prediction model, the server searches for an optimal optimization sequence in the search space according to the above search algorithm and outputs the result. The search process for the optimal optimization sequence is similar to the iterative compilation process in the training phase (e.g., using a neighborhood algorithm to determine the optimal optimization sequence with the shortest execution time among several candidate optimization sequences). This description will not elaborate on this in detail.

[0100] As can be seen from the above method, this solution uses an iterative compilation approach to construct the offline sample dataset, recording sample points along the search path. Compared to random sampling, these sample points correspond to optimization sequences that achieve better target program performance. Therefore, the pre-trained cost function model can more accurately predict the target program's runtime corresponding to high-performance optimization sequences in the search space. This not only makes the sampling process during the training phase more efficient than random sampling, but also allows for less or even no sampling during the application phase, reducing optimization time, improving tuning efficiency, and ultimately enhancing the performance of the target program.

[0101] The above are one or more implementation model deployment methods of this specification. Based on the same idea, this specification also provides corresponding model training and compiler automatic tuning devices, as shown in Figures 6 and 7.

[0102] FIG6 is a schematic diagram of a model training device provided in this specification, including:

[0103] An acquisition module 601 is configured to acquire multiple optimization sequences when a compiler compiles a target program, wherein each optimization sequence corresponds to a combination of optimization options;

[0104] a determination module 602 configured to determine a current optimization sequence, wherein an initial optimization sequence is randomly determined from the multiple optimization sequences as the current optimization sequence for a first iteration, wherein the current optimization sequence corresponds to a current sample point in the search space, and determine a runtime for compiling the target program according to the current optimization sequence as a first runtime;

[0105] A generating module 603 is configured to generate neighborhood sample points of the current sample point, and determine a runtime required to compile the target program according to an optimization sequence corresponding to the neighborhood sample points as a second runtime;

[0106] A judgment module 604 is configured to judge whether the first running time is greater than the second running time, and if so, use the neighborhood sample point as the current sample point for the next iteration;

[0107] A construction module 605 is configured to determine, after reaching a specified number of iterations, a number of candidate optimization sequences having a running time less than a preset time, and construct training samples based on the number of candidate optimization sequences;

[0108] An input module 606 is configured to input the training sample into a prediction model to be trained, so as to determine a prediction optimization sequence when compiling the target program through the prediction model;

[0109] The training module 607 is configured to train the prediction model with the goal of minimizing the deviation between the predicted optimization sequence and the candidate optimization sequence with the minimum running time.

[0110] Optionally, the acquisition module 601 is further configured to acquire the target program, specifically to: determine a program set; and acquire each target program in the program set. Optionally, a benchmark test suite is used to determine the program set.

[0111] Optionally, the construction module 605 is specifically configured to, for each candidate optimization sequence, extract features from the target program and / or a program compiled using the candidate optimization sequence to obtain input features; and construct training samples corresponding to the candidate optimization sequence based on the input features and the runtime of the target program compiled using the candidate optimization sequence. Optionally, the input features include at least one of arithmetic instructions, loop information, memory operations, and parallelism information corresponding to the target program.

[0112] Optionally, the generation module 603 is specifically configured to, if the target program has been compiled according to the optimization sequence corresponding to the newly generated neighborhood sample point, regenerate neighborhood sample points until neighborhood sample points corresponding to the optimization sequence that has not been compiled are generated as neighborhood sample points of the current sample point.

[0113] Optionally, the optimization sequence corresponding to the current sample point and the optimization sequence corresponding to the neighborhood sample point have one different optimization option.

[0114] FIG7 is a schematic diagram of a compiler automatic tuning device provided in this specification, comprising:

[0115] Receiving module 701, used for receiving a compilation request for a program to be compiled;

[0116] a determination module 702 for inputting the program to be compiled into a prediction model to determine, by means of the prediction model, an optimal optimization sequence for compiling the program to be compiled by a target compiler, wherein the prediction model is obtained by training using the above-mentioned model training method;

[0117] An execution module 703 is configured to execute each optimization option corresponding to the optimal optimization sequence;

[0118] The compiling module 704 is configured to compile the program to be compiled according to the optimization options using the target compiler.

[0119] This specification also provides a computer-readable storage medium, which stores a computer program. The computer program can be used to execute a model deployment or compiler automatic tuning method provided in Figure 1 or Figure 4 above.

[0120] This specification also provides a schematic structural diagram of an electronic device corresponding to Figure 1 or Figure 4, as shown in Figure 8. As shown in Figure 8, at the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and of course 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 model deployment method described in Figure 1 or the compiler automatic tuning method described in Figure 4. 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, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0121] Improvements to a technology can be clearly distinguished as either hardware improvements (for example, improvements to circuit structures such as diodes, transistors, and switches) or software improvements (improvements to process flows). However, with technological advancements, 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 a hardware module. 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 onto 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.

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

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

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

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

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

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

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

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

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

[0131] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The 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.

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

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

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

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

[0136] 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 model training method, characterized in that: include: Acquire multiple optimization sequences when the compiler compiles the target program, wherein each of the optimization sequences corresponds to a combination of optimization options; Determine a current optimization sequence, wherein an initial optimization sequence is randomly determined from the multiple optimization sequences as the current optimization sequence in the first iteration, wherein the current optimization sequence corresponds to a current sample point in the search space; Determine a runtime for compiling the target program according to the current optimization sequence as a first runtime; Generate neighborhood sample points of the current sample point, and determine the running time of compiling the target program according to the optimization sequence corresponding to the neighborhood sample points as the second running time; Determine whether the first running time is greater than the second running time, and if so, use the neighborhood sample point as the current sample point for the next iteration; After reaching the specified number of iterations, determining a number of candidate optimization sequences whose running time is less than a preset time, and constructing training samples according to the number of candidate optimization sequences; Inputting the training samples into a prediction model to be trained, so as to determine a prediction optimization sequence when compiling the target program through the prediction model; The prediction model is trained with the training objective of minimizing the deviation between the predicted optimization sequence and the candidate optimization sequence with the smallest running time.

2. The method according to claim 1, characterized in that It also includes obtaining the target program, specifically including: Determine the set of programs; Each target program in the program set is obtained.

3. The method according to claim 2, characterized in that A benchmark test suite is employed to determine the set of programs.

4. The method according to claim 1, characterized in that Constructing training samples according to the candidate optimization sequences specifically includes: For each candidate optimization sequence, extracting features from the target program and / or a program compiled by the candidate optimization sequence to obtain input features; According to the input features and the running time of compiling the target program through the candidate optimization sequence, a training sample corresponding to the candidate optimization sequence is constructed.

5. The method according to claim 4, characterized in that The input feature includes at least one of arithmetic instructions, loop information, memory operations, and parallel information corresponding to the target program.

6. The method according to claim 1, characterized in that Generating the neighborhood sample points of the current sample point specifically includes: If the target program has been compiled according to the optimization sequence corresponding to the newly generated neighborhood sample point, the neighborhood sample points are regenerated until the neighborhood sample points corresponding to the optimization sequence that has not been compiled are generated as the neighborhood sample points of the current sample point.

7. The method according to claim 1, characterized in that The optimization sequence corresponding to the current sample point and the optimization sequence corresponding to the neighborhood sample point have one optimization option different.

8. A compiler automatic tuning method, characterized in that: include: receiving a compilation request for a program to be compiled; Inputting the program to be compiled into a prediction model to determine the optimal optimization sequence when the program to be compiled is compiled by a target compiler through the prediction model, wherein the prediction model is obtained by training the model training method according to any one of claims 1 to 7; Execute each optimization option corresponding to the optimal optimization sequence; The target compiler is used to compile the program to be compiled according to the optimization options.

9. A model training device, characterized in that: include: An acquisition module is used to acquire multiple optimization sequences when the compiler compiles the target program, wherein each of the optimization sequences corresponds to a combination of optimization options; A determination module is configured to determine a current optimization sequence, wherein an initial optimization sequence is randomly determined from the multiple optimization sequences as the current optimization sequence at the first iteration, wherein the current optimization sequence corresponds to a current sample point in the search space, and a running time for compiling the target program according to the current optimization sequence is determined as a first running time; A generating module, generating neighborhood sample points of the current sample point, and determining a running time for compiling the target program according to an optimization sequence corresponding to the neighborhood sample points as a second running time; A judging module, judging whether the first running time is greater than the second running time, and if so, taking the neighborhood sample point as the current sample point of the next iteration; A construction module, after reaching a specified number of iterations, determines a number of candidate optimization sequences whose running time is less than a preset time, and constructs training samples according to the number of candidate optimization sequences; An input module inputs the training sample into a prediction model to be trained, so as to determine a prediction optimization sequence when compiling the target program through the prediction model; The training module trains the prediction model by taking minimizing the deviation between the predicted optimization sequence and the candidate optimization sequence with the smallest running time as a training goal.

10. A compiler automatic tuning device, characterized in that: include: A receiving module receives a compilation request for a program to be compiled; A determination module, inputting the program to be compiled into a prediction model to determine, through the prediction model, an optimal optimization sequence when the program to be compiled is compiled by a target compiler, wherein the prediction model is obtained by training the model training method according to any one of claims 1 to 7; An execution module executes each optimization option corresponding to the optimal optimization sequence; A compiling module compiles the program to be compiled according to the optimization options through the target compiler.

11. 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 8 is implemented.

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

Citation Information

Patent Citations

  • Automatic parameter adjusting method for compiler

    CN115469851A

  • Deep learning model deployment method and device based on search

    CN116306856A

  • Operator optimization method and device, storage medium and electronic equipment

    CN116663618A

  • Method, device and equipment for model training and compiler automatic tuning

    CN116860259A

  • Architecture exploration and compiler optimization using neural networks

    US20210319157A1

Cited By

  • Dynamic binary translation method and device based on neural network assisted simulated annealing

    CN119987787A