Operator fusion method, electronic device and storage medium

By using the second processing tool in the target compiler to fusion of operators in deep neural networks, the computing resource and time consumption problems caused by the large number of operators in deep neural networks are solved, and vector processing core and tensor processing core are realized The effective fusion of operators improves computing efficiency and chip performance.

CN118585200BActive Publication Date: 2024-11-29北京壁仞科技开发有限公司 +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411067103.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-06
Publication Date
2024-11-29
Estimated Expiration
2044-08-06

AI Technical Summary

Technical Problem

The large number of operators in deep neural networks leads to huge computing resources and time consumption. It is difficult for existing operator fusion technology to effectively integrate operators of vector processing core types and tensor processing core types.

Method used

By using the first processing tool to obtain the input data and turn off its operator split function, the second processing tool in the target compiler is used to fusion multiple operators to generate a fusion operator. This method supports the fusion of vector processing core types and tensor processing core type operators.

Benefits of technology

The number of fused operators is reduced, the number of video memory accesses is reduced, the execution efficiency of computing tasks is improved, and the performance of the chip is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118585200B_ABST
    Figure CN118585200B_ABST
Patent Text Reader

Abstract

An operator fusion method, an electronic device and a storage medium. The operator fusion method comprises: using a first processing tool to obtain input data, wherein the input data comprises a plurality of operators, the plurality of operators comprise at least one operator type, the first processing tool comprises an operator splitting function, the operator splitting function is used to split operators of a first type among the plurality of operators; closing the operator splitting function in the first processing tool; using a target compiler to obtain input data processed by the first processing tool, wherein a second processing tool is provided in the target compiler; calling the second processing tool in the target compiler to fuse at least two operators among the plurality of operators to obtain a first fused operator, wherein at least two operators have the same operator type or different operator types. The operator fusion method reduces the number of fused operators, improves the execution efficiency of computing tasks, and improves the performance of the chip.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present disclosure relate to an operator fusion method, an electronic device, and a storage medium. Background Art

[0002] In the field of artificial intelligence (AI), as the application scenarios of deep learning continue to generalize, deep learning computing tasks need to be deployed on deep neural networks. Due to the deep number of layers and complex structure of deep neural networks, a large number of operators are generated, which leads to huge consumption of computing resources and time. Operator fusion is a method to improve the execution efficiency of deep learning computing tasks. For example, before executing a computing task, multiple operators that meet certain conditions or rules in a neural network can be fused to generate a fused operator. By fusing multiple operators, memory reuse can be achieved and the utilization of computing resources such as the central processing unit (CPU), graphics processing unit (GPU), compiler, registers, etc. can be improved. Summary of the invention

[0003] At least one embodiment of the present disclosure provides an operator fusion method, which includes: using a first processing tool to obtain input data, wherein the input data includes multiple operators, the multiple operators include at least one operator type, and the first processing tool includes an operator splitting function, and the operator splitting function is used to split operators of a first type among the multiple operators; turning off the operator splitting function in the first processing tool; using a target compiler to obtain input data processed by the first processing tool, wherein a second processing tool is provided in the target compiler; calling the second processing tool in the target compiler to fuse at least two operators among the multiple operators to obtain a first fused operator, wherein the at least two operators have the same operator type or different operator types.

[0004] For example, in the operator fusion method provided by at least one embodiment of the present disclosure, the operator splitting function in the first processing tool includes: searching for the multiple operators in a splitting dictionary, wherein the splitting dictionary contains at least one operator type to be split and a splitting method corresponding to each operator type to be split in the at least one operator type to be split; in response to at least one operator type to be split in the splitting dictionary including the first type, splitting the operators of the first type among the multiple operators.

[0005] For example, in the operator fusion method provided in at least one embodiment of the present disclosure, shutting down the operator splitting function in the first processing tool includes: clearing the at least one operator type to be split in the splitting dictionary.

[0006] For example, in the operator fusion method provided in at least one embodiment of the present disclosure, a graph matching paradigm is provided in the second processing tool, and calling the second processing tool in the target compiler to fuse at least two operators among the multiple operators to obtain a first fused operator includes: using the graph matching paradigm in the second processing tool to perform graph matching mapping on the at least two operators to be fused to obtain the first fused operator.

[0007] For example, in the operator fusion method provided in at least one embodiment of the present disclosure, the at least two operators to be fused include a first operator and a second operator, and calling the second processing tool in the target compiler to fuse at least two operators of the multiple operators to obtain a first fused operator includes: calling the second processing tool in the target compiler to set a target cache to write the output data of the first operator into the target cache, and reading the output data of the first operator from the target cache as input data of the second operator.

[0008] For example, in the operator fusion method provided in at least one embodiment of the present disclosure, a third processing tool and a fourth processing tool are also provided in the target compiler, and the operator fusion method further includes: using the third processing tool to split at least two unfused first-type operators among the multiple operators into multiple split operators; and using the fourth processing tool to fuse the multiple split operators to obtain a second fused operator.

[0009] For example, in the operator fusion method provided by at least one embodiment of the present disclosure, the use of the fourth processing tool to fuse the multiple split operators to obtain a second fused operator includes: assembling each of the multiple split operators downward to obtain an intermediate representation corresponding to each of the multiple split operators; fusing the multiple intermediate representations corresponding to the multiple split operators to obtain a fused intermediate representation corresponding to the second fused operator; and using the fused intermediate representation to generate an execution file corresponding to the second fused operator.

[0010] For example, in the operator fusion method provided in at least one embodiment of the present disclosure, the at least two operators include operators of the first type and operators of a second type that is different from the first type.

[0011] For example, in the operator fusion method provided in at least one embodiment of the present disclosure, the first type of operator is a vector processing core type operator, and the second type of operator is a tensor processing core type operator.

[0012] For example, in the operator fusion method provided in at least one embodiment of the present disclosure, the first processing tool is an automatic differentiation tool.

[0013] At least one embodiment of the present disclosure further provides an electronic device, comprising: a first processing tool, configured to obtain input data, wherein the input data includes multiple operators, the multiple operators include at least one operator type, the first processing tool includes an operator splitting function, the operator splitting function is used to split operators of a first type among the multiple operators; a processing device, configured to turn off the operator splitting function in the first processing tool; a target compiler, configured to obtain the input data processed by the first processing tool, wherein a second processing tool is provided in the target compiler; the target compiler is further configured to call the second processing tool to fuse at least two operators among the multiple operators to obtain a first fused operator, wherein the at least two operators have the same operator type or different operator types.

[0014] At least one embodiment of the present disclosure further provides an electronic device, comprising: one or more processors; one or more memories, including one or more computer program modules; wherein the one or more computer program modules are stored in the one or more memories and are configured to be executed by the one or more processors, and the one or more computer program modules are used to implement the operator fusion method provided in any embodiment of the present disclosure.

[0015] At least one embodiment of the present disclosure further provides a storage medium storing non-transitory computer-readable instructions, which, when executed by a computer, implements the operator fusion method provided by any embodiment of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings of the embodiments will be briefly introduced below. Obviously, the drawings in the following description only relate to some embodiments of the present disclosure, but are not intended to limit the present disclosure.

[0017] Figure 1 An exemplary flow chart of an operator fusion method provided for at least one embodiment of the present disclosure;

[0018] Figure 2 A schematic diagram of an example of an operator fusion method provided by at least one embodiment of the present disclosure;

[0019] Figure 3 Another exemplary flow chart of the operator fusion method provided for at least one embodiment of the present disclosure;

[0020] Figure 4 A schematic diagram of another example of an operator fusion method provided by at least one embodiment of the present disclosure;

[0021] Figure 5 A schematic block diagram of an electronic device provided for at least one embodiment of the present disclosure;

[0022] Figure 6 A schematic block diagram of another electronic device provided for at least one embodiment of the present disclosure;

[0023] Figure 7 A schematic block diagram of another electronic device provided for at least one embodiment of the present disclosure; and

[0024] Figure 8 A schematic diagram of a storage medium provided for at least one embodiment of the present disclosure. DETAILED DESCRIPTION

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

[0026] Unless otherwise defined, the technical terms or scientific terms used in the present disclosure should be understood by people with ordinary skills in the field to which the present disclosure belongs. The "first", "second" and similar words used in the present disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, similar words such as "one", "one" or "the" do not indicate quantity restrictions, but indicate that there is at least one. Similar words such as "include" or "comprise" mean that the elements or objects appearing before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. Similar words such as "connect" or "connected" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0027] The present disclosure is described below through several specific embodiments. In order to keep the following description of the embodiments of the present disclosure clear and concise, detailed descriptions of known functions and known components may be omitted. When any component of the embodiments of the present disclosure appears in more than one figure, the component is represented by the same or similar reference numeral in each figure.

[0028] Deep learning computing tasks are composed of multiple operators (Operators, Ops). In artificial intelligence models, operators correspond to the computing logic of layers or nodes. For example, the convolution computing task in the convolution layer can be an operator; the weight sum computing task in the fully-connected layer (FC layer) can also be an operator. When implementing a neural network, operators can be implemented in software (for example, through a computer program) or in hardware (for example, through a circuit).

[0029] During the training or reasoning process of an AI model, multiple operators in the AI ​​model need to be called to perform predetermined computing tasks. For example, traditional deep learning frameworks use manual methods to optimize operators, and then establish runtime graph interpreters to solve problems such as memory allocation scheduling, while AI compilers can automatically generate operators to complete computing tasks during the optimization process. For example, specifically, using an AI compiler for deep learning compilation and optimization is the process of translating and optimizing the current deep learning computing task through one or more layers of intermediate representation (IR), and finally converting it into an executable file on the target hardware. By using an AI compiler, the efficiency of software and hardware collaboration can be improved, further meeting the requirements for hardware performance in actual deployment of computing tasks or training scenarios.

[0030] In order to improve computing efficiency, AI compiler optimization uses operator fusion technology; operator fusion mainly occurs in the layer, and the kernel layer will also draw on the operator fusion strategy to provide fused operators to the deep learning framework. For example, in some emerging deep learning frameworks (such as the PyTorch 2.0 framework, etc.), high-performance compilers (such as the Inductor compiler, etc.) can be used to generate high-performance code for the backend of the accelerator, and operator fusion tools written in high-performance programming languages ​​(such as the Triton language, etc.) can be used for operator fusion; operator fusion can reduce the number of operators, thereby reducing the number of accesses to the video memory and achieving high-performance computing of the chip.

[0031] For example, in order to perform operator fusion in a high-performance compiler, a specific capture tool can be used to obtain input data, and the captured input data can be output as a computational graph containing multiple operators; further, a specific optimization tool is used to optimize the computational graph, and then the optimized computational graph is passed to the high-performance compiler at the back end of the accelerator to perform operator fusion using an operator fusion tool in the compiler.

[0032] For example, artificial intelligence chips contain vector processing cores (Vector Core) and tensor processing cores (TensorCore). For example, vector processing cores have better versatility, but lower performance; tensor processing cores have higher performance, but can only support some operators; therefore, in actual applications, vector processing core type operators and tensor processing core type operators are used at the same time.

[0033] For example, taking the high-performance compiler Inductor and the high-performance programming language Triton as examples, the operator fusion tool (Triton fusion tool) written in the Triton language only supports the fusion between multiple vector processing core type operators, and cannot support the fusion between generalized vector processing core type operators and tensor processing core type operators, nor can it support the fusion between multiple tensor processing core type operators, resulting in limited chip performance. In addition, when performing operator fusion, the Triton fusion tool cannot directly fuse vector processing core type operators, but needs to first split the vector processing core type operators into multiple small operators in the front-end calculation graph optimization stage, and then fuse multiple small operators in the Triton fusion tool; due to the large number of operators in the large model, the total number of operators is greatly increased after the splitting of small operators, resulting in an increase in the computational complexity of the operator fusion process, further reducing the performance of the chip.

[0034] At least one embodiment of the present disclosure provides an operator fusion method, which includes: using a first processing tool to obtain input data, wherein the input data includes multiple operators, the multiple operators include at least one operator type, and the first processing tool includes an operator splitting function, and the operator splitting function is used to split operators of a first type among the multiple operators; turning off the operator splitting function in the first processing tool; using a target compiler to obtain input data processed by the first processing tool, wherein a second processing tool is provided in the target compiler; calling the second processing tool in the target compiler to fuse at least two operators among the multiple operators to obtain a first fused operator, wherein the at least two operators have the same operator type or different operator types.

[0035] At least one embodiment of the present disclosure also provides at least one electronic device and a storage medium for implementing the operator fusion method of the above embodiment.

[0036] The method, apparatus, electronic device, and storage medium provided by at least one embodiment of the present disclosure can achieve fusion between multiple operators of the same or different operator types while reducing computational complexity by turning off the operator splitting function in the first processing tool and setting the second processing tool in the target compiler, thereby reducing the number of operators after fusion, reducing the number of video memory accesses, improving the execution efficiency of computing tasks, and enhancing chip performance.

[0037] Hereinafter, at least one embodiment of the present disclosure will be described in detail with reference to the accompanying drawings. It should be noted that the same reference numerals in different drawings will be used to refer to the same elements described.

[0038] Figure 1 An exemplary flow chart of an operator fusion method provided for at least one embodiment of the present disclosure.

[0039] For example, Figure 1 As shown, at least one embodiment of the present disclosure provides an operator fusion method, which may include the following steps S110~S140.

[0040] Step S110: using a first processing tool to obtain input data.

[0041] For example, in step S110, the input data includes multiple operators, and the multiple operators include at least one operator type. In some examples, the at least two operators to be fused include a first type of operator and a second type of operator different from the first type, and the first type of operator may be a vector core type operator (for example, a softmax operator, an add operator, etc.), and the second type of operator may be a tensor core type operator (for example, a matmul operator, a convolution operator, etc.); depending on the specific application scenario, the operator to be fused in the input data may also be of other types, and the embodiments of the present disclosure are not limited to this.

[0042] For example, in step S110, the first processing tool includes an operator splitting function, and the operator splitting function is used to split the first type of operators among multiple operators; taking the first type of operator as a vector processing core type as an example, since the Triton fusion tool in the Inductor compiler cannot directly fuse the vector processing core type operator when performing operator fusion, it is necessary to first split the vector processing core type operator into multiple split operators in the front-end calculation graph optimization stage. The first processing tool of the front-end can be used to implement the above splitting function of the vector processing core type operator.

[0043] For example, in some examples, the input data may be a computational graph containing multiple operators, and the first processing tool may be an automatic differentiation tool. For example, in the PyTorch 2.0 framework, the input data may be an FX computational graph (Function Annotation and Transformation Graph) output after being acquired by a capture tool (e.g., Dynamo tool), and the first processing tool may be an AOTAutograd (Ahead-Of-Time Automatic Differentiation) automatic differentiation tool, which is used to acquire the FX computational graph output by the capture tool and optimize it (e.g., generate forward and reverse graphs, operator splitting, etc.); since the Triton fusion tool in the backend Inductor compiler only supports the fusion of vector processing core type operators, and cannot directly fuse unsplit vector processing core type operators, the operator splitting function of AOTAutograd can split the operator to be fused into multiple split operators, so as to realize the fusion of vector processing core type operators by fusing multiple split operators in the backend compiler.

[0044] It should be noted that the first processing tool is used to optimize the input data, and the specific optimization method is not limited to operator splitting; taking AOTAutograd as an example, the first processing tool can also achieve optimization by generating forward and reverse graphs in the input data, etc., and specific reference is made to the description in the art, which will not be repeated here; the embodiments of the present disclosure do not limit the type of the first processing tool and the specific optimization method.

[0045] It should be noted that other selections may be made for the input data and the type and quantity of operators contained therein, the type and function of the first processing tool, etc. according to the specific application scenario, and the embodiments of the present disclosure do not limit this.

[0046] Step S120: Turn off the operator splitting function in the first processing tool.

[0047] For example, since at least one embodiment of the present disclosure provides an operator fusion method that can use the second fusion tool set in the target compiler to directly perform operator fusion (that is, there is no need to split the operator into small operators for fusion), the operator splitting function in the first processing tool can be turned off in step S120. For example, a large-scale artificial intelligence model contains a large number of operators. After further splitting the operators to be fused, a large number of split operators will be obtained. In subsequent processing, the split operators need to be transmitted and screened to achieve operator fusion, which greatly increases the workload and complexity of operator fusion; by turning off the operator splitting function in the first processing tool, the workload and complexity of operator fusion can be reduced to a certain extent.

[0048] In some examples, for the operator splitting function of the first processing tool, a splitting dictionary or other method may be used in the first processing tool to split operators of a specific type. For example, taking the splitting dictionary as an example, the operator splitting function in the first processing tool may include: searching for multiple operators in the splitting dictionary; in response to at least one operator type to be split in the splitting dictionary including the first type, splitting operators of the first type among the multiple operators.

[0049] For example, the split dictionary contains one or more types of operators to be split and the splitting methods corresponding to each type of operator to be split. For example, if there is no closing operation in step S120, the first processing tool will perform the operator splitting function in the process of obtaining input data in step S110; specifically, the first processing tool first searches the split dictionary to determine whether the multiple operators of the input data contain the type of operator to be split; if the first type of operator is found in the split dictionary to be split, the splitting method corresponding to the first type of operator is read to split the first type of operator.

[0050] For example, when the first processing tool obtains input data and finds that the input data contains a softmax type operator, it will search the split dictionary for the softmax type; if the type exists in the split dictionary, it will further obtain the value corresponding to the softmax type in the split dictionary to determine how to split the softmax type operator.

[0051] For example, accordingly, Figure 1 Step S120 may further include: clearing at least one type of operator to be split in the split dictionary. For example, the operator types and corresponding values ​​contained in the split dictionary may be set to empty (eg, split dictionary = {}) to disable the operator splitting function.

[0052] It should be noted that, in addition to the split dictionary, other methods can also be selected according to the specific application scenario to implement the operator splitting function of the first processing tool, and the corresponding method can be selected to close the operator splitting function. The embodiments of the present disclosure do not limit this.

[0053] Step S130: using the target compiler to obtain input data processed by the first processing tool.

[0054] For example, after turning off the operator splitting function in the first processing tool in step S120, the first processing tool optimizes the acquired input data; in step S130, the target compiler acquires the input data processed by the first processing tool, that is, the input data processed by the first processing tool is the processing result without being processed by the operator splitting function of the first processing tool.

[0055] For example, in step S130, a second processing tool is provided in the target compiler. For example, the second processing tool may be an operator fusion tool developed based on an adaptation scenario of a specific chip, and may specifically implement the function of fusing multiple types of operators by adding a function or pass with a fusion function. The embodiments of the present disclosure do not limit the specific implementation form of the second processing tool.

[0056] For example, in step S130, the target compiler can be a high-performance compiler (e.g., Inductor compiler, etc.) used in a deep learning framework (e.g., PyTorch 2.0 framework, etc.), or other types of compilers can be selected according to different application scenarios or AI frameworks. The specific selection can be made according to actual needs, and the embodiments of the present disclosure are not limited to this.

[0057] Step S140: calling a second processing tool in the target compiler to fuse at least two operators among the multiple operators to obtain a first fused operator.

[0058] For example, in step S140, since the operator splitting function of the first processing tool is turned off in step S120, the input data processed by the first processing tool only includes multiple unsplit operators; the second processing tool can directly merge at least two unsplit operators.

[0059] For example, in step S140, at least two operators have the same operator type or different operator types; the first fused operator can be obtained by the fusion of multiple vector processing core type operators, or by the fusion of multiple tensor processing core type operators, or by the fusion of vector processing core type operators and tensor processing core type operators, or by the fusion of other types of operators, which is not limited by the embodiments of the present disclosure.

[0060] In some examples, in order to use the second processing tool to implement the function of fusing multiple types of operators, a graph matching paradigm can be set in the second processing tool. Figure 1 The step S140 may further include the following step S141.

[0061] Step S141: Use the graph matching paradigm in the second processing tool to perform graph matching mapping on at least two operators to be fused to obtain a first fusion operator.

[0062] For example, the second processing tool may be implemented by multiple paradigms, wherein the added graph matching paradigm may be a function with a graph matching mapping function, etc. For example, in step S141, the graph matching paradigm is used to perform graph matching mapping on the operators to be fused in the input data (e.g., the computation graph), thereby calling the second processing tool to implement the fusion of the operators.

[0063] For example, the input data of the graph matching paradigm can be a computation graph, and graph-to-graph transformation can be achieved by performing graph matching mapping on the computation graph. For example, operators A and B in the computation graph are input into the graph matching paradigm (for example, represented by Pass), and the process of performing graph matching mapping can be simply illustrated as: Pass(A, B)-->AB, thereby preliminarily achieving the fusion of operators A and B in the computation graph. For example, the specific implementation of graph matching can refer to the description in the art, and will not be repeated here.

[0064] In some examples, the at least two operators to be fused include a first operator and a second operator. Figure 1 The step S140 may further include the following step S142.

[0065] Step S142: calling a second processing tool in the target compiler to set a target cache, so as to write the output data of the first operator into the target cache, and read the output data of the first operator from the target cache as input data of the second operator.

[0066] For example, in step S142, the second processing tool can realize the fusion of the first operator and the second operator according to the characteristics of a specific chip. For example, according to the execution order of the calculation graph, the first operator is in front and the second operator is after the first operator; specifically, the second processing tool can set the target cache inside the chip, write the output data of the first operator in front to the target cache, and then read the output data of the first operator from the target cache as the input data of the second operator behind, thereby realizing the fusion of the first operator and the second operator.

[0067] For example, the first operator and the second operator have the same operator type or different operator types; the first operator and the second operator can both be of the first type (for example, a vector processing core type, etc.), or both be of the second type (for example, a tensor processing core type, etc.), or respectively be of the first type and the second type, and the embodiments of the present disclosure are not limited to this.

[0068] It should be noted that the first fusion operator can be obtained by fusing the first operator and the second operator, or by fusing more than two operators. The embodiments of the present disclosure do not limit the number and type of operators used for fusion. For example, when the first fusion operator is obtained by fusing more than two operators, the fusion method between each two operators among the more than two operators can refer to the fusion method of the first operator and the second operator in step S142, and the embodiments of the present disclosure do not limit this.

[0069] Figure 2 A schematic diagram of an example of an operator fusion method provided by at least one embodiment of the present disclosure. For example, Figure 2 for Figure 1 A specific example of the operator fusion method shown.

[0070] For example, Figure 2 As shown, in step S110, the first processing tool 110 is used to obtain input data, and the operator splitting function included in the first processing tool 110 can split the first type of operators among the multiple operators. For example, further, in order to reduce the workload and complexity of subsequent operator fusion, the operator splitting function of the first processing tool 110 is turned off in step S120; specifically, one or more types of operators to be split in the splitting dictionary of the first processing tool 110 can be cleared, for example, the operator types and corresponding values ​​included in the splitting dictionary are set to be empty (for example, splitting dictionary = {}) to turn off the operator splitting function.

[0071] For example, Figure 2 As shown, in step S130, the target compiler 120 is used to obtain input data processed by the first processing tool 110; since the operator splitting function of the first processing tool 110 is turned off in step S120, the input data processed by the first processing tool 110 only includes multiple operators that have not been split.

[0072] For example, Figure 2 As shown, in step S140, the second processing tool 121 is called in the target compiler 120 to directly fuse at least two operators that have not been split to obtain a first fused operator. For example, specifically, when executing step S141, the graph matching paradigm in the second processing tool 121 is used to perform graph matching mapping on at least two operators to be fused; and when executing step S142, the second processing tool 121 is called to set the target cache to write the output data of the previous first operator into the target cache, and read the output data of the first operator from the target cache as the input data of the next second operator, so as to fuse the first operator and the second operator.

[0073] It should be noted that Figure 3The processing framework for operator fusion shown is only illustrative; for example, in the PyTorch 2.0 framework, the input data may be the FX computational graph output after being acquired by the capture tool, the first processing tool may be the AOTAutograd automatic differentiation tool, the target compiler may be the Inductor compiler, and the second processing tool may be an operator fusion tool developed based on an adaptation scenario of a specific chip; the input data, the first processing tool, the target compiler, and the second processing tool may also be selected as other types and implementation methods according to the actual application scenario, and the embodiments of the present disclosure are not limited to this.

[0074] The operator fusion method provided by at least one embodiment of the present disclosure can achieve the fusion between multiple operators of the same or different operator types while reducing the calculation complexity by turning off the operator splitting function in the first processing tool and setting the second processing tool in the target compiler, thereby reducing the number of operators after fusion, reducing the number of accesses to the video memory, improving the execution efficiency of the computing tasks, and improving the performance of the chip.

[0075] In some examples, the target compiler is further provided with a third processing tool and a fourth processing tool. Figure 1 After using the second processing tool to fuse all the operators that can be fused among the multiple operators in step S140, if there are still at least two unfused first-type operators remaining among the multiple operators, a third processing tool can be added to the target compiler, and a fourth processing tool in the target compiler can be used to fuse the remaining at least two unfused first-type operators.

[0076] Figure 3 Another exemplary flowchart of the operator fusion method provided for at least one embodiment of the present disclosure.

[0077] For example, Figure 3 As shown, in the execution Figure 1 After step S140, the operator fusion method provided by at least one embodiment of the present disclosure may further include the following steps S150~S160.

[0078] Step S150: using a third processing tool to split at least two unfused first-type operators among the multiple operators into multiple split operators.

[0079] For example, in step S150, when executing Figure 1 After step S140, if there are at least two unfused first type operators remaining among the multiple operators, the third processing tool added in the target compiler is first used to split the at least two unfused first type operators into multiple split operators for subsequent operator fusion operations.

[0080] For example, the third processing tool can be an operator splitting tool developed based on the adaptation scenario of a specific chip, which is used to supplement the target compiler. Figure 1 The operator splitting function of the first processing tool is turned off in step S120. For example, the operator splitting function of the third processing tool can be basically consistent with the operator splitting function of the first processing tool, or other splitting methods can be selected according to actual conditions, which is not limited in the embodiments of the present disclosure.

[0081] Step S160: Use a fourth processing tool to fuse multiple split operators to obtain a second fused operator.

[0082] For example, in step S160, the fourth processing tool may fuse the multiple split operators obtained by splitting in step S150, thereby fusing at least two remaining unfused first type operators in the input data, thereby achieving further fusion of operators in the input data.

[0083] For example, taking the first type of operator as a vector processing core type operator, and the fourth processing tool as the Triton fusion tool in the Inductor compiler, since the Triton fusion tool cannot directly fuse the vector processing core type operator, the vector processing core type operator can be first split into multiple split operators in step S150, and then the Triton fusion tool is used in step S160 to fuse the multiple split operators. It should be noted that the target compiler and the fourth processing tool can also select other types according to actual conditions, and the embodiments of the present disclosure are not limited to this.

[0084] In some examples, for a process of fusing multiple split operators using a fourth processing tool, Figure 3 The step S160 may further include the following steps S161 to S163.

[0085] Step S161: assemble each split operator in the multiple split operators downward to obtain an intermediate representation corresponding to each split operator in the multiple split operators;

[0086] Step S162: fusing the multiple intermediate representations corresponding to the multiple splitting operators to obtain a fused intermediate representation corresponding to the second fusion operator;

[0087] Step S163: Generate an execution file corresponding to the second fusion operator using the fused intermediate representation.

[0088] For example, in step S161, the fourth processing tool can obtain the intermediate representation (IR) of each split operator by lowering each split operator. For example, taking the fourth processing tool as the Triton fusion tool in the Inductor compiler as an example, the intermediate representation obtained by lowering the split operator can be a loop-level intermediate representation (LoopLevel IR). The loop-level intermediate representation of the Inductor compiler contains a small number of operators, which can greatly simplify the calculation graph and reduce the complexity of the calculation processing. For example, the intermediate representation of the split operator can also be selected as other types according to the actual application scenario, and the embodiments of the present disclosure are not limited to this.

[0089] For example, in step S162, multiple intermediate representations corresponding to multiple splitting operators are fused (for example, horizontal fusion and vertical fusion, etc.) to obtain a fused intermediate representation, which corresponds to the second fusion operator.

[0090] For example, in step S163, a fourth processing tool is used to perform a code generation operation (e.g., CodeGen, etc.) on the fusion intermediate representation to generate an execution file corresponding to the second fusion operator; the execution file may be an executable file that can be deployed and executed on hardware (e.g., machine executable code, etc.), thereby enabling the execution of the second fusion operator on hardware.

[0091] Figure 4 A schematic diagram of another example of an operator fusion method provided by at least one embodiment of the present disclosure. For example, Figure 4 for Figure 1 and Figure 3 A specific example of the operator fusion method shown.

[0092] For example, Figure 4 As shown, compared Figure 2 In the example of , a third processing tool 122 is additionally added to the target compiler 120 to perform the operator splitting operation of step S150, and a fourth processing tool 123 is additionally used to perform the second operator fusion operation of step S160. For example, Figure 4 The input data in the first processing tool 110, the second processing tool 121 in the target compiler 120, and the specific processing process of steps S110 to S140 are the same as Figure 2 The examples are basically the same, please refer to Figure 2 The description will not be repeated here.

[0093] For example, Figure 4As shown, after executing step S140, if there are at least two unfused first type operators remaining in the multiple operators of the input data, step S150 is executed, that is, the at least two unfused first type operators are split into multiple split operators using the third processing tool 122. Figure 4 In the example of , the operator splitting function of the third processing tool 122 may be substantially the same as the operator splitting function of the first processing tool 110 closed in step S120.

[0094] For example, Figure 4 As shown, for the multiple split operators obtained by splitting the third processing tool 122, in step S160, the fourth processing tool 123 can be used to fuse the multiple split operators to obtain a second fused operator. For example, specifically, step S161 is executed, and each split operator is assembled downward using the fourth processing tool 123 to obtain an intermediate representation of each split operator; further, step S162 is executed, and the multiple intermediate representations corresponding to the multiple split operators are fused using the fourth processing tool 123 to obtain a fused intermediate representation corresponding to the second fused operator; further, step S163 is executed, and the fourth processing tool 123 is used to perform a code generation operation on the fused intermediate representation to generate an execution file corresponding to the second fused operator.

[0095] It should be noted that Figure 4 The processing framework for operator fusion shown is only illustrative; for example, in the PyTorch 2.0 framework, the third processing tool may be an operator splitting tool developed in the Inductor compiler based on an adaptation scenario of a specific chip, and the fourth processing tool may be the Triton fusion tool in the Inductor compiler; the third processing tool and the fourth processing tool may also be selected as other types and implementation methods according to actual application scenarios, and the embodiments of the present disclosure are not limited to this.

[0096] The operator fusion method provided by at least one embodiment of the present disclosure can use the third processing tool to split the remaining unfused operators by further adding a third processing tool in the target compiler after the second processing tool completes the first fusion, so that the fourth processing tool in the target compiler can be used to perform a second fusion operation on the multiple split operators obtained by the splitting, so that the fusion functions of the second processing tool and the fourth processing tool in the target compiler complement each other, thereby realizing further fusion of operators in the input data, thereby further reducing the number of operators and improving the computing performance of the chip.

[0097] Figure 5 A schematic block diagram of an electronic device provided for at least one embodiment of the present disclosure.

[0098] For example, Figure 5As shown, the electronic device 200 includes a first processing tool 110 , a processing device 220 and a target compiler 120 .

[0099] For example, the first processing tool 110 is configured to obtain input data. For example, the input data includes multiple operators, and the multiple operators include at least one operator type. The first processing tool 110 includes an operator splitting function, and the operator splitting function is used to split the first type of operators in the multiple operators. That is, the first processing tool 110 can be configured to perform, for example Figure 1 Step S110 is shown.

[0100] For example, the processing device 220 is configured to turn off the operator splitting function in the first processing tool 110. That is, the processing device 220 can be configured to perform, for example Figure 1 Step S120 is shown.

[0101] For example, the target compiler 120 is configured to obtain input data processed by the first processing tool 110. For example, the target compiler 120 is provided with a second processing tool 121 (not shown in the figure). That is, the target compiler 120 can be configured to execute, for example Figure 1 Step S130 is shown.

[0102] For example, the target compiler 120 is further configured to call the second processing tool 121 to fuse at least two operators of the plurality of operators to obtain a first fused operator. For example, the at least two operators have the same operator type or different operator types. That is, the target compiler 120 can also be configured to execute, for example Figure 1 Step S140 is shown.

[0103] In some examples, the at least two operators include an operator of a first type and an operator of a second type different from the first type. For example, the operator of the first type may be an operator of a vector processing core type, and the operator of the second type may be an operator of a tensor processing core type.

[0104] In some examples, the first processing tool 110 is an automatic differentiation tool.

[0105] In some examples, the operator splitting function in the first processing tool 110 includes: searching for multiple operators in a splitting dictionary, wherein the splitting dictionary contains at least one operator type to be split and a splitting method corresponding to each operator type to be split in at least one operator type to be split; in response to at least one operator type to be split in the splitting dictionary including a first type, splitting operators of the first type among the multiple operators.

[0106] For example, the processing device 220 is further configured to clear at least one type of operator to be split in the split dictionary.

[0107] In some examples, a graph matching paradigm is provided in the second processing tool 121. For example, the target compiler 120 is further configured to use the graph matching paradigm in the second processing tool 121 to perform graph matching mapping on at least two operators to be fused to obtain a first fused operator.

[0108] In some examples, the at least two operators to be fused include a first operator and a second operator. For example, the target compiler 120 is further configured to call the second processing tool 121 in the target compiler 120 to set a target cache to write the output data of the first operator to the target cache, and read the output data of the first operator from the target cache as input data of the second operator.

[0109] In some examples, a third processing tool and a fourth processing tool are also provided in the target compiler 120. The electronic device 200 further includes a third processing tool 122 and a fourth processing tool 123 (not shown in the figure).

[0110] For example, the third processing tool 122 is configured to split at least two unfused first-type operators among the plurality of operators into a plurality of split operators. That is, the third processing tool 122 may be configured to perform, for example Figure 3 Step S150 is shown.

[0111] For example, the fourth processing tool 123 is configured to use the fourth processing tool 123 to fuse multiple split operators to obtain a second fused operator. That is, the fourth processing tool 123 can be configured to perform, for example Figure 3 Step S160 is shown.

[0112] For example, the fourth processing tool 123 is also configured to: assemble each split operator in the multiple split operators downward to obtain an intermediate representation corresponding to each split operator in the multiple split operators; fuse the multiple intermediate representations corresponding to the multiple split operators to obtain a fused intermediate representation corresponding to the second fused operator; and use the fused intermediate representation to generate an execution file corresponding to the second fused operator.

[0113] Since in the above description, for example Figure 2 In the process of the operator fusion method shown in FIG. 1 , the details of the operation of the electronic device 200 have been introduced, so for the sake of brevity, they will not be repeated here. For relevant details, please refer to the above Figure 1~Figure 4 etc.

[0114] It should be noted that Figure 5The above-mentioned processing device 220 in the electronic device 200 shown can be implemented directly by a processor, or by a plurality of functional modules, and each functional module can be configured as software, hardware, firmware or any combination of the above items to perform a specific function. For example, these modules may correspond to a dedicated integrated circuit, or to a pure software code, or to a module that combines software and hardware. In addition, it is clear to those skilled in the art that the processing performed by each module can also be performed in the processing device 220 without any specific module division or without clear demarcation between the modules. As an example, refer to Figure 5 The electronic device 200 described may be a PC computer, a tablet device, a personal digital assistant, a smart phone, a web application or other device capable of executing program instructions, but is not limited thereto.

[0115] At least one embodiment of the present disclosure also provides another electronic device, which includes one or more processors and one or more memories; the one or more memories include one or more computer program modules; the one or more computer program modules are stored in the one or more memories and are configured to be executed by one or more processors, and the one or more computer program modules include methods for implementing the operator fusion method provided by the embodiment of the present disclosure described above. For example, the one or more processors may be a single-core processor or a multi-core processor.

[0116] Figure 6 A schematic block diagram of another electronic device provided for at least one embodiment of the present disclosure.

[0117] For example, Figure 6 As shown, the electronic device 300 includes a processor 310 and a memory 320. For example, the memory 320 is used to store non-transitory computer-readable instructions (e.g., one or more computer program modules). The processor 310 is used to run non-transitory computer-readable instructions, and when the non-transitory computer-readable instructions are run by the processor 310, one or more steps of the operator fusion method described above can be executed. The memory 320 and the processor 310 can be interconnected through a bus system and / or other forms of connection mechanisms (not shown).

[0118] For example, the processor 310 may be a central processing unit (CPU), a graphics processing unit (GPU), a general purpose graphics processing unit (GPGPU), a digital signal processor (DSP), or other forms of processing units, such as a field programmable gate array (FPGA), etc.; for example, the central processing unit (CPU) may be an X86, RISC-V, or ARM architecture, etc. The processor 310 may be a general-purpose processor or a dedicated processor, and may control other components in the electronic device 300 to perform desired functions.

[0119] For example, the memory 320 may include any combination of one or more computer program products, and the computer program product may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and / or cache memory (cache), etc. Non-volatile memory may include, for example, read-only memory (ROM), hard disk, erasable programmable read-only memory (EPROM), portable compact disc read-only memory (CD-ROM), USB memory, flash memory, etc. One or more computer program modules may be stored on the computer-readable storage medium, and the processor 310 may run one or more computer program modules to implement various functions of the electronic device 300. Various applications and various data, as well as various data used and / or generated by the application, etc. may also be stored in the computer-readable storage medium.

[0120] It should be noted that in the embodiments of the present disclosure, the specific functions and technical effects of the electronic device 300 can refer to the above description of the operator fusion method provided in at least one embodiment of the present disclosure, and will not be repeated here.

[0121] Figure 7 A schematic block diagram of another electronic device provided for at least one embodiment of the present disclosure.

[0122] For example, Figure 7 As shown, the electronic device 400 is suitable for implementing the operator fusion method provided in the embodiment of the present disclosure. It should be noted that, Figure 7 The electronic device 400 shown is only an example and does not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0123] For example, Figure 7As shown, the electronic device 400 may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 41, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 42 or a program loaded from a storage device 48 to a random access memory (RAM) 43. In the RAM 43, various programs and data required for the operation of the electronic device 400 are also stored. The processing device 41, the ROM 42, and the RAM 43 are connected to each other through a bus 44. An input / output (I / O) interface 45 is also connected to the bus 44. Generally, the following devices can be connected to the I / O interface 45: an input device 46 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 47 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 48 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 49. The communication device 49 can allow the electronic device 400 to communicate with other electronic devices wirelessly or by wire to exchange data.

[0124] Although Figure 7 The electronic device 400 is shown to have various devices, but it should be understood that it is not required to implement or possess all the devices shown, and the electronic device 400 may alternatively implement or possess more or fewer devices.

[0125] For the detailed description and technical effects of the electronic device 400, please refer to the above description of the operator fusion method, which will not be repeated here.

[0126] Figure 8 A schematic diagram of a storage medium provided for at least one embodiment of the present disclosure.

[0127] For example, Figure 8 As shown, the storage medium 500 stores non-transitory computer-readable instructions 510. For example, when the non-transitory computer-readable instructions 510 are executed by a computer, one or more steps in the operator fusion method described above are performed.

[0128] For example, the storage medium 500 can be applied to Figure 6 For example, the storage medium 500 may be the memory 320 in the electronic device 300. For example, the description of the storage medium 500 may refer to Figure 6 The corresponding description of the memory 320 in the electronic device 300 is shown and will not be repeated here.

[0129] There are a few points to note about this disclosure:

[0130] (1) In the drawings of the embodiments of the present disclosure, only the structures related to the embodiments of the present disclosure are involved, and other structures can refer to the general design.

[0131] (2) Unless there is a conflict, the features of the same embodiment or different embodiments of the present disclosure may be combined with each other.

[0132] The above are only specific embodiments of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present disclosure, which should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.

Claims

1. An operator fusion method, characterized in that: The operator fusion method comprises: Using a first processing tool to obtain input data, wherein the input data includes a plurality of operators, the plurality of operators include at least one operator type, and the first processing tool includes an operator splitting function, the operator splitting function is used to split operators of a first type among the plurality of operators; Turn off the operator splitting function in the first processing tool; Using a target compiler to obtain input data processed by the first processing tool, wherein the input data processed by the first processing tool only includes a plurality of unsplit operators, and the target compiler is provided with a second processing tool; Invoking the second processing tool in the target compiler to fuse at least two operators of the plurality of operators to obtain a first fused operator, wherein the at least two operators have the same operator type or different operator types, Wherein, the second processing tool is provided with a graph matching paradigm, The calling of the second processing tool in the target compiler to fuse at least two operators of the multiple operators to obtain a first fused operator includes: Using the graph matching paradigm in the second processing tool, the at least two operators to be fused are subjected to graph matching mapping to obtain the first fusion operator, The target compiler is further provided with a third processing tool and a fourth processing tool, and the operator fusion method further includes: Using the third processing tool, splitting at least two unfused operators of the first type among the plurality of operators into a plurality of split operators; The plurality of split operators are fused using the fourth processing tool to obtain a second fused operator.

2. The operator fusion method according to claim 1, characterized in that: The operator splitting function in the first processing tool includes: Searching for the multiple operators in a split dictionary, wherein the split dictionary contains at least one type of operator to be split and a splitting mode corresponding to each type of operator to be split in the at least one type of operator to be split; In response to at least one type of operator to be split in the split dictionary including the first type, operators of the first type among the multiple operators are split.

3. The operator fusion method according to claim 2, characterized in that: The disabling of the operator splitting function in the first processing tool includes: The at least one operator type to be split in the split dictionary is cleared.

4. The operator fusion method according to claim 1, characterized in that: The at least two operators to be fused include a first operator and a second operator, The calling of the second processing tool in the target compiler to fuse at least two operators of the multiple operators to obtain a first fused operator includes: The second processing tool is called in the target compiler to set a target cache to write the output data of the first operator into the target cache, and read the output data of the first operator from the target cache as input data of the second operator.

5. The operator fusion method according to claim 1, characterized in that: The using the fourth processing tool to fuse the multiple split operators to obtain a second fused operator includes: Assemble each split operator in the plurality of split operators downward to obtain an intermediate representation corresponding to each split operator in the plurality of split operators; fusing the multiple intermediate representations corresponding to the multiple splitting operators to obtain a fused intermediate representation corresponding to the second fusion operator; An execution file corresponding to the second fused operator is generated using the fused intermediate representation.

6. The operator fusion method according to any one of claims 1 to 5, characterized in that: The at least two operators include operators of the first type and operators of a second type different from the first type.

7. The operator fusion method according to claim 6, characterized in that: The first type of operator is a vector processing core type operator, and the second type of operator is a tensor processing core type operator.

8. The operator fusion method according to any one of claims 1 to 5, characterized in that: The first processing tool is an automatic differentiation tool.

9. An electronic device, characterized in that: The electronic device comprises: A first processing tool is configured to obtain input data, wherein the input data includes a plurality of operators, the plurality of operators include at least one operator type, and the first processing tool includes an operator splitting function, the operator splitting function is used to split operators of a first type among the plurality of operators; a processing device configured to disable an operator splitting function in the first processing tool; a target compiler configured to obtain input data processed by the first processing tool, wherein the input data processed by the first processing tool only includes a plurality of unsplit operators, and the target compiler is provided with a second processing tool; The target compiler is further configured to call the second processing tool to fuse at least two operators of the plurality of operators to obtain a first fused operator, wherein the at least two operators have the same operator type or different operator types, The second processing tool is provided with a graph matching paradigm, and the target compiler is further configured to: use the graph matching paradigm in the second processing tool to perform graph matching mapping on the at least two operators to be fused to obtain the first fusion operator, The target compiler is further provided with a third processing tool and a fourth processing tool, and the target compiler is further configured as follows: Using the third processing tool, splitting at least two unfused operators of the first type among the plurality of operators into a plurality of split operators; The plurality of split operators are fused using the fourth processing tool to obtain a second fused operator.

10. An electronic device, characterized in that: The electronic device comprises: one or more processors; one or more memories including one or more computer program modules; The one or more computer program modules are stored in the one or more memories and are configured to be executed by the one or more processors, and the one or more computer program modules are used to implement the operator fusion method according to any one of claims 1 to 8.

11. A storage medium, characterized in that: The storage medium stores non-transitory computer-readable instructions, and when the non-transitory computer-readable instructions are executed by a computer, the operator fusion method according to any one of claims 1 to 8 is implemented.

Citation Information

Patent Citations

  • Neural network compiler configuration method and device, computer equipment and storage medium

    CN113703741A

  • Operator fusion method and device, electronic equipment and storage medium

    CN116523023A