Code generation method, device and equipment
By generating and storing the code of the calculation diagram in the network card program memory, the network card memory limitation and programming complexity problems are solved, and business diversification and memory saving are achieved.
Patent Information
- Application Number
- CN202410168570.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-05
- Publication Date
- 2025-08-05
AI Technical Summary
Network card memory is limited, existing programming languages and instructions are complex, and it is difficult to meet the needs of diversified business. The existing technology cannot effectively utilize directed acyclic graphs to generate executable code sets.
By generating calculation diagrams, splicing nodes and general code segments, forming a code set, which is directly stored in the network card program memory area, avoiding the shared library from occupying data memory and achieving general functions.
It reduces the network card programming workload, meets the needs of diversified business, saves data memory area overhead, and supports complex business processing processes.
Smart Images

Figure CN120428962A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a code generation method, apparatus, and device. Background Art
[0002] As the gap between the growth rate of processor computing power and the growth rate of network bandwidth becomes increasingly larger, more and more functions are offloaded to network cards. For example, network cards play an important role in network protocol processing, network function virtualization, storage protocol processing, security control, etc.
[0003] Programming enables hardware to implement different functions through software. As network cards (NICs) handle more diverse services, they also require programming. However, NICs have limited memory, which restricts their programmability. Currently, NICs are programmed using a domain-specific language (DSL) and specific hardware instructions. This requires developers to learn both DSL and specific hardware instructions, increasing the NIC programming workload. Furthermore, the DSL currently used for NIC programming has limited functionality, making it difficult to meet the diverse needs of NIC services. Summary of the Invention
[0004] The present application provides a code generation method, apparatus, and device. The code generated by the method can save data memory area in the memory.
[0005] In a first aspect, a code generation method is provided, the method comprising: obtaining a computational graph corresponding to a processing flow of a target business, the computational graph comprising a plurality of nodes and connecting edges between the nodes; wherein each of the plurality of nodes corresponds to at least one processing step in the processing flow, the node comprises a code segment for executing the processing step corresponding to the node, and the connecting edges are used to represent data dependencies between the nodes connected by the connecting edges; splicing the code segments included in the plurality of nodes and the general code segments to obtain a code set for processing the target business; wherein the general code segment comprises a first code segment for transferring data between nodes, and in the code set, the first code segment is inserted between the code segments included in the nodes connected by the connecting edges.
[0006] The method provided in the embodiment of the present application can be used to program devices with limited memory (such as network cards), reduce programming workload, and meet the needs of device business diversification.
[0007] In related technologies, business logic code implements general functions by calling general operators in a shared object library (SO). The shared library is stored in the computer's data memory area, which means that the shared library occupies the storage space in the data memory area.
[0008] The method provided by the embodiments of the present application incorporates common code segments that perform common functions into a business code set. This eliminates the need for shared libraries when using this code set to process the target business, eliminating the need to store shared libraries in the data memory area, thus saving data memory area overhead. Furthermore, the code set occupies the program memory area in the main memory, not the data memory area, further saving data memory area.
[0009] In a possible implementation, the target service is a service executed in a network card, and the method further includes: storing the code set in a program memory area of the network card, so that the network card uses the code set to process the target service.
[0010] The code set is stored in the program memory area of the network card. When the network card needs to execute a service, it can load the code set from the program memory area, so that the code set can be used to process the service.
[0011] In a possible implementation, the first code segment is used to transmit a storage address of data between nodes, and the code segment included in the node is used to obtain data based on the storage address.
[0012] The storage address of data is transferred between nodes, and the nodes can obtain related data based on the storage address, thereby realizing the transfer of data between nodes without copying the data.
[0013] In one possible implementation, the computational graph is generated in response to a user's operation; the method further includes: providing guidance information for the graph generation operation to the user, the guidance information including multiple node types, functions corresponding to each of the multiple node types, and the function corresponding to a node type being associated with at least one processing step in the processing flow.
[0014] Guidance information can be provided to the user, and the user can develop a node relationship diagram suitable for the method based on the guidance information, thereby improving the development efficiency of the node relationship diagram.
[0015] In one possible implementation, multiple node types include node types corresponding to conditional branch judgment functions and node types corresponding to conditional branch processing functions; wherein, the processing steps associated with the conditional branch judgment function are used to determine the conditions satisfied by the business data of the target business, and based on the conditions satisfied by the business data, the processing steps associated with the conditional branch processing function are called to process the business data.
[0016] The method can generate conditional branch code, that is, generate a code set including the conditional branch code, thereby expressing the conditional branch semantics, and can generate a code set for a business process flow containing the conditional branch semantics.
[0017] In one possible implementation, multiple node types include node types corresponding to parallel data distribution functions; wherein the multiple nodes include a first node, a second node, and a third node of a node type corresponding to the parallel data distribution function; wherein the processing steps corresponding to the third node are used to distribute business data of the target business to the first node and the second node; the first node and the second node are each used to process the received data.
[0018] The method can generate parallel data distribution code, that is, generate a code set including parallel data distribution code, thereby expressing parallel data distribution semantics, and generating a code set for a business process flow containing parallel data distribution semantics.
[0019] In one possible implementation, different nodes among the multiple nodes read and write data based on the same data structure. In this way, different nodes can recognize each other's output data, facilitating data transmission between different nodes.
[0020] In one possible implementation, the computation graph is a directed acyclic graph (DAG). In other words, the method can generate a code set based on the DAG.
[0021] In a second aspect, a code generation device is provided, which includes: an acquisition unit for acquiring a computational graph corresponding to a processing flow of a target business, the computational graph including multiple nodes and connecting edges between the nodes; wherein each of the multiple nodes corresponds to at least one processing step in the processing flow, the node includes a code segment for executing the processing step corresponding to the node, and the connecting edge is used to represent the data dependency relationship between the nodes connected by the connecting edge; a splicing unit for splicing the code segments included in the multiple nodes and the general code segment to obtain a code set for processing the target business; wherein the general code segment includes a first code segment for transferring data between nodes, and in the code set, the first code segment is inserted between the code segments included in the nodes connected by the connecting edge.
[0022] In a possible implementation, the target service is a service executed in a network card, and the device further includes: a storage unit, configured to store the code set in a program memory area of the network card, so that the network card uses the code set to process the target service.
[0023] In a possible implementation, the first code segment is used to transmit a storage address of data between nodes, and the code segment included in the node is used to obtain data based on the storage address.
[0024] In one possible implementation, the computational graph is generated in response to a user's operation; the device also includes: a providing unit for providing guidance information for the graph generation operation to the user, the guidance information including multiple node types, functions corresponding to each of the multiple node types, and a function corresponding to a node type being associated with at least one processing step in the processing flow.
[0025] In one possible implementation, multiple node types include node types corresponding to conditional branch judgment functions and node types corresponding to conditional branch processing functions; wherein, the processing steps associated with the conditional branch judgment function are used to determine the conditions satisfied by the business data of the target business, and based on the conditions satisfied by the business data, the processing steps associated with the conditional branch processing function are called to process the business data.
[0026] In one possible implementation, multiple node types include node types corresponding to parallel data distribution functions; wherein the multiple nodes include a first node, a second node, and a third node of a node type corresponding to the parallel data distribution function; wherein the processing steps corresponding to the third node are used to distribute business data of the target business to the first node and the second node; the first node and the second node are each used to process the received data.
[0027] In a possible implementation, different nodes among the multiple nodes read and write data based on the same data structure.
[0028] In a possible implementation, the computation graph is a directed acyclic graph (DAG).
[0029] In a third aspect, a computing device is provided, comprising: a memory for storing an executable program; and a processor for executing the method provided in the first aspect by running the executable program.
[0030] In a fourth aspect, a computer-readable storage medium is provided, comprising: computer program instructions. When the computer program instructions are executed by a computing device, the computing device executes the method provided in the first aspect.
[0031] In a fifth aspect, a computer program product comprising instructions is provided, wherein when the instructions are executed by a computing device, the computing device is caused to execute the method provided in the first aspect.
[0032] The beneficial effects of the second to fifth aspects can be referred to the above introduction to the beneficial effects of the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 This is a schematic diagram of a system architecture provided by an embodiment of the present application;
[0034] Figure 2This is a flowchart of a code generation method provided by an embodiment of the present application;
[0035] Figure 3 is a schematic diagram of a calculation graph provided in an embodiment of the present application;
[0036] Figure 4 is a schematic diagram of a calculation graph provided in an embodiment of the present application;
[0037] Figure 5 is a schematic diagram of a calculation graph provided in an embodiment of the present application;
[0038] Figure 6 is a schematic diagram of a calculation graph provided in an embodiment of the present application;
[0039] Figure 7 This is a schematic diagram of a computational graph construction provided by an embodiment of the present application;
[0040] Figure 8 is a schematic diagram of a calculation graph provided in an embodiment of the present application;
[0041] Figure 9 is a schematic diagram of a calculation graph provided in an embodiment of the present application;
[0042] Figure 10 is a schematic diagram of a calculation graph provided in an embodiment of the present application;
[0043] Figure 11 is a schematic diagram of a calculation graph provided in an embodiment of the present application;
[0044] Figure 12 This is a schematic diagram of the structure of a code generation device provided in an embodiment of the present application;
[0045] Figure 13 A schematic diagram of the structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0046] The following describes the solutions provided by the embodiments of the present application in conjunction with the accompanying drawings. In the embodiments of the present application, "plurality" refers to two or more, and "multiple" refers to two or more. Terms such as "first" and "second" are used only to distinguish similar objects and do not necessarily describe a specific order or quantity of objects.
[0047] To facilitate understanding of the solutions provided by the embodiments of the present application, the technical terms that may be involved in the embodiments of the present application are first introduced.
[0048] Network card: also known as network interface card (NIC): is a piece of hardware used for computers to communicate on a computer network.
[0049] Smart NIC (Smart NIC): A smart NIC includes a processor and memory. In some application scenarios, a smart NIC may have persistent memory media, such as persistent memory (PM), non-volatile random access memory (NVRAM), or phase change memory (PCM). The processor performs operations such as address translation and reading and writing data. The NIC's memory can be divided into a program memory area and a data memory area. The program memory area is used to store software code used by the NIC. After the software code is stored in the program memory area, the NIC's processor can call and execute the software code from the program memory area after the NIC is started, thereby implementing related functions. The data memory area is used to store data, such as service data received by the NIC and intermediate processing results of the NIC.
[0050] Programmable network cards (NICs): These are smart NICs that can execute software code to implement related functions. NICs can be implemented using field programmable gate arrays (FPGAs), network processors (NPs), and application-specific integrated circuits (ASICs). FPGA-based NICs achieve programmability by directly programming hardware logic, and their performance approaches that of ASICs. However, FPGAs are programmed using Verilog / VHDL, which has a low level of abstraction and is difficult to program. The usability of the entire FPGA development tool chain also needs to be improved. NP-based NICs have weaker single-core performance than FPGAs, so they use a multi-core approach to improve the processing power of the entire NIC. NP-based NICs are typically multi-core NPs. NPs are often written in the general-purpose C / C++ language and offer a high degree of programmability.
[0051] A dedicated processing device (DP) is a device whose processor is a specialized processor. A dedicated processor, as opposed to a central processing unit (CPU), is designed for a specific application or domain. A programmable network interface card (NIC) is a typical dedicated processing device. Memory resources and other resources are limited in dedicated processing devices. Specifically, the data memory area of a dedicated processing device has limited storage space. Furthermore, the program memory area of a dedicated processing device is more spacious than the data memory area.
[0052] A computational graph (graph) is a graphical representation of a business process. A computational graph consists of multiple nodes, each corresponding to one or more processing steps. Each node contains a code segment for executing the processing step corresponding to that node. Data dependencies between nodes are represented by edges between them. Edges are directed, running from the end to the beginning. The output of the node connected to the end of the edge is the input of the node connected to the beginning of the edge. A directed acyclic graph (DAG) is a common computational graph.
[0053] Code snippet: refers to a section of code that can be used to implement one or more functions.
[0054] Common functions: These are functions involved in processing multiple services, such as transferring data between nodes or threads, sending data from a network card to a host or network, and allocating memory to nodes or threads.
[0055] Common code segment: refers to the code used for one or more common functions.
[0056] Shared object library (SO): A shared library encapsulates the functionality of multiple general-purpose operators. Shared libraries are stored in the computer's data memory area, occupying storage space in the data memory area. In related technologies, business code implements general-purpose functionality by calling general-purpose operators in shared libraries.
[0057] One approach uses DSL and specific hardware instructions to program programmable network cards. However, this approach increases the programming workload for network cards. Furthermore, DSL offers limited functionality, making it difficult to meet the diverse needs of network card services.
[0058] In one approach, the business process is divided into multiple stages, which are then executed serially. This approach reduces the memory requirements at any given moment by trading time for space. However, this approach is only suitable for pipelined business processes and cannot handle more complex business processes. For example, if the business process requires conditional branching or parallel execution, this approach is no longer applicable.
[0059] Business processing flows on the data plane are becoming increasingly complex, involving diverse core business modules, internal logic operations, caching, persistence, and external resource handling. This requires modular decoupling and abstraction to reduce programming complexity. Currently, directed acyclic graphs (DAGs) are commonly used to represent business processing flows. DAGs can express branching and parallel processing logic. However, due to the limited memory resources of dedicated processing devices such as programmable network cards (NICs), current NIC programming technologies do not yet offer a solution for generating a code set executable by a dedicated processing device based on DAGs.
[0060] An embodiment of the present application provides a code generation method. This method can generate a code set that can be executed by a dedicated data processing device based on a computation graph such as a directed acyclic graph. Specifically, the code segments and general code segments in the computation graph can be spliced together to obtain a code set for processing the target business. In other words, the general code is included in the code set for the target business. The general code is used to implement general functions, and the general code occupies the program memory area of the dedicated data processing device. In this way, general functions can be implemented without increasing the data memory area overhead of the dedicated data processing device.
[0061] Next, the code generation method provided by the embodiment of the present application is introduced.
[0062] Figure 1 A system architecture provided by an embodiment of the present application is shown. Figure 1 As shown, the system architecture includes a code generating device 100 and a business processing device 200.
[0063] The code generation device 100 may be any module, device, equipment, cluster or platform with data processing capabilities. Figure 1 As shown, the code generation device 100 can obtain a computation graph developed by a user. The code generation device 100 can combine the code segments in the computation graph with the common code segments to obtain a code set for the business. The code generation device 100 can then store the code set in the program memory area of the business processing device 200.
[0064] The service processing device 200 may be a dedicated processing device, such as a network card, and may process received service data by executing a code set.
[0065] Next, the code generation method provided in the embodiment of the present application is introduced in combination with the system architecture.
[0066] This method can be specifically executed by the code generating device 100. Figure 2 As shown, the method includes the following steps.
[0067] Step 201: Obtain a computational graph corresponding to the processing flow of the target business, wherein the computational graph includes multiple nodes and connecting edges between the nodes; wherein each of the multiple nodes corresponds to at least one processing step in the processing flow, the node includes a code segment for executing the processing step corresponding to the node, and the connecting edges are used to represent data dependencies between the nodes connected by the connecting edges.
[0068] In some embodiments, the computation graph is specifically a directed acyclic graph.
[0069] The computation graph can be user-developed. Graphical code development can improve code development efficiency and reduce code development difficulty. Furthermore, the computation graph can express complex business process flows. The code generation method provided in the embodiments of this application uses the computation graph as input, which can improve the development efficiency of business process logic code and reduce its difficulty. Furthermore, the code generation method provided in this application can handle complex business process flows.
[0070] In some embodiments, the model description language (MDL) format may be used to describe the nodes and connecting edges in the computation graph.
[0071] In some embodiments, the computation graph may be generated by the code generation device 100 in response to a user's operation. To facilitate user computation graph development and improve computation graph development efficiency, the code generation device 100 also provides the user with guidance information for the graph generation operation. The graph generation operation refers to the operation of generating a computation graph. The guidance information may include multiple node types and the functions corresponding to each of the multiple node types. The functions corresponding to the node types are associated with at least one processing step in the business processing flow.
[0072] In an example, the guidance information may be as shown in Table 1.
[0073]
[0074]
[0075] Node types may include parsing nodes, processing nodes, forwarding nodes, conditional branch nodes, parallel dispatch nodes, and the like.
[0076] The function corresponding to the parsing node is message parsing, and the processing steps associated with the function are parsing of the message header or message body, etc. The parsing node includes a code segment for executing the processing steps associated with the function corresponding to the parsing node.
[0077] The function corresponding to a processing node is data processing, and the processing steps associated with this function include processing of service data carried in a message. The processing node includes a code segment for executing processing steps such as processing service data. The processing node includes a code segment for executing processing steps associated with the function corresponding to the processing node.
[0078] The function corresponding to the forwarding node is message forwarding, and the processing step associated with this function is forwarding the message to the host or network side. The forwarding node includes a code segment for executing the processing step such as forwarding the message to the host or network side. The forwarding node also includes a code segment for executing the processing step associated with the function corresponding to the forwarding node.
[0079] The function corresponding to a conditional branch node is a conditional branch judgment function. The associated processing steps are used to determine whether the business data of a business meets the conditions. Based on the conditions met by the data, the processing steps associated with the conditional branch processing function are called to process the business data. The conditional branch node includes a code segment for executing the processing steps associated with the function corresponding to the conditional branch node. The node type corresponding to the conditional branch processing function is a processing node. In other words, the processing node includes a node corresponding to the branch processing function.
[0080] The function corresponding to a parallel distribution node is parallel data distribution. A parallel distribution node can distribute service data to multiple processing nodes. A node within these multiple processing nodes can be referred to as a parallel computing node. Each of these multiple parallel computing nodes processes its own received data. The parallel distribution node includes a code segment for executing the processing steps associated with the function corresponding to the parallel distribution node.
[0081] The processing steps in the business processing flow can be converted into nodes in the calculation graph, where the connecting edges between the nodes in the calculation graph describe the data dependency between the processing steps corresponding to the nodes. Usually, the basic calculation graph consists of a parsing node, at least one processing node and a forwarding node. The calculation graph can be nested, that is, a node can be a child graph, and a child graph includes at least one or more processing nodes. In the child graph, the parsing node and the forwarding node are optional. In one example, Figure 3 In the computational graph shown, node 31 is a parsing node, node 32 is a processing node, and node 33 is a forwarding node. Node 32 may be a subgraph that includes nodes 321, 322, and 323. Nodes 321, 322, and 323 are all processing nodes.
[0082] The nodes in a computational graph have independent processing functions. Nodes are decoupled and can be flexibly orchestrated. This allows for node reuse across different businesses, reducing the burden on developers. More specifically, a node library can be provided, containing multiple nodes, each corresponding to a specific function. Based on business needs, nodes can be selected from the library and the data dependencies between the selected nodes can be orchestrated to create a computational graph suitable for processing that business.
[0083] Computational graphs can be divided into pipeline computational graphs, conditional computational graphs, parallel computational graphs, and hybrid computational graphs.
[0084] The pipeline computation graph is the simplest computation graph. Figure 3 is a pipeline computation graph. Figure 3 As shown, each node in the pipeline computation graph is connected in series. The pipeline computation graph does not contain conditional branches or parallel distribution logic. The output of the predecessor node is the input of the successor node. The predecessor node is at the end of the connection edge, and the successor node is at the beginning of the connection edge, that is, the connection edge points from the predecessor node to the successor node. Figure 3 As shown, a node can be a sub-pipeline computation graph.
[0085] A conditional computation graph is a computation graph with conditional branches. The conditional computation graph includes at least one conditional branch node. The conditional branch node, which is a predecessor node, has multiple successor nodes. The conditional branch node selects different successor nodes to process business data based on its unique output condition. For example, Figure 4 A conditional computation graph is shown, which includes nodes 41, 42, 43, and 44. Node 42 is a conditional branch node, and nodes 43 and 44 are successor nodes of node 42. Node 42 can select one of nodes 43 and 44 based on the unique output condition of node 42 and send business data to the selected node, so that the selected node processes the business data.
[0086] In some embodiments, a conditional branch node only supports the judgment logic of one condition, which can be expressed using conditional branch judgment semantics. In complex condition scenarios, users are required to convert complex conditions into a single condition.
[0087] In some embodiments, the successor node of the conditional branch node has no successor node. The successor node of the conditional branch node may be a subgraph, and a successor node of the conditional branch node may include multiple nodes.
[0088] If there is no data dependency between two or more steps in the business processing flow, the two or more steps can be executed in parallel. The parallel execution of steps can be achieved through a parallel computation graph. The parallel computation graph includes at least a parallel distribution node. The parallel distribution node has multiple successor nodes. The parallel distribution node can distribute business data to different successor nodes, wherein each successor node processes the data received by the successor node. In addition, the multiple successor nodes can serve as predecessor nodes and have one successor node. The processing results of the multiple successor nodes can be aggregated, and the aggregated results can be sent to the successor nodes of the multiple successor nodes. For example, Figure 5 A parallel computation graph is shown, comprising nodes 51, 52, 53, 54, 55, and 56. Node 52 is a parallel distribution node, and nodes 53 and 54 are successor nodes of node 52. Node 52 can send a portion of its received service data to node 53 and another portion to node 54. Node 54 and node 53 share a common successor node 55. The processing results of nodes 53 and 54 can be aggregated, and node 55 can obtain the aggregated results.
[0089] A hybrid computation graph includes multiple nodes, where each node can be a subgraph.
[0090] The examples above introduce the types of computation graphs. Next, we will introduce the data corresponding to the computation graphs.
[0091] The formal parameters of the code snippet in the first node of the computation graph (i.e., the first node through which data enters the computation graph from outside) must include both output and input parameters. The code snippet in the last node of the computation graph (i.e., the last node through which data passes in the computation graph) serves as input parameters, and the code snippets in intermediate nodes (i.e., nodes in the computation graph other than the first and last nodes) serve as both output and input parameters. If nodes are reused, the generated function may actually have either output or input parameters, in which case the description must include superimposed attributes. The validity of the parameters is guaranteed by the business during use.
[0092] In order to facilitate the nodes in the calculation graph to identify the data output by other nodes, a data structure can be predefined. Each node reads and writes data according to the data structure, that is, different nodes in the calculation graph read and write data based on the same data structure. In this way, the node can read the data stored in the storage space of other nodes, so that the node can identify the data output by other nodes. When the calculation graph is applied in the network protocol processing scenario, the calculation graph needs to process the message header and the user data (userdata) carried by the message. A data structure that can accommodate the message header and user data can be predefined, wherein the data structure is also called a context structure. For scenarios that do not require processing of network protocol processing, the defined data structure can only accommodate user data.
[0093] When data needs to be transferred between nodes, only the pointer of the data structure needs to be transferred. The pointer refers to the memory address of the data structure. For example, Figure 6 As shown, node 62 is the successor node of node 61, and node 63 is the successor node of node 62. Node 61 can write the processing result of node 61 into a data structure. A pointer to the data structure can be passed to node 62, and node 62 can read the processing result of node 61 from the data structure based on the pointer. Node 62 can write the processing result of node 62 into a data structure. A pointer to the data structure can be passed to node 63, and node 63 can read the processing result of node 62 from the data structure based on the pointer. In this way, when the nodes of the computation graph run on the same device, data transfer between nodes does not require data copying, saving the overhead of data copying.
[0094] In some embodiments, different nodes in the same computation graph can run on different devices. For example, some nodes can run on a network card (NIC) and others on a host computer. Nodes running on the same device can transfer data between them by passing pointers to data structures. When a node running on a device needs to transfer data to a node running on another device, the data can be transferred via direct memory access (DMA).
[0095] You can refer to Figure 7 The method shown,develops the computation graph as follows.
[0096] In step 701, a computation graph is defined. A computation graph may be defined by using the "graph" function, for example, defining a name for the computation graph.
[0097] In some embodiments, when the business corresponding to the computation graph is triggered by a direct call from an application (APP), or when the business corresponding to the computation graph is triggered by a message in the receive (RX) direction, it is necessary to use "main" to modify the first node of the computation graph to identify the node as the graph flow entry. The first node in a subgraph called by other nodes in the same computation graph does not need to be modified with "main". In addition, the computation graph where the node modified by "main" is located can be used as a subgraph of other businesses and called by the computation graphs corresponding to other businesses. The node modified by "main" is the first node of the computation graph where the node is located.
[0098] In step 702, multiple nodes may be selected in sequence, and data dependencies between the nodes may be established. Nodes may be selected based on the target business's processing flow, sorted, and data dependencies between the nodes established. The order in which the nodes are arranged aligns with the order of the processing steps in the target business's processing flow. The data dependencies between the nodes align with the data dependencies between the processing steps in the processing flow.
[0099] In step 703, the code in the node is constructed. The node code is used to execute the processing flow corresponding to the node. The code can be a parameter prototype. For parsing nodes, the code is used to perform steps such as parsing the message header. For processing nodes, the code is used to perform steps such as message processing. A unified parameter structure is defined for each node, simplifying implementation. The data structure is predefined and used by the node to read and write data. In some embodiments, the data structure can be user-defined.
[0100] In some embodiments, Figure 8 The pipeline calculation diagram is shown in Figure 8 In the computation graph shown, nodes 81, 82, and 83 are defined in sequence. The order of nodes 81, 82, and 83 corresponds to the order of the processing steps in the target business process corresponding to the computation graph. Node 81 includes the code "func81," node 82 includes the code "func82," and node 83 includes the code "func83." The execution result of code "func81" is the input to code "func82," and the execution result of code "func82" is the input to code "func83."
[0101] In some embodiments, Figure 9 A conditional branch calculation graph is shown. Figure 9In the calculation graph shown, nodes 91, node 92, node 93 / node 94, and node 95 are defined in sequence. Among them, node 92 is a conditional branch node. "context.key" is metadata defined by the user or manufacturer, and is a thread variable. Among them, the manufacturer may refer to the manufacturer that produces or designs the business processing device 200. "context.key" represents the branch condition set by the user, that is, the value that meets the condition. "context.key" can be dynamically set when the code set corresponding to the calculation graph is running, that is, when the business data is processed by the code set of the calculation graph object, "context.key" is dynamically set. "Case" and the numerical value following it are the conditional results enumerated by the user. Node 91 includes the code "func91", node 92 includes the code "func92", node 93 includes the code "func93", node 94 includes the code "func94", and node 95 includes the code "func95". Among them, the execution result of code "func91" is the input of code "func92", the execution result of code "func92" is the input of code "func93" or the input of code "func94", and the execution result of code "func93" or the execution result of code "func94" is the input of code "func95".
[0102] Figure 9 The “switch” shown is a keyword in the code of node 92 . “Switch” provides branching semantics, and each conditional branch process can be nested as a subgraph.
[0103] Generally speaking, conditional statements encountered during message processing can be included in the node's internal programming, that is, included in the node's code, and do not need to be arranged as conditional branch nodes. However, if nodes 93 and 94 involve thread switching, asynchronous processing, cross-device interaction, etc., it is necessary to explicitly define the predecessor node of nodes 93 and 94 (i.e., node 92) as a conditional branch node.
[0104] Figure 10 A parallel computation graph is shown. Figure 10The computation graph shown in the figure defines node 101, node 102, multiple nodes 103, and node 104. Node 101 includes the code "func101," node 102 includes the code "func102," and node 103 includes the code "func103." The execution result of code "func101" is the input to code "func102," the execution result of code "func102" is the input to code "func103," and the execution result of code "func103" is the input to code "func104." "context.num" is user- or vendor-defined metadata, a thread variable that indicates the maximum concurrency value. Node 102 is a parallel distribution node, and the execution results of node 102's code are distributed to multiple nodes 103. The number of nodes 103 in multiple nodes 103 is "context.num." Multiple nodes 103 are executed in parallel, and can be referred to as parallel computing nodes.
[0105] in, Figure 10 "parallel_copy" is a keyword in the code of node 102. "parallel_copy" provides parallel copy semantics. The value of "context.num" can be determined at runtime. Multiple nodes 103 are executed in parallel and can be nested into a subgraph.
[0106] In some embodiments, as Figure 11 As shown, node 102 (i.e., a parallel distribution node) in the parallel computing graph has multiple data outlets. Each of these data outlets corresponds to a single node 103. Node 102 sends data through a data outlet to the corresponding node 103. Multiple nodes 103 perform computations in parallel and save the computation results. Each node 103 has a corresponding timer. The timer values of these timers are used to determine whether the execution of different nodes 103 is synchronized.
[0107] Continue reading Figure 2 The code generation method provided in the embodiment of the present application also includes step 202, splicing the code segments included in the multiple nodes and the general code segments to obtain a code set for processing the target business; wherein the general code segment includes a first code segment for transmitting data between nodes, and in the code set, the first code segment is inserted between the code segments included in the nodes connected by the connection edge.
[0108] As mentioned above, the order in which the nodes are arranged corresponds to the order in which the processing steps in the target business process are sequenced. Therefore, the code segments in each node can be concatenated according to the order in which the nodes are arranged. The execution order of the concatenated code segments will be consistent with the order in which the processing steps in the target business process are sequenced.
[0109] Universal code can be obtained or designed. The manufacturer that produces or designs the business processing device 200 can design the universal code. The universal code includes a code segment for transferring data between nodes or threads, i.e., a first code segment. The first code segment can be inserted between the code segments included in two nodes with a connecting edge. In this way, when the code segments included in the two nodes are executed, the first code can transfer the output of the code segment included in one of the two nodes to the code segment included in the other node. In one example, the code segments in different nodes can be executed by different threads. The first code segment can transfer the output of the execution thread of the code segment in one of the two nodes to the execution thread of the code segment in the other node.
[0110] The first code segment may transmit a storage address of data to be transmitted to the code segment included in the node, wherein the data to be transmitted is data required for the execution of the code segment included in the node. The code segment obtains the data to be transmitted from the storage address, that is, the code segment obtains the data required for the execution of the code based on the storage address. The storage address may be a memory address.
[0111] In some embodiments, the general code segment includes a code segment for allocating memory for a node or a thread. For ease of description, the code segment for allocating memory for a node or a thread may be referred to as a second code segment.
[0112] The execution of a code segment requires memory to store the data and results required for its execution. A code segment is executed by a thread, and the memory required for executing a code segment is specifically the memory required by the thread to execute the code segment. The memory used by the same thread is the same, while the memory used by different threads is different. A thread can execute code segments included in one or more nodes. When a thread executes code segments included in multiple nodes, the code segments included in these nodes share the thread's memory.
[0113] In step 202, the second code segment can be spliced with the code segment of the node. For example, the second code segment can be spliced with the beginning of the code segment included in the node. When multiple nodes are executed by a single thread, the second code segment can be spliced with the code segment included in the first node among the multiple nodes, without splicing the second code segment with the code segments included in other nodes among the multiple nodes. The first node among the multiple nodes is the node that first processes business data among the multiple nodes.
[0114] In some embodiments, the general code segment includes code for sending data to a host or network. For ease of description, the code for sending data to a host or network may be referred to as a third code. The third code may be spliced with the code segment included in the last node in the computational graph, for example, by splicing the third code to the end of the code segment included in the last node.
[0115] The examples above describe general code segments and how to combine them with code segments included in nodes. These examples are not exhaustive. General code segments combined with code segments included in nodes may also include code segments that implement other functions, which are not listed here.
[0116] The common code segments are concatenated with the code segments included in the nodes in the computation graph to create a code set. This code set is the complete code set for processing the target business. When using this code set to process the target business, no shared libraries are required. Therefore, there is no need to store shared libraries in the data memory area, saving data memory overhead.
[0117] In some embodiments, after obtaining the code set, the code set can be compiled into firmware on the service processing device 200. Specifically, the code set in a high-level language can be compiled into a machine language code set, which is then stored in the program memory area of the service processing device 200, so that the service processing device 200 uses the code set to process the target service. In one example, the service processing device 200 is a network card, such as a programmable network card.
[0118] In some embodiments, after obtaining the code set, an entry function header of the code set may be provided. The entry function header allows a user to call the code set. The code set may be compiled into firmware on the service processing device 200, and the entry function header allows a user to call the firmware on the service processing device 200.
[0119] Next, the implementation of step 202 is introduced in combination with different types of computation graphs.
[0120] In some embodiments, when the computation graph is a pipelined computation graph, the code generation device 100 generates code for sequentially calling functions based on the code segments included in the nodes in the computation graph. Based on this code and the aforementioned general code segments, a code set for processing the target business can be obtained. In this code set, the aforementioned first code is inserted between the code segments included in adjacent nodes of the computation graph. The code set can be compiled into firmware on the business processing device 200, and an entry function header is provided so that users can use the entry function header to call this firmware on the business processing device 200.
[0121] In some embodiments, when the computation graph is a conditional branch computation graph, the code generation device 100 generates code for conditionally calling functions based on the code segments included in the nodes in the computation graph. Based on this code and the above-mentioned general code segments, a code set for processing the target business can be obtained. In this code set, the above-mentioned first code is inserted between the code segments included in adjacent nodes of the computation graph. The code set can be compiled into firmware on the business processing device 200, and an entry function header is provided so that the user can call the firmware on the business processing device 200 using the entry function header. The function header file of "context.key" can also be provided to the user. The function header file of "context.key" is used to set distribution conditions. The user can set or update the distribution conditions during the processing of the target business through the function header file of "context.key".
[0122] In some embodiments, when the computation graph is a parallel distributed computation graph, the code generation device 100 generates code capable of parallel computation based on the code segments included in the nodes in the computation graph. The code of the successor nodes of the parallel distributed node can be copied to generate multiple thread processing functions, each of which calls the code included in the parallel distributed node. Based on the generated code and the aforementioned common code segments, a code set for processing the target business can be obtained. In this code set, the aforementioned first code is inserted between the code segments included in adjacent nodes of the computation graph. The code set can be compiled into firmware on the business processing device 200, and an entry function header is provided so that users can use the entry function header to call the firmware on the business processing device 200. A function header file called "context.num" can also be provided to the user. The "context.num" function header file is used to set the parallel value, i.e., the parallel number. Users can use the "context.num" function header file to set or update the parallel number while processing the target business.
[0123] In one example, some programmable network cards (e.g., NPs) cannot create threads directly. If threads are created through a computation graph, when the code generation device 100 parses the keyword "parallel_copy," it automatically generates the following processing code and inserts it into the original code flow:
[0124] (1) Temporarily storing the user- or manufacturer-defined "context.num", user-defined data structure, and stack information in the memory of the programmable network card; or storing the "context.num", data structure, and stack information in the host's memory through DMA technology.
[0125] (2) Knocking the hardware doorbell triggers a new processing task. The new execution thread does not contain the user's original context information.
[0126] (3) The new execution thread does not contain the user's original context information. Therefore, the new execution thread needs to restore the context information and then call the code segment included in the parallel distribution node for execution. After the execution is completed, the data is saved. After all parallel computing nodes have finished executing, the code included in the subsequent nodes can be called.
[0127] In summary, the code generation method provided by the embodiments of this application allows the inclusion of common code segments that perform common functions into the code set for a business. Thus, when using this code set to process the target business, no shared libraries are required. Consequently, there is no need to store shared libraries in the data memory area, saving data memory area overhead.
[0128] See Figure 12 , an embodiment of the present application provides a code generation device 1200. The device 1200 includes:
[0129] An acquisition unit 1210 is configured to acquire a computation graph corresponding to a process flow of a target business, the computation graph comprising a plurality of nodes and connecting edges between the nodes; wherein each of the plurality of nodes corresponds to at least one processing step in the process flow, the node comprises a code segment for executing the processing step corresponding to the node, and the connecting edges represent data dependencies between the nodes connected by the connecting edges;
[0130] The splicing unit 1220 is used to splice the code segments included in the multiple nodes and the general code segments to obtain a code set for processing the target business; wherein the general code segment includes a first code segment for transmitting data between nodes, and in the code set, the first code segment is inserted between the code segments included in the nodes connected by the connection edge.
[0131] In some embodiments, the target service is a service executed in a network card, and the device further includes: a storage unit for storing the code set in a program memory area of the network card, so that the network card uses the code set to process the target service.
[0132] In some embodiments, the first code segment is used to transfer a storage address of data between nodes, and the code segment included in the node is used to obtain the data based on the storage address.
[0133] In some embodiments, the computational graph is generated in response to a user's operation; the apparatus further comprises: a providing unit for providing guidance information for the graph generation operation to the user, the guidance information comprising a plurality of node types, functions corresponding to each of the plurality of node types, and a function corresponding to a node type being associated with at least one processing step in the processing flow.
[0134] In some embodiments, the multiple node types include node types corresponding to conditional branch judgment functions and node types corresponding to conditional branch processing functions; wherein, the processing steps associated with the conditional branch judgment function are used to judge the conditions satisfied by the business data of the target business, and based on the conditions satisfied by the business data, call the processing steps associated with the conditional branch processing function to process the business data.
[0135] In some embodiments, the multiple node types include node types corresponding to parallel data distribution functions; wherein the multiple nodes include a first node, a second node and a third node of the node type corresponding to the parallel data distribution function; wherein the processing steps corresponding to the third node are used to distribute the business data of the target business to the first node and the second node; the first node and the second node are each used to process the received data.
[0136] In some embodiments, different nodes among the plurality of nodes read and write data based on the same data structure.
[0137] In some embodiments, the computation graph is a directed acyclic graph (DAG).
[0138] The functions of the functional units of the apparatus 1200 may be implemented with reference to the above description of the operations performed by the code generating apparatus 100, for example, Figure 2 Operations performed by the code generating apparatus 100.
[0139] The embodiment of the present application provides a computing device 1300. Figure 13 As shown, the computing device 1300 includes a processor 1310 and a memory 1320. The memory 1320 is used to store executable programs. The processor 1310 is used to execute the executable programs stored in the memory 1320, so that the computing device 1300 can perform the operations performed by the code generation device 100 above, such as Figure 2 Operations performed by the code generating apparatus 100.
[0140] The present application also provides a computer program product including instructions. The computer program product may be a software or program product including instructions that can be run on a computing device or stored in any available medium. When the computer program product is run on a computing device, the computing device executes the operations performed by the code generation device 100 above, such as Figure 2 Operations performed by the code generating apparatus 100.
[0141] The embodiment of the present application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that can be stored by a computing device or a data storage device such as a data center that contains one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to perform the operations performed by the code generation device 100 above, such as Figure 2 Operations performed by the code generating apparatus 100.
[0142] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the protection scope of the technical solutions of the embodiments of the present application.
Claims
1. A code generation method, characterized in that: The method comprises: Obtaining a computation graph corresponding to a processing flow of a target business, the computation graph comprising a plurality of nodes and connecting edges between the nodes; wherein each of the plurality of nodes corresponds to at least one processing step in the processing flow, the node comprises a code segment for executing the processing step corresponding to the node, and the connecting edges are used to represent data dependency relationships between the nodes connected by the connecting edges; The code segments included in the multiple nodes and the general code segments are spliced to obtain a code set for processing the target business; wherein the general code segment includes a first code segment for transmitting data between nodes, and in the code set, the first code segment is inserted between the code segments included in the nodes connected by the connection edge.
2. The method according to claim 1, characterized in that The target service is a service executed in a network card. The method further includes: storing the code set in a program memory area of the network card, so that the network card uses the code set to process the target service.
3. The method according to claim 1 or 2, characterized in that The first code segment is used to transfer the storage address of data between nodes, and the code segment included in the node is used to obtain the data based on the storage address.
4. The method according to any one of claims 1 to 3, characterized in that The computation graph is generated in response to a user operation; the method further includes: Guidance information for a graph generation operation is provided to the user, the guidance information including a plurality of node types and a function corresponding to each of the plurality of node types, wherein a function corresponding to a node type is associated with at least one processing step in the processing flow.
5. The method according to any one of claims 1 to 4, characterized in that The multiple node types include a node type corresponding to a conditional branch judgment function and a node type corresponding to a conditional branch processing function; The processing steps associated with the conditional branch judgment function are used to judge the conditions satisfied by the business data of the target business, and based on the conditions satisfied by the business data, call the processing steps associated with the conditional branch processing function to process the business data.
6. The method according to any one of claims 1 to 4, characterized in that The plurality of node types include node types corresponding to parallel data distribution functions; Wherein, the multiple nodes include a first node, a second node and a third node of the node type corresponding to the parallel data distribution function; wherein, the processing steps corresponding to the third node are used to distribute the business data of the target business to the first node and the second node; the first node and the second node are each used to process the received data.
7. The method according to any one of claims 1 to 6, characterized in that Different nodes among the multiple nodes read and write data based on the same data structure.
8. The method according to any one of claims 1 to 7, characterized in that The computation graph is a directed acyclic graph (DAG).
9. A code generating device, characterized in that: The device comprises: an acquisition unit, configured to acquire a computation graph corresponding to a processing flow of a target business, the computation graph comprising a plurality of nodes and connecting edges between the nodes; wherein each of the plurality of nodes corresponds to at least one processing step in the processing flow, the node comprises a code segment for executing the processing step corresponding to the node, and the connecting edges are used to represent data dependency relationships between the nodes connected by the connecting edges; A splicing unit is used to splice the code segments included in the multiple nodes and the common code segments to obtain a code set for processing the target business; wherein the common code segment includes a first code segment for transmitting data between nodes, and in the code set, the first code segment is inserted between the code segments included in the nodes connected by the connection edge.
10. The device according to claim 9, characterized in that The target service is a service executed in a network card. The device further includes: a storage unit, configured to store the code set in a program memory area of the network card, so that the network card processes the target service using the code set.
11. The device according to claim 9 or 10, characterized in that The first code segment is used to transfer the storage address of data between nodes, and the code segment included in the node is used to obtain the data based on the storage address.
12. The device according to any one of claims 9 to 11, characterized in that The computation graph is generated in response to a user operation; the apparatus further comprises: A providing unit is used to provide the user with guidance information for the graph generation operation, wherein the guidance information includes multiple node types and functions corresponding to each of the multiple node types, and a function corresponding to a node type is associated with at least one processing step in the processing flow.
13. The device according to any one of claims 9 to 12, characterized in that The multiple node types include a node type corresponding to a conditional branch judgment function and a node type corresponding to a conditional branch processing function; The processing steps associated with the conditional branch judgment function are used to judge the conditions satisfied by the business data of the target business, and based on the conditions satisfied by the business data, call the processing steps associated with the conditional branch processing function to process the business data.
14. The device according to any one of claims 9 to 12, characterized in that The plurality of node types include node types corresponding to parallel data distribution functions; Wherein, the multiple nodes include a first node, a second node and a third node of the node type corresponding to the parallel data distribution function; wherein, the processing steps corresponding to the third node are used to distribute the business data of the target business to the first node and the second node; the first node and the second node are each used to process the received data.
15. The device according to any one of claims 9 to 14, characterized in that Different nodes among the multiple nodes read and write data based on the same data structure.
16. The device according to any one of claims 9 to 15, characterized in that The computation graph is a directed acyclic graph (DAG).
17. A computing device, characterized in that include: a memory for storing executable programs; A processor, configured to execute the method according to any one of claims 1 to 8 by running the executable program.
18. A computer-readable storage medium, characterized in that The method comprises computer program instructions, and when the computer program instructions are executed by a computing device, the computing device performs the method according to any one of claims 1 to 8.
19. A computer program product comprising instructions, characterized in that When the instructions are executed by a computing device, the computing device is caused to perform the method according to any one of claims 1 to 8.