Deep learning compilation optimization method and device, electronic equipment and storage medium

Through the combination of the deep learning framework and the microkernel library, the problem of low development efficiency and long compilation time of the deep learning compiler when processing long-tail operators is solved, and efficient programming and computing performance is achieved, taking into account flexibility and efficiency.

CN118780351APending Publication Date: 2024-10-15北京辉羲智能科技有限公司
View PDF 0 Cites 5 Cited by

Patent Information

Application Number
CN202410768426.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-14
Publication Date
2024-10-15

AI Technical Summary

Technical Problem

When the deep learning compiler handles long-tail operators, developers need to manually optimize the operator library, resulting in low development efficiency, inability to balance flexibility and performance, and high compilation time overhead.

Method used

Express the deep neural network as a calculation graph through the deep learning framework, convert it into an intermediate layer, mark the operators that need to be compiled for clustering, generate fusion operators, use the microkernel library to compile online to generate kernel code, optimize the loop intermediate representation layer and Convert to vectorized instruction sequence.

Benefits of technology

It improves development efficiency, reduces compilation time overhead, and takes into account programming flexibility and computing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118780351A_ABST
    Figure CN118780351A_ABST
Patent Text Reader

Abstract

The invention provides a deep learning compilation optimization method and device, electronic equipment and a storage medium, and the method comprises the steps: expressing a deep neural network as a computational graph through a deep learning framework, and converting the computational graph into a middle layer between the deep learning framework and a deep learning compiler; marking operators needing to be compiled in the middle layer, and clustering the marked operators into a plurality of sub-graphs; the sub-graph comprises at least one fusion operator, and the fusion operator is obtained by fusing a plurality of marked operators; compiling the fusion operator on line through a deep learning compiler, and generating a kernel code of the fusion operator; the online compilation comprises the step of converting the innermost loop code into a calling code of the microkernel based on the microkernel library. According to the method, the flexibility of programming and the high efficiency of calculation can be considered, the development efficiency is improved, the problem of large code generation search space is solved, and the compiling time overhead is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a deep learning compilation optimization method, device, electronic device and storage medium. Background Art

[0002] In recent years, deep neural networks have been widely used in natural language processing, speech recognition, image recognition, autonomous driving, industrial robots, etc. With the continuous development and innovation in the field of artificial intelligence, various computing devices have emerged, and the requirements for the adaptability of deep learning frameworks / compilers have become increasingly higher.

[0003] Currently, for long-tail operators, deep learning compilers can replace pure manual optimization through automatic or semi-automatic code generation. However, deep learning compilers still use handwritten operator libraries, which often rely on deep manual optimization by domain experts. Developers must understand the operator calculation logic and be familiar with the hardware architecture and instruction set, resulting in low development efficiency and failure to resolve the contradiction between flexibility and performance.

[0004] As a new framework for building reusable and extensible compilers, Multi Level Intermediate Representation (MLIR) is very suitable for developing compilers for new hardware because it can reuse a lot of community infrastructure and design new dialects to solve problems encountered under specific architectures, abstracting at different levels until they are converted into instructions on the back-end hardware. However, due to the constraints of the back-end instruction set and the diversity of the front-end computational graph, the search space for compiling and generating kernel code is very large, resulting in high compilation time overhead. Summary of the invention

[0005] The present invention provides a deep learning compilation optimization method, device, electronic device and storage medium, which are used to achieve both programming flexibility and computing efficiency, improve development efficiency, improve the problem of large code generation search space, and reduce compilation time overhead.

[0006] The present invention provides a deep learning compilation optimization method, comprising: Expressing a deep neural network as a computational graph through a deep learning framework, and converting the computational graph into an intermediate layer between the deep learning framework and a deep learning compiler; Marking the operators that need to be compiled in the intermediate layer, and clustering the marked operators into multiple subgraphs; the subgraphs include at least one fusion operator, and the fusion operator is obtained by fusion of multiple marked operators; The fusion operator is compiled online by the deep learning compiler to generate the kernel code of the fusion operator; the online compilation includes converting the innermost loop code into a calling code of the microkernel based on the microkernel library.

[0007] According to a deep learning compilation optimization method provided by the present invention, the online compilation of the fusion operator by the deep learning compiler to generate the kernel code of the fusion operator includes: The following steps are performed by the deep learning compiler: Converting the fusion operator into a loop intermediate representation layer; the loop intermediate representation layer is an intermediate representation layer in a nested perfect loop format or a non-perfect loop format; When the loop intermediate representation layer needs to be optimized, optimizing the loop intermediate representation layer; Converting the optimized loop intermediate representation layer into a vectorized instruction sequence adapted to the back-end hardware; Based on the microkernel library, the innermost loop code of the vectorized instruction sequence is converted into a calling code of the microkernel, and the other parts are converted into inline functions predefined by the backend hardware; The converted vectorized instruction sequence is translated into the underlying virtual machine dialect, and a backend compilation tool is called to compile the underlying virtual machine dialect into a binary code supported by the backend as the kernel code of the fusion operator.

[0008] According to a deep learning compilation optimization method provided by the present invention, the converting of the fusion operator into a loop intermediate representation layer includes: Determining whether the fusion operator is a structured operator; In the case where the fusion operator is a structured operator, converting the fusion operator into a linear algebra dialect; Converting the core operator represented by the linear algebra dialect into an intermediate representation layer of the nested perfect loop format; In the case where the fused operator is an unstructured operator, the fused operator is converted into a mixed intermediate representation layer of cyclic and affine transformations as the intermediate representation layer of the non-perfect cyclic format.

[0009] According to a deep learning compilation optimization method provided by the present invention, when the loop intermediate representation layer needs to be optimized, optimizing the loop intermediate representation layer includes: In the case where the loop intermediate representation layer needs to be optimized, determining a target optimization method from optimization methods based on loop fusion, loop order rearrangement, and loop slicing; The target optimization method is used to optimize the cyclic intermediate representation layer.

[0010] According to a deep learning compilation optimization method provided by the present invention, based on the microkernel library, converting the innermost loop code of the vectorized instruction sequence into a calling code of the microkernel includes: For a first operator in the fused operator, based on the microkernel library, converting the innermost loop code of the vectorized instruction sequence corresponding to the first operator into a calling code of the microkernel; For the second operator in the fused operator, the output result of the calling code of the microkernel is used as the input data of the second operator to obtain the calling code of the fused microkernel.

[0011] According to a deep learning compilation optimization method provided by the present invention, based on the microkernel library, converting the innermost loop code of the vectorized instruction sequence corresponding to the first operator into a calling code of the microkernel includes: For each tile size, obtaining a microkernel corresponding to the tile size based on the microkernel library; When the length of the vectorized instruction sequence corresponding to the first operator is divisible by the vectorization length in the backend hardware architecture, selecting a microkernel with the highest performance from a plurality of microkernels corresponding to the plurality of tile sizes; According to the sub-tile size supported by the microkernel with the highest performance, the innermost loop code of the vectorized instruction sequence corresponding to the first operator is converted into the calling code of the microkernel with the highest performance.

[0012] According to a deep learning compilation optimization method provided by the present invention, based on the microkernel library, converting the innermost loop code of the vectorized instruction sequence corresponding to the first operator into a calling code of the microkernel includes: For each tile size, obtaining a microkernel corresponding to the tile size based on the microkernel library; When the length of the vectorized instruction sequence corresponding to the first operator cannot be divided by the vectorization length in the backend hardware architecture, the vectorized instruction sequence corresponding to the first operator is loop-split to obtain an aligned first loop processing logic code and a non-aligned second loop processing logic code; Selecting a first microkernel corresponding to the aligned first loop processing logic code and a second microkernel corresponding to the unaligned second loop processing logic code from a plurality of microkernels corresponding to the plurality of tile sizes; According to the sub-tile size supported by the first microkernel, converting the aligned first loop processing logic code into a calling code of the first microkernel; According to the sub-tile size supported by the second microkernel, converting the non-aligned second loop processing logic code into a calling code of the second microkernel; The step of using the output result of the calling code of the microkernel as the input data of the second operator to obtain the calling code of the fused microkernel includes: Using the output result of the calling code of the first microkernel as input data of the second operator to obtain the fused calling code of the first microkernel; The output result of the calling code of the second microkernel is used as input data of the second operator to obtain the fused calling code of the second microkernel.

[0013] The present invention also provides a deep learning compilation optimization device, comprising: A conversion module, used to express a deep neural network as a computational graph through a deep learning framework, and convert the computational graph into an intermediate layer between the deep learning framework and a deep learning compiler; A clustering module, used for marking operators that need to be compiled in the intermediate layer, and clustering the marked operators into multiple subgraphs; the subgraphs include at least one fusion operator, and the fusion operator is obtained by fusion of multiple marked operators; A compilation module is used to compile the fusion operator online through the deep learning compiler to generate the kernel code of the fusion operator; the online compilation includes converting the innermost loop code into the calling code of the microkernel based on the microkernel library.

[0014] 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, the steps of the deep learning compilation optimization method as described in any one of the above are implemented.

[0015] 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 the steps of any of the deep learning compilation optimization methods described above.

[0016] The deep learning compilation optimization method, device, electronic device and storage medium provided by the present invention firstly express the deep neural network as a calculation graph through the deep learning framework, and convert the calculation graph into an intermediate layer between the deep learning framework and the deep learning compiler; then, mark the operators that need to be compiled in the intermediate layer, and cluster the marked operators into multiple subgraphs; the subgraphs include at least one fusion operator, which is obtained by fusion of multiple marked operators; finally, the fusion operator is compiled online by the deep learning compiler to generate the kernel code of the fusion operator; the online compilation includes converting the innermost loop code into the calling code of the microkernel based on the microkernel library. The present invention takes into account the respective advantages of the deep learning compiler and the microkernel library, can take into account the flexibility of programming and the efficiency of calculation, improve development efficiency, and improve the problem of large code generation search space, and reduce compilation time overhead. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] 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.

[0018] Figure 1 It is a flowchart of the deep learning compilation optimization method provided by an embodiment of the present invention.

[0019] Figure 2 It is a schematic diagram of the subgraph construction process provided by an embodiment of the present invention.

[0020] Figure 3 It is a schematic diagram of compiling and calling a single microkernel provided by an embodiment of the present invention.

[0021] Figure 4 It is a schematic diagram of the compilation and calling microkernel combination provided by an embodiment of the present invention.

[0022] Figure 5 It is a schematic diagram of implementing operator fusion by using a microkernel combination provided in an embodiment of the present invention.

[0023] Figure 6 It is a structural diagram of a deep learning compilation optimization device provided by an embodiment of the present invention.

[0024] Figure 7 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0025] 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.

[0026] Combine the following Figures 1 to 5 The deep learning compilation optimization method of the present invention is described.

[0027] Please refer to Figure 1 , Figure 1 Schematic diagram of the process of deep learning compilation optimization method provided by the embodiment of the present invention. Figure 1 As shown, the method may include the following steps 101-103.

[0028] Step 101: Express the deep neural network as a computational graph through a deep learning framework, and convert the computational graph into an intermediate layer between the deep learning framework and the deep learning compiler.

[0029] Specifically, a neural network can be composed of neural units, which can be understood as a neural network with an input layer, a hidden layer, and an output layer. Generally speaking, the first layer is the input layer, the last layer is the output layer, and the layers in between are all hidden layers. Among them, a neural network with many hidden layers is called a deep neural network (DNN).

[0030] A computational graph is a general method for representing computational processes. It is a directed acyclic graph used to describe functions and is widely used on various data processing platforms. A computational graph consists of multiple nodes and directed edges.

[0031] The deep learning framework expresses the deep neural network as a computational graph, where each node in the computational graph represents the corresponding operation performed by the deep neural network (e.g., the add node represents an addition operation). The corresponding operation can also be called a computational task. The direction of the arrows of the directed edges in the computational graph represents the flow of data. The directed edge with an arrow connects the previous node (which can be called the previous node or parent node) to the next node (which can be called the next node or child node), indicating that the output of the parent node serves as the input of the child node.

[0032] Convert the computational graph to MHLO (Meta HLO Dialect), which represents the middle layer between the deep learning framework and the deep learning compiler.

[0033] Step 102: Mark the operators that need to be compiled in the middle layer, and cluster the marked operators into multiple subgraphs; the subgraphs include at least one fusion operator, and the fusion operator is obtained by fusion of multiple marked operators.

[0034] For example, Figure 2 As shown in the figure, assume that the user-defined operator fusion rule is to fuse the gather operator and the subsequent element-wise operator, and the shape of the indice operand of the gather operator is not 16-byte aligned. The element-wise operator is used to perform element-by-element operations on two arrays of the same shape, such as addition, subtraction, multiplication, division, maximum value, minimum value, etc. Then, according to the user-defined operator fusion rule, the gather operator, sub operator, and div operator will be marked, and the three marked operators will be fused into a fused operator, and this fused operator will be used as a subgraph (cluster0).

[0035] The gather(input, indice, dim=0) operator has two input operands. The rank and shape of these two input operands can theoretically be of any dimension. Taking 2D input and output as an example, the calculation formula of the gather operator is: output[i][j][k]=input[indice[i][j]][k]#dim=0.

[0036] It should be noted that, in a specific implementation, the number of fusion operators in a subgraph is greater than or equal to 1, and the number of operators in a fusion operator is greater than or equal to 2.

[0037] Specific subgraphs are generated by clustering according to user-defined operator fusion rules, supporting more long-tail operator combinations.

[0038] Step 103: compile the fusion operator online through the deep learning compiler to generate the kernel code of the fusion operator; the online compilation includes converting the innermost loop code into the calling code of the microkernel based on the microkernel library.

[0039] Specifically, by taking into account the respective advantages of the deep learning compiler and the microkernel library, the fixed code generation process is offloaded to the micro kernel, which greatly reduces the compilation complexity. It can take into account both programming flexibility and computing efficiency, improve development efficiency, improve the problem of large code generation search space, and reduce compilation time overhead.

[0040] The deep learning compilation optimization method provided by the embodiment of the present invention firstly expresses the deep neural network as a computational graph through the deep learning framework, and converts the computational graph into an intermediate layer between the deep learning framework and the deep learning compiler; then, marks the operators that need to be compiled in the intermediate layer, and clusters the marked operators into multiple subgraphs; the subgraphs include at least one fusion operator, which is obtained by fusion of multiple marked operators; finally, the fusion operator is compiled online by the deep learning compiler to generate the kernel code of the fusion operator; the online compilation includes converting the innermost loop code into the calling code of the microkernel based on the microkernel library. The embodiment of the present invention takes into account the respective advantages of the deep learning compiler and the microkernel library, and can take into account the flexibility of programming and the high efficiency of calculation, improve development efficiency, and improve the problem of large code generation search space, and reduce compilation time overhead.

[0041] In one embodiment, step 103 includes executing the following steps by a deep learning compiler: Step 1031: Convert the fusion operator into a loop intermediate representation (IR) layer; the loop intermediate representation layer is an intermediate representation layer in a nested perfect loop format or a non-perfect loop format.

[0042] Optionally, step 1031 includes: determining whether the fusion operator is a structured operator; if the fusion operator is a structured operator, converting the fusion operator into a linear algebra dialect (linalg dialect); converting the core operator represented by the linear algebra dialect (for example: linalg.generic) into an intermediate representation layer in a nested perfect loop format; if the fusion operator is an unstructured operator, converting the fusion operator into a mixed intermediate representation layer of loop and affine transformation, as an intermediate representation layer in a non-perfect loop format, can prepare for further lowering.

[0043] Step 1032: When the loop intermediate representation layer needs to be optimized, optimize the loop intermediate representation layer.

[0044] Optionally, step 1032 includes: when the loop intermediate representation layer needs to be optimized, determining a target optimization method from optimization methods such as loop-based fusion, loop order rearrangement, and loop-based slicing, and optimizing the loop intermediate representation layer using the target optimization method. When the loop intermediate representation layer does not need to be optimized, no optimization is performed on the loop intermediate representation layer.

[0045] Step 1033: Convert the optimized loop intermediate representation layer into a vectorized instruction sequence adapted to the backend hardware.

[0046] Optionally, the backend hardware may include a neural network processor (NPU), a CPU, a graphics processor (GPU), etc.

[0047] Step 1034: Based on the microkernel library, the innermost loop code of the vectorized instruction sequence is converted into the calling code of the microkernel, and the other parts are converted into inline functions predefined by the backend hardware.

[0048] Step 1035: translate the converted vectorized instruction sequence into the underlying virtual machine dialect (LLVM Dialect), and call the backend compilation tool to compile the underlying virtual machine dialect into binary code supported by the backend as the kernel code of the fusion operator.

[0049] In this embodiment, the fixed code generation process is offloaded to the microkernel, which greatly reduces the compilation complexity and simplifies the operator development process.

[0050] In one embodiment, step 1034 includes: Step 10341: for the first operator in the fused operator, based on the microkernel library, convert the innermost loop code of the vectorized instruction sequence corresponding to the first operator into the calling code of the microkernel; Step 10342: For the second operator in the fused operator, use the output result of the microkernel's calling code as input data of the second operator to obtain the fused microkernel's calling code.

[0051] Optionally, step 10341 includes: for each tile size, obtaining a microkernel corresponding to the tile size based on a microkernel library; when the length of the vectorized instruction sequence corresponding to the first operator is divisible by the vectorization length in the back-end hardware architecture, selecting the microkernel with the highest performance from multiple microkernels corresponding to multiple tile sizes; according to the sub-tile size supported by the microkernel with the highest performance, converting the innermost loop code of the vectorized instruction sequence corresponding to the first operator into a calling code of the microkernel with the highest performance.

[0052] like Figure 3 As shown in the figure, assume that the first operator of the fusion operator is the gather operator, the input shape of the gather operator is [26257,24], the indice shape is [7,2000], and dim=0. Based on the microkernel library, microkernels corresponding to different tile sizes are obtained. When the input indice can be divided by the vectorization length in the backend hardware architecture, the microkernel with the highest performance is selected from multiple microkernels corresponding to multiple tile sizes. According to the sub-tile size supported by the microkernel with the highest performance, the innermost loop code of the gather operator is converted into the calling code of the microkernel with the highest performance, that is, the k-loop code.

[0053] Optionally, step 10341 includes: for each tile size, obtaining a microkernel corresponding to the tile size based on the microkernel library; when the length of the vectorized instruction sequence corresponding to the first operator cannot be divided by the vectorization length in the back-end hardware architecture, loop splitting the vectorized instruction sequence corresponding to the first operator to obtain an aligned first loop processing logic code and an unaligned second loop processing logic code; selecting a first microkernel corresponding to the aligned first loop processing logic code and a second microkernel corresponding to the unaligned second loop processing logic code from multiple microkernels corresponding to multiple tile sizes; converting the aligned first loop processing logic code into a calling code of the first microkernel according to the sub-tile size supported by the first microkernel; converting the unaligned second loop processing logic code into a calling code of the second microkernel according to the sub-tile size supported by the second microkernel.

[0054] like Figure 4As shown in the figure, it is assumed that the first operator of the fusion operator is the gather operator, the input shape of the gather operator is [26257, 24], the indice shape is [7, 2040], and dim = 0. Since the input indice cannot be divided by the vectorization length in the backend hardware architecture, a tail loop processing logic is generated. The i loop traverses the first dimension of the indice, and the j loop performs loop splitting after analyzing the combination of the sub-tile size of the microkernel and obtaining the appropriate task division to obtain the aligned first loop processing logic code and the unaligned second loop processing logic code. The first microkernel corresponding to the aligned first loop processing logic code and the second microkernel corresponding to the unaligned second loop processing logic code are selected from the multiple microkernels corresponding to the multiple tile sizes. According to the sub-tile size supported by the first microkernel, the aligned first loop processing logic code is converted into the calling code of the first microkernel. According to the sub-tile size supported by the second microkernel, the unaligned second loop processing logic code is converted into the calling code of the second microkernel.

[0055] Step 10342 includes: using the output result of the calling code of the first microkernel as the input data of the second operator to obtain the fused calling code of the first microkernel; using the output result of the calling code of the second microkernel as the input data of the second operator to obtain the fused calling code of the second microkernel.

[0056] like Figure 5 As shown in the figure, assume that the input shape of the gather operator is [26257,24], the index shape is [7,2040], and dim=0. Taking the fusion of the gather operator and the add / div operator as an example, since the input of the add / div operator can reuse the output of the microkernel of the parent node at the register IR level, the post-processing logic (epilogue) feature is added to the implementation of the microkernel. Figure 4 Based on the loop IR optimization, adding loop merging optimization can merge the gather operator and the add / div operator into a microkernel call.

[0057] In this embodiment, operator fusion is achieved through microkernel combination, which can simplify the operator development process.

[0058] The deep learning compilation optimization device provided by the present invention is described below. The deep learning compilation optimization device described below and the deep learning compilation optimization method described above can refer to each other.

[0059] Please refer to Figure 6 , Figure 6 Schematic diagram of the structure of the deep learning compilation optimization device provided by the embodiment of the present invention. Figure 6As shown, the device may include: A conversion module 10, used to express the deep neural network as a computational graph through a deep learning framework, and convert the computational graph into an intermediate layer between the deep learning framework and the deep learning compiler; The clustering module 20 is used to mark the operators that need to be compiled in the middle layer, and cluster the marked operators into multiple subgraphs; the subgraphs include at least one fusion operator, and the fusion operator is obtained by fusion of multiple marked operators; The compilation module 30 is used to compile the fusion operator online through the deep learning compiler to generate the kernel code of the fusion operator; the online compilation includes converting the innermost loop code into the calling code of the microkernel based on the microkernel library.

[0060] In one embodiment, the compilation module 30 includes: A first conversion unit is used to convert the fusion operator into a loop intermediate representation layer; the loop intermediate representation layer is an intermediate representation layer in a nested perfect loop format or a non-perfect loop format; An optimization unit, used for optimizing the loop intermediate representation layer when the loop intermediate representation layer needs to be optimized; A second conversion unit, used to convert the optimized loop intermediate representation layer into a vectorized instruction sequence adapted to the back-end hardware; A third conversion unit is used to convert the innermost loop code of the vectorized instruction sequence into a calling code of the microkernel based on the microkernel library, and convert other parts into inline functions predefined by the backend hardware; A translation unit, used to translate the converted vectorized instruction sequence into the underlying virtual machine dialect; The compilation unit is used to call the backend compilation tool to compile the underlying virtual machine dialect into binary code supported by the backend as the kernel code of the fusion operator.

[0061] In one embodiment, the first conversion unit is specifically configured to: Determine whether the fusion operator is a structured operator; In the case where the fused operator is a structured operator, the fused operator is converted into a linear algebra dialect; An intermediate representation layer that converts the core operators represented in the linear algebra dialect into a nested perfect loop format; In the case where the fused operator is an unstructured operator, the fused operator is converted into a hybrid intermediate representation layer of cyclic and affine transformations as an intermediate representation layer in a non-perfect cyclic format.

[0062] In one embodiment, the optimization unit is specifically configured to: When the loop intermediate representation layer needs to be optimized, a target optimization method is determined from optimization methods based on loop fusion, loop order rearrangement, and loop slicing; The target optimization method is used to optimize the recurrent intermediate representation layer.

[0063] In one embodiment, the third conversion unit includes: A conversion subunit, for converting, for a first operator in the fused operator, an innermost loop code of a vectorized instruction sequence corresponding to the first operator into a calling code of the microkernel based on a microkernel library; The fusion subunit is used to use the output result of the calling code of the microkernel as the input data of the second operator in the fused operator to obtain the calling code of the fused microkernel.

[0064] In one embodiment, the conversion subunit is specifically used for: For each tile size, obtain the microkernel corresponding to the tile size based on the microkernel library; When the length of the vectorized instruction sequence corresponding to the first operator is divisible by the vectorization length in the backend hardware architecture, a microkernel with the highest performance is selected from a plurality of microkernels corresponding to the plurality of tile sizes; According to the sub-tile size supported by the microkernel with the highest performance, the innermost loop code of the vectorized instruction sequence corresponding to the first operator is converted into the calling code of the microkernel with the highest performance.

[0065] In one embodiment, the conversion subunit is specifically used for: For each tile size, obtain the microkernel corresponding to the tile size based on the microkernel library; When the length of the vectorized instruction sequence corresponding to the first operator cannot be divided by the vectorization length in the backend hardware architecture, the vectorized instruction sequence corresponding to the first operator is loop-split to obtain an aligned first loop processing logic code and a non-aligned second loop processing logic code; Selecting a first microkernel corresponding to the aligned first loop processing logic code and a second microkernel corresponding to the unaligned second loop processing logic code from a plurality of microkernels corresponding to the plurality of tile sizes; According to the sub-tile size supported by the first microkernel, converting the aligned first loop processing logic code into a calling code of the first microkernel; According to the sub-tile size supported by the second microkernel, converting the non-aligned second loop processing logic code into a calling code of the second microkernel; The fusion subunit is specifically used for: Using the output result of the calling code of the first microkernel as input data of the second operator to obtain the fused calling code of the first microkernel; The output result of the calling code of the second microkernel is used as input data of the second operator to obtain the fused calling code of the second microkernel.

[0066] Figure 7 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 7 As shown, the electronic device may include: a processor 710, a communication interface 720, a memory 730 and a communication bus 740, wherein the processor 710, the communication interface 720 and the memory 730 communicate with each other through the communication bus 740. The processor 710 may call the logic instructions in the memory 730 to execute the deep learning compilation optimization method, which includes: expressing the deep neural network as a calculation graph through a deep learning framework, converting the calculation graph into an intermediate layer between the deep learning framework and the deep learning compiler; marking the operators to be compiled in the intermediate layer, and clustering the marked operators into multiple subgraphs; the subgraphs include at least one fusion operator, which is obtained by fusion of multiple marked operators; compiling the fusion operator online through the deep learning compiler to generate the kernel code of the fusion operator; the online compilation includes converting the innermost loop code into the calling code of the microkernel based on the microkernel library.

[0067] In addition, the logic instructions in the above-mentioned memory 730 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 and other media that can store program codes.

[0068] On the other hand, the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the deep learning compilation optimization method provided by the above-mentioned method embodiments, the method including: expressing a deep neural network as a computational graph through a deep learning framework, and converting the computational graph into an intermediate layer between the deep learning framework and the deep learning compiler; marking the operators that need to be compiled in the intermediate layer, and clustering the marked operators into multiple subgraphs; the subgraphs include at least one fusion operator, which is obtained by fusing multiple marked operators; compiling the fusion operator online through the deep learning compiler to generate the kernel code of the fusion operator; the online compilation includes converting the innermost loop code into a microkernel calling code based on the microkernel library.

[0069] 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 deep learning compilation optimization method provided by the above-mentioned method embodiments, the method comprising: expressing a deep neural network as a computational graph through a deep learning framework, and converting the computational graph into an intermediate layer between the deep learning framework and the deep learning compiler; marking the operators that need to be compiled in the intermediate layer, and clustering the marked operators into multiple subgraphs; the subgraphs include at least one fusion operator, which is obtained by fusion of multiple marked operators; compiling the fusion operator online through the deep learning compiler to generate the kernel code of the fusion operator; the online compilation includes converting the innermost loop code into a calling code of the microkernel based on the microkernel library.

[0070] 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.

[0071] 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, it 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.

[0072] 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 deep learning compilation optimization method, characterized in that: include: Expressing a deep neural network as a computational graph through a deep learning framework, and converting the computational graph into an intermediate layer between the deep learning framework and a deep learning compiler; Marking the operators that need to be compiled in the intermediate layer, and clustering the marked operators into multiple subgraphs; the subgraphs include at least one fusion operator, and the fusion operator is obtained by fusion of multiple marked operators; The fusion operator is compiled online by the deep learning compiler to generate the kernel code of the fusion operator; the online compilation includes converting the innermost loop code into a calling code of the microkernel based on the microkernel library.

2. The deep learning compilation optimization method according to claim 1, characterized in that: The step of online compiling the fusion operator by the deep learning compiler to generate the kernel code of the fusion operator includes: The following steps are performed by the deep learning compiler: Converting the fusion operator into a loop intermediate representation layer; the loop intermediate representation layer is an intermediate representation layer in a nested perfect loop format or a non-perfect loop format; When the loop intermediate representation layer needs to be optimized, optimizing the loop intermediate representation layer; Converting the optimized loop intermediate representation layer into a vectorized instruction sequence adapted to the back-end hardware; Based on the microkernel library, the innermost loop code of the vectorized instruction sequence is converted into a calling code of the microkernel, and the other parts are converted into inline functions predefined by the backend hardware; The converted vectorized instruction sequence is translated into the underlying virtual machine dialect, and a backend compilation tool is called to compile the underlying virtual machine dialect into a binary code supported by the backend as the kernel code of the fusion operator.

3. The deep learning compilation optimization method according to claim 2, characterized in that: The converting the fusion operator into a cyclic intermediate representation layer comprises: Determining whether the fusion operator is a structured operator; In the case where the fusion operator is a structured operator, converting the fusion operator into a linear algebra dialect; Converting the core operator represented by the linear algebra dialect into an intermediate representation layer of the nested perfect loop format; In the case where the fused operator is an unstructured operator, the fused operator is converted into a mixed intermediate representation layer of cyclic and affine transformations as the intermediate representation layer of the non-perfect cyclic format.

4. The deep learning compilation optimization method according to claim 2, characterized in that: When the loop intermediate representation layer needs to be optimized, optimizing the loop intermediate representation layer includes: In the case where the loop intermediate representation layer needs to be optimized, determining a target optimization method from optimization methods based on loop fusion, loop order rearrangement, and loop slicing; The target optimization method is used to optimize the cyclic intermediate representation layer.

5. The deep learning compilation optimization method according to claim 2, characterized in that: The converting the innermost loop code of the vectorized instruction sequence into a calling code of the microkernel based on the microkernel library comprises: For a first operator in the fused operator, based on the microkernel library, converting the innermost loop code of the vectorized instruction sequence corresponding to the first operator into a calling code of the microkernel; For the second operator in the fused operator, the output result of the calling code of the microkernel is used as the input data of the second operator to obtain the calling code of the fused microkernel.

6. The deep learning compilation optimization method according to claim 5, characterized in that: The converting the innermost loop code of the vectorized instruction sequence corresponding to the first operator into a calling code of the microkernel based on the microkernel library includes: for each tile size, obtaining the microkernel corresponding to the tile size based on the microkernel library; When the length of the vectorized instruction sequence corresponding to the first operator is divisible by the vectorization length in the backend hardware architecture, selecting a microkernel with the highest performance from a plurality of microkernels corresponding to the plurality of tile sizes; According to the sub-tile size supported by the microkernel with the highest performance, the innermost loop code of the vectorized instruction sequence corresponding to the first operator is converted into the calling code of the microkernel with the highest performance.

7. The deep learning compilation optimization method according to claim 5, characterized in that: The converting the innermost loop code of the vectorized instruction sequence corresponding to the first operator into a calling code of the microkernel based on the microkernel library includes: for each tile size, obtaining the microkernel corresponding to the tile size based on the microkernel library; When the length of the vectorized instruction sequence corresponding to the first operator cannot be divided by the vectorization length in the backend hardware architecture, the vectorized instruction sequence corresponding to the first operator is loop-split to obtain an aligned first loop processing logic code and a non-aligned second loop processing logic code; Selecting a first microkernel corresponding to the aligned first loop processing logic code and a second microkernel corresponding to the unaligned second loop processing logic code from a plurality of microkernels corresponding to the plurality of tile sizes; According to the sub-tile size supported by the first microkernel, converting the aligned first loop processing logic code into a calling code of the first microkernel; According to the sub-tile size supported by the second microkernel, converting the non-aligned second loop processing logic code into a calling code of the second microkernel; The step of using the output result of the calling code of the microkernel as the input data of the second operator to obtain the fused calling code of the microkernel includes: Using the output result of the calling code of the first microkernel as input data of the second operator to obtain the fused calling code of the first microkernel; The output result of the calling code of the second microkernel is used as input data of the second operator to obtain the fused calling code of the second microkernel.

8. A deep learning compilation optimization device, characterized in that: include: A conversion module, used to express a deep neural network as a computational graph through a deep learning framework, and convert the computational graph into an intermediate layer between the deep learning framework and a deep learning compiler; A clustering module, used for marking operators that need to be compiled in the intermediate layer, and clustering the marked operators into multiple subgraphs; the subgraphs include at least one fusion operator, and the fusion operator is obtained by fusion of multiple marked operators; A compilation module is used to compile the fusion operator online through the deep learning compiler to generate the kernel code of the fusion operator; the online compilation includes converting the innermost loop code into the calling code of the microkernel based on the microkernel library.

9. 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, the steps of the deep learning compilation optimization method according to any one of claims 1 to 7 are implemented.

10. 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 steps of the deep learning compilation optimization method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Program optimization method, device, electronic device and storage medium

    CN119759327A

  • A program optimization method, device, electronic device and storage medium

    CN119759327B

  • Compiling optimization method and device for computational graph, equipment and medium

    CN119806542A

  • A Compilation Optimization Method, Device, Equipment and Medium for Computational Graphs

    CN119806542B

  • Deep learning model-oriented graph level compilation optimization method and deep learning model-oriented graph level compilation optimization equipment

    CN121209886A