Code generation method and device, computer equipment and computer readable storage medium
By determining the associated nodes and execution priorities of nodes in the graphical workflow and generating target execution sequences, the problem of difficult to determine the execution order of nodes in the graphical workflow is solved, and the quality of code generation and execution efficiency are improved.
Patent Information
- Application Number
- CN202510168206.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-14
- Publication Date
- 2025-05-13
AI Technical Summary
The execution order of nodes in a graphical workflow is difficult to determine, resulting in code generation errors.
By obtaining the nodes and their connection relationships in the graphical workflow, determining the associated nodes and execution priorities for each node, a target execution sequence is generated to ensure that the node executes before its associated node.
Improve the quality of code generation, avoid execution errors caused by missing input data from nodes, and improve the execution efficiency of code.
Smart Images

Figure CN119987755A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a code generation method, apparatus, computer device and computer-readable storage medium. Background Art
[0002] A graphical workflow can be a workflow that is built through nodes on a graphical user interface and can implement corresponding functions. Since a graphical workflow is different from a tree structure, there can be multiple root nodes in a graphical workflow, and each node can have multiple parent nodes. The execution of nodes in a graphical workflow is difficult to determine, resulting in code generation for the graphical workflow, which often leads to errors due to the wrong order of node execution. Summary of the invention
[0003] The embodiments of the present application provide a code generation method, apparatus, computer device, and computer-readable storage medium, which can improve the quality of code generation.
[0004] A code generation method provided in an embodiment of the present application includes:
[0005] Acquire a graphical workflow for implementing a specified function, wherein the graphical workflow includes a plurality of nodes, wherein each node is configured to perform a corresponding operation;
[0006] Determine, according to the connection relationship between the plurality of nodes in the graphical workflow, an associated node corresponding to each of the nodes, wherein the associated node is used to receive an output of a corresponding node as an input;
[0007] For each of the nodes, determining the execution priority of the node according to the execution priority of the associated node corresponding to the node;
[0008] Determining a target execution sequence corresponding to the plurality of nodes in the graphical workflow according to the execution priority of each of the nodes, wherein each node in the target execution sequence is ranked before the corresponding associated node;
[0009] A second logic code for implementing the specified function is generated according to the first logic code corresponding to each of the nodes in the graphical workflow and the target execution sequence.
[0010] Accordingly, an embodiment of the present application further provides a code generation device, including:
[0011] An acquisition unit, configured to acquire a graphical workflow for implementing a specified function, wherein the graphical workflow includes a plurality of nodes, wherein each node is configured to perform a corresponding operation;
[0012] A node determination unit, configured to determine an associated node corresponding to each of the nodes according to a connection relationship between the plurality of nodes in the graphical workflow, wherein the associated node is configured to receive an output of a corresponding node as an input;
[0013] A priority determination unit, configured to determine, for each of the nodes, an execution priority of the node according to an execution priority of an associated node corresponding to the node;
[0014] A sorting unit, configured to determine a target execution sequence corresponding to the plurality of nodes in the graphical workflow according to the execution priority of each of the nodes, wherein each node in the target execution sequence is sorted prior to the corresponding associated node;
[0015] A generating unit is used to generate a second logic code for implementing the specified function according to the first logic code corresponding to each of the nodes in the graphical workflow and the target execution sequence.
[0016] Correspondingly, an embodiment of the present application also provides a computer device, including a memory and a processor; the memory stores a computer program, and the processor is used to run the computer program in the memory to execute any code generation method provided in the embodiment of the present application.
[0017] Correspondingly, an embodiment of the present application also provides a computer-readable storage medium, which is used to store a computer program, and the computer program is loaded by a processor to execute any code generation method provided in the embodiment of the present application.
[0018] The embodiment of the present application obtains a graphical workflow for implementing a specified function, wherein the graphical workflow includes multiple nodes, wherein each node is configured to perform a corresponding operation; based on the connection relationship between the multiple nodes in the graphical workflow, an associated node corresponding to each node is determined, wherein the associated node is used to receive the output of the corresponding node as input; for each node, the execution priority of the node is determined according to the execution priority of the associated node corresponding to the node; based on the execution priority of each node, a target execution sequence corresponding to the multiple nodes in the graphical workflow is determined, and the order of each node in the target execution sequence precedes the corresponding associated node; based on the first logic code corresponding to each node in the graphical workflow and the target execution sequence, a second logic code for implementing the specified function can be generated.
[0019] In the embodiment of the present application, the execution priority of the node is determined according to the associated node of the node in the graphical workflow, and then the target execution sequence of multiple nodes of the graphical workflow is determined based on the execution priority. The execution order between the nodes can be accurately determined, and the nodes in the generated second logic code are executed before the associated nodes. This can avoid execution errors caused by lack of input data at the nodes, improve the code generation quality of the graphical workflow, and avoid or reduce the time waiting for the corresponding node to execute when executing to the associated node, thereby improving the execution efficiency of the code. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0021] Figure 1 is a flowchart of a code generation method provided in an embodiment of the present application;
[0022] Figure 2 is a schematic diagram of a code generation device provided in an embodiment of the present application;
[0023] Figure 3 It is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0024] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0025] The embodiment of the present application provides a code generation method, device, computer equipment and computer readable storage medium. The code generation device can be integrated in a computer equipment, which can be a server or a terminal.
[0026] The terminal may include a mobile phone, a wearable smart device, a tablet computer, a laptop computer, a personal computer (PC), and a vehicle-mounted computer.
[0027] Among them, the server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), as well as big data and artificial intelligence platforms.
[0028] It should be noted that the description order of the following embodiments is not intended to limit the preferred order of the embodiments.
[0029] This embodiment will be described from the perspective of a code generating device, which may be integrated into a computer device, which may be a server or a terminal.
[0030] The present application provides a method for generating a code, such as Figure 1 As shown, the specific process of the code generation method can be as follows:
[0031] 101. Obtain a graphical workflow for implementing a specified function, wherein the graphical workflow includes multiple nodes, wherein each node is configured to perform a corresponding operation.
[0032] The graphical workflow may include nodes and edges, and each node is equivalent to a functional module that can perform the configured operation. The graphical workflow can be configured through a graphical user interface, which may provide nodes for performing different operations, such as loader nodes, sampler nodes, encoder nodes, decoder nodes, preview / save nodes, etc. Users can obtain the corresponding graphical workflow by connecting nodes.
[0033] Loader Node can be used to load models, data or other resources. Sampler Node can be used to perform operations such as sampling or calculation. Encoder Node can be used to encode or convert input, for example, converting a text prompt entered by the user into a vector representation that the model can understand.
[0034] The code generation method provided in the embodiment of the present application can be applied to the field of image generation. The graphical workflow can be used to generate an image according to the output guide information (promt) input by the user, for example, to generate an image according to the text, picture, video or music input by the user. That is, in one embodiment, the graphical workflow is used to generate an image based on the obtained output guide information. The terminal of the embodiment of the present application executes the following steps by running the second logic code:
[0035] Obtaining output guidance information for generating an image;
[0036] Performing feature extraction processing on the output guidance information to obtain guidance feature information of the output guidance information;
[0037] A target image that conforms to the output guidance information is generated based on the guidance feature information.
[0038] Specifically, output guidance information for generating an image, such as a text image, etc., may be obtained, feature extraction processing may be performed on the output guidance information to obtain guidance feature information of the output guidance information, and a target image conforming to the output guidance information may be generated based on the guidance feature information.
[0039] Optionally, if the graphical workflow includes a node for loading a model for image generation, such as loading a DALL-E model, the image generation model can be loaded by running the second logic code, and then the output guidance information is input into the image generation model to generate a target image through the image generation model.
[0040] Optionally, depending on the requirements for image generation, corresponding nodes can be set up in the graphical workflow. For example, a node for segmenting the input image can be added to extract features of each part of the image. By running the second logic code, the image can be segmented and the features of each part of the image can be extracted.
[0041] The code generation method provided by the embodiment of the present application can accurately identify the execution dependencies of nodes in a graphical workflow, and determine the correct execution order of nodes in the graphical workflow based on the dependencies, that is, the target execution sequence. In the target execution sequence, the node is executed before the associated node, so when the associated node is executed, there will be no execution errors due to lack of input data. Therefore, the code generation method provided by the example of the present application can generate high-quality code, and when other branches execute to the associated node, there is no need to wait for the corresponding node to complete execution, which can improve the execution efficiency of the graphical workflow.
[0042] 102. Determine an associated node corresponding to each of the nodes according to a connection relationship between the multiple nodes in the graphical workflow, wherein the associated node is used to receive an output of a corresponding node as an input.
[0043] Since the nodes in the graphical workflow can be connected by edges, the associated node corresponding to each node can be determined according to the connection relationship between the nodes in the graphical workflow. The associated node takes the output of the node as input. Suppose node A in the graphical workflow outputs data a, and data a is input to node B, then node B is the associated node of node A. If the output data a of node A is not input to node B, node B is not the associated node of node A.
[0044] According to the connection relationship between the nodes in the graphical workflow, the associated node corresponding to each node can be determined. It can be understood that for the output node in the graphical workflow, as the end node of the graphical workflow, there is no corresponding associated node, or the associated node is the node itself, which is equivalent to the associated node can include a first node and a second node, wherein the input of the first node will be input to another node, and the output of the second node is not input to another node.
[0045] 103. For each of the nodes, determine the execution priority of the node according to the execution priority of the associated node corresponding to the node.
[0046] For each node, the execution priority of the node may be determined according to the execution priority of its associated node, and the execution priority of the associated node may be determined according to the execution priority of its corresponding associated node.
[0047] Exemplarily, different nodes may correspond to a preset execution priority. Based on the preset priority, the execution dependency of the nodes in the graphical workflow can be recursively analyzed, and the execution priority of the nodes can be updated. Assume that the output of node A is input to node B, and the output of node B is input to node C and node D. Node C and node D process the input respectively and output the obtained data, and the obtained data is not input to other nodes. Since node C and node D have no associated nodes, the execution priority of node C and node D is their preset execution priority. The execution priority of node B can be determined based on the execution priority of node C and node D, and the execution priority of node A can be determined based on the execution priority of node B.
[0048] For some nodes, if the execution order is late, it may cause the execution speed of the entire graphical workflow. For example, for a node with a long execution time, if the execution order is late, when its associated node has obtained other inputs, it needs to wait for the execution of the node to be completed before execution, resulting in low execution efficiency of the graphical workflow. For example, the loader node is used to load files, models and other data. If the execution order is late, it will affect the execution of other nodes. Therefore, for this type of node (which can be called a target node), a larger execution priority can be set so that the target node can be executed earlier, thereby improving the execution efficiency of the graphical workflow. Exemplarily, node c is an associated node of node a and node b, where node a has a longer execution time. If node a is executed earlier, but the output of node b is input to node c, node c can be executed immediately without waiting for node b to be executed, so the execution efficiency of the graphical workflow can be shortened.
[0049] The target node may include at least one of a loader node, a control flow point, an encoder node, a control flow node, and a node with a long execution time. Among them, a non-dependent node does not depend on the output of other nodes, and it has no input, or the input is a constant and a parameter, etc.; a control flow node is used to control the execution process of the workflow, such as conditional branches, loops, etc.
[0050] The associated node set D(n) of node n in the graphical workflow is as follows, where d is the associated node, V node represents all nodes in the graphical workflow, (n, d) represents the input dependency from node b and the output of the node, and E represents all edges in the graphical workflow.
[0051] D(n)={d|d∈V node ,(n,d)∈E}
[0052] The execution priority of a node may be the sum of the execution priorities of all its associated nodes, or the execution priorities may be weighted and summed according to the weights of the associated nodes. That is, in one embodiment, the step of "for each of the nodes, determining the execution priority of the node according to the execution priorities of the associated nodes corresponding to the node" may include:
[0053] Obtaining the execution weight of each node associated with the node;
[0054] For each of the nodes, the execution priority of the node is determined according to the execution priority and execution weight of the associated node corresponding to the node.
[0055] Among them, the execution weight of the node can be pre-set. For example, a node with complex execution logic can be given a larger weight, and a node with simple execution logic can be given a smaller weight. In one embodiment, the execution weight of the node can be set according to the amount of data of the logic code corresponding to the node.
[0056] Optionally, the weight of the associated node can be set according to the importance of the input data to the associated node. For example, assuming that the node has two inputs, one of which is the main data source and the other is auxiliary configuration information, the weight of the node for the node that outputs the main data source can be set to be greater than the weight of the node that outputs the auxiliary configuration information. For another example, assuming that the output of the node is input into two nodes respectively, one of which is used as the main data source and the other as auxiliary configuration information, the weight of the node that is the main data source can be set to be greater than the weight of the node that is used as auxiliary configuration information.
[0057] 104. Determine a target execution sequence corresponding to the plurality of nodes in the graphical workflow according to the execution priority of each of the nodes, wherein each node in the target execution sequence is arranged before the corresponding associated node.
[0058] Among them, the target execution sequence indicates the execution order of multiple nodes in the graphical workflow. The nodes of the graphical workflow are sorted according to the execution priority of each node to obtain the target execution sequence. Specifically, the node objects can be arranged from large to small based on their execution priority to obtain the target execution sequence.
[0059] It can be understood that the target execution sequence indicates the execution order of the nodes in the graphical workflow. The nodes can be executed serially or in parallel and can be set according to specific needs.
[0060] Optionally, the nodes may be topologically sorted according to execution priorities and execution dependencies between the nodes.
[0061] The execution dependency between nodes means that one node must be executed after another node. For example, the output of node A is input to node B, and the output of node B is input to node C. Then node C must be executed after nodes A and B, that is, node C depends on nodes A and B, and node B must be executed after node A, that is, node B depends on node A.
[0062] In the process of topologically sorting nodes based on execution priority and dependencies between nodes, each node is sorted before its associated node, that is, each node is sorted later than the node it depends on, to obtain the target execution sequence.
[0063] Based on the execution priority, an execution sequence can be obtained whose execution order satisfies the execution dependency, and then the logic code that can realize the execution function can be accurately generated. If a higher execution priority is set for the target node, the target node will be executed first in the target execution sequence.
[0064] Nodes with execution dependencies can be sorted based on execution priority. For nodes without execution dependencies, for example, assuming that node A and node B do not have execution dependencies, node A can be executed after node B or before node B. Therefore, in the execution sequence determined by execution priority, node A may be executed after node B or before node B.
[0065] However, for some nodes, executing them later will affect the execution efficiency of the graphical workflow. For example, there are multiple loader nodes in the graphical workflow, and some loader nodes need to be executed first to ensure that the graphical workflow is running normally. For example, in a graphical workflow for image generation, the loading node used to load the model for generating the image needs to be executed first to ensure that the generated image can be output quickly when receiving user input, without having to wait for the model to be loaded after receiving the user input.
[0066] Therefore, in one embodiment, the execution priority of the node can be adjusted according to the position characteristics of the node in the graphical workflow, and the execution sequence can be optimized based on the adjusted execution priority, so that the execution efficiency of the generated target execution sequence is higher, that is, the step of "determining the target execution sequence corresponding to the multiple nodes in the graphical workflow according to the execution priority of each node" may include:
[0067] Sort the multiple nodes according to the connection relationship of the multiple nodes and the execution priority of each of the nodes to obtain an initial execution sequence;
[0068] According to each of the nodes, based on the position characteristics of the node in the graphical workflow, adjusting the execution priority to obtain an adjusted execution priority;
[0069] The initial execution sequence is optimized based on the adjusted execution priority to obtain the target execution sequence.
[0070] For example, according to the connection relationship between the multiple nodes and the execution priority of each node, the multiple nodes are sorted to obtain an initial execution sequence. In the initial execution sequence, each node is sorted before its associated node. In the process of generating the initial execution sequence, for nodes that have no dependency relationship, the order between the nodes is randomly determined.
[0071] By adjusting the execution priority according to the position characteristics of the nodes in the graphical workflow, a target execution sequence with higher execution efficiency can be obtained. Specifically, the order of the two nodes in the node pairs that are adjacent to each other and have no execution dependency in the initial execution sequence can be adjusted according to the adjusted execution priority, and the nodes with larger execution priorities after the adjustment are sorted first, until the order of any two node pairs that are adjacent to each other and have no execution dependency is such that the nodes with larger execution priorities after the adjustment are sorted first.
[0072] Optionally, the initial execution sequence may be optimized based on the execution cost function. That is, in one embodiment, the initial execution sequence includes a plurality of node pairs, and the node pairs are used to indicate the execution order between two nodes included. The step of "optimizing the initial execution sequence based on the adjusted execution priority to obtain the target execution sequence" may include:
[0073] For the node pairs in the initial execution sequence, constructing execution cost functions of the multiple nodes, the execution cost functions are used to indicate the amount of resources consumed by executing the multiple nodes according to the current execution order;
[0074] Based on the execution cost function and the adjusted execution priority, the execution order between the multiple nodes is continuously adjusted to determine an execution sequence with a small execution cost, so as to obtain the target execution sequence.
[0075] The execution cost function can be shown as follows: opt is the target execution sequence, c(n i , n j ) is node n i Before node n j The execution cost, |S| is the total number of nodes in the target execution sequence is the execution cost of the sequence. Based on the execution cost function, the target execution sequence with the minimum sum of execution costs between node pairs in the sequence can be searched among all possible sequences of the initial execution sequence.
[0076]
[0077] For example, a cost function may be constructed, and the execution order between the multiple nodes may be continuously adjusted based on the execution cost function and the adjusted execution priority, so that the node ordering conforms to the adjusted execution priority, the execution dependency between the nodes, and the execution cost is minimized.
[0078] In one embodiment, in practical applications, we usually use heuristic algorithms to find an approximate optimal solution. Based on the heuristic algorithm, a sufficiently good solution can be found within a certain period of time. The heuristic algorithm may include a greedy algorithm, a genetic algorithm, and a taboo search algorithm.
[0079] The execution priority is adjusted according to the position characteristics of the node in the graphical workflow. The position characteristics can indicate the characteristics of the node's position in the graphical workflow, such as the depth of the node in the graphical workflow, whether it is on the critical path in the graphical workflow, and the number of its subordinate nodes (i.e., its associated nodes). According to the needs of the application scenario, one or more of the depth of the node in the graphical workflow, whether it is on the critical path in the graphical workflow, and the number of its subordinate nodes can be selected as the position characteristics of the node.
[0080] The depth of a node in a graphical workflow can be determined based on the number of its parent nodes. For example, if a node has no parent node, the depth of the node is 0. If a node is a parent node, its depth is the depth of the parent node + 1.
[0081] The critical path of a graphical workflow can be the longest execution path in the graphical workflow. Specifically, the length from each non-dependent node to the end node (such as the output node) of the graphical workflow can be determined. The length can refer to the number of nodes on the path formed from the non-dependent node to the end node according to the connection relationship. If the critical path is not executed, the final processing result cannot be obtained. Therefore, the nodes on the critical path are important nodes. Based on the critical path, it can be determined whether the node is on the critical path.
[0082] The more nodes a node has associated with it, the more nodes need the input of the node. If the node is not executed, many nodes cannot be executed. Therefore, nodes with multiple associated nodes need to be executed first.
[0083] Optionally, an adjustment parameter for adjusting the execution priority may be determined according to the position characteristics of the node, and then the execution priority may be adjusted based on the adjustment parameter. Specifically, the adjustment parameter may be added to the execution priority, or the adjustment parameter may be multiplied by the execution priority, etc., to adjust the execution priority to obtain the adjusted execution priority. That is, in one embodiment, the step of "adjusting the execution priority according to each of the nodes based on the position characteristics of the node in the graphical workflow to obtain the adjusted execution priority" may include:
[0084] According to each of the nodes, determining adjustment parameters of the node based on the position characteristics of the node in the graphical workflow;
[0085] The execution priority is adjusted based on the adjustment parameter to obtain an adjusted execution priority.
[0086] In one embodiment, the step of “determining, according to each of the nodes, the adjustment parameters of the node based on the position characteristics of the node in the graphical workflow” may include:
[0087] Determining the node depth of each node in the graphical workflow, wherein the more parent nodes a node has, the greater the node depth;
[0088] Determine a first sub-adjustment parameter corresponding to the node according to the node depth;
[0089] An adjustment parameter is determined based on the first sub-adjustment parameter.
[0090] In one embodiment, before the step of “determining the adjustment parameter based on the first sub-adjustment parameter”, the code generation method provided in the embodiment of the present application may further include:
[0091] Determining a critical path of the graphical workflow;
[0092] Determining a second sub-adjustment parameter of each node based on whether each node in the graphical workflow is located on the critical path;
[0093] The “determining the adjustment parameter based on the first sub-adjustment parameter” includes:
[0094] According to the first sub-adjustment parameter and the second sub-adjustment parameter of each node, an adjustment parameter corresponding to each of the nodes is determined.
[0095] In one embodiment, before the step of “determining the adjustment parameter corresponding to each of the nodes according to the first sub-adjustment parameter and the second sub-adjustment parameter of each node”, the code generation method provided in the embodiment of the present application may further include:
[0096] According to the number of associated nodes of each node, the third sub-adjustment parameter is determined.
[0097] The step of “determining the adjustment parameter corresponding to each node according to the first sub-adjustment parameter and the second sub-adjustment parameter of each node” may include:
[0098] Based on the first sub-adjustment parameter, the second sub-adjustment parameter and the third sub-adjustment parameter, an adjustment parameter is obtained.
[0099] The adjustment parameter may be used to adjust the execution priority, for example, by adding the adjustment parameter to the execution priority, or by multiplying the execution priority by the adjustment parameter.
[0100] Nodes with smaller node depths should be executed earlier to reduce the time the node data stays in the graphical workflow, reduce the memory usage of the data, and improve the execution effect. Therefore, the smaller the node depth, the larger the corresponding first sub-adjustment parameter.
[0101] The more associated nodes a node has, the larger its corresponding third sub-adjustment parameter is. The second sub-adjustment parameter of a node located on the critical path is greater than the second sub-adjustment parameter of a node not located on the critical path.
[0102] The adjustment parameter may be obtained by adding the first sub-adjustment parameter, the second sub-adjustment parameter and the third sub-adjustment parameter, or by weighted summing the first sub-adjustment parameter, the second sub-adjustment parameter and the third sub-adjustment parameter based on their respective corresponding weights.
[0103] It is understandable that the node's depth in the graphical workflow, whether it is on the critical path in the graphical workflow, and one or more of its subordinate nodes can be used as the node's location characteristics, and the corresponding sub-adjustment parameters can be determined to further determine the adjustment parameters. The specific process can be referred to the above-mentioned related content and will not be elaborated here.
[0104] 105. Generate a second logic code for implementing the specified function according to the first logic code corresponding to each of the nodes in the graphical workflow and the target execution sequence.
[0105] For example, each node may correspond to a logic code, and the logic code corresponding to each node may be preset, and a corresponding first logic code may be generated according to the input, output and preset logic code of the node.
[0106] A second logic code is generated based on the first logic code of each node in the graphical workflow and the target execution sequence.
[0107] Since there are many data types, usually, data are operated through general setting operation instructions. General operation instructions can be compatible with different data types, but it is difficult to take into account the execution speed. For example, for integers, efficient integer operation instructions can be used. Therefore, in one embodiment, the data type of the data processed by the graphical workflow can be determined to generate code with higher execution efficiency. The graphical workflow also includes variables. Before the step of "generating a second logic code to implement the specified function according to the first logic code corresponding to each node in the graphical workflow and the target execution sequence", the modified code generation method of the present application can also include:
[0108] Determining, according to the node corresponding to the variable in the graphical workflow, an operation to be performed on the variable;
[0109] Determining the data type of the variable according to the data type of other data involved in the operation;
[0110] According to the data type of the variable, a first logic code of the node corresponding to the variable is determined.
[0111] Nodes in a graphical workflow can be used to perform data operations, such as assignment, four arithmetic operations, etc. The nodes corresponding to a variable may include the input node of the variable, the output node of the variable, or the node that contains the variable itself. Based on each node corresponding to the variable, the operation performed on the variable can be determined, and the data type of the variable can be determined based on the data type of other data involved in the operation.
[0112] The data type that the variable needs to conform to is determined according to the data type of other data involved in the operation. Specifically, the target data type with the highest complexity can be determined from the other data types involved in the operation, and the target data type can be determined as the data type of the variable.
[0113] The complexity of the data type can be pre-set. The complexity can be set according to the difficulty of operating the data. For example, the complexity of an integer can be set smaller than the complexity of a floating-point number. The complexity can also be set according to the memory occupied by the data. For example, an integer type data occupies 4 bytes and a long integer occupies 8 bytes. The complexity of the long integer can be set greater than the integer type. Optionally, the target data type that occupies the largest memory can be selected based on the memory occupied by each data type.
[0114] The first logic code of the node is generated according to the data type of the variable. The operation instructions of the variable in the first logic code of the node can be instructions that match the data type of the variable. For example, if the variable is an integer, the instructions related to the operation of the variable in the first logic code are integer operation instructions rather than general numerical operation instructions.
[0115] It is also possible to determine the data type required for each operation according to the data type of other data involved in each operation, and then determine the data type compatible with each operation as the data type of the variable. That is, in one embodiment, there are multiple operations, and the step of "determining the data type of the variable according to the data type of other data involved in the operation" may include:
[0116] For each of the operations, determining a set of data types that the variables in the operation need to conform to according to the data types of the other data involved;
[0117] The data type of the variable is determined according to an intersection of a plurality of the data type sets.
[0118] For example, for each operation in which a variable participates, determine the data type of other data involved in the operation, determine the set of data types that the variable needs to conform to in the operation, and determine the intersection of the data type sets corresponding to multiple data operations to obtain the data type of the variable. The data model for determining the data type of the variable can be as follows:
[0119] Where T(v) is the data type of the determined variable b, t|t satisfies c is the data type required to be met in operation c, C v All operations involved in variable b, c is one of the operations.
[0120]
[0121] For example, assuming a=1, b=a+2.5, c=b×2, for b, in b=a+2.5, the data type of b must be the data type of the result of adding a and the floating-point number 2.5, because the result of adding an integer and a floating-point number is a floating-point number, so the data type set of b is {float}; in c=b×2, the data type of b must support multiplication with the integer 2, because both integers and floating-point numbers support multiplication with integers, the set of b is {int, float}, and the data type of variable b T(b)={float}∩{int, float}={float}.
[0122] After generating the second logic code capable of executing the specified function implemented by the graphical workflow, the generation quality of the second logic code may be evaluated so as to optimize the algorithm for generating the code to optimize the quality of the second logic code. That is, in one embodiment, the code generation method provided in the embodiment of the present application may further include:
[0123] A quality assessment is performed on the second logic code according to at least one quality indicator to obtain quality assessment information of the second logic code.
[0124] Among them, the quality indicators may include code complexity indicators, performance indicators and readability indicators, among which the code complexity indicators can be obtained by analyzing the structure of the code, such as the length of the function in the second logic code, the depth of nesting, the number of branches, etc., and then calculating the complexity score according to preset rules.
[0125] Optionally, the complexity index of the second logic code may also be determined based on at least one of cyclomatic complexity, Halstead complexity, and the number of code lines.
[0126] Cyclomatic complexity can be determined based on the number of edges, nodes, and connected components in the control flow graph of the second logic code. Cyclomatic complexity is an indicator used to measure the number of independent paths in the code. The higher the cyclomatic complexity, the more difficult the code is to understand and maintain. Halstead complexity can be determined based on the number of operators and operands in the code, program length, vocabulary, capacity, difficulty, and workload.
[0127] The performance indicator may be determined based on the performance of the second logic code when it is running, such as execution time, memory usage, CPU usage, etc.
[0128] Readability indicators can be determined by analyzing whether the naming and formatting of the second logic code conform to the specifications, for example, whether the naming of variables, functions, classes, etc. conforms to the specifications, such as whether camel case naming or underscore naming is used, whether meaningful names are used, etc. Whether the format of the second logic code conforms to certain specifications, such as whether appropriate indentation, spaces and line breaks are used, and whether coding specifications such as PEP8 are followed.
[0129] The model for quality assessment of the second logic code can be as follows, where Q code is the quality assessment information of the second logic code, C complexity is the code complexity index, C performance is the performance index, C readability is the readability index. α, β, and γ are the weights corresponding to the code complexity index, performance index, and readability index, respectively.
[0130] Q code =α·C complexity +β·C performance +γ·C readability
[0131] Optionally, there are multiple second logic codes, and different second logic codes are generated by different algorithms. Each second logic code may have quality evaluation information. According to the quality evaluation information of each second logic code, the second logic code with the best quality may be determined for application.
[0132] In one embodiment, after the second logic code is generated, the second logic code may be optimized to improve the operation speed of the second logic code, that is, the code generation method provided in the embodiment of the present application may further include:
[0133] Optimizing at least one of a scope, an execution path, and a memory management of the second logic code variable to obtain an optimized second logic code;
[0134] Determining a first performance evaluation index of the second logic code and a second performance evaluation index of the optimized second logic code;
[0135] An optimization evaluation result of the second logic code is determined according to the first performance evaluation index and the second performance evaluation index.
[0136] Among them, variable scope optimization can narrow the scope of variables by analyzing the definition and use of variables, thereby reducing the life cycle of variables and avoiding naming conflicts, improving the execution efficiency and maintainability of the code. For example, define variables as local variables instead of global variables; postpone the definition of variables until the first use, instead of defining all variables at the beginning of the code, so that variables are only created when they are needed; when a variable is no longer needed, delete it in time or set it to None so that the garbage collector can reclaim the memory it occupies.
[0137] Execution path optimization can improve the execution efficiency of the code by analyzing the control flow of the second logic code, removing unnecessary calculations and jumps, eliminating dead code, constant folding and optimizing loops.
[0138] Memory management optimization can reduce memory usage and memory usage by reducing the number of memory allocations and memory usage, thereby improving memory access efficiency and improving code execution efficiency. Specifically, a memory pool is allocated in advance, and the memory pool is reused during the execution of the second logic code, without having to apply to the operating system for memory allocation every time it is needed.
[0139] Memory allocation can be performed based on a memory usage optimization model to reduce memory usage, where M opt is the allocated memory size, w i is the weight factor, which is related to the importance or execution priority of the node, m i is the memory usage of each node, M max is the maximum available memory.
[0140]
[0141] For some objects that are expensive to create, you can cache them and use the cached objects directly the next time you need them, so you don't need to create a new object every time. Choose a suitable data structure to store data, such as using arrays instead of linked lists, using sparse matrices instead of dense matrices, etc. Postpone the calculation time until the result is really needed. This can avoid some unnecessary calculations and reduce memory usage.
[0142] Determine a first performance evaluation index of the second logic code and a second performance evaluation index of the optimized second logic code; and determine an optimization evaluation result of the second logic code according to the first performance evaluation index and the second performance evaluation index.
[0143] The calculation formula of the optimization evaluation result of the second logic code can be as follows, where E opt Optimize the evaluation results, P before,i is the first performance evaluation index of the i-th optimization performance index of the second logic code, P after,i is the second performance evaluation indicator of the i-th optimized performance indicator of the optimized second logic code, and n is the number of optimized performance indicators.
[0144]
[0145] The optimization performance indicator may include at least one of execution time, memory usage, CPU usage, and I / O operation times.
[0146] Optionally, the parallel efficiency of the second logic code or the optimized second logic code may also be calculated. That is, in one embodiment, the code generation method provided in the embodiment of the present application may further include:
[0147] Determining a parallel execution time and a serial execution time of the second logic code;
[0148] Determining the parallel efficiency of the second logic code according to the parallel execution time and the serial execution time;
[0149] The second logic code is optimized in parallel according to the parallel efficiency.
[0150] The calculation model of parallel efficiency is as follows, where S p is the parallel efficiency, T 1 Through a single
[0151]
[0152] Processor serial execution time, T p is the parallel execution time by p processors.
[0153] If Sp =4, indicating that the speed of executing tasks through p processors is 4 times that of using a single processor. If the speedup ratio is close to the number of processors p, the parallel effect is better; if the speedup ratio is much smaller than p, the effect of parallelization may not be good and further analysis and optimization are needed.
[0154] For example, suppose there is an image processing task that requires the same processing operation to be performed on 1,000 images. If a single processor is used to execute this task, the serial execution time T 1 The task is executed in parallel by 4 processors for 100 seconds. p The parallel efficiency is 30 seconds. According to the calculation model of parallel efficiency, we can calculate the parallel efficiency to be 3.33, which means that the speed of executing tasks using 4 processors is about 3.33 times that of using a single processor. 3.33 is less than the number of processors, 4. This shows that the parallel effect is good and can be further optimized. The reason for the long parallel time may be the overhead of task decomposition, the overhead of data synchronization, load imbalance and other reasons. By analyzing these factors, we can find the bottleneck of parallelization and optimize it in a targeted manner to improve the parallel speed.
[0155] Optionally, an error handling mechanism may be set to analyze errors that occur during the running of the second logic code. The error handling model may be as follows, where R system is the system reliability, P failure,i is the failure probability of the i-th component in the second logic code. The component can be a module, a function, a node, etc., which can be selected according to the analysis granularity.
[0156]
[0157] If the probability of errors occurring in the second logic code is high, a module that often makes errors may be determined, and then the module may be improved or switched to a spare module.
[0158] As can be seen from the above, the embodiment of the present application obtains a graphical workflow for implementing a specified function, wherein the graphical workflow includes multiple nodes, wherein each node is configured to perform a corresponding operation; based on the connection relationship between the multiple nodes in the graphical workflow, the associated node corresponding to each node is determined, wherein the associated node is used to receive the output of the corresponding node as input; for each node, the execution priority of the node is determined according to the execution priority of the associated node corresponding to the node; based on the execution priority of each node, the target execution sequence corresponding to the multiple nodes in the graphical workflow is determined, and the order of each node in the target execution sequence precedes the corresponding associated node; based on the first logic code corresponding to each node in the graphical workflow and the target execution sequence, a second logic code that implements the specified function can be generated.
[0159] In the embodiment of the present application, the execution priority of the node is determined according to the associated node of the node in the graphical workflow, and then the target execution sequence of multiple nodes of the graphical workflow is determined based on the execution priority. The execution order between the nodes can be accurately determined, and the nodes in the generated second logic code are executed before the associated nodes. This can avoid execution errors caused by lack of input data at the nodes, improve the code generation quality of the graphical workflow, and avoid or reduce the time waiting for the corresponding node to execute when executing to the associated node, thereby improving the execution efficiency of the code.
[0160] In order to better implement the code generation method provided in the embodiment of the present application, a code generation device is also provided in one embodiment. The meanings of the terms are the same as those in the above code generation method, and the specific implementation details can refer to the description in the method embodiment.
[0161] The code generating device can be integrated into a computer device, such as Figure 2 As shown, the code generation device may include: an acquisition unit 301, a node determination unit 302, a priority determination unit 303, a sorting unit 304 and a generation unit 305, which are specifically as follows:
[0162] (1) An acquisition unit 301 is used to acquire a graphical workflow for implementing a specified function, wherein the graphical workflow includes a plurality of nodes, wherein each node is configured to perform a corresponding operation.
[0163] (2) A node determination unit 302, configured to determine an associated node corresponding to each of the nodes according to a connection relationship between the plurality of nodes in the graphical workflow, wherein the associated node is configured to receive an output of a corresponding node as an input.
[0164] (3) A priority determination unit 303, configured to determine, for each of the nodes, the execution priority of the node according to the execution priority of the associated node corresponding to the node.
[0165] (4) A sorting unit 304, configured to determine a target execution sequence corresponding to the plurality of nodes in the graphical workflow according to the execution priority of each of the nodes, wherein each node in the target execution sequence is sorted prior to the corresponding associated node.
[0166] (5) A generating unit 305, configured to generate a second logic code for implementing the specified function according to the first logic code corresponding to each of the nodes in the graphical workflow and the target execution sequence.
[0167] In one embodiment, the sorting unit 304 may also be used to:
[0168] Sort the multiple nodes according to the connection relationship of the multiple nodes and the execution priority of each of the nodes to obtain an initial execution sequence;
[0169] According to each of the nodes, based on the position characteristics of the node in the graphical workflow, adjusting the execution priority to obtain an adjusted execution priority;
[0170] The initial execution sequence is optimized based on the adjusted execution priority to obtain the target execution sequence.
[0171] In one embodiment, the initial execution sequence includes a plurality of node pairs, where the node pairs are used to indicate an execution order between two nodes included. The sorting unit 304 may also be used to:
[0172] For the node pairs in the initial execution sequence, constructing execution cost functions of the multiple nodes, the execution cost functions are used to indicate the amount of resources consumed by executing the multiple nodes according to the current execution order;
[0173] Based on the execution cost function and the adjusted execution priority, the execution order between the multiple nodes is continuously adjusted to determine an execution sequence with a small execution cost, so as to obtain the target execution sequence.
[0174] In one embodiment, the sorting unit 304 may also be used to:
[0175] Obtaining the execution weight of each node associated with the node;
[0176] For each of the nodes, the execution priority of the node is determined according to the execution priority and execution weight of the associated node corresponding to the node.
[0177] In one embodiment, the graphical workflow further includes variables, and the code generation device provided in the embodiment of the present application may further include:
[0178] An operation determination unit, configured to determine an operation to be performed on a variable according to a node corresponding to the variable in the graphical workflow;
[0179] a type determination unit, configured to determine the data type of the variable according to the data type of other data involved in the operation;
[0180] The code determination unit is used to determine the first logic code of the node corresponding to the variable according to the data type of the variable.
[0181] In one embodiment, there are multiple operations, and the type determination unit may also be used to:
[0182] For each of the operations, determining a set of data types that the variables in the operation need to conform to according to the data types of the other data involved;
[0183] The data type of the variable is determined according to an intersection of a plurality of the data type sets.
[0184] In one embodiment, the code generation device provided in the embodiment of the present application may also include:
[0185] The quality assessment unit is used to perform quality assessment on the second logic code according to at least one quality indicator to obtain quality assessment information of the second logic code.
[0186] In one embodiment, the code generation device provided in the embodiment of the present application may also include:
[0187] an optimization unit, configured to optimize at least one of a scope, an execution path, and a memory management of a variable of the second logic code to obtain an optimized second logic code;
[0188] A performance evaluation unit, used to determine a first performance evaluation index of the second logic code and a second performance evaluation index of the optimized second logic code;
[0189] An optimization evaluation unit is used to determine an optimization evaluation result of the second logic code according to the first performance evaluation index and the second performance evaluation index.
[0190] In one embodiment, the code generation device provided in the embodiment of the present application may also include:
[0191] A time determination unit, used to determine a parallel execution time and a serial execution time of the second logic code;
[0192] An efficiency unit, configured to determine a parallel efficiency of the second logic code according to the parallel execution time and the serial execution time;
[0193] A parallel unit is used to perform parallel optimization on the second logic code according to the parallel efficiency.
[0194] As can be seen from the above, the code generation device of the embodiment of the present application obtains a graphical workflow for implementing a specified function through an acquisition unit 301, wherein the graphical workflow includes multiple nodes, wherein each node is configured to perform a corresponding operation; the node determination unit 302 determines the associated node corresponding to each node according to the connection relationship between the multiple nodes in the graphical workflow, wherein the associated node is used to receive the output of the corresponding node as input; the priority determination unit 303 determines the execution priority of the node for each node according to the execution priority of the associated node corresponding to the node; the sorting unit 304 determines the target execution sequence corresponding to the multiple nodes in the graphical workflow according to the execution priority of each node, and the sorting of each node in the target execution sequence precedes the corresponding associated node; the generation unit 305 can generate a second logic code for implementing the specified function according to the first logic code corresponding to each node in the graphical workflow and the target execution sequence.
[0195] In the embodiment of the present application, the execution priority of the node is determined according to the associated node of the node in the graphical workflow, and then the target execution sequence of multiple nodes of the graphical workflow is determined based on the execution priority. The execution order between the nodes can be accurately determined, and the nodes in the generated second logic code are executed before the associated nodes. This can avoid execution errors caused by lack of input data at the nodes, improve the code generation quality of the graphical workflow, and avoid or reduce the time waiting for the corresponding node to execute when executing to the associated node, thereby improving the execution efficiency of the code.
[0196] Accordingly, the embodiment of the present application also provides a computer device, which may be a terminal. Figure 3 As shown, Figure 3 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. The computer device 500 includes a processor 501 having one or more processing cores, a memory 502 having one or more computer-readable storage media, and a computer program stored in the memory 502 and executable on the processor. The processor 501 is electrically connected to the memory 502. It will be understood by those skilled in the art that the computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0197] The processor 501 is the control center of the computer device 500. It uses various interfaces and lines to connect the various parts of the entire computer device 500, executes various functions of the computer device 500 and processes data by running or loading software programs and / or modules stored in the memory 502, and calling data stored in the memory 502, thereby monitoring the computer device 500 as a whole.
[0198] In the embodiment of the present application, the processor 501 in the computer device 500 will load instructions corresponding to the processes of one or more application programs into the memory 502 according to the following steps, and the processor 501 will run the application programs stored in the memory 502 to implement various functions:
[0199] Acquire a graphical workflow for implementing a specified function, the graphical workflow comprising a plurality of nodes, wherein each node is configured to perform a corresponding operation;
[0200] Determine, according to the connection relationship between multiple nodes in the graphical workflow, an associated node corresponding to each node, wherein the associated node is used to receive the output of the corresponding node as input;
[0201] For each node, determine the execution priority of the node according to the execution priority of the associated node corresponding to the node;
[0202] According to the execution priority of each node, a target execution sequence corresponding to multiple nodes in the graphical workflow is determined, and each node in the target execution sequence is sorted before the corresponding associated node;
[0203] According to the first logic code corresponding to each node in the graphical workflow and the target execution sequence, a second logic code for implementing the specified function can be generated.
[0204] From the above, it can be seen that in the embodiment of the present application, the execution priority of the node is determined according to the associated node of the node in the graphical workflow, and then the target execution sequence of multiple nodes of the graphical workflow is determined based on the execution priority. The execution order between the nodes can be accurately determined, and the nodes in the generated second logic code are executed before the associated nodes, which can avoid execution errors caused by lack of input data at the nodes, improve the code generation quality of the graphical workflow, and avoid or reduce the time waiting for the corresponding node to execute when executing to the associated node, thereby improving the execution efficiency of the code.
[0205] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0206] Optional, such as Figure 3 As shown, the computer device 500 further includes: a touch screen 503, a radio frequency circuit 504, an audio circuit 505, an input unit 506, and a power supply 507. The processor 501 is electrically connected to the touch screen 503, the radio frequency circuit 504, the audio circuit 505, the input unit 506, and the power supply 507, respectively. Those skilled in the art can understand that Figure 3 The computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0207] The touch display screen 503 can be used to display a graphical user interface and receive operation instructions generated by the user acting on the graphical user interface. The touch display screen 503 may include a display panel and a touch panel. Among them, the display panel may be used to display information input by the user or information provided to the user and various graphical user interfaces of computer equipment, and these graphical user interfaces may be composed of graphics, text, icons, videos and any combination thereof. Optionally, the display panel may be configured in the form of a liquid crystal display (LCD, Liquid Crystal Display), an organic light emitting diode (OLED, Organic Light-Emitting Diode) and the like. The touch panel may be used to collect the user's touch operation on or near it (such as the user using any suitable object or attachment such as a finger, a stylus, etc. on the touch panel or near the touch panel), and generate corresponding operation instructions, and the operation instructions execute corresponding programs. Optionally, the touch panel may include two parts, a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into the touch point coordinates, and then sends it to the processor 501, and can receive the command sent by the processor 501 and execute it. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it is transmitted to the processor 501 to determine the type of touch event, and then the processor 501 provides a corresponding visual output on the display panel according to the type of touch event. In an embodiment of the present application, the touch panel and the display panel can be integrated into the touch display screen 503 to realize the input and output functions. However, in some embodiments, the touch panel and the touch panel can be used as two independent components to realize the input and output functions. That is, the touch display screen 503 can also be used as a part of the input unit 506 to realize the input function.
[0208] The radio frequency circuit 504 may be used to send and receive radio frequency signals, so as to establish wireless communication with a network device or other computer devices through wireless communication, and to send and receive signals between the network device or other computer devices.
[0209] The audio circuit 505 can be used to provide an audio interface between the user and the computer device through a speaker and a microphone. The audio circuit 505 can transmit the electrical signal converted from the received audio data to the speaker, which is converted into a sound signal for output; on the other hand, the microphone converts the collected sound signal into an electrical signal, which is received by the audio circuit 505 and converted into audio data, and then the audio data is output to the processor 501 for processing, and then sent to another computer device through the radio frequency circuit 504, or the audio data is output to the memory 502 for further processing. The audio circuit 505 may also include an earphone jack to provide communication between an external headset and the computer device.
[0210] The input unit 506 may be used to receive input numbers, character information or user feature information (such as fingerprint, iris, facial information, etc.), and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0211] The power supply 507 is used to supply power to various components of the computer device 500. Optionally, the power supply 507 can be logically connected to the processor 501 through a power management system, so that the power management system can manage charging, discharging, and power consumption. The power supply 507 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0212] although Figure 3 Not shown, the computer device 500 may also include a camera, a sensor, a wireless fidelity module, a Bluetooth module, etc., which will not be described in detail here.
[0213] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0214] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0215] To this end, an embodiment of the present application provides a computer-readable storage medium, in which multiple computer programs are stored, and the computer program can be loaded by a processor to execute the steps in any code generation method provided in the embodiment of the present application. For example, the computer program can execute the following steps:
[0216] Acquire a graphical workflow for implementing a specified function, the graphical workflow comprising a plurality of nodes, wherein each node is configured to perform a corresponding operation;
[0217] Determine, according to the connection relationship between multiple nodes in the graphical workflow, an associated node corresponding to each node, wherein the associated node is used to receive the output of the corresponding node as input;
[0218] For each node, determine the execution priority of the node according to the execution priority of the associated node corresponding to the node;
[0219] According to the execution priority of each node, a target execution sequence corresponding to multiple nodes in the graphical workflow is determined, and each node in the target execution sequence is sorted before the corresponding associated node;
[0220] According to the first logic code corresponding to each node in the graphical workflow and the target execution sequence, a second logic code for implementing the specified function can be generated.
[0221] From the above, it can be seen that in the embodiment of the present application, the execution priority of the node is determined according to the associated node of the node in the graphical workflow, and then the target execution sequence of multiple nodes of the graphical workflow is determined based on the execution priority. The execution order between the nodes can be accurately determined, and the nodes in the generated second logic code are executed before the associated nodes, which can avoid execution errors caused by lack of input data at the nodes, improve the code generation quality of the graphical workflow, and avoid or reduce the time waiting for the corresponding node to execute when executing to the associated node, thereby improving the execution efficiency of the code.
[0222] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0223] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0224] The above is a detailed introduction to a code generation method, device, computer equipment and computer storage medium provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for technical personnel in this field, according to the ideas of the present application, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A code generation method, characterized in that: include: Acquire a graphical workflow for implementing a specified function, wherein the graphical workflow includes a plurality of nodes, wherein each node is configured to perform a corresponding operation; Determine, according to the connection relationship between the plurality of nodes in the graphical workflow, an associated node corresponding to each of the nodes, wherein the associated node is used to receive an output of a corresponding node as an input; For each of the nodes, determining the execution priority of the node according to the execution priority of the associated node corresponding to the node; Determining a target execution sequence corresponding to the plurality of nodes in the graphical workflow according to the execution priority of each of the nodes, wherein each node in the target execution sequence is ranked before the corresponding associated node; A second logic code for implementing the specified function is generated according to the first logic code corresponding to each of the nodes in the graphical workflow and the target execution sequence.
2. The method according to claim 1, characterized in that Determining the target execution sequence corresponding to the plurality of nodes in the graphical workflow according to the execution priority of each of the nodes includes: Sort the multiple nodes according to the connection relationship of the multiple nodes and the execution priority of each of the nodes to obtain an initial execution sequence; According to each of the nodes, based on the position characteristics of the node in the graphical workflow, adjusting the execution priority to obtain an adjusted execution priority; The initial execution sequence is optimized based on the adjusted execution priority to obtain the target execution sequence.
3. The method according to claim 2, characterized in that The initial execution sequence includes a plurality of node pairs, where the node pairs are used to indicate an execution order between two nodes included therein, and the initial execution sequence is optimized based on the adjusted execution priority to obtain the target execution sequence, including: For the node pairs in the initial execution sequence, constructing execution cost functions of the multiple nodes, the execution cost functions are used to indicate the amount of resources consumed by executing the multiple nodes according to the current execution order; Based on the execution cost function and the adjusted execution priority, the execution order between the multiple nodes is continuously adjusted to determine an execution sequence with a small execution cost, so as to obtain the target execution sequence.
4. The method according to claim 1, characterized in that: The step of determining, for each of the nodes, the execution priority of the node according to the execution priority of the associated node corresponding to the node, includes: Obtaining the execution weight of each node associated with the node; For each of the nodes, the execution priority of the node is determined according to the execution priority and execution weight of the associated node corresponding to the node.
5. The method according to claim 1, characterized in that The graphical workflow further includes variables. Before generating the second logic code for implementing the specified function according to the first logic code corresponding to each node in the graphical workflow and the target execution sequence, the method further includes: Determining, according to the node corresponding to the variable in the graphical workflow, an operation to be performed on the variable; Determining the data type of the variable according to the data type of other data involved in the operation; According to the data type of the variable, a first logic code of the node corresponding to the variable is determined.
6. The method according to claim 5, characterized in that There are multiple operations, and determining the data type of the variable according to the data type of other data involved in the operation includes: For each of the operations, determining a set of data types that the variables in the operation need to conform to according to the data types of the other data involved; The data type of the variable is determined according to an intersection of a plurality of the data type sets.
7. The method according to any one of claims 1 to 6, characterized in that: The method further comprises: A quality assessment is performed on the second logic code according to at least one quality indicator to obtain quality assessment information of the second logic code.
8. The method according to any one of claims 1 to 6, characterized in that: The method further comprises: Optimizing at least one of a scope, an execution path, and a memory management of a variable of the second logic code to obtain an optimized second logic code; Determining a first performance evaluation index of the second logic code and a second performance evaluation index of the optimized second logic code; An optimization evaluation result of the second logic code is determined according to the first performance evaluation index and the second performance evaluation index.
9. The method according to any one of claims 1 to 6, characterized in that: The method further comprises: Determining a parallel execution time and a serial execution time of the second logic code; Determining the parallel efficiency of the second logic code according to the parallel execution time and the serial execution time; The second logic code is optimized in parallel according to the parallel efficiency.
10. The method according to any one of claims 1 to 6, characterized in that: The graphical workflow is used to generate an image based on the acquired output guidance information, and the following steps are performed by running the second logic code: Obtaining output guidance information for generating an image; Performing feature extraction processing on the output guidance information to obtain guidance feature information of the output guidance information; A target image that conforms to the output guide information is generated based on the guide feature information.
11. A code generating device, characterized in that: include: An acquisition unit, configured to acquire a graphical workflow for implementing a specified function, wherein the graphical workflow includes a plurality of nodes, wherein each node is configured to perform a corresponding operation; A node determination unit, configured to determine an associated node corresponding to each of the nodes according to a connection relationship between the plurality of nodes in the graphical workflow, wherein the associated node is configured to receive an output of a corresponding node as an input; A priority determination unit, configured to determine, for each of the nodes, an execution priority of the node according to an execution priority of an associated node corresponding to the node; A sorting unit, configured to determine a target execution sequence corresponding to the plurality of nodes in the graphical workflow according to the execution priority of each of the nodes, wherein each node in the target execution sequence is sorted prior to the corresponding associated node; A generating unit is used to generate a second logic code for implementing the specified function according to the first logic code corresponding to each of the nodes in the graphical workflow and the target execution sequence.
12. A computer device, characterized in that: The invention comprises a memory and a processor; the memory stores a computer program, and the processor is used to run the computer program in the memory to execute the code generation method according to any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, and the computer program is loaded by a processor to execute the code generation method according to any one of claims 1 to 10.