A compiler collaborative optimization method and system based on Wasserstein distance and Bayesian Thompson sampling
Through the compiler co-optimization method of Wasserstein distance and Bayesian Thompson sampling, the distribution evaluation distortion and exploration-exploitation imbalance problems in compiler automatic tuning are solved, achieving more efficient compiler parameter optimization and cross-platform tuning, and improving compiler performance and search efficiency.
Patent Information
- Application Number
- CN202510990752.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-18
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2045-07-18
AI Technical Summary
Existing compiler automatic tuning technologies suffer from problems such as distribution evaluation distortion, exploration-exploitation imbalance, and difficulty in cross-platform tuning, which results in compiler performance failing to reach hardware peak.
A compiler co-optimization method based on Wasserstein distance and Bayes-Thompson sampling is adopted. Through a hierarchical decision tree structure, histogram binning discretization and outlier processing, Wasserstein distance and Bayes-Thompson sampling are combined to achieve adaptive decision-making and optimize compiler parameter configuration.
It realizes the integration of robust distribution measurement and adaptive decision-making in compiler automatic tuning technology, improves the efficiency of high-dimensional space search and cross-platform tuning capabilities, shortens optimization time and improves compiler performance.
Smart Images

Figure CN120491945B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the technical field of compiler automatic optimization, and in particular relates to a compiler collaborative optimization method and system based on Wasserstein distance and Bayes-Thompson sampling. Background Art
[0002] Compiler auto-tuners are crucial intelligent decision-making engines in the modern compiler ecosystem. Their core mission is to address the critical issue of intelligent configuration of compilation optimization parameters. With the end of Moore's Law, software compilation optimization has become a key means of unlocking the performance potential of hardware. Modern compilers (such as GCC, the GNU Compiler Collection, and the GNU Compiler Suite) offer hundreds of refined optimization parameters (such as loop unrolling factors, vectorization strategies, and inlining thresholds). These parameters directly influence the quality of the generated machine code and program execution efficiency. However, the optimal parameter combination is highly dependent on the inherent characteristics of the target program (such as compute-intensive loop structures and memory access patterns) and the architectural details of the underlying hardware platform (such as CPU pipeline depth and GPU core count). Traditional compilers' fixed optimization levels (such as -O3, the highest optimization level) adopt a one-size-fits-all approach and are unable to adapt to this diversity, resulting in program performance far below the theoretical peak of the hardware.
[0003] To meet this challenge, the auto-tuner was developed to replace the expensive manual trial and error process with an intelligent search algorithm. 45 It automatically searches for the globally optimal or near-optimal compilation configuration in a large search space (of the order of magnitude), thereby generating more efficient machine code and significantly improving program execution speed.
[0004] In summary, compiler auto-tuning technology, through machine learning-driven search of high-dimensional parameter spaces (e.g., loop unrolling factors, vectorization switches), has become a key means of improving heterogeneous computing performance. However, existing methods face the dual bottlenecks of distorted distribution evaluation and exploration-exploitation imbalance. For example, the inherent flaw of KL divergence: mainstream solutions quantify differences in configuration performance distribution, but their sensitivity to zero-probability regions (e.g., configurations with compilation failures) leads to infinitely divergent values, distorting the assessment of true optimization potential. Experiments show that KL divergence fluctuates by more than an order of magnitude within 30 iterations, making it unable to reliably capture parameter synergies (e.g., the interaction between loop unrolling and vectorization), leading to entrapment in local optima. Another example is the rigidity of decision-making mechanisms: static exploration strategies struggle to adapt to sparse parameter spaces, making the cold start phase susceptible to initial sampling noise and the later convergence phase prone to ineffective search. Another example is the knowledge transfer gap: the configuration weight matrices and bin boundaries generated during the optimization process are not systematically stored, resulting in repeated calculations for cross-platform tuning and limiting the scalability of the heterogeneous computing ecosystem.
[0005] These problems cause existing tuners to exhibit high task sensitivity during testing, and therefore a solution that integrates robust distribution metrics and adaptive decision-making is urgently needed. Summary of the Invention
[0006] The present application discloses a compiler co-tuning method and system based on Wasserstein distance and Bayesian Thompson sampling, which can integrate robust distribution measurement and adaptive decision-making in the compiler co-tuning process.
[0007] Other purposes and advantages of this application can be further understood from the technical features disclosed in this application.
[0008] To achieve one, part, or all of the above objectives or other objectives, in a first aspect, the present application provides a compiler co-optimization method based on Wasserstein distance and Bayes-Thompson sampling, the method comprising:
[0009] Obtain the program to be optimized, define the optimization space, determine the decision order based on the preset optimization stage mapping list, and construct the optimization space into a hierarchical decision structure. Each optimization stage is a node in the hierarchical decision structure, and the configuration options are the child nodes of the node.
[0010] Traverse the hierarchical decision structure, select the optimal child nodes layer by layer according to Thompson sampling, and generate candidate configurations;
[0011] Based on the candidate configurations, target configuration parameters are selected and injected into the program to be optimized, which is then compiled and executed in real time to obtain performance data.
[0012] A binned histogram model is built based on all historical performance data to extract the distribution data of the best and worst configurations within the same optimization phase. The cumulative distribution function is calculated and the Wasserstein distance between the two distributions is quantified.
[0013] The Wasserstein distance value is determined according to the preset rules, and the optimization stage reordering mechanism is triggered based on the determination result. The optimization stage sequence is reordered in descending order, and the hierarchical decision structure is reconstructed according to the reordered optimization stage sequence.
[0014] In some embodiments, the configuration options include the sum of all reward values obtained by the node in history, the number of times the node has been selected, and the performance value obtained each time the node is selected.
[0015] In some embodiments, the method includes: unexplored nodes are based on a prior distribution Generate sample values, explored nodes based on posterior distribution Generate sample values based on , determine the child node with the largest sampling value as the optimal child node, and continue to explore downward; among them, Indicates the sampled value of the current configuration option, represents the historical average performance score of the i-th node, , Indicates the number of times the i-th node is selected; when the decision depth reaches the total number of preset optimization stages, a leaf node termination path is created to form a complete configuration path.
[0016] In some embodiments, the method further includes: determining a reward value of a node based on the performance data in combination with historical performance data; transmitting the performance data layer by layer to a root node along a configuration path, and synchronously updating configuration options for each node on the configuration path.
[0017] In some embodiments, a method for establishing a binned histogram model based on historical performance data includes:
[0018] Based on the extreme values of historical performance data, the optimal and worst values are determined to obtain the numerical range of the binning histogram model. The binning boundaries are then generated based on the number of times the node is selected to determine the binning interval.
[0019] For the performance data under each configuration option, count statistics are performed according to the binning interval, and the performance data less than or equal to the optimal value is classified into the first bin, and the performance data greater than or equal to the worst value is classified into the last bin.
[0020] In some embodiments, the method further comprises:
[0021] If new performance data breaks through the bin boundary, the extreme values of the historical performance data are dynamically updated, all bins are recalculated and normalized into a probability distribution;
[0022] The distribution data of the best and worst configurations with average performance in the same optimization stage are extracted, Laplace smoothing is performed, the cumulative distribution function is calculated, and the Wasserstein distance between the two distributions is quantified.
[0023] In some embodiments, the formula for determining the Wasserstein distance based on the cumulative distribution function is:
[0024] ;
[0025] Among them, W represents the Wasserstein distance value, numBins represents the number of bins, and CDF represents the cumulative distribution function. Indicates the bin width.
[0026] In some embodiments, rebuilding the hierarchical decision structure includes: updating historical performance extremes, maintaining a high-variance prior distribution for unexplored nodes, forcing outliers to be binned into first and last bins, and retaining historical test data to the new hierarchical decision structure.
[0027] In some embodiments, the method also includes: extracting and hierarchically storing workload features, bin boundaries and collaborative optimization relationships, comparing new tasks with historical feature libraries through feature matching, recommending initial configuration solutions based on similarity and feeding them back to the hierarchical decision structure to form a closed-loop knowledge transfer.
[0028] In a second aspect, the present application provides a compiler co-optimization system based on Wasserstein distance and Bayes-Thompson sampling, the system being configured to execute a compiler co-optimization method based on Wasserstein distance and Bayes-Thompson sampling as described in any one of the first aspects, the system comprising:
[0029] The input module is used to obtain the program to be optimized, define the optimization space, determine the decision order based on the preset optimization stage mapping list, and construct the optimization space into a hierarchical decision structure. Each optimization stage is a node in the hierarchical decision structure, and the configuration options are the child nodes of the node;
[0030] The configuration generation module is used to traverse the hierarchical decision structure, select the optimal child nodes layer by layer based on Thompson sampling, and generate candidate configurations;
[0031] The program evaluation module is used to select target configuration parameters based on candidate configurations and inject them into the program to be optimized, perform real-time compilation and execution, and obtain performance data;
[0032] The distribution modeling module is used to build a binned histogram model based on all historical performance data, extract the distribution data of the best and worst configurations in the same optimization stage, calculate the cumulative distribution function, and quantify the Wasserstein distance between the two distributions;
[0033] The strategy updating module is used to determine the Wasserstein distance value according to preset rules, trigger the optimization stage reordering mechanism based on the determination result, reorder the optimization stage sequence in descending order, and rebuild the hierarchical decision structure according to the reordered optimization stage sequence.
[0034] In some embodiments, the system also includes an output storage module for extracting and hierarchically storing workload characteristics, bin boundaries, and collaborative optimization relationships, comparing new tasks with historical feature libraries through feature matching, recommending initial configuration solutions based on similarity, and feeding back to the hierarchical decision structure to form a closed-loop knowledge transfer.
[0035] In a third aspect, the present application provides a computer-readable storage medium storing program code, which is called by a processor to execute a compiler collaborative optimization method based on Wasserstein distance and Bayes-Thompson sampling according to any one of the first aspects.
[0036] In a fourth aspect, the present application also provides an electronic device comprising one or more processors; a memory; and one or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more applications are configured to execute a compiler collaborative optimization method based on Wasserstein distance and Bayes-Thompson sampling as described in any one of the first aspects.
[0037] The above-mentioned compiler collaborative tuning method and system based on Wasserstein distance and Bayes-Thompson sampling optimizes decisions through multi-stage decision tree structure decomposition, adopts a performance evaluation method of histogram binning discretization and outlier processing to accurately quantify program behavior, and uses Wasserstein distance and Bayes-Thompson sampling to achieve adaptive dynamic feedback to balance the relationship between exploration and utilization, thereby realizing the integration of robust distribution measurement and adaptive decision-making in compiler automatic tuning technology.
[0038] In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions in the specific embodiments of the present application, the following is a brief introduction to the drawings required for the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0040] Figure 1Schematic diagram of a flow chart of a compiler collaborative tuning method based on Wasserstein distance and Bayes-Thompson sampling in an embodiment of the present application.
[0041] Figure 2 Schematic diagram of the structure of a Thompson sampling search strategy in an embodiment of the present application.
[0042] Figure 3 This is a flowchart of a program evaluation based on target configuration parameters in an embodiment of the present application.
[0043] Figure 4 Schematic diagram of a process for calculating Wasserstein distance in an embodiment of the present application.
[0044] Figure 5 This is a flowchart of rebuilding and updating a hierarchical decision structure in an embodiment of the present application.
[0045] Figure 6 This is a structural block diagram of a compiler collaborative tuning system based on Wasserstein distance and Bayes-Thompson sampling in an embodiment of the present application. DETAILED DESCRIPTION
[0046] The aforementioned and other technical contents, features, and functions of the present application will be clearly presented in the following detailed description of a preferred embodiment with reference to the drawings. The terms "first," "second," and the like in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate, and this is merely a way of distinguishing objects of the same attributes when describing them in the embodiments of the present application.
[0047] To address the problems of large decision spaces, high volatility in performance evaluation, low exploration efficiency, and difficulty in reusing cross-platform experience in compiler automatic tuning, the present application provides a compiler collaborative tuning method and system based on Wasserstein distance and Bayes-Thompson sampling. This method optimizes decisions through multi-stage decision tree structure decomposition, employs a performance evaluation method using histogram binning discretization and outlier processing to accurately quantify program behavior, and uses Wasserstein distance and Bayes-Thompson sampling to achieve adaptive dynamic feedback to balance exploration and utilization, thereby achieving the integration of robust distribution metrics and adaptive decision-making in compiler automatic tuning technology. Furthermore, by efficiently storing and reusing key optimization paths and configuration parameters, a closed-loop knowledge transfer is constructed to establish a transferable optimization knowledge base while ensuring high-dimensional space search efficiency, thereby further improving tuning accuracy, efficiency, and cross-platform generalization capabilities.
[0048] The solution of this application is described in detail below with reference to the accompanying drawings.
[0049] refer to Figure 1 The embodiment of the present application provides a compiler collaborative tuning method based on Wasserstein distance and Bayes-Thompson sampling, which specifically includes the following steps:
[0050] Step S101: Obtain the program to be optimized, define the optimization space, and construct a hierarchical decision tree according to a preset optimization stage mapping list. Each optimization stage is a hierarchical node of the tree, and the configuration options are child nodes of the hierarchical node.
[0051] Specifically, a program to be optimized is obtained, such as various expression statements, functions, or system tasks, to set a tuning workload, and an optimization space is defined to provide a set of optimization options derived from compiler optimization flags for exploration.
[0052] For example, the optimization space is defined using a structured dictionary, where the key is the optimization flag name (e.g., "loop_unroll") and the value is a FlagInfo object containing a list of configuration options. The optimization stage mapping list (opt_stage_mapping) determines the order of stage decisions, forming a hierarchical decision tree structure with each optimization stage as a level in the tree and the configuration options as children of the level's nodes.
[0053] For example, a default initial performance benchmark (default_perf) can be injected to initialize the search, and the final configuration is represented by a comma-separated index encoding (such as "0,1") to represent the selection of each stage, ensuring a visual mapping of the optimization space and the generation of a complete configuration.
[0054] For example, each optimization flag serves as an independent decision axis, and configuration options serve as specific execution parameters. Through multi-layered iterative optimization, a complete hierarchical space model encompassing all compiler optimization options is ultimately formed. As shown in Table 1 below, F1, F2, and F3 represent different optimization flags, each controlling different dimensions of code transformation, such as compiler phases and loop transformation strategies. Each optimization flag offers multiple configurable options (C1, C2, and C3), which determine specific implementation parameters, ranging from numeric values to binary activation switches. For example, the F1 flag controlling loop unrolling might offer three configuration options: disabling the transformation (C1=disable), applying a 4x loop unrolling (C2=unroll=4), or using a more aggressive 8x unrolling factor (C3=unroll=8). Similarly, the F2 flag for vectorization optimization might offer a binary option: enabling (C1=enable) or disabling (C2=disable) the vectorization process. Therefore, this hierarchical decision tree structure enables deep exploration of the optimization space, with each optimization flag serving as an independent decision axis, enabling the implementation of a specific parameterization scheme.
[0055] Table 1
[0056]
[0057] Step S102: traverse the hierarchical decision structure, select the optimal child node layer by layer according to Thompson sampling, and generate candidate configurations.
[0058] refer to Figure 2 ,Each node (corresponding to a configuration option) maintains three key states: reward represents the sum of all rewards ,received by the node in history (sample data), num represents the number of times the node has been ,selected (number of samples), and history represents the performance value (raw data) ,obtained each time the node is selected. The subsequent modules will update ,the three-state information.
[0059] Starting from the root node, traverse the hierarchical decision structure and select the optimal child nodes layer by layer according to Thompson sampling to generate candidate configurations. For example, the sampling value of each child node is calculated, and the unexplored nodes are based on the prior distribution Generate sample values, explored nodes based on posterior distribution Generate sample values based on , determine the child node with the largest sampling value as the optimal child node, and continue to explore downward; among them, Indicates the sampled value of the current configuration option, represents the historical average performance score of the i-th node, Indicates the number of times the i-th node is selected, It also dynamically reflects changes in confidence and selects the child node with the largest sample value to continue exploring. Generating multiple sets of candidate configurations in each round improves search efficiency. When the decision depth reaches the total number of preset optimization stages, a leaf node termination path is created to form a complete configuration path.
[0060] By dynamically adjusting the decision-making strategy, the system can conduct extensive exploration in the early stages and focus on configurations with known good performance in the later stages, thereby accelerating convergence to the optimal configuration and achieving a precise balance between exploration and utilization.
[0061] Step S103: Based on the candidate configurations, target configuration parameters are selected and injected into the program to be optimized, and real-time compilation and execution are performed to obtain performance data.
[0062] For example, refer to Figure 3 , select the target configuration parameters (e.g., the combination of F3 and C2), write a makefile script, dynamically inject the target configuration into the compilation and build environment of the program to be optimized, and perform real-time compilation and execution. Use a millisecond-precision timing device to capture the program's runtime and obtain raw performance data (perf).
[0063] Furthermore, the node's reward value is determined based on performance data combined with historical performance data. This performance data is then propagated layer by layer along the configuration path to the root node, and configuration options are synchronously updated for each node along the configuration path. For example, through a scalable reward function mechanism, the default implementation is a dynamic conversion based on performance ratio: when the minimum number of trials is met and the current performance is better than the historical best, a proportional reward value (ratio = best_perf / perf) is calculated. This reward value is used to update the node state through backpropagation operations, driving search strategy optimization.
[0064] Step S104: A binned histogram model is established based on all historical performance data, the distribution data of the best configuration and the worst configuration in the same optimization stage are extracted, the cumulative distribution function is calculated, and the Wasserstein distance value of the two distributions is quantified.
[0065] Specifically, a binned histogram model is established based on the extreme values of historical performance data (best_perf / worst_perf) (outliers are forced to be placed in the first and last bins). The distribution data of the optimal and worst configurations in the same optimization stage are extracted. After Laplace smoothing and calculation of the cumulative distribution function, the Wasserstein distance between the two distributions is quantified using an integral formula.
[0066] For example, refer to Figure 4Based on the node's performance data, a backpropagation operation is performed, starting from the evaluated leaf node and propagating performance data layer by layer along the search tree path toward the root node. Three-state information is synchronously updated for each node along the path: the current performance value is accumulated to the node's reward attribute, the node visit count num is incremented, and the performance value is inserted into the history record, maintaining the ordered order. The Wasserstein distance calculation phase then begins: for each optimization flag, a uniformly binned execution time histogram model is constructed. This model first determines the value range based on the historical best value (best_perf) and the worst value (worst_perf), generating numBins+1 equally spaced boundary points. After binning, the performance data collected for each configuration (history) is counted according to the binning intervals. All values less than or equal to best_perf are placed in the first bin, and all values greater than or equal to worst_perf are placed in the last bin, ensuring that outliers are properly handled. If new data breaks the bounds, dynamic extreme value updates are performed and all bins are recalculated. Then normalize it to a probability distribution (i.e., the ratio of the number of data points in each bin to the total number of data points). Then, extract the distribution data of the best and worst configurations with the same average performance in the same optimization stage, and perform Laplace smoothing on the two distributions (smoothing factor ), calculate the cumulative distribution function (CDF) of the two, and calculate the Wasserstein distance using the integral formula:
[0067] ;
[0068] in, Indicates the bin width, numBins indicates the number of bins, and CDF indicates the cumulative distribution function. represents the bin width. The W calculated here quantifies the degree of difference in performance distribution between the optimal and worst-case configurations within the same optimization phase (Flag). It measures the minimum amount of work required to transform one distribution into another (numerically equal to the horizontal shift distance multiplied by the amount shifted). This difference reflects the sensitivity of different configuration choices during that optimization phase to the final performance. If the Wasserstein distance is large, it indicates that different configuration choices during that optimization phase will lead to significantly different performance distributions, meaning that the decision at that phase is important. Conversely, if the Wasserstein distance is small, it indicates that the performance distribution is similar regardless of the configuration chosen, meaning that the decision at that phase is unimportant.
[0069] Step S105: determining the Wasserstein distance value according to a preset rule, triggering an optimization stage reordering mechanism based on the determination result, reordering the optimization stage sequence in descending order, and rebuilding the hierarchical decision structure according to the reordered optimization stage sequence.
[0070] Example line, reference Figure 5 After calculating the Wasserstein distance, a threshold is set to evaluate the calculated W value. When W is greater than the threshold, the optimization stage reordering mechanism is triggered, shifting the current optimization stage to a higher exploration priority. When W is less than or equal to the threshold, the current optimization order is maintained. The optimization stage reordering mechanism reorders the optimization stages in descending order and rebuilds the decision tree based on the new sequence. This reconstruction process incorporates three layers of protection: updating historical performance extremes, maintaining a high-variance prior distribution for unexplored nodes, forcing outliers to be binned first and last, and preserving historical test data in the new hierarchical decision structure through intelligent encoding conversion technology.
[0071] Then, based on the reconstructed hierarchical decision structure (decision tree) after reordering, the Wasserstein distance calculated for each optimization stage is sorted from largest to smallest. Stages with large distances (i.e., stages with high sensitivity and impact) are placed at the top of the decision tree and prioritized for execution. In a hierarchical decision structure, decisions made at upper-level nodes affect all subsequent decisions at lower levels. Stages with large Wasserstein distances (i.e., stages with a significant performance impact) are placed at the top to prioritize exploration and decision-making for these important stages. This allows for early determination of configurations for important stages, avoiding wasting exploration resources on less important stages. Prioritizing decisions for important stages (those with a significant performance impact) allows for more attention (exploration resources) to be focused on these critical decisions. Because important stages are placed at the top, and Thompson sampling selects layers from the root node, decisions at the top nodes (important stages) receive more attention (since each configuration selection must pass through the top nodes). The child nodes of the top nodes (i.e., the different configuration options for that important stage) are accessed and updated more frequently, leading to faster convergence to the optimal configuration. Lower-level nodes (secondary stages) have less impact on the entire program, and therefore require less exploration. This strategy update allows the system to converge to a better optimized configuration in a short period of time.
[0072] Then, the collaborative relationship analysis model is updated, ultimately completing the distribution modeling state update. A triple protection mechanism is implemented simultaneously during the decision tree reconstruction process: dynamic updates to historical performance extremes ensure data boundary reliability, maintaining high-contrast prior distributions for unexplored nodes to ensure exploration potential, and overflow protection is achieved by forcing outliers into the first and last bins. Historical test data is fully preserved through intelligent encoding conversion technology: the original encoding and performance values of all test records are extracted, the configuration encoding is reconstructed in the reorganized order, and the converted efficient configuration is reinjected into the new tree structure.
[0073] The final output is the optimized search system. Through this periodic structural reorganization mechanism, the high-difference optimization stage obtains priority exploration rights, realizes the cross-cycle migration of historical knowledge, and establishes a dynamic exploration space based on stage correlation. While ensuring the stability of the algorithm, it achieves continuous convergence in high-performance areas and precisely balances the dialectical relationship between exploration and utilization.
[0074] Step S106: Extract and hierarchically store workload features, bin boundaries, and collaborative optimization relationships, compare new tasks with historical feature libraries through feature matching, recommend initial configuration solutions based on similarity, and feed them back to the hierarchical decision-making structure to form a closed-loop knowledge transfer.
[0075] Specifically, workload features, bin boundaries, and collaborative optimization relationships are extracted, compressed, and platform fingerprinted before being stored in layers. A feature matching engine compares new tasks with the historical feature library, recommends an initial configuration based on similarity, and feeds back to step S101, forming a closed-loop knowledge transfer mechanism.
[0076] For example, starting with receiving the optimization result data, the feature extraction engine is started and tasks are performed: workload feature extraction captures program static properties, bin boundary calculation saves performance histogram metadata, and collaborative relationship analysis identifies correlation patterns between markers. The extracted feature data is used to construct the collaborative optimization matrix stage to form a performance impact matrix of the marker combination. Subsequently, Delta encoding and dictionary compression are used to reduce storage overhead; the hardware architecture and system environment identifiers are collected in the platform fingerprint generation stage; and the version control management stage adds timestamp versions and tracks change history. After processing is completed, the data is stored in layers: the workload feature layer records the key attributes of the program, the bin boundary layer saves the histogram partition information, the collaborative optimization matrix layer stores the empirical data of the marker combination, and the platform fingerprint layer retains the environmental identifier information.
[0077] After storage is complete, a closed knowledge transfer loop is established: a feature matching engine compares workloads with historical features. The initial configuration recommendation system recommends optimized solutions based on similarity. Finally, a feedback mechanism transmits the recommended results to the input module, forming a complete knowledge transfer closed loop. The entire process optimizes storage efficiency through data processing sub-processes and organizes data using a hierarchical storage structure, ultimately achieving an intelligent storage cycle from results to knowledge feedback.
[0078] In summary, the compiler collaborative tuning method based on Wasserstein distance and Bayes-Thompson sampling of the present application defines the optimization space, constructs a hierarchical decision tree, performs real-time compilation and performance measurement to obtain operation data, and then quantifies the influence of the optimization stage by analyzing performance differences and calculating the Wasserstein distance. Based on the analysis results, the initially constructed hierarchical decision tree is dynamically reorganized, and the optimization knowledge base is encapsulated to form a closed loop. The knowledge transfer mechanism provides initial optimization suggestions for new tasks, forming a complete closed-loop optimization framework of decision-making-evaluation-learning-optimization.
[0079] Compared with the prior art, the compiler collaborative optimization method based on Wasserstein distance and Bayesian Thompson sampling in this application has the following technical effects:
[0080] Effect 1: Breaking through the bottleneck of traditional distribution evaluation and significantly improving robustness in high-dimensional sparse spaces. By introducing the Wasserstein distance metric based on optimal transmission theory and using the geometric space alignment strategy of the cumulative distribution function, the evaluation distortion of traditional methods in sparse probability regions is effectively eliminated.
[0081] Effect 2: Achieving a dynamic balance between exploration and exploitation, accelerating convergence to the global optimum. By designing a Bayesian Thompson sampling engine, the dynamic attenuation of the variance term drives the adaptive transition from "strong exploration (high) in the early stages" to "intensive exploitation (low) in the later stages."
[0082] Effect 3: Deeply coupling the Wasserstein distance with Bayes-Thompson sampling achieves a dynamic closed loop for compiler optimization decisions, achieving faster convergence in a shorter time than other tuning solutions and achieving better tuning performance within the same tuning time. At the same time, it deeply explores optimization synergy relationships and enables compiler architecture upgrades. Traditional tuning methods ignore the interaction effects between optimization strategies, while this application automatically extracts high-value collaborative optimization pairs through persistently stored configuration weights and bin boundaries.
[0083] It should be understood that, although the various steps in the flowcharts involved in the various embodiments described above are displayed in sequence according to the instructions of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowcharts involved in the various embodiments described above can include multiple steps or multiple stages, and these steps or stages are not necessarily executed and completed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of steps or stages in other steps.
[0084] Based on the same inventive concept, an embodiment of the present application also provides a compiler collaborative optimization system based on Wasserstein distance and Bayes-Thompson sampling. The implementation solution of this system to solve the problem is similar to the implementation solution recorded in the above method, so only a brief description of its modules is given here and no further details are given.
[0085] In one embodiment, reference Figure 6 , this application provides a compiler collaborative optimization system based on Wasserstein distance and Bayesian Thompson sampling, including:
[0086] The input module is used to obtain the program to be optimized, define the optimization space, determine the decision order based on the preset optimization stage mapping list, and construct the optimization space into a hierarchical decision structure. Each optimization stage is a node in the hierarchical decision structure, and the configuration options are the child nodes of the node.
[0087] The configuration generation module is used to traverse the hierarchical decision structure, select the optimal child nodes layer by layer according to Thompson sampling, and generate candidate configurations.
[0088] The program evaluation module is used to select target configuration parameters based on candidate configurations and inject them into the program to be optimized, perform real-time compilation and execution, and obtain performance data.
[0089] The distribution modeling module is used to establish a binned histogram model based on all historical performance data, extract the distribution data of the optimal and worst configurations in the same optimization stage, calculate the cumulative distribution function, and quantify the Wasserstein distance value between the two distributions.
[0090] The strategy updating module is used to determine the Wasserstein distance value according to preset rules, trigger the optimization stage reordering mechanism based on the determination result, reorder the optimization stage sequence in descending order, and rebuild the hierarchical decision structure according to the reordered optimization stage sequence.
[0091] The output storage module is used to extract and hierarchically store workload characteristics, bin boundaries, and collaborative optimization relationships. It compares new tasks with the historical feature library through feature matching, recommends initial configuration solutions based on similarity, and feeds back to the hierarchical decision-making structure to form a closed-loop knowledge transfer.
[0092] In one embodiment, the present application also provides a computer-readable storage medium, which stores program code, and the program code is called by a processor to execute any of the above-mentioned compiler collaborative optimization methods based on Wasserstein distance and Bayes-Thompson sampling.
[0093] In one embodiment, the present application also provides an electronic device, which includes one or more processors; a memory; and one or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more applications are configured to execute any of the above-mentioned compiler co-optimization methods based on Wasserstein distance and Bayes-Thompson sampling.
[0094] It should be noted that, for those skilled in the art, various improvements and modifications may be made to the present invention without departing from the principles of the present invention, and such improvements and modifications also fall within the scope of protection of the claims of the present invention. It should be understood that certain features of the present invention described in the context of separate embodiments for the sake of clarity may also be provided in combination in a single embodiment. Conversely, various features of the present invention described in the context of a single embodiment for the sake of clarity may also be provided individually or in any suitable combination or as any other described embodiment of the present invention.
Claims
1. A compiler collaborative optimization method based on Wasserstein distance and Bayesian Thompson sampling, characterized in that: The method comprises: Obtaining a program to be optimized, defining an optimization space, determining a decision order based on a preset optimization stage mapping list, and constructing the optimization space into a hierarchical decision structure, with each optimization stage serving as a node of the hierarchical decision structure and configuration options serving as child nodes of the node; Traverse the hierarchical decision structure, select the optimal child node layer by layer according to Thompson sampling, and generate candidate configurations; among them, the unexplored nodes are based on the prior distribution Generate sample values, explored nodes based on posterior distribution Generate sample values based on , determine the child node with the largest sampling value as the optimal child node and continue to explore downward; Indicates the sampled value of the current configuration option, represents the historical average performance score of the i-th node, , Indicates the number of times the i-th node is selected; when the decision depth reaches the total number of preset optimization stages, a leaf node termination path is created to form a complete configuration path; Based on the candidate configurations, target configuration parameters are selected and injected into the program to be optimized, and real-time compilation and execution are performed to obtain performance data; A binned histogram model is built based on all historical performance data to extract the distribution data of the best and worst configurations within the same optimization phase. The cumulative distribution function is calculated and the Wasserstein distance between the two distributions is quantified. The Wasserstein distance value is determined according to a preset rule, and an optimization stage reordering mechanism is triggered based on the determination result, the optimization stage sequence is reordered in descending order, and the hierarchical decision structure is rebuilt according to the reordered optimization stage sequence.
2. The compiler collaborative optimization method based on Wasserstein distance and Bayesian Thompson sampling according to claim 1, characterized in that: The configuration options include the sum of all reward values obtained by the node in history, the number of times the node is selected, and the performance value obtained each time the node is selected.
3. The compiler collaborative optimization method based on Wasserstein distance and Bayesian Thompson sampling according to claim 1, characterized in that: The method further comprises: Determining a reward value for the node based on the performance data and in combination with historical performance data; The performance data is delivered layer by layer to the root node along the configuration path, and the configuration options of each node on the configuration path are synchronously updated.
4. The compiler collaborative optimization method based on Wasserstein distance and Bayesian Thompson sampling according to claim 1, characterized in that: Methods for building binned histogram models based on historical performance data include: Based on the extreme values of the historical performance data, the optimal value and the worst value are determined to obtain the value range of the binning histogram model, and the binning interval is determined by generating equidistant bin boundaries in combination with the number of times the node is selected; The performance data under each configuration option is counted according to the binning interval, and the performance data less than or equal to the optimal value is classified into the first bin, and the performance data greater than or equal to the worst value is classified into the last bin.
5. The compiler collaborative optimization method based on Wasserstein distance and Bayesian Thompson sampling according to claim 4, characterized in that: The method further comprises: If new performance data breaks through the bin boundary, the extreme value of the historical performance data is dynamically updated, all bins are recalculated and normalized into a probability distribution; The distribution data of the best and worst configurations with average performance in the same optimization stage are extracted, Laplace smoothing is performed, the cumulative distribution function is calculated, and the Wasserstein distance between the two distributions is quantified.
6. The compiler collaborative optimization method based on Wasserstein distance and Bayesian Thompson sampling according to claim 5, characterized in that: The formula for determining the Wasserstein distance based on the cumulative distribution function is: ; Among them, W represents the Wasserstein distance value, numBins represents the number of bins, and CDF represents the cumulative distribution function. Indicates the bin width.
7. The compiler collaborative optimization method based on Wasserstein distance and Bayesian Thompson sampling according to claim 1, characterized in that: The reconstruction of the hierarchical decision structure includes: updating historical performance extremes, maintaining a high variance prior distribution for unexplored nodes, forcing outliers to be classified into first and last bins, and retaining historical test data to the new hierarchical decision structure.
8. The compiler collaborative optimization method based on Wasserstein distance and Bayesian Thompson sampling according to claim 1, characterized in that: The method also includes: extracting and hierarchically storing workload features, bin boundaries, and collaborative optimization relationships, comparing new tasks with historical feature libraries through feature matching, recommending initial configuration solutions based on similarity, and feeding back to the hierarchical decision-making structure to form a closed-loop knowledge transfer.
9. A compiler collaborative optimization system based on Wasserstein distance and Bayesian Thompson sampling, characterized in that: A system for executing a compiler collaborative optimization method based on Wasserstein distance and Bayes-Thompson sampling according to any one of claims 1 to 8, wherein the system comprises: An input module is configured to obtain a program to be optimized, define an optimization space, determine a decision order based on a preset optimization stage mapping list, and construct the optimization space into a hierarchical decision structure, with each optimization stage serving as a node of the hierarchical decision structure and configuration options serving as subnodes of the node; A configuration generation module is used to traverse the hierarchical decision structure, select the optimal child node layer by layer according to Thompson sampling, and generate candidate configurations; A program evaluation module is used to select target configuration parameters based on the candidate configurations, inject them into the program to be optimized, compile and execute them in real time, and obtain performance data; The distribution modeling module is used to build a binned histogram model based on all historical performance data, extract the distribution data of the best and worst configurations in the same optimization stage, calculate the cumulative distribution function, and quantify the Wasserstein distance between the two distributions; A strategy updating module is used to determine the Wasserstein distance value according to a preset rule, trigger an optimization stage reordering mechanism based on the determination result, reorder the optimization stage sequence in descending order, and rebuild the hierarchical decision structure according to the reordered optimization stage sequence.
10. The compiler collaborative optimization system based on Wasserstein distance and Bayesian Thompson sampling according to claim 9, characterized in that: The system also includes an output storage module for extracting and hierarchically storing workload features, bin boundaries, and collaborative optimization relationships, comparing new tasks with historical feature libraries through feature matching, recommending initial configuration solutions based on similarity, and feeding back to the hierarchical decision-making structure to form a closed-loop knowledge transfer.
11. A computer-readable storage medium, characterized in that The computer-readable storage medium stores program code, and the program code is called by a processor to execute the compiler collaborative optimization method based on Wasserstein distance and Bayes-Thompson sampling as described in any one of claims 1 to 8.
12. An electronic device, characterized in that: including one or more processors; Memory; One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more applications are configured to execute a compiler co-optimization method based on Wasserstein distance and Bayes-Thompson sampling as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Ray-based lightweight distributed reinforcement learning training platform design method
CN119151019A
Bayesian earth sound parameter inversion method based on Wasserstein measurement form
CN119441784A