Intermediate representation optimization method and device for code and related equipment

CN123011234APending Publication Date: 2026-10-30HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510571832.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-30
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

但是,实际应用场景中,基于优化后的IR所最终编译得到的计算机可执行代码,在硬件上的执行性能仍然较差

Benefits of technology

[0024]第五方面,本申请提供了一种包含指令的计算机程序产品,当其在计算设备上运行时,使得计算设备执行上述第一方面或第一方面的任一种实现方式所述的代码的中间表示优化方法的操作步骤。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123011234A_ABST
    Figure CN123011234A_ABST
Patent Text Reader

Abstract

The application relates to a code intermediate representation optimization method and device and related equipment, and relates to the technical field of computers. A first intermediate representation including a plurality of operators is acquired, and optimization strategy searching is performed on the plurality of operators according to an optimization condition, so that an optimization strategy sequence and optimization parameters satisfying the optimization condition are obtained for a performance optimization result generated for the first intermediate representation. The optimization strategy sequence includes a plurality of optimization strategies for sequentially converting the codes of the plurality of operators, and the optimization parameters include parameters in each optimization strategy. The codes of the plurality of operators in the first intermediate representation are converted according to the optimization strategy sequence and the optimization parameters, so that a second intermediate representation is obtained. In this way, the optimization strategy sequence and the optimization parameters for optimizing the intermediate representation are searched according to the performance optimization result generated for the intermediate representation, so that the computer executable code generated based on the optimized intermediate representation can reach a high level of performance in a hardware environment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method, apparatus and related equipment for optimizing intermediate representation of code. Background Technology

[0002] User-developed source code, such as code programmed in Java or C, is typically compiled into an intermediate representation (IR). Depending on the instruction set and architecture supported by the hardware running the code, the IR is then compiled into executable code, such as assembly language or machine language. IR is a code abstraction representation that lies between source code and executable code. It can include a sequence of operators that can be executed sequentially.

[0003] In fields such as high-performance computing (HPC) and artificial intelligence (AI), compiler optimization techniques are often used to optimize the IR (Instructions for Replication) while keeping the semantics largely unchanged, in order to improve the execution performance of the final executable code compiled based on the IR on the hardware, such as improving the execution efficiency of the code.

[0004] Currently, users typically define optimization strategies for each operator in the IR (Integrated Resource Interpreter), and specify the execution order of these strategies. The compiler then optimizes the IR sequentially using these strategies, specifically optimizing the code of each operator in the IR. However, in practical applications, the executable code compiled from the optimized IR still exhibits poor hardware performance. Summary of the Invention

[0005] This application provides a method for optimizing intermediate representations of code to improve the execution performance of computer-executable code compiled based on the optimized intermediate representation on hardware. Furthermore, this application also provides corresponding optimization apparatus, computing devices, computer-readable storage media, and computer program products.

[0006] Firstly, this application provides a method for optimizing intermediate representations of code, which can be executed by an optimization device for optimizing intermediate representations of code. Specifically, the optimization device obtains a first intermediate representation, which includes multiple operators. These multiple operators can be all or some of the operators in the first intermediate representation. Then, the optimization device searches for optimization strategies for the multiple operators according to optimization conditions to obtain a first optimization strategy sequence and optimization parameters. The first optimization strategy sequence includes multiple first optimization strategies that sequentially transform the code of the multiple operators. These multiple first optimization strategies are used to optimize the performance of the multiple operators when executed in a hardware environment. The optimization parameters include parameters in each of the multiple first optimization strategies. Furthermore, the performance optimization result produced by the first optimization strategy sequence and optimization parameters for the first intermediate representation satisfies the optimization conditions. For example, the optimization performance produced by the first optimization strategy sequence and optimization parameters for the first intermediate representation is higher than the optimization performance produced by other optimization strategy sequences or other parameter values ​​of the optimization strategies in the first optimization strategy sequence for the first intermediate representation. Finally, the optimization device transforms the code of the multiple operators in the first intermediate representation according to the first optimization strategy sequence and optimization parameters to obtain a second intermediate representation.

[0007] Because the optimization of the first intermediate representation is based on the performance optimization results generated for the first intermediate representation, and the optimization strategy sequence and optimization parameters are searched for for multiple operators in the first intermediate representation, rather than using multiple optimization strategies to optimize the first intermediate representation sequentially based on the user-specified order or the default order (such as the execution order of operators), this allows the code of multiple operators in the first intermediate representation to be transformed based on the searched optimization strategy sequence and optimization parameters to obtain the second intermediate representation. This enables the computer executable code compiled based on the second intermediate representation to achieve a higher performance level on the hardware environment.

[0008] In one possible implementation, when the optimization device searches for optimization strategies for multiple operators based on optimization conditions to obtain a first optimization strategy sequence and optimization parameters, it may first acquire a description file. This description file records the input and output operators of each optimization strategy among the multiple optimization strategies. The input operators are those supported by the optimization strategy for transformation, and the output operators are those transformed using the optimization strategy. Then, the optimization device can determine candidate optimization strategies corresponding to each operator from the multiple optimization strategies based on the description file. Based on these candidate optimization strategies, it determines a combination space, which includes multiple candidate optimization strategy sequences. Each candidate optimization strategy sequence includes multiple candidate optimization strategies that sequentially transform the code of multiple operators. The candidate optimization strategies differ between different candidate optimization strategy sequences, or the execution order of the candidate optimization strategies differs. Therefore, the optimization device can search for optimization strategies from the combination space based on optimization conditions to obtain the first optimization strategy sequence and optimization parameters. Thus, the optimization device can determine multiple candidate optimization strategies that may be adopted for optimizing multiple operators in the first IR based on the description file, and determine the combination space accordingly. The optimization device can then determine the optimization strategy sequence and optimization parameters that can improve the performance optimization effect of the intermediate representation for the multiple operators from the determined combination space, thereby improving the performance of the computer executable code generated based on the optimized intermediate representation on the hardware environment.

[0009] In one possible implementation, the description file is also used to record the optimization order among different optimization strategies. Specifically, when the optimization device determines the combinatorial space based on the candidate optimization strategies corresponding to multiple operators, it can determine the combinatorial space based on the optimization order among different optimization strategies and the candidate optimization strategies corresponding to multiple operators. Thus, by defining the optimization order among different optimization strategies through the description file, candidate optimization strategy sequences in the combinatorial space that do not satisfy the optimization order can be filtered out, achieving pruning of the combinatorial space. This effectively reduces the number of candidate optimization strategy sequences included in the combinatorial space, thereby reducing the computational load required to subsequently search for the first optimization strategy sequence and optimization parameters from the combinatorial space, and improving computational efficiency.

[0010] In one possible implementation, the optimization order among different optimization strategies includes the sorting of multiple groups, each group comprising at least one optimization strategy. Thus, the execution order among the multiple groups indicates the execution order among the multiple optimization strategies, thereby achieving effective pruning of the combinatorial space. This reduces the computational cost required to subsequently search for the first optimization strategy sequence and optimization parameters from the combinatorial space, improving computational efficiency.

[0011] In one possible implementation, when the optimization device searches for optimization strategies from the combinatorial space based on optimization conditions to obtain a first optimization strategy sequence and optimization parameters, it may specifically determine a first set, which includes at least one candidate optimization strategy sequence from the combinatorial space, and determine at least one parameter combination for each candidate optimization strategy sequence in the first set. Each parameter combination is a parameter value among the multiple candidate optimization strategies included in the candidate optimization strategy sequence. Then, the optimization device can use an artificial intelligence (AI) model to predict the performance optimization result of each parameter combination used by each candidate optimization strategy sequence for the first intermediate representation, and determine the first optimization strategy sequence and optimization parameters based on the optimization conditions and the performance optimization result of each parameter combination used by each candidate optimization strategy sequence for the first intermediate representation. Thus, by determining the performance optimization result through AI model prediction, it is possible to obtain the performance optimization result without running computer-executable code on a real hardware environment, which can effectively improve the efficiency of the optimization device in obtaining the performance optimization result.

[0012] In one possible implementation, when the optimization device determines the first optimization strategy sequence and optimization parameters based on the performance optimization results generated by each parameter combination used by each candidate optimization strategy sequence for the first intermediate representation according to the optimization conditions, specifically, it can determine the first candidate optimization strategy sequence and the first parameter combination used by the first candidate optimization strategy sequence based on the performance optimization results generated by each parameter combination used by each candidate optimization strategy sequence for the first intermediate representation. The performance optimization results generated by the first candidate optimization strategy sequence using the first parameter combination for the first intermediate representation are better than the performance optimization results generated by the parameter combinations used by the other candidate optimization strategy sequences for the first intermediate representation. Then, the optimization device uses the first candidate optimization strategy sequence and the first parameter combination to transform the code of multiple operators in the first intermediate representation to obtain a test intermediate representation, and compiles the test intermediate representation to obtain computer-executable code. Thus, the optimization device can execute the computer-executable code in a hardware environment to obtain the actual optimization performance generated by the first candidate optimization strategy sequence and the first parameter combination for the first intermediate representation, and determine the first optimization strategy sequence and optimization parameters based on the optimization conditions and the actual optimization performance of the first candidate optimization strategy sequence and the first parameter combination for the first intermediate representation. In this way, by first using AI models to predict the performance optimization results of a large number of candidate optimization strategy sequences and parameter combinations, and then using hardware environment to verify the performance optimization results of a small number of candidate optimization strategy sequences and parameter combinations, we can not only improve the overall efficiency of determining the first optimization strategy sequence and optimization parameters, but also ensure the accuracy of determining the first optimization strategy sequence and optimization parameters.

[0013] In one possible implementation, when the optimization device determines the first optimization strategy sequence and optimization parameters based on the optimization conditions, the first candidate optimization strategy sequence, and the actual optimization performance of the first parameter combination for the first intermediate representation, it may first determine a second set based on the actual optimization performance of the first candidate optimization strategy sequence and the first parameter combination for the first intermediate representation. The second set includes at least one candidate optimization strategy sequence in the combination space, and the second set does not overlap with the first set. Then, the optimization device determines at least one parameter combination for each candidate optimization strategy sequence in the second set, and uses an AI model to predict the performance optimization result of each parameter combination used by each candidate optimization strategy sequence in the second set for the first intermediate representation. Thus, the optimization device can determine the first optimization strategy sequence and optimization parameters based on the optimization conditions, the performance optimization result of each parameter combination used by each candidate optimization strategy sequence in the second set for the first intermediate representation, and the actual optimization performance of the first candidate optimization strategy sequence and the first parameter combination for the first intermediate representation. In this way, the optimization device can determine the first optimization strategy sequence and optimization parameters whose performance optimization result satisfies the optimization conditions from the combination space through iterative search, improving the accuracy of determining the optimization strategy sequence and optimization parameters for the first intermediate representation.

[0014] Secondly, this application provides an intermediate representation optimization apparatus for code. The apparatus includes: an acquisition module for acquiring a first intermediate representation, the first intermediate representation including multiple operators; a search module for searching optimization strategies for the multiple operators according to optimization conditions to obtain a first optimization strategy sequence and optimization parameters, the first optimization strategy sequence including multiple first optimization strategies that sequentially transform the code of the multiple operators, the multiple first optimization strategies being used to optimize the performance of the multiple operators when executed in a hardware environment, the optimization parameters including parameters in each of the multiple first optimization strategies, the performance optimization result generated by the first optimization strategy sequence and optimization parameters for the first intermediate representation satisfying the optimization conditions; and a conversion module for converting the code of the multiple operators in the first intermediate representation according to the first optimization strategy sequence and optimization parameters to obtain a second intermediate representation.

[0015] In one possible implementation, the search module is configured to: obtain a description file, which records the input and output operators of each of a plurality of optimization strategies, wherein the input operators are operators supported by the optimization strategy for transformation, and the output operators are operators obtained by transformation using the optimization strategy; determine candidate optimization strategies corresponding to multiple operators from the plurality of optimization strategies according to the description file; determine a combination space according to the candidate optimization strategies corresponding to the multiple operators, wherein the combination space includes multiple candidate optimization strategy sequences, each of the multiple candidate optimization strategy sequences including multiple candidate optimization strategies that sequentially transform the code of multiple operators, and the candidate optimization strategies between different candidate optimization strategy sequences are different or the execution order of the candidate optimization strategies is different; and search for optimization strategies from the combination space according to optimization conditions to obtain a first optimization strategy sequence and optimization parameters.

[0016] In one possible implementation, the description file is also used to record the optimization order among different optimization strategies; the search module is used to determine the combination space based on the optimization order among different optimization strategies and the candidate optimization strategies corresponding to multiple operators respectively.

[0017] In one possible implementation, the optimization order among different optimization strategies includes the sorting among multiple groups, each of which includes at least one optimization strategy.

[0018] In one possible implementation, the search module is configured to: determine a first set, the first set including at least one candidate optimization strategy sequence in a combinatorial space; determine at least one parameter combination for each candidate optimization strategy sequence in the first set, each parameter combination being a parameter value among a plurality of candidate optimization strategies included in the candidate optimization strategy sequence; use an artificial intelligence (AI) model to predict the performance optimization result generated by each parameter combination used by each candidate optimization strategy sequence for a first intermediate representation; and determine a first optimization strategy sequence and optimization parameters based on optimization conditions and the performance optimization result generated by each parameter combination used by each candidate optimization strategy sequence for the first intermediate representation.

[0019] In one possible implementation, the search module is configured to: determine a first candidate optimization strategy sequence and a first parameter combination used by the first candidate optimization strategy sequence based on the performance optimization results generated by each parameter combination used by each candidate optimization strategy sequence for the first intermediate representation, wherein the performance optimization results generated by the first candidate optimization strategy sequence using the first parameter combination for the first intermediate representation are better than the performance optimization results generated by the parameter combinations used by the other candidate optimization strategy sequences for the first intermediate representation; convert the code of multiple operators in the first intermediate representation using the first candidate optimization strategy sequence and the first parameter combination to obtain a test intermediate representation; compile the test intermediate representation to obtain computer-executable code; execute the computer-executable code in a hardware environment to obtain the actual optimization performance generated by the first candidate optimization strategy sequence and the first parameter combination for the first intermediate representation; and determine a first optimization strategy sequence and optimization parameters based on the optimization conditions and the actual optimization performance of the first candidate optimization strategy sequence and the first parameter combination for the first intermediate representation.

[0020] In one possible implementation, the search module is configured to: determine a second set based on the actual optimization performance of a first candidate optimization strategy sequence and a first parameter combination for a first intermediate representation, the second set including at least one candidate optimization strategy sequence in the combination space, the second set not overlapping with the first set; determine at least one parameter combination for each candidate optimization strategy sequence in the second set; use an AI model to predict the performance optimization result of each parameter combination used by each candidate optimization strategy sequence in the second set for the first intermediate representation; and determine a first optimization strategy sequence and optimization parameters based on optimization conditions, the performance optimization result of each parameter combination used by each candidate optimization strategy sequence in the second set for the first intermediate representation, and the actual optimization performance of the first candidate optimization strategy sequence and the first parameter combination for the first intermediate representation.

[0021] The intermediate representation optimization device for the code provided in the second aspect corresponds to the intermediate representation optimization method for the code provided in the first aspect. Therefore, the technical effects of any implementation method in the second aspect can be found in the relevant descriptions of the technical effects of the corresponding implementation methods in the first aspect, and will not be repeated here.

[0022] Thirdly, this application provides a computing device, which includes a processor and a memory. The processor and the memory communicate with each other. The processor executes instructions stored in the memory to cause the computing device to execute an intermediate representation optimization method for the code as described in the first aspect or any implementation thereof. It should be noted that the memory can be integrated into the processor or can be independent of the processor. The computing device may also include a bus. The processor is connected to the memory via the bus. The memory may include readable storage and random access memory.

[0023] Fourthly, this application provides a computer-readable storage medium storing instructions that, when executed on a computing device, cause the computing device to perform the operation steps of the intermediate representation optimization method of the code described in the first aspect or any implementation thereof.

[0024] Fifthly, this application provides a computer program product containing instructions that, when run on a computing device, cause the computing device to execute the operational steps of the intermediate representation optimization method of the code described in the first aspect or any implementation thereof.

[0025] Based on the implementation methods provided in the above aspects, this application can be further combined to provide more implementation methods. Attached Figure Description

[0026] Figure 1 A schematic diagram of the structure of an exemplary data processing system provided in this application;

[0027] Figure 2 A flowchart illustrating an intermediate representation optimization method for code provided in this application;

[0028] Figure 3 A flowchart illustrating the process of determining the first optimization strategy sequence and optimization parameters through iterative search;

[0029] Figure 4 A flowchart illustrating the process of optimizing the first IR using multiple first optimization strategies and optimization parameters;

[0030] Figure 5 A schematic diagram illustrating the process of constructing training samples and using them to train an AI model;

[0031] Figure 6 A schematic diagram of the structure of an intermediate representation optimization device for codes provided in this application;

[0032] Figure 7 This is a schematic diagram of the hardware structure of a computing device provided in this application. Detailed Implementation

[0033] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms can be used interchangeably where appropriate; this is merely a method of distinction used in describing objects with the same attributes in the embodiments of this application.

[0034] The technical solutions in this application will now be described with reference to the accompanying drawings.

[0035] See Figure 1 This is a schematic diagram of the structure of an exemplary data processing system 10. Figure 1 As shown, the data processing system 10 includes a client 100, a compiler 200, and at least one processor. Figure 1 The following example uses two processors (processor 301 and processor 302) for illustration.

[0036] Client 100 is used for data interaction with the user, such as obtaining source code to be compiled provided by the user, or presenting the optimized IR or the final compiled computer-executable code to the user. Furthermore, client 100 can also support user configuration, such as allowing the user to configure thresholds involved in the IR optimization process. For example, client 100 can be an application running on a terminal device on the user's side, or it can be a web browser provided by the data processing system 10; there is no limitation on this.

[0037] Compiler 200 is used to compile code, such as compiling source code into IR (Input Retrieval System) and IR into computer-executable code. Furthermore, during the compilation process, compiler 200 can also optimize the code, such as transforming the code of operators in the IR to improve the execution performance of the final computer-executable code generated from the IR on a hardware environment. Exemplarily, compiler 200 can be implemented in software or hardware. When implemented in software, compiler 200 can be program code running on hardware, such as a process running on a computing device; when implemented in hardware, compiler 200 can be implemented using a processor or at least one computing device including a processor, without limitation, and the processor can be similar to the implementation of processor 301 described below.

[0038] Processor 301 (and similarly processor 302) can be used to execute executable code. That is, processors 301 and 302 can serve as a hardware environment to support the execution of the computer executable code finally compiled by compiler 200. Processor 301 can be any one of the following or any combination of the following: central processing unit (CPU), accelerator, application-specific integrated circuit (ASIC), programmable logic device (PLD), complex programmable logical device (CPLD), field-programmable gate array (FPGA), generic array logic (GAL), system-on-chip (SoC), software-defined infrastructure (SDI) chip, artificial intelligence (AI) chip, data processing unit (DPU). Accelerators can be, for example, graphics processing unit (GPU), neural network processing unit (NPU), or tensor processing unit (TPU).

[0039] In practical applications, after compiler 200 compiles the source code, the resulting execution logic (IR) is usually semantically identical to the original source code. However, it may not be adapted to the hardware environment. For example, the computational logic in the IR might be serial, failing to utilize the parallel computing capabilities provided by processors 301 and 302. Alternatively, the IR might contain redundant code, resulting in redundant computations. Therefore, compiler 200 can optimize the IR to improve the execution performance of the executable code generated based on the optimized IR on the hardware environment.

[0040] During the optimization of the Instructions Reduction (IR) by Compiler 200, if the user specifies the execution order of multiple optimization strategies, it not only requires a high level of technical skill but also means that the code of operators in the IR is optimized sequentially based on the user-specified execution order. This often results in the final executable code's performance on the hardware environment falling short of expectations. On one hand, the execution order of the multiple optimization strategies specified by the user is not the optimal one; on the other hand, due to limitations in technical experience, the optimization strategies manually selected by the user are often not truly suitable for optimizing the IR. Therefore, in practical applications, although the IR is optimized by Compiler 200, the final executable code's performance on the hardware environment remains relatively low.

[0041] Based on this, in the data processing system 10 provided in this application, the compiler 200 may be configured with an optimization device 201 for optimizing the intermediate representation of the code. The optimization device 201 may automatically search for a number of suitable optimization strategies and automatically determine the execution order of the multiple optimization strategies and the parameters in each optimization strategy, so as to improve the execution performance of the final IR-based computer executable code on the hardware environment (such as processor 301 and processor 302).

[0042] In specific implementation, the optimization device 201 automatically searches for optimization strategies for multiple operators in the IR. During the optimization strategy search, the optimization device 201 can determine multiple optimization strategies that can be used to transform the code of the multiple operators, and based on these multiple optimization strategies, determine multiple optimization strategy sequences and the performance optimization results generated by the parameters used in each optimization strategy sequence for the IR. These performance optimization results can be, for example, the execution time of the computer executable code generated based on the optimized IR. For example, the execution time of the computer executable code can be obtained through model prediction or actual testing. Thus, the optimization device 201 can search for a first optimization strategy sequence whose performance optimization results for the IR satisfy the optimization conditions, and the parameters in each first optimization strategy within this first optimization strategy sequence. For example, the first optimization strategy sequence and the parameters in each first optimization strategy within this first optimization strategy sequence can generate the highest performance optimization result for the IR. Therefore, the optimization device 201 can transform the IR based on these multiple first optimization strategy sequences and the parameters in each first optimization strategy to obtain the optimized IR.

[0043] Thus, compared to optimizing IR sequentially using multiple optimization strategies based on a user-specified execution order or a default execution order (such as the execution order of operators), automatically searching for the execution order of multiple first optimization strategies and the parameters in each first optimization strategy based on the performance optimization results, and optimizing IR based on this execution order and the parameters in each first optimization strategy, enables the computer executable code generated based on the optimized IR to achieve a higher level of execution performance on the hardware environment, thereby improving the execution performance of the final generated computer executable code on the hardware environment.

[0044] Furthermore, the optimization device 201 automatically searches for multiple suitable first optimization strategies, their execution order, and the parameters in each first optimization strategy for the IR, eliminating the need for the user to specify multiple optimization strategies and their execution order for the IR, thereby reducing the technical requirements on the user.

[0045] For example, the optimization device 201 can be implemented in software or hardware. When implemented in software, the optimization device 201 can be an application running on hardware. When implemented in hardware, the optimization device 201 can be a processor, or one or more computing devices including a processor, etc., without limitation.

[0046] In practical applications, the optimization device 201 (or compiler 200) can be deployed in the cloud to provide cloud services for optimizing IR. Alternatively, the optimization device 201 (or compiler 200) can be deployed on a local device on the user's side to provide users with localized services for optimizing IR.

[0047] It is worth noting that the above Figure 1 The data processing system 10 shown is merely an illustrative example and is not intended to be limiting. For instance, in other possible data processing systems 10, the optimization device 201 may be deployed independently of the compiler 200. In this case, the compiler 200 can call the optimization device 201 via a network or bus during the compilation process to optimize the IR, and then further compile the optimized IR to obtain computer-executable code. Furthermore, in other possible data processing systems 10, the hardware used to run the computer-executable code may include a greater or lesser number of processors, or the number of clients provided for interaction with users may be different; this is not limited.

[0048] For ease of understanding, embodiments of the intermediate representation optimization method for the code provided in this application will be described below with reference to the accompanying drawings.

[0049] See Figure 2 , Figure 2This application provides a flowchart illustrating a method for optimizing intermediate code representation, which can be applied to... Figure 1 The data processing system 10 shown can also be applied to other applicable data processing systems. For ease of understanding, the following description uses an application... Figure 1 The data processing system 10 shown is used as an example for illustration.

[0050] in, Figure 2 The intermediate representation optimization method shown in the code can specifically include the following steps.

[0051] S201: Optimization device 201 acquires the first IR.

[0052] The first IR obtained is the IR to be optimized. For example, it could be an IR generated under a multi-level intermediate representation (MLIR) framework, an IR generated under a tensor virtual machine (TVM) compilation framework, or an IR generated under a data-centric parallel programming (DACE) scenario. In this embodiment, optimizing the IR specifically refers to transforming the code of the operators in the IR. The execution performance of the computer executable code generated on the hardware environment based on the IR after code transformation (i.e., the second IR below) is usually higher than the execution performance of the computer executable code generated on the hardware environment based on the IR before code transformation (i.e., the first IR).

[0053] In this embodiment, the following two non-limiting implementation examples for obtaining the first IR are provided.

[0054] In the first implementation example, the first IR can be obtained by compiling the source code using compiler 200.

[0055] In practice, client 100 can present an interactive interface to the user, where the user can input source code, such as importing a Java file written in the Java language. Then, client 100 can send the source code to compiler 200. Compiler 200 can perform lexical analysis, syntax analysis, and semantic analysis on the received source code. Lexical analysis, also known as scanning, is used to convert the input source code character stream into multiple lexical units. Syntax analysis is used to organize the multiple lexical units into a tree structure, the abstract syntax tree (AST), according to the syntax rules of the programming language. Semantic analysis is used to check the semantic correctness of the source code based on the AST. After completing the semantic analysis, compiler 200 can convert the AST into a first IR and provide the first IR to optimization device 201 for optimization.

[0056] In the second implementation example, the user can directly import an IR file, which includes a first IR to be optimized, onto the interactive interface presented by the client 100. The client 100 can then send the IR file to the compiler 200, so that the compiler 200 can invoke the optimization device 201 to optimize the first IR in the IR file.

[0057] S202: The optimization device 201 performs optimization strategy search on multiple operators in the first IR according to the optimization conditions, and obtains the first optimization strategy sequence and optimization parameters.

[0058] S203: The optimization device 201 converts the codes of multiple operators in the first IR according to the first optimization strategy sequence and optimization parameters to obtain the second IR.

[0059] The multiple operators in the first IR can be all the operators in the first IR, meaning the optimization device 201 can optimize all the operators in the first IR by default. Alternatively, the multiple operators in the first IR can be some of the operators included in the first IR, such as operators included in one or more functions. For example, when a user inputs an IR file in the interactive interface presented by the client 100, they can also specify the operators or functions in the IR to be optimized (the function includes at least one operator, and specifying the function to be optimized allows optimization of all operators in that function by default). For example, the user can input the name of the operator or function to be optimized in the interactive interface. In this way, the optimization device 201 can determine the multiple operators to be optimized in the first IR based on the user's specified operation on the operator or function. Furthermore, when specifying a function, the user can also input relevant information about the function, such as the shape, value type, or value of the input parameters. The value type can include a random assignment type, a specified value type, or a default type, or other types, without limitation.

[0060] The first optimization strategy sequence searched by the optimization device 201 may include multiple first optimization strategies that sequentially transform the code of the multiple operators. The multiple first optimization strategies are used to optimize the performance of the multiple operators when they are executed on a hardware environment (such as processor 301 and / or processor 302). The searched optimization parameters include the parameters in each of the multiple first optimization strategies. Furthermore, the performance optimization results generated by the searched first optimization strategy sequence and the optimization parameters for the first IR satisfy the optimization conditions.

[0061] For example, the optimization condition could be that the searched first optimization strategy sequence and optimization parameters produce the highest optimization performance for the first IR compared to other optimization strategy sequences or other parameter values ​​of the optimization strategies in the first optimization strategy sequence. Alternatively, the optimization condition could be that the searchable first optimization strategy sequence and optimization parameters produce optimization performance for the first IR that reaches a performance threshold. Taking execution time as an example, the optimization condition could be that after optimizing the first IR using the first optimization strategy sequence and optimization parameters, the execution time of the optimized first IR on the hardware environment is less than a time threshold. In practical applications, the optimization condition can also be implemented in other applicable ways, and there is no limitation on this.

[0062] In this embodiment, the optimization device 201 can automatically search for multiple suitable optimization strategies for IR, the execution order of these optimization strategies, and the parameters in each optimization strategy to improve the optimization effect for IR. Here, an optimization strategy refers to a strategy used to transform the code of an operator to optimize the execution performance of the code on the hardware environment. For example, an optimization strategy can be a pass, which can be an optimization program that can transform the code of a specific operator (i.e., the operator supported by the pass) into code more suitable for the hardware environment, thereby helping to improve the execution performance of the operator's code on the hardware environment. For ease of distinction, in this embodiment, the finally searched optimization strategy is referred to as the first optimization strategy, and the parameters in the multiple first optimization strategies are referred to as optimization parameters.

[0063] In one possible implementation, such as Figure 3 As shown, the optimization device 201 may have a pre-configured optimization strategy library, which may include multiple optimization strategies. However, not all optimization strategies in the library are suitable for optimizing the first IR; for example, some optimization strategies support operators that are not present in the first IR. Therefore, the optimization device 201 can search for optimization strategies suitable for optimizing the first IR from among these multiple optimization strategies.

[0064] In specific implementation, such as Figure 3 As shown, the optimization device 201 is equipped with a description file, which can be used to record the input operators and output operators corresponding to each of the multiple optimization strategies. The input operators refer to the operators that the optimization strategy supports in transforming its code, and the output operators refer to the operators obtained after transforming the code of the input operators using the optimization strategy. The input operators or output operators differ between different optimization strategies.

[0065] After acquiring the first IR, the optimization device 201 can determine, based on the description file, an optimization strategy capable of converting the code of multiple operators in the first IR from multiple optimization strategies. For example, the optimization device 201 can determine the optimization strategy capable of converting the code of each operator in the first IR sequentially, according to the execution order of the multiple operators or the execution order of the optimization strategies, based on the description file and the topology between the multiple operators in the first IR. In practical applications, the optimization device 201 can also use other methods to determine the corresponding optimization strategies for each operator in the first IR sequentially, such as determining the optimization strategy corresponding to each operator based on the reverse order of the execution order of the multiple operators, etc., without limitation. Since the optimization strategy may convert the input operator into one or more output operators, after determining the optimization strategy for an operator, the optimization device 201 can update the topology of the operator and, based on the updated topology, determine the optimization strategy for the next operator in the topology, thereby determining multiple optimization strategies for multiple operators in the first IR, and using the order in which the multiple optimization strategies are determined as the execution order of the multiple optimization strategies.

[0066] For ease of distinction, the optimization strategy determined based on the description file will be referred to as the candidate optimization strategy. Thus, as... Figure 3 As shown, the optimization device 201 can determine a combination space of candidate optimization strategies based on the candidate optimization strategies corresponding to the plurality of operators. This combination space typically includes multiple sequences of candidate optimization strategies, each sequence comprising an execution order of the candidate optimization strategies corresponding to the plurality of operators. Specifically, different candidate optimization strategy sequences may include different candidate optimization strategies, or different candidate optimization strategy sequences may include the same plurality of candidate optimization sequences but with different execution orders, or different sequences may have different candidate optimization strategies and different execution orders of both the candidate optimization strategies and the optimization candidate strategies.

[0067] For example, suppose the first IR includes n different operators, where n is a positive integer, and the optimization device 201 determines n candidate optimization strategies for these n operators, each candidate optimization strategy capable of transforming the code of an operator. Then, the combination space determined by the optimization device 201 may include... A sequence of candidate optimization strategies, among which,

[0068] In practical applications, since different optimization strategies can all support code conversion for the same operator, the optimization device 201 can determine m different candidate optimization strategies for n operators, where m is an integer greater than n. In this case, the combination space determined by the optimization device 201 can include... A sequence of candidate optimization strategies, among which,

[0069] Alternatively, since the output operators of some optimization strategies can serve as input operators for other optimization strategies—for example, after optimization strategy 1 transforms input operator X1 into output operator X2, optimization strategy 2 can use X2 as input operator and further transform it into X3. Furthermore, a single optimization strategy can transform one input operator into two different output operators, such as transforming a two-dimensional convolution operator into an im2col operator and a matrix multiplication operator, or a single optimization strategy can transform multiple input operators into one output operator. Therefore, the optimization device 201 determines p different candidate optimization strategies for n operators, where p is a positive integer. Based on these p candidate optimization strategies, Q different candidate optimization strategy sequences can be determined, where Q is a positive integer. Different candidate optimization strategy sequences can include different numbers of candidate optimization strategies.

[0070] Then, the optimization device 201 can search the combination space for the optimization strategy sequence that satisfies the optimization conditions for the first IR, as well as the parameters in each optimization strategy in the optimization strategy sequence, according to the optimization conditions.

[0071] In practical applications, the first IR typically contains a large number of operators, resulting in a potentially large number of candidate optimization strategy sequences within the combination space. Therefore, the optimization device 201 can prune this combination space to reduce the number of candidate optimization strategy sequences, thereby reducing the computational load required to subsequently search for the first optimization strategy sequence and optimization parameters from the combination space, and improving computational efficiency.

[0072] For example, the description file can record the execution order between different optimization strategies, meaning that the execution order of some optimization strategies must precede the execution order of other optimization strategies. Thus, the optimization device 201 can filter candidate optimization strategy sequences in the combinatorial space that do not satisfy this execution order, thereby pruning the combinatorial space. For instance, suppose the description file records that the execution order of candidate optimization strategy A precedes the execution order of candidate optimization strategy B, and the combinatorial space includes 1000 candidate optimization strategies. Among these, there are 200 candidate optimization strategy sequences in which the execution order of candidate optimization strategy B precedes the execution order of candidate optimization strategy A. Then, the optimization device 201 can filter these 200 candidate optimization strategy sequences in the combinatorial space to achieve effective pruning of the combinatorial space.

[0073] Furthermore, the execution order of different optimization strategies recorded in the description file can be a group-based order. Each group can include one or more optimization strategies, so the order between different groups is the execution order of optimization strategies within different groups. The execution order of different optimization strategies within the same group is not restricted. For example, in the arrangement order between some groups recorded in the description file, the order between group 1 and group 2 is that group 1 is before group 2, and it is recorded that candidate optimization strategy A and candidate optimization strategy C belong to group 1, and candidate optimization strategy B belongs to group 2. The optimization device 201 can determine from the description file that the execution order of candidate optimization strategy A and candidate optimization strategy C is both before the execution order of candidate optimization strategy B, thereby filtering the candidate optimization strategy sequence in the combinatorial space where the execution order of candidate optimization strategy B is before the execution order of candidate optimization strategy A, and filtering the candidate optimization strategy sequence in the combinatorial space where the execution order of candidate optimization strategy B is before the execution order of candidate optimization strategy C.

[0074] In this context, the execution order of different optimization strategies within the same group is not restricted. Multiple optimization strategies within the same group can optimize the IR in any execution order, achieving similar or identical optimization results. Therefore, when some optimization strategies (two or more optimization strategies) that transform operators in the first IR belong to the same group, the optimization device 201 can select an execution order for these optimization strategies. Other execution orders used by these optimization strategies are equivalent in optimization effect. Thus, the optimization device 201 can filter candidate optimization strategy sequences in the combinatorial space that include these optimization strategies and use other execution orders, thereby achieving further effective pruning of the combinatorial space.

[0075] Taking the example where group 1 is located before group 2 in the aforementioned description file, assuming the combinatorial space contains 1000 candidate optimization strategy sequences, among which, in 200 candidate optimization strategy sequences, the execution order of candidate optimization strategy B precedes the execution order of candidate optimization strategy A, in 200 candidate optimization strategy sequences, the execution order of candidate optimization strategy B precedes the execution order of candidate optimization strategy C, and in the remaining 600 candidate optimization strategy sequences, the execution order of candidate optimization strategy A and C both precedes the execution order of candidate optimization strategy B. Then, assuming that in 80 candidate optimization strategy sequences, the execution order of candidate optimization strategy A precedes the execution order of candidate optimization strategy C, and in 80 candidate optimization strategy sequences, the execution order of candidate optimization strategy C precedes the execution order of candidate optimization strategy A, then the optimization device 201 can continue to filter the remaining 600 candidate optimization strategy sequences to reduce the number of candidate optimization strategy sequences included in the combinatorial space to 520, thereby achieving further effective pruning of the combinatorial space.

[0076] In practical applications, if multiple execution orders of optimization strategies within the same group are equivalent in terms of optimization effect, the optimization device 201 can specifically divide the multiple optimization strategies within the group into multiple groups when specifying the execution order of the multiple optimization strategies within the group. The execution order between the multiple groups can then be used to indicate the execution order between the multiple optimization strategies, thereby achieving effective pruning of the combinatorial space.

[0077] Accordingly, when multiple optimization strategies within the same group produce different optimization effects when executed in different orders, the optimization device 201 can retain the multiple optimization strategies in the group to avoid specifying an incorrect execution order for the multiple optimization strategies and affecting the optimization performance for IR.

[0078] In this embodiment, for various candidate optimization strategy sequences in the combination space and each parameter combination that can be used for each candidate optimization strategy sequence, the optimization device 201 can determine the first optimization strategy sequence and the parameter combination used by the first optimization strategy sequence based on the performance optimization results that can be generated by optimizing for IR.

[0079] As an example of implementation, the optimization device 201 can utilize an AI model to predict the performance optimization results that a sequence of candidate optimization strategies can produce for IR using a parameter combination. The AI ​​model can be, for example, a model built on a deep neural network, or other types of models; there is no limitation on this.

[0080] In specific implementation, the optimization device 201 can first determine set 1, which includes U candidate optimization strategy sequences from the aforementioned combinatorial space, where U is a positive integer. For example, the optimization device 201 can randomly select some candidate optimization strategy sequences from the combinatorial space to form set 1. Since the parameters in each candidate optimization strategy sequence can have multiple possible values, and different values ​​will lead to different performance optimization results for the IR from the candidate optimization strategy sequence, therefore, as... Figure 3 As shown, the optimization device 201 can determine at least one parameter combination for each candidate optimization strategy sequence. Each parameter combination is a parameter value from among the multiple candidate optimization strategies included in the candidate optimization strategy sequence. The determined at least one parameter combination can be all possible parameter combinations or a subset of them. Furthermore, the number of parameter combinations determined for different candidate optimization strategy sequences can be the same or different.

[0081] For example, for each candidate optimization strategy sequence, the optimization device 201 can determine all possible values ​​of the parameters in each candidate optimization strategy within the sequence, thereby determining the parameter space of the candidate optimization strategy sequence. This parameter space can include various parameter combinations of the candidate optimization strategy sequence. For instance, suppose the candidate optimization strategy sequence includes candidate optimization strategy A and candidate optimization strategy B, and the parameters in candidate optimization strategy A are x1 and x2, while the parameters in candidate optimization strategy B are y1 and y2. Then, the parameter space of the candidate optimization strategy sequence can include four parameter combinations: {x1, y1}, {x1, y2}, {x2, y1}, and {x2, y2}. Therefore, the optimization device 201 can randomly select some or all of the parameter combinations from this parameter space for the candidate optimization strategy sequence in set 1, as the parameter combinations used by that candidate optimization strategy sequence.

[0082] Next, the optimization device 201 can use an AI model to predict the performance optimization result of each parameter combination among the multiple parameter combinations used in each candidate optimization strategy sequence in set 1 for the first IR, such as... Figure 3As shown. For example, the optimization device 201 can input the first IR, the candidate optimization strategy sequence, and the parameter combinations used by the candidate optimization strategy sequence into the AI ​​model. The AI ​​model performs inference and outputs the corresponding inference result, which is the performance optimization result produced by the candidate optimization strategy sequence using the parameter combination for the first IR. In practical applications, the optimization device 201 can use a genetic algorithm to iteratively determine the performance optimization results produced by each candidate optimization strategy sequence in set 1 using multiple parameter combinations for the first IR. In this way, the optimization device 201 can use the AI ​​model to predict the performance optimization results produced by each candidate optimization strategy sequence using various parameter combinations, thereby obtaining W performance optimization results. Among them, u i This refers to the number of combined parameters that can be used in the i-th candidate optimization strategy sequence; U is the number of candidate optimization strategy sequences. The AI ​​model can be pre-trained based on training samples. The training process of the AI ​​model is described in detail below and will not be elaborated upon here. Thus, by determining the performance optimization result through AI model prediction, it is possible to obtain the performance optimization result without running computer-executable code on a real hardware environment, which effectively improves the efficiency of the optimization device 201 in obtaining the performance optimization result.

[0083] Finally, the optimization device 201 can determine, based on the optimization conditions and the parameter combinations used by each candidate optimization strategy sequence for each performance optimization result generated by the first IR, the candidate optimization strategy sequence (i.e., the first optimization strategy sequence) and its parameter combinations (i.e., optimization parameters) that enable the performance optimization result to meet the optimization conditions. For example, when the performance optimization result is measured by the execution time of the code, the optimization device 201 can determine the minimum code execution time from W code execution times, and determine the candidate optimization strategy sequence that produces the minimum code execution time and its parameter combinations as the first optimization strategy sequence and optimization parameters, respectively.

[0084] In practical applications, since the accuracy of AI models in predicting performance optimization results is difficult to reach 100%, the optimization device 201 can further determine the true performance optimization results by running code on the hardware environment.

[0085] like Figure 3As shown, the optimization device 201 can determine the first candidate optimization strategy sequence and the first parameter combination used by the first candidate optimization strategy sequence based on the performance optimization results generated by each candidate optimization strategy sequence in set 1 using each parameter combination for the first IR. The performance optimization result generated by the first candidate optimization strategy sequence using the first parameter combination for the first IR is better than the performance optimization results generated by the other candidate optimization strategy sequences in set 1 using parameter combinations for the first IR. The first candidate optimization strategy sequence can be one or more candidate optimization strategy sequences, and the first parameter combination can be one or more parameter combinations. Then, the optimization device 201 can use the determined first candidate optimization strategy sequence and the first parameter combination used by the first candidate optimization strategy sequence to transform the code of multiple operators in the first IR to obtain a new IR, which is referred to as the test IR for ease of distinction and description. Next, the optimization device can compile the test IR, such as by using compiler 200, to obtain corresponding computer-executable code, such as a binary file or a file including assembly language code. Then, the optimization device 201 can execute the computer-executable code on a hardware environment (such as processor 301 and / or processor 302) to obtain the actual optimization performance generated for the first IR using the first candidate optimization strategy sequence and the first parameter combination. This actual optimization performance is the true performance optimization result generated for the first IR. Processor 301 and / or processor 302 can execute the function-related code in the computer-executable code based on function-related information input by the user in the interactive interface. Thus, the optimization device 201 determines the first optimization strategy sequence and optimization parameters based on the optimization conditions and the actual optimization performance of the first candidate optimization strategy sequence and the first parameter combination for the first IR, such as... Figure 3 As shown. For example, when the actual optimization performance meets the optimization conditions, the optimization device 201 can determine the first candidate optimization strategy sequence as the first optimization strategy sequence, and determine the first parameter combination as the optimization parameters adopted by the first optimization strategy sequence.

[0086] To facilitate understanding, an example is given below. Assuming performance optimization results are measured by code execution time, the optimization device 201 can determine the k smallest code execution times from W code execution times, i.e., determine the k best performance optimization results. It then generates a candidate optimization strategy sequence for these k smallest code execution times and their parameter combinations, which are the aforementioned first candidate optimization strategy sequence and first parameter combination. Here, k is a positive integer less than W. Next, the optimization device 201 can use the candidate optimization strategy sequence and parameter combination to compile the code of multiple operators in the first IR, thereby obtaining k different test IRs. Compiling these k test IRs yields k different computer-executable codes. Finally, the optimization device 201 can run these k computer-executable codes on a hardware environment to obtain the actual execution time corresponding to these k computer-executable codes. This actual execution time is the aforementioned actual optimized performance. Furthermore, when the actual execution time is less than the duration threshold, the optimization device 201 can determine the candidate optimization strategy sequence corresponding to the actual execution time and its parameter combination as the first optimization strategy sequence and optimization parameters. Accordingly, the optimization condition can be that the execution time corresponding to the optimized IR is less than the duration threshold.

[0087] In this way, by first using AI models to predict the performance optimization results of a large number of candidate optimization strategy sequences and parameter combinations, and then using hardware environment to verify the performance optimization results of a small number of candidate optimization strategy sequences and parameter combinations, we can not only improve the overall efficiency of determining the first optimization strategy sequence and optimization parameters, but also ensure the accuracy of determining the first optimization strategy sequence and optimization parameters.

[0088] Furthermore, by utilizing a subset of candidate optimization strategy sequences and parameter combinations in the combinatorial space, it is possible to determine a first optimization strategy sequence and optimization parameters whose performance optimization results satisfy the optimization conditions. Alternatively, it is possible that neither the candidate optimization strategy sequence nor the parameter combinations produce performance optimization results for the first IR that satisfy the optimization conditions. In this case, the optimization device 201 can iteratively search for another subset of candidate optimization strategy sequences in the combinatorial space to determine whether any of these candidate optimization strategy sequences, using a certain parameter combination, produce performance optimization results for the first IR that satisfy the optimization conditions.

[0089] like Figure 3As shown, if the number of iterations has not reached the preset number, the optimization device 201 can reselect multiple candidate optimization strategy sequences from the combination space based on the actual optimization performance of the first candidate optimization strategy sequence with the first parameter combination for the first IR. Specifically, it can select V candidate optimization strategy sequences to obtain set 2, where V is a positive integer. For example, the optimization device 201 can use a heuristic search algorithm to select V candidate optimization strategies from the combination space based on the performance optimization results of the first candidate optimization strategy sequence with the first parameter combination for the first IR. This is to guide the selection of candidate optimization strategy sequences from the combination space in the second iteration search based on the candidate optimization strategy sequences, parameter combinations, and actual optimization performance determined in the first iteration search, so that the newly selected candidate optimization strategy sequences from the combination space can contain candidate optimization strategy sequences that produce better performance optimization results.

[0090] Then, the optimization device 201 can determine at least one parameter combination for each candidate optimization strategy sequence in set 2, and use an AI model to predict the performance optimization result of each parameter combination adopted by each candidate optimization strategy sequence in set 2 for the first IR.

[0091] Finally, the optimization device 201 can determine the first optimization strategy sequence and optimization parameters based on the optimization conditions and the performance optimization results of each parameter combination used by each candidate optimization strategy sequence in set 2 for the first IR, as well as the actual optimization performance of the first candidate optimization strategy sequence and the first parameter combination for the first IR.

[0092] For example, the optimization device 201 can determine a second candidate optimization strategy sequence and a second parameter combination based on the performance optimization results of each candidate optimization strategy sequence in set 2 using each parameter combination for the first IR. The performance optimization result of the second candidate optimization strategy sequence using the second parameter combination for the first IR is better than the performance optimization results of the other candidate optimization strategy sequences in set 2 using their respective parameter combinations for the first IR. Then, the optimization device 201 can use the determined second candidate optimization strategy sequence and the second parameter combination to transform the code of multiple operators in the first IR to obtain a new test IR, and compile the test IR to obtain computer-executable code. Next, the optimization device 201 can execute the computer-executable code on a hardware environment to obtain the actual optimization performance of the first IR using the second candidate optimization strategy sequence and the second parameter combination. If the actual optimization performance meets the optimization conditions, the optimization device 201 can determine the second candidate optimization strategy sequence as the first optimization strategy sequence and the second parameter combination as the optimization parameters used by the first optimization strategy sequence. If the actual optimization performance does not meet the optimization conditions, the optimization device 201 can continue to search for new candidate optimization strategy sequences from the combinatorial space in the manner described above.

[0093] In practical applications, the optimization device 201 can perform iterative searches as described above. Specifically, before the preset number of iterations is reached, if a candidate optimization strategy sequence and its parameter combination produce a performance optimization result that satisfies the optimization conditions, the optimization device 201 can use this candidate optimization strategy sequence and parameter combination as the first optimization strategy sequence and optimization parameters. When the preset number of iterations is reached, if no candidate optimization strategy sequence and its parameter combination produce a performance optimization result that satisfies the optimization conditions, the optimization device 201 can use the candidate optimization strategy sequence and parameter combination corresponding to the optimal performance optimization result obtained from the search as the first optimization strategy sequence and optimization parameters. Alternatively, during each IR optimization process, the optimization device 201 can default to performing a preset number of iterative search processes as described above, and determine the optimal performance optimization result from the performance optimization results determined during multiple iterative searches, such as determining the minimum code execution time. Therefore, the optimization device 201 can use the candidate optimization strategy sequence and parameter combination corresponding to this optimal performance optimization result as the first optimization strategy sequence and optimization parameters.

[0094] Furthermore, the above explanation uses the example of iteratively searching for the first optimization strategy and optimization parameters from the optimization device 201 at the set granularity. In other implementations, the optimization device 201 can use a sequence of candidate optimization strategies as the granularity, employing heuristic algorithms or genetic algorithms to search for the first optimization strategy and optimization parameters from the combinatorial space. That is, after selecting a candidate optimization strategy sequence from the combinatorial space and determining the performance optimization result produced by the candidate optimization strategy sequence using one or more parameter combinations, the optimization device 201 can select the next candidate optimization strategy sequence from the combinatorial space to continue the iterative search, without any limitation on this.

[0095] After determining the first optimization strategy sequence and optimization parameters, the optimization device 201 can use the execution order of the multiple first optimization strategies indicated by the first optimization strategy sequence to sequentially convert the code of multiple operators in the first IR using the corresponding optimization parameters, and finally obtain a new IR, that is, the second IR in step S203.

[0096] For example, suppose the first optimal policy sequence includes N first optimal policies, where N is a positive integer greater than 1. Figure 4 As shown, the optimization device 201 can convert the first IR according to the execution order indicated by the first optimization strategy sequence, using optimization strategy 1 in the first optimization strategy sequence and the parameter values ​​related to optimization strategy 1 in the optimization parameters, to obtain IR1. Then, the optimization device 201 further converts IR1 according to the execution order, using optimization strategy 2 in the first optimization strategy sequence and the parameter values ​​related to optimization strategy 2 in the optimization parameters, to obtain IR2. And so on, as... Figure 4 As shown, finally, the optimization strategy N in the first optimization strategy sequence and the parameter values ​​related to optimization strategy N in the optimization parameters are used to optimize the IR. N-1 By performing the conversion, a second IR can be obtained.

[0097] In further possible implementations, such as Figure 2 As shown, after generating the second IR, the optimization device 201 can also provide the second IR to the compiler 200. The compiler 200 then compiles the second IR into computer-executable code and presents this code to the user through the client 100. The computer-executable code can be a binary file, such as a ".o" format object file, a library file (static or dynamic library, etc.), an executable file, or an assembly language file, etc.

[0098] Furthermore, during the process of determining the first optimization strategy sequence and optimization parameters, if the optimization device 201 determines the first optimization strategy sequence and optimization parameters based on the actual optimization performance, since the optimization device 201 has already optimized the first IR using the candidate optimization strategy sequence and parameter combination that generated the actual optimization performance, and compiled computer-executable code based on the optimized IR, the optimization device 201 can directly provide the computer-executable code to the client 100, and the client 100 can then present it to the user.

[0099] Alternatively, in a compile-and-execute scenario, after generating computer-executable code, the optimization device 201 or the compiler 200 can directly send the computer-executable code to the processor 301 and / or the processor 302 so that the processor 301 and / or the processor 302 can execute the computer-executable code.

[0100] It should be noted that the above Figure 2 The embodiments shown are merely illustrative of how to implement optimized IR and are not intended to limit the scope. Figure 2 Based on the illustrated embodiment, other implementations are also possible, which will be described below.

[0101] In this embodiment, the optimization device 201 is described using the operator as the granularity to determine the first optimization strategy sequence and optimization parameters for the first IR. In other embodiments, the optimization device 201 can also use the function as the granularity to determine the first optimization strategy sequence and optimization parameters for each function in the first IR. Thus, for each function, the optimization device 201 can use the corresponding first optimization strategy sequence and optimization parameters to convert the code of the operator in that function. The first optimization strategy sequence and optimization parameters for different functions may differ. Specifically, when there are two or more functions (including two) in the first IR that have a call-and-be-called relationship, the optimization device 201 can treat these two or more functions as a single function to determine the corresponding first optimization strategy sequence and optimization parameters.

[0102] In this embodiment, the optimization device 201 is described by example of directly optimizing the first IR using the searched first optimization strategy sequence and optimization parameters. In other embodiments, in addition to optimizing the first IR using the first optimization strategy sequence and optimization parameters, the optimization device 201 can also optimize the first IR using an operator-independent optimization strategy. For example, an operator-independent optimization strategy could be an optimization strategy for constant folding, specifically replacing the constant part of the calculation expression in the IR directly with the calculation result; or, an operator-independent optimization strategy could be an optimization strategy for dead code elimination, specifically eliminating code that will not be executed; or other types of optimization strategies, which are not limited thereto. In practical applications, the result of optimizing the first IR using an operator-independent optimization strategy can be independent of the result of optimizing the first IR using the first optimization strategy sequence. Therefore, the optimization device 201 can first optimize the first IR using the first optimization strategy sequence and optimization parameters to obtain the second IR, and then optimize the second IR using an operator-independent optimization strategy. Alternatively, the optimization device 201 can first optimize the first IR using an operator-independent optimization strategy, and then optimize the optimized first IR using the first optimization strategy sequence and optimization parameters; there is no limitation on this. Furthermore, during the optimization of the first IR using the first optimization strategy sequence and optimization parameters, the operator-independent optimization strategy can be used simultaneously to optimize the first IR.

[0103] In this embodiment, the optimization device 201 utilizes the hardware environment provided by processors 301 and 302 to determine the actual optimization performance generated by the optimization strategy sequence and parameter combination for IR. In other embodiments, the data processing system 10 may include more types of processors. In this case, different types of processors can provide different hardware environments, thereby enabling the optimization device 201 to support running computer-executable code on a user-specified hardware environment to obtain the actual optimization performance. Accordingly, when using an AI model to predict the performance optimization results generated by each candidate optimization strategy and parameter combination for IR, an AI model adapted to the hardware environment can be selected for performance prediction. A single AI model may be adapted to only one hardware environment, or it may be adapted to multiple hardware environments, such as different hardware environments under the same architecture (e.g., x86 architecture).

[0104] In addition, for other IRs, taking the third IR as an example, the optimization device 201 can also refer to the above-described process of optimizing the first IR to determine a second optimization strategy sequence that enables the performance optimization result of the third IR to meet the optimization conditions, as well as the parameters in each optimization strategy in the second optimization strategy sequence. For details, please refer to the relevant descriptions above, which will not be repeated here.

[0105] The training process of the AI ​​model mentioned above will be illustrated below.

[0106] Before training the AI ​​model, training samples for the AI ​​model can be pre-constructed. These training samples can be constructed by the optimization device 201 or by other devices. For ease of understanding and explanation, the following example illustrates the construction of training samples by the optimization device 201.

[0107] For example, such as Figure 5 As shown, the optimization device 201 can acquire one or more IR files, which include multiple operators or multiple functions, each function including at least one operator. For ease of understanding, the following explanation uses the example of an IR file including multiple operators.

[0108] Since the training accuracy of an AI model is related to the number of training samples, the optimization device 201 can perform data augmentation on the IR file after acquiring it, in order to enrich the number of training samples, such as... Figure 5 As shown. For example, the optimization device 201 can decompose the code of multiple operators included in the IR file into multiple code units, each code unit may include the code of one or more operators. Then, the optimization device 201 can combine the multiple code units to obtain multiple extended IR files. Each extended IR file may include some or all of the code units from the multiple code units, and different extended IR files may include different code units, or the order of the code units included in different extended IR files may be different. In this way, the optimization device 201 can subsequently generate training based on the acquired IR file and the extended IR files obtained through data augmentation.

[0109] Furthermore, the optimization device 201 can also acquire the aforementioned description file, such as... Figure 5 As shown. For example, the optimization device 201 can construct the aforementioned description file. This can be achieved by the user specifying input and output operators for each of the multiple optimization strategies through an interactive interface. Based on the user's configuration, the optimization device 201 can create a description file that records the input operators supported by each optimization strategy and the resulting output operators. Alternatively, the description file can be pre-constructed by the user, who can then provide it to the optimization device 201.

[0110] Thus, for each IR file, the optimization device 201 can determine an optimization strategy that can transform the code of multiple operators in the IR file based on the description file. For example, it can determine the corresponding optimization strategy based on the execution order of the optimization strategy in the description file or the execution order among the multiple operators, and determine the combination space based on the determined optimization strategy. Figure 5 As shown, the combination space includes multiple optimization strategy sequences, each of which indicates the execution order of optimization strategies used to transform the code of multiple operators in the IR file. Furthermore, for each optimization strategy sequence in the combination space, the optimization device 201 can determine the corresponding parameter space, which includes multiple parameter combinations, each of which represents a parameter value for one of the multiple optimization strategies in the optimization strategy sequence. In practical applications, the optimization device 201 can exhaustively enumerate all optimization strategy sequences in the combination space and all parameter combinations in the parameter space corresponding to each optimization strategy sequence, such as... Figure 5 As shown.

[0111] Similarly, for each extended IR file, the optimization device 201 can also determine the combination space for multiple operators in the extended IR file, and exhaustively enumerate all optimization strategy sequences in the combination space, as well as exhaustively enumerate all parameter combinations in the parameter space corresponding to each optimization strategy sequence.

[0112] Next, as Figure 5 As shown, for each IR file, the optimization device 201 can utilize multiple optimization strategy sequences adapted to the IR file and multiple parameter combinations corresponding to each optimization strategy sequence to optimize the IR file separately, obtaining multiple optimized IR files. These multiple optimized IR files are then compiled separately to obtain multiple computer-executable codes. Similarly, for each extended IR file, the optimization device 201 can also generate multiple computer-executable codes in a similar manner.

[0113] Then, the optimization device 201 can run each piece of computer executable code on a separate hardware environment, such as a hardware environment composed of processor 301 and / or processor 302, thereby obtaining the execution performance corresponding to each piece of computer executable code, such as... Figure 5As shown. Thus, the optimization device 201 can use this execution performance as label data, along with the IR file (or extended IR file) on which the computer executable code is based, the sequence of optimization strategies used, and the parameter combinations, as a training sample for training the AI ​​model. Therefore, for multiple computer executable codes, the optimization device 201 can generate multiple training samples. In this way, the optimization device 201 automatically constructs multiple training samples for training the AI ​​model using a small number of IR files, such as... Figure 5 As shown.

[0114] After generating training samples, such as Figure 5 As shown, the optimization device 201 can iteratively train the AI ​​model using multiple training samples until the AI ​​model meets the termination conditions of iterative training, such as the number of iterations of the AI ​​model reaching a preset number or the training accuracy of the AI ​​model reaching a preset accuracy. For example, for each training sample, the optimization device 201 can input the IR file (or extended IR file), optimization policy sequence, and parameter combination from the training sample into the AI ​​model, which will then perform inference and obtain the inference result. Then, the optimization device 201 can compare the difference (loss value) between the inference result and the label data in the training sample, and calculate the gradient data corresponding to the parameters in the AI ​​model based on the difference, thereby updating the parameter values ​​in the AI ​​model based on the gradient data. In this way, the optimization device 201 can iteratively update the parameters in the AI ​​model using multiple training samples in the manner described above until the termination conditions of iterative training are met, thus completing the training process for the AI ​​model.

[0115] Furthermore, when the compiler 200 supports compiling computer-executable code for various hardware environments, the training samples constructed by the optimization device 201 can also include hardware environment information, such as the number of hardware components, hardware types, and instruction sets supported by the hardware. Figure 5 As shown. In this way, the optimization device 201 can optimize the IR using an AI model trained on training samples, before the compiler 200 compiles the IR into computer executable code that runs on the hardware environment, using an AI model adapted to the hardware environment, thereby further improving the optimization effect for the IR.

[0116] It is worth noting that other reasonable combinations of steps that can be conceived by those skilled in the art based on the above description also fall within the scope of protection of this application. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily essential to this application.

[0117] The above combination Figures 1 to 5The intermediate representation optimization method for code provided in the embodiments of this application will be introduced. Next, the structure of the apparatus and computing device for optimizing the intermediate representation of code provided in the embodiments of this application will be described with reference to the accompanying drawings.

[0118] See Figure 6 This illustrates a schematic diagram of a device structure for optimizing the intermediate representation of code. For example... Figure 6 As shown, the device 600 includes:

[0119] The acquisition module 601 is used to acquire a first intermediate representation, which includes multiple operators;

[0120] Search module 602 is used to search for optimization strategies for multiple operators according to optimization conditions, and obtain a first optimization strategy sequence and optimization parameters. The first optimization strategy sequence includes multiple first optimization strategies that sequentially transform the code of multiple operators. The multiple first optimization strategies are used to optimize the performance of multiple operators when they are executed on the hardware environment. The optimization parameters include the parameters in each of the multiple first optimization strategies. The performance optimization result generated by the first optimization strategy sequence and optimization parameters for the first intermediate representation satisfies the optimization conditions.

[0121] The conversion module 603 is used to convert the code of multiple operators in the first intermediate representation according to the first optimization strategy sequence and optimization parameters to obtain the second intermediate representation.

[0122] In one possible implementation, the search module 602 is used for:

[0123] Obtain the description file. The description file is used to record the input operators and output operators of each optimization strategy among multiple optimization strategies. The input operators are the operators that the optimization strategy supports for transformation, and the output operators are the operators obtained by transformation using the optimization strategy.

[0124] Based on the description file, candidate optimization strategies corresponding to multiple operators are determined from multiple optimization strategies;

[0125] Based on the candidate optimization strategies corresponding to multiple operators, a combination space is determined. The combination space includes multiple sequences of candidate optimization strategies. Each sequence of candidate optimization strategies includes multiple candidate optimization strategies that sequentially transform the code of multiple operators. The candidate optimization strategies of different sequences of candidate optimization strategies are different or the execution order of the candidate optimization strategies is different.

[0126] Based on the optimization conditions, an optimization strategy search is performed in the combinatorial space to obtain the first optimization strategy sequence and optimization parameters.

[0127] In one possible implementation, the description file is also used to record the optimization order between different optimization strategies;

[0128] The search module 602 is used to determine the combination space based on the optimization order among different optimization strategies and the candidate optimization strategies corresponding to multiple operators.

[0129] In one possible implementation, the optimization order among different optimization strategies includes the sorting among multiple groups, each of which includes at least one optimization strategy.

[0130] In one possible implementation, the search module 602 is used for:

[0131] Determine a first set, which includes at least one sequence of candidate optimization strategies in the combinatorial space;

[0132] For each candidate optimization strategy sequence in the first set, at least one parameter combination is determined, and each parameter combination is a parameter value among the multiple candidate optimization strategies included in the candidate optimization strategy sequence;

[0133] Using an artificial intelligence (AI) model, predict the performance optimization results of each parameter combination used in each candidate optimization strategy sequence for the first intermediate representation;

[0134] Based on the optimization conditions and the performance optimization results generated by each parameter combination used in each candidate optimization strategy sequence for the first intermediate representation, the first optimization strategy sequence and optimization parameters are determined.

[0135] In one possible implementation, the search module 602 is used for:

[0136] Based on the performance optimization results of each parameter combination used by each candidate optimization strategy sequence for the first intermediate representation, the first candidate optimization strategy sequence and the first parameter combination used by the first candidate optimization strategy sequence are determined. The performance optimization results of the first candidate optimization strategy sequence using the first parameter combination for the first intermediate representation are better than the performance optimization results of the other candidate optimization strategy sequences using the parameter combinations for the first intermediate representation.

[0137] Using the first candidate optimization strategy sequence and the first parameter combination, the code of multiple operators in the first intermediate representation is transformed to obtain the test intermediate representation;

[0138] The intermediate test representation is compiled to obtain executable code for the computer.

[0139] Execute computer-executable code on a hardware environment to obtain the actual optimized performance generated for the first intermediate representation using a first candidate optimization strategy sequence and a first parameter combination;

[0140] Based on the optimization conditions, the first candidate optimization strategy sequence, and the first parameter combination, and the actual optimization performance of the first intermediate representation, the first optimization strategy sequence and optimization parameters are determined.

[0141] In one possible implementation, the search module 602 is used for:

[0142] Based on the first candidate optimization strategy sequence and the actual optimization performance of the first parameter combination for the first intermediate representation, a second set is determined. The second set includes at least one candidate optimization strategy sequence in the combination space. The second set does not overlap with the first set.

[0143] For each candidate optimization strategy sequence in the second set, determine at least one parameter combination;

[0144] Using an AI model, predict the performance optimization results of each parameter combination used by each candidate optimization strategy sequence in the second set for the first intermediate representation;

[0145] Based on the optimization conditions and the performance optimization results of each parameter combination used by each candidate optimization strategy sequence in the second set for the first intermediate representation, as well as the actual optimization performance of the first candidate optimization strategy sequence and the first parameter combination for the first intermediate representation, the first optimization strategy sequence and optimization parameters are determined.

[0146] because Figure 6 The device 600 shown corresponds to the above. Figure 2 The optimization device 201 in the illustrated embodiment, therefore Figure 6 For the specific implementation of the device 600 and its technical effects, please refer to the above. Figure 2 The relevant details in the illustrated embodiments are described in detail here, and will not be repeated here.

[0147] Figure 7 This is a schematic diagram of the structure of a computing device provided in this application. Figure 7 As shown, the computing device 700 includes a processor 701, a memory 702, a communication interface 703, and a bus 704. The processor 701, memory 702, and communication interface 703 communicate via the bus 704. The bus 704 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 7 The symbol is represented by only one thick line, but this does not indicate that there is only one bus or one type of bus. Communication interface 703 is used for communication with external devices.

[0148] It should be understood that in the embodiments of this application, processor 701 may be a CPU, or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete device assemblies, etc. General-purpose processors may be microprocessors or any conventional processors, etc.

[0149] The memory 702 may include read-only memory and random access memory, and provides instructions and data to the processor 701. The memory 702 may also include non-volatile random access memory.

[0150] The memory 702 can be volatile memory or non-volatile memory, or it can include both. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).

[0151] The memory 702 stores executable code, and the processor 701 executes the executable code to perform the aforementioned actions. Figure 2 The method executed by the optimization device 201 in the illustrated embodiment.

[0152] It should be understood that the computing device 700 according to the embodiments of this application may correspond to Figure 2 The optimization device 201 in the illustrated embodiment can correspond to the execution of the embodiments according to this application. Figure 2The method executed by the optimization device 201 in the illustrated method, and the above-mentioned and other operations and / or functions implemented by the computing device 700, are respectively for the purpose of achieving Figure 2 The process of the corresponding methods in [the document] will not be elaborated here for the sake of brevity.

[0153] This application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that a computing device can store, or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive). The computer-readable storage medium includes instructions that instruct a computing device to execute the intermediate representation optimization method of the aforementioned code.

[0154] This application also provides a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computing device, all or part of the processes or functions described in this application are generated.

[0155] The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, or data center to another website, computer, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means.

[0156] The computer program product can be a software installation package. In cases where any of the aforementioned intermediate representation optimization methods of the code is required, the computer program product can be downloaded and executed on a computing device.

[0157] The above embodiments can be implemented, in whole or in part, by software, hardware, firmware, or any other combination thereof. When implemented using software, the above embodiments can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded or executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more sets of available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium. A semiconductor medium can be a solid-state drive.

[0158] The terminology used in the above embodiments is for the purpose of describing specific embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to also include expressions such as “one or more,” unless the context clearly indicates otherwise. It should also be understood that in the embodiments of this application, “one or more” refers to one, two, or more; the character “ / ” generally indicates that the preceding and following objects are in an “or” relationship. In the embodiments of this application, “simultaneously” means within the same time period, including situations where they are at the same moment.

[0159] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.

[0160] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method for optimizing intermediate code representation, characterized in that, The method includes: Obtain a first intermediate representation, which includes multiple operators; Based on the optimization conditions, an optimization strategy search is performed on the plurality of operators to obtain a first optimization strategy sequence and optimization parameters. The first optimization strategy sequence includes a plurality of first optimization strategies that sequentially transform the code of the plurality of operators. The plurality of first optimization strategies are used to optimize the performance of the plurality of operators when they are executed on the hardware environment. The optimization parameters include the parameters in each of the plurality of first optimization strategies. The performance optimization result generated by the first optimization strategy sequence and the optimization parameters for the first intermediate representation satisfies the optimization conditions. Based on the first optimization strategy sequence and the optimization parameters, the codes of the multiple operators in the first intermediate representation are transformed to obtain the second intermediate representation.

2. The method according to claim 1, characterized in that, The step of searching for optimization strategies for the plurality of operators based on optimization conditions to obtain a first optimization strategy sequence and optimization parameters includes: Obtain a description file, which is used to record the input operators and output operators of each optimization strategy among multiple optimization strategies. The input operators are operators that the optimization strategy supports for transformation, and the output operators are operators obtained by transformation using the optimization strategy. Based on the description file, candidate optimization strategies corresponding to the plurality of operators are determined from the plurality of optimization strategies; Based on the candidate optimization strategies corresponding to the multiple operators, a combination space is determined. The combination space includes multiple candidate optimization strategy sequences. Each candidate optimization strategy sequence includes multiple candidate optimization strategies that sequentially transform the code of the multiple operators. The candidate optimization strategies of different candidate optimization strategy sequences are different or the execution order of the candidate optimization strategies is different. Based on the optimization conditions, an optimization strategy search is performed from the combination space to obtain the first optimization strategy sequence and optimization parameters.

3. The method according to claim 2, characterized in that, The description file is also used to record the optimization order between different optimization strategies; The step of determining the combination space based on the candidate optimization strategies corresponding to the plurality of operators includes: The combination space is determined based on the optimization order among the different optimization strategies and the candidate optimization strategies corresponding to the multiple operators.

4. The method according to claim 3, characterized in that, The optimization order among the different optimization strategies includes the sorting among multiple groups, each of which includes at least one optimization strategy.

5. The method according to any one of claims 2 to 4, characterized in that, The step of searching for optimization strategies from the combinatorial space based on the optimization conditions to obtain the first optimization strategy sequence and optimization parameters includes: Determine a first set, the first set comprising at least one sequence of candidate optimization strategies in the combination space; For each candidate optimization strategy sequence in the first set, at least one parameter combination is determined, wherein each parameter combination is a parameter value among the multiple candidate optimization strategies included in the candidate optimization strategy sequence; Using an artificial intelligence (AI) model, predict the performance optimization result of each parameter combination used in each candidate optimization strategy sequence for the first intermediate representation; Based on the optimization conditions and the performance optimization results generated by each parameter combination used in each candidate optimization strategy sequence for the first intermediate representation, the first optimization strategy sequence and optimization parameters are determined.

6. The method according to claim 5, characterized in that, The step of determining the first optimization strategy sequence and optimization parameters based on the optimization conditions and the performance optimization results generated by each parameter combination used in each candidate optimization strategy sequence for the first intermediate representation includes: Based on the performance optimization results generated by each parameter combination used by each candidate optimization strategy sequence for the first intermediate representation, a first candidate optimization strategy sequence and a first parameter combination used by the first candidate optimization strategy sequence are determined. The performance optimization results generated by the first candidate optimization strategy sequence using the first parameter combination for the first intermediate representation are better than the performance optimization results generated by the other candidate optimization strategy sequences using parameter combinations for the first intermediate representation. Using the first candidate optimization strategy sequence and the first parameter combination, the code of the multiple operators in the first intermediate representation is transformed to obtain the test intermediate representation; The intermediate test representation is compiled to obtain computer-executable code; Execute the computer-executable code on the hardware environment to obtain the actual optimized performance generated for the first intermediate representation using the first candidate optimization strategy sequence and the first parameter combination; Based on the optimization conditions, the first candidate optimization strategy sequence, and the first parameter combination, and their actual optimization performance for the first intermediate representation, the first optimization strategy sequence and the optimization parameters are determined.

7. The method according to claim 6, characterized in that, The step of determining the first optimization strategy sequence and the optimization parameters based on the optimization conditions, the first candidate optimization strategy sequence, and the first parameter combination for the actual optimization performance of the first intermediate representation includes: Based on the first candidate optimization strategy sequence and the actual optimization performance of the first parameter combination for the first intermediate representation, a second set is determined. The second set includes at least one candidate optimization strategy sequence in the combination space. The second set does not overlap with the first set. For each candidate optimization strategy sequence in the second set, at least one parameter combination shall be determined; Using the AI ​​model, predict the performance optimization result of each parameter combination used by each candidate optimization strategy sequence in the second set for the first intermediate representation; Based on the optimization conditions and the performance optimization results of each parameter combination used by each candidate optimization strategy sequence in the second set for the first intermediate representation, as well as the actual optimization performance of the first candidate optimization strategy sequence and the first parameter combination for the first intermediate representation, the first optimization strategy sequence and optimization parameters are determined.

8. A code intermediate representation optimization device, characterized in that, The device includes: The acquisition module is used to acquire a first intermediate representation, wherein the first intermediate representation includes multiple operators; The search module is used to search for optimization strategies for the plurality of operators according to optimization conditions, and obtain a first optimization strategy sequence and optimization parameters. The first optimization strategy sequence includes a plurality of first optimization strategies that sequentially transform the code of the plurality of operators. The plurality of first optimization strategies are used to optimize the performance of the plurality of operators when they are executed on a hardware environment. The optimization parameters include the parameters in each of the plurality of first optimization strategies. The performance optimization result generated by the first optimization strategy sequence and the optimization parameters for the first intermediate representation satisfies the optimization conditions. The conversion module is used to convert the codes of the plurality of operators in the first intermediate representation according to the first optimization strategy sequence and the optimization parameters to obtain a second intermediate representation.

9. The apparatus according to claim 8, characterized in that, The search module is used for: Obtain a description file, which is used to record the input operators and output operators of each optimization strategy among multiple optimization strategies. The input operators are operators that the optimization strategy supports for transformation, and the output operators are operators obtained by transformation using the optimization strategy. Based on the description file, candidate optimization strategies corresponding to the plurality of operators are determined from the plurality of optimization strategies; Based on the candidate optimization strategies corresponding to the multiple operators, a combination space is determined. The combination space includes multiple candidate optimization strategy sequences. Each candidate optimization strategy sequence includes multiple candidate optimization strategies that sequentially transform the code of the multiple operators. The candidate optimization strategies of different candidate optimization strategy sequences are different or the execution order of the candidate optimization strategies is different. Based on the optimization conditions, an optimization strategy search is performed from the combination space to obtain the first optimization strategy sequence and optimization parameters.

10. The apparatus according to claim 9, characterized in that, The description file is also used to record the optimization order between different optimization strategies; The search module is used to determine the combination space based on the optimization order among the different optimization strategies and the candidate optimization strategies corresponding to the multiple operators.

11. The apparatus according to claim 10, characterized in that, The optimization order among the different optimization strategies includes the sorting among multiple groups, each of which includes at least one optimization strategy.

12. The apparatus according to any one of claims 9 to 11, characterized in that, The search module is used for: Determine a first set, the first set comprising at least one sequence of candidate optimization strategies in the combination space; For each candidate optimization strategy sequence in the first set, at least one parameter combination is determined, wherein each parameter combination is a parameter value among the multiple candidate optimization strategies included in the candidate optimization strategy sequence; Using an artificial intelligence (AI) model, predict the performance optimization result of each parameter combination used in each candidate optimization strategy sequence for the first intermediate representation; Based on the optimization conditions and the performance optimization results generated by each parameter combination used in each candidate optimization strategy sequence for the first intermediate representation, the first optimization strategy sequence and optimization parameters are determined.

13. The apparatus according to claim 12, characterized in that, The search module is used for: Based on the performance optimization results generated by each parameter combination used by each candidate optimization strategy sequence for the first intermediate representation, a first candidate optimization strategy sequence and a first parameter combination used by the first candidate optimization strategy sequence are determined. The performance optimization results generated by the first candidate optimization strategy sequence using the first parameter combination for the first intermediate representation are better than the performance optimization results generated by the other candidate optimization strategy sequences using parameter combinations for the first intermediate representation. Using the first candidate optimization strategy sequence and the first parameter combination, the code of the multiple operators in the first intermediate representation is transformed to obtain the test intermediate representation; The intermediate test representation is compiled to obtain computer-executable code; Execute the computer-executable code on the hardware environment to obtain the actual optimized performance generated for the first intermediate representation using the first candidate optimization strategy sequence and the first parameter combination; Based on the optimization conditions, the first candidate optimization strategy sequence, and the first parameter combination, and their actual optimization performance for the first intermediate representation, the first optimization strategy sequence and the optimization parameters are determined.

14. The apparatus according to claim 13, characterized in that, The search module is used for: Based on the first candidate optimization strategy sequence and the actual optimization performance of the first parameter combination for the first intermediate representation, a second set is determined. The second set includes at least one candidate optimization strategy sequence in the combination space. The second set does not overlap with the first set. For each candidate optimization strategy sequence in the second set, at least one parameter combination shall be determined; Using the AI ​​model, predict the performance optimization result of each parameter combination used by each candidate optimization strategy sequence in the second set for the first intermediate representation; Based on the optimization conditions and the performance optimization results of each parameter combination used by each candidate optimization strategy sequence in the second set for the first intermediate representation, as well as the actual optimization performance of the first candidate optimization strategy sequence and the first parameter combination for the first intermediate representation, the first optimization strategy sequence and optimization parameters are determined.

15. A computing device, characterized in that, The computing device includes a processor and a memory; The processor is configured to execute instructions stored in the memory to cause the computing device to perform the method as described in any one of claims 1 to 7.

16. A computer-readable storage medium, characterized in that, Includes instructions that, when executed on a computing device, cause the computing device to perform the method as described in any one of claims 1 to 7.

17. A computer program product containing instructions, characterized in that, When it is run on a computing device, it causes the computing device to perform the method as described in any one of claims 1 to 7.