Pass assembly line automatic generation method based on multistage intermediate representation and knowledge base

Through the automatic generation method of Pass pipeline based on multi-level intermediate representation and knowledge base, the high threshold problem of manual design of Pass pipeline in the prior art is solved, and the Pass pipeline with better compilation paths is realized.

CN119918507AActive Publication Date: 2025-05-02INST OF SOFTWARE - CHINESE ACAD OF SCI

Patent Information

Application Number
CN202510390267.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-31
Publication Date
2025-05-02
Estimated Expiration
2045-03-31

AI Technical Summary

Technical Problem

In the prior art, the Pass pipeline based on manual design requires experts to master the core concepts of MLIR and specific domain knowledge, which leads to high technical thresholds and difficulty in exploring better compilation paths.

Method used

The Pass pipeline automatic generation method based on multi-level intermediate representation and knowledge base is adopted. The dialect to be converted is selected from the current dialect set of files to be converted, and the appropriate target Pass is searched from the knowledge base. Through the iterative process, the file to be converted into the target dialect set is converted to the Pass pipeline to be generated.

Benefits of technology

It realizes accurate, reliable, better performance and strong versatility of automated Pass pipeline generation without relying on professional personnel, lowering the technical threshold.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119918507A_ABST
    Figure CN119918507A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of compiler optimization, and provides a Pass assembly line automatic generation method based on multistage intermediate representation and a knowledge base, which comprises the following steps of: selecting a dialect to be converted from a current dialect set of a file to be converted, and searching a target Pass suitable for the dialect to be converted from the knowledge base; under the condition that the target Pass successfully converts the to-be-converted dialect, taking the converted current dialect set as an updated dialect set; and the to-be-converted dialect is repeatedly selected and obtained from the updated dialect set, the target Pass suitable for the to-be-converted dialect is searched and obtained from the knowledge base until conversion of the to-be-converted file to the target dialect set is completed, the target Pass obtained in each round serves as the Pass assembly line, and automatic Pass assembly line generation which is accurate, reliable, better in performance and high in universality is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of compiler optimization, and in particular to a method for automatically generating a Pass pipeline based on a multi-level intermediate representation and a knowledge base. Background Art

[0002] In actual applications, compilers in the MLIR (Multi-Level Intermediate Representation) ecosystem need to reasonably design and arrange the Pass pipeline according to the target hardware and application scenarios to complete the compilation process from high-level abstraction to low-level implementation. Pass is an atomic processing unit that the compiler executes on the intermediate representation (IR) in the code processing flow. Each Pass encapsulates an independent functional module, whose input and output are both an intermediate state of IR. By sequentially connecting multiple Passes, a Pass pipeline is formed to realize the complete compilation process. The current mainstream Pass pipeline configuration method relies on compiler experts to select the type and arrangement order of Pass based on experience. The entire process needs to comprehensively consider the dependency constraints between different dialects, operations, and Passes.

[0003] However, manually designed Pass pipelines require experts to master the core concepts of MLIR and specific domain knowledge, which leads to a high technical threshold and makes it difficult to explore a better compilation path. Summary of the invention

[0004] The present invention provides a method for automatically generating a Pass pipeline based on a multi-level intermediate representation and a knowledge base, so as to solve the defects in the prior art that the manually designed Pass pipeline requires experts to master the core concepts of MLIR and specific domain knowledge, resulting in a high technical threshold and difficulty in exploring a better compilation path.

[0005] The present invention provides a method for generating a Pass pipeline based on a multi-level intermediate representation, comprising: Obtaining a file to be converted and a target dialect set corresponding to the file to be converted, wherein the file to be converted is compiled based on a multi-level intermediate representation; Selecting a dialect to be converted from the current dialect set of the file to be converted, and searching a knowledge base to obtain a target Pass applicable to the dialect to be converted; the knowledge base includes structural information of the dialect and a Pass set applicable to the dialect; When the target Pass successfully converts the dialect to be converted, the converted current dialect set is used as the updated dialect set; Repeatedly select the dialect to be converted from the updated dialect set, and search from the knowledge base to obtain the target Pass applicable to the dialect to be converted, until the conversion of the file to be converted to the target dialect set is completed, and use the target Pass obtained in each round as the Pass pipeline.

[0006] According to a method for generating a Pass pipeline based on a multi-level intermediate representation provided by the present invention, the dialect to be converted is selected from the current dialect set of the file to be converted, and a target Pass applicable to the dialect to be converted is searched from a knowledge base, and then the method further includes: When the target Pass fails to convert the dialect to be converted, backtrack to the previous dialect set of the current dialect set; A candidate target Pass of the dialect to be converted in the previous dialect set is searched from the knowledge base and used as an updated target Pass.

[0007] According to a method for generating a Pass pipeline based on a multi-level intermediate representation provided by the present invention, the knowledge base also includes an abstraction level corresponding to the dialect; The step of selecting the dialect to be converted from the current dialect set of the file to be converted comprises: Retrieving from the knowledge base the abstraction level corresponding to each current dialect in the current dialect set; Based on the abstract levels corresponding to the current dialects, the dialect to be converted is selected from the current dialect set.

[0008] According to a method for generating a Pass pipeline based on a multi-level intermediate representation provided by the present invention, the steps of constructing the knowledge base include: Get the compiler source code; Extracting key code snippets from the compiler source code; the key code snippets include at least one of a dialect definition code snippet, a pass registration code snippet, and an operation implementation code snippet; Analyze the key code snippets to obtain key information; Based on the key information, the knowledge base is constructed.

[0009] According to a method for generating a Pass pipeline based on a multi-level intermediate representation provided by the present invention, the knowledge base is constructed based on key information, including: Based on the YAML data description language, a template knowledge base is constructed according to the hierarchical structure between the dialect and the Pass set applicable to the dialect; Fill the key information into the template knowledge base to obtain the knowledge base.

[0010] According to a method for generating a Pass pipeline based on a multi-level intermediate representation provided by the present invention, the step of analyzing the key code snippet to obtain key information includes: Construct analysis prompt text; Based on a large language model, the analysis prompt text and the key code snippet are applied to analyze and obtain the key information.

[0011] The present invention also provides a device for generating a Pass pipeline based on a multi-level intermediate representation, comprising: An acquisition unit, which acquires a file to be converted and a target dialect set corresponding to the file to be converted, wherein the file to be converted is compiled based on a multi-level intermediate representation; A search unit, which selects a dialect to be converted from the current dialect set of the file to be converted, and searches a knowledge base to obtain a target Pass applicable to the dialect to be converted; the knowledge base includes structural information of the dialect and a Pass set applicable to the dialect; An updating unit, when the target Pass successfully converts the dialect to be converted, uses the converted current dialect set as an updated dialect set; The search iteration unit repeatedly selects the dialect to be converted from the updated dialect set, and searches the knowledge base to obtain the target Pass applicable to the dialect to be converted, until the conversion of the file to be converted to the target dialect set is completed, and the target Pass obtained in each round is used as the Pass pipeline.

[0012] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, a method for generating a Pass pipeline based on a multi-level intermediate representation as described in any one of the above is implemented.

[0013] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a method for generating a Pass pipeline based on a multi-level intermediate representation as described in any one of the above.

[0014] The present invention also provides a computer program product, including a computer program, which, when executed by a processor, implements any of the above-mentioned methods for generating a Pass pipeline based on a multi-level intermediate representation.

[0015] The present invention provides a method for automatically generating a Pass pipeline based on a multi-level intermediate representation and a knowledge base. The method selects a dialect to be converted from the current dialect set of the file to be converted, and searches for a target Pass applicable to the dialect to be converted from the knowledge base. When the target Pass successfully converts the dialect to be converted, the converted current dialect set is used as an updated dialect set. The method repeatedly selects a dialect to be converted from the updated dialect set, and searches for a target Pass applicable to the dialect to be converted from the knowledge base, until the conversion of the file to be converted to the target dialect set is completed. The target Pass obtained in each round is used as a Pass pipeline, thereby realizing accurate, reliable, better-performing and more versatile automatic Pass pipeline generation. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0017] Figure 1 It is a flow chart of a method for generating a Pass pipeline based on a multi-level intermediate representation provided by the present invention; Figure 2 It is a structural schematic diagram of a device for generating a Pass pipeline based on a multi-level intermediate representation provided by the present invention; Figure 3 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0018] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0019] It should be understood that in the compilation process from high-level abstraction to low-level implementation, the dialect and Pass in MLIR are open and extensible. The compilation process will change with the expansion of dialect / Pass, and a single Phase Ordering rule is difficult to adapt. In addition, the configuration of the Pass pipeline of MLIR needs to comprehensively consider the semantic information and constraints of the dialect and operation granularity. The simple heuristic search space is too large. Different dialects and Passes represent special optimizations in specific fields. It is necessary for domain experts to participate in the design of the Pass rule base, and the manual development cost is high. Therefore, the manual design of the Pass pipeline requires experts to master the core concepts of MLIR and specific domain knowledge, which has a high threshold and affects the promotion and application of MLIR. In addition, with the continuous development of the MLIR ecosystem, new dialects and Passes are frequently generated, and the maintenance cost is high if the Pass pipeline is manually debugged and modified multiple times. In addition, it is difficult to share the Pass pipeline configuration experience between different projects, which is easy to cause repeated development. Moreover, the combination of manually designed Pass pipelines is limited, and it is difficult to explore a better compilation path.

[0020] In response to the above problems, the present invention provides a method for generating a Pass pipeline based on a multi-level intermediate representation to achieve an end-to-end automated solution without relying on professional personnel, and the resulting Pass pipeline has better performance. Figure 1 is a flow chart of a method for generating a Pass pipeline based on a multi-level intermediate representation provided by the present invention, such as Figure 1 As shown, the method includes: Step 110, obtaining a file to be converted and a target dialect set corresponding to the file to be converted, wherein the file to be converted is compiled based on a multi-level intermediate representation; Here, the file to be converted refers to a set of dialects with a higher level of abstraction, and the target dialect set corresponding to the file to be converted refers to a set of dialects with a lower level of abstraction. It should be explained that MLIR supports multi-level abstraction through dialects, reflecting the advantages of grammatical uniformity, domain scalability, and operational compatibility. Each dialect contains a set of operations, representing computing primitives at a specific level of abstraction. Different dialects are converted and optimized at the abstract level through Pass. Therefore, the high-level abstraction files to be converted can be converted into a set of target dialects with a lower level of abstraction through the designed Pass pipeline. Among them, the abstraction level refers to the different levels of information detail and complexity in the computational representation and optimization process.

[0021] Specifically, an MLIR file may be obtained as a file to be converted, and a target dialect set corresponding to the file to be converted. The file to be converted may include multiple dialects, wherein each dialect is composed of multiple operations.

[0022] Step 120, selecting a dialect to be converted from the current dialect set of the file to be converted, and searching a knowledge base to obtain a target Pass applicable to the dialect to be converted; the knowledge base includes structural information of the dialect and a Pass set applicable to the dialect; Here, the knowledge base is composed of the structural information of the dialects in various fields, the abstract level corresponding to the dialects, and the Pass set applicable to the dialects, which can be used as the background knowledge of the Pass pipeline for generating the files to be converted. Among them, the structural information of the dialect includes the name of the dialect, the description of the dialect, the grammatical rules and other information; the Pass set applicable to the dialect refers to the name of each Pass in the Pass set applicable to the dialect, the definition of the Pass and other information.

[0023] Specifically, any dialect can be selected from the current dialect set of the file to be converted as the dialect to be converted, or according to the abstraction level of each dialect in the current dialect set, a dialect with a higher abstraction level can be selected as the dialect to be converted in the current round. Then, based on the search algorithm, a set of Passes applicable to the dialect to be converted can be searched from the knowledge base, and any feasible Pass can be selected from the applicable Pass set as the target Pass. The search algorithm here can be a backtracking search algorithm, a breadth-first search algorithm, etc. Among them, the breadth-first search algorithm can be to use the dialect or the operation corresponding to the dialect as the state, the Pass as the transfer condition, and use the queue to perform hierarchical expansion of the state space until the target state is found.

[0024] It should be noted that, in view of the openness and scalability based on multi-level intermediate representation, a knowledge base containing the structural information of the dialect and the Pass definition information corresponding to the dialect is pre-built, so that when selecting the Pass, the feasible target Pass corresponding to the dialect to be converted can be selected based on a reliable and comprehensive knowledge base, ensuring the accuracy, reliability and performance of the target Pass, so as to realize the automatic generation of the target Pass pipeline. In addition, there is no need for professionals who master the core concepts of MLIR and specific domain knowledge to design and select the target Pass, which reduces the technical threshold for designing the Pass pipeline.

[0025] It should also be noted that different dialects and Passes represent dedicated optimizations for specific fields, and the knowledge base contains dialect information for multiple fields, as well as Pass information applicable to the dialects. This allows the Pass pipeline generation method provided in the embodiment of the present invention to be applied to Pass pipeline generation in multiple fields, greatly improving the versatility of the Pass pipeline generation method.

[0026] Step 130, when the target Pass successfully converts the dialect to be converted, the converted current dialect set is used as the updated dialect set; Specifically, each operation in the dialect to be converted can be converted through the target Pass. When the target Pass successfully converts the dialect to be converted, the converted current dialect set can be used as the updated dialect set, that is, the current dialect set after the current round of conversion can be used as the current dialect set of the next round of target Pass to be found.

[0027] Step 140, repeatedly selecting the dialect to be converted from the updated dialect set, and searching from the knowledge base to obtain the target Pass applicable to the dialect to be converted, until the conversion of the file to be converted to the target dialect set is completed, and the target Pass obtained in each round is used as the Pass pipeline.

[0028] Specifically, the dialect to be converted can be repeatedly selected from the updated dialect set, and the target Pass applicable to the dialect to be converted can be searched from the knowledge base until the conversion of the file to be converted to the target dialect set is completed, that is, the conversion of the dialects in the file to be converted to the target dialect set is completed.

[0029] Finally, the target Pass obtained in each round can be used as a Pass pipeline, that is, a Pass pipeline of the file to be converted based on the multi-level intermediate representation is generated.

[0030] Here, the generated Pass pipeline can be used to convert and optimize the dialects in the current dialect set in the file to be converted into the target dialect set according to the order of the Pass pipeline, that is, to achieve end-to-end automatic compilation of the file to be converted into the target dialect.

[0031] It should be noted that by building and mastering rich dialect, Pass knowledge and compilation experience, novice developers do not need to delve into the details of the MLIR framework, and can use the method provided in the embodiment of the present invention to automatically complete the compilation work, which effectively lowers the threshold for learning and using MLIR.

[0032] It should also be noted that by breaking down the problem of designing the Pass pipeline into building a knowledge base and building a unified Pass pipeline generation, a complete MLIR compilation automation theoretical framework is constructed, which converts manual experience into a structured modeling method, so that complex compilation processes can be automated, greatly reducing manual development and maintenance costs.

[0033] The method provided by the embodiment of the present invention selects the dialect to be converted from the current dialect set of the file to be converted, and searches for the target Pass applicable to the dialect to be converted from the knowledge base; when the target Pass successfully converts the dialect to be converted, the converted current dialect set is used as the updated dialect set; repeatedly selects the dialect to be converted from the updated dialect set, and searches for the target Pass applicable to the dialect to be converted from the knowledge base, until the conversion of the file to be converted to the target dialect set is completed, and the target Pass obtained in each round is used as the Pass pipeline, thereby realizing accurate, reliable, better-performing and highly versatile automated Pass pipeline generation.

[0034] Based on any of the above embodiments, after step 120, the following steps may be further performed: When the target Pass fails to convert the dialect to be converted, backtrack to the previous dialect set of the current dialect set; A candidate target Pass of the dialect to be converted in the previous dialect set is searched from the knowledge base and used as an updated target Pass.

[0035] Specifically, a backtracking tree mechanism can be used to search for feasible Pass permutations and combinations, that is, to obtain a Pass pipeline. In detail, the current dialect set of the initial file to be converted can be used as the root node, and a target Pass corresponding to a dialect to be converted can be selected in each round. The operations contained in the dialect to be converted can be tried to be converted from the starting dialect to the target dialect, and the converted current dialect set can be used as a new tree node, that is, as an updated dialect set. Repeat the search for the next round of target Pass until all dialect sets in the file to be converted are converted to the target dialect set.

[0036] In addition, if the target Pass cannot complete the expected conversion of the dialect to be converted, that is, when the target Pass fails to convert the dialect to be converted, the current dialect set can be traced back to the dialect set of the previous round, and the target Pass for updating the dialect to be converted in this round can be reselected. For example, the candidate target Pass of the dialect to be converted in the previous dialect set is searched from the knowledge base as the updated target Pass. The candidate target Pass here refers to other Passes in the pass set applicable to the dialect to be converted.

[0037] It should be noted that if the first starting target Pass fails to convert the dialect to be converted, the current dialect set is the starting dialect set, and there is no previous dialect set of the current dialect set. If the search fails after reaching the maximum number of iterations, the search is terminated.

[0038] The method provided by the embodiment of the present invention abstracts the MLIR compilation process into a backtracking tree model, represents the compilation stage through the tree hierarchy, the tree nodes represent the optimization operation, and the tree path search corresponds to the Pass pipeline search, thereby realizing unified compilation for any file to be converted. In addition, combined with a domain-specific knowledge base, an end-to-end automated solution can be realized.

[0039] It should be noted that compared with manual design, the method provided by the embodiment of the present invention can systematically explore the combinatorial optimization space of the Pass pipeline, make full use of computing resources to find a better compilation path, and achieve better performance in indicators such as compilation efficiency and target code performance.

[0040] It should also be noted that the backtracking tree model well describes the process of MLIR compilation pass selection and sorting. Compared with manually stacking pass pipelines, the backtracking tree can systematically manage different solutions, accelerate search through strategies such as pruning and priority adjustment, and support backtracking correction when compilation fails, improving the efficiency and reliability of pass pipeline generation. Experimental results show that the average success rate of the backtracking tree generation module exceeds 90%, which reflects the effectiveness of this technology.

[0041] Based on any of the above embodiments, the knowledge base further includes an abstraction level corresponding to the dialect; The step of selecting the dialect to be converted from the current dialect set of the file to be converted comprises: Retrieving from the knowledge base the abstraction level corresponding to each current dialect in the current dialect set; Based on the abstract levels corresponding to the current dialects, the dialect to be converted is selected from the current dialect set.

[0042] Here, the knowledge base also includes the abstract levels corresponding to each dialect, and it can be considered that the knowledge base stores the abstract levels to which each dialect belongs.

[0043] Specifically, the abstract level corresponding to each current dialect in the current dialect set can be retrieved from the knowledge base. Then, according to the abstract level corresponding to each current dialect, a current dialect with a higher abstract level can be selected from the current dialect set as the dialect to be converted. Therefore, in the entire compilation process of the dialect to be converted, it can be regarded as selecting the dialect to be converted from high to low based on the abstract level corresponding to each current dialect, that is, according to the level of the abstract level of each current dialect, the conversion of each current dialect is completed from high to low.

[0044] It is understandable that there may be multiple current dialects in the current dialect set that correspond to the same abstract level. After retrieving the abstract level of each current dialect, the current dialects in the current dialect set can be divided according to the abstract level to which each current dialect belongs, and current dialects at several abstract levels can be obtained. Furthermore, any current dialect can be selected from the current dialects at the highest abstract level as the dialect to be converted.

[0045] It should be noted that current dialects with a higher level of abstraction often contain more common and widely accepted language features, which helps reduce the complexity and workload of the conversion process and improve the overall conversion efficiency. In addition, considering that starting from a more common dialect, it is easier to find commonalities and conversion rules with other dialects or standard languages, the current dialect with a higher level of abstraction is prioritized for conversion, which reduces conversion errors caused by dialect differences and improves the accuracy of the conversion of the dialect to be converted.

[0046] Based on any of the above embodiments, the step of constructing the knowledge base includes: Get the compiler source code; Extracting key code snippets from the compiler source code; the key code snippets include at least one of a dialect definition code snippet, a pass registration code snippet, and an operation implementation code snippet; Analyze the key code snippets to obtain key information; Based on the key information, the knowledge base is constructed.

[0047] Specifically, you can obtain the compiler source code of the target dialect set (target compiler) applied in various fields from the code manager, the official website of the open source compiler project, or a third-party platform. Here, the compiler source code contains all the functions and implementation details of the compiler, that is, it contains the specific implementation details of the compiled dialect and Pass.

[0048] Then, you can identify and extract key code snippets from the compiler source code using static analysis tools or by writing custom scripts.

[0049] Here, the key code snippet refers to a specific type of code snippet, which may include at least one of a dialect definition snippet, a Pass registration snippet, an operation implementation snippet, and a test snippet. It is understandable that the dialect definition snippet may be used to reflect the grammatical rules, description, and applicable Pass type of the dialect; the Pass registration snippet may be used to reflect the description, name, and applicable dialect type of the Pass; the operation implementation snippet may be used to reflect the implementation logic of the specific compilation operation of the dialect and Pass; the test snippet may include unit testing, integration testing, etc., and may also be used to reflect the implementation logic of the specific compilation operation of the dialect and Pass.

[0050] Furthermore, the extracted key code snippets can be input into the large language model, and the key code snippets can be analyzed by the large language model to extract the semantic information contained in the key code snippets, such as dialect characteristics, the role of Pass, specific implementation details of the operation, etc. The semantic information is converted into structured knowledge base entries, that is, the key information of the compiler source code. In addition, a set of rule templates can be predefined, and the code analysis results can be matched and filled with the templates to generate corresponding knowledge entries, that is, key information. It should be noted that the knowledge fusion method needs to match the code analysis method, use prior knowledge and constraints to guide knowledge generation, and improve the integrity and consistency of the knowledge base. The key information here can include the structural information of the dialect and the set of Passes applicable to the dialect.

[0051] In addition, other code analysis methods can be used to analyze and obtain key information. For example, an abstract syntax tree of the source code is constructed through the compiler front end, and then the abstract syntax tree is traversed to extract the semantic information of key nodes, generate knowledge entries, and use the knowledge entries as key information. For another example, by constructing a data dependency graph of the compiler Pass, the flow of data between Passes is analyzed, the functions and calling relationships of Passes are inferred, and key information is obtained. For another example, by slicing the compiler source code, code snippets related to specific dialects and Passes are extracted, and their structure and semantics are further analyzed to obtain key information. It should be noted that the alternative code analysis method needs to be adapted to the target language (C++, TableGen), make full use of the characteristics of the MLIR framework, accurately and efficiently extract knowledge, and ensure the quality of the knowledge base.

[0052] Finally, the organizational form of the template specification knowledge base constructed by the structured YAML (YAML Ain't Markup Language) data description language can be adopted to fill the key information into the organizational form of the YAML template specification knowledge base to obtain the knowledge base.

[0053] It should be noted that for the organization and presentation of the knowledge base, ontology languages ​​such as RDF (Resource Description Framework) and OWL (Web Ontology Language) can also be used to systematically represent key information in the form of concepts, attributes, and relationships to support richer semantic expressions and reasoning. Alternatively, it can be built in the form of a graph database, such as using a graph database such as Neo4j to store entities such as dialect and Pass in the form of nodes, and relationships in the form of edges, to support complex graph queries and analysis. Alternatively, JSON can be used to represent knowledge in a structured manner such as key-value pairs and lists, which is lightweight and easy to parse.

[0054] In addition, after obtaining the knowledge base, in addition to using the file system to store the knowledge base, the knowledge base can also be stored in a database, such as a relational database or a non-relational database. For example, using MySQL, PostgreSQL and other databases, the knowledge items are stored in a structured table format, supporting efficient query and update, so as to facilitate subsequent query and use, and obtain a database-type knowledge base. Alternatively, using databases such as MongoDB and CouchDB, the knowledge items are stored in a flexible document (BSON, JSON) format, supporting dynamic schema and horizontal expansion. Alternatively, the knowledge base can be stored on cloud storage services such as AWS S3 and Google Cloud Storage, and its high availability, elastic expansion and other features can be used to achieve centralized management and on-demand access to knowledge.

[0055] It is understandable that alternative knowledge storage methods need to ensure data persistence, consistency and efficient access, and seamlessly integrate with other parts of the Pass pipeline generation method to ensure the normal progress of the Pass pipeline generation process.

[0056] It should be noted that the knowledge base can also be dynamically updated at any time. It can obtain the compiler source code related to the target dialect set, extract the key code snippets in the compiler source code, analyze the key code snippets, and obtain key information; the extracted key information can be added to the knowledge base to achieve dynamic updating of the knowledge base, thereby further ensuring the accuracy of compilation optimization for the target dialect set, that is, ensuring the accuracy of the generated Pass pipeline.

[0057] The method provided in the embodiment of the present invention designs a dynamically updateable knowledge base based on the openness and extensibility of MLIR, provides comprehensive and diverse background knowledge support for the compilation process of MLIR, so as to ensure the accuracy of the Pass pipeline and realize the design of a high-performance Pass pipeline.

[0058] Based on any of the above embodiments, the step of constructing the knowledge base based on key information includes: Based on the YAML data description language, a template knowledge base is constructed according to the hierarchical structure between the dialect and the Pass set applicable to the dialect; Fill the key information into the template knowledge base to obtain the knowledge base.

[0059] Here, the YAML data description language uses indentation to indicate hierarchical relationships, making the hierarchical structure of the data clearer. The degree of indentation determines the hierarchical relationship of the elements. Usually 2 or 4 spaces are used for indentation, and the number of indented spaces in the entire file should be consistent. Therefore, the hierarchical structure of the YAML data description language can be used to clearly indicate the relationship between dialects and Passes. For example, a smaller indentation degree can reflect a large dialect set. Under a large dialect set, a larger degree of indentation can be used to indicate the dialects under the dialect set. Furthermore, under each dialect under the dialect set, a larger degree of indentation can be used to indicate the Pass information applicable to the dialect.

[0060] Specifically, the template knowledge base can be constructed by using the YAML data description language. For example, the template knowledge base can be constructed by determining the indentation degree between the dialect and each Pass in the Pass set according to the hierarchical structure between the dialect and the Pass set to which the dialect is applicable.

[0061] Then, the key information is filled into the template knowledge base to obtain a complete knowledge base. Specifically, the structural information of the dialect in the key information can be filled into the position corresponding to the dialect in the template knowledge base, and the information of each pass in the Pass set applicable to the dialect in the key information can be filled into the position corresponding to the dialect in the template knowledge base, thereby obtaining a knowledge base with a clear hierarchical structure.

[0062] For example, the knowledge base K can be represented by multiple triples ( ), of which, Represents a specific Dialect, belonging to the set D of all Dialects; express The abstract level it is in belongs to the set A of all abstract levels; Representation and The collection of related Passes is A subset of all Pass collections.

[0063] It can be understood that the knowledge base K organizes the structure of each Dialect, its abstraction level and the corresponding Pass set, and comprehensively represents the information of different abstraction levels and processing stages of the compiler.

[0064] It should be noted that the knowledge base can adaptively learn the characteristics of the target compiler and continuously update knowledge during the continuous evolution of the MLIR ecosystem, so that the automation solution can adapt to MLIR compilers in different fields, with openness and scalability. In the experiment, the knowledge base automatically learned more than 20 dialects and 30 passes from the compiler source code on average, and the accuracy of knowledge extraction exceeded 95%, which greatly enriched knowledge and experience and improved its generalization ability.

[0065] Based on any of the above embodiments, analyzing the key code snippet to obtain key information includes: Construct analysis prompt text; Based on a large language model, the analysis prompt text and the key code snippet are applied to analyze and obtain the key information.

[0066] Here, the analysis prompt text can be used to help guide the large language model to correctly understand the design concept and working mechanism of the target compiler (target dialect), and improve the accuracy of the extracted key information and its strong correlation with the target compiler.

[0067] Specifically, the analysis prompt text can be pre-constructed, for example, the analysis prompt text can be "Please extract the name and description information of the dialect from the dialect definition code segment". Then, the analysis prompt text and the key code snippet can be input into the large language model, and the key code snippet is analyzed by the large language model according to the analysis prompt text to output the key information. It should be noted that the large language model here can be a large language model obtained after instruction fine-tuning training, that is, it can better understand the design concept and working mechanism of the target compiler (target dialect).

[0068] It should be noted that there are Phase Ordering optimization issues in traditional compilers, which mainly use heuristic search and machine learning methods to automatically arrange the order of optimization stages. However, the configuration problem of the MLIR Pass pipeline is different from the traditional Phase Ordering, mainly reflected in: the dialect and Pass in MLIR are open and extensible, the compilation process will change with the expansion of dialect / Pass, and a single Phase Ordering rule is difficult to adapt. The configuration of the MLIR Pass pipeline needs to comprehensively consider the semantic information and constraints of the dialect and operation granularity, and the simple heuristic search space is too large. Different dialects and Passes represent special optimizations for specific fields, and domain experts are required to participate in the design of the Pass rule library, which has high manual development costs.

[0069] In view of the above problems, based on any of the above embodiments, the present invention also provides a method for generating a Pass pipeline based on a multi-level intermediate representation, the method comprising: knowledge base construction and Pass pipeline generation.

[0070] Among them, in the knowledge base construction process, first, the relationship between each dialect and pass can be clearly expressed through the hierarchical structure of the YAML file, and the dialect information, pass definition, etc. can be efficiently parsed and extracted, and automatically organized into a structured knowledge base, which can be recorded as a COMPASS knowledge base. It should be noted that in the design of the knowledge base, a knowledge base K can be defined, which contains multiple dialects. Each dialect corresponds to an abstract level and contains a set of related passes.

[0071] Then, a knowledge importer can be built to automatically extract information from the target compiler source code and update the knowledge base. In detail, key code snippets in the compiler source code can be automatically identified, including dialect definition, Pass registration, operation implementation, unit test, integration test, etc., and the semantic information contained therein can be extracted to obtain key information. In addition, a structured YAML template is used to standardize the organization of the knowledge base. The knowledge importer analyzes code snippets through a large language model, extracts key information and fills it into the YAML template to form structured knowledge entries. Among them, when the key information is extracted, the necessary context information can be defined for the knowledge base construction task to guide the knowledge importer to correctly understand the design concept and working mechanism of the target compiler and improve the accuracy of knowledge extraction.

[0072] In addition, in the Pass pipeline generation process, a backtracking tree mechanism can be used to automatically search for feasible Pass permutations and combinations in the constructed knowledge base to achieve automatic compilation of the MLIR source file to the target dialect set. In detail, the initial state definition: the distribution of operations is analyzed according to the input MLIR file to obtain the starting dialect set. Then, the abstract level corresponding to each dialect in the dialect set is retrieved from the knowledge base to form the root node of the backtracking tree. Then, the recursive iteration process: each round selects a feasible Pass, tries to convert the operation from the starting dialect to the target dialect, and updates the current state to form a new tree node. Backtracking mechanism: If the current Pass cannot complete the expected conversion of the operation, it backtracks to the previous state and tries other Pass combinations. Target state judgment: If all operations are successfully converted to the target dialect, the search is successful and the corresponding Pass pipeline solution is generated. Or, if the search fails after reaching the maximum number of iterations, the search is terminated.

[0073] It is understandable that in the process of exploring the Pass pipeline, some extreme cases may be constructed, which may trigger hidden bugs in the compiler. Developers can analyze the causes of these bugs, discover and fix defects in the compiler, and improve the quality and stability of the compiler.

[0074] It should be noted that the design of an end-to-end MLIR compilation Pass Pipeline automatic generation system, including functional modules such as knowledge base construction, knowledge import, and pipeline generation, can be applied to any MLIR compiler project, realizing end-to-end automation from MLIR compiler source code learning, Pass pipeline generation to target code, forming a complete closed-loop solution that can be seamlessly integrated into the MLIR compilation system, providing developers and users with a transparent automated compilation experience. Experiments show that this method can be effectively applied to mainstream machine learning frameworks such as TensorFlow and PyTorch, as well as typical MLIR compiler projects such as CIRCT and Toy. The performance of the generated Pass pipeline is comparable to that of the manually optimized benchmark solution, reflecting significant practical value.

[0075] The method provided in the embodiment of the present invention proposes an MLIR compilation process automation solution based on artificial intelligence technology from the two dimensions of automated modeling and knowledge extraction, forming a complete end-to-end Pass pipeline generation method, which can be applied to various compiler projects in the MLIR ecosystem, greatly reducing the manual development and maintenance costs of the MLIR system, and has broad application prospects.

[0076] Based on any of the above embodiments, Figure 2 is a schematic diagram of the structure of a device for generating a Pass pipeline based on a multi-level intermediate representation provided by the present invention, such as Figure 2 As shown, the device comprises: An acquisition unit 210 acquires a file to be converted and a target dialect set corresponding to the file to be converted, wherein the file to be converted is compiled based on a multi-level intermediate representation; A search unit 220 selects a dialect to be converted from the current dialect set of the file to be converted, and searches a knowledge base to obtain a target Pass applicable to the dialect to be converted; the knowledge base includes structural information of the dialect and a Pass set applicable to the dialect; The updating unit 230, when the target Pass successfully converts the dialect to be converted, uses the converted current dialect set as the updated dialect set; The search iteration unit 240 repeatedly selects the dialect to be converted from the updated dialect set, and searches the knowledge base to obtain the target Pass applicable to the dialect to be converted, until the conversion of the file to be converted to the target dialect set is completed, and the target Pass obtained in each round is used as the Pass pipeline.

[0077] The device provided by the embodiment of the present invention obtains the dialect to be converted by selecting it from the current dialect set of the file to be converted, and searches for the target Pass applicable to the dialect to be converted from the knowledge base; when the target Pass successfully converts the dialect to be converted, the converted current dialect set is used as the updated dialect set; the dialect to be converted is repeatedly selected from the updated dialect set, and the target Pass applicable to the dialect to be converted is searched from the knowledge base until the conversion of the file to be converted to the target dialect set is completed, and the target Pass obtained in each round is used as the Pass pipeline, thereby realizing accurate, reliable, better-performing and highly versatile automated Pass pipeline generation.

[0078] Based on any of the above embodiments, the search iteration unit is further specifically used for: When the target Pass fails to convert the dialect to be converted, backtrack to the previous dialect set of the current dialect set; A candidate target Pass of the dialect to be converted in the previous dialect set is searched from the knowledge base and used as an updated target Pass.

[0079] Based on any of the above embodiments, the knowledge base further includes an abstraction level corresponding to the dialect; The search unit is specifically used for: Retrieving from the knowledge base the abstraction level corresponding to each current dialect in the current dialect set; Based on the abstract levels corresponding to the current dialects, the dialect to be converted is selected from the current dialect set.

[0080] Based on any of the above embodiments, the device further includes a knowledge base construction unit, and the knowledge base construction unit is specifically used to: Get the compiler source code; Extracting key code snippets from the compiler source code; the key code snippets include at least one of a dialect definition code snippet, a pass registration code snippet, and an operation implementation code snippet; Analyze the key code snippets to obtain key information; Based on the key information, the knowledge base is constructed.

[0081] Based on any of the above embodiments, the knowledge base construction unit is further specifically used for: Based on the YAML data description language, a template knowledge base is constructed according to the hierarchical structure between the dialect and the Pass set applicable to the dialect; Fill the key information into the template knowledge base to obtain the knowledge base.

[0082] Based on any of the above embodiments, the knowledge base construction unit is further specifically used for: Construct analysis prompt text; Based on a large language model, the analysis prompt text and the key code snippet are applied to analyze and obtain the key information.

[0083] Figure 3 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 3 As shown, the electronic device may include: a processor 310 , a communications interface 320 , a memory 330 and a communication bus 340 , wherein the processor 310 , the communications interface 320 , and the memory 330 communicate with each other via the communication bus 340 . The processor 310 can call the logic instructions in the memory 330 to execute a method for generating a Pass pipeline based on a multi-level intermediate representation, the method comprising: obtaining a file to be converted and a target dialect set corresponding to the file to be converted, the file to be converted being compiled based on the multi-level intermediate representation; selecting a dialect to be converted from the current dialect set of the file to be converted, and searching a target Pass applicable to the dialect to be converted from a knowledge base; the knowledge base includes structural information of the dialect, and a Pass set applicable to the dialect; when the target Pass successfully converts the dialect to be converted, the converted current dialect set is used as an updated dialect set; repeatedly selecting the dialect to be converted from the updated dialect set, and searching the knowledge base for a target Pass applicable to the dialect to be converted, until the conversion of the file to be converted to the target dialect set is completed, and the target Pass obtained in each round is used as the Pass pipeline.

[0084] In addition, the logic instructions in the above-mentioned memory 330 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.

[0085] On the other hand, the present invention also provides a computer program product, which includes a computer program, which can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the method for generating a Pass pipeline based on a multi-level intermediate representation provided by the above methods, the method including: obtaining a file to be converted and a target dialect set corresponding to the file to be converted, the file to be converted being compiled based on a multi-level intermediate representation; selecting a dialect to be converted from a current dialect set of the file to be converted, and searching a target Pass applicable to the dialect to be converted from a knowledge base; the knowledge base includes structural information of the dialect, and a Pass set applicable to the dialect; when the target Pass successfully converts the dialect to be converted, the converted current dialect set is used as an updated dialect set; repeatedly selecting the dialect to be converted from the updated dialect set, and searching the knowledge base for a target Pass applicable to the dialect to be converted, until the conversion of the file to be converted to the target dialect set is completed, and the target Pass obtained in each round is used as a Pass pipeline.

[0086] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the method for generating a Pass pipeline based on a multi-level intermediate representation provided by the above-mentioned methods, the method comprising: obtaining a file to be converted and a target dialect set corresponding to the file to be converted, the file to be converted being compiled based on a multi-level intermediate representation; selecting a dialect to be converted from a current dialect set of the file to be converted, and searching a target Pass applicable to the dialect to be converted from a knowledge base; the knowledge base includes structural information of the dialect, and a Pass set applicable to the dialect; when the target Pass successfully converts the dialect to be converted, the converted current dialect set is used as an updated dialect set; repeatedly selecting the dialect to be converted from the updated dialect set, and searching the knowledge base for a target Pass applicable to the dialect to be converted, until the conversion of the file to be converted to the target dialect set is completed, and the target Pass obtained in each round is used as the Pass pipeline.

[0087] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0088] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0089] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for generating a Pass pipeline based on a multi-level intermediate representation, characterized in that: include: Obtaining a file to be converted and a target dialect set corresponding to the file to be converted, wherein the file to be converted is compiled based on a multi-level intermediate representation; Selecting a dialect to be converted from the current dialect set of the file to be converted, and searching a knowledge base to obtain a target Pass applicable to the dialect to be converted; the knowledge base includes structural information of the dialect and a Pass set applicable to the dialect; When the target Pass successfully converts the dialect to be converted, the converted current dialect set is used as the updated dialect set; Repeatedly select the dialect to be converted from the updated dialect set, and search from the knowledge base to obtain the target Pass applicable to the dialect to be converted, until the conversion of the file to be converted to the target dialect set is completed, and use the target Pass obtained in each round as the Pass pipeline.

2. The method for generating a Pass pipeline based on a multi-level intermediate representation according to claim 1, characterized in that: The step of selecting a dialect to be converted from the current dialect set of the file to be converted, and searching a knowledge base to obtain a target Pass applicable to the dialect to be converted, further comprises: When the target Pass fails to convert the dialect to be converted, backtrack to the previous dialect set of the current dialect set; A candidate target Pass of the dialect to be converted in the previous dialect set is searched from the knowledge base and used as an updated target Pass.

3. The method for generating a Pass pipeline based on a multi-level intermediate representation according to claim 1, characterized in that: The knowledge base also includes an abstraction level corresponding to the dialect; The step of selecting the dialect to be converted from the current dialect set of the file to be converted comprises: Retrieving from the knowledge base the abstraction level corresponding to each current dialect in the current dialect set; Based on the abstract levels corresponding to the current dialects, the dialect to be converted is selected from the current dialect set.

4. The method for generating a Pass pipeline based on a multi-level intermediate representation according to any one of claims 1 to 3, characterized in that: The steps of constructing the knowledge base include: Get the compiler source code; Extracting key code snippets from the compiler source code; the key code snippets include at least one of a dialect definition code snippet, a pass registration code snippet, and an operation implementation code snippet; Analyze the key code snippets to obtain key information; Based on the key information, the knowledge base is constructed.

5. The method for generating a Pass pipeline based on a multi-level intermediate representation according to claim 4, characterized in that: The knowledge base is constructed based on the key information, including: Based on the YAML data description language, a template knowledge base is constructed according to the hierarchical structure between the dialect and the Pass set applicable to the dialect; Fill the key information into the template knowledge base to obtain the knowledge base.

6. The method for generating a Pass pipeline based on a multi-level intermediate representation according to claim 4, characterized in that: The analyzing the key code snippet to obtain key information includes: Construct analysis prompt text; Based on a large language model, the analysis prompt text and the key code snippet are applied to analyze and obtain the key information.

7. A device for generating a Pass pipeline based on a multi-level intermediate representation, characterized in that: include: An acquisition unit, which acquires a file to be converted and a target dialect set corresponding to the file to be converted, wherein the file to be converted is compiled based on a multi-level intermediate representation; A search unit, which selects a dialect to be converted from the current dialect set of the file to be converted, and searches a knowledge base to obtain a target Pass applicable to the dialect to be converted; the knowledge base includes structural information of the dialect and a Pass set applicable to the dialect; An updating unit, when the target Pass successfully converts the dialect to be converted, uses the converted current dialect set as an updated dialect set; The search iteration unit repeatedly selects the dialect to be converted from the updated dialect set, and searches the knowledge base to obtain the target Pass applicable to the dialect to be converted, until the conversion of the file to be converted to the target dialect set is completed, and the target Pass obtained in each round is used as the Pass pipeline.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the method for generating a Pass pipeline based on a multi-level intermediate representation as described in any one of claims 1 to 6 is implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for generating a Pass pipeline based on a multi-level intermediate representation as described in any one of claims 1 to 6 is implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method for generating a Pass pipeline based on a multi-level intermediate representation as described in any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Probability model AI field compiling system and method based on multistage intermediate representation

    CN116679933A

  • Triton compiler assembly line-oriented optimization system and optimization method

    CN118605850A

  • Cross-platform automatic code generation method and device, equipment, medium and product

    CN119336336A

  • Domain-specific language compiler optimization method and system based on multi-layer intermediate representation

    CN119512557A

  • Method and device with iterative compilation for deep learning

    EP4474979A1

Cited By

  • Data processing method and device

    CN121597447A

  • Data processing method and apparatus

    CN121597447B