Artificial intelligence-oriented code generation method and device based on computational graph model
By constructing a computational logic tree and performing node preprocessing, code logic adapted to the storage limitations of onboard computers is generated, solving the problem of insufficient storage space in onboard computers and enabling the effective operation of complex computational graph models.
Patent Information
- Application Number
- CN202111537354.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-15
- Publication Date
- 2026-03-03
- Estimated Expiration
- 2041-12-15
Smart Images

Figure CN114385179B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of deep learning technology, and in particular to a code generation method and apparatus based on computational graph models for artificial intelligence. Background Technology
[0002] The core of a machine learning task is the definition of the model and the method of solving the model's parameters. After abstracting these two, a unique computational logic can be determined. This logic can be represented by a graph, which is called a computational graph.
[0003] A computation graph is represented as a directed acyclic graph (DAG), defining how data flows, how it is computed, and the dependencies between various computations. A computation graph consists of nodes and directed edges. Nodes represent operations, and directed edges represent dependencies between operations and the direction of data flow.
[0004] In related technologies, a computation graph represents an algorithm for reasoning logic. Converting the computation graph into code that can be recognized by hardware devices completes the code generation of the computation graph.
[0005] Based on the above, when the reasoning logic is relatively complex, the reasoning logic corresponds to a computational graph with high complexity, which requires a lot of computation and preprocessing of the computational graph.
[0006] Deep learning models trained on desktop Linux systems encounter problems when running in embedded systems. The difficulty lies in the limited storage space on the onboard computer, which cannot accommodate the necessary dependency libraries and runtime memory requirements. Summary of the Invention
[0007] The technical problem solved by this invention is to overcome the shortcomings of the prior art and provide a code generation method and apparatus based on a computational graph model for artificial intelligence.
[0008] The technical solution of this invention is: a code generation method based on a computational graph model for artificial intelligence, comprising:
[0009] Obtain the computation graph and output nodes; the computation graph is a code graph generated using preset code.
[0010] Starting from the output node, the search proceeds forward along the directed edges in the computation graph until all input nodes are found;
[0011] Using all nodes on the search path as a set, construct a computational logic tree with the output node as the root node and the input node as the leaf node;
[0012] Based on the node type of all nodes in the computational logic tree, all nodes are preprocessed;
[0013] Starting from one of the leaf nodes N1 with the highest level in the computational logic tree, upward generation is performed, and N1, its sibling nodes, and its parent node are generated as new leaf nodes;
[0014] Repeat the process of generating upwards from one of the leaf nodes N1 with the highest level in the computational logic tree, with N1, its sibling nodes, and its parent node generating new leaf nodes, until the root node becomes the parent node.
[0015] Optionally, the step of starting from the output node and searching forward based on the directed edges in the computation graph until all input nodes are found includes:
[0016] Obtain all directed edges in the computation graph that point to the output node;
[0017] Using depth-first traversal, the starting node of the directed edge is obtained based on the directed edge;
[0018] Based on the starting node, find the directed edges that serve as ending nodes;
[0019] Repeat the steps of obtaining all directed edges pointing to the output node in the computation graph, up to finding the directed edge that is the end node based on the starting node, until no directed edge is found that is the end node.
[0020] Optionally, constructing a computational logic tree with the output node as the root node and the input node as the leaf nodes, using all nodes on the search path as a set, includes:
[0021] Generate a node set based on all nodes along the search path;
[0022] The computational logic tree is formed by connecting all nodes in the node set with directed edges.
[0023] Optionally, the preprocessing of all nodes based on their node types in the computational logic tree includes:
[0024] Collect the level number of each node in the computational logic tree;
[0025] Preprocessing is performed to collect all nodes on the computational logic tree:
[0026] Different transformation rules are defined for different nodes, and variable nodes are converted into data values of specific data types.
[0027] The computation operation node is converted into a computation method according to its computation operation logic to complete the preprocessing process.
[0028] Optionally, after repeatedly executing the process of generating upwards from one of the leaf nodes N1 with the highest level in the computational logic tree, where N1, its sibling nodes, and its parent node are generated as new leaf nodes, until the root node becomes the parent node, the process further includes:
[0029] Get the input and output nodes;
[0030] Based on the input and output nodes, the computation graph is parsed to obtain the network structure and execution order;
[0031] Code logic is generated according to the network structure and the execution order.
[0032] To address the aforementioned technical problems, embodiments of the present invention provide a code generation apparatus based on a computational graph model for artificial intelligence, comprising:
[0033] The output node acquisition module is used to acquire the computation graph and output nodes; the computation graph is a code graph generated using preset code.
[0034] The input node search module is used to search forward from the output node according to the directed edges in the computation graph until all input nodes are found.
[0035] The computational logic tree construction module is used to construct a computational logic tree with the output node as the root node and the input node as the leaf node, using all nodes on the search path as a set.
[0036] The node preprocessing module is used to preprocess all nodes according to the node type of all nodes in the computational logic tree;
[0037] The new leaf node generation module is used to generate upwards from one of the leaf nodes N1 with the largest layer in the computational logic tree. N1, its sibling nodes, and its parent node are generated as new leaf nodes.
[0038] The repetitive execution module is used to repeatedly execute the process of generating new leaf nodes from one of the leaf nodes N1 with the highest level in the computational logic tree, N1 and its sibling nodes and parent nodes, until the root node becomes the parent node.
[0039] Optionally, the input node lookup module includes:
[0040] A directed edge acquisition unit is used to acquire all directed edges in the computation graph that point to the output node;
[0041] The starting node acquisition unit is used to obtain the starting node of the directed edge based on the directed edge using depth traversal;
[0042] A directed edge search unit is used to search for directed edges that serve as end nodes based on the starting node.
[0043] A repeated execution unit is used to repeatedly execute the directed edge acquisition unit, the starting node acquisition unit, and the directed edge search unit until a directed edge that does not serve as an end node is obtained.
[0044] Optionally, the computational logic tree construction module includes:
[0045] A node set generation unit is used to generate a node set based on all nodes on the search path;
[0046] The computational logic tree component unit is used to assemble the computational logic tree by arranging all nodes in the node set according to the relationship of directed edges.
[0047] Optionally, the node preprocessing module includes:
[0048] A node layer number collection unit is used to collect the layer number of each node in the computational logic tree;
[0049] The all-node collection unit is used for preprocessing, collecting all nodes on the computational logic tree:
[0050] The transformation rule formulation unit is used to formulate different transformation rules for different nodes, and to convert variable nodes into data values of specific data types.
[0051] The calculation method conversion unit is used to convert the calculation operation node into a calculation method according to its calculation operation logic in order to complete the preprocessing process.
[0052] Optionally, the device further includes:
[0053] The input / output node acquisition module is used to acquire input and output nodes;
[0054] The execution order acquisition module is used to parse the computation graph based on the input and output nodes to obtain the network structure and execution order;
[0055] The code logic generation module is used to generate code logic according to the network structure and the execution order.
[0056] The advantages of this invention compared to the prior art are:
[0057] The embodiments of the present invention can solve the problem that the storage space of the spaceborne computer in the prior art is limited and cannot accommodate the corresponding dependent libraries and the memory occupied by the runtime, thereby improving the memory utilization of the spaceborne computer. Attached Figure Description
[0058] Figure 1A flowchart illustrating the steps of a code generation method based on a computational graph model for artificial intelligence, provided in an embodiment of the present invention;
[0059] Figure 2 An example of a TensorFlow computation graph provided in this embodiment of the invention;
[0060] Figure 3 A schematic diagram illustrating an example model training method provided by the present invention;
[0061] Figure 4 This invention provides a complete computational graph that is available in memory;
[0062] Figure 5 A schematic diagram of inference on a PC provided by the present invention;
[0063] Figure 6 This invention provides a schematic diagram of using C for inference during testing on an embedded board and a PC;
[0064] Figure 7 A schematic diagram of a computation graph provided in an embodiment of the present invention;
[0065] Figure 8 A schematic diagram illustrating the unfolding of a computation graph into an abstract syntax tree, provided as an embodiment of the present invention;
[0066] Figure 9 This is a schematic diagram of the structure of a code generation method based on a computational graph model for artificial intelligence, provided in an embodiment of the present invention. Detailed Implementation
[0067] Example 1
[0068] Reference Figure 1 The diagram illustrates a flowchart of a code generation method based on a computational graph model for artificial intelligence, as provided in an embodiment of the present invention. Figure 1 As shown, the code generation method may include the following steps:
[0069] Step 101: Obtain the computation graph and output nodes; the computation graph is a code graph generated using preset code.
[0070] In this embodiment, the computation graph is represented as a directed acyclic graph, defining the data flow, computation methods, and dependencies between various computations. The computation graph consists of nodes and directed edges. Nodes represent operations, and directed edges represent dependencies between operations and data flow directions.
[0071] The computation graph can be a code graph generated using preset code, such as C++ code, C code, etc.
[0072] When generating code, the computation graph and the output nodes on the computation graph can be obtained.
[0073] After obtaining the computation graph and output nodes, proceed to step 102.
[0074] Step 102: Starting from the output node, perform a forward search based on the directed edges in the computation graph until all input nodes are found.
[0075] After obtaining the computation graph and output nodes, you can start from the output nodes and search forward based on the directed edges in the computation graph until you find all the input nodes in the computation graph.
[0076] After performing a forward search based on the directed edges in the computation graph and finding all the input nodes in the computation graph, proceed to step 103.
[0077] Step 103: Using all nodes on the search path as a set, construct a computational logic tree with the output node as the root node and the input node as the leaf node.
[0078] After searching forward along the directed edges of the computation graph and finding all input nodes, all nodes along the search path can be grouped into a set to construct a computational logic tree with the output node as the root node and the input nodes as leaf nodes. This logic tree is known as an abstract syntax tree (AST). Figure 8 As shown.
[0079] After constructing the computational logic tree, proceed to step 104.
[0080] Step 104: Preprocess all nodes according to their node types in the computational logic tree.
[0081] After constructing the computational logic tree, all nodes can be preprocessed according to their node types, and then step 105 can be executed.
[0082] Step 105: Generate upwards from one of the leaf nodes N1 with the highest level in the computational logic tree. N1, its sibling nodes, and its parent node are generated as new leaf nodes.
[0083] We can start by generating upwards from one of the leaf nodes N1, which has the highest level in the computational logic tree. N1, its sibling nodes, and its parent node will then form a new leaf node.
[0084] Step 106: Repeat the process of generating upwards from one of the leaf nodes N1 with the highest level in the computational logic tree, with N1, its sibling nodes, and its parent node generating new leaf nodes, until the root node becomes the parent node.
[0085] Repeat step 105 above until the root node becomes the parent node. Then the generated code can be placed in the outermost method body. The input parameter of the outermost method body is the set of input nodes, and the output parameter is the output node.
[0086] The inference network model transfer process is implemented as follows:
[0087] (1) Components of the calculation graph
[0088] The core of a machine learning task lies in the definition of the model and the method for solving its parameters. Abstracting these two aspects reveals a unique computational logic. Representing this logic as a graph is called a computation graph. A computation graph is a directed acyclic graph (DAG), defining how data flows, how it is computed, and the dependencies between various computations.
[0089] TensorFlow's computation graph has a relatively fine granularity (the computation graph can be like...). Figure 7 As shown), it consists of nodes and directed edges (layers were added later, but we don't need to focus on them this time).
[0090] a) Node
[0091] A node (also called a node) abstractly represents the execution of an Op function. Its key properties are as follows:
[0092] name: unique identifier
[0093] shape: dimensional information
[0094] `dtype` specifies the data type of the tensor. TensorFlow performs type checks on all tensors involved in computation, and will throw an error if a type mismatch is found.
[0095] value: Initial value; not every node will have this.
[0096] `op`: `Placeholder` is used to define the type and shape of input data, etc. `VariableV2` corresponds to stateful variable operations, usually used to store model parameters. `Operation`, such as `add`, corresponds to stateless computation or control operations, mainly responsible for algorithm logic expression or flow control. `Const` corresponds to constant nodes.
[0097] Input: 0 to multiple, representing the input of a node.
[0098] b) Graph topology: Consists of edges and nodes
[0099] Edges describe the dependencies between nodes. After the computation graph of TensorFlow is loaded, the edges do not have explicit content, but the relationships between nodes can be constructed by a node and its input nodes.
[0100] Knowing the set of nodes and all dependencies between nodes, we can obtain the topology of the computation graph.
[0101] Given clear inputs and outputs, the execution sequence of the computation graph can be obtained.
[0102] (2) Implementation scheme for computation graph transformation
[0103] 1) Preparatory work
[0104] 1) Formulate conversion rules
[0105] Different rules are set for different nodes, as shown in Table 1 below:
[0106] Table 1:
[0107]
[0108] Different rules are established for different data types.
[0109] The data types and their meanings in TF are shown in Table 2 below, and need to be converted to their corresponding C variables.
[0110] Table 2:
[0111]
[0112] 2) Encapsulate computational or control operations into logic libraries
[0113] Write the operation type nodes involved in the computation graph, their execution logic, or state control logic in C code, and encapsulate them into a way that can be called by reference.
[0114] Considering cost, only the operation nodes involved in the current code can be converted, as shown in Table 3 below.
[0115] Table 3:
[0116]
[0117] (tf.mul, tf.sub, and tf.neg are deprecated and can be replaced by tf.multiply, tf.subtract, and tf.negative, respectively.)
[0118] To ensure accuracy, verification methods are needed after conversion.
[0119] For a single operation node, its logic can be built in a standard TensorFlow environment using a simple computation graph that uses the node, and the error of the calculated output result can be compared using the same input as the C code.
[0120] (ii) Computation graph to C code conversion
[0121] Determine input and output nodes
[0122] Objective: To obtain the input and output nodes and their data formats.
[0123] The user needs to confirm the name and data format of the input node, as well as the name and data format of the output node.
[0124] After this step, some verification work can be done. Using fixed values, assemble the data according to the input data format, and directly call it in the TensorFlow standard version environment. Then, verify whether the data was obtained correctly by comparing the result set.
[0125] Based on the input and output, analyze the computation graph to obtain the network structure and execution order.
[0126] Objective: To construct logic capable of parsing computation graphs, with universal applicability, and the final result is shown in the following example:
[0127] For example, having confirmed the input node x and the output node y in the previous step, by loading and parsing ckpt, a complete graph can be obtained. Further parsing of the graph, assuming the original computational graph logic is y = x * a + b, reveals the corresponding network structure, such as... Figure 2 As shown.
[0128] The execution order is as follows:
[0129] x,a,*,b,+,y
[0130] The key attributes resolved for each node are as follows:
[0131] x: is a placeholder of type tf.double, which is used as an input parameter in the generated C code, corresponding to the input value given by the user when calling the tf.session.run method.
[0132] a and b: During training, a and b are variables. For a trained computation graph, a and b are constants with definite values in the generated C code.
[0133] * and +: Both are calculation operations. In the preparation stage 2.2.2.1, these two calculation operations have been encapsulated into corresponding library methods. In the generated C code, they are reflected as calls to fixed methods, where the values of the input nodes of these two nodes are used as input parameters for calling the fixed methods.
[0134] y: Confirmed output node, used as a return parameter in the generated C code.
[0135] Generate C code logic according to network execution order
[0136] Objective: To construct logic capable of generating C code based on network execution order and node characteristics. The input to this logic is the result obtained from the previous computation graph parsing step, and the output is directly callable C code. When the C code is called, the input data is the test set, and the output is the expected result set. The final effect is shown in the following example:
[0137] Taking the logical execution order of the topology obtained in the previous step and the key attributes of each node as input, the final output C code is as follows:
[0138] double run(x)
[0139] {
[0140] double a = XXXX; / / Fixed value
[0141] double b = YYYY; / / Fixed value
[0142] temp1 = x * a;
[0143] temp2 = temp1 + b;
[0144] y = temp2;
[0145] return y;
[0146] }
[0147] At this point, the user can call the generated C code to perform inference. The C code is responsible for executing the inference logic that originally used TensorFlow but now uses C.
[0148] Next, we will illustrate a complete process with an example, such as using TFLearn to train a human weight overweight calculation model, converting it to C code, and then using the converted C code for inference.
[0149] Training phase
[0150] The model definition and parameter calculation process are the same as the previous training process: build the network computing model on CPU / GPU, train it using the training set, and after training, export the network model as a ckpt file. Example model training is as follows: Figure 3 As shown.
[0151] (2) Transition Phase
[0152] Load the ckpt exported in the previous step using TensorFlow's Session.
[0153] The complete computation graph can be obtained in memory, such as Figure 4 As shown.
[0154] The next step in the intermediate conversion tool layer
[0155] The computation graph is identified, and for nodes with inputs, the input nodes can be obtained. This allows the graph topology to be acquired; however, this step requires user confirmation of the input and output nodes.
[0156] Input nodes: height, weight
[0157] Output node: result
[0158] And identify the execution order of the computation graph as follows:
[0159] a,height,*,weight,-,weight, / ,b,>,result
[0160] After identifying the type of each node, its characteristics are shown in Table 4 below:
[0161] Table 4:
[0162]
[0163] The functions multiply(), subtract(), realDiv(), and largerThan() are pre-encapsulated C logic.
[0164] Based on the input / output, execution order, and node type, convert the logic into C code.
[0165] What the user sees
[0166] Callable run method:
[0167] Input parameters: double height, double weight
[0168] Return parameter: int result
[0169] The logic in the actual generated run method can be:
[0170] int run(double height, double weight)
[0171] {
[0172] double a = 0.7; / / Fixed value
[0173] double b = -0.1; / / Fixed value
[0174] double temp1 = a * height;
[0175] double temp2=temp1–weight;
[0176] double temp3=temp2 / weight;
[0177] double y = (temp3 > b)
[0178] return y;
[0179] }
[0180] (3) Reasoning stage
[0181] Reasoning on PC, such as Figure 5 As shown.
[0182] For inference using C during testing on embedded boards and PCs, such as... Figure 6 As shown.
[0183] The present invention provides the above method, which can solve the problem that the storage space on the onboard computer is limited and cannot accommodate the corresponding dependent libraries and runtime memory.
[0184] Example 2
[0185] Reference Figure 9 This illustration shows a schematic diagram of a code generation device based on a computational graph model for artificial intelligence, provided by an embodiment of the present invention. Figure 9 As shown, the code generation device may include the following modules:
[0186] The output node acquisition module 210 is used to acquire the computation graph and output nodes; the computation graph is a code graph generated using preset code.
[0187] The input node search module 220 is used to search forward from the output node according to the directed edges in the computation graph until all input nodes are found.
[0188] The computational logic tree construction module 230 is used to construct a computational logic tree with the output node as the root node and the input node as the leaf node, using all nodes on the search path as a set.
[0189] The node preprocessing module 240 is used to preprocess all nodes according to the node type of all nodes in the computational logic tree;
[0190] The new leaf node generation module 250 is used to generate upwards from one of the leaf nodes N1 with the largest layer in the computational logic tree, and N1, its sibling nodes, and its parent node are generated as new leaf nodes.
[0191] The repeat execution module 260 is used to repeatedly execute the process of generating new leaf nodes from one of the leaf nodes N1 with the highest level in the computational logic tree, N1 and its sibling nodes and parent nodes, until the root node becomes the parent node.
[0192] Optionally, the input node lookup module includes:
[0193] A directed edge acquisition unit is used to acquire all directed edges in the computation graph that point to the output node;
[0194] The starting node acquisition unit is used to obtain the starting node of the directed edge based on the directed edge using depth traversal;
[0195] A directed edge search unit is used to search for directed edges that serve as end nodes based on the starting node.
[0196] A repeated execution unit is used to repeatedly execute the directed edge acquisition unit, the starting node acquisition unit, and the directed edge search unit until a directed edge that does not serve as an end node is obtained.
[0197] Optionally, the computational logic tree construction module includes:
[0198] A node set generation unit is used to generate a node set based on all nodes on the search path;
[0199] The computational logic tree component unit is used to assemble the computational logic tree by arranging all nodes in the node set according to the relationship of directed edges.
[0200] Optionally, the node preprocessing module includes:
[0201] A node layer number collection unit is used to collect the layer number of each node in the computational logic tree;
[0202] The all-node collection unit is used for preprocessing, collecting all nodes on the computational logic tree:
[0203] The transformation rule formulation unit is used to formulate different transformation rules for different nodes, and to convert variable nodes into data values of specific data types.
[0204] The calculation method conversion unit is used to convert the calculation operation node into a calculation method according to its calculation operation logic in order to complete the preprocessing process.
[0205] Optionally, the device further includes:
[0206] The input / output node acquisition module is used to acquire input and output nodes;
[0207] The execution order acquisition module is used to parse the computation graph based on the input and output nodes to obtain the network structure and execution order;
[0208] The code logic generation module is used to generate code logic according to the network structure and the execution order.
[0209] The code generation device provided in this embodiment of the invention can solve the problem that the storage space on the onboard computer is limited and cannot accommodate the corresponding dependent libraries and runtime memory.
[0210] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.
[0211] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
[0212] The parts of this invention not described in detail are common knowledge to those skilled in the art.
Claims
1. An artificial intelligence-oriented code generation method based on a computational graph model, characterized by, The method comprises the following steps: acquiring a calculation graph and an output node; the calculation graph is a code graph generated by using a preset code; the calculation graph comprises nodes and directed edges, the nodes comprise variable nodes or operation nodes, and the edges describe the dependency relationship between the nodes; starting from the output node, performing forward searching according to the directed edges in the calculation graph until all input nodes are found; taking all the nodes on the searching path as a set, constructing a calculation logic tree with the output node as a root node and the input nodes as leaf nodes; preprocessing all the nodes on the calculation logic tree according to the node types of the nodes; generating upwards from one of the leaf nodes with the largest layer number in the calculation logic tree N1, and generating N1 and its sibling nodes and parent node as new leaf nodes; repeating the step of generating upwards from one of the leaf nodes with the largest layer number in the calculation logic tree N1, and generating N1 and its sibling nodes and parent node as new leaf nodes until the root node is used as a parent node; the preprocessing of all the nodes on the calculation logic tree according to the node types of the nodes comprises the following steps: collecting the layer numbers of all the nodes on the calculation logic tree; collecting all the nodes on the calculation logic tree by preprocessing; formulating different conversion rules for different nodes, and converting variable nodes into data values of specific data types; the operation nodes are converted into calculation methods according to the calculation operation logic of the operation nodes, which comprises the following steps: mapping the operation nodes to pre-packaged C language functions; and completing the preprocessing process.
2. The method of claim 1, wherein, the step of starting from the output node and performing forward searching according to the directed edges in the calculation graph until all the input nodes are found comprises the following steps: acquiring all the directed edges pointing to the output node in the calculation graph; acquiring the starting nodes of the directed edges according to the directed edges by using depth-first traversal; finding the directed edges with the starting nodes as terminal nodes according to the starting nodes; repeating the steps of acquiring all the directed edges pointing to the output node in the calculation graph and finding the directed edges with the starting nodes as terminal nodes according to the starting nodes until no directed edge with the starting nodes as terminal nodes is obtained.
3. The method of claim 1, wherein, the step of taking all the nodes on the searching path as a set and constructing a calculation logic tree with the output node as a root node and the input nodes as leaf nodes comprises the following steps: generating a node set according to all the nodes on the searching path; composing the calculation logic tree by using all the nodes in the node set according to the relationship of the directed edges.
4. The method of claim 1, wherein, after the step of repeating the step of generating upwards from one of the leaf nodes with the largest layer number in the calculation logic tree N1, and generating N1 and its sibling nodes and parent node as new leaf nodes until the root node is used as a parent node, the method further comprises the following steps: acquiring input and output nodes; parsing the calculation graph according to the input and output nodes to obtain a network structure and an execution sequence; generating code logic according to the network structure and the execution sequence.
5. An apparatus for artificial intelligence-oriented code generation based on a computational graph model, characterized by, The method comprises the following steps: an output node acquisition module is configured to acquire a calculation graph and an output node; The computing graph is a code graph generated by using a preset code; the computing graph comprises nodes and directed edges, the nodes comprise variable nodes or operation nodes, and the edges describe the dependency relationship between the nodes; The input node searching module is configured to search forward from the output node according to the directed edges in the computing graph until all the input nodes are found; The computing logic tree construction module is configured to construct a computing logic tree with the output node as a root node and the input nodes as leaf nodes based on all the nodes on the searching path; The node preprocessing module is configured to preprocess all the nodes on the computing logic tree according to the node types of the nodes; The new leaf node generation module is configured to generate upwards from one of the leaf nodes with the largest number of layers N1 in the computing logic tree, and N1 and its sibling nodes and parent node are generated as new leaf nodes; The repeated execution module is configured to repeatedly execute the generation upwards from one of the leaf nodes with the largest number of layers N1 in the computing logic tree, and N1 and its sibling nodes and parent node are generated as new leaf nodes until the root node is used as a parent node; The node preprocessing module comprises: The node layer number collection unit is configured to collect the layer numbers of each node on the computing logic tree; The all-node collection unit is configured to collect all the nodes on the computing logic tree for preprocessing; The conversion rule formulation unit is configured to formulate different conversion rules for different nodes, and the variable nodes are converted into data values of specific data types; The computing method conversion unit is configured to convert the operation nodes into computing methods according to the computing operation logic of the operation nodes, including: mapping the operation nodes to pre-packaged C language functions; and completing a preprocessing process.
6. The apparatus of claim 5, wherein, The input node searching module comprises: The directed edge acquisition unit is configured to acquire all the directed edges pointing to the output node in the computing graph; The starting node acquisition unit is configured to acquire starting nodes of the directed edges according to the directed edges by using depth-first traversal; The directed edge searching unit is configured to search for directed edges with the starting nodes as terminal nodes according to the starting nodes; The searching and repeated execution unit is configured to repeatedly execute the directed edge acquisition unit, the starting node acquisition unit and the directed edge searching unit until no directed edge with the starting nodes as terminal nodes is obtained.
7. The apparatus of claim 5, wherein, The computing logic tree construction module comprises: The node set generation unit is configured to generate a node set based on all the nodes on the searching path; The computing logic tree composition unit is configured to compose the computing logic tree by arranging all the nodes in the node set according to the relationship of the directed edges.
8. The apparatus of claim 5, wherein, The apparatus further comprises: The input and output node acquisition module is configured to acquire input and output nodes; The execution order acquisition module is configured to parse the computing graph according to the input and output nodes to obtain a network structure and an execution order; The code logic generation module is configured to generate code logic according to the network structure and the execution order.