A control flow graph processing method and related equipment
By compiling source code in the deep learning framework and generating control flow diagrams, segmenting and connecting linear execution sequences, the inefficiency problem of artificially analyzing source code logical relationships in the existing technology is solved, and more efficient and accurate neural network structure processing is achieved.
Patent Information
- Application Number
- CN202010230463.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-03-27
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2040-03-27
AI Technical Summary
When handling complex neural network structures, existing deep learning frameworks need to artificially parse the logical relationships inside the source code, resulting in low performance, error-prone and time-consuming.
Multiple linear execution sequences are obtained by compiling the source code in a deep learning framework, generating a control flow graph, and segmenting it at including nonlinear semantics. These sequences are then executed by simulation and inserting control operators and assignment operators, which are connected into calculation diagrams that can be directly identified by the device.
This method avoids the steps of artificially parsing the source code, reduces the error rate and processing time, improves the processing efficiency of the device, and makes the processing of neural network structures faster and more accurate.
Smart Images

Figure CN113449856B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of deep learning, and in particular to a control flow graph processing method and related equipment. Background Art
[0002] With the rapid development of artificial intelligence, deep learning has also been widely used, such as image recognition, speech recognition, autonomous driving, etc. In order to meet the growing demand for neural networks, deep learning frameworks have emerged. Through deep learning frameworks, researchers only need to focus on the deep learning network structure and complete a complex deep learning network structure by writing simple source code (such as Python language), thereby realizing model reasoning and training on hardware.
[0003] There are many existing deep learning frameworks (such as tensorflow, pytorch, mxnet, etc.). In order to quickly use deep learning to solve new problems, it is essential to choose a deep learning framework. Different deep learning frameworks support different capabilities. Most of the existing deep learning frameworks are based on source code such as python language to write scripts for training networks. As the structure of neural networks becomes more and more complex, the semantics of the source code that deep learning frameworks need to support are also becoming more and more complex.
[0004] However, most current deep learning frameworks can only determine the complete neural network structure expressed by the entire source code by manually parsing the logical relationships within the source code. This processing method has low performance, is prone to errors, and is time-consuming. Summary of the invention
[0005] The embodiments of the present application provide a control flow graph processing method and related equipment, which are used to insert at least one operator (such as a control operator, an assignment operator, etc.) into multiple linear execution sequences to connect the multiple linear execution sequences into a calculation graph that can be directly recognized by a device, which is not prone to errors and is convenient and fast.
[0006] Based on this, the embodiments of the present application provide the following technical solutions:
[0007] In the first aspect, the present application first provides a control flow graph processing method, which can be used in the field of artificial intelligence. The method includes: first, if the user decides which neural network to use (such as a convolutional upgrade network), the source code can be input through the deep learning framework. The source code is the structure of the neural network formed by the user by writing a simple high-level language (such as a python script). After that, the input source code is compiled by the deep learning framework to obtain a control flow graph corresponding to the source code. After the deep learning framework obtains the control flow graph corresponding to the source code, it will segment the control flow graph at the nonlinear semantics to obtain multiple subgraphs after segmentation. There is no control dependency between the subgraphs. The subgraph refers to a graph in which the node set and the edge set are respectively a subset of the node set and the edge set of a certain graph. The subgraph can also be called a node series, that is, a node sequence that can be executed in sequence according to the input to obtain the execution result. By recompiling the subgraphs obtained after segmentation, multiple linear execution sequences can be obtained. The multiple linear execution sequences obtained have no data dependencies and cannot be executed separately on the deep learning framework. Then, the deep learning framework simulates the execution of each linear execution sequence, thereby identifying the semantics represented by the source code corresponding to each linear execution sequence, and inserting at least one operator between each linear execution sequence according to the semantics of each linear execution sequence. The operator described in the embodiment of the present application refers to the mapping from one function space to another function space supported by the device. Among them, the deep learning framework can identify the semantics of these linear execution sequences based on the semantic rules of the source code during the simulation and execution of the multiple linear execution sequences. That is, the deep learning framework understands which part of the program logic described by the source code corresponds to each of the split linear execution sequences by simulating the execution process. When the type of source code is determined, the semantic rules of the source code are determined. Specifically, the control operator indicates to jump from one linear execution sequence to another linear execution sequence according to the meaning of the control semantics in the semantic rules; the assignment operator indicates to assign the address of the output data of one linear execution sequence to the address of the input data of another linear execution sequence. In this way, each isolated linear execution sequence is connected into a computational graph in the manner described above, and the computational graph can be directly recognized by a device (such as an AI chip).
[0008] In the above-mentioned implementation mode of the present application, the source code is compiled through a deep learning framework to obtain a control flow graph, and then the control flow graph is segmented and recompiled to obtain a linear execution sequence supported by multiple devices (there is no control dependency between the multiple linear execution sequences). Finally, each linear execution sequence is simulated and executed on the deep learning framework, and operators are inserted between each linear execution sequence according to the semantics of each linear execution sequence, so as to connect each linear execution subsequence into a calculation graph that can be directly recognized by the device. This calculation graph describes a complete neural network structure. This processing method avoids manually parsing the logical relationship within the source code to determine the neural network structure expressed by the entire source code. It is not easy to make mistakes, and it is convenient and fast, thereby improving the processing efficiency of the device.
[0009] In conjunction with the first aspect of the embodiment of the present application, in a first implementation of the first aspect of the embodiment of the present application, if there is a data dependency relationship between one linear execution sequence and another linear execution sequence, for example, the output data of the linear execution sequence a1 is the input data of the linear execution sequence a2, then it is necessary to insert an assignment operator (also referred to as an assign operator) after the linear execution sequence a1, and the assignment operator is used to assign the address of the output data of the linear execution sequence a1 to the address of the input data of the linear execution sequence a2. The linear execution sequence a1 and the linear execution sequence a2 both belong to the multiple linear execution sequences described above.
[0010] In the embodiment of the present application, it is explained how to connect at least two linear execution sequences through an assignment operator, which is operable.
[0011] In combination with the first aspect of the embodiment of the present application and the first implementation method of the first aspect of the embodiment of the present application, in the second implementation method of the first aspect of the embodiment of the present application, if the deep learning framework determines according to the semantic rules of the source code that the linear execution sequence that has been simulated and executed is a linear execution sequence that includes control semantics, then it is necessary to insert a control operator (which may be called a first control operator) after the linear execution sequence. The control operator is used to jump from the linear execution sequence that has been simulated and executed to one or more other linear execution sequences. How the deep learning framework determines which other one or more linear execution sequences to jump to is pointed to by the pointers of each linear execution sequence.
[0012] It should be noted that, in the embodiments of the present application, inserting control operators and inserting assignment operators between various linear execution sequences according to the semantics of the source code does not conflict, that is, the control operator can be inserted only after the linear execution sequence including the control semantics. If the output data of the linear execution sequence also needs to be used as the input data of other linear execution sequences, then the assignment operator can also be inserted after the linear execution sequence; if the current linear execution sequence does not include control semantics, but the output data of the linear execution sequence needs to be used as the input data of other linear execution sequences, then it is only necessary to insert the assignment operator after the linear execution sequence. The specific details are not limited here.
[0013] In the embodiment of the present application, it is explained how to connect at least two linear execution sequences through a control operator, and another type of inserted operator is provided with flexibility.
[0014] In combination with the second implementation method of the first aspect of the embodiment of the present application, in the third implementation method of the first aspect of the embodiment of the present application, after the deep learning framework simulates the execution of the current linear execution sequence (the current linear execution sequence is an execution sequence with conditional judgment semantics (such as, an if statement with conditional judgment semantics)), a control operator corresponding to the conditional judgment semantics is inserted after the current linear execution sequence, and then jumps to multiple other linear execution sequences pointing to multiple branches that are connected to the current linear execution sequence through the control operator.
[0015] In combination with the second implementation of the first aspect of the embodiment of the present application, in the fourth implementation of the first aspect of the embodiment of the present application, after the deep learning framework simulates and executes the current linear execution sequence (the current linear execution sequence is an execution sequence with loop semantics (such as a while statement with loop semantics)), a control operator corresponding to the loop semantics is inserted after the current linear execution sequence, and then jumps to the loop structure (i.e., the second linear execution sequence) connected to the current linear execution sequence through the control operator and pointing to the corresponding current linear execution sequence, and a jump operator (also referred to as a second control operator or an active operator) is inserted after the second linear execution sequence, and the active operator is used to loop the execution sequence and loop structure with loop semantics until the output data of the loop structure meets the preset value. At this time, the preset value meets the condition of no longer looping, and the loop execution is stopped. The first linear execution sequence and the loop structure constitute a loop body. The loop structure refers to a program structure set up for repeatedly executing a certain function in the program. It determines whether to continue to execute a certain function or exit the loop based on the condition in the loop body (i.e., the first linear execution sequence).
[0016] In the embodiments of the present application, it is specifically explained how to insert a control operator when encountering a linear execution series with control semantics (such as if statements and while statements), taking into account the actual application situation and being operable.
[0017] In combination with the first aspect of the embodiment of the present application, and the first to fourth implementations of the first aspect, in the fifth implementation of the first aspect of the embodiment of the present application, each linear execution sequence is simulated and executed in sequence through a deep learning framework, and at least one operator is inserted between each linear execution sequence according to the semantics of each linear execution sequence. There are multiple specific implementation methods, including but not limited to the following: a. After all linear execution sequences are simulated and executed, operators are uniformly inserted between each linear execution sequence. That is, after the deep learning framework obtains multiple linear execution sequences by recompiling multiple subgraphs, it first simulates and executes all the obtained linear execution sequences. After all these linear execution sequences are simulated and executed, it is judged whether an operator needs to be inserted after each linear execution sequence and what type of operator needs to be inserted according to the semantics of each linear execution sequence. b. Each time a linear execution sequence is simulated and executed, it is judged whether an operator needs to be inserted after the linear execution sequence and what type of operator needs to be inserted. That is, after the deep learning framework obtains multiple linear execution sequences by recompiling multiple subgraphs, it can determine whether it is necessary to insert an operator after this linear execution sequence after each simulated execution of a linear execution sequence. If it is necessary to insert an operator after this linear execution sequence, the semantics of the current linear execution sequence is determined according to the semantic rules of the source code, and it is determined what type of operator needs to be inserted after the current linear execution sequence.
[0018] In the embodiments of the present application, the order between the deep learning framework simulating the execution of linear execution sequences and interpolating operators is specifically explained, that is, all linear execution sequences can be simulated and executed before interpolating operators, or operators can be interpolated while simulating execution, which has flexibility.
[0019] In combination with the first aspect of the embodiment of the present application, and the first to fifth implementation methods of the first aspect, in the sixth implementation method of the first aspect of the embodiment of the present application, the specific processing method for the deep learning framework to insert at least one operator between the multiple linear execution sequences mentioned above according to the semantics of each linear execution sequence may be: first, an instruction set is generated according to the semantics of each linear execution sequence, the instruction set includes multiple instructions, and each instruction of the multiple instructions is used to instruct the deep learning framework to insert at least one operator between the multiple linear execution sequences.
[0020] In the embodiment of the present application, it is explained that the insertion operator is indicated by an instruction in the instruction set, which is feasible.
[0021] In combination with the first aspect of the embodiment of the present application, the first to sixth implementations of the first aspect, in the seventh implementation of the first aspect of the embodiment of the present application, the deep learning framework can be located at the first node of the device, and the first node can send the obtained calculation graph to the second node located at the same device through the deep learning framework, or it can be sent to the second node located at a different device. Specifically, when the second node needs to execute data, the calculation graph can be obtained from the deep learning framework, or the deep learning framework can connect multiple linear execution sequences into a calculation graph and then send it to the second node. The specific method of sending the calculation graph to the second node is not limited here. When the second node is located on a different device, the second node can be the device itself, for example, an independent server.
[0022] In the embodiments of the present application, several processing methods of the obtained calculation graph are described, which are flexible.
[0023] In combination with the first aspect of the embodiment of the present application and the first to seventh implementation methods of the first aspect, in the eighth implementation method of the first aspect of the embodiment of the present application, the deep learning framework can specifically be any one of mindspore, tensorflow, pytorch, mxnet, caffe or theano.
[0024] In combination with the first aspect of the embodiment of the present application, the first to eighth implementations of the first aspect, in the ninth implementation of the first aspect of the embodiment of the present application, the device for acquiring the computational graph may be an AI chip, which is also referred to as an AI accelerator or computing card, i.e., a module for processing a large number of computing tasks in artificial intelligence applications. For example, the AI chip described in the embodiment of the present application may be a GPU, FPGA, ASIC, etc. without a CPU (other non-computing tasks are handled by the CPU), or an AI chip of the Ascend series (such as Ascend 910), or an AI chip with an independent AI CPU. The type of AI chip is not limited here.
[0025] The second aspect of the embodiment of the present application provides a deep learning framework, which has the function of implementing the method of the first aspect or any possible implementation of the first aspect. The function can be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions.
[0026] The third aspect of the embodiments of the present application provides an execution device, which may include a memory, a processor, and a bus system, wherein the memory is used to store programs, and the processor is used to call the programs stored in the memory to execute the method of the first aspect of the embodiments of the present application or any possible implementation method of the first aspect.
[0027] A fourth aspect of the present application provides a computer-readable storage medium, which stores instructions. When the computer-readable storage medium is run on a computer, the computer can execute the method of the first aspect or any possible implementation of the first aspect.
[0028] A fifth aspect of an embodiment of the present application provides a computer program, which, when executed on a computer, enables the computer to execute the method of the first aspect or any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 A schematic diagram of the structure of the artificial intelligence main framework provided in the embodiment of the present application;
[0030] Figure 2 A schematic diagram of a control flow graph processing method provided in an embodiment of the present application;
[0031] Figure 3 A schematic diagram of a control flow graph of an embodiment of the present application being divided into multiple sub-graphs;
[0032] Figure 4 A schematic diagram of how multiple linear execution sequences are connected into a large execution sequence according to an embodiment of the present application;
[0033] Figure 5 It is a schematic diagram of how to connect multiple linear execution sequences into a large execution sequence when the control semantics is an if statement in the embodiment of the present application;
[0034] Figure 6 A schematic diagram of connecting multiple linear execution sequences into a large execution sequence in an embodiment of the present application;
[0035] Figure 7 It is a schematic diagram of how to connect multiple linear execution sequences into a large execution sequence when the control semantics is a while statement in an embodiment of the present application;
[0036] Figure 8 Another schematic diagram of connecting multiple linear execution sequences into a large execution sequence in an embodiment of the present application;
[0037] Fig. 9 Another schematic diagram of connecting multiple linear execution sequences into a large execution sequence in an embodiment of the present application;
[0038] Fig.10 A schematic diagram of a deep learning framework in an embodiment of the present application;
[0039] Fig.11 A schematic diagram of an execution device in an embodiment of the present application. DETAILED DESCRIPTION
[0040] The embodiments of the present application provide a control flow graph processing method and related devices, which are used to insert corresponding operators (such as control operators, assignment operators, etc.) into multiple linear execution sequences, and connect the multiple linear execution sequences into a calculation graph that can be directly recognized by a device through operators (such as compiling source code written in a high-level language into an assembly language supported by the device through a deep learning framework), so that the device does not need to frequently obtain each linear execution sequence.
[0041] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0042] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0043] First, the overall workflow of the artificial intelligence system is described. Figure 1 , Figure 1 The figure shows a structural diagram of the main framework of artificial intelligence. The following is an explanation of the above artificial intelligence theme framework from the two dimensions of "intelligent information chain" (horizontal axis) and "IT value chain" (vertical axis). Among them, the "intelligent information chain" reflects a series of processes from data acquisition to processing. For example, it can be a general process of intelligent information perception, intelligent information representation and formation, intelligent reasoning, intelligent decision-making, intelligent execution and output. In this process, the data has undergone a condensation process of "data-information-knowledge-wisdom". The "IT value chain" reflects the value that artificial intelligence brings to the information technology industry from the underlying infrastructure of human intelligence, information (providing and processing technology implementation) to the industrial ecology process of the system.
[0044] (1) Infrastructure
[0045] The infrastructure provides computing power support for the artificial intelligence system, enables communication with the outside world, and supports it through the basic platform. Communicate with the outside world through sensors; computing power is provided by smart chips, that is, the AI chips mentioned above (CPU, NPU, GPU, ASIC, FPGA and other hardware acceleration chips). In the embodiment of this application, smart chips also include AI chips of the Ascend series (such as Ascend 910); the basic platform includes distributed computing frameworks and networks and other related platform guarantees and support, which may include cloud storage and computing, interconnected networks, etc. For example, sensors communicate with the outside world to obtain data, and these data are provided to the smart chips in the distributed computing system provided by the basic platform for calculation.
[0046] (2) Data
[0047] The data on the upper layer of the infrastructure is used to represent the data sources in the field of artificial intelligence. The data involves graphics, images, voice, text, and IoT data of traditional devices, including business data of existing systems and perception data such as force, displacement, liquid level, temperature, and humidity.
[0048] (3) Data processing
[0049] Data processing usually includes data training, machine learning, deep learning, search, reasoning, decision-making and other methods.
[0050] Among them, machine learning and deep learning can symbolize and formalize data for intelligent information modeling, extraction, preprocessing, and training.
[0051] Reasoning refers to the process of simulating human intelligent reasoning in computers or intelligent systems, using formalized information to perform machine thinking and solve problems based on reasoning control strategies. Typical functions are search and matching.
[0052] Decision-making refers to the process of making decisions after intelligent information is reasoned, usually providing functions such as classification, sorting, and prediction.
[0053] (4) General ability
[0054] After the data has undergone the data processing mentioned above, some general capabilities can be further formed based on the results of the data processing, such as an algorithm or a general system, for example, translation, text analysis, computer vision processing, speech recognition, image recognition, etc.
[0055] (5) Smart products and industry applications
[0056] Smart products and industry applications refer to the products and applications of artificial intelligence systems in various fields. They are the encapsulation of the overall artificial intelligence solution, which productizes intelligent information decision-making and realizes practical application. Its application areas mainly include: smart terminals, smart manufacturing, smart transportation, smart homes, smart medical care, smart security, autonomous driving, safe cities, etc.
[0057] This application can be applied to various fields of artificial intelligence (such as image processing, computer vision, semantic analysis, etc.), specifically, combined with Figure 1 Generally speaking, the control flow graph processing method in the embodiment of the present application belongs to a specific data processing method in the above-mentioned "(3) data processing". The control flow graph processing method is applied to a deep learning framework, and the control flow graph is processed into a computational graph that can be recognized by the intelligent chip through the deep learning framework (for example, the control flow graph written in a high-level language is compiled into a computational graph in a low-level language supported by the intelligent chip).
[0058] Since the processing method of the control flow graph in the embodiment of the present application is applied to the deep learning framework, before introducing the embodiment of the present application, the deep learning framework involved in the present application is first introduced. The processing flow of the deep learning framework generally includes: converting the data to be processed into data that can be processed by the deep learning framework, and its data format can be in various forms such as tensors. For example, the data to be processed can be image data involved in the field of image processing (such as, it can be obtained by taking pictures by a mobile terminal camera), or video data involved in the field of computer vision (such as, it can be taken by a monitoring system), or some text data obtained (such as, text information input by a user through a terminal device), which is not limited here. Apply various required operations to the tensor, train the model through automatic differentiation, and then get the output result to start testing. Since most of the early deep learning frameworks for the above-mentioned processing flow are based on high-level languages (such as Java, Python, Lua, etc.), and even if the simplest operation is performed, the high-level language will consume more CPU cycles than the low-level language, not to mention the complex structure of the deep neural network, so slow operation has become a natural defect of the high-level language. There are two solutions to this problem: 1) The first method is to simulate the traditional compiler. Just like traditional compilers compile high-level languages into assembly languages for specific platforms to achieve efficient operation, this method converts high-level languages into low-level languages (such as C language), and then compiles and executes them based on C language. Among them, high-level language is a machine-independent, process-oriented or object-oriented language. It is programming that is closer to natural language and mathematical formulas. It is basically separated from the hardware system of the machine and programs are written in a way that is easier for people to understand. The written program is called a source program. Low-level language refers to a program language or instruction code that can be directly recognized by the machine without translation. Each instruction code has a corresponding circuit inside the computer to complete it, or it refers to a program language or instruction code that can be directly understood and accepted by the machine without translation. In order to achieve this conversion, the implementation code of each tensor operation will be pre-added with the conversion part of C language, and then the compiler will combine these tensor operations implemented by C language together during the compilation stage. 2) The second method is to use scripting languages to implement front-end modeling and use low-level languages such as C++ to implement back-end operation. This means that the interaction between high-level languages and low-level languages occurs within the deep learning framework. Therefore, each change to the back-end does not require modification of the front-end or full compilation (only partial compilation by modifying the compilation parameters is required), so the overall speed is faster.
[0059] For the embodiment of the present application, the deep learning framework of the second solution is adopted, that is, the user first establishes a neural network model by writing source code, and then compiles the source code into an assembly language that can be recognized by the back-end device (such as an AI chip) through the deep learning framework, thereby improving the overall speed of the deep learning framework. It should be noted that the deep learning framework used in the control flow graph processing method in the embodiment of the present application can be any deep learning framework that meets the above requirements, for example, it can be any one of mindspore, tensorflow, pytorch, mxnet, caffe or theano.
[0060] Next, we will introduce the processing method of the control flow graph provided in the embodiment of the present application. Figure 2 :
[0061] 201. Compile the source code to obtain a control flow graph corresponding to the source code.
[0062] First, once the user has decided which neural network to use (e.g., convolutional neural network), the source code can be input through the deep learning framework. The source code is the structure of the neural network formed by the user by writing a simple high-level language (e.g., python script). After that, the input source code is compiled through the deep learning framework to obtain the control flow graph corresponding to the source code. Here we need to explain what a control flow graph is. A control flow graph is also called a control flow chart. It is an abstraction of the branch jump relationship in a program. It describes all possible execution paths of the program. The nodes of the control flow graph are statement sets. The edge from A to B indicates that statement B may be executed directly after statement A is executed.
[0063] 202. Split the control flow graph to obtain multiple sub-graphs.
[0064] After the deep learning framework obtains the control flow graph corresponding to the source code, it will split the control flow graph at the nonlinear semantics to obtain multiple subgraphs after segmentation. There is no control dependency between the subgraphs. Here we also need to explain what a subgraph is. A subgraph refers to a graph whose node set and edge set are respectively a subset of the node set and edge set of a certain graph. A subgraph can also be called a node series, that is, a node sequence that can be executed in sequence according to the input to obtain the execution result. Figure 3 Take this as an example: Assume Figure 3 The figure shows a control flow graph, where each circle represents a node (i.e., a basic block), and the nodes ( Figure 3 The arrows in Figure 1 indicate the direction of data flow, and the control flow graph can be divided into three subgraphs, as shown in Figure 1. Figure 3 The child shown Figure 1 ,son Figure 2 ,son Figure 3 , among which Figure 1 It consists of node 1, node 2, node 3 and the data flow between these three nodes. Figure 2 It consists of node 1, node 4 and the data flow between these two nodes. Figure 3 It consists of node 1, node 5, node 6 and the data flow between these three nodes.
[0065] 203. Compile multiple subgraphs to obtain multiple linear execution sequences.
[0066] By recompiling the subgraphs obtained after segmentation, multiple linear execution sequences can be obtained. Since the subgraphs are directly segmented from the control flow graph, similar to the control flow graph, at this time, the subgraphs can only be recognized by the deep learning framework, but devices such as AI chips cannot directly recognize each subgraph. Each subgraph needs to be recompiled through the deep learning framework to obtain multiple linear execution sequences that the device can recognize. In other words, the difference between subgraphs and linear execution sequences is that the linear execution sequence is a logical structure compiled in a machine language that can be recognized by the device, while the subgraph is a logical structure compiled in a machine language that can only be recognized by the deep learning framework but not directly by the device. A sequence in which all nodes in the linear structure can be arranged according to the order of their execution is called a linear execution sequence. There is no control dependency between each linear execution sequence, but only data dependency.
[0067] 204. Simulate and execute multiple linear execution sequences in sequence, and insert at least one operator between each linear execution sequence according to the semantics of each linear execution sequence.
[0068] After recompiling the subgraphs obtained after segmentation to obtain multiple linear execution sequences, since the multiple linear execution sequences obtained have no data dependencies and cannot be executed separately on the deep learning framework, the deep learning framework can be further used to simulate and execute each linear execution sequence in sequence. According to the semantic rules of the source code, the semantics represented by the source code corresponding to each linear execution sequence is identified during the simulation execution process, and at least one operator is inserted into each linear execution sequence according to the semantics. The operator described in the embodiment of the present application refers to the mapping from one function space to another function space supported by the device. Specifically, a control operator refers to an operation that jumps from one linear execution sequence to another linear execution sequence according to the meaning of the control semantics in the semantic rules; an assignment operator refers to an operation that assigns the address of the output data of one linear execution sequence to the address of the input data of another linear execution sequence.
[0069] It should be noted that the deep learning framework simulates the execution process of each linear execution sequence in order to identify the semantic rules of the source code, based on which the semantics contained in each linear execution code can be further identified. The simulation execution process does not change the structure of the linear execution sequence.
[0070] It should be noted that, in some embodiments of the present application, sequentially simulating and executing each linear execution sequence through a deep learning framework, and inserting at least one operator between each linear execution sequence according to the semantics of each linear execution sequence may be implemented in a variety of ways, including but not limited to the following:
[0071] a. After all the linear execution sequences are executed in the simulation, operators are uniformly inserted between the linear execution sequences.
[0072] After the deep learning framework obtains multiple linear execution sequences by recompiling multiple subgraphs, it first simulates the execution of all these linear execution sequences. After simulating the execution of all these linear execution sequences, it determines whether an operator needs to be inserted after each linear execution sequence and what type of operator needs to be inserted based on the semantics of each linear execution sequence.
[0073] b. After each simulation completes a linear execution sequence, it is determined whether an operator needs to be inserted after the linear execution sequence and what type of operator to insert.
[0074] After the deep learning framework obtains multiple linear execution sequences by recompiling multiple subgraphs, it can determine whether it is necessary to insert an operator after this linear execution sequence after each simulation is completed in sequence. If an operator needs to be inserted after this linear execution sequence, the type of operator that needs to be inserted after the current linear execution sequence is determined based on the semantics of the current linear execution sequence.
[0075] It should be noted that, in some embodiments of the present application, the specific processing method for the deep learning framework to insert at least one operator between the multiple linear execution sequences mentioned above according to the semantics of each linear execution sequence may be: first, an instruction set is generated according to the semantics of each linear execution sequence, and the instruction set includes multiple instructions, and each instruction of the multiple instructions is used to instruct the deep learning framework to insert at least one operator between the multiple linear execution sequences.
[0076] It should also be noted that in some embodiments of the present application, according to the semantic rules of the source code, the semantics contained in each linear execution sequence may be different, so the operator type to be inserted after each linear execution sequence is also different, including but not limited to the following methods:
[0077] A. Insert control operators according to the semantic rules of the source code.
[0078] Taking the above-mentioned situation where each time a linear execution sequence is simulated and executed, it is determined whether an operator needs to be inserted after the linear execution sequence and what type of operator to insert as an example, if the deep learning framework determines according to the semantic rules of the source code that the linear execution sequence that has been simulated and executed is a linear execution sequence that includes control semantics, then it is necessary to insert a control operator (which can be called the first control operator). The control operator is used to jump from the linear execution sequence that has been simulated and executed to one or more other linear execution sequences. How the deep learning framework determines which other one or more linear execution sequences to jump to is pointed to by the pointers of each linear execution sequence.
[0079] It should be noted here that although the control operator is inserted after the linear execution sequence including the control semantics, the specific execution method of inserting the operator is slightly different when the control semantics are different. The following is an example of an if statement and a while statement with control semantics:
[0080] a. When the control semantics is conditional judgment semantics.
[0081] Taking the if statement with conditional judgment semantics as an example, after the deep learning framework simulates and executes the current linear execution sequence (the current linear execution sequence is an execution sequence with the control semantics of the if statement), the control operator corresponding to the if statement is inserted after the current linear execution sequence, and then jumps to multiple other linear execution sequences pointing to multiple branches connected to the current linear execution sequence through the control operator.
[0082] For ease of understanding, the following example is used to illustrate: Figure 4 As shown, first, the deep learning framework will traverse all paths of the entire control flow graph obtained by compiling the source code, and split it when encountering a control node, thereby splitting the control flow graph into various subgraphs (also called node series), and compiling each subgraph again to obtain various linear execution sequences that can be executed by the device. At the same time, a graph number and an ID number will be generated for each linear execution sequence, where the graph number is used by the deep learning framework to identify each linear executable sequence, and the ID number is used by the device to identify each linear executable sequence. The deep learning framework will generate an instruction set while splitting and compiling the entire control flow graph. Each instruction in the instruction set is used by the deep learning framework to insert the corresponding control operator when simulating the execution of each linear execution sequence in sequence. When the control semantics is an if statement, a linear execution sequence that can execute the correct branch in sequence after the linear execution sequence is generated (such as Figure 4 The truegraph in ) and the linear execution sequence of the error branch (such as Figure 4) (it can also be an instruction that generates a linear execution sequence that can execute the error branch and the correct branch in sequence, or even execute them simultaneously, which is not limited here). Specifically, the simulation execution process can be: first simulate the execution of the cond node, set true to execute the true graph for the first time, obtain the graph number of the true graph, return the switch instruction, execute the cond node (the cond node represents the representation compiled in the control flow graph when there is a conditional statement such as <……>, etc.), set it to false to execute the false graph, obtain the graph number of the false graph, use the cond node as a connection, save the graph number of the linear execution sequence where the cond corresponding to the cond node is located, the graph number of the true graph and the graph number of the true graph, execute the switch end instruction after the false graph is executed, call the interface, and insert the control operator (such as the switch operator). Since the if statement is a statement with conditional judgment semantics, the conditional judgment semantics generally has two branches of judgment results (i.e., the true graph and the false graph), then the switch operator is inserted after the linear execution series including the cond node, and cooperates with the cond node to connect the linear execution sequence where the cond is located, the true graph, and the false graph. Similarly, according to the execution principle described above, all linear execution sequences with control semantics are connected into a large execution sequence consisting of multiple streams through the switch operator.
[0083] To further facilitate understanding, the following example is used to illustrate: Figure 5 As shown in the figure, the control flow graph with the control semantics of the if statement will be compiled into four subgraphs during the compilation process, namely the switch graph, the true branch subgraph, the false branch subgraph, and the after subgraph. These four subgraphs will form four linear executable sequences after recompilation, as shown in Figure 5 The test_if graph, true graph, false graph and after graph shown in the figure are shown in the figure. In some embodiments, the after graph is automatically merged into the true graph or false graph according to the conditions, which is not limited here. After recompiling each subgraph, an instruction set for simulating the execution of a linear execution sequence is generated, and each linear execution sequence is simulated and executed in sequence according to the instruction set. Figure 5For example, if it is assumed that the after graph has been integrated into the true graph, the generated switch instruction is: switch(cond=true)->call true graph->exec true graph->return output->switch return (switch processing returns to the original function call stack)->switch(cond=false)->callfalse graph+exec false graph->set switch graph (according to the current cond, connect the three linear execution sequences of the current cond). Afterwards, the deep learning framework executes the switch instruction in the above order, sets the input (the address of the input data) for the current graph when calling the graph, inserts the assignment operator (also called the assign operator) after the input node, and after executing the false graph, connects the cond graph and the three linear execution sequences of the true graph and the false graph. After all the linear execution sequences are simulated and executed, the large execution sequence (i.e., a computational graph) that can be executed on a device (such as an AI chip) is obtained by connecting the final linear execution sequences. The large execution sequence can be as follows Figure 6 As shown, at this time, the large execution sequence can be directly identified by the device, and the device identifies the execution order between sequences through the ID numbers of each linear execution sequence.
[0084] b. When the control semantics is loop semantics.
[0085] Taking the while statement with loop semantics as an example, after the deep learning framework simulates and executes the current linear execution sequence (the current linear execution sequence is an execution sequence with the control semantics of the while statement), a control operator corresponding to the while statement is inserted after the current linear execution sequence, and then jumps to other linear execution sequences with loop semantics that are connected to the current linear execution sequence through the control operator, and a jump operator (also called a second control operator or an active operator) is inserted after the linear execution sequence with loop semantics. The active operator is used to loop execute the above-mentioned execution sequence with the control semantics of the while statement and the linear execution sequence with loop semantics until the output data of the linear execution sequence with loop semantics meets the preset value. At this time, the preset value meets the condition for no longer looping, and the loop execution is stopped.
[0086] For ease of understanding, the following example is used to illustrate: Figure 7As shown in the figure, the control flow graph with the control semantics of the while statement will be compiled into four subgraphs during the compilation process. The while conditional judgment statement generates a switch node. The subgraph where the switch node is located is recompiled into a header graph. The subgraph where the while execution body statement node is located is recompiled into a bodygraph. The subgraph where the after statement node is located is recompiled into an after graph. The process is the same as the if statement. After the graph is split, all subgraphs are compiled into isolated linear execution sequences that can be executed on the device, that is, Figure 7 After recompiling each subgraph, an instruction set for simulating the execution of a linear execution sequence is generated, and each linear execution sequence is simulated and executed in sequence according to the instruction set. Figure 7 For example, the generated switch instruction is: switch(cond=true)+call body graph->exec body graph->body graph call switch graph->switch(true)(insert active operator)->switch return+switch(cond=false)+call after graph(->exec after graph. During simulation execution, if and while use different switch instructions to return to the original switch stack. If uses return to return. When while needs to call back the header graph in the true graph, the active operator is inserted in the switch instruction execution function to connect the header graph and the body graph, and the active operator is inserted at the last node of the body graph to achieve a loop effect. The remaining process is similar to the processing process of if, which will not be repeated here.
[0087] It should be noted that in some embodiments of the present application, if there is a nested relationship, and an if statement or a while statement is encountered in the nested relationship, the compilation and execution are performed as described above, and all isolated linear execution sequences are connected into a large execution sequence. The large execution sequence can be as follows: Figure 8 As shown, at this time, the large execution sequence can be directly identified by the device, and the device identifies the execution order between sequences through the ID numbers of each linear execution sequence.
[0088] Currently, users manually parse the logical relationship within the source code to determine the complete neural network structure expressed by the entire source code. For example, if you want to implement the control semantics of the while statement, take the deep learning framework MindSpore as an example. The original while statement written under MindSpore is as follows:
[0089]
[0090] By using the control flow graph processing method described in this application, the user can directly write according to the semantic rules of the source code in MindSpore. The written if statements and while statements are as follows:
[0091]
[0092] B. Insert assignment operators according to the semantic rules of the source code.
[0093] Still taking the above-mentioned case where each time a linear execution sequence is simulated and executed, it is determined whether an operator needs to be inserted after the linear execution sequence and what type of operator to insert as an example, if there is a data dependency relationship between one linear execution sequence and another linear execution sequence, for example, the output data of linear execution sequence a1 is the input data of linear execution sequence a2, then it is necessary to insert an assignment operator (also called assign operator) after the linear execution sequence a1. The assignment operator is used to assign the address of the output data of linear execution sequence a1 to the address of the input data of linear execution sequence a2. Specifically, when the control flow graph is split, the data of each linear subgraph is connected to each other through parameter. The output of a subgraph may be the input of multiple other subgraphs. When simulation execution is required, the assignment operator is inserted into the output when the exec instruction is executed to connect the data dependencies between subgraphs. The specific operation process is as follows: during simulation execution, where the main graph calls the subgraph, the output node (i.e. node) of the previous graph and the parameter node in the subgraph are set together, and set_input is called to insert the assign operator after the node of the previous graph, and the output node is assigned to the parameter node of the called subgraph to complete the connection between the graphs. After the subgraph connection is completed, an output is set for the global execution result. If the last graph executed is the switch graph, the assign operator is added to the last node of the true graph and the false graph, and the value of the output data is assigned to the output. The final connected large execution sequence is as follows: Fig. 9As shown, at this time, the large execution sequence can be directly identified by the device, and the device identifies the execution order between sequences through the ID numbers of each linear execution sequence.
[0094] It should be noted that, in the embodiments of the present application, inserting control operators and inserting assignment operators between various linear execution sequences according to the semantics of the source code does not conflict, that is, the control operator can be inserted only after the linear execution sequence including the control semantics. If the output data of the linear execution sequence also needs to be used as the input data of other linear execution sequences, then the assignment operator can also be inserted after the linear execution sequence; if the current linear execution sequence does not include control semantics, but the output data of the linear execution sequence needs to be used as the input data of other linear execution sequences, then it is only necessary to insert the assignment operator after the linear execution sequence. The specific details are not limited here.
[0095] 205. A computational graph formed by connecting multiple linear execution sequences is obtained.
[0096] By connecting each isolated linear execution sequence into a computational graph in the manner described above, the computational graph can be directly recognized by a device (e.g., an AI chip).
[0097] It should be noted that the obtained calculation graph can be sent to the device. Specifically, when the device needs to execute data, the calculation graph can be obtained from the deep learning framework, or the deep learning framework can connect multiple linear execution sequences into a calculation graph and then send it to the device. The specific way in which the calculation graph is sent to the device is not limited here.
[0098] In the above-mentioned implementation mode of the present application, the source code is compiled through a deep learning framework to obtain a control flow graph, and then the control flow graph is segmented and recompiled to obtain a linear execution sequence supported by multiple devices (there is no control dependency between the multiple linear execution sequences). Finally, each linear execution sequence is simulated and executed on the deep learning framework, and the semantics corresponding to each linear execution sequence is identified during the simulation execution process. Operators are inserted between each linear execution sequence according to the semantics, so that each linear execution subsequence is connected into a calculation graph that can be directly recognized by the device. This calculation graph describes a complete neural network structure. This processing method avoids manually parsing the logical relationship within the source code to determine the neural network structure expressed by the entire source code. It is not easy to make mistakes, and it is convenient and fast, thereby improving the processing efficiency of the device.
[0099] exist Figure 2 On the basis of the corresponding embodiments, in order to better implement the above solutions of the embodiments of the present application, a deep learning framework for implementing the above solutions is also provided below. Fig.10 , Fig.10A structural schematic diagram of an execution device provided in an embodiment of the present application, the deep learning framework includes: a first compilation module 1001, a segmentation module 1002, a second compilation module 1003, and a simulation execution module 1004, wherein the first compilation module 1001 is used to compile source code to obtain a control flow graph corresponding to the source code; the segmentation module 1002 is used to segment the control flow graph to obtain multiple sub-graphs after segmentation; the second compilation module 1003 is used to recompile the multiple sub-graphs to obtain multiple linear execution sequences, wherein the multiple linear execution sequences are multiple execution sequences without control dependencies; the simulation execution module 1004 is used to simulate the execution of the multiple linear execution sequences in sequence, identify the semantics corresponding to the multiple linear execution sequences during the simulation execution process, and insert at least one operator between the multiple linear execution sequences according to the semantics to connect the multiple linear execution sequences into a calculation graph.
[0100] In one possible design, the simulation execution module 1003 is specifically used to: insert an assignment operator after a first linear execution sequence, and the assignment operator is used to assign the address of the output data of the first linear execution sequence to the address of the input data of the second linear execution sequence, and the first linear execution sequence and the second linear execution sequence both belong to the multiple linear execution sequences.
[0101] In a possible design, the simulation execution module 1003 is specifically used to: insert a first control operator after a first linear execution sequence, the first linear execution sequence is a linear execution sequence including control semantics among the multiple linear execution sequences, the first control operator is used to jump from the first linear execution sequence to a second linear execution sequence, and the second linear execution sequence is a linear execution sequence among the multiple linear execution sequences except the first linear execution sequence.
[0102] In a possible design, the control semantics conditional judgment semantics (such as an if statement with conditional judgment semantics), the simulation execution module 1003 is also specifically used to: jump to multiple second linear execution sequences through the first control operator, and the multiple second linear execution sequences are branches of multiple judgment results corresponding to the conditional judgment semantics.
[0103] In a possible design, the control semantics are loop semantics (e.g., a while statement with loop semantics). After inserting the first control operator after the first linear execution sequence, the simulation execution module 1003 is specifically used to: jump to the second linear execution sequence connected to the first linear execution sequence through the first control operator, the second linear execution sequence being a loop structure corresponding to the first linear execution sequence; inserting a second control operator after the second linear execution sequence, the second control operator being used to loop execute the first linear execution sequence and the second linear execution sequence until output data of the second linear execution sequence meets a preset value.
[0104] In a possible design, the simulation execution module 1003 is specifically used to: after simulating and executing all the linear execution sequences in the multiple linear execution sequences in sequence, insert the at least one operator between the multiple linear execution sequences according to the semantics corresponding to the multiple linear execution sequences; or, simulate and execute a target linear execution sequence, where the target linear execution sequence is a linear execution sequence in the multiple linear execution sequences that is being simulated, and when the target linear execution sequence is simulated and executed, insert an operator corresponding to the semantics of the target linear execution sequence after the target linear execution sequence.
[0105] In a possible design, the simulation execution module 1003 is further specifically used to: generate an instruction set according to semantics corresponding to multiple linear execution sequences, the instruction set including multiple instructions, and the multiple instructions are used to indicate the insertion of at least one operator between the multiple linear execution sequences.
[0106] In one possible design, if the deep learning framework is located at a first node, the simulation execution module 1003 is further specifically used to send the computational graph to a second node. The first node and the second node may be located on the same device or on different devices, which is not limited here.
[0107] In a possible design, the deep learning framework includes: mindspore, tensorflow, pytorch, mxnet, caffe, and theano.
[0108] It should be noted that Fig.10 The information interaction and execution process between the modules / units in the deep learning framework provided are consistent with the content in this application. Figure 2 The corresponding method embodiments are based on the same concept. For specific contents, please refer to the description in the method embodiments shown above in this application, which will not be repeated here.
[0109] The present application also provides an execution device. Fig.11, Fig.11 This is a schematic diagram of the structure of the execution device provided in the embodiment of the present application. For the convenience of explanation, only the part related to the embodiment of the present application is shown. For specific technical details not disclosed, please refer to the method part of the embodiment of the present application. The execution device 1100 may be deployed with Fig.10 The corresponding modules in the deep learning framework described in the corresponding embodiment are used to implement Fig.10 Corresponding to the functions of the deep learning framework in the embodiment, specifically, the execution device 1100 is implemented by one or more servers, and the execution device 1100 may have relatively large differences due to different configurations or performances, and may include one or more processors 1122, memories 1132, and one or more storage media 1130 (e.g., one or more mass storage devices) storing application programs 1142 or data 1144. Specifically, the processor 1122 can be a central processing unit (CPU), an embedded microcontroller, an AI processor, etc., and the type of processor 1122 is not limited here, wherein the memory 1132 and the storage medium 1130 can be short-term storage or persistent storage. The program stored in the storage medium 1130 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the training device. Furthermore, the processor 1122 can be configured to communicate with the storage medium 1130 and execute a series of instruction operations in the storage medium 1130 on the execution device 1100. For example, the processor 1122 can call a series of instruction operations in the storage medium 1130 to perform the following steps: compile the source code to obtain a control flow graph corresponding to the source code, then split the obtained control flow graph to obtain multiple sub-graphs after segmentation, and recompile the obtained multiple sub-graphs to obtain multiple linear execution sequences, and then simulate the execution of the multiple linear execution sequences in sequence, and insert at least one operator between the multiple linear execution sequences according to the semantics corresponding to the multiple linear execution sequences to connect the multiple linear execution sequences into a computational graph.
[0110] The execution device 1100 may also include one or more power supplies 1126, one or more wired or wireless network interfaces 1150, one or more input and output interfaces 1158, and / or one or more operating systems 1141, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
[0111] In the embodiment of the present application, the steps performed by the deep learning framework in the aforementioned various control flow graph processing methods can be based on the Fig.11The structure shown in the execution device is executed on the processor by calling the relevant code stored in the storage medium, and the details are not repeated here.
[0112] It should also be noted that the device embodiments described above are merely schematic, 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 over 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. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.
[0113] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0114] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0115] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.
Claims
1. A control flow graph processing method, applied to a deep learning framework, characterized in that: include: Compiling source code through the deep learning framework to obtain a control flow graph corresponding to the source code; Splitting the control flow graph to obtain a plurality of subgraphs after segmentation; Recompiling the plurality of subgraphs to obtain a plurality of linear execution sequences, wherein the plurality of linear execution sequences are a plurality of execution sequences without control dependencies; The multiple linear execution sequences are simulated and executed in sequence through the deep learning framework, the semantics corresponding to the multiple linear execution sequences are identified during the simulation execution process, and at least one operator is inserted between the multiple linear execution sequences according to the semantics to connect the multiple linear execution sequences into a computational graph.
2. The method according to claim 1, characterized in that The inserting at least one operator between the plurality of linear execution sequences according to the semantics comprises: An assignment operator is inserted after the first linear execution sequence, and the assignment operator is used to assign the address of the output data of the first linear execution sequence to the address of the input data of the second linear execution sequence, and the first linear execution sequence and the second linear execution sequence both belong to the multiple linear execution sequences.
3. The method according to claim 1, characterized in that The inserting at least one operator between the plurality of linear execution sequences according to the semantics comprises: A first control operator is inserted after a first linear execution sequence, where the first linear execution sequence is a linear execution sequence including control semantics among the multiple linear execution sequences, and the first control operator is used to jump from the first linear execution sequence to a second linear execution sequence, where the second linear execution sequence is a linear execution sequence among the multiple linear execution sequences except the first linear execution sequence.
4. The method according to claim 3, characterized in that The control semantics is conditional judgment semantics. After inserting the first control operator after the first linear execution sequence, the method further includes: The first control operator is used to jump to a plurality of the second linear execution sequences, where the plurality of the second linear execution sequences are branches of a plurality of judgment results corresponding to the conditional judgment semantics.
5. The method according to claim 3, characterized in that: The control semantics is loop semantics, and after inserting the first control operator after the first linear execution sequence, the method further includes: Jump to the second linear execution sequence connected to the first linear execution sequence through the first control operator, where the second linear execution sequence is a loop structure corresponding to the first linear execution sequence; A second control operator is inserted after the second linear execution sequence, and the second control operator is used to cyclically execute the first linear execution sequence and the second linear execution sequence until output data of the second linear execution sequence meets a preset value.
6. The method according to any one of claims 1 to 5, characterized in that The step of sequentially simulating and executing the multiple linear execution sequences through the deep learning framework and inserting at least one operator between the multiple linear execution sequences according to the semantics includes: After all the linear execution sequences in the multiple linear execution sequences are simulated and executed in sequence by the deep learning framework, the at least one operator is inserted between the multiple linear execution sequences according to the semantics; or, Simulating and executing a target linear execution sequence by the deep learning framework, wherein the target linear execution sequence is a linear execution sequence being simulated and executed among the multiple linear execution sequences; When the target linear execution sequence is simulated and executed, an operator corresponding to the semantics of the target linear execution sequence is inserted after the target linear execution sequence.
7. The method according to any one of claims 1 to 5, characterized in that The inserting at least one operator between the plurality of linear execution sequences according to the semantics comprises: An instruction set is generated according to the semantics, wherein the instruction set includes a plurality of instructions, and the plurality of instructions are used to instruct to insert at least one operator between the plurality of linear execution sequences.
8. The method according to any one of claims 1 to 5, characterized in that The deep learning framework is located at the first node, and the method further includes: The computation graph is sent to a second node, where the first node and the second node are located on the same device or on different devices.
9. The method according to any one of claims 1 to 5, characterized in that The deep learning framework includes: mindspore, tensorflow, pytorch, mxnet, caffe or theano.
10. The method according to claim 8, characterized in that The first node comprises: AI chip.
11. A deep learning framework, characterized in that: include: A first compiling module, used for compiling source code to obtain a control flow graph corresponding to the source code; A segmentation module, used for segmenting the control flow graph to obtain a plurality of segmented subgraphs; A second compiling module, used to recompile the plurality of subgraphs to obtain a plurality of linear execution sequences, wherein the plurality of linear execution sequences are a plurality of execution sequences without control dependency; A simulation execution module is used to simulate and execute the multiple linear execution sequences in sequence, identify the semantics corresponding to the multiple linear execution sequences during the simulation execution process, and insert at least one operator between the multiple linear execution sequences according to the semantics to connect the multiple linear execution sequences into a calculation graph.
12. The frame according to claim 11, characterized in that The simulation execution module is specifically used for: An assignment operator is inserted after the first linear execution sequence, and the assignment operator is used to assign the address of the output data of the first linear execution sequence to the address of the input data of the second linear execution sequence, and the first linear execution sequence and the second linear execution sequence both belong to the multiple linear execution sequences.
13. The frame according to claim 11, characterized in that The simulation execution module is also specifically used for: A first control operator is inserted after a first linear execution sequence, where the first linear execution sequence is a linear execution sequence including control semantics among the multiple linear execution sequences, and the first control operator is used to jump from the first linear execution sequence to a second linear execution sequence, where the second linear execution sequence is a linear execution sequence among the multiple linear execution sequences except the first linear execution sequence.
14. The frame according to claim 13, characterized in that The control semantics is conditional judgment semantics. After the first control operator is inserted after the first linear execution sequence, the simulation execution module is further used to: The first control operator is used to jump to a plurality of the second linear execution sequences, where the plurality of the second linear execution sequences are branches of a plurality of judgment results corresponding to the conditional judgment semantics.
15. The frame according to claim 13, characterized in that The control semantics is loop semantics. After the first control operator is inserted after the first linear execution sequence, the simulation execution module is further used to: Jump to the second linear execution sequence connected to the first linear execution sequence through the first control operator, where the second linear execution sequence is a loop structure corresponding to the first linear execution sequence; A second control operator is inserted after the second linear execution sequence, and the second control operator is used to cyclically execute the first linear execution sequence and the second linear execution sequence until output data of the second linear execution sequence meets a preset value.
16. A frame according to any one of claims 11 to 15, characterized in that The simulation execution module is also specifically used for: After all the linear execution sequences in the plurality of linear execution sequences are simulated and executed in sequence, the at least one operator is inserted between the plurality of linear execution sequences according to the semantics; or, Simulating and executing a target linear execution sequence, wherein the target linear execution sequence is a linear execution sequence among the plurality of linear execution sequences that is being simulated and executed; When the target linear execution sequence is simulated and executed, an operator corresponding to the semantics of the target linear execution sequence is inserted after the target linear execution sequence.
17. A frame according to any one of claims 11 to 15, characterized in that The simulation execution module is also specifically used for: An instruction set is generated according to the semantics, wherein the instruction set includes a plurality of instructions, and the plurality of instructions are used to instruct to insert at least one operator between the plurality of linear execution sequences.
18. A frame according to any one of claims 11 to 15, characterized in that The deep learning framework is located at the first node, and the simulation execution module is further used for: The computation graph is sent to a second node, where the first node and the second node are located on the same device or on different devices.
19. A frame according to any one of claims 11 to 15, characterized in that The deep learning framework includes: mindspore, tensorflow, pytorch, mxnet, caffe or theano.
20. An execution device, comprising a processor and a memory, wherein the processor is coupled to the memory, characterized in that: The memory is used to store programs; The processor is used to execute the program in the memory, so that the execution device executes the method according to any one of claims 1 to 10.
21. A computer-readable storage medium comprising a program, which, when executed on a computer, causes the computer to execute the method according to any one of claims 1 to 10.
22. A computer program product comprising instructions, which, when executed on a computer, causes the computer to perform the method according to any one of claims 1 to 10.
Citation Information
Patent Citations
A control flow graph construction method for object-oriented programming
CN109408034A