Compiling methods using genetic monte carlo tree search for compiler phase-ordering optimization, and systems, apparatuses, and computer-readable storage media employing same
Patent Information
- Application Number
- PCT/CN2023/090926
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-04-26
- Publication Date
- 2024-10-31
Smart Images

Figure CN2023090926_31102024_PF_FP_ABST
Abstract
Description
COMPILING METHODS USING GENETIC MONTE CARLO TREE SEARCH FOR COMPILER PHASE-ORDERING OPTIMIZATION, AND SYSTEMS, APPARATUSES, AND COMPUTER-READABLE STORAGE MEDIA EMPLOYING SAME
[0001] FIELD OF THE DISCLOSURE
[0002] The present disclosure relates generally to computer-code compilers, and in particular to computer-code compiling methods using genetic Monte Carlo tree search for compilation optimization such as compiler phase-ordering optimization, and systems, apparatuses, and computer-readable storage media employing same.
[0003] DEFINITIONS AND REFERENCES
[0004] For ease of reading, subsection H of the Detailed Description lists the definitions of acronyms and glossaries used in this disclosure. Subsection I of the Detailed Description lists the references cited herein, the content of each of which is incorporated herein by reference in its entirety.BACKGROUND
[0005] Computer-code compilation plays an important role in computer technologies. Generally, computer-code compilation involves the use of a special computer program called compiler to convert a computer program from one format such as a human-readable format into another format such as a computer-executable format. The computer program in computer-executable format may comprise machine-executable code for being executed by one or more processors of a computing device, or may be an intermediate representation (IR) as the machine-executable code for execution by a virtual machine. Usually, a compiler requires optimization to adapt to various aspects of computer programs (such as the runtimes, code size, binary size, and the like) and various execution environments.
[0006] SUMMARY
[0007] According to one aspect of this disclosure, there is provided a computerized method comprising: using a search tree to determine an optimized compilation-action sequence for program compilation optimization; the search tree comprises a plurality of nodes comprising a plurality of compilation-action sequences and arranged in a tree structure, the optimized compilation-action sequence being one of the plurality of compilation-action sequences; each node comprises a respective compilation-action sequence of a plurality of compilation actions.
[0008] In some embodiments, the compilation-action sequence of a child node is obtained based on the compilation-action sequence of the parent node.
[0009] In some embodiments, the number of compilation actions of each of the plurality of compilation-action sequences is greater than or equal to 50, and smaller than or equal to 80.
[0010] In some embodiments, each of the plurality of compilation-action sequences has a same number of compilation actions.
[0011] In some embodiments, said using the search tree to determine the optimized compilation-action sequence comprises: selecting a node of the plurality of nodes by traversing the search tree from a root node thereof along a path to the node based on one or more selection conditions; generating one or more variant compilation-action sequences based on the compilation-action sequence of the selected node; adding one or more children nodes to the selected node to expand the search tree, each child node comprising a respective one of the one or more variant compilation-action sequences; obtaining a performance measure of the compilation-action sequence of each of the one or more children nodes; and updating each node along the path from the selected node to the root node.
[0012] In some embodiments, said selecting the node of the plurality of nodes comprises: traversing the search tree from a root node thereof along a path to find the node that maximizing an upper confidence bound applied to trees (UCT) formula.
[0013] In some embodiments, said selecting the node of the plurality of nodes comprises: starting from the root as a current node, (1) selecting a node from the current node and the children nodes thereof based on the one or more selection conditions; and (2) if the selected node is not the current node and the selected node is not a leaf node, letting the selected node be the current node and going to (1) .
[0014] In some embodiments, said generating the one or more variant compilation-action sequences comprises at least one of: reordering at least a first portion of the compilation-action sequence of the selected node; swapping a second portion and a third portion of the compilation-action sequence of the selected node; and replacing a fourth portion of the compilation-action sequence of the selected node with replacement compilation actions.
[0015] In some embodiments, said obtaining the performance measure of the compilation-action sequence of each of the one or more children nodes comprises: obtaining the performance measure of the compilation-action sequence of each of the one or more children nodes by evaluating performance of one or more benchmarks using the compilation-action sequence of the child node.
[0016] In some embodiments, said obtaining the performance measure of the compilation-action sequence of each of the one or more children nodes comprises: obtaining the performance measure of the compilation-action sequence of each of the one or more children nodes using a geometric mean of results of the performance evaluation of the one or more benchmarks.
[0017] In some embodiments, the computerized method further comprises: obtaining N individual performance measures of the compilation-action sequence of each of one or more of the plurality of nodes by evaluating the compilation-action sequence of the node for N times, where N > 1 is an integer; and obtaining a performance measure of the compilation-action sequence of the node based on the N individual performance measures.
[0018] In some embodiments, said obtaining the performance measure of the compilation-action sequence of the node based on the N individual performance measures comprises: obtaining the performance measure of the compilation-action sequence of the node as an average of the N individual performance measures, or as a median of the N individual performance measures.
[0019] In some embodiments, N is determined based on the number of children nodes of the node.
[0020] In some embodiments, N is a function of WE, where W is the number of children nodes of the node, and E is a hyperparameter
[0021] In some embodiments, N≥WE.
[0022] In some embodiments, E is zero (0) or 0.5.
[0023] In some embodiments, the computerized method further comprises: selecting k compilation-action sequences from the plurality of compilation-action sequences as k survivor compilation-action sequences, where k ≥ 1 is an integer; and for each of the one or more children nodes, after said obtaining the performance measure of the compilation-action sequence of the child node, comparing the performance measure of the compilation-action sequence of the child node at least with that of a worst one of the k survivor compilation-action sequences having a worst performance measure, and if the performance measure of the compilation-action sequence of the child node is better than that of the worst survivor compilation-action sequence, removing the worst survivor compilation-action sequence from the k survivor compilation-action sequences and including the compilation-action sequence of the child node as one of the k survivor compilation-action sequences.
[0024] In some embodiments, the k compilation-action sequences have best performance measures among the plurality of compilation-action sequences.
[0025] In some embodiments, the computerized method further comprises: evaluating each of the k survivor compilation-action sequences for Ns times to obtain the performance measure thereof, where Ns ≥ 1 is an integer.
[0026] In some embodiments, Ns is determined based on a number of times of performing said comparing the performance measure of the compilation-action sequence of the child node at least with that of the worst survivor compilation-action sequence.
[0027] In some embodiments, Ns is a function of GF, where G is the number of times of performing said comparing the performance measure of the compilation-action sequence of the child node at least with that of the worst survivor compilation-action sequence, and F is a hyperparameter.
[0028] In some embodiments, Ns≥GF.
[0029] In some embodiments, F is zero (0) or 0.5.
[0030] In some embodiments, if the performance measure of the compilation-action sequence of the child node is better than that of the worst survivor compilation-action sequence, evaluating the compilation-action sequence of the child node such that a number of evaluations thereof is equal to an average number of evaluations of the k compilation-action sequences.
[0031] In some embodiments, each of the plurality of nodes is associated with one or more features; and said wherein said generating the one or more variant compilation-action sequences comprises: for each of the one or more variant compilation-action sequences, generating a plurality of candidate compilation-action sequences based on the compilation-action sequence of the selected node, and selecting one of the plurality of candidate compilation-action sequences as the variant compilation-action sequence, the selected candidate compilation-action sequence maximizing a similarity-comparison function.
[0032] In some embodiments, each of the one or more features is a value; and the similarity-comparison function comprises a similarity function Sim () defined as:
[0033] where A and B are vectors of features of two nodes, respectively; the symbol “·” represents inner production, and the symbol “| |” represents the vector modulus.
[0034] In some embodiments, the similarity-comparison function is: caSa (i) -cpSp (i)
[0035] where
[0036] · i = 1, 2, …, K, and K is the number of the candidate compilation-action sequences;
[0037] · Sa (i) =Sim (Xi, V) , where Xi represents the features of the i-th candidate compilation-action sequence, V= (V1+V2+…+Vt) / t, V1, V2, …, Vt are the vectors of features of t compilation-action sequences, respectively, and t ≥ 1 is an integer,
[0038] · Sa (i) =Sim (Xi, P) , where P is the feature vector of the selected node, and
[0039] · ca and cp are coefficients calculated as: cp=1-ca
[0040] where Tp is a number of visits of the selected node, and TR is a number of visits of a parent node of the selected node.
[0041] In some embodiments, the performance measures of the t compilation-action sequences are better than those of other compilation-action sequences.
[0042] In some embodiments, the computerized method further comprises: finding an ancestor node along a reversed path from the selected node to the root node, the ancestor node having a highest similarity to the selected node in terms of the one or more features; and letting the performance measure of the selected candidate compilation-action sequence be that of the ancestor node.
[0043] In some embodiments, said similarity is calculated using the similarity function Sim () .
[0044] According to one aspect of this disclosure, there is provided a computing apparatus comprising: a processor for performing the above-described computerized method.
[0045] According to one aspect of this disclosure, there is provided a computer system comprising: a processor for performing the above-described computerized method.
[0046] According to one aspect of this disclosure, there is provided one or more non-transitory computer-readable storage media comprising computer-executable instructions, wherein the instructions, when executed, cause a processor to perform the above-described computerized method.
[0047] Those skilled in the art will appreciate that the method, system, and computer-readable storage media disclosed herein combine the MCTS method with genetic algorithm for search, and may be suitable for optimizing compilation-action sequences in stochastic environments such as runtime with improved runtime speedup.
[0048] As the method disclosed herein does not require a learned cost model, the method disclosed herein may avoid the generally expensive need of training large neural networks.
[0049] In some embodiments, the method disclosed herein may evaluate a same action sequence multiple times to reduce the variance of its cost, which gives an advantage for stochastic environments where cost evaluations may vary for the same action sequences.
[0050] In some embodiments, the GMCTS method may use geometric mean (geomean) of multiple speedup numbers for calculating the cost evaluation of the action sequence, which is usually more stable than arithmetic mean for large fluctuations.
[0051] In some embodiments, the method disclosed herein may use the width-based extra evaluation method to evaluate a same action sequence multiple times. The rate of evaluation counts for promising nodes is controllable or otherwise tunable for adapting different environments.
[0052] In some embodiments, the method disclosed herein may track the best compilation-action sequences in an arena and evaluate them multiple times to reduce their cost-evaluation variances. By replacing “bad” compilation-action sequences in the arena with promising compilation-action sequences outside thereof, the arena is repeatedly updated to have the best compilation-action sequences. The best one of the compilation-action sequences in the arena may then be used for final evaluation and in the geomean speedup.
[0053] In some embodiments, the method disclosed herein may use features to guide the search thereby facilitating the transfer of knowledge from other parts of the search tree. The method disclosed herein leverages previous knowledge in the search. When a node is similar to a previous promising node, the search may be directed toward that node. On the other hand, if a node is similar to a previous poor node, the search may be directed away from that node. Also, if a node is similar to another node with poor evaluations, it is less likely to be selected.
[0054] By using the arena, the method disclosed herein may have more exploration in the beginning stages of a node and more exploitation toward the end. Thus, in the beginning the search tree is more likely to spread in the search space and more likely to find an optimized action sequence in the end.
[0055] The method disclosed herein is a generic search algorithm suitable for use in various backends such as LLVM and GCC. The method disclosed herein is framework independent, meaning that it may be easily integrated with other frameworks with environments for evaluation and testing such as CompilerGym. The method disclosed herein is a purely search algorithm, and may be implemented and tested in CPU machines and does not need highly powered GPUs for training and evaluation.
[0056] In some embodiments, the method disclosed herein is dependent on a real cost function (that is, a signal coming from the environment) rather than a predicted signal. Therefore, the method disclosed herein may be used for environments that can provide real cost heuristics.
[0057] The method disclosed herein is not machine dependent, and may be used for various instruction set architectures such as x86 CPUs, ARM CPUs, GPUs, and the like to speedup runtimes of programs, or reduce code size produced by compilation.
[0058] Moreover, the method disclosed herein is not restricted to the compilation optimization application and it may be used for any heuristic search application requiring sequence optimization.BRIEF DESCRIPTION OF THE DRAWINGS
[0059] For a more complete understanding of the disclosure, reference is made to the following description and accompanying drawings, in which:
[0060] FIG. 1 is a schematic diagram of a computer network system, according to some embodiments of the present disclosure;
[0061] FIG. 2A is a schematic diagram showing a simplified hardware structure of a computing device of the computer network system shown in FIG. 1;
[0062] FIG. 2B a schematic diagram showing a simplified software architecture of a computing device of the computer network system shown in FIG. 1;
[0063] FIG. 3 is a schematic diagram showing a simplified LLVM compilation procedure performed by a computing device of the computer network system shown in FIG. 1;
[0064] FIG. 4 is a schematic diagram showing a search tree used by the Monte Carlo tree search (MCTS) method for organizing the possible actions for optimizing the phases of IR in the LLVM compilation procedure shown in FIG. 3;
[0065] FIGs. 5A, 5B, 5C, and 5D are schematic diagrams showing the selection operation, expansion operation, simulation operation, and backpropagation operation used in the MCTS method;
[0066] FIG. 6 is a schematic diagram showing a procedure of compilation optimization, according to some embodiments of this disclosure;
[0067] FIG. 7 is a schematic diagram showing a search tree used by the Genetic Monte Carlo tree search (GMCTS) method for organizing the possible actions for compilation optimization, according to some embodiments of this disclosure;
[0068] FIG. 8A and 8B are schematic diagrams showing two examples of the selection operation used by the GMCTS method;
[0069] FIG. 9 is a flowchart showing the steps of the selection operation used by the GMCTS method;
[0070] FIGs. 10A and 10B are schematic diagrams showing two examples of the expansion operation used by GMCTS method;
[0071] FIG. 11 is a schematic diagram showing some examples of transformations on an action sequence during the expansion operation, according to some embodiments of this disclosure;
[0072] FIG. 12 is a schematic diagram showing the evaluation operation used in the GMCTS method, according to some embodiments of this disclosure;
[0073] FIG. 13 is a schematic diagram showing the backpropagation operation used in the GMCTS method, according to some embodiments of this disclosure;
[0074] FIG. 14 is a flowchart showing the GMCTS procedure for compilation optimization;
[0075] FIGs. 15A and 15B are schematic diagrams showing an example wherein a biased cost evaluation biases the selection operation and consequently biases the compilation optimization;
[0076] FIG. 16 is a schematic diagram showing an example wherein the GMCTS method uses the width-based extra evaluation method to reduce variance of cost evaluation for improved compilation optimization;
[0077] FIG. 17 is a flowchart showing the GMCTS procedure using the width-based extra evaluation method, according to some embodiments of this disclosure;
[0078] FIGs. 18A to 18D are schematic diagrams showing an example of updating an arena having a plurality of states or action sequences performed by the GMCTS method using the alternative query plan exploration (Arena) top-k method for variance reduction;
[0079] FIG. 19 is a flowchart showing the GMCTS procedure using the Arena top-k method, according to some embodiments of this disclosure;
[0080] FIG. 20 shows the detail of the updating-arena step of the GMCTS procedure shown in FIG. 19;
[0081] FIG. 21 is a flowchart showing a procedure of the expansion operation performed by the feature-guided GMCTS method, according to some embodiments of this disclosure;
[0082] FIG. 22 is a schematic diagram showing an example of a step of the expansion operation shown in FIG. 21 for finding the most similar ancestor node and updating the selected node, according to some embodiments of this disclosure; and
[0083] FIG. 23 is a schematic diagram showing other steps of the expansion operation shown in FIG. 21, according to some embodiments of this disclosure.DETAILED DESCRIPTION
[0084] A. SYSTEM STRUCTURE
[0085] Turning now to FIG. 1, a computer network system is shown and is generally identified using reference numeral 100. In these embodiments, the computer network system 100 is a so-called cloud-computing system or platform for providing various data services to a plurality of users.
[0086] As shown in FIG. 1, the computer network system 100 comprises one or more server computers 102, a plurality of client computing devices 104, and one or more client computer systems 106 functionally interconnected by a network 108, such as the Internet, a local area network (LAN) , a wide area network (WAN) , a metropolitan area network (MAN) , and / or the like, via suitable wired and wireless networking connections.
[0087] The server computers 102 may be computing devices designed specifically for use as a server, and / or general-purpose computing devices acting server computers while also being used by various users. Each server computer 102 may execute one or more server programs.
[0088] The client computing devices 104 may be portable and / or non-portable computing devices such as laptop computers, tablets, smartphones, Personal Digital Assistants (PDAs) , desktop computers, and / or the like. Each client computing device 104 may execute one or more client application programs which sometimes may be called “apps” .
[0089] Generally, the computing devices 102 and 104 comprise similar hardware structures such as hardware structure 120 shown in FIG. 2A. As shown, the hardware structure 120 comprises a processing structure 122, a controlling structure 124, one or more non-transitory computer-readable memory or storage media 126, a network interface 128, an input interface 130, and an output interface 132, functionally interconnected by a system bus 138. The hardware structure 120 may also comprise other components 134 coupled to the system bus 138.
[0090] The processing structure 122 may be one or more single-core or multiple-core computing processors, generally referred to as central processing units (CPUs) , such as microprocessors (INTEL is a registered trademark of Intel Corp., Santa Clara, CA, USA) , microprocessors (AMD is a registered trademark of Advanced Micro Devices Inc., Sunnyvale, CA, USA) , microprocessors (ARM is a registered trademark of Arm Ltd., Cambridge, UK) manufactured by a variety of manufactures such as Qualcomm of San Diego, California, USA, under the architecture, or the like. When the processing structure 122 comprises a plurality of processors, the processors thereof may collaborate via a specialized circuit such as a specialized bus or via the system bus 138.
[0091] The processing structure 122 may also comprise one or more real-time processors, programmable logic controllers (PLCs) , microcontroller units (MCUs) , μ-controllers (UCs) , specialized / customized processors, hardware accelerators, and / or controlling circuits (also denoted “controllers” ) using, for example, field-programmable gate array (FPGA) or application-specific integrated circuit (ASIC) technologies, and / or the like. In some embodiments, the processing structure includes a CPU (otherwise referred to as a host processor) and a specialized hardware accelerator which includes circuitry configured to perform computations of neural networks such as tensor multiplication, matrix multiplication, and the like. The host processor may offload some computations to the hardware accelerator to perform computation operations of neural network. Examples of a hardware accelerator include a graphics processing unit (GPU) , Neural Processing Unit (NPU) , and Tensor Process Unit (TPU) . In some embodiments, the host processors and the hardware accelerators (such as the GPUs, NPUs, and / or TPUs) may be generally considered processors.
[0092] Generally, the processing structure 122 comprises necessary circuitries implemented using technologies such as electrical and / or optical hardware components for executing an encryption process and / or a decryption process, as the design purpose and / or the use case maybe, for encrypting and / or decrypting data received from the input 106 and outputting the resulting encrypted or decrypted data through the output 108.
[0093] For example, the processing structure 122 may comprise logic gates implemented by semiconductors to perform various computations, calculations, and / or processings. Examples of logic gates include AND gate, OR gate, XOR (exclusive OR) gate, and NOT gate, each of which takes one or more inputs and generates or otherwise produces an output therefrom based on the logic implemented therein. For example, a NOT gate receives an input (for example, a high voltage, a state with electrical current, a state with an emitted light, or the like) , inverts the input (for example, forming a low voltage, a state with no electrical current, a state with no light, or the like) , and output the inverted input as the output.
[0094] While the inputs and outputs of the logic gates are generally physical signals and the logics or processings thereof are tangible operations with physical results (for example, outputs of physical signals) , the inputs and outputs thereof are generally described using numerals (for example, numerals “0” and “1” ) and the operations thereof are generally described as “computing” (which is how the “computer” or “computing device” is named) or “calculation” , or more generally, “processing” , for generating or producing the outputs from the inputs thereof.
[0095] Sophisticated combinations of logic gates in the form of a circuitry of logic gates, such as the processing structure 122, may be formed using a plurality of AND, OR, XOR, and / or NOT gates. Such combinations of logic gates may be implemented using individual semiconductors, or more often be implemented as integrated circuits (ICs) .
[0096] A circuitry of logic gates may be “hard-wired” circuitry which, once designed, may only perform the designed functions. In this example, the processes and functions thereof are “hard-coded” in the circuitry.
[0097] With the advance of technologies, it is often that a circuitry of logic gates such as the processing structure 122 may be alternatively designed in a general manner so that it may perform various processes and functions according to a set of “programmed” instructions implemented as firmware and / or software and stored in one or more non-transitory computer-readable storage media. In this example, the circuitry of logic gates such as the processing structure 122 is usually of no use without meaningful firmware and / or software.
[0098] Of course, those skilled the art will appreciate that a process or a function (and thus the processor 102) may be implemented using other technologies such as analog technologies.
[0099] Referring back to FIG. 1, the controlling structure 124 comprises one or more controlling circuits, such as graphic controllers, input / output chipsets and the like, for coordinating operations of various hardware components and modules of the computing device 102 / 104.
[0100] The memory 126 comprises one or more storage media accessible by the processing structure 122 and the controlling structure 124 for reading and / or storing instructions for the processing structure 122 to execute, and for reading and / or storing data, including input data and data generated by the processing structure 122 and the controlling structure 124. The memory 126 may be volatile and / or non-volatile, non-removable or removable memory such as RAM, ROM, EEPROM, solid-state memory, hard disks, CD, DVD, flash memory, or the like.
[0101] The network interface 128 comprises one or more network modules for connecting to other computing devices or networks through the network 108 by using suitable wired or wireless communication technologies such as Ethernet, (WI-FI is a registered trademark of Wi-Fi Alliance, Austin, TX, USA) , (BLUETOOTH is a registered trademark of Bluetooth Sig Inc., Kirkland, WA, USA) , Bluetooth Low Energy (BLE) , Z-Wave, Long Range (LoRa) , (ZIGBEE is a registered trademark of ZigBee Alliance Corp., San Ramon, CA, USA) , wireless broadband communication technologies such as Global System for Mobile Communications (GSM) , Code Division Multiple Access (CDMA) , Universal Mobile Telecommunications System (UMTS) , Worldwide Interoperability for Microwave Access (WiMAX) , CDMA2000, Long Term Evolution (LTE) , 3GPP, 5G New Radio (5G NR) and / or other 5G networks, and / or the like. In some embodiments, parallel ports, serial ports, USB connections, optical connections, or the like may also be used for connecting other computing devices or networks although they are usually considered as input / output interfaces for connecting input / output devices.
[0102] The input interface 130 comprises one or more input modules for one or more users to input data via, for example, touch-sensitive screen, touch-sensitive whiteboard, touch-pad, keyboards, computer mouse, trackball, microphone, scanners, cameras, and / or the like. The input interface 130 may be a physically integrated part of the computing device 102 / 104 (for example, the touch-pad of a laptop computer or the touch-sensitive screen of a tablet) , or may be a device physically separate from, but functionally coupled to, other components of the computing device 102 / 104 (for example, a computer mouse) . The input interface 130, in some implementation, may be integrated with a display output to form a touch-sensitive screen or touch-sensitive whiteboard.
[0103] The output interface 132 comprises one or more output modules for output data to a user. Examples of the output modules comprise displays (such as monitors, LCD displays, LED displays, projectors, and the like) , speakers, printers, virtual reality (VR) headsets, augmented reality (AR) goggles, and / or the like. The output interface 132 may be a physically integrated part of the computing device 102 / 104 (for example, the display of a laptop computer or tablet) , or may be a device physically separate from but functionally coupled to other components of the computing device 102 / 104 (for example, the monitor of a desktop computer) .
[0104] The computing device 102 / 104 may also comprise other components 134 such as one or more positioning modules, temperature sensors, barometers, inertial measurement unit (IMU) , and / or the like.
[0105] The system bus 138 interconnects various components 122 to 134 enabling them to transmit and receive data and control signals to and from each other.
[0106] FIG. 2B shows a simplified software architecture 160 of the computing device 102 or 104. The software architecture 160 comprises an operating system 164, a logical input / output (I / O) interface 168, a logical memory 172, and one or more programs 174 (collectively denoted “application programs” to differentiate from the programs of the operation system 164) . The operating system 164, logical I / O interface 168, and one or more application programs 174 are generally implemented as computer-executable instructions or code in the form of software programs or firmware programs stored in the logical memory 172 which may be executed by the processing structure 122.
[0107] The operating system 164 manages various hardware components of the computing device 102 or 104 via the logical I / O interface 168, manages the logical memory 172, and manages and supports the application programs 174. The operating system 164 is also in communication with other computing devices (not shown) via the network 108 to allow application programs 174 to communicate with those running on other computing devices. As those skilled in the art will appreciate, the operating system 164 may be any suitable operating system such as (MICROSOFT and WINDOWS are registered trademarks of the Microsoft Corp., Redmond, WA, USA) , OS X, iOS (APPLE is a registered trademark of Apple Inc., Cupertino, CA, USA) , Unix, Linux, (ANDROID is a registered trademark of Google LLC, Mountain View, CA, USA) , or the like. The computing devices 102 and 104 of the computer network system 100 may all have the same operating system, or may have different operating systems.
[0108] The logical I / O interface 168 comprises one or more device drivers 170 for communicating with respective input and output interfaces 130 and 132 for receiving data therefrom and sending data thereto. Received data may be sent to the one or more application programs 164 for being processed by one or more application programs 164. Data generated by the application programs 164 may be sent to the logical I / O interface 168 for outputting to various output devices (via the output interface 132) .
[0109] The logical memory 172 is a logical mapping of the physical memory 126 for facilitating the application programs 164 to access. In this embodiment, the logical memory 172 comprises a storage memory area that may be mapped to a non-volatile physical memory such as hard disks, solid-state disks, flash drives, and the like, generally for long-term data storage therein. The logical memory 172 also comprises a working memory area that is generally mapped to high-speed, and in some implementations volatile, physical memory such as RAM, generally for application programs 164 to temporarily store data during program execution. For example, an application program 164 may load data from the storage memory area into the working memory area, and may store data generated during its execution into the working memory area. The application program 164 may also store some data into the storage memory area as required or in response to a user’s command.
[0110] The one or more application programs 174 executed by or run by the processing structure 122 for performing various tasks. In a server computer 102, the one or more application programs 174 generally provide server functions for managing network communication with client computing devices 104 and facilitating collaboration between the server computer 102 and the client computing devices 104. Herein, the term “server” may refer to a server computer 102 from a hardware point of view or a logical server from a software point of view, depending on the context.
[0111] As described above, the processing structure 122 is usually of no use without meaningful firmware and / or software. Similarly, while a computer system such as the computer network system 100 may have the potential to perform various tasks, it cannot perform any tasks and is of no use without meaningful firmware and / or software. As will be described in more detail later, the computer network system 100 disclosed herein and the modules, circuitries, and components thereof, as a combination of hardware and software, generally produces tangible results tied to the physical world, wherein the tangible results such as those disclosed herein may lead to improvements to the computer devices and systems themselves, the modules, circuitries, and components thereof, and / or the like.
[0112] In fact, with the advance of computer technologies, the boundary between hardware and software is fading. For example, an application may appear to the users that it is executed in one logic server (also called a “virtual server” ) while different application programs or program modules of the application may be executed on a plurality of server computers and / or with the use of resources from a plurality of server computers and / or a plurality of network components. Such a computer network system is also denoted a distributed system.
[0113] Moreover, while the software structure 160 shown in FIG. 2B partitions the programs running on a computing device 102 / 104 as an OS 164 and application programs 174, those skilled in the art will appreciate that such a program-partitioning may vary in different embodiments. For example, a program such as a compiler (which translates human-readable source code into target code for execution by a computing device 102 / 104) may be implemented as an application program 174 in some embodiments, and may be implemented as a part of the OS 164 in some other embodiments.
[0114] B. LLVM AND COMPILATION OPTIMIZATION
[0115] LLVM (which is not an acronym; see https: / / llvm. org / ) is a widely used, production-grade compiler. LLVM comprises is a set of a collection of modular and reusable compiler and toolchain technologies for developing a frontend for various programming languages and a backend for various processor architectures. FIG. 3 is a schematic diagram showing a simplified procedure 200 of LLVM compilation.
[0116] As shown, the program code 202 is fed into a LLVM compiler 204, which converts the program code 202 into a LLVM intermediate representation (IR) 206. The LLVM IR 206 may be optimized with a variety of transformations over a plurality of passes to obtain an optimized LLVM IR 210, which is output by the LLVM compiler 204 as the binary code 212 for execution by one or more processors. Herein, a pass is an operation (such as analysis, transformation, or the like) on a unit of the IR and may produce a result which can then be queried. During the optimization, a plurality of phases of IR optimizations (such as cleanup, simplification, and lowering) may be performed. As those skilled in the art understand, the order of the plurality of phases of IR optimizations (denoted the “phase-ordering problem” ) may have a significant impact to the performance of the compiler.
[0117] Generally, a compiler-optimization method may be used for phase-order optimization (or more generally for compilation optimization) . For example, a search algorithm (also called “policy” or “planner” ) implementing a search method as a computer-executable routine may be used to operate on a search space (which comprises a plurality of compiler-optimization flags, each compiler-optimization flag corresponding to a compilation action (or simply an “action” ) ) , and return an optimized sequence of actions based on a cost function. Herein, a cost function is a function for measuring or evaluating the performance (in one or more aspects such as code size, binary size, runtime, and / or the like) of a sequence of actions using one or more benchmarks. A benchmark is a program compiled and run by the search algorithm during the search and evaluation for obtaining cost evaluations of the search candidates (such as sequences of actions) , and the set of benchmarks used for search and evaluation by the search algorithm may be denoted a dataset.
[0118] More specifically, the search algorithm uses a suitable evaluation method (also called an “evaluation strategy” ) to command the compiler such as LLVM to compile and run benchmarks in accordance with a sequence of actions for obtaining the performance evaluation (such as the cost evaluation) of the benchmarks. The evaluated performance is then used as the performance measure of the sequence of actions to allow the search algorithm to find the optimized sequence of actions that achieve the optimization objectives or goals in the one or more aspects.
[0119] Artificial intelligence (AI) may be used for compilation optimization such as for LLVM optimization to solve decision-making issues such as the phase-ordering problem in compilation optimization. For example, the “CompilerGym” framework offered by Meta Platforms, Inc. of Menlo Park, California, USA is a compiler-optimization framework for developing and evaluating search algorithms on optimizing LLVM phase-ordering. CompilerGym includes multiple available datasets and backend compilers such as the GNU compiler collection (GCC) and LLVM to perform real-world compilation optimization tasks and evaluate different optimization algorithms (see Reference [1] ) .
[0120] CompilerGym presents four objectives: code size, binary size, runtime x86, and runtime ARM. They used four different learning methods and search paradigms on different datasets on the LLVM backend x86 for the code size reduction, including: APEX (see Reference [2] ) , A2C (see Reference [3] ) , IMPALA (see Reference [4] ) , and PPO (see Reference [5] ) .
[0121] · APEX: This method uses online deep reinforcement learning (RL) framework with multiple actors that rely on a shared trained cost model by prioritizing experience replay memory. The shared cost model is trained from the shared prioritized experience replay memory online.
[0122] · A2C: This method is an actor critic method that learns parallel cost models asynchronously using deep RL framework.
[0123] · IMPALA: This method is another deep RL algorithm using weighted actor-critic architecture. It is scalable and can make use of distributed training across same or different machines.
[0124] · PPO: This method learns policies using stochastic gradient ascent (SGA) technique.
[0125] Interestingly, none of these four deep RL frameworks outperforms the other three across different datasets for code-size objective.
[0126] For the runtime objective, CompilerGym uses five different methods on the Carleton Benchmark Suite (CBench) dataset (which is an extensible and informative benchmarking framework for evaluating question answering systems over knowledge graphs) , including: greedy search, random search, LaMCTS (see Reference [6] ) , OpenTurner (see Reference [7] ) , and NeverGrad (see Reference [8] ) .
[0127] · Greedy search: This method picks the action which gives the highest reward at each point and terminates when there is no action available with a positive reward.
[0128] · Random search: This method randomly generates action until some timeout is passed without any improvement.
[0129] · LaMCTS: This method is an adaptation of Monte Carlo tree search (MCTS) which focuses on the more important part of the search space.
[0130] · OpenTurner: This method is a black-box search technique that uses different combination of methods to optimize a target function.
[0131] · NeverGrad: This method is also another black-box method which is a gradient-free optimization and includes differential evolution, sequential quadratic programming, covariance matrix adaptation, and the like.
[0132] Nevergrad may outperform the other four methods on runtime and on all other objectives (such as code size and binary size) .
[0133] Despite the progress of using AI in code compilation, research in this area may be challenging due to limited access to datasets and frameworks that enables rapid research and development.
[0134] Monte Carlo tree search (MCTS) methods may be used for decision making in compilation optimization. As shown in FIG. 4, the MCTS method uses a search tree 260 for organizing the possible actions such as the phases of IR optimizations. The search tree 260 comprises a plurality of nodes 264 to 274 linked to a root node 262 thereby forming a tree structure. Depending on the linkages thereof, the plurality of nodes 264 to 274 are generally classified as intermediate nodes (such as nodes 264 and 266, each having one or more children nodes) and leaf nodes (such as nodes 268 to 274 which have no children nodes) . A path from the root node 262 to a leaf node (for example, node 268) represent an ordered combination of the actions to be performed.
[0135] Each of the intermediate nodes and leaf nodes represents or otherwise corresponds to a possible action, and is associated with a suitable performance measure (such as a “win ratio” ) representing the performance if the corresponding action and the actions of the children nodes thereof are performed. The root node 262 is associated with an overall performance measure representing the performance if the actions of the children nodes thereof (that is, the actions of the plurality of nodes 264 to 274) are performed.
[0136] The MCTS method builds the search tree 260 from an initial tree only having the root node 262. More specifically, the MCTS methods iteratively expand the search tree 260 from the root node 262 generally using four operations including selection 282, expansion 284, simulation 286, and backpropagation 288. FIGs. 5A to 5D show examples of these operations.
[0137] As shown in FIG. 5A, the selection operation 282 traverses the search tree 260 from the root node 262 to a leaf node (such as node 272) using a specific selection method (such as a random method, or a method with a balance between exploration and exploitation) to select that leaf node 272. When the search tree 260 only has the root node 262, the selection operation 282 selects the root node 262.
[0138] As shown in FIG. 5B, in the expansion operation 284, the search tree 260 is expanded from the selected leaf node 272 obtained from the last step (such as from a selection operation) by adding one or more children nodes (such as nodes 276 and 278; each representing a possible next action (that is, a possible action immediately subsequent the action represented by the selected leaf node) thereto.
[0139] As shown in FIG. 5C, in the simulation operation 286, the action of an added node (such as node 276) is simulated to evaluate the performance of the action.
[0140] As shown in FIG. 5D, in the backpropagation operation 288, the result of the simulation operation 286 is used to update the performance measures associated with the nodes along the path from the simulated leaf node 276 to the root node 262.
[0141] The selection, expansion, simulation, and backpropagation operations 282, 284, 286, and 288 may be repeatedly performed to grow or otherwise expand the search tree 260 until an optimized path (that is, an optimized action sequence) is obtained or a predefined number of iterations are performed.
[0142] C. GENETIC MONTE CARLO TREE SEARCH FOR LLVM PHASE-ORDERING OPTIMIZATION
[0143] FIG. 6 is a schematic diagram showing a procedure 300 of compilation optimization according to some embodiments of this disclosure. As those skilled in the art understand, the terms “optimize” , “optimized” , and “optimization” refer to obtaining a solution (such as a phase ordering) that is better than some other solutions in some aspects of interest. Such terms do not necessarily mean obtaining an absolutely optimized solution, or an absolutely best solution, or a solution that is better than other solutions in all relevant aspects, and often refer to a suboptimized solution compared to the absolutely optimized solution.
[0144] As shown in FIG. 6, a piece of source code 302 (such as a piece of code written in a programming language, for example C, C++, Java, or the like) is input into the frontend 304 (such as the LLVM frontend) of a code compiler. The code compiler then processes the piece of source code 302 and generates an IR 306 (such as a LLVM IR) . An optimizer 308 is then used to optimize the LLVM IR 306 and obtain an optimized LLVM IR 310. A code evaluator 312 evaluates the optimized LLVM IR 310 to generate an overall cost assessment 314 for indicating the optimization performance.
[0145] As shown in FIG. 6, the code evaluator 312 may evaluate the optimized LLVM IR 310 from a variety of aspects such as code size 320, binary size 330, x86 runtime 340, runtime 350, and / or the like. In the following, the term “x86” refers to a family of complex instruction set computer (CISC) instruction set architectures used by microprocessors and compatible variants, and the term “ARM” refers to a family of reduced instruction set computer (RISC) instruction set architectures developed by Arm Ltd. FIG. 6 shows the x86 runtime 340 and runtime 350 as examples to show that the procedure 300 may be adapted to one or more instruction set architectures for one or more processors.
[0146] The code-size evaluation 320 gives rise to a code-size cost assessment 328 based on the code size of the optimized LLVM IR 310. In the binary-size evaluation 330, a backend 332 (such as a LLVM backend) of the code compiler converts the optimized LLVM IR 310 into binary code 334, which is evaluated by the code evaluator 312 for obtaining a binary-size cost assessment 338. In the x86 runtime evaluation 340, a x86 backend 342 (such as a LLVM backend x86) of the code compiler converts the optimized LLVM IR 310 into x86-compatible binary code 344. The code evaluator 312 then runs or simulates the x86-compatible binary code 344 on the x86 platform 346 for obtaining a x86-runtime cost assessment 348. In the runtime evaluation 350, an ARM backend 352 (such as a LLVM backend ) of the code compiler converts the optimized LLVM IR 310 into -compatible binary code 354. The code evaluator 312 then runs or simulates the x86-compatible binary code 344 on the platform 356 for obtaining an -runtime cost assessment 358. In some embodiments, a web service framework 360 may be used to facilitate compiling and running workloads on ARM devices 356 and evaluating custom datasets and benchmarks on the ARM devices 356.
[0147] The obtained cost assessments 328 to 358 are combined to obtain the overall cost assessment 314. The optimizer may use a suitable method such as the MCTS method to assess various optimization options (such as different phase-ordering options) and obtain the best optimization solution from the assessed optimization options.
[0148] In some embodiments, a genetic Monte Carlo tree search (GMCTS) method is used for optimizing phase-ordering (such as LLVM phase-ordering optimization) . As will be described in more detail below, the GMCTS method is a method combining the MCTS method and the genetic algorithm, and comprises the following aspects:
[0149] · Genetic encoding of solution (such as LLVM sequence of passes) ;
[0150] · Sampling actions to generate children nodes; and
[0151] · Explicit search tree construction &maintenance.
[0152] As shown in FIG. 7, the GMCTS method in these embodiments uses a search tree 400 for organizing the possible actions such as the phases of IR optimizations. The search tree 400 comprises a plurality of nodes 404 to 414 linked to a root node 402 thereby forming a tree structure. Depending on the linkages thereof, the plurality of nodes 404 to 414 are generally classified as intermediate nodes (such as nodes 404 and 406, each having one or more children nodes) and leaf nodes (such as nodes 408 to 414 which have no children nodes) .
[0153] Each of the nodes 402 to 414 represents or otherwise corresponds to a possible action sequence of a fixed length, for example, having n actions where 50 ≤ n ≤ 80 (that is, n between 50 and 80, inclusive) . As will be described in more detail later, the action sequence of a child node is a variant of the action sequence of its parent node. Moreover, each of the nodes 402 to 414 is associated with a suitable performance measure such as a cost evaluation representing the cost if the corresponding action sequence is performed. A lower or smaller cost evaluation corresponds to a better performance measure.
[0154] The GMCTS method builds the search tree 400 from an initial tree only having the root node 402. More specifically, the GMCTS methods iteratively expand the search tree 400 from the root node 402 generally using four operations including selection, expansion, evaluation, and backpropagation.
[0155] In these embodiments, the selection operation traverses the search tree 400 from the root node 402 to a node using a suitable selection method (such as a random method, or a method with a balance between exploration and exploitation) to select that node. Unlike the MCTS selection operation which always selects a leaf node, the GMCTS selection operation may select a leaf node or an intermediate node.
[0156] For example, as shown in FIG. 8A, the selection operation 432 may traverse the search tree 400 from the root node 402 to the leaf node 412 using a selection method and select the leaf node 412. More specifically, the selection operation 432 starts from the root node 402 and selects the node 406 from the children nodes 404 and 406 of the root node 402 using the selection method, and then selects the node 412 from the children nodes 412 and 414 of the current node 406 using the selection method.
[0157] As shown in FIG. 8B, the selection operation 432 may traverse the search tree 402 from the root node 402 to the intermediate node 404 using the selection method and select the intermediate node 404.
[0158] FIG. 9 is a flowchart showing the steps of the selection operation 432.
[0159] After the selection operation 432 starts (step 442) , the GMCTS method uses the root node 402 as the current node and selects a node from the current node and the children nodes thereof based the selection conditions of these nodes (step 444) . For example, a node j (which may be the current node or a child node thereof) is selected if, among the current node and the children nodes thereof, the following upper confidence bound applied to trees (UCT) formula of node j is maximized:
[0160] where Xj is the performance measure (for example, the inverse of the cost evaluation) of node j, n is the number of times the current node has been selected, nj is the number of times node j has been selected, C is a constant.
[0161] The UCT formula (1) is a representation of the upper confidence bound a tree, and usually balances exploitation (for example, the first component of the UCT formula (1) ) and exploration (for example, the second component of the UCT formula (1) ) based on hyperparameters (such as the parameter C in the UCT formula (1) ) to control level of exploration.
[0162] At step 446, the GMCTS method checks if the selected node is the current node. If the selected node is the current node, the selection operation is ended (step 452) and the current node is the selected node.
[0163] If at step 446, it is determined that the selected node is not the current node, the GMCTS method checks if the selected node is a leaf node (448) . If the selected node is a leaf node, the selection operation is ended (step 452) and the leaf node is the selected node.
[0164] If at step 448, it is determined that the selected node is not a leaf node, then the selected node is used as the current node (step 450) , and the selection operation 432 loops to step 444 to make further selection until either a current node is selected or a leaf node is selected.
[0165] After a node is selected, the expansion operation may be performed to add one or more children nodes to the selected node by using one or more transformations based on the selected node.
[0166] For example, FIG. 10A shows the expansion operation 434 after the leaf node 412 is selected (see FIG. 8A) , wherein the children nodes 416 and 418 are created for the selected node 412 by using one or more transformations based on the selected node 412.
[0167] FIG. 10B shows another example of the expansion operation 434 after the intermediate node 404 is selected (see FIG. 8B) , wherein the children nodes 420 and 422 are created for the selected node 404 by using one or more transformations based on the selected node 404.
[0168] In these embodiments, a transformation alters or otherwise modifies all or a subset of the actions of the action sequence of the selected node to generate an action sequence for a child node of the selected node. FIG. 11 show some examples of transformations. As shown, the action sequence of the selected node may be sampled (step 462) according to a specific condition (such as sampling a random number of actions from random locations of the action sequence, obtaining a predefined number of actions from the front, middle, or end of the action sequence, or the like) to determine one or more actions 464 to be transformed (such as ordered actions 8, 7, 4, 3, and 2; denoted an “action subsequence” for ease of description) .
[0169] Then, the actions of the action subsequence 464 may be shuffled or reordered (step 466; that is, reordered) . For example, after shuffling, the action subsequence becomes the shuffled action subsequence 468 of ordered actions 7, 8, 3, 4, and 2, or the shuffled action subsequence 470 of ordered actions 8, 3, 7, 4, and 2.
[0170] The actions of the action subsequence 464 may be swapped (step 472; also called “pivotswap” ) . For example, after pivotswapping, the action subsequence becomes the swapped action subsequence 474 of ordered actions 7, 8, 4, 3, and 2 (wherein actions 7 and 8 are swapped their positions) , or the swapped action subsequence 476 of ordered actions 7, 8, 3, 4, and 2 (wherein actions 4 and 3 are swapped their positions) .
[0171] The actions of the action subsequence 464 may be edited or otherwise changed (step 478) . For example, after editing, the action subsequence becomes the edited action subsequence 480 of ordered actions 8, 7, 1, 9, and 0 (wherein actions 4, 3, and 2 are replaced with actions 1, 9, and 0) , or the edited action subsequence 482 of ordered actions 6, 5, 4, 1, and 2 (wherein actions 8, 7, and 3 are replaced with actions 6, 5, and 1) .
[0172] Thus, the expansion operation 434 may apply one or more transformations to at least a portion of the action sequence of the selected node (such as one or more shuffle operations 466, one or more pivotswap operations 472, one or more edit operations 478, or a combination thereof) to obtain a child node for linking to the selected node. Those skilled in the art will appreciate that, when multiple transformations are used in the expansion operation 434, the transformations may be applied to the same portion of the action sequence of the selected node or different portions thereof.
[0173] In some embodiments, the expansion operation 434 is not limited to a defined action space (such as the LLVM passes) . In some embodiments, the expansion operation 434 may generate a set of action sequence candidates using different transformations on the action sequence of the selected node and select the best candidate (with respect to the cost evaluation) as the child node of the selected node. In some embodiments, the selection of the best candidate may be feature-based selection (that is, based on the features of the action sequence candidates; described in more detail later) .
[0174] As shown in FIG. 12, in the evaluation operation 436, the action sequence of a selected node such as node 422 is performed in a real environment to evaluate the cost of the action sequence. For example, in some embodiments, LLVM may be used as the backend, and benchmarks may be compiled with the given action sequence (having a plurality of actions or optimization flags) , and run to retrieve runtimes.
[0175] For example, the cost evaluation of the action sequence on multiple benchmarks gives rise to multiple speedup numbers. For example, cBench has 18 benchmarks, and thus, in some embodiments where cBench is used, the cost evaluation of the action sequence on cBench gives rise to 18 speedup numbers. Then, the geometric mean (geomean) of the multiple speedup numbers may be calculated as the cost evaluation of the action sequence. Those skilled in the art will appreciate that geometric mean is usually more preferred than arithmetic mean as geometric mean is more stable for large fluctuations.
[0176] As shown in FIG. 13, in the backpropagation operation 438, the result (such as the cost evaluation) of the evaluation operation 436 on node 422 is used to update some statistics such as the score value of each of the nodes 422, 404, and 402 along the path from the evaluated node 422 to the root node 402. The GMCTS procedure 500 also updates its record of the best scored action sequence.
[0177] The selection, expansion, evaluation, and backpropagation operations 432, 434, 436, and 438 may be repeatedly performed to grow or otherwise expand the search tree 400 until an optimized action sequence is obtained or a predefined number of iterations are performed.
[0178] FIG. 14 is a flowchart showing the GMCTS procedure 500 for compilation optimization. When the procedure 500 starts (step 502) , the search tree is initialized by associating the root node with an action sequence and evaluating the cost of the action sequence (step 504) . At this step, the root node 402 may be associated with any suitable action sequence such as a randomly generated action sequence, a good action sequence (that is, an action sequence with a cost evaluation meeting a predefined condition) found from previous experiments, or the like.
[0179] At step 506, the selection operation is performed by traversing the search tree from the root node 402 along a path to select a node based on, for example, the UCT formula (1) .
[0180] At step 508, the expansion operation is performed wherein the search tree is expanded by adding one or more children nodes to the selected node, each of the one or more children nodes associated with a corresponding variant action sequence obtained based on the action sequence of the selected node (using, for example, the shuffle operation, pivotswap operation, edit operation, and / or the like) .
[0181] At step 510, the evaluation operation is performed wherein the cost of the variant action sequence of each of the one or more children nodes is evaluated.
[0182] At step 512, the backpropagation operation is performed wherein the nodes along the path from the selected node to the root node are updated.
[0183] At step 514, if the search is not completed, the procedure 500 goes to step 506 to repeat the selection, expansion, evaluation, and backpropagation operations.
[0184] If at step 514, the search is completed (for example, a certain number of iterations have been performed, an optimum action sequence has been found, or the like) , the best action sequence in the search tree is output (step 516) , and the procedure is ended (step 518) . The action sequence output from the procedure 500 may be used by the compiler for optimizing the code compilation.
[0185] In some embodiments, instead of using fixed-length action sequences, the GMCTS method may use variable-length action sequences with lengths variable within a predefined length threshold such as between 50 and 80 actions.
[0186] As those skilled in the art will appreciate, the GMCTS method disclosed herein is a search method and does not incorporate a learned cost model. Therefore, the GMCTS method may avoid the need of training large neural networks on multiple GPUs. The GMCTS method requires much fewer resources than a deep reinforcement learning framework that needs a learned cost model that may need to be trained on multiple GPUs.
[0187] Unlike MCTS, the GMCTS method may select an intermediate node (that is, a non-leaf node) and expand it with one or more children nodes. Moreover, when a node (which may be a leaf node or a non-leaf node) is selected, its performance measure (such as its cost evaluation) may be evaluated with the benchmarks, and a node may be selected multiple times and accordingly the action sequence thereof may be evaluated multiple times. This technique helps the GMCTS method to overcome the variance in the cost function and forces a stable performance.
[0188] Another difference between MCTS and GMCTS is that the GMCTS method does not add one action at a time during expansion. Rather, each node in the GMCTS search tree represents an action sequence, and the GMCTS method modifies the action sequence to obtain child nodes. It has been observed that action sequences with sufficient lengths (such as 50 to 80 actions) generally perform better than those with short lengths. Thus, the GMCTS method improves the complier optimization by avoiding searching on short action sequences. Moreover, the expansion operation 434 controls the number of children nodes and thus avoids the exponentially growing width of the search tree that may otherwise occur.
[0189] The LLVM environment has 124 different actions with a large action space. However, an action sequence for a compilation optimization may have any suitable length, which may be longer than 124 because a same action may be used multiple times in the action sequence. Consequently, there may exist a large number of different action sequences applicable for the compilation optimization although most of them may not be optimum. The GMCTS method avoids the need of searching a very large number of action sequences by using and modifying action sequences of a fixed length.
[0190] D. VARIANCE REDUCTION IN GMCTS USING WIDTH-BASED EXTRA EVALUATION METHOD
[0191] As described above, when a node is selected (by the selection operation 432) , the corresponding action sequence is evaluated (by the evaluation operation 436) in a real environment to obtain the evaluated cost of the action sequence. However, due to the limited evaluation accuracy in stochastic environments such as runtime, the evaluated cost of the action sequence may be biased from its expected or true cost (for example, the cost of the action sequence in an ideal environment) . For example, in some environments, the variance of evaluated cost may average around about 11%. Such a biased cost evaluation may bias the selection operation and consequently bias the compilation optimization. FIGs. 15A and 15B show an example.
[0192] FIG. 15A shows a portion of a search tree 400 where a selection operation 432 traversing the search tree 400 from the root node 402 (not shown) has reached the node 542 and needs to select a node between the children nodes 544 and 546. The node with lowest cost evaluation will be selected.
[0193] In this example, the nodes 544 and 546 have the same expected or true cost of 1.0. However, the evaluated cost of node 544 is about or approximately 1.0 (denoted “~1.0” in FIG. 15A) and the evaluated cost of node 546 is about 0.9. Therefore, node 546 has the lowest cost evaluation and will be selected. Consequently, node 546 will be visited more often than node 544 and thus will have more children than node 544 (see FIG. 15B) . As a result, the cost of node 546 may be overpromised and node 546 may dominate the search tree 400, thereby making the tree search ignore node 544 and expand node 546 as much as possible.
[0194] In some embodiments, the GMCTS method may evaluate each of one or more nodes (such as each of one or more promising nodes) for a plurality of times to obtain a plurality of individual cost evaluations and use the average of the plurality of individual cost evaluations as the cost evaluation of the node to reduce the variance of its cost evaluation for improving the performance of finding optimized action sequences in the stochastic environments such as runtime. As will be described in more detail below, the plurality of individual cost evaluations may be obtained using various methods and through multiple iterations. The GMCTS method may record the continuously growing number of individual cost evaluations for calculating the cost evaluation for the node.
[0195] For ease of description, the following description may only describe that a node may be evaluated for multiple times. While not explicitly described, those skilled in the art will understand that the multiple individual cost evaluations will be used for calculating the cost evaluation for the node.
[0196] In some embodiments, the GMCTS method may use a variance-reduction method to evaluate a selected node for a plurality of times to reduce the variance of its cost evaluation. For example, the GMCTS method may use a width-based extra evaluation method to determine the number of evaluations of the action sequence of a selected node based on the width of the node (that is, the number of children thereof) , and then evaluate the action sequence of the node for the determined number of times for variance reduction.
[0197] For example, the number of evaluations N of a selected node may be a function of WE, where N ≥ 1 is an integer, W is the width of the selected node, and E is a hyperparameter as the exponent of width-based extra evaluations.
[0198] As another example, the number of evaluations N of a selected node may be selected such that N≥WE (2)
[0199] For example, in some embodiments where the exponent E is set to 0.5, the number of evaluations of a selected node having 16 children (W = 16) is N = 4, meaning that the selected node will be evaluated at least 4 times.
[0200] As yet another example, the number of evaluations N of a selected node may be: N=int (WE) (3)
[0201] where int (x) represents an integer function for converting the parameter x to an integer such as a nearest integer of x, a smallest integer that is greater than x, a largest integer that is smaller than x, or the like.
[0202] The width-based number of evaluations N may give rise to more accurate tree search in promising subtrees or branches. FIG. 16 show an example.
[0203] With the use of the width-based extra evaluation method, as the number of children of node 546 grows, N grows and node 546 are evaluated more times, thereby bringing its cost evaluation closer to the true cost of about 1.0. As shown in FIG. 16, nodes 544 and 546 will eventually have similar cost evaluations of about 1.0, and thus the tree search will also expand node 544.
[0204] FIG. 17 is a flowchart showing the GMCTS procedure 500 using the width-based extra evaluation method. The process 500 is similar to that shown in FIG. 14 except that at step 506, the selected node is evaluated for N times.
[0205] The width-based extra evaluation method may provide more evaluations on more promising nodes, thereby making the tree search more accurate in more promising subtrees. The hyperparameter E controls how many evaluations a node receives when it gets wider (that is, having more children nodes) . A large hyperparameter E may lead to more accurate cost evaluations of the nodes.
[0206] In some embodiments, the hyperparameter E may be adjusted to control the number of width-based evaluations of promising action sequences and / or adapt the GMCTS method to different environments. For example, the hyperparameter E may be set to zero (0) for deterministic environments such as code size, and may be set to a higher value such as 0.5 for stochastic environments such as runtime.
[0207] In above embodiments, the GMCTS method uses the average of a plurality of individual cost evaluations of a node as the cost evaluation thereof. In some embodiments, the GMCTS method may use the median of a plurality of individual cost evaluations of a node as the cost evaluation thereof.
[0208] The advantage of the width-based extra evaluation method is evident for stochastic environments where it leads to reduction of variance in the final geometric mean (geomean) speedup. By evaluating promising action sequences multiple times, their variance of cost may be reduced. The action sequences that were promising because of luck may converge to their true values. The action sequences that initially gave a poor cost may also converge to their true values. Then, the true best action sequences may eventually be found.
[0209] E. VARIANCE REDUCTION IN GMCTS USING ALTERNATIVE QUERY PLAN EXPLORATION (ARENA) TOP-K METHOD
[0210] In some embodiments, the GMCTS method may use the alternative query plan exploration (Arena) top-k method for variance reduction to facilitate finding of optimized action sequences for stochastic environments such as the runtime objective.
[0211] The Arena top-k method maintains the top k states as the currently most promising states during the search. Herein, a state represents an action sequence whose cost has been evaluated over one or more multiple iterations, and the top-k states are the k states with best performance measures (for example, k states with lowest cost evaluations) , where k ≥ 1 is a predefined integer (for example, k = 1 for deterministic environments and k > 1 for stochastic environments such as runtime) . For ease of description, the top k states are also denoted “survivor states” with other states denoted “challenger states” , and the set of top-k states is denoted an “arena” .
[0212] Each of the k survivor states in the arena is considered a most promising state, and may be repeatedly evaluated for a plurality of times based on one or more conditions (in addition to other cost evaluations such as those described above) to obtain a plurality of individual cost evaluations for calculating the cost evaluation of the survivor node (for example, using average or median as described above) . For example, each of the k survivor states in the arena may be evaluated one or more times using the benchmarks based on the number of times the survivor states are challenged by a challenger state (described in more detail later) .
[0213] For example, the number of evaluations Ns of each survivor state may be a function of GF, where Ns ≥ 1 is an integer, G is the number of times the survivor states have been challenged, and F is a hyperparameter as the exponent of challenge-based extra evaluations, and may be any suitable number such as 0, 0.5, or the like.
[0214] As another example, the number of evaluations Ns of each survivor state may be selected such that Ns≥GF (4)
[0215] As yet another example, the number of evaluations N of a survivor state may be: Ns=int (GF) (5)
[0216] Thus, the above-described challenge-based extra evaluation method ensures that the survivor states are evaluated more times with more challenges being conducted.
[0217] In these embodiments, the k survivor states in the arena may be repeatedly updated by admitting promising challenger states into the arena and removing unpromising survivor states out of the arena. In other words, the k survivor states in the arena may be repeatedly challenged by challenger states.
[0218] For example, after a challenger state is evaluated, it challenges the survivor states by comparing the cost evaluation of the challenger state with that of the worst survivor state (that is, the survivor state having the highest cost evaluation or worst performance measure among all k survivor states) . Before the challenge or comparison, the number of evaluations Ns of each survivor state is updated and further individual cost evaluations for each survivor state in the arena may be conducted to update the cost evaluation of the survivor state.
[0219] If the challenge is unsuccessful (for example, the evaluated cost evaluation of the challenger state is greater than that of the worst survivor state) , the challenger state is not admitted into the arena and is maintained as a challenge state (that is, “rejected” ) .
[0220] If the challenge is successful (for example, the cost evaluation of the challenger state is smaller than that of the worst survivor state (that is, the performance measure of the challenger state is better than that of the worst survivor state) ) , then the challenger state is further evaluated to update its cost evaluation such that the number of evaluations thereof is equal to the average number of cost evaluations of the k survivor states. The challenger state is then admitted into the arena and becomes a survivor state. The worst survivor state is removed from the arena and becomes a challenger state.
[0221] FIGs. 18A to 18D show an example wherein the capacity k of the arena is k = 2.
[0222] As shown in FIG. 18A When the GMCTS method starts, the first k states 552 and 554 are admitted into the arena 550, wherein state 552 is evaluated once with a cost evaluation of 1.0 and state 554 is evaluated once with a cost evaluation of 0.9. None of states 552 and 554 are challenged yet.
[0223] During the execution of the GMCTS method, more challenger states are evaluated and their cost evaluations (or more precisely, the cost evaluations of their corresponding action sequences) are compared with the survivor states 552 and 554 in the arena 550. As shown in FIG. 18B, as the cost evaluations of challenger states 556 (about 1.1) are greater than the cost evaluation of the worst survivor state 552 in the arena 550, these challenger states 556 are rejected.
[0224] As the survivor states 552 and 554 in the arena 550 are challenged more times, they are also evaluated more times (as shown in FIG. 18B, the numbers of challenges of the survivor states 552 and 554 in the arena 550 have increased) , thereby making their cost evaluations more accurate. As shown in FIG. 18C, after the survivor states 552 and 554 in the arena 550 are challenged 100 times, they are evaluated 10 times leading to a cost evaluation of 1.1 (that is, changed from 1.0) for survivor state 552 and 0.9 for survivor state 554.
[0225] As shown in FIG. 18C, when a challenger state 558 wins the challenge (for example, its cost evaluation is smaller than that of the worst survivor state 552 in the area 550) , the challenger state 558 is further evaluated to have the same number of evaluations (for example, 10 times) as the survivor states 552 and 554 in the arena 550. The further evaluations of challenger state 558 generally reduce the evaluation variance and give a more accurate cost evaluation of 1.0 smaller than that of the worst survivor state 552 in the arena 550.
[0226] As shown in FIG. 18D, the challenger state 558 is admitted into the arena 550 and the worst survivor state 552 is removed from the arena 550.
[0227] Thus, the Arena top-k GMCTS method gradually increases evaluation budget on the k most promising states in the arena 550. In other words, if a survivor state is maintained in the arena 550 for longer time, it is then evaluated more times. The average number of evaluations of survivor states generally goes up over time. Consequently, a challenger state would need more evaluations to “defeat” the survivor state and be admitted into the arena 550.
[0228] This process repeats until the search finishes. At the end of the search, the arena 550 contains k states that are both promising and well-evaluated. Then, the best state (for example, the state with the lowest cost evaluation) in the arena 550 is selected as the final best state of the search.
[0229] FIG. 19 is a flowchart showing the GMCTS procedure 500 using the Arena top-k method. The process 500 is similar to that shown in FIG. 14 except that
[0230] · the GMCTS procedure 500 in these embodiments admits the action sequence of the root node into the arena (step 602) after the initialization step 504,
[0231] · the GMCTS procedure 500 updates the arena (step 604) when the variant action sequence of each of the one or more children nodes is evaluated at step 510, and
[0232] · the GMCTS procedure 500 outputs the best action sequence in the arena at step 516.
[0233] FIG. 20 shows the detail of step 604. For each variant state or action sequence obtained at step 510, the number of survivor states in the arena 550 is checked (step 612) . If the arena 550 does not have k survivor states, the variant state is admitted into the arena 550 (step 614) . If the arena 550 already has k survivor states, the k survivor states in the arena 550 are challenged by the variant state as described above (step 616) . If the challenge is successful (the “Yes” branch of step 618) , the arena is updated by admitting the variant state into the arena and removing the worst survivor state from the arena as described above (step 620) . If the challenge is unsuccessful (the “No” branch of step 618) , the arena is not updated.
[0234] After all variant state obtained at step 510 are processed by steps 612 to 620, the procedure 500 then goes to step 512.
[0235] In above embodiments, if a challenge is successful, then the challenger state is admitted into the arena and is further evaluated to update its cost evaluation such that the number of evaluations thereof is equal to the average number of cost evaluations of the k survivor states. In some embodiments, if a challenge is successful, then the challenger state is admitted into the arena and is further evaluated to update its cost evaluation such that the number of evaluations thereof is equal to the median number of cost evaluations of the k survivor states.
[0236] In some embodiments, the Arena top-k GMCTS method may be fine-tuned (for example, by adjusting the parameter k) for stochastic or deterministic environments. The Arena top-k method allows iterative tracking of the best current action sequences (that is, the survivor states) based on their cost evaluations. By iteratively evaluating the top-k action sequences in the arena multiple times, the cost-evaluation variances of the current top-k action sequences may be reduced. By replacing “bad” action sequences in the arena with promising action sequences outside thereof (that is, promising challenger states) , the arena is repeatedly updated to have the best action sequences. The best of the top-k action sequences in the arena may then be used for final evaluation and in the geomean speedup. Experiments has shown that the best of top-k action sequences results in an improved geomean speedup while reducing variance.
[0237] F. FEATURE-GUIDED GMCTS METHOD
[0238] In some embodiments, the GMCTS method may use features to guide the search and generate the best children nodes during the expansion operation. Herein, a feature is an integer value representing a characteristic of a specific IR. For example, Table 1 below lists 56 features described in Reference [9] (the ID column is included in Table 1 for ease of reference and is not used in the GMCTS method) . Each of these features has an integer value.
[0239] Table 1. List of program features
[0240] In these embodiments, each node is also associated with one or more features which may be used to guide the search. For example, each node may be associated with the plurality of features as shown in Table 1. When a node is added to the search tree, the set of features are then associated with the node.
[0241] The feature-guided GMCTS method uses the similarity between the features of different nodes to guide its search. In some embodiments, the Cosine similarity metric which is bounded between zero (0) and one (1) , may be used for calculating the similarity of features between two nodes as:
[0242] where A and B are the vectors of features of the two nodes, respectively; the symbol “·” represents inner production, that is, if A= [a0, a1, …, am] and B= [b0, b1, …, bm] , where a0, a1, …, am are features of A, and b0, b1, …, bm are features of B, then A·B=a0b0+a1b1+…+ambm; and the symbol “| |” represents the modulus of a vector, for example, and
[0243] As will be described in more detail below, the feature-guided GMCTS method uses ancestor nodes of the selected node (that is, other nodes along the path from the selected node to the root node) and a set of selected nodes such as an arena of top-k survivor nodes (which may or may not be repeatedly evaluated depending on the implementation) to facilitate the search.
[0244] FIG. 21 is a flowchart showing a procedure of the expansion operation 444, according to some embodiments of this disclosure.
[0245] After the selection operation, the feature-guided GMCTS method finds the most similar ancestor node of the selected node and uses the features of the ancestor node (step 632) .
[0246] More specifically, the feature-guided GMCTS method checks all ancestor nodes of the selected node to determine an ancestor node having features of the highest similarity (for example, using formula (6) ) to the features of the selected node.
[0247] FIG. 22 shows an example. The search tree 400 comprises a plurality of nodes 402 to 410, and an ancestor memory 642 stores the features of all nodes 402 to 410. In a selection operation, node 408 is selected. The feature-guided GMCTS method checks all ancestor nodes 404 and 402 of the selected node 408 and determines that node 402 has features of the highest similarity to those of the selected node 408. The cost evaluation of the most similar ancestor node 402 will later be used as that of the selected child node candidate.
[0248] Referring back to FIG. 21 and also with reference to FIG. 23, at step 634, the feature-guided GMCTS method generates a plurality of K children node candidates (K > 1 is an integer) each having a feature vector Xi.
[0249] At step 636, the feature-guided GMCTS method selects a child node candidate (for example, Xj, 1 ≤ j ≤ K) that maximizes the following similarity-comparison function: caSa (i) -cpSp (i) (7)
[0250] for all i = 1, 2, …, K, where
[0251] · Sa (i) is the similarity between the features of the i-th child node candidate and the features of an arena representative V, that is, Sa (i) =Sim (Xi, V) , and the arena representative V is the average of the features of all the arena survivors, that is, V= (V1+V2+…+Vk) / k (8)
[0252] where V is the arena representative vector, V1, V2, …, Vk are the feature vectors of the top-k survivor nodes in the arena, respectively;
[0253] · Sp (i) is the similarity between the features of the i-th child node candidate and the selected node 408, that is, Sa (i) =Sim (Xi, P) , where P is the feature vector of the selected node 408, and
[0254] · ca and cp are the coefficients or weights calculated as: cp=1-ca
[0255] where Tp is the number of visits of the selected node 408, and TR is the number of visits of the parent node 404 of the selected node 408.
[0256] After a selection is made, the cost evaluation of the most similar ancestor node 402 (obtained at step 632) is then used as that of the selected child node candidate Xj. In this way, the selected child node candidate does not need to be evaluated, thereby saving computational cost.
[0257] At step 638, the selected child node candidate Xj is then linked to the current node 408 as a child node thereof.
[0258] Steps 632 to 638 may be repeated to generate other children nodes for expansion.
[0259] In some alternative embodiments, the child node candidate selected at step 636 is evaluated. In these embodiments, the expansion operation 444 does not need step 632.
[0260] The feature-guided GMCTS method facilitates the transfer of knowledge from other parts of the search tree which might not necessarily be directly connected to the selected node. In the feature-guided GMCTS method, when a node is in the early stages, Sp being low has more impact, which provides more exploration. On the other hand, when the number of visits are high, Sa being high has more impact which provides more exploitation toward the arena survivors.
[0261] The feature-guided GMCTS method leverages previous knowledge in the search. When a node is similar to a previous promising node, the search may be directed toward that node. On the other hand, if a node is similar to a previous poor node, the search may be directed away from that node. Also, if a node is similar to another node with poor evaluations, it is less likely to be selected.
[0262] By using the arena, the feature-guided GMCTS method may have more exploration in the beginning stages of a node and more exploitation toward the end. Thus, in the beginning the search tree is more likely to spread in the search space and more likely to find an optimized action sequence in the end.
[0263] In some embodiments, the GMCTS method may be implemented using the CompilerGym framework and tested on the cBench dataset (which is easily downloadable and runnable via the CompilerGym framework) .
[0264] Tests have been performed on the x86 architecture on the cBench dataset. The testing results show that the GMCTS method disclosed herein outperforms many existing compilation optimization methods (such as NeverGrad) on binary size and runtime objectives. The GMCTS method disclosed herein may perform well on deterministic and stochastic environments.
[0265] Table 2 below shows the testing results showing the performance comparison of the GMCTS method disclosed with NeverGrad and genetic beam search (GBS) (runtime speedup) . Each test has 10 trials.
[0266] Table 2: Geomean speedup on cBench dataset on runtime (x86)
[0267] As can be seen, the GMCTS method disclosed herein has a reduced variance over GBS, meaning that the variance reduction methods used in GMCTS are effective. With the Arena top-k method, the GMCTS method exhibits the best results of 1.131, outperforming the version without using the Arena top-k method. These results are obtained after the top-k action sequences from the arena were evaluated again after search and the best of top-k with highest speedup returned. The results show that using the Arena top-k method, the GMCTS method gains performance improvement during and after search.
[0268] Although in above embodiments, the GMCTS method is performed by a computer network system 100, in some embodiments, the GMCTS method may be performed by a standalone computing device.
[0269] G. ADVANTAGES AND BENEFITS OF THE GMCTS METHOD
[0270] With above description, those skilled in the art will appreciate that the GMCTS method disclosed herein combines the MCTS method with genetic algorithm for search, and is suitable for optimizing action sequences in stochastic environments such as runtime. The GMCTS method disclosed herein may provide improved runtime speedup over the prior-art baseline.
[0271] As the GMCTS method disclosed herein does not require a learned cost model, the GMCTS method disclosed herein may avoid the generally expensive need of training large neural networks.
[0272] In some embodiments, the GMCTS method may evaluate a same action sequence multiple times to reduce the variance of its cost, which gives an advantage for stochastic environments where cost evaluations may vary for the same action sequences.
[0273] In some embodiments, the GMCTS method may use geomean of multiple speedup numbers for calculating the cost evaluation of the action sequence, which is usually more stable than arithmetic mean for large fluctuations.
[0274] In some embodiments, the GMCTS method may use the width-based extra evaluation method to evaluate a same action sequence multiple times. The rate of evaluation counts for promising nodes is controllable or otherwise tunable for adapting different environments.
[0275] In some embodiments, the GMCTS method may use the Arena top-k method to track the best action sequences and evaluate them multiple times. By iteratively evaluating the top-k action sequences in the arena multiple times, the cost-evaluation variances of the current top-k action sequences may be reduced. By replacing “bad” action sequences in the arena with promising action sequences outside thereof (that is, promising challenger states) , the arena is repeatedly updated to have the best action sequences. The best of the top-k action sequences in the arena may then be used for final evaluation and in the geomean speedup.
[0276] In some embodiments, the GMCTS method may use features to guide the search thereby facilitating the transfer of knowledge from other parts of the search tree. The feature-guided GMCTS method leverages previous knowledge in the search. When a node is similar to a previous promising node, the search may be directed toward that node. On the other hand, if a node is similar to a previous poor node, the search may be directed away from that node. Also, if a node is similar to another node with poor evaluations, it is less likely to be selected.
[0277] By using the arena, the feature-guided GMCTS method may have more exploration in the beginning stages of a node and more exploitation toward the end. Thus, in the beginning the search tree is more likely to spread in the search space and more likely to find an optimized action sequence in the end.
[0278] The GMCTS method disclosed herein is a generic search algorithm suitable for use in various backends such as LLVM and GCC. The GMCTS method disclosed herein is framework independent, meaning that it may be easily integrated with other frameworks with environments for evaluation and testing such as CompilerGym. The GMCTS method disclosed herein is a purely search algorithm, and may be implemented and tested in CPU machines and does not need highly powered GPUs for training and evaluation.
[0279] In some embodiments, the GMCTS method disclosed herein is dependent on a real cost function (that is, a signal coming from the environment) rather than a predicted signal. Therefore, the GMCTS method disclosed herein may be used for environments that can provide real cost heuristics.
[0280] The GMCTS method disclosed herein is not machine dependent, and may be used for various instruction set architectures such as x86 CPUs, ARM CPUs, GPUs, and the like to speedup runtimes of programs, or reduce code size produced by compilation.
[0281] Moreover, the GMCTS method disclosed herein is not restricted to the compilation optimization application and it may be used for any heuristic search application requiring sequence optimization.
[0282] H. DEFINITIONS OF ACRONYMS &GLOSSARIES
[0283] LLVM: The compiler infrastructure for compiling and run benchmarks.
[0284] Benchmark: A program compiled and run during search and evaluation of search algorithms.
[0285] Search algorithm: Also called “policy” or “planner” , which is a routine that operates on a search space and returns best candidates based on a cost function.
[0286] Search space: A set of compiler-optimization flags.
[0287] Dataset: A set of benchmarks used for search and evaluation of search algorithms.
[0288] CompilerGym: A compilation optimization framework used to develop and evaluate search algorithms on optimizing LLVM phase ordering.
[0289] Evaluation strategy: A method by which the performance of a search algorithm is measured.
[0290] RL: Reinforcement learning.
[0291] AI: Artificial intelligence.
[0292] MCTS: Monte Carlo tree search.
[0293] GMCTS: Genetic Monte Carlo tree search.
[0294] GBS: Genetic beam search.
[0295] Action sequence: A list of actions representing compilation optimization flags.
[0296] State: A unique action sequence representing a unique state, interchangeably used with action sequence.
[0297] IR: Intermediate representation, which is generated from the code by the compiler such as LLVM.
[0298] Feature: An integer value representing a characteristic of a specific IR.
[0299] Arena: A fixed-size set with the most promising action sequences so far.
[0300] Objective: A function that shows the goal of the search algorithm (such as code size, binary size, runtime, and / or the like) .
[0301] SGA: Stochastic gradient ascent, which is a technique to maximize a score function.
[0302] UCT: Upper confidence bound applied to trees.
[0303] GCC: GNU compiler collection.
[0304] I. REFERENCES
[0305] [1] Cummins, C., et al. (2022, April) . “CompilerGym: robust, performant compiler optimization environments for AI research. ” In 2022 IEEE / ACM International Symposium on Code Generation and Optimization (CGO) (pp. 92-105) . IEEE.
[0306] [2] Horgan, D., et al. (2018) . “Distributed prioritized experience replay. ” arXiv preprint arXiv: 1803.00933.
[0307] [3] Mnih, V., et al. (2016, June) . “Asynchronous methods for deep reinforcement learning. ” In International conference on machine learning (pp. 1928-1937) . PMLR.
[0308] [4] Espeholt, L., et al. (2018, July) . “Impala: Scalable distributed deep-rl with importance weighted actor-learner architectures. ” In International conference on machine learning (pp. 1407-1416) . PMLR.
[0309] [5] Schulman, J., et al. (2017) . “Proximal policy optimization algorithms. ” arXiv preprint arXiv: 1707. 06347.
[0310] [6] Wang, L., et al. (2020) . “Learning search space partition for black-box optimization using monte carlo tree search. ” Advances in Neural Information Processing Systems, 33, 19511-19522.
[0311] [7] Ansel, J., et al. (2014, August) . “Opentuner: An extensible framework for program autotuning. ” In Proceedings of the 23rd international conference on Parallel architectures and compilation (pp. 303-316) .
[0312] [8] Rapin, J., &Teytaud, O. (2018) . “Nevergrad-A gradient-free optimization platform. ” https: / / facebookresearch. github. io / nevergrad /
[0313] [9] Haj-Ali, et al. (2020) . “Autophase: Juggling HLS phase orderings in random forests with deep reinforcement learning. ” Proceedings of Machine Learning and Systems, 2, 70-81.
[0314] Although embodiments have been described above with reference to the accompanying drawings, those of skill in the art will appreciate that the embodiments described above are examples only and other embodiments are readily available. For example, in various embodiments, various aspects of above-described embodiments may be combined. Generally, variations and modifications may be made without departing from the scope thereof as defined by the appended claims.
Claims
1.A computerized method comprising:using a search tree to determine an optimized compilation-action sequence for program compilation optimization;wherein the search tree comprises a plurality of nodes comprising a plurality of compilation-action sequences and arranged in a tree structure, the optimized compilation-action sequence being one of the plurality of compilation-action sequences;wherein each node comprises a respective compilation-action sequence of a plurality of compilation actions.2.The computerized method of claim 1, wherein the compilation-action sequence of a child node is obtained based on the compilation-action sequence of the parent node.3.The computerized method of claim 1 or 2, wherein the number of compilation actions of each of the plurality of compilation-action sequences is greater than or equal to 50, and smaller than or equal to 80.4.The computerized method of any one of claims 1 to 3, wherein each of the plurality of compilation-action sequences has a same number of compilation actions.5.The computerized method of any one of claims 1 to 4, wherein said using the search tree to determine the optimized compilation-action sequence comprises:selecting a node of the plurality of nodes by traversing the search tree from a root node thereof along a path to the node based on one or more selection conditions;generating one or more variant compilation-action sequences based on the compilation-action sequence of the selected node;adding one or more children nodes to the selected node to expand the search tree, each child node comprising a respective one of the one or more variant compilation-action sequences;obtaining a performance measure of the compilation-action sequence of each of the one or more children nodes; andupdating each node along the path from the selected node to the root node.6.The computerized method of claim 5, wherein said selecting the node of the plurality of nodes comprises:traversing the search tree from a root node thereof along a path to find the node that maximizing an upper confidence bound applied to trees (UCT) formula.7.The computerized method of claim 5, wherein said selecting the node of the plurality of nodes comprises:starting from the root as a current node,(1) selecting a node from the current node and the children nodes thereof based on the one or more selection conditions; and(2) if the selected node is not the current node and the selected node is not a leaf node, letting the selected node be the current node and going to (1) .8.The computerized method of any one of claims 5 to 7, wherein said generating the one or more variant compilation-action sequences comprises at least one of:reordering at least a first portion of the compilation-action sequence of the selected node;swapping a second portion and a third portion of the compilation-action sequence of the selected node; andreplacing a fourth portion of the compilation-action sequence of the selected node with replacement compilation actions.9.The computerized method of any one of claims 5 to 8, wherein said obtaining the performance measure of the compilation-action sequence of each of the one or more children nodes comprises:obtaining the performance measure of the compilation-action sequence of each of the one or more children nodes by evaluating performance of one or more benchmarks using the compilation-action sequence of the child node.10.The computerized method of claim 9, wherein said obtaining the performance measure of the compilation-action sequence of each of the one or more children nodes comprises:obtaining the performance measure of the compilation-action sequence of each of the one or more children nodes using a geometric mean of results of the performance evaluation of the one or more benchmarks.11.The computerized method of any one of claims 5 to 10 further comprising:obtaining N individual performance measures of the compilation-action sequence of each of one or more of the plurality of nodes by evaluating the compilation-action sequence of the node for N times, where N > 1 is an integer; andobtaining a performance measure of the compilation-action sequence of the node based on the N individual performance measures.12.The computerized method of claim 11, wherein said obtaining the performance measure of the compilation-action sequence of the node based on the N individual performance measures comprises:obtaining the performance measure of the compilation-action sequence of the node as an average of the N individual performance measures, or as a median of the N individual performance measures.13.The computerized method of claim 11 or 12, wherein N is determined based on the number of children nodes of the node.14.The computerized method of claim 13, wherein N is a function of WE, where W is the number of children nodes of the node, and E is a hyperparameter.15.The computerized method of claim 14, wherein N≥WE.16.The computerized method of claim 14 or 15, wherein E is zero (0) or 0.5.17.The computerized method of any one of claims 5 to 16 further comprising:selecting k compilation-action sequences from the plurality of compilation-action sequences as k survivor compilation-action sequences, where k ≥ 1 is an integer; andfor each of the one or more children nodes, after said obtaining the performance measure of the compilation-action sequence of the child node,comparing the performance measure of the compilation-action sequence of the child node at least with that of a worst one of the k survivor compilation-action sequences having a worst performance measure, andif the performance measure of the compilation-action sequence of the child node is better than that of the worst survivor compilation-action sequence, removing the worst survivor compilation-action sequence from the k survivor compilation-action sequences and including the compilation-action sequence of the child node as one of the k survivor compilation-action sequences.18.The computerized method of claim 17, wherein the k compilation-action sequences have best performance measures among the plurality of compilation-action sequences.19.The computerized method of claim 17 or 18 further comprising:evaluating each of the k survivor compilation-action sequences for Ns times to obtain the performance measure thereof, where Ns ≥ 1 is an integer.20.The computerized method of claim 19, wherein Ns is determined based on a number of times of performing said comparing the performance measure of the compilation-action sequence of the child node at least with that of the worst survivor compilation-action sequence.21.The computerized method of claim 20, wherein Ns is a function of GF, where G is the number of times of performing said comparing the performance measure of the compilation-action sequence of the child node at least with that of the worst survivor compilation-action sequence, and F is a hyperparameter.22.The computerized method of claim 21, wherein Ns≥GF.23.The computerized method of claim 21 or 22, wherein F is zero (0) or 0.5.24.The computerized method of any one of claims 17 to 23, wherein, if the performance measure of the compilation-action sequence of the child node is better than that of the worst survivor compilation-action sequence, evaluating the compilation-action sequence of the child node such that a number of evaluations thereof is equal to an average number of evaluations of the k compilation-action sequences.25.The computerized method of any one of claims 5 to 24, wherein each of the plurality of nodes is associated with one or more features; andwherein said wherein said generating the one or more variant compilation-action sequences comprises: for each of the one or more variant compilation-action sequences,generating a plurality of candidate compilation-action sequences based on the compilation-action sequence of the selected node, andselecting one of the plurality of candidate compilation-action sequences as the variant compilation-action sequence, the selected candidate compilation-action sequence maximizing a similarity-comparison function.26.The computerized method of claim 25, wherein each of the one or more features is a value; and wherein the similarity-comparison function comprises a similarity function Sim () defined as: where A and B are vectors of features of two nodes, respectively; the symbol “·” represents inner production, and the symbol “| |” represents the vector modulus.27.The computerized method of claim 26, wherein the similarity-comparison function is: caSa (i) -cpSp (i)where· i = 1, 2, …, K, and K is the number of the candidate compilation-action sequences,· Sa (i) =Sim (Xi, V) , where Xi represents the features of the i-th candidate compilation-action sequence, V= (V1+V2+…+Vt) / t, V1, V2, …, Vt are the vectors of features of t compilation-action sequences, respectively, and t ≥ 1 is an integer, ·Sa (i) = Sim (Xi, P) , where P is the feature vector of the selected node, and· ca and cp are coefficients calculated as:cp=1-cawhere Tp is a number of visits of the selected node, and TR is a number of visits of a parent node of the selected node.28.The computerized method of claim 27, wherein the performance measures of the t compilation-action sequences are better than those of other compilation-action sequences.29.The computerized method of any one of claims 25 to 28 further comprising:finding an ancestor node along a reversed path from the selected node to the root node, the ancestor node having a highest similarity to the selected node in terms of the one or more features; andletting the performance measure of the selected candidate compilation-action sequence be that of the ancestor node.30.The computerized method of claim 29 dependent from claim 26, wherein said similarity is calculated using the similarity function Sim () .31.A computing apparatus comprising:a processor for performing the computerized method of any one of claims 1 to 30.32.A computer system comprising:a processor for performing the computerized method of any one of claims 1 to 30.33.One or more non-transitory computer-readable storage media comprising computer-executable instructions, wherein the instructions, when executed, cause a processor to perform the computerized method of any one of claims 1 to 30.
Citation Information
Patent Citations
Agent modeling method for multi-objective compilation optimization sequence selection
CN112035116A
Machine learning algorithm search using symbol programming
CN115398446A
System and method for branch function based obfuscation
US20130036473A1
Method and system for providing a context-sensitive, non-intrusive data processing optimization framework
US20230004563A1
Cited By
Dynamic traversal optimization method, equipment and medium
CN119536745A
Compiling method and system for near storage computing architecture, electronic equipment and storage medium
CN120144134A
Compilation methods and systems, electronic devices and storage media for near-memory computing architectures
CN120144134B
