Numba-based large-scale instance symbol model error calculation method
By parallelizing the symbol model error calculations on the GPU, the problem of insufficient parallelization in large-scale instance data processing in the prior art is solved, and efficient symbol model error calculations are achieved.
Patent Information
- Application Number
- CN202411515714.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2044-10-29
AI Technical Summary
The existing heterogeneous parallel symbol model error calculation methods are insufficient in parallelism during large-scale instance data processing, resulting in inefficient calculation efficiency, especially in symbol regression and high-tech explanatory research.
The Numba library is used to implement symbol model error calculation on the GPU. By converting the symbol model into an inverse Polish form, using the simulation stack to perform data error calculation, and parallelizing the entire process through two error merging processing.
The degree of parallelization of symbol model error calculations has been significantly improved, the calculation time has been significantly reduced, and the efficiency of related scientific computing fields has been improved.
Smart Images

Figure CN119512741A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of data science and high performance computing, and in particular to a large-scale instance symbolic model error calculation method based on Numba, wherein the method utilizes Numba to realize fast error calculation of symbolic models. Background Art
[0002] Symbolic models are models used to represent symbolic operations. Common forms are mathematical expressions and equations. They are widely used in data description and prediction in scientific research and engineering, including regression analysis, motion control, mathematical law representation, etc. When optimizing and comparing models, it is necessary to calculate the error between the predicted model and the real data or the real model. When the number of models is large and the number of instance data is large, the calculation is very slow, especially in symbolic regression and high-tech explanatory research. It is very time-consuming and seriously affects the calculation efficiency.
[0003] With the development of big data technology and high-performance computing, scholars have designed various homogeneous and heterogeneous parallel symbolic model error calculation methods. Common errors of symbolic models include sum-of-variance, mean square error, root mean square error, coefficient of determination, etc., all of which include steps such as single instance error calculation and error summation. The homogeneous parallel method creates multiple threads, calculates the errors of different instance data in parallel and then sums them. Due to the number and characteristics of CPU physical cores, the acceleration effect is limited. The heterogeneous parallel method deploys the error calculation and summation on the GPU with a single instruction stream multiple data stream architecture, which is similar to the homogeneous parallel method, but fully utilizes the advantages of GPU multi-core and has a significant acceleration effect. The current heterogeneous parallel algorithms mostly use OpenCL and CUDA based on C language to obtain GPU computing resources, which requires high coding ability. Python language is widely used in data science. At present, there is a way to accelerate the error calculation in the Python language environment by using the vectorization of the TensorFlow library, which complicates the problem, and the parallel granularity and computing process are insufficient. Summary of the invention
[0004] The purpose of the present invention is to provide a large-scale instance symbol model error calculation method based on Numba, so as to improve the parallelization degree of the current heterogeneous parallel symbol model error calculation, thereby improving the efficiency of the algorithm.
[0005] In order to achieve the above tasks, the present invention adopts the following technical solutions:
[0006] A large-scale instance symbolic model error calculation method based on Numba, comprising:
[0007] In the Numba environment, the symbolic model based on the syntax tree encoding is subsequently traversed to obtain the serialized reverse Polish notation, and then the reverse Polish notation is represented as an array according to the corresponding relationship; then the instance data to be calculated and the reverse Polish notation in array form are sent from the host memory to the GPU and stored in the global memory and constant memory respectively;
[0008] Apply for a two-dimensional grid structure and a two-dimensional block structure, allocate data indexes to each thread based on the position of the thread in the block structure and the position of the block structure in the grid, allocate threads to each piece of data in the instance data, and allocate a simulation stack to each thread in the shared memory;
[0009] For the reverse Polish form in array form, use the thread assigned to each data to substitute each data into the reverse Polish form to calculate the data error respectively; perform different stack operations on different node types in the reverse Polish form in sequence, and the bottom value of the simulated stack is the output of the reverse Polish form; based on the output and the actual output of each data, the data error is obtained;
[0010] When the data errors of all threads are calculated, two error merging processes are performed: the first error merging sums the data errors calculated by all threads in each block structure in parallel and stores them in the first simulation stack of the block structure as the error sum of the block structure; the second error merging first copies the error sum of each block structure to the allocated global memory, and gradually sums it to obtain the final error value and stores it at the bottom of the first simulation stack in the grid structure, and finally sends the error value to the host.
[0011] Furthermore, the corresponding relationship is a corresponding relationship between node types in the symbolic model and constant data in the array; the node types include operators such as addition, subtraction, multiplication and division, and the constant data is an integer.
[0012] Furthermore, each thread can access global memory and constant memory, while shared memory can only be accessed by threads in the same block structure.
[0013] Furthermore, the grid structure is set to (gD.x, gD.y), wherein each block structure is (bD.x, bD.y), the position of a thread in the block structure is (tId.x, tId.y), the position of the block in the grid is (bId.x, bId.y), and the data index allocated to the thread by the present invention is:
[0014] Id=(bId.y×gD.x+bId.x)×(bD.x×bD.y)+tId.y×bD.x+tId.x
[0015] Wherein, gD.x, gD.y are the x and y coordinate positions of the grid structure, bD.x, bD.y are the x and y coordinate positions of the block structure, tId.x, tId.y are the x and y coordinate positions of the thread in the block structure, and bId.x, bId.y are the x and y coordinate positions of the block structure in the grid structure;
[0016] Allocate a simulation stack for each thread in the shared memory area. Assume that the length of the reverse Polish program is lMax, then the array size of the model stack is set to At the same time, the stack index is allocated in the local memory area, and the size of the global memory allocation is The array provides support for the second error merging; n is the number of data in the instance data.
[0017] Furthermore, each thread performs calculations according to the following rules:
[0018] For each data X i The variables and constant values in are pushed directly onto the stack. For unary operators, the top element of the stack is directly calculated. For binary operators, the two top elements of the stack are used as inputs to calculate and overwrite. The bottom data of the stack is the output of each data after the reverse Polish notation, and then the output and the corresponding actual output y are calculated. i 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, and the errors are summed according to the thread index and step size control thread in the block structure. The step size changes to Finally, the bottom of the simulation stack corresponding to the first thread of each block is the sum of the block errors; where k satisfies
[0020] Furthermore, in the second error merging, the error sum of each block structure is first copied to the allocated global memory, and then the error sum is calculated according to the step size {2 k ,2 k-1 ,…,1} are gradually summed up, and the final total error value is stored at the bottom of the first simulation stack in the grid structure.
[0021] A computing device comprises a processor, a memory and a computer program stored in the memory; when the processor executes the computer program, the Numba-based large-scale instance symbol model error calculation method is implemented.
[0022] A computer-readable storage medium stores a computer program; when the computer program is executed by a processor, the Numba-based large-scale instance symbolic model error calculation method is implemented.
[0023] Compared with the prior art, the present invention has the following technical features:
[0024] 1. The present invention provides a symbolic model representation method based on the Numba library, and uses the output calculation method of the simulation stack to provide a symbolic model error calculation paradigm for obtaining CUDA resources of Nvidia GPU in the Python environment, which can be widely used in symbolic model evaluation in various fields.
[0025] 2. The present invention constructs a large-scale instance data thread allocation method with high parallel granularity. The two error merging parallelizes the entire error calculation process, which can be used in the error calculation of other heterogeneous symbol models, thereby improving the overall efficiency of the algorithm. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 Schematic diagram of the calculation principle of the method of the present invention;
[0027] Figure 2 It is a schematic diagram of the correspondence between node types and integers;
[0028] Figure 3 This is a schematic diagram of GPU thread allocation and thread index;
[0029] Figure 4 It is a schematic diagram of the two error merging calculation methods. DETAILED DESCRIPTION
[0030] In order to improve the parallelization degree of the current heterogeneous parallel symbolic model error calculation and provide a calculation method for large-scale instance data in a Python environment, the present invention uses Numba to design a high-parallel granularity symbolic model error calculation method, including symbolic model conversion and representation, thread and memory allocation, error calculation, error merging and other steps; referring to the accompanying drawings, the method of the present invention specifically includes the following steps:
[0031] Step 1: In the Numba environment, the symbolic model based on the syntax tree encoding is subsequently traversed to obtain the serialized reverse Polish notation, and then the reverse Polish notation is represented as an array according to the corresponding relationship; then the instance data to be calculated and the reverse Polish notation in array form are sent from the host memory to the GPU memory, and stored in the global memory and constant memory respectively. The corresponding relationship is the corresponding relationship between the node type in the symbolic model and the constant data in the array; the node type includes operators such as addition, subtraction, multiplication and division, and the constant data is an integer.
[0032] In this step, since the commonly used representation forms of symbolic models in computer programs include syntax tree-based encoding, gene expression encoding, and sequence-based encoding, all of which are variants of syntax trees; Numba only provides data storage in array form, the model needs to be converted and represented by an array.
[0033] In one embodiment of the present invention, the computational symbol model M is used in large-scale instance data. The error of the model is explained here by taking the root mean square error as an example; among them, the instance data D, X i is the i-th data, y i For X i The corresponding actual output, n is the number of data.
[0034] First, the model conversion is performed, and the symbolic model M based on the syntax tree encoding is traversed in post-order to obtain the serialized reverse Polish Program of the syntax model; secondly, according to the correspondence between the preset node type and the constant data, see Figure 2 As shown, the Program is converted into an array form, and the node type and array are saved; the Program and instance data D are sent from the host memory to the GPU memory and stored in the constant memory and the global memory respectively.
[0035] Step 2: Apply for a two-dimensional grid structure and a two-dimensional block structure, allocate data indexes for each thread based on the position of the thread in the block structure and the position of the block structure in the grid, and allocate threads for each data in the instance data; allocate a simulation stack for each thread in the shared memory, and allocate a stack index in the local memory.
[0036] In this solution, each thread can access the global memory and constant memory, only threads in the same block structure can access the shared memory, and only the thread to which the register belongs can access it.
[0037] Nvidia GPU provides threads and virtual memory for each memory function. Threads are divided into different levels and correspond to specific physical components. Grid is executed on the entire GPU, Block is executed on the entire stream processor, and Thread is executed on the CUDA core. The present invention applies for 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 data set in global memory, which is instance data-oriented parallelism.
[0038] Specifically, Figure 3 As shown, the grid structure of the kernel function is set to (gD.x, gD.y), where each block structure is (bD.x, bD.y), then the total number of threads is the product of gD.x, gD.y and bD.x, bD.y thdNum; it is known that the position of a thread in the block structure is (tId.x, tId.y), and the position of the block in the grid is (bId.x, bId.y), and the data index allocated to the thread by the present invention is:
[0039] Id=(bId.y×gD.x+bId.x)×(bD.x×bD.y)+tId.y×bD.x+tId.x
[0040] Among them, gD.x, gD.y are the x and y coordinate positions of the grid structure, bD.x, bD.y are the x and y coordinate positions of the block structure, tId.x, tId.y are the x and y coordinate positions of the thread in the block structure, and bId.x, bId.y are the x and y coordinate positions of the block structure in the grid structure.
[0041] When thdNum<n, it will cause a waste of computing resources. Since Nvidia stipulates that the minimum processing unit is 32 threads, the product of the size of the block structure two-dimensional array must be a multiple of 32.
[0042] Allocate a simulation stack for each thread in the shared memory area. Suppose the model Program length is lMax, then the array size of the model stack is set to No overflow error will occur; at the same time, the stack index is allocated in the local memory area, and the size of the global memory allocation is The array provides support for the second error merging.
[0043] Step 3, for the reverse Polish form in array form, use the thread assigned to each data to substitute each data into the reverse Polish form to calculate the data error respectively; since an array-form simulation stack is used, different stack operations are performed on different node types in the reverse Polish form in sequence, and the bottom value of the simulation stack is the output of the reverse Polish form; based on the output and the actual output of each data, the data error is obtained.
[0044] In this solution, each thread performs calculations according to the following rules:
[0045] For each data X i The variables and constant values in are pushed directly onto the stack. For unary operators, the top element of the stack is directly calculated. For binary operators, the two top elements of the stack are used as inputs to calculate and overwrite. The bottom data of the stack is the output of each data after the reverse Polish notation, and then the output and the corresponding actual output y are calculated. i The square of the difference is the root mean square error.
[0046] Step 4, when the data errors of all threads are calculated, two error merging processes are performed: the first error merging is to parallel sum the data errors calculated by all threads in each block structure and store them in the first simulation stack of the block structure as the error sum of the block structure; the second error merging is to first copy the error sum of each block structure to the allocated global memory, and gradually sum it up to obtain the final error value and store it at the bottom of the first simulation stack in the grid structure (i.e., the first simulation stack of the first block structure), and finally send the error value to the host memory.
[0047] In the embodiment of the present invention, the first error merging is performed, such as Figure 4As shown, each block structure performs the same operation, and the error is summed according to the thread index and step size in the block structure. The step size changes to Figure 4 The step size decreases from 32, and finally the bottom of the simulation stack corresponding to the first thread of each block is the block error sum.
[0048] The second error merging first copies the error sum of each block structure to the allocated global memory, and then k ,2 k-1 ,…,1} step by step, where k satisfies The final total sum of squared errors is stored at the bottom of the first stack in the grid.
[0049] Send error sum, send the error sum from GPU memory to host memory for further calculation as needed.
[0050] In order to test the performance of the present invention for symbolic model error calculation, taking the fitness evaluation of the symbolic regression model as an example, 50 independent experiments were carried out on the synthetic problem Pagie-1 and four black box problems with the number of instances {4096, 16384, 65536, 262144, 1048576} respectively. The acceleration ratio of the synthetic problem was about 60 times, and that of the black box problem was about 36 times using Nvidia GTX 1080Ti.
[0051] The above experiments show that the present invention effectively provides a method for accelerating the calculation of symbolic model errors, which can significantly reduce the calculation time and improve the efficiency of related scientific computing fields.
[0052] 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. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A large-scale instance symbolic model error calculation method based on Numba, characterized in that: include: In the Numba environment, the symbolic model based on the syntax tree encoding is subsequently traversed to obtain the serialized reverse Polish notation, and then the reverse Polish notation is represented as an array according to the corresponding relationship; then the instance data to be calculated and the reverse Polish notation in array form are sent from the host memory to the GPU and stored in the global memory and constant memory respectively; Apply for a two-dimensional grid structure and a two-dimensional block structure, allocate data indexes to each thread based on the position of the thread in the block structure and the position of the block structure in the grid, allocate threads to each piece of data in the instance data, and allocate a simulation stack to each thread in the shared memory; For the reverse Polish form in array form, use the thread assigned to each data to substitute each data into the reverse Polish form to calculate the data error respectively; perform different stack operations on different node types in the reverse Polish form in sequence, and the bottom value of the simulated stack is the output of the reverse Polish form; based on the output and the actual output of each data, the data error is obtained; After all the data errors of all threads are calculated, two error merging processes are performed: the first error merging is to sum the data errors calculated by all threads in each block structure in parallel and store them in the first simulation stack of the block structure as the error sum of the block structure; The second error reduction first copies the error sum of each block structure to the allocated global memory, and then gradually sums it to obtain the final error value and stores it at the bottom of the first simulation stack in the grid structure. Finally, the error value is sent to the host.
2. The large-scale instance symbolic model error calculation method based on Numba according to claim 1, characterized in that: The correspondence is the correspondence between the node type in the symbolic model and the constant data in the array; the node type includes operators such as addition, subtraction, multiplication and division, and the constant data is an integer.
3. The large-scale instance symbolic model error calculation method based on Numba according to claim 1, characterized in that: Every thread can access global memory and constant memory, and shared memory can only be accessed by threads in the same block structure.
4. The large-scale instance symbolic model error calculation method based on Numba according to claim 1, characterized in that: The grid structure is set to (gD.x, gD.y), where each block structure is (bD.x, bD.y), the position of a thread in the block structure is (tId.x, tId.y), the position of the block in the grid is (bId.x, bId.y), and the data index allocated to the thread by the present invention is: Id=(bId.y×gD.x+bId.x)×(bD.x×bD.y)+tId.y×bD.x+tId.x Wherein, gD.x, gD.y are the x and y coordinate positions of the grid structure, bD.x, bD.y are the x and y coordinate positions of the block structure, tId.x, tId.y are the x and y coordinate positions of the thread in the block structure, and bId.x, bId.y are the x and y coordinate positions of the block structure in the grid structure; Allocate a simulation stack for each thread in the shared memory area. Assume that the length of the reverse Polish program is lMax, then the array size of the model stack is set to At the same time, the stack index is allocated in the local memory area, and the size of the global memory allocation is The array provides support for the second error merging; n is the number of data in the instance data.
5. The large-scale instance symbolic model error calculation method based on Numba according to claim 1, characterized in that: Each thread is calculated according to the following rules: For each data X i The variables and constant values in are pushed directly onto the stack. For unary operators, the top element of the stack is directly calculated. For binary operators, the two top elements of the stack are used as inputs to calculate and overwrite. The bottom data of the stack is the output of each data after the reverse Polish notation, and then the output and the corresponding actual output y are calculated. i The square of the difference is the root mean square error.
6. The method for calculating large-scale instance symbolic model errors based on Numba according to claim 1, characterized in that: During the first error merging, each block structure performs the same operation, and the errors are summed according to the thread index and step length control thread in the block structure. The step length changes to Finally, the bottom of the simulation stack corresponding to the first thread of each block is the sum of the block errors; where k satisfies 7. The large-scale instance symbolic model error calculation method 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, and then the error sum is calculated according to the step size {2 k ,2 k-1 ,…,1} are gradually summed up, 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 the computer program, it implements the large-scale instance symbol model error calculation method based on Numba according to any one of claims 1-7.
9. A computer-readable storage medium, wherein a computer program is stored in the medium; characterized in that: When the computer program is executed by a processor, the large-scale instance symbol model error calculation method based on Numba according to any one of claims 1 to 7 is implemented.
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
Nonlinear regression calculation technology based on general functional expression recognition assignment calculation and Powell algorithm
CN111651723A
Digital oscilloscope mathematical operation processing method based on inverse Polish algorithm
CN111767004A
Method for automatically configuring GPU expansion box
CN112651162A