Compilation optimization method of graph neural network model, compiler and storage medium
By configuring the calculation graph rewriting rules and graph-level semantics, decomposing the composite graph operator and performing graph-aware nested loop optimization, the problem of insufficient compilation and optimization of graph neural network models in the existing technology is solved, and high-performance graphs are achieved Neural network model execution.
Patent Information
- Application Number
- CN202310713862.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-15
- Publication Date
- 2024-12-17
AI Technical Summary
The existing graph neural network model compilation optimization technology has insufficient operator level and model level optimization capabilities, and cannot achieve complete compilation optimization, which limits the high-performance execution of the model.
The intermediate representation of the graph neural network model is optimized by configuring the calculation graph rewriting rules and the graph-level semantics of tensors, decomposing the composite graph operator as the basic graph operator, and using the scatter function and the aggregation function to establish the attribute propagation rules, based on the graph Perceptual nested loop bodies perform operator fusion and scheduling transformation to realize computational graph slicing and horizontal and vertical partition optimization.
The dynamic code program adaptive automatic generation of operators is realized, which improves the computing performance of graph neural network models, provides complete joint optimization of model level and operator level, ensuring computational equivalence and high-performance execution.
Smart Images

Figure CN119149040A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of graph neural network technology, and in particular to the field of compilation technology of graph neural network models. Background Art
[0002] In the current era of big data, more and more data is stored in an unstructured way. In this context, graphs, as a universal data representation format, have natural advantages and can well express the data itself and the connections between data. By abstracting entities as vertices and representing the relationships between vertices as edges, the data structure of graphs can better describe the associations and interactions between complex data. This trend also puts higher demands on modern neural networks, and the data forms that need to be processed have become more complex. At the same time, it also promotes the rapid emergence and development of neural network models with operators for irregular data as the core.
[0003] In recent years, Graph Neural Network (GNN), as a model with powerful graph learning and reasoning capabilities, has become a research hotspot in academia and industry. The emergence of GNN enables machine learning to be applied to graph structures in non-Euclidean spaces and has the ability to learn graphs. The concept of GNN was first proposed by Gori et al. in 2005 and further clarified by Scarselli et al. in 2009. These early studies mainly explored learning the representation of target vertices by propagating neighboring information through a recurrent neural architecture in an iterative manner. Inspired by the great success of convolutional networks in the field of machine learning, many methods have recently emerged to redefine the concept of convolution for graph data. Bruna et al. proposed the first important study on graph convolutional networks (GCN) in 2013. They developed a variant of graph convolution based on spectral graph theory. This study later developed into spectral methods in the field of graph convolution. The original spectral method has the disadvantage of high temporal and spatial complexity. Inspired by GCN, spatial methods came into being. Its main feature is that it focuses more on information extraction considering the spatial structure of the graph. Subsequent research work has also used attention mechanisms, serialization models, etc. to model the weights between vertices in the vertex domain to explore further information extraction. Due to its good performance and interpretability, graph neural networks have recently become a widely used graph analysis method. At present, graph neural networks have shown good results in many application fields such as social networks, recommendation systems, and transportation.
[0004] Figure 1A typical process of graph neural network model calculation is shown. When calculating, the graph neural network model will take graph topology data (such as node and edge information) and input feature tensors (such as node and edge attributes) as input, and obtain the corresponding output feature tensors after calculation through different GNN model layers. These output feature tensors will be further used in different downstream computing tasks. In each model layer of the graph neural network, the calculation of the graph neural network will combine graph operators (such as aggregation, propagation, update, etc.) and neural network operators (such as convolution, pooling, full connection, etc.). Since the graph neural network model needs to process irregular graph topology data and regular feature tensor data at the same time, its calculation process has both irregular and regular interweaving and mixed execution modes. This mixed execution mode brings new challenges and opportunities to the calculation optimization of graph neural networks. On the one hand, for the irregular part, the calculation strategy needs to take into account the memory access and calculation efficiency problems caused by the sparsity and non-uniformity of graph data; on the other hand, for the regular part, the calculation strategy needs to take into account the high parallelism and high computing intensity characteristics of traditional neural network calculations. Therefore, when designing an efficient and scalable graph neural network computing optimization solution, it is necessary to fully utilize the parallel resources and memory hierarchy provided by the existing hardware platform, and to perform collaborative optimization between different types and granularities of abstract levels, including the operator layer and the model layer.
[0005] Faced with increasingly iterative neural network models and a variety of hardware platforms, how to effectively execute neural network model algorithm calculations and give full play to the computing power of hardware has become a new challenge facing the field of artificial intelligence. Hardware acceleration platforms for specific fields often require the design of new architectures, including new instruction sets and programming models, which require full-stack support for software and hardware implementation. However, the continuous iteration of algorithm models and the fragmentation of hardware platforms have brought huge challenges to the rapid and efficient deployment of neural networks.
[0006] In order to meet these challenges, neural network compilation optimization has become a research field that has attracted much attention. Compilation optimization research can be divided into two categories: operator level and model level. Operator level work optimizes a single computing operation, while the model level considers how to improve the performance of the neural network as a whole. Both methods are of great significance and can significantly improve the performance of neural networks.
[0007] For operator-level compilation optimization, existing solutions mainly rely on the code abstraction representation of nested loops, and the supported optimization is mainly loop transformation. For dense operators and sparse operators, a lot of research work has made progress. In the research work on compilation optimization of dense operators, Facebook launched Tensor Comprenension, which provides a series of programming primitives and uses polyhedron models to optimize loops in programs to achieve computational optimization of deep learning applications. The University of Washington borrowed the design method of the computation and scheduling separation definition of the Halide[] language and launched the end-to-end framework TVM for deploying deep learning workloads to hardware, which is used to optimize the rapid deployment and efficient reasoning execution of deep learning models on any target hardware platform such as CPU, GPU, ARM, etc. In the research work on compilation optimization of sparse operators, TACO can automatically generate efficient and concise code for general sparse algebraic calculations. Graphit is a typical work for graph data processing. It follows the design principle of decoupling scheduling and computation, and can achieve code optimization and automatic generation on CPU hardware platforms for different graph algorithms running on graphs of different sizes and structures.
[0008] For model-level compilation optimization, existing solutions are mainly based on the abstract representation of computational graphs for analysis and optimization. Computational graphs are the mainstream representation method for neural network model levels today. A computational graph is a directed acyclic graph in which nodes correspond to operators in a neural network model and edges are used to represent data dependencies between operators. Currently, the abstract representation of computational graphs has been widely used in neural network frameworks such as TensorFlow and PyTorch. Model-level analysis and optimization can be performed based on computational graphs. Operator fusion is a typical optimization method between operators. By fusing some continuous operators into a large operator, unnecessary storage overhead of intermediate results is eliminated and unnecessary input reading is reduced. Currently, many neural network frameworks and compilers support operator fusion optimization. Computational graph rewriting is another typical model-level optimization method. This method uses the characteristics of operators to map and replace operator combinations that meet specific patterns on the premise of satisfying computational equivalence, so that the neural network model can be calculated in a lower memory access or computational overhead mode.
[0009] Seastar is a vertex-centric GNN programming model framework. It uses graph information tags on the computational graph to describe and track the model's operator and data features. Based on this feature information, Seastar combines fixed static templates to implement compilation optimization of GNN models including operator fusion and automatic code generation, thereby improving the computational performance of GNN model execution.
[0010] Although Seastar has implemented some compilation optimizations for GNN models, there are still some shortcomings and limitations. First, Seastar does not implement model-level optimization for computational graph rewriting, which makes the optimization of the model incomplete and cannot maximize the potential of computing resources. Second, Seastar's code generation for the operator level is achieved by manually providing a small number of static templates. This approach will greatly limit the strategy space for code execution, thus limiting the ability of operator-level optimization.
[0011] Graphiler is a GNN compiler designed specifically for DGL. It provides GNN model-level optimization capabilities. For the model code of GNN user-defined input, Graphiler can achieve optimizations including operator reordering and operator fusion at the model level based on pattern matching. In the optimized computational graph, the operators will be mapped to the composite operators of DGL again, thereby achieving more efficient calculations. Although Graphiler has advantages such as computational graph reconstruction and model-level operator optimization, it has some defects and limitations. The most significant problem is that it lacks the ability to generate and optimize operator-level code. The operators in the optimized computational graph can only be mapped to the operators provided by DGL. Since individual operators cannot be optimized, the execution efficiency of the operator level cannot be maximized. At the same time, it also limits the optimization space of the compiler and cannot maximize the potential of computing resources.
[0012] As GNN models become more and more complex, how to efficiently execute GNN models has become a task that has attracted much attention. However, the current technical solutions for GNN compilation optimization have many limitations and cannot achieve complete compilation optimization, which has caused serious obstacles to the widespread application and deployment of models. Summary of the invention
[0013] In view of the shortcomings of the prior art mentioned above, the purpose of the present invention is to provide a compilation optimization method, compiler and storage medium of a graph neural network model, which are used to optimize the compilation of the graph neural network model, thereby achieving high-performance execution of the graph neural network model.
[0014] To achieve the above-mentioned purpose and other related purposes, the present invention provides a compilation optimization method for a graph neural network model, including: obtaining an input graph neural network model, optimizing the first-level intermediate representation of the graph neural network model by configuring computational graph rewriting rules and graph-level semantics of tensors; performing computational graph segmentation on the optimized output of the first level; and optimizing the second-level intermediate representation of the graph neural network model based on the segmented computational graph and graph-aware nested loop body.
[0015] In a specific embodiment of the present invention, the optimization of the first-level intermediate representation of the graph neural network model by configuring computational graph rewriting rules includes: decomposing the composite graph operators of the graph neural network model into basic graph operators and neural network operators, and configuring rewriting rules for the basic graph operators.
[0016] In a specific embodiment of the present invention, optimizing the first-level intermediate representation of the graph neural network model through the graph-level semantics of tensors includes: using the scatter function and aggregation function of the basic graph operator to establish relevant attribute propagation rules of the basic graph operator; wherein, the scatter function converts the vertex tensor into an edge tensor, and the aggregation function converts the edge tensor into a vertex tensor.
[0017] In a specific implementation of the present invention, it also includes: obtaining the graph semantics of the corresponding tensor shape based on the tensor type related to the basic graph operator, and estimating the computational overhead based on the graph semantics; wherein the fixed-point tensor and the edge tensor are marked with different dimension marking symbols.
[0018] In a specific embodiment of the present invention, the computational graph segmentation of the optimized output of the first level includes: generating all different valid computational graph transformation output versions for the input graph neural network model; outputting the optimal candidate output by comparing the computational amount between different versions; and performing computational graph segmentation on the optimal candidate output of the first level.
[0019] In a specific embodiment of the present invention, the graph-aware nested loop body includes: a vertex graph-aware nested loop body in which each loop element has graph voice information of a vertex and an edge graph-aware nested loop body in which each loop element has graph voice information of an edge.
[0020] In a specific embodiment of the present invention, the optimization of the second-level intermediate representation of the graph neural network model based on the segmentation-based computational graph and graph-aware nested loop body includes: constructing graph traversal-related primitives for scheduling transformations of basic graph operators and operator fusion-related primitives for fusing the graph-aware nested loop bodies.
[0021] In a specific implementation of the present invention, it also includes: dividing the first-level intermediate representation into horizontal partitions and vertical partitions; in the vertical partitions, using a scatter operation as a starting boundary and ending at the next scatter operation or a node with dependencies and multiple outputs; in the horizontal partitions, merging graph element operations with the same computational shape at the thread level.
[0022] In order to achieve the above-mentioned purpose and other related purposes, the present invention also provides a computer storage medium storing program instructions, wherein the program instructions, when executed, implement the steps of the compilation optimization method of the graph neural network model as described above.
[0023] In order to achieve the above-mentioned purpose and other related purposes, the present invention also provides a compiler, which uses the compilation optimization method of the graph neural network model as described above for compilation.
[0024] As described above, the compilation optimization method, compiler and storage medium of the graph neural network model of the present invention have the following beneficial effects:
[0025] The present invention realizes the compilation optimization of the adaptive automatic generation of the dynamic code program of the operator. The compiler provided by the present invention can not only realize the compilation optimization based on the model level and the operator level, but also adopts a new intermediate representation method to make the optimization effect more significant. Under the premise of ensuring computational equivalence, the present invention can greatly improve the computing performance of the GNN model. Provide high-performance computing support for the wide application of the GNN model. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0027] Figure 1 A flowchart showing the computational principle of the graph neural network model.
[0028] Figure 2 Shown is a flowchart of a compilation optimization method for a graph neural network model in one embodiment of the present application.
[0029] Figure 3 Shown is the computational graph transformation of the GIN model in the compilation optimization method of the graph neural network model in one embodiment of the present application.
[0030] Figure 4 Shown is a schematic diagram of the graph traversal mode and supported primitives in the compilation optimization method of the graph neural network model in one embodiment of the present application.
[0031] Figure 5 Shown is a schematic diagram of operator fusion primitives in the compilation optimization method of the graph neural network model in one embodiment of the present application.
[0032] Figure 6 Shown is a schematic diagram of the execution logic of the compilation optimization method of the graph neural network model in one embodiment of the present application. DETAILED DESCRIPTION
[0033] The following describes the implementation of this embodiment through specific examples, and those skilled in the art can easily understand other advantages and effects of this embodiment from the content disclosed in this specification. This embodiment can also be implemented or applied through other different specific implementations, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of this embodiment. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.
[0034] As GNN models become more and more complex, how to efficiently execute GNN models has become a task that has attracted much attention. However, the current technical solutions for GNN compilation optimization have many limitations and cannot achieve complete compilation optimization, which has caused serious obstacles to the widespread application and deployment of models. This embodiment aims to propose an end-to-end high-performance GNN compiler that can achieve complete joint optimization of the operator layer and the model layer, thereby achieving high-performance execution of the GNN model.
[0035] The purpose of this embodiment is to provide a compilation optimization method, compiler and storage medium for a graph neural network model, which realizes editable shapes of specific organs and lesions, while retaining the complex image background of the original medical images, further enhancing the diversity and authenticity of medical images.
[0036] The following will explain in detail the principles and implementation methods of the compilation optimization method, compiler and storage medium of the graph neural network model of this embodiment, so that those skilled in the art can understand the compilation optimization method, compiler and storage medium of the graph neural network model of this embodiment without creative labor.
[0037] This embodiment provides a compilation optimization method for a graph neural network model. Figure 2 The flowchart of the compilation optimization method of the graph neural network model in one embodiment of the present application is shown. Specifically, Figure 2 As shown, the compilation optimization method of the graph neural network model includes the following steps S100 to S300.
[0038] Step S100, obtaining an input graph neural network model, and optimizing the first-level intermediate representation of the graph neural network model by configuring a computational graph rewriting rule and graph-level semantics of tensors;
[0039] Step S200, performing computation graph segmentation on the optimization output of the first level;
[0040] Step S300, optimizing the second-level intermediate representation of the graph neural network model based on the segmented computational graph and the graph-aware nested loop body.
[0041] The following is a detailed description of the compilation optimization method of the graph neural network model of this embodiment.
[0042] Step S100, obtain the input graph neural network model, and optimize the first-level intermediate representation of the graph neural network model by configuring the computational graph rewriting rules and the graph-level semantics of the tensor.
[0043] In this embodiment, the first-level intermediate representation is a high-level intermediate representation of the graph neural network model.
[0044] In a specific implementation, the optimization of the first-level intermediate representation of the graph neural network model by configuring computational graph rewriting rules includes: decomposing the composite graph operators of the graph neural network model into basic graph operators and neural network operators, and configuring rewriting rules for the basic graph operators.
[0045] In the embodiment, the design of mainstream deep neural network compilers is followed, and computational graphs are used as abstract representations of the model level. The existing high-level intermediate representation is extended by fusing basic graph operations and graph-related data attributes, thereby extending the representation of computational graphs to all operators in the GNN model, including graph operators (GOPs) and traditional neural network operators (NN-ops).
[0046] This embodiment first explores the model-level compilation optimization of the computational graph rewriting of the GNN model. Since the high-level intermediate representation has a wider optimization range, it also leads to the generation of a more complex optimization space. Most of the prior art uses pattern matching technology to implement computational graph rewriting. However, the existing GNN framework defines hundreds of graph operators. Simply applying pattern matching technology will require defining thousands of matching rules, which will be a significant burden and therefore not scalable.
[0047] In order to reduce the burden caused by too many rewrite rules, the compilation optimization method of this embodiment proposes to decompose the existing composite graph operators into basic GOPs and NN-ops. A front-end parser is built to map all composite graph operators to these basic operations, and summarize all the rewrite rules required in the GNN model in Table 1. In this way, it is only necessary to define rewrite rules for these basic GOPs. In fact, in the GNN model studied in the work, the first four rules in Table 1 are sufficient. The remaining four rules directly follow the NN-related rewrite rules in previous DNN compiler work. By reducing the number of graph operators from thousands to single digits, the complexity of the computational graph rewrite pattern is greatly simplified.
[0048] Table 1 Computational graph rewriting rules
[0049]
[0050] In a specific implementation, optimizing the first-level intermediate representation of the graph neural network model through the graph-level semantics of tensors includes: using the scatter function (scatter) and gather function (gather) of the basic graph operator to establish relevant attribute propagation rules of the basic graph operator; wherein the scatter function converts the vertex tensor into an edge tensor, and the gather function converts the edge tensor into a vertex tensor.
[0051] Without complete information about the shape of the tensor, it is difficult to determine whether rewriting the computational graph IR is beneficial (i.e., whether the overall computational overhead is reduced). To solve this problem, this embodiment proposes to use graph-related semantic properties in high-level intermediate representations to compare computational overhead before and after applying the rewrite rules. This embodiment extends the graph-level semantics of each tensor in the GNN model, which can be associated with vertices or edges. This embodiment calls the former a vertex tensor because each vertex in the graph has its own embedding vector; similarly, this embodiment calls the latter an edge tensor because each edge has its own embedding vector. This embodiment uses scatter and gather in basic GOPs to establish graph-related attribute propagation rules. Specifically, scatter converts vertex tensors into edge tensors, while gather does the opposite. The remaining NN-ops do not change the tensor type in this attribute propagation.
[0052] In an embodiment, it also includes: obtaining the graph semantics of the corresponding tensor shape based on the tensor type related to the basic graph operator, and estimating the computational overhead based on the graph semantics; wherein the fixed-point tensor and the edge tensor are marked with different dimension marking symbols.
[0053] By inferring the graph-related tensor types, the present embodiment can further infer the graph semantics of the tensor shape and use it to estimate the computational overhead. The key to estimating the computational overhead is to use special placeholders related to the graph to mark unknown shape parameters. Specifically, for vertex tensors, this embodiment marks the first-dimensional shape as 'V', and for edge tensors, this embodiment marks the first-dimensional shape as 'E'. The remaining dimensions are marked as 'F'. The present embodiment uses a well-known property, that is, the vertex count in the graph is always much smaller than the edge count, to estimate and compare the computational overhead of applying different high-level intermediate representation rewrite rules. Through the above-mentioned high-level graph-aware intermediate representation and graph-related properties, the compiler of the present embodiment can use pre-defined enrichment rules to automatically generate an optimized version of the high-level intermediate representation of the given GNN model.
[0054] Step S200, performing computation graph segmentation on the optimization output of the first level.
[0055] In this embodiment, the computational graph segmentation of the optimized output of the first level includes: generating all different valid computational graph transformation output versions for the input graph neural network model; outputting the optimal candidate output by comparing the computational amount between different versions; and performing computational graph segmentation on the optimal candidate output of the first level.
[0056] This embodiment takes the GIN model as an example to specifically illustrate these processes. Figure 3 The sliced subgraph of the GIN high-level intermediate representation consisting of two GOPs and three NN-ops is shown, and the process of applying rules to the subgraph for computational graph rewriting in this embodiment is shown. This embodiment first uses all rewriting rules and the BFS algorithm to generate all different valid computational graph transformation output versions for the input model. By comparing the computational amount between different versions, the optimal candidate output is finally saved.
[0057] Step S300, optimizing the second-level intermediate representation of the graph neural network model based on the segmented computational graph and the graph-aware nested loop body.
[0058] In this embodiment, the second-level intermediate representation is a low-level intermediate representation of the graph neural network model.
[0059] In order to meet the challenges of high-performance code generation for diverse input graph topologies, this embodiment designs a low-level intermediate representation. Based on this low-level intermediate representation, this embodiment can explore opportunities for compilation optimization of complex operator fusions and build a complete systematic code generation scheduling space for single operators and fused operators.
[0060] Specifically, this embodiment uses a graph-aware nested loop body as a low-level intermediate representation. This embodiment refers to the traditional dense loop as an NN-Loop, which iterates within a fixed size range, and the loop iteration index can be used as an address. This abstraction is commonly used for NN-ops similar to matmul and conv operators. However, operator operations related to graph traversal cannot be represented using NN-loop because they involve irregular and indirect addressing processes related to the graph structure.
[0061] In order to overcome the limitations of traditional loop abstraction, in this embodiment, the graph-aware nested loop body includes: a vertex graph-aware nested loop body (V-Loop) in which each loop element has the graph voice information of the vertex and an edge graph-aware nested loop body (E-Loop) in which each loop element has the graph voice information of the edge.
[0062] This embodiment proposes a design for expressing abstractions of V-Loop and E-Loop. This embodiment uses a loop body containing graph semantics to represent memory access and computation information within GOPs. Specifically, the traversal associated with the V-Loop occurs on a set of vertices, where each V-loop element has graph semantic information of the vertex. The V-loop element vertex has the ability to be used as an index value like the NN-Loop, except for the set of in-edges and out-edges of the vertex based on the graph structure. At the same time, this embodiment defines E-Loop to represent the traversal process of the edge. Each loop element of the E-Loop has the graph semantic information of the edge and can access its source vertex and target vertex.
[0063] Based on the abstract representation of V-Loop and E-Loop designed above, this embodiment further proposes a series of conversion primitives for low-level intermediate representation. These primitives help to generate efficient executable programs corresponding to GNN operators. The design of these primitives is inspired by the NN-Loop conversion primitives used in Halide and TVM. This embodiment extends these conversions to V-loop and E-loop for graph topology, and constructs a comprehensive and systematic code generation scheduling space for operators of GNN models.
[0064] That is, in a specific implementation, the optimization of the second-level intermediate representation of the graph neural network model based on the segmentation-based computational graph and graph-aware nested loop body includes: constructing graph traversal-related primitives for scheduling transformations of basic graph operators and operator fusion-related primitives for fusing the graph-aware nested loop bodies.
[0065] The graph traversal related primitives implement scheduling transformations for GOPs. These primitives help users implement different graph traversal modes with different parallelism and locality tradeoffs. Figure 4 Three typical graph traversal modes are shown. The basic strategy space of this embodiment starts from Dst-major centered on the target vertex set, Src-major centered on the source vertex set, and E-major centered on the edge set.
[0066] This embodiment proposes three primitives VE-Reorder, VE-Fuse and E-Split to achieve the conversion between these traversal modes. For example, this embodiment can use the VE-Fuse primitive to traverse the Dst-major or Src-major graph into a loop mode.
[0067] The execution performance of many GNN operators is limited by memory access, so operator fusion implemented by operator fusion related primitives can potentially improve their performance. Since each nested loop group corresponds to a kernel function code, this embodiment proposes two basic operations Group-Fuse and Group-Split to fuse or split two loop groups. This embodiment uses Figure 5 The examples in are used to illustrate their specific working modes. The left side includes two nested loop groups for gather and matmul operations, and this embodiment generates a kernel function for each operation. It should be noted that the matmul operation represented in the V-Loop form shares the outermost loop with the gather operation. This embodiment can use the Group-Fuse basic operation to fuse them into the representation on the right. The fused operation is still in the V / E-Loop form, so this embodiment can still use other scheduling basic operations to explore the scheduling space. It should be noted that not all adjacent nested loop groups can be fused. This embodiment performs basic operations while ensuring parallelism and data communication legitimacy. Based on the relevant primitives of the low-level abstraction level proposed above in this embodiment, this embodiment can obtain different scheduling strategies for GNN.
[0068] In a specific implementation, it also includes: dividing the first-level intermediate representation into horizontal partitions and vertical partitions; in the vertical partitions, using the scatter operation as the starting boundary and ending at the next scatter operation or a node with dependencies and multiple outputs; in the horizontal partitions, merging graph element operations with the same computational shape at the thread level.
[0069] That is, the compiler of this embodiment provides an end-to-end automated solution for the GNN model, aiming to provide an execution version with the best GNN performance for the input of the GNN model.
[0070] This embodiment first implements a high-level intermediate representation on top of the standard ONNX format. ONNX is a format designed for exchanging DNN models between different frameworks and tools. This embodiment is currently implementing a front-end parser that supports converting the PyTorch-based DGL framework into the extended ONNX high-level IR of this embodiment. It is worth noting that the method of this embodiment can also be extended to other GNN frameworks. By using a mature and widely adopted framework such as DGL, this embodiment can more easily demonstrate the capabilities of the method of this embodiment and highlight its potential in practical applications.
[0071] In order to obtain the low-level intermediate representation, the present embodiment must first determine the scope of the reduction from the high-level intermediate representation. The present embodiment uses the low-level intermediate representation to construct the search space for the execution strategy. A large search space may hinder the search time and the acquisition of subsequent candidate versions. Therefore, the present embodiment implements the partitioning of the high-level intermediate representation as an initial step.
[0072] This embodiment designs a set of heuristic rules for high-level partitioning. This embodiment divides partitions into two categories based on topological dependencies: vertical and horizontal. For vertical partitioning, this embodiment uses the scatter operation as the starting boundary and ends at the next scatter operation or a node with complex consumer dependencies and multiple outputs. This is because the scatter operation performs global data communication based on the topological structure of the input graph, making it impossible to reason about the input source range of a specific output. For horizontal partitioning, this embodiment merges element-by-element operations with the same computational shape at the thread level. Other cases are merged at the thread block level. This approach enables this embodiment to better utilize hardware resources. After partitioning the high-level intermediate representation, this embodiment uses TVM to implement the low-level intermediate representation of this embodiment. Since this embodiment only has basic graphic operators scatter and gather in the final high-level intermediate representation, this embodiment implements the default reduced-order templates of these operators based on the existing NN operator mapping. This embodiment follows the default mapping rules in the TVM Operator Inventory (TOPI) to process other NN operators (such as relu).
[0073] After successfully implementing the expression of the low-level intermediate representation and specifying the corresponding conversion primitives, this embodiment implements operator code generation and further performance optimization. Specifically, the compiler of this embodiment provides a comprehensive scheduling space for operator execution to exploit the parallelism of the GPU, which can generally be organized into three levels of execution: collaborative thread group (CTA), thread bundle (warp) and thread. CTA is a group of threads that execute instructions as a unit on a single stream multiprocessor (SM) and communicate through shared memory. In a CTA, 32 thread warps execute simultaneously. Each thread is executed independently with its own program counter and registers. The binding between loops and iterations determines the parallel execution scheduling of operations. This embodiment uses the "bind" primitive with the "thread", "warp" or "CTA" parameters to implement the parallelization strategy space corresponding to the loop body and the hardware mapping. This embodiment implements the serialization strategy of the time dimension by using the thread traversal mapping of the loop body. At the same time, this embodiment further improves performance by performing additional optimizations to improve computing and memory access performance. The core design of this embodiment is to determine the locality of data use. For data that implements intra-thread and intra-CTA repetitions, this embodiment automatically uses registers or shared memory as temporary read / write buffers. After implementing these optimizations, this embodiment generates CUDA code based on the low-level intermediate representation and calls a dedicated backend compiler to compile it into a shared library that can be dynamically loaded for execution.
[0074] The execution logic of the compilation optimization method of the graph neural network model of this embodiment is as follows Figure 6 shown.
[0075] 1) Model input: The user provides the GNN model to be optimized.
[0076] 2) High-level intermediate representation optimizer: implements high-level model representation, opens composite graph operators, rewrites and prunes computational graphs, and retains high-performance computational graph candidate versions.
[0077] 3) High-level intermediate representation splitter: splits the computational graph based on the output of the high-level optimizer.
[0078] 4) Low-level intermediate representation optimizer: Based on the output of the segmenter, the low-level intermediate representation is optimized to obtain the final execution code output.
[0079] As can be seen from the above, in view of the computational complexity of the GNN model, the present invention proposes a high-performance computing compiler for GNN computing tasks, which can realize complete compilation optimization including the model layer and the operator layer. A new type of multi-level intermediate representation for the GNN model is proposed in the present invention. The high-level intermediate representation is used to realize the expression abstraction of the model layer, and based on the abstraction, the present invention realizes the compilation optimization of the model layer including the computational graph rewriting and operator fusion for the GNN model. The low-level intermediate representation is used to realize the expression abstraction of the operator layer, and based on the abstraction, the present invention realizes the compilation optimization of the dynamic code program adaptively and automatically generated by the operator. Compared with the prior art, the compiler provided by the present invention can not only realize the compilation optimization based on the model layer and the operator layer, but also adopts a new intermediate representation method, so that the optimization effect is more significant. Under the premise of ensuring computational equivalence, the present invention can greatly improve the computing performance of GNN. Provide high-performance computing support for the wide application of GNN models.
[0080] This embodiment provides a compiler, which applies the compilation optimization method of the graph neural network model as described above for compilation.
[0081] In addition, this embodiment also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps in the compilation optimization method of the graph neural network model described above are implemented. The compilation optimization method of the graph neural network model has been described in detail above and will not be repeated here.
[0082] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to the computer program. The aforementioned computer program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes.
[0083] In summary, the present invention realizes the compilation optimization of the adaptive automatic generation of the dynamic code program of the operator. The compiler provided by the present invention can not only realize the compilation optimization based on the model level and the operator level, but also adopts a new intermediate representation method, so that the optimization effect is more significant. Under the premise of ensuring computational equivalence, the present invention can greatly improve the computing performance of the GNN model. Provide high-performance computing support for the wide application based on the GNN model. Therefore, the present invention effectively overcomes the various shortcomings in the prior art and has a high industrial utilization value.
[0084] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical ideas disclosed by the present invention shall still be covered by the claims of the present invention.
Claims
1. A compilation optimization method for a graph neural network model, characterized in that: include: Obtain an input graph neural network model, and optimize the first-level intermediate representation of the graph neural network model by configuring computational graph rewriting rules and graph-level semantics of tensors; Performing computational graph segmentation on the optimization output of the first level; The second-level intermediate representation of the graph neural network model is optimized based on the segmented computational graph and graph-aware nested loop body.
2. The compilation optimization method of the graph neural network model according to claim 1, characterized in that: The optimization of the first-level intermediate representation of the graph neural network model by configuring computational graph rewriting rules includes: decomposing the composite graph operators of the graph neural network model into basic graph operators and neural network operators, and configuring rewriting rules for the basic graph operators.
3. The compilation optimization method of the graph neural network model according to claim 2 is characterized in that: Optimizing the first-level intermediate representation of the graph neural network model through the graph-level semantics of tensors includes: The related attribute propagation rules of the basic graph operator are established using the scatter function and the gather function of the basic graph operator; wherein the scatter function converts the vertex tensor into the edge tensor, and the gather function converts the edge tensor into the vertex tensor.
4. The compilation optimization method of the graph neural network model according to claim 3 is characterized in that: Also includes: Based on the tensor type related to the basic graph operator, the graph semantics of the corresponding tensor shape is obtained, and the computational overhead is estimated based on the graph semantics; wherein the fixed-point tensor and the edge tensor are marked with different dimension marking symbols.
5. The compilation optimization method of the graph neural network model according to claim 1, characterized in that: The step of dividing the calculation graph of the optimization output of the first level includes: Generate all different valid computational graph transformation output versions for the input graph neural network model; By comparing the computational effort between different versions, the optimal candidate output is output; The computation graph is segmented for the optimal candidate output of the first level.
6. The compilation optimization method of the graph neural network model according to claim 2, characterized in that: The graph-aware nested loop body includes: a vertex graph-aware nested loop body in which each loop element has graph voice information of a vertex and an edge graph-aware nested loop body in which each loop element has graph voice information of an edge.
7. The compilation optimization method of the graph neural network model according to claim 6 is characterized in that: The optimization of the second-level intermediate representation of the graph neural network model based on the segmented computational graph and the graph-aware nested loop body includes: Graph traversal related primitives for scheduling transformation of basic graph operators and operator fusion related primitives for the graph-aware nested loop body fusion are constructed.
8. The compilation optimization method of the graph neural network model according to claim 1, characterized in that: Also includes: The first-level intermediate representation is divided into horizontal partitions and vertical partitions; in the vertical partitions, a scatter operation is used as a starting boundary and ends at the next scatter operation or a node with dependencies and multiple outputs; in the horizontal partitions, graph element operations with the same computational shape are merged at the thread level.
9. A computer storage medium storing program instructions, wherein: When the program instructions are executed, the steps of the compilation optimization method of the graph neural network model as described in any one of claims 1 to 8 are implemented.
10. A compiler, characterized in that: Compilation is performed using the compilation optimization method of the graph neural network model as described in any one of claims 1 to 8.
Citation Information
Cited By
Compiling method and system for near storage computing architecture, electronic equipment and storage medium
CN120144134A
