Parallel BVH minimum distance query algorithm based on CUDA
By adopting the parallelized hierarchical body enclosure box minimum distance query algorithm based on CUDA in the three-dimensional model close-distance query algorithm, a two-level task queue and a binary tree search strategy are designed, which solves the problem of insufficient efficiency and real-time performance of the existing algorithm under the requirements of high real-time, and realizes efficient and high-speed three-dimensional model distance query.
Patent Information
- Application Number
- CN202510402459.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-01
- Publication Date
- 2025-05-02
- Estimated Expiration
- 2045-04-01
AI Technical Summary
The existing three-dimensional model close-distance query algorithm cannot meet the high real-time requirements of industrial automation scenarios, especially when processing tens of millions of three-dimensional models, the calculation efficiency is inefficient and the real-time is insufficient.
The parallelized hierarchical body enclosure box minimum distance query algorithm is adopted based on CUDA, and a binary tree search strategy matching the design is realized, and the computing resource allocation and data processing efficiency are optimized.
It significantly improves the minimum distance query efficiency between high-complexity and high-precision three-dimensional models, improves the allocation efficiency of computing resources and the efficiency of data processing, and meets the high real-time requirements of industrial automation scenarios.
Smart Images

Figure CN119917683A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of computer graphics, in particular to a CUDA-based parallel hierarchical volume bounding box minimum distance query algorithm. Background Art
[0002] In computer graphics, the closest distance query between two three-dimensional objects is currently accelerated by the bounding box hierarchy (BVH) algorithm. As computer graphics is gradually applied to industrial automation scenarios such as assembly management, digital twins, and robot simulation, the accuracy and real-time requirements of related algorithms are becoming higher and higher. In some high-precision computing scenarios, it may be necessary to perform real-time distance queries on three-dimensional models containing tens of millions or even hundreds of millions of primitives at a frequency of about 30-50Hz. This includes the following issues: The amount of data is huge; a model with tens of millions of primitives may require the construction of about 40 layers of BVH trees, so the hierarchical volume bounding box test tree (BVTT) contains more than 10 leaf nodes. 24 Strict alignment in three-dimensional space: Due to the coarseness of the bounding box, it is usually impossible to eliminate it by pruning BVTT. Severe branch divergence: These vertices with similar distances may eventually be distributed in different subtrees of BVTT, which greatly increases the query workload.
[0003] At present, the existing three-dimensional model closest distance query algorithm cannot meet the high real-time requirements of industrial automation scenarios. In the existing technology, the following methods are usually used to partially solve the above problems: Surface Area Heuristic (SAH) algorithm. SAH is a common and effective method for constructing high-quality BVH. However, for geometric bodies with relatively regular shapes in industrial scenes, the segmentation mode using the SAH algorithm is not much different from the traditional equidistant segmentation mode, and the performance improvement is relatively limited.
[0004] Choose a denser bounding box. However, these denser bounding boxes usually have much more complicated geometric distance calculation methods than traditional rectangular bounding boxes, which significantly increases the computational cost of each search, which is not worth the cost.
[0005] Use GPU to parallelize the search. However, the existing parallel recursive method is limited to collision detection. Although the functions are similar, the parallelization difficulty of collision detection is much smaller than that of distance query, and the existing algorithm cannot be directly transplanted due to the significant differences in algorithm logic. Summary of the invention
[0006] Aiming at the characteristics of NVIDIA GPU and the high-precision and high-real-time requirements of industrial application scenarios, the present invention provides a parallelized BVH minimum distance query algorithm to overcome the defects of low computational efficiency and insufficient real-time performance of existing distance query algorithms when dealing with tens of millions of three-dimensional models.
[0007] The technical solution adopted by the present invention to achieve the above-mentioned purpose is: based on the CUDA parallel BVH minimum distance query algorithm, a two-level task queue is constructed, CUDA thread blocks are used as batch processing units, and a hierarchical bounding box test tree is used to implement parallel search to query the shortest distance between two three-dimensional objects, including the following steps: Build a two-level task queue, including a global queue and a local queue; Before starting the search, all threads of the GPU are initialized in thread blocks. Thread 0 of each thread block first takes a node from the global queue and puts it at the top of the local queue, which is initialized as the root node of the current thread block. When searching, all threads in the same thread block read child nodes in batches from the local queue and perform concurrent searches. After the search is completed, the child nodes that need to be searched next time are added to the local queue in batches. After the thread block completes the search, the minimum distance of the bounding box of the hierarchy is obtained.
[0008] The construction of the two-level task queue is as follows: The first-level queue is a global queue, which is visible to all threads participating in the search. This queue is a first-in-first-out queue; The second-level queue is a local queue, that is, a thread block-specific queue. Each thread block instantiates a queue, which is visible to all threads in the current thread block. The queue adopts a double-ended design, in which the front end is a fixed-length buffer with the same length as the number of threads in the thread block; the back end is a first-in, last-out queue.
[0009] All threads in the same thread block read child nodes in batches from the local queue and perform concurrent search, including the following steps: In each batch search, for the child nodes containing two hierarchical bounding boxes, the distance of the bounding box in the left child node and the distance of the bounding box in the right child node are calculated respectively; When the calculated distance of a child node is greater than or equal to the currently memorized minimum distance, the child node is directly skipped; otherwise, the child node with a closer distance is stored in the front of the local queue, and the child node with a farther distance is stored in the back of the local queue; In addition, if the child node is a leaf node, the distance between the graphics elements contained in the child node is directly calculated; if the calculated distance is less than the currently remembered minimum distance, the calculated distance replaces the currently remembered minimum distance to update the memory.
[0010] When storing in child nodes, a parallel prefix compression algorithm is used to format and store data without locks, and thread blocks are used to share memory.
[0011] When taking out child nodes, the thread block takes out all nodes in batches from the front end of the local queue first; when the number of child nodes in the front end of the local queue is less than the total number of threads in the thread block, the threads exceeding the length take out data from the back end.
[0012] The child nodes to be prioritized for parallelization are selected according to the judgment condition and added to the global queue; the judgment condition is any one of the following conditions: a. The number of layers the node is located in is less than 1 / M of the total number of layers of BVTT, 2≤M≤10; b. The distance between the closer child node and the farther child node is less than (1 / N) of the total volume of the bounding box. -1 / 3 , 5≤N≤20; c. The number of child nodes in the current global queue is not greater than the total number of thread blocks.
[0013] After the thread block completes the search, the minimum distance of the bounding box of the hierarchical volume is obtained, which includes the following steps: All thread blocks preferentially search the nodes in their own local queues; when a thread block completes the search of all child nodes in its own local queue and no longer adds new child nodes to the local queue, the thread block takes out a new child node from the global queue as the root node for the next round of search, and repeats the steps of batch reading child nodes from the local queue by all threads in the same thread block to perform concurrent search; When all thread blocks have completed the search and there are no nodes in the global queue, the algorithm exits and the currently memorized minimum distance is the global minimum distance, which is used as the minimum distance of the bounding box of the hierarchy.
[0014] A CUDA-based parallel BVH minimum distance query system, including: Task queue construction module, used to build two-level task queues, including global queues and local queues; The thread initialization module is used to initialize all threads of the GPU in thread blocks before starting the search. Thread No. 0 of each thread block first takes a node from the global queue and puts it at the top of the local queue, which is initialized as the root node of the current thread block. Batch search module, when searching, all threads in the same thread block read sub-nodes in batches from the local queue for concurrent search; after the search is completed, the sub-nodes to be searched next time are added to the local queue in batches; The BVH minimum distance acquisition module is used to obtain the minimum distance of the bounding box of the hierarchy after the thread block completes the search.
[0015] A CUDA-based parallel BVH minimum distance query device comprises a memory and a processor; the memory is used to store a computer program; the processor is used to implement the CUDA-based parallel BVH minimum distance query method when executing the computer program.
[0016] A computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the CUDA-based parallel BVH minimum distance query method is implemented.
[0017] The present invention has the following beneficial effects and advantages: 1. This paper designs an innovative two-layer task queue structure for parallel distance query tasks of 3D models, and formulates matching queue entry and exit rules. This design not only allows the algorithm to prioritize BVTT nodes with closer distances in a highly parallel situation, like traditional single-thread recursion, thereby effectively performing pruning operations, but also takes into account the hardware characteristics of NVIDIA GPUs and avoids the thread branch divergence phenomenon commonly seen in CUDA programming; 2. In view of the proposed double-layer queue structure, the present invention designs a matching binary tree search strategy to meet the needs of processing highly complex three-dimensional models in industrial production scenarios. This search strategy realizes a highly parallel query process, effectively avoids the problems discussed in the previous section, and significantly improves the efficiency of the minimum distance query between highly complex and high-precision three-dimensional models. The design of this strategy not only optimizes the allocation of computing resources, but also ensures efficient and high-precision data processing. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 The overall architecture diagram of the algorithm of the present invention.
[0019] Figure 2 Algorithm thread block search flow chart of the present invention.
[0020] Figure 3 Schematic diagram of the local queue design of the present invention.
[0021] Figure 4 Schematic diagram of the local queue data storage / retrieval method of the present invention.
[0022] Figure 5 Schematic diagram of the global queue design of the present invention. DETAILED DESCRIPTION
[0023] The present invention is further described in detail below in conjunction with the accompanying drawings and embodiments.
[0024] The present invention uses a hierarchical volume bounding box (BVH) algorithm to accelerate the query process. The algorithm recursively groups one or a group of primitives into bounding boxes, each of which can be enclosed in a larger box to form a binary tree or multi-tree structure that is easy to index. In the collision / distance query task between two geometric bodies, by aggregating two BVH binary trees into a hierarchical volume test tree (BVTT), the query task can be converted into a classic binary tree search problem, simplifying the algorithm logic and facilitating the implementation of the program.
[0025] For example, in industrial manufacturing scenarios, in order to monitor the status of the production line in real time, the machine vision system uses sensors (such as depth cameras or lidar) to obtain three-dimensional point clouds or models of workpieces in the environment, thereby building a digital twin to simulate the current real working conditions. The amount of data of these point clouds or three-dimensional models can reach tens of millions or hundreds of millions. To improve computing efficiency, object models are stored in the computer in the form of BVH trees (such as AABB trees or OBB trees), representing the hierarchical bounding boxes of each object. When the robot performs grasping, obstacle avoidance or detection tasks, it is necessary to quickly calculate the minimum distance between the robot and the target object. At this time, the BVHs of the two query objects need to be aggregated to form a BVTT, and the binary tree is traversed to achieve the minimum distance query.
[0026] The classic distance query algorithm uses a depth-first approach to recursively traverse and search the BVTT. Before recursively entering a subtree, the algorithm first calculates the distance between the bounding boxes of two child nodes so that the subtree with a closer distance is visited first. In this way, the algorithm can quickly locate vertex pairs with a closer distance. In the later stages of the recursion, based on the current closest distance found, the algorithm can quickly exclude those child nodes with a longer distance and perform pruning on the BVTT, thereby greatly accelerating the search process. This method significantly reduces unnecessary calculations, improves search efficiency, and optimizes the performance of the entire distance query.
[0027] like Figure 1 As shown, in view of the hardware characteristics of NVIDIA GPU and the characteristics of distance query in industrial production scenarios, the present invention designs a parallelized recursive search algorithm with two-level task queues based on the classic recursive algorithm according to the classification of the CUDA framework itself. Among them, the first-level queue is a global queue, which is visible to all threads participating in the search; the second-level queue is a thread block-specific queue, and each thread block instantiates a queue, which is visible to all threads in the thread block.
[0028] like Figure 2As shown, when executing distance queries, CUDA thread blocks are used as batch processing units, and the batch search optimization process is used to improve the computing speed. Before starting the search, thread 0 of each thread block first takes a node from the global queue and puts it into the head of the front end of the local queue, and initializes it as the root node of the thread block. Among them, the front end is a fixed-length buffer of the local queue, and the head is the front part of the front end. During the search, all threads in the same thread block read nodes in batches from the local queue for concurrent search. After the search is completed, the nodes to be searched next time are added to the local queue in batches according to the recursive termination condition. Specifically, the main process includes the following steps: 1. Global queue management 1.1. Getting Started: Start the minimum distance query process. Initialize the root node of the BVTT to be processed in the global queue.
[0029] 1.2. Take a node from the global queue: Thread No. 0 of each thread block independently takes a node from the queue, indicating that the thread block needs to calculate the minimum distance of the primitive contained in the subtree expanded by the node.
[0030] 1.3. Initialize the local queue: Generate a local queue for the current thread block to manage batch searches of its child nodes. Put the current node at the head of the local queue as the initial node.
[0031] 1.4. Thread block batch search subtree: Call a subprocess (local search process) to search the subtree expanded by the current node.
[0032] 1.5. Determine whether the global queue is empty and all thread blocks have been processed Determine whether the global queue is empty and all subtrees in the local queue have been searched. If so, the process ends and the final minimum distance is returned; if not, return to step 1.2 to continue.
[0033] 2. Local Search Process 2.1. Take out the node from the local queue: Nodes are taken out from the local queue in batches and given to each thread in the thread block to search.
[0034] 2.2. Determine whether it is a leaf node Determine whether the current node is a leaf node (i.e., the bottom node of BVTT). If so, directly calculate the minimum distance between the internal primitives of the node, update the optimal solution, and jump to step 2.9.
[0035] 2.3. Get the left and right child nodes: If the node is not a leaf node, get its left and right child nodes as the target for further processing.
[0036] 2.4. Calculate the distance between the left and right child nodes and the target object: Calculate the distance (geometric distance or other measurement method) between the inner bounding boxes of the left and right child nodes respectively.
[0037] 2.5. Sort by distance from smallest to largest: According to the calculated distance, the left and right child nodes are sorted from near to far, so that the closer child nodes are processed first.
[0038] 2.6. Recursive termination condition judgment: Is the closest child node greater than the current global minimum value? If it is greater, the child node is placed at the front of the local queue, indicating that further search is needed. If it is less than or equal to, the node is skipped directly because there is no possibility of a closer distance inside the node.
[0039] After the judgment is completed, parallel prefix scanning is used to compress the front part of the local queue to eliminate the vacancies caused by skipping nodes.
[0040] 2.7. Recursive termination condition judgment: Is the distance of the child node farther away greater than the current global minimum? If it is greater, proceed to step 2.8; if it is less than or equal to, skip the node directly because there is no closer distance inside the node.
[0041] 2.8. Whether to add child nodes to the global queue If the current node meets the conditions for priority search, it will be added to the global queue and handed over to other thread blocks for batch processing; otherwise, the child node will be added to the back end of the local queue and searched by this thread block later. The judgment conditions are as follows: The number of layers the node is located in is less than 1 / 4 of the total number of layers of BVTT (the threshold is adjustable). For nodes that are too low in the hierarchy, the subtrees they correspond to are not very large to begin with, so the time spent splitting them to search in other thread blocks is not much different from the time spent searching in the current thread block, which in turn increases the memory read and write overhead.
[0042] The distance between the closer child nodes and the farther child nodes is less than (1 / 10) of the total volume of the bounding box. -1 / 3 (The threshold is adjustable.) For bounding boxes with very close or even identical distances, it is more likely that similar distances will appear in their expanded subtrees, so it is worth parallelizing the processing.
[0043] The amount of data in the current global queue is not greater than the total number of thread blocks. If the number of nodes to be processed in the global queue exceeds the total number of thread blocks supported by the GPU, some nodes that were originally expected to be searched in parallel may not be searched for a long time, but may take longer.
[0044] 2.9. Is the local queue empty? If there are still unprocessed nodes in the local queue, return to step 2.1 to continue; if the local queue is empty, the local processing flow ends.
[0045] Through the above process, the algorithm can realize step-by-step processing of nodes in the global queue, complete node block processing of complex structures based on the optimized search of the local queue, and control the search path according to the node distance and priority.
[0046] like Figure 3 , Figure 4 As shown, the local queue is a composite queue, which is divided into two parts. The front end is a fixed-length buffer (the size is equal to the number of threads contained in the thread block), and the back end is a last-in-first-out queue. This design is to match the priority search mode of the binary tree. When storing data, the child nodes with closer distances in each batch search are stored in the front end, and the child nodes with farther distances are stored in the back end. Since the recursive termination condition (i.e., steps 2.6 and 2.7 above) will exclude some bounding boxes with farther distances, the length relationship of the data stored in each batch must satisfy: The length of the data stored in the back end is Len. _ back<= the length of the data stored in the front end, Len _ front<= thread block size block_size. Therefore, such a design will not cause queue overflow. When retrieving data, the thread block will first retrieve all data in batches from the front end. When the amount of data in the front end is less than the total number of thread blocks, the remaining threads retrieve data from the back end. The queue also adopts a lock-free design, uses a parallel prefix compression algorithm to format the stored data, and uses thread block shared memory to speed up memory reading and writing.
[0047] like Figure 5 As shown in the figure, the design of the global queue is relatively simple. It is a first-in, first-out queue used to store the nodes selected in step 2.8 above. The buffer of this queue is implemented in the global video memory and is visible to all thread blocks. Since the number of times a thread block accesses the queue in a search is not large, data access is implemented using atomic memory operations, which is easier to implement in programming.
[0048] By using the algorithm of the present invention, the speed of executing the closest distance query task of the three-dimensional model in the graphics algorithm is increased by 5-30 times, which greatly improves the execution efficiency of the relevant algorithms. In the digital twin system of industrial production, if the relevant algorithms are applied to perform graphics operations, the production efficiency of high-precision scenes can be greatly improved. In a robot simulation environment (such as reinforcement learning training, etc.), if the relevant algorithms are applied to perform physical simulation, the convergence speed of the model can be greatly improved and the time required for training can be reduced. Or while ensuring that the training time remains unchanged, the accuracy of the simulation environment is greatly improved, so that the trained model is more accurate and reliable.
Claims
1. The parallelized BVH minimum distance query algorithm based on CUDA is characterized by: A two-level task queue is constructed, CUDA thread blocks are used as batch processing units, and a hierarchical bounding box test tree is used to implement parallel search to query the shortest distance between two three-dimensional objects, including the following steps: Build a two-level task queue, including a global queue and a local queue; Before starting the search, all threads of the GPU are initialized in thread blocks. Thread 0 of each thread block first takes a node from the global queue and puts it at the top of the local queue, which is initialized as the root node of the current thread block. When searching, all threads in the same thread block read child nodes in batches from the local queue and perform concurrent searches. After the search is completed, the child nodes that need to be searched next time are added to the local queue in batches. After the thread block completes the search, the minimum distance of the bounding box of the hierarchy is obtained; All threads in the same thread block read child nodes in batches from the local queue and perform concurrent search, including the following steps: In each batch search, for the child nodes containing two hierarchical bounding boxes, the distance of the bounding box in the left child node and the distance of the bounding box in the right child node are calculated respectively; When the calculated distance of a child node is greater than or equal to the currently memorized minimum distance, the child node is directly skipped; otherwise, the child node with a closer distance is stored in the front of the local queue, and the child node with a farther distance is stored in the back of the local queue; In addition, if the child node is a leaf node, the distance between the graphics elements contained in the child node is directly calculated; if the calculated distance is less than the currently remembered minimum distance, the calculated distance replaces the currently remembered minimum distance to update the memory.
2. The CUDA-based parallel BVH minimum distance query algorithm according to claim 1, characterized in that: The construction of the two-level task queue is as follows: The first-level queue is a global queue, which is visible to all threads participating in the search. This queue is a first-in-first-out queue; The second-level queue is a local queue, that is, a thread block-specific queue. Each thread block instantiates a queue, which is visible to all threads in the current thread block. The queue adopts a double-ended design, in which the front end is a fixed-length buffer with the same length as the number of threads in the thread block; the back end is a first-in, last-out queue.
3. The CUDA-based parallel BVH minimum distance query algorithm according to claim 1, characterized in that: When storing in child nodes, a parallel prefix compression algorithm is used to format and store data without locks, and thread blocks are used to share memory.
4. The CUDA-based parallel BVH minimum distance query algorithm according to claim 1, characterized in that: When taking out child nodes, the thread block takes out all nodes in batches from the front end of the local queue first; when the number of child nodes in the front end of the local queue is less than the total number of threads in the thread block, the threads exceeding the length take out data from the back end.
5. The CUDA-based parallel BVH minimum distance query algorithm according to claim 1, characterized in that: The child nodes to be prioritized for parallelization are selected according to the judgment condition and added to the global queue; the judgment condition is any one of the following conditions: a. The number of layers the node is located in is less than 1 / M of the total number of layers of BVTT, 2≦M≦10; b. The distance between the closer child node and the farther child node is less than (1 / N) of the total volume of the bounding box. -1 / 3 , 5≦N≦20; c. The number of child nodes in the current global queue is not greater than the total number of thread blocks.
6. The CUDA-based parallel BVH minimum distance query algorithm according to claim 1, characterized in that: After the thread block completes the search, the minimum distance of the bounding box of the hierarchical volume is obtained, which includes the following steps: All thread blocks preferentially search the nodes in their own local queues; when a thread block completes the search of all child nodes in its own local queue and no longer adds new child nodes to the local queue, the thread block takes out a new child node from the global queue as the root node for the next round of search, and repeats the steps of batch reading child nodes from the local queue by all threads in the same thread block to perform concurrent search; When all thread blocks have completed the search and there are no nodes in the global queue, the algorithm exits and the currently memorized minimum distance is the global minimum distance, which is used as the minimum distance of the bounding box of the hierarchy.
7. A CUDA-based parallel BVH minimum distance query system, applied to the CUDA-based parallel BVH minimum distance query algorithm according to any one of claims 1 to 6, characterized in that: include: Task queue construction module, used to build two-level task queues, including global queues and local queues; The thread initialization module is used to initialize all threads of the GPU in thread blocks before starting the search. Thread No. 0 of each thread block first takes a node from the global queue and puts it at the top of the local queue, and initializes it as the root node of the current thread block. Batch search module, when used for searching, all threads in the same thread block read sub-nodes in batches from the local queue for concurrent search; after the search is completed, the sub-nodes to be searched next time are added to the local queue in batches; The BVH minimum distance acquisition module is used to obtain the minimum distance of the bounding box of the hierarchy after the thread block completes the search.
8. A parallel BVH minimum distance query device based on CUDA, characterized in that: It comprises a memory and a processor; the memory is used to store a computer program; the processor is used to implement the CUDA-based parallelized BVH minimum distance query algorithm as described in any one of claims 1 to 6 when executing the computer program.
9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by the processor, the CUDA-based parallelized BVH minimum distance query algorithm according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Method for quickly constructing bounding volume hierarchy (BVH) based on GPU
CN101819675A
Parallel acceleration method about class PLL shortest path distance query algorithm
CN108363723A
Hierarchical structure search method and device, computer equipment and storage medium
CN117331962A
Three-dimensional CAD model collision detection method based on BVH and quadratic sum planning
CN119129183A
Rigid body obstacle avoidance method based on three-dimensional discrete model distance calculation
CN119129376A