A System and Method for Accelerating Script Calculation Using a Graphics Processing Unit
By converting DolphinScript scripts into calculation diagrams and executing them on the GPU, script acceleration problems in the prior art are solved, high-performance script computing is realized, and compatible with CPU computing.
Patent Information
- Application Number
- CN202510245110.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-04
- Publication Date
- 2025-05-27
- Estimated Expiration
- 2045-03-04
AI Technical Summary
The existing technology is difficult to accelerate DolphinScript scripts directly to GPUs, and it faces the problems of high code porting complexity, mismatch in programming paradigms and lack of efficient conversion systems.
By parsing and converting DolphinScript scripts into calculation graphs, and optimizing and executing the calculation graphs, using GPU to accelerate script calculations. The system includes input modules, parsing modules, execution modules and output modules, and is able to identify and process complex syntax, context, calculation and process control logic.
Significantly improves the performance and ease of use of script computing and is compatible with CPU-based script computing, so users can use GPU to accelerate existing scripts without learning the GPU programming interface.
Smart Images

Figure CN119741186B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data analysis, and in particular relates to a system and method for accelerating script calculation using a graphics processing unit. Background Art
[0002] In the field of data analysis, users generally perform data analysis through scripts implemented in the DolphinScript language. In addition to calculating some basic data indicators such as correlation, variance, and mean data indicators, they also use complex control flow logic, nested function calls, and other methods to further process the data. The execution process of the script is completed in the CPU. With the increase in the number of data indicators, the complexity of scripts, and the expansion of the scale of available data, using the CPU to calculate data indicators can no longer meet users' real-time requirements. The graphics processing unit (GPU) is a system-on-chip with many processor cores, registers, high-performance memory and other related hardware. It has great advantages in accelerating computing tasks in the field of data analysis. For many algorithms, it can achieve hundreds or thousands of times performance improvement compared to the CPU. However, using GPU to accelerate DolphinScript scripts faces the following challenges:
[0003] 1. It is difficult to directly port CPU code to GPU. Therefore, the data indicator calculation function in DolphinScript needs to be specially developed and optimized on GPU, which has high engineering complexity and cost.
[0004] 2. Using GPU to accelerate DolphinScript scripts presents challenges in programming paradigms, because DolphinScript often contains a large amount of complex syntax, context, calculation, and process control logic. The following script is shown:
[0005] def factor(table) {
[0006] sumA = table.col_a
[0007] sumB = table.col_b
[0008] if (sumA>sumB) {
[0009] return corr(table.col_a, table.col_b)
[0010] } else {
[0011] return std(table.col_a, table.col_b)
[0012] }
[0013] }
[0014] The script contains nested functions and control flow logic. The example script cannot be directly completed using the GPU, and the script needs to be converted into a high-concurrency parallel computing task that the GPU is good at processing. However, there is currently a lack of an efficient and effective conversion system that can automatically convert DolphinScript scripts into parallel computing tasks suitable for GPU execution.
[0015] 3. The system and method using GPU to accelerate DolphinScript needs to be fully compatible with the system and method using CPU to provide users with a consistent and efficient experience.
[0016] In order to meet these challenges, the present invention proposes a technology that first parses and converts DolphinScript scripts into calculation graphs, and then optimizes and executes the calculation graphs. In the calculation graph, each node comes from a statement block in the script. The present invention systematically implements the technology of identifying, parsing, modeling, optimizing and executing the complex syntax, context, calculation and process control logic in DolphinScript scripts, which can significantly improve the performance and ease of use of script calculations and is compatible with CPU-based script calculations. Summary of the invention
[0017] In order to solve the shortcomings of the prior art and achieve the purpose of using GPU to accelerate script calculation speed, the present invention adopts the following technical solutions:
[0018] A system for accelerating script calculations, comprising an input module, a parsing module, an execution module and an output module;
[0019] The input module is used to obtain the script and the data required for calculating the script;
[0020] The parsing module parses the statement blocks of the script and writes it into a calculation graph composed of nodes. The execution process is as follows:
[0021] Create a symbol table of variables and nodes in the script;
[0022] Get the script's statement block and parse it. Based on the type of the statement block, create nodes for its variables and match neighboring nodes. Maintain the symbol table of variables and nodes.
[0023] Finally, a computational graph based on nodes and relationships between nodes is generated;
[0024] The execution node constructs a work queue based on the node structure of the computation graph, and uses this to execute the computation corresponding to the node to obtain the computation result;
[0025] The output node outputs the final calculation result after execution.
[0026] Furthermore, the node includes a data node; the statement block includes an assignment statement block. For the assignment statement block, the data node is obtained by parsing the statement block of the expression, a data node of the assigned variable is created, the data node of the expression is used as its input neighbor, and a mapping relationship between the variable and its data node is established in the symbol table.
[0027] Furthermore, the node includes a data node; the statement block includes a function statement block. For the function statement block, if it is a built-in function, an operator node is created for it; if it is a custom function, its statement block is expanded and parsed to obtain a data node that stores the function result; by consulting the symbol table, the node corresponding to the input parameter of the called function is found, and it is used as the input neighbor of the data node that stores the function result.
[0028] Furthermore, the nodes include conditional nodes, incoming nodes, and merge nodes; the statement blocks include conditional transfer statement blocks. For the conditional transfer statement blocks, they include conditional statement blocks, if statement blocks, and otherwise statement blocks. An incoming node is created for the variables of the conditional transfer statement blocks, and the node corresponding to the variable is found by querying the symbol table, and the node is used as the incoming neighbor of the incoming node; a conditional node is created for the conditional statement block, and the incoming node is used as the incoming neighbor of the conditional node; the statement blocks are parsed for the if statement block and the otherwise statement block respectively, and the node created by the if statement block is used as the left child node of the conditional node, and the node created by the otherwise statement block is used as the right child node of the conditional node; since only one statement block can be executed during the execution of if and else statements, the if statement block and the otherwise statement block are analyzed in turn, a merge node is created for the variables that appear in both of them, the symbol table is updated, and the nodes of the variables that appear in both of them are updated to the merge node.
[0029] Furthermore, the nodes include conditional nodes, incoming nodes, iteration nodes, and exit nodes; the statement blocks include loop statement blocks. For loop statement blocks, they contain loop conditions and loop statement blocks. The loop statement blocks are analyzed to create incoming nodes for variables created in non-loop statement blocks. By consulting the symbol table, the node corresponding to the variable is found and the node is used as an incoming neighbor of the incoming node; the loop conditions and loop statement blocks are analyzed and the parsing of the statement blocks is performed to create a conditional node for each variable in the loop statement block, whose incoming neighbors are nodes created in the process of analyzing the loop conditions, and the left child node of the conditional node is a node created by the variable in the process of parsing the loop statement block; an iteration node is created for the variable, whose incoming neighbors are nodes created by the variable in the process of parsing the loop statement block, and whose outgoing neighbors are nodes created in the process of analyzing the loop conditions; an exit node is created for the variable and used as the right child node of the conditional node, and the symbol table of the variable is updated.
[0030] Furthermore, the loop statement block also includes a statement block for ending this loop. For the statement block for ending this loop, an internal variable continueFlag is created in the loop statement block and is set to an initial value of 0. The statement block for ending this loop is then rewritten as an assignment statement block with continueFlag = 1 to assign a value to it. For the statement block subsequent to the statement block for ending this loop, it is rewritten as a conditional transfer statement block, wherein the judgment condition in the conditional statement block is that the internal variable continueFlag is not equal to the value 1 assigned during the rewrite.
[0031] Furthermore, the conditional transfer statement block includes an if statement block; the content of the if statement block is a statement block subsequent to the statement block that ends this loop.
[0032] Furthermore, the loop statement block also includes a loop exit statement block. For the loop exit statement block, an external variable breakFlag is created outside the loop statement block, which is set to the first value 1, and the loop exit statement is rewritten as an assignment statement block in which the external variable breakFlag is the second value 0 and ends the current loop statement block, and then a judgment is added in the loop condition that the external variable breakFlag is not equal to the second value 0.
[0033] A system using a graphics processing unit to accelerate script calculations, wherein the nodes include data nodes, operator nodes, conditional nodes, merge nodes, and iteration nodes; the execution module performs the following operations:
[0034] Find the node with in-degree 0 from the computation graph and add it to the work queue;
[0035] Take a node from the work queue. If it is a data node, get the corresponding data through the CPU or GPU. If it is an operator node, execute the operator. If it is a conditional node, add the left child node to the work queue when the condition is true, and add the right child node to the work queue when the condition is false. If it is an iteration node, increment the iteration counter.
[0036] Determine all outgoing neighbors of the node. If all incoming neighbor nodes of the outgoing neighbor have been executed, add the outgoing neighbor node to the work queue;
[0037] Continue executing until the work queue is empty.
[0038] A method for accelerating script calculation, based on the system for accelerating script calculation, transcribes the script into a calculation graph, and performs calculation on the calculation graph to obtain the script calculation result.
[0039] The advantages and beneficial effects of the present invention are:
[0040] The present invention discloses a system and method for accelerating script calculation using a graphics processing unit. The system parses the user script into a representation of a calculation graph by a recursive parsing method. For scripts containing control flow statements (the control flow statements contain conditional transfer statements if and loop statements for), the mapping relationship between statements and graph nodes cannot be directly established. The present invention implements control flow graph construction by control flow transcription, and then directly uses a GPU to execute the calculation graph to accelerate the calculation of existing scripts. In the present invention, users can use a GPU to directly accelerate existing scripts without learning a GPU programming interface. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 It is a schematic diagram of the structure of the system in an embodiment of the present invention.
[0042] Figure 2 It is an execution flow chart of the parsing module in the system of an embodiment of the present invention.
[0043] Figure 3 It is an execution flow chart of the execution module in the system in an embodiment of the present invention. DETAILED DESCRIPTION
[0044] The specific implementation of the present invention is described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation described here is only used to illustrate and explain the present invention, and is not used to limit the present invention.
[0045] like Figure 1As shown, a system using a graphics processing unit to accelerate script calculation includes an input module, a parsing module, an execution module and an output module. The script calculation speed is improved by converting the user's indicator calculation script into a calculation graph and executing it on the GPU. The nodes in the calculation graph include data nodes, operator nodes, conditional nodes, incoming nodes, merge nodes, iteration nodes, and exit nodes. The data nodes are responsible for storing data, providing input for calculations and storing intermediate results. The operator nodes correspond to built-in functions that can be executed by the GPU. The conditional nodes and merge nodes are a special type of nodes that are responsible for the selection and execution of different branch statements and the merging of the results of different branch statements during the execution of the control flow. The iteration nodes are used to iterate the loop conditions in the loop control flow.
[0046] The input module is responsible for reading the user script and the data required to calculate the script. The user script is an abstract syntax tree represented by multiple statement blocks.
[0047] The parsing module uses a top-down approach to traverse the abstract syntax tree in sequence and convert it into a computational graph, such as Figure 2 As shown, the execution process of the parsing module is as follows:
[0048] Step 1: Create a symbol table to record the corresponding values of variables in the script and the nodes in the computational graph.
[0049] Step 2: Take a statement block from the abstract syntax tree and parse it.
[0050] Step 2.1: If it is an assignment statement block, such as a = b, it will first try to parse the statement block of b to get the data node node b, then create the data node node a, and the incoming neighbor is node b (that is, node b points to the data node node a), and establish a mapping relationship between the variable a and the data node node a in the symbol table.
[0051] Step 2.2: If it is a function statement block, perform the following operations:
[0052] Step 2.2.1: If the function is a built-in function, create a node node n, the node type is an operator node;
[0053] Step 2.2.2: If the function is a user-defined function, the user-defined function will be expanded, and all statement blocks of the function will be parsed in sequence to obtain the data node node n that stores the function result;
[0054] Step 2.2.3: Consult the symbol table, find the node m corresponding to the input parameter (the parameter required by the called function), and use m as the input neighbor of node n.
[0055] Step 2.3: If it is a conditional transfer statement block, perform the following operations. The conditional transfer statement block contains a conditional statement block, an if statement block, and an else statement block.
[0056] Step 2.3.1: Analyze the variable v in the conditional transfer statement and create an incoming node n for it; then consult the symbol table to find the node m corresponding to the variable v and use m as the incoming neighbor of the incoming node n;
[0057] Step 2.3.2: Analyze the conditions in the conditional transfer statement and create a conditional node n1 for it. The incoming node n in the previous step needs to be the incoming neighbor of the conditional node n1.
[0058] Step 2.3.3: For the if statement block and the else statement block, execute step 2 respectively; for the conditional node n1 created in step 2.3.2, use the node n2 created by the if statement block as the left child node of n1, and use the node n3 created by the else statement block as the right child node of n2;
[0059] Step 2.3.4: Since only one statement block can be executed during the execution of if and else statements, analyze the if and else statement blocks in turn, create a merge node merge for the variable x that appears in both of them, and finally update the symbol table and update the node of variable x to merge.
[0060] Step 2.4: If it is a loop statement block, perform the following operations. The loop statement contains the loop condition, the loop statement block, and may contain the break statement block and the continue statement block. The break statement block will jump out of the current loop, and the continue statement block will end the current loop.
[0061] Step 2.4.1: Analyze the loop block. If it contains break, create a variable breakFlag outside the loop block, set it to 1, rewrite the break statement into an assignment block and a continue block with breakFlag = 0, and then add a check that breakFlag is not equal to 0 in the loop condition.
[0062] Step 2.4.2: Analyze the loop block. If it contains continue, create a variable continueFlag in the loop block and set it to 0. Then rewrite the continue block into an assignment block with continueFlag = 1. Then rewrite the block following continue into a conditional transfer block, where the judgment condition in the conditional block is that continueFlag is not equal to 1, and the content in the if block is the block following continue.
[0063] Step 2.4.3: Analyze the loop block, and for the variable x created in the non-loop block, create an incoming node n; then consult the symbol table to find the node m corresponding to the variable x, and use m as the incoming neighbor of the incoming node n;
[0064] Step 2.4.4: Analyze the loop conditions and execute step 2;
[0065] Step 2.4.5: Parse the loop statement block and execute step 2 for each statement block;
[0066] Step 2.4.6: For each variable x in the loop block, create a conditional node n, whose incoming neighbors are nodes created during step 2.4.4, and whose left child is the node where variable x was created in step 2.4.5;
[0067] Step 2.4.7: Create an iteration node for variable x. The in-neighbor of the iteration node is the node where variable x is created in step 2.4.5, and the out-neighbor is the node created in step 2.4.4 (i.e., points to the node created in step 2.4.4).
[0068] Step 2.4.8: Create an exit node for variable x and make it the right child of node n created in step 2.4.6. Update the symbol table of variable x.
[0069] Step 3: If there are still statement blocks in the abstract syntax tree, execute step 2, otherwise end parsing.
[0070] After the parsing module is executed, a graph will be obtained, and then, Figure 3 As shown, the execution module will execute this diagram, including the following steps:
[0071] Step 1: Find the node with in-degree 0 in the graph and add it to the work queue;
[0072] Step 2: Take a node from the work queue;
[0073] Step 2.1: If it is a data node, get the corresponding data from the CPU or GPU; if it is an operator node, execute the operator; if it is a conditional node, when the condition is true, add the left child node to the work queue, and when the condition is false, add the right child node to the work queue; if it is an iteration node, increment the iteration counter;
[0074] Step 2.2: Otherwise, go to step 3;
[0075] Step 3: Determine all outgoing neighbors of the node. If all incoming neighbor nodes of the outgoing neighbor have been executed, add the outgoing neighbor node to the work queue;
[0076] Step 4: If the work queue is not empty, execute step 2, otherwise the execution ends.
[0077] After the execution module is executed, the execution result will be obtained, and the output module will output the execution result.
[0078] A method for accelerating script calculations using a graphics processing unit, based on the system for accelerating script calculations using a graphics processing unit, transcribes the script into a calculation graph, performs calculations on the calculation graph to obtain the script calculation results, and the transcription and execution process is similar to the implementation method of the above-mentioned method embodiment, which will not be repeated here.
[0079] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some or all of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A system for accelerating script calculation using a graphics processing unit, comprising an input module, a parsing module, an execution module and an output module, characterized in that: The input module is used to obtain the script and the data required for calculating the script; The parsing module parses the statement blocks of the script and writes it into a calculation graph composed of nodes. The execution process is as follows: Create a symbol table of variables and nodes in the script; Get the script's statement block and parse it. Based on the type of the statement block, create nodes for its variables and match neighboring nodes. Maintain the symbol table of variables and nodes. Finally, a computational graph based on nodes and relationships between nodes is generated; The execution module constructs a work queue based on the node structure of the calculation graph, and executes the calculation corresponding to the node to obtain the calculation result; The nodes in the computation graph include data nodes, operator nodes, conditional nodes, merge nodes, and iteration nodes. The following operations are performed: Find the node with in-degree 0 from the computation graph and add it to the work queue; Take a node from the work queue. If it is a data node, get the corresponding data through the processor or graphics processing unit. If it is an operator node, execute the operator. If it is a conditional node, add the left child node to the work queue when the condition is true, and add the right child node to the work queue when the condition is false. If it is an iteration node, increment the iteration counter. Determine all outgoing neighbors of the node. If all incoming neighbor nodes of the outgoing neighbor have been executed, add the outgoing neighbor node to the work queue; Continue execution until the work queue is empty; The output module outputs the final calculation result after execution.
2. A system for accelerating script calculation using a graphics processing unit according to claim 1, characterized in that: The nodes include data nodes; the statement blocks include assignment statement blocks. For the assignment statement blocks, the data nodes are obtained by parsing the statement blocks of the expressions, and the data nodes of the assigned variables are created, the data nodes of the expressions are used as their input neighbors, and a mapping relationship between the variables and their data nodes is established in the symbol table.
3. The system for accelerating script calculation using a graphics processing unit according to claim 1, characterized in that: The nodes include data nodes; the statement blocks include function statement blocks. For the function statement blocks, if it is a built-in function, an operator node is created for it; if it is a custom function, it is expanded and its statement block is parsed to obtain a data node for storing the function result; by consulting the symbol table, the node corresponding to the input parameter of the called function is found, and it is used as the input neighbor of the data node for storing the function result.
4. The system for accelerating script calculation using a graphics processing unit according to claim 1, characterized in that: The nodes include conditional nodes, incoming nodes, and merge nodes; the statement blocks include conditional transfer statement blocks, which include conditional statement blocks, if statement blocks, and otherwise statement blocks; an incoming node is created for a variable of the conditional transfer statement block, and a node corresponding to the variable is found by querying a symbol table, and the node is used as an incoming neighbor of the incoming node; Create a conditional node for the conditional statement block, and use the incoming node as the incoming neighbor of the conditional node; parse the if statement block and the otherwise statement block respectively, and use the node created by the if statement block as the left child node of the conditional node, and use the node created by the otherwise statement block as the right child node of the conditional node; analyze the if statement block and the otherwise statement block in turn, create a merge node for the variables that appear in both, update the symbol table, and update the nodes of the variables that appear in both to the merge node.
5. The system for accelerating script calculation using a graphics processing unit according to claim 1, characterized in that: The nodes include conditional nodes, incoming nodes, iteration nodes, and exit nodes; the statement blocks include loop statement blocks, which contain loop conditions and loop statement blocks, analyze the loop statement blocks, create incoming nodes for variables created in non-loop statement blocks, find the node corresponding to the variable by consulting the symbol table, and use the node as the incoming neighbor of the incoming node; analyze the loop conditions and loop statement blocks and perform parsing of the statement blocks, create conditional nodes for each variable in the loop statement block, and their incoming neighbors are nodes created in the process of analyzing the loop conditions, and the left child node of the conditional node is the node created by the variable in the process of parsing the loop statement block; Create an iteration node for the variable. The in-neighbors of the iteration node are the nodes created by the variable during the parsing of the loop statement block, and the out-neighbors are the nodes created during the analysis of the loop condition. Create an exit node for the variable and make it the right child of the condition node, and update the symbol table of the variable.
6. A system for accelerating script calculation using a graphics processing unit according to claim 5, characterized in that: The loop statement block also includes an end-of-loop statement block. For the end-of-loop statement block, an internal variable is created in the loop statement block and set to an initial value. The end-of-loop statement is then rewritten into an assignment statement block to assign a value to it. The statement block subsequent to the end-of-loop statement block is rewritten into a conditional transfer statement block, wherein the judgment condition in the conditional statement block is that the internal variable is not equal to the value assigned during the rewrite.
7. A system for accelerating script calculation using a graphics processing unit according to claim 6, characterized in that: The conditional transfer statement block includes an if statement block; the content of the if statement block is the statement block subsequent to the statement block that ends this loop.
8. The system for accelerating script calculation using a graphics processing unit according to claim 6, characterized in that: The loop statement block also includes a loop exit statement block. For the loop exit statement block, an external variable is created outside the loop statement block, set to a first value, and the loop exit statement is rewritten as an assignment statement block in which the external variable is a second value and ends the current loop statement block, and then a judgment is added in the loop condition that the external variable is not equal to the second value.
9. A method for accelerating script calculation using a graphics processing unit, characterized in that: Based on a system for accelerating script calculation using a graphics processing unit as described in any one of claims 1 to 8, the script is transcribed into a calculation graph, and calculations are performed on the calculation graph to obtain the script calculation results.
Citation Information
Patent Citations
Executing computational graphs on graphics processing unit
CN114429201A
Compiling method and device, electronic equipment and storage medium
CN114489656A