A large-scale instance symbolic model error calculation method based on Numba

By using the Numba library in the Python environment to convert the symbolic model into a Reverse Polish Notation array, and combining GPU threads and memory allocation, highly parallel granular error calculation is achieved, solving the problem of low efficiency in symbolic model error calculation and achieving a significant speedup effect.

CN119512741BActive Publication Date: 2025-10-28NORTHWEST ELECTROMECHANICAL ENG RES INST
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411515714.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-29
Publication Date
2025-10-28
Estimated Expiration
2044-10-29

AI Technical Summary

Technical Problem

Existing technologies lack sufficient parallelism in large-scale symbolic model error computation, especially in the Python environment where the coding complexity and parallel granularity of heterogeneous parallel methods are insufficient, resulting in low computational efficiency.

Method used

Using the Numba library in a Python environment, the symbolic model is converted into a Reverse Polish Notation array, and the GPU's thread allocation and memory structure are used to perform highly parallel error calculation, including two error merging operations, to achieve parallel computation of symbolic model errors.

Benefits of technology

It significantly improves the efficiency of symbolic model error calculation, with an acceleration effect of about 60 times on large-scale instance data, thus improving calculation speed and efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119512741B_ABST
    Figure CN119512741B_ABST
Patent Text Reader

Abstract

This invention discloses a method for calculating errors in large-scale instance symbolic models based on Numba, including: model transformation and representation, error calculation, memory and thread organization, and error merging. This invention transforms the model into Reverse Polish Notation (RPN) form and represents it in Numba data format. It utilizes an array to simulate a stack to perform error calculation on individual instance data, organizes multi-level memory to improve access efficiency, designs highly parallel thread allocation, and performs two error merging operations to quickly sum all errors. This invention provides a fast error calculation method for symbolic models in a Python environment, fully utilizing the CUDA core resources of GPUs, significantly improving the efficiency of symbolic model evaluation, and providing support for related fields.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of data science and high-performance computing, specifically to a method for calculating the error of a large-scale instance symbolic model based on Numba. This method utilizes Numba to achieve fast error calculation of the symbolic model. Background Technology

[0002] Symbolic models are models used to represent symbolic operations. They commonly take the form of mathematical expressions and equations and are widely used in data description and prediction in scientific research and engineering, including regression analysis, motion control, and representation of mathematical laws. Model optimization and comparison require calculating the error between the predicted model and the actual data or the actual model. This calculation is very slow when there are many models and a large amount of instance data, especially in symbolic regression and high-tech interpretive research, which is extremely time-consuming and severely impacts computational efficiency.

[0003] With the development of big data technology and high-performance computing, scholars have designed various homogeneous and heterogeneous parallel methods for symbolic model error calculation. Common errors in symbolic models include sum of variances, mean squared errors, root mean square errors, and coefficients of determination, all of which involve steps such as calculating the error of a single instance and summing the errors. Homogeneous parallel methods create multiple threads to calculate the errors of different instance data in parallel and then sum them. However, the speedup is limited by the number and characteristics of CPU physical cores. Heterogeneous parallel methods deploy error calculation and summation on GPUs with a single instruction stream multiple data stream architecture. Similar to homogeneous parallel methods, they fully utilize the advantages of GPU multi-core architecture, resulting in significant speedup. Current heterogeneous parallel algorithms mostly utilize OpenCL and CUDA based on the C language to obtain GPU computing resources, which requires high coding skills. Python is widely used in data science. Currently, there are methods that use TensorFlow libraries for vectorization to accelerate error calculation in the Python environment, which complicates the problem and lacks sufficient parallel granularity and parallelization of the computation process. Summary of the Invention

[0004] The purpose of this invention is to provide a method for calculating errors in large-scale instance symbolic models based on Numba, so as to improve the parallelism of current heterogeneous parallel symbolic model error calculation and thus improve algorithm efficiency.

[0005] To achieve the above objectives, the present invention employs the following technical solution:

[0006] A method for calculating errors in large-scale instance symbolic models based on Numba, comprising:

[0007] In the Numba environment, the symbolic model based on syntax tree encoding is traversed to obtain the serialized Reverse Polish Notation (RPN). Then, the RPN is represented as an array according to the correspondence. The instance data to be computed and the array-form RPN are then sent from the host memory to the GPU and stored in global memory and constant memory, respectively.

[0008] Apply for a two-dimensional grid structure and a two-dimensional block structure. Based on the position of the thread in the block structure and the position of the block structure in the grid, allocate data indexes for each thread, allocate threads for each piece of data in the instance data, and allocate a simulation stack for each thread in shared memory.

[0009] For the array-based Reverse Polish Notation, each data point is assigned a thread to substitute it into the Reverse Polish Notation and calculate the data error. Different stack operations are performed sequentially on different node types in the Reverse Polish Notation, and the bottom value of the simulated stack is the output of the Reverse Polish Notation. Based on this output and the actual output of each data point, the data error is obtained.

[0010] After all threads have completed their data errors, two error merging processes are performed: The first error merging process sums the data errors calculated by all threads in each block structure in parallel and stores them in the first simulation stack of that block structure as the error sum of that block structure; The second error merging process copies the error sum of each block structure to the allocated global memory and performs step-by-step summation to obtain the final error value, which is then stored at the bottom of the first simulation stack in the grid structure. Finally, the error value is sent to the host.

[0011] Furthermore, the correspondence is the correspondence between node types in the symbolic model and constant data in the array; node types include operators such as addition, subtraction, multiplication, and division, and constant data are integers.

[0012] Furthermore, global memory and constant memory can be accessed by every thread, while shared memory can only be accessed by threads within the same block structure.

[0013] Furthermore, the grid structure is set as follows: Each block structure is The position of a certain thread in this block structure is The position of this block in the grid is The data index allocated to this thread in this invention is:

[0014]

[0015] in, The x and y coordinates of the grid structure The x and y coordinates of the block structure Here are the x and y coordinates of the thread within the block structure. These represent the x and y coordinates of the block structure within the mesh structure.

[0016] A simulated stack is allocated for each thread in the shared memory area, and Reverse Polish notation is used. Length is Then the array size of the model stack is set to Simultaneously, a stack index is allocated in the local memory area, and a global memory allocation size of [size missing]. The array provides support for the second error merging; n This represents the number of data points in the instance data.

[0017] Furthermore, each thread performs calculations according to the following rules:

[0018] For each data entry Variables and constants are pushed directly onto the stack. For unary operators, the calculation is performed directly on the top element of the stack. For binary operators, the top two elements of the stack are used as input for calculation and overwrite the existing data. The data at the bottom of the stack is the output of each data item after processing using Reverse Polish Notation. This output is then compared with the corresponding actual output. The square of the difference is the root mean square error.

[0019] Furthermore, during the first error merging, each block structure performs the same operation: summing the errors based on the thread index within the block structure and the step size control thread, with the step size changing as follows: Finally, the bottom of the simulated stack corresponding to the first thread of each block is the sum of block errors; where satisfy .

[0020] Furthermore, in the second error merging, the error sum of each block structure is first copied to the allocated global memory, according to the step size. The errors are summed step by step, and the final total error value is stored at the bottom of the first simulation stack in the grid structure.

[0021] A computing device includes a processor, a memory, and a computer program stored in the memory; when the processor executes the computer program, it implements the method for calculating errors of a large-scale instance symbolic model based on Numba.

[0022] A computer-readable storage medium storing a computer program; when executed by a processor, the computer program implements the method for calculating errors in a large-scale instance symbolic model based on Numba.

[0023] Compared with the prior art, the present invention has the following technical features:

[0024] 1. This invention provides a symbolic model representation method based on the Numba library. By utilizing the output calculation method of the simulated stack, it provides a symbolic model error calculation paradigm for obtaining CUDA resources of Nvidia GPUs in the Python environment, which can be widely used for symbolic model evaluation in various fields.

[0025] 2. This invention constructs a large-scale instance data thread allocation method with high parallel granularity. Two error merging operations make the entire error calculation process parallel, which can be used in error calculation of other heterogeneous symbolic models, thereby improving the overall efficiency of the algorithm. Attached Figure Description

[0026] Figure 1 This is a schematic diagram illustrating the calculation principle of the method of the present invention;

[0027] Figure 2 This is a diagram showing the correspondence between node types and integers;

[0028] Figure 3 This is a diagram illustrating GPU thread allocation and thread indexing;

[0029] Figure 4 This is a schematic diagram of the two error merging calculation methods. Detailed Implementation

[0030] To improve the parallelism of current heterogeneous parallel symbolic model error calculation and provide a computation method for large-scale instance data in a Python environment, this invention utilizes Numba to design a highly parallel granular symbolic model error calculation method, including symbolic model conversion and representation, thread and memory allocation, error calculation, and error merging steps; referring to the accompanying drawings, the method of this invention specifically includes the following steps:

[0031] Step 1: In the Numba environment, the symbolic model based on syntax tree encoding is traversed to obtain the serialized Reverse Polish Notation (RPN). Then, the RPN is represented as an array according to the correspondence. Next, the instance data to be computed and the array-form RPN are sent from host memory to GPU memory, stored in global memory and constant memory respectively. The correspondence refers to the mapping between node types in the symbolic model and constant data in the array; node types include operators such as addition, subtraction, multiplication, and division, and constant data are integers.

[0032] In this step, since the symbolic model is commonly represented in computer programs in forms including syntax tree-based encoding, gene expression encoding, and sequence-based encoding, all of which are variations of syntax trees; and Numba only provides data storage in array form, the model needs to be converted and represented using an array.

[0033] In one embodiment of the present invention, a computational symbolic model is used. In large-scale instance data The error is illustrated here using the root mean square error as an example; where, the example data... , For the first i data, for The corresponding actual output, n The number of data points.

[0034] First, a model conversion is performed, transforming the symbolic model based on syntax tree encoding. Perform a post-order traversal to obtain the serialized Reverse Polish notation of the syntax model. Secondly, based on the preset correspondence between node types and constant data, see [link / reference]. Figure 2 As shown, Convert to array format, storing node type and array; and instance data Data is sent from host memory to GPU memory and stored in constant memory and global memory, respectively.

[0035] Step 2: Apply for a two-dimensional grid structure and a two-dimensional block structure. Based on the position of the thread in the block structure and the position of the block structure in the grid, allocate data indexes for each thread and allocate threads for each piece of data in the instance data. Allocate a simulation stack for each thread in shared memory and allocate stack indexes in local memory.

[0036] In this scheme, global memory and constant memory can be accessed by every thread, shared memory can only be accessed by threads within the same block structure, and registers can only be accessed by the thread to which they belong.

[0037] Nvidia GPUs provide threads and virtual memory for each memory function. Threads are divided into different levels and correspond to specific physical components. Grids execute on the entire GPU, blocks execute on the entire stream processor, and threads execute on CUDA cores. This invention allocates two-dimensional grids and two-dimensional blocks for kernel functions, allocates threads and simulation stacks for each instance data, stores the model in constant memory, and stores the dataset in global memory, representing instance-data-oriented parallelism.

[0038] Specifically, such as Figure 3 As shown, the kernel function grid structure is set as follows: Each block structure is The total number of threads is as well as The product of four numbers It is known that the position of a certain thread in this block structure is... The position of this block in the grid is The data index allocated to this thread in this invention is:

[0039]

[0040] in, The x and y coordinates of the grid structure The x and y coordinates of the block structure Here are the x and y coordinates of the thread within the block structure. These represent the x and y coordinates of the block structure within the mesh structure.

[0041] when This can lead to a waste of computing resources, as Nvidia specifies that the minimum processing unit is 32 threads, and the product of the sizes of the block structure two-dimensional arrays must be a multiple of 32.

[0042] A simulated stack is allocated for each thread in the shared memory area, and the model is set up. Length is Then the array size of the model stack is set to No overflow error will occur; simultaneously, a stack index is allocated in the local memory area, and a global memory allocation size of [size missing]. The array provides support for the second error merging.

[0043] Step 3: For the array-based Reverse Polish Notation (RPN), each data point is assigned a thread to substitute into the RPN and calculate the data error. Since an array-based simulated stack is used, different stack operations are performed sequentially on different node types in the RPN. The bottom value of the simulated stack is the output of the RPN. Based on this output and the actual output of each data point, the data error is obtained.

[0044] In this scheme, each thread performs calculations according to the following rules:

[0045] For each data entry Variables and constants are pushed directly onto the stack. For unary operators, the calculation is performed directly on the top element of the stack. For binary operators, the top two elements of the stack are used as input for calculation and overwrite the existing data. The data at the bottom of the stack is the output of each data item after processing using Reverse Polish Notation. This output is then compared with the corresponding actual output. The square of the difference is the root mean square error.

[0046] Step 4: After all threads have finished calculating their data errors, perform two error merging processes: The first error merging process sums the data errors calculated by all threads in each block structure in parallel and stores them in the first simulation stack of that block structure as the error sum of that block structure; The second error merging process copies the error sum of each block structure to the allocated global memory and performs step-by-step summation to obtain the final error value, which is then stored at the bottom of the first simulation stack in the grid structure (i.e., the first simulation stack of the first block structure). Finally, the error value is sent to the host memory.

[0047] In embodiments of the present invention, the first error merging, such as Figure 4 As shown, each block structure performs the same operation, summing the errors based on the thread index and step size control thread within the block structure, with the step size changing as follows: , Figure 4 The step size decreases from 32, and the bottom of the simulated stack corresponding to the first thread of each block is the sum of block errors.

[0048] The second error merging process first copies the error sum of each block structure to the allocated global memory, based on the step size. Summation by step, where satisfy Finally, the total sum of squared errors is stored at the bottom of the first stack of the grid.

[0049] Send the error sum from GPU memory to host memory for further calculation as needed.

[0050] To test the performance of this invention in calculating symbolic model errors, taking the fitness evaluation of symbolic regression models as an example, 50 independent experiments were conducted on the Pagie-1 synthesis problem with instance numbers {4096, 16384, 65536, 262144, 1048576} and four black-box problems, respectively. The speedup for the synthesis problem using an Nvidia GTX 1080Ti was approximately 60 times, and for the black-box problems approximately 36 times.

[0051] The above experiments demonstrate that the present invention effectively provides a method for accelerating symbolic model error calculation, which can significantly reduce computation time and improve efficiency in related scientific computing fields.

[0052] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A method for calculating the error of a large-scale instance symbolic model based on Numba, characterized in that, include: In the Numba environment, the symbolic model based on syntax tree encoding is traversed to obtain the serialized Reverse Polish Notation (RPN). Then, the RPN is represented as an array according to the correspondence. The instance data to be computed and the array-form RPN are then sent from the host memory to the GPU and stored in global memory and constant memory, respectively. Apply for a two-dimensional grid structure and a two-dimensional block structure. Based on the position of the thread in the block structure and the position of the block structure in the grid, allocate data indexes for each thread, allocate threads for each piece of data in the instance data, and allocate a simulation stack for each thread in shared memory. For the array-based Reverse Polish Notation, each data point is assigned a thread to substitute it into the Reverse Polish Notation and calculate the data error. Different stack operations are performed sequentially on different node types in the Reverse Polish Notation, and the bottom value of the simulated stack is the output of the Reverse Polish Notation. Based on this output and the actual output of each data point, the data error is obtained. After all threads have finished calculating their data errors, two error merging processes are performed: the first error merging process sums the data errors calculated by all threads in each block structure in parallel and stores them in the first simulated stack of that block structure as the error sum of that block structure. The second error correction first copies the error of each block structure to the allocated global memory, and then performs stepwise summation to obtain the final error value, which is stored at the bottom of the first simulation stack in the mesh structure. Finally, the error value is sent to the host.

2. The method for calculating the error of a large-scale instance symbolic model based on Numba according to claim 1, characterized in that, The correspondence is the correspondence between node types in the symbolic model and constant data in the array; node types include operators such as addition, subtraction, multiplication, and division, and constant data are integers.

3. The method for calculating the error of a large-scale instance symbolic model based on Numba according to claim 1, characterized in that, Global memory and constant memory can be accessed by every thread, while shared memory can only be accessed by threads within the same block structure.

4. The method for calculating the error of a large-scale instance symbolic model based on Numba according to claim 1, characterized in that, Set the grid structure as follows Each block structure is The position of a certain thread in this block structure is The position of this block in the grid is The data index allocated to this thread in this invention is: in, The x and y coordinates of the grid structure The x and y coordinates of the block structure Here are the x and y coordinates of the thread within the block structure. These represent the x and y coordinates of the block structure within the mesh structure. A simulated stack is allocated for each thread in the shared memory area, and Reverse Polish notation is used. Length is Then the array size of the model stack is set to Simultaneously, a stack index is allocated in the local memory area, and a global memory allocation size of [size missing]. The array provides support for the second error merging; n This represents the number of data points in the instance data.

5. The method for calculating the error of a large-scale instance symbolic model based on Numba according to claim 1, characterized in that, Each thread performs calculations according to the following rules: For each data entry Variables and constants are pushed directly onto the stack. For unary operators, the calculation is performed directly on the top element of the stack. For binary operators, the top two elements of the stack are used as input for calculation and overwrite the existing data. The data at the bottom of the stack is the output of each data item after processing using Reverse Polish Notation. This output is then compared with the corresponding actual output. The square of the difference is the root mean square error.

6. The method for calculating the error of a large-scale instance symbolic model based on Numba according to claim 1, characterized in that, During the first error merging, each block structure performs the same operation: summing the errors based on the thread index within the block structure and the step size control thread, with the step size changing as follows. Finally, the bottom of the simulated stack corresponding to the first thread of each block is the sum of block errors; where satisfy .

7. The method for calculating the error of a large-scale instance symbolic model based on Numba according to claim 1, characterized in that, In the second error merging, the error sum of each block structure is first copied to the allocated global memory, according to the step size. The errors are summed step by step, and the final total error value is stored at the bottom of the first simulation stack in the grid structure.

8. A computing device, comprising a processor, a memory, and a computer program stored in the memory; characterized in that, When the processor executes a computer program, it implements the method for calculating the error of a large-scale instance symbolic model based on Numba, as described in any one of claims 1-7.

9. A computer-readable storage medium storing a computer program; characterized in that, When the computer program is executed by a processor, it implements the method for calculating errors of large-scale instance symbolic models based on Numba as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Large-scale symbol regression method and system based on adaptive parallel genetic algorithm

    CN110135584A

  • Implementation method and system of high-efficiency deep threat recognition engine

    CN110493167A