CN116204191A - Compiler parameter automatic tuning method based on genetic algorithm - Google Patents

Compiler parameter automatic tuning method based on genetic algorithm Download PDF

Info

Publication number
CN116204191A
CN116204191A CN202310026161.7A CN202310026161A CN116204191A CN 116204191 A CN116204191 A CN 116204191A CN 202310026161 A CN202310026161 A CN 202310026161A CN 116204191 A CN116204191 A CN 116204191A
Authority
CN
China
Prior art keywords
compiling
option
tuned
program
user
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310026161.7A
Other languages
Chinese (zh)
Inventor
史晓华
黄达
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beihang University
Original Assignee
Beihang University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beihang University filed Critical Beihang University
Priority to CN202310026161.7A priority Critical patent/CN116204191A/en
Publication of CN116204191A publication Critical patent/CN116204191A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/37Compiler construction; Parser generation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/12Computing arrangements based on biological models using genetic models
    • G06N3/126Evolutionary algorithms, e.g. genetic algorithms or genetic programming
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The invention provides a compiler parameter automatic optimization method based on a genetic algorithm, and relates to a computer compiler. The method comprises the following steps: recording a compiling option set to be tuned by a user by modifying a tuning option configuration file; compiling a compiling operation script file, reading a compiling option set to be optimized, and operating and outputting program performance data; and performing iterative compiling in a search space formed by the compiling option combinations to be optimized to obtain the optimal compiling option combinations, wherein each iteration trains a cost model based on Xgboost, and program performance data prediction is performed by using the model. The invention can select the compiling option combination which can lead the program performance to reach the best from the compiling option set given by the user, exceeds the compiling option combination provided by the default of the compiler, does not need to modify the user program code and the compiler code, and has better universality and suitability.

Description

Compiler parameter automatic tuning method based on genetic algorithm
Technical Field
The invention belongs to the technical field of computers, and particularly relates to an automatic compiler parameter tuning method based on a genetic algorithm.
Background
The general compilers such as GCC (GNU compiler suite) and LLVM (framework system for constructing the compiler) have hundreds or more compiling optimization options, are oriented to different types of architectures and application programs in different fields, and if different optimization options or parameters are selected, the performances of the finally obtained target codes are different, but the combination of the optimization options and parameters is extremely huge and complex, and the satisfactory and convincing results are difficult to obtain by adopting a traditional manual screening mode based on experience. In general, a compiler developer will provide multiple sets of optimization option combinations for a user, for example, the compilation option combinations provided by GCC by default include-O1, -O2, -O3, and-Os, and the optimization algorithm complexity and compilation time employed by the first three combinations sequentially increase. Through experiments of developers, the combination of the optimization options can achieve better performance on a group of benchmark application programs. However, due to the different effects of target platform, program behavior, data and code distribution, the predefined optimization option combinations tend to fall short of the optimal performance of the target application.
Disclosure of Invention
In order to solve the problems, the invention provides an automatic compiler parameter tuning method based on a genetic algorithm, which can select a compiling option combination which can enable the program performance to be optimal from a compiling option set given by a user and exceeds a compiling option combination provided by a compiler by default, and meanwhile, an automatic tuning tool does not need to modify user program codes and compiler codes, so that the automatic tuning method has better universality and suitability.
The invention provides a compiler parameter automatic tuning method based on a genetic algorithm, which comprises the following steps:
step 1, modifying a tuning preference configuration file, and recording a compiling option set to be tuned by a user;
step 2, compiling a compiling operation script file, compiling and operating the program to be tuned, reading a compiling option set to be tuned currently from the configuration file, replacing the compiling option set to be tuned into a compiling instruction, and outputting tested program performance data into a file performance. Txt after operation;
step 3, iterative compiling is carried out in a search space formed by compiling option combinations to be optimized by a user, and the optimal compiling option combinations are obtained; in the iterative compiling process, a cost model based on Xgboost is established, the input of the model is a feature vector formed by all compiling options to be tuned by a user, the feature vector is output as performance data of a tuned program, and the optimal compiling option combination is determined through the model.
In the step 1, compiling options contained in the tuning preference configuration file are classified into three types: 1 represents a compiling option which must be selected by a user designation; 2 represents a 0/1 type compiling and selecting type, namely, the switch of compiling options is optimized; and 4 represents a numerical compiling option, namely, the value of the compiling option is optimized, and a default value, a minimum value and a maximum value are given in the numerical compiling option.
In the step 3, performing iterative compiling includes the following steps:
(1) Selecting 100 configuration configs from a search space formed by compiling option combinations to be optimized by a user without repetition to form an initial population;
(2) Dividing configs in the current population into two parts, wherein one part compiles and runs the tuned program by utilizing a compiling and running script file, acquiring performance data of the tuned program corresponding to each config, acquiring a training sample of < compiling option combination, performance > for training a cost model based on Xgboost, and the other part directly uses the trained cost model to predict the performance data of the tuned program;
(3) Sorting all configs in the current population according to the performance data of the tuned program, reserving the first 3% of configs in the current population as elites, and carrying out cross mutation and single-gene mutation on all the configs in the current population according to the proportion of 10%;
(4) Forming a new population by the mutated config and the elite reserved in the previous time;
(5) Judging whether iteration is stopped, if so, stopping automatic tuning, continuing the next step, and if not, continuing to perform the step (2);
(6) And storing all the < compiling option combinations, wherein the performance > is in the historical data, and outputting the compiling option combination corresponding to the optimal performance data as the current tuning result.
The invention has the advantages and positive effects that:
(1) The method supports user-defined compiling option sets needing to be optimized, so that tuning parameters exceed compiling option combinations provided by a compiler by default, such as-O2, -O3 of GCC, and the method is more suitable for tuning targets and tuning programs of users;
(2) The method separates the tuning process from the compiling and running process, can realize the selection of different tuning programs and tuning targets by compiling the running script file without compiling, does not need to modify user program codes and compiler codes, and has better universality and suitability;
(3) According to the method, the parameter combination which can enable the program performance to be optimal can be selected from the compiling option set given by a user through iterative compiling, the program performance is predicted by using the cost model based on Xgboost, a large amount of compiling and running time are saved, and the acquisition efficiency of the optimal compiling parameter combination is improved.
Drawings
FIG. 1 is a schematic diagram of an implementation of the compiler parameter auto-tuning method of the present invention;
FIG. 2 is an exemplary diagram of a tuning preference profile in accordance with an embodiment of the present invention;
FIG. 3 is an exemplary diagram of the contents of a compiled runtime script file in accordance with an embodiment of the present invention;
FIG. 4 is a schematic diagram of the process of iterative compilation to automatically tune compiler parameters in accordance with the present invention.
Detailed Description
The invention will be described in further detail with reference to the drawings and examples.
The invention provides a compiler parameter automatic tuning method based on a genetic algorithm, and the implementation principle is shown in figure 1. First, the user needs to define an initial parameter space, i.e., the user is required to determine the compilation option set to be tuned by modifying the tuning preference profile config.
The tuning preference configuration file contains all compiling options which the user wants to tune, and the compiling options are divided into three types: 1 represents a compiling option which must be selected by a user designation; 2 represents a 0/1 type compiling and selecting type, namely, the switch of compiling options is optimized; 4 represents a numerical compiling option, namely, the value of the compiling option is optimized. An example of a tuning preference profile is shown in fig. 2, where the last three values in the numeric compilation option, such as 15,10,190 for the first parameter, represent default, minimum, and maximum values, respectively.
Secondly, considering different compiling and running modes of different programs, the user selects different tuning targets. The automatic tuning tool of the invention separates tuning process from compiling and running process. In order to correctly execute the iterative compiling process, a user needs to write a compiling operation script file for compiling, operating and testing performance of a program to be optimized. The current compiling option set needs to be read from the configuration file config. Txt under the path of the current compiling option set to be replaced in a compiling instruction, and final performance data (only including numbers) needs to be output to the performance. Txt file. The performance file is used for recording test performance data of the executable file obtained by compiling, such as the running time of the executable file obtained by compiling by combining certain compiling options. Thus, the selection function of the tuning program and the tuning target is realized by writing different compiling operation script files. An example of the contents of a compiled runtime script file of an embodiment of the present invention is shown in FIG. 3. Therefore, through compiling the compiling operation script file, the automatic tuning tool correspondingly realized by the invention does not need to modify user program codes and compiler codes, and has better universality and suitability.
The iterative compiling process of the automatic tuning tool is shown in fig. 4, and includes the following steps:
(1) Firstly, initializing, namely, repeatedly selecting 100 configuration configs from a search space formed by compiling option combinations to form an initial population. Each configuration contains a set of values for all the compilation options that the user wants to tune.
(2) Then, according to the partial config in the current population, for example, 50%, the tuned program is compiled and run, the performance data is taken to construct a cost model based on Xgboost (extreme gradient lifting tree), and after the Xgboost is trained by using iterative compiling performance data of < compiling option combination, performance >, the cost model can be used to predict the program performance of various different compiling option combinations. The config which does not actually run directly predicts the performance of the config through Xgboost, so that a great deal of compiling and running time can be saved.
The input of the cost model of Xgboost is a feature vector formed by all compiling options to be tuned by a user, and the feature vector is output as performance data of a tuned program. In the training phase, training samples of < compile options combination, performance > are input into the model for training. In the prediction stage, the compiling options are directly combined and input into the model, and the performance data of the tuned program is predicted and output.
(3) After all configuration configs in the current population acquire program performance data, sequencing all configs according to the height of the corresponding program performance data. The better the program performance data, the earlier the configuration ordering. All configs in the current population were cross mutated and single gene mutated at a rate of 10% and the first 3% of configs in the current population were kept as elite for the next round of iteration.
(4) Then, the mutated config is combined with the elite remaining the previous time to form a new population.
(5) And if the continuous iteration condition is met, continuing to perform the step (2), and iterating according to the rule. Otherwise, the automatic tuning process is exited.
The condition for completing the iteration may be one of two conditions: 1) Config with better performance could not be found for a long time; 2) The manually set upper limit of the number of iterations is exceeded.
(6) All the < compiling option combinations, the performance > data are stored in the history data, and after tuning is completed, the compiling option combination corresponding to the optimal program performance data is output as the tuning result.
Other than the technical features described in the specification, all are known to those skilled in the art. Descriptions of well-known components and well-known techniques are omitted so as to not unnecessarily obscure the present invention. The embodiments described in the above examples are not intended to represent all the embodiments consistent with the present application, and on the basis of the technical solutions of the present invention, various modifications or variations may be made by those skilled in the art without the need for inventive efforts, while remaining within the scope of the present invention.

Claims (5)

1. The compiler parameter automatic tuning method based on the genetic algorithm is characterized by comprising the following steps:
step 1, modifying a tuning preference configuration file, and recording a compiling option set to be tuned by a user;
step 2, compiling a compiling operation script file, compiling and operating the program to be tuned, reading a compiling option set to be tuned currently from the configuration file, replacing the compiling option set to be tuned into a compiling instruction, and outputting tested program performance data into a file performance. Txt after operation;
step 3, iterative compiling is carried out in a search space formed by compiling option combinations to be optimized by a user, and the optimal compiling option combinations are obtained; in the iterative compiling process, a cost model based on Xgboost is established, the input of the model is a feature vector formed by all compiling options to be tuned by a user, the feature vector is output as performance data of a tuned program, and the optimal compiling option combination is determined through the model.
2. The method according to claim 1, wherein in step 1, the compiling options included in the tuning preference profile are classified into three types: 1 represents a compiling option which must be selected by a user designation; 2 represents a 0/1 type compiling and selecting type, namely, the switch of compiling options is optimized; and 4 represents a numerical compiling option, namely, the value of the compiling option is optimized, and a default value, a minimum value and a maximum value are given in the numerical compiling option.
3. The method according to claim 1 or 2, wherein the iterative compiling in step 3 comprises the steps of:
(1) Selecting 100 configuration configs from a search space formed by compiling option combinations to be optimized by a user without repetition to form an initial population;
(2) Dividing configs in the current population into two parts, wherein one part compiles and runs the tuned program by utilizing a compiling and running script file, acquiring performance data of the tuned program corresponding to each config, acquiring a training sample of < compiling option combination, performance > for training a cost model based on Xgboost, and the other part directly uses the trained cost model to predict the performance data of the tuned program;
(3) Sorting all configs in the current population according to the performance data of the tuned program, reserving the first 3% of configs in the current population as elites, and carrying out cross mutation and single-gene mutation on all the configs in the current population according to the proportion of 10%;
(4) Forming a new population by the mutated config and the elite reserved in the previous time;
(5) Judging whether iteration is stopped, if so, stopping automatic tuning, continuing the next step, and if not, continuing to perform the step (2);
(6) And storing all the < compiling option combinations, wherein the performance > is in the historical data, and outputting the compiling option combination corresponding to the optimal performance data as the current tuning result.
4. The method of claim 1, wherein the program performance data is a runtime of the executable file compiled from the compilation option combination.
5. A method according to claim 3, wherein in step 3, the condition for stopping the iteration is one of: 1) The config with better program performance can not be found in the set time; 2) Exceeding a preset upper limit of iteration times.
CN202310026161.7A 2023-01-09 2023-01-09 Compiler parameter automatic tuning method based on genetic algorithm Pending CN116204191A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310026161.7A CN116204191A (en) 2023-01-09 2023-01-09 Compiler parameter automatic tuning method based on genetic algorithm

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310026161.7A CN116204191A (en) 2023-01-09 2023-01-09 Compiler parameter automatic tuning method based on genetic algorithm

Publications (1)

Publication Number Publication Date
CN116204191A true CN116204191A (en) 2023-06-02

Family

ID=86518360

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310026161.7A Pending CN116204191A (en) 2023-01-09 2023-01-09 Compiler parameter automatic tuning method based on genetic algorithm

Country Status (1)

Country Link
CN (1) CN116204191A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116860259A (en) * 2023-09-05 2023-10-10 之江实验室 Method, device and equipment for model training and automatic optimization of compiler
CN116931955A (en) * 2023-09-18 2023-10-24 之江实验室 Compiler automatic optimization method and device based on artificial intelligence
CN116991429A (en) * 2023-09-28 2023-11-03 之江实验室 Compiling and optimizing method, device and storage medium of computer program

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116860259A (en) * 2023-09-05 2023-10-10 之江实验室 Method, device and equipment for model training and automatic optimization of compiler
CN116860259B (en) * 2023-09-05 2023-12-19 之江实验室 Method, device and equipment for model training and automatic optimization of compiler
CN116931955A (en) * 2023-09-18 2023-10-24 之江实验室 Compiler automatic optimization method and device based on artificial intelligence
CN116931955B (en) * 2023-09-18 2024-01-09 之江实验室 Compiler automatic optimization method and device based on artificial intelligence
CN116991429A (en) * 2023-09-28 2023-11-03 之江实验室 Compiling and optimizing method, device and storage medium of computer program
CN116991429B (en) * 2023-09-28 2024-01-16 之江实验室 Compiling and optimizing method, device and storage medium of computer program

Similar Documents

Publication Publication Date Title
CN116204191A (en) Compiler parameter automatic tuning method based on genetic algorithm
Triantafyllis et al. Compiler optimization-space exploration
US9081586B2 (en) Systems and methods for customizing optimization/transformation/ processing strategies
US7533375B2 (en) Program parallelization device, program parallelization method, and program parallelization program
US6308323B1 (en) Apparatus and method for compiling a plurality of instruction sets for a processor and a media for recording the compiling method
US20090193402A1 (en) Iterative Compilation Supporting Entity Instance-Specific Compiler Option Variations
US20010032332A1 (en) Method of generating profile-optimized code
EP3244306B1 (en) A computer-implemented method for allowing modification of a region of original code
CN109086215B (en) Embedded software unit test case generation method and system
Ashouri et al. A Bayesian network approach for compiler auto-tuning for embedded processors
WO2006036504A2 (en) System, method and apparatus for dependency chain processing
Ogilvie et al. Fast automatic heuristic construction using active learning
CN110968321A (en) Tensor calculation code optimization method, device, equipment and medium
CN113407185B (en) Compiler optimization option recommendation method based on Bayesian optimization
JPH10123284A (en) Device for determining control blade disposition for reactor core
Andreou et al. An automatic software test-data generation scheme based on data flow criteria and genetic algorithms
CN112433706B (en) Compiling option tuning method and device, processor chip and server
US20120096247A1 (en) Reconfigurable processor and method for processing loop having memory dependency
CN112990461B (en) Method, device, computer equipment and storage medium for constructing neural network model
CN104809067A (en) Equality constraint-oriented test case generation method and device
CN102455897B (en) Iterative compilation method and device based on embodiment
US20200183658A1 (en) Identification and visualization of associations among code generated from a model and sources that affect code generation
CN112363954B (en) Software dynamic update test method based on object state consistency
CN115222030A (en) Automatic optimization accelerating method for deep learning network operator program
Bashkansky et al. Black box approach for selecting optimization options using budget-limited genetic algorithms

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination