Interlayer independent balance tree parallel construction method

Through hierarchically independent parallel algorithms and thread-safe hash tables, the hierarchical dependence and ripple effect problems of the balanced tree construction process in fluid simulation are solved, and efficient balanced tree construction and performance improvement are achieved, suitable for N-balanced octaves. , quad-tree or binary tree construction makes full use of the large-scale parallelism provided by modern GPU architectures.

CN119004833APending Publication Date: 2024-11-22INST OF SOFTWARE - CHINESE ACAD OF SCI
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411145031.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-20
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

Performance bottlenecks caused by the balanced tree construction process on hierarchical dependence and ripple effects in existing fluid simulations, especially in the GPU architecture, where parallelism cannot be fully utilized, and the lack of thread-safe hash tables lead to poor performance in duplicate node deletion.

Method used

The N-balanced minimum spanning tree is constructed using a hierarchical-independent parallel algorithm, and the repetitive nodes are merged through a thread-safe hash table to eliminate hierarchical dependence and ripple effects, and achieve thread-safety and efficient construction of the equilibrium tree.

Benefits of technology

A balance tree construction framework that meets 2:1 balance constraints is realized, eliminating hierarchical dependence and ripple effects, improving GPU parallelism utilization, significantly improving performance, and computing overhead acceleration ratio is as high as 2 to 5 times.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119004833A_ABST
    Figure CN119004833A_ABST
Patent Text Reader

Abstract

The invention discloses an inter-layer independent balance tree parallel construction method, which comprises the following steps that: an N-balance minimum spanning tree is constructed for each node of the finest layer by adopting a layer-independent parallel algorithm, and the node of the finest layer at least comprises a seed node; combining all N-balanced minimum spanning trees into a single tree by using a thread-safe hash table to eliminate duplicate nodes representing nodes that are repeatedly created in the process of constructing a single tree structure; establishing a father-son relationship for all the intermediate nodes, and constructing all leaf nodes based on the intermediate nodes and the father-son relationship to complete the construction of the balance tree; wherein the intermediate node represents a node comprising at least one child node, and the leaf node represents a node not comprising any child node. According to the method, tree construction is eliminated, dependency of the refining process on layers is balanced, repeated internal nodes are prevented from being constructed, and the algorithm is completely compatible with the GPU.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of fluid simulation, and in particular relates to a method for parallel construction of independent balanced trees between layers. Background Art

[0002] The construction of balanced trees used in existing fluid simulations usually includes two stages. The first stage is to construct a tree without any constraints using a bottom-up or top-down approach. The second stage is to achieve 2:1 balance refinement, which involves subdividing nodes that do not satisfy the 2:1 balance constraint until they satisfy the 2:1 balance constraint.

[0003] However, the 2:1 balanced refinement process is dependent on the hierarchy, that is, in order to meet the 2:1 balance constraint, leaf nodes may need to be subdivided multiple times, and the subdivision needs to be completed layer by layer from coarse resolution to fine resolution; secondly, the 2:1 balanced refinement also has a ripple effect, that is, the subdivision of leaf nodes will trigger a series of subdivisions, and nodes that are not direct neighbors need to be refined. The dependency on the hierarchy and the ripple effect make it impossible to fully utilize the massive parallelism provided by modern GPU architectures. In addition, since GPU hardware lacks a thread-safe hash table, deleting duplicate nodes generated across different GPU threads requires multiple sorting and deletion operations, which will significantly affect the overall performance. Summary of the invention

[0004] To solve the above technical problems, the present invention provides a method for parallel construction of balanced trees with independent layers, which eliminates the dependence of the balanced tree construction process on the hierarchy and the iterative process caused by the ripple effect, balances the workload between GPU threads, and implements a thread-safe hash table to effectively eliminate duplicate nodes.

[0005] To achieve the above purpose, the technical solution adopted by the present invention is as follows: A method for parallel construction of independent balanced trees between layers, the method comprising the following steps: Step 1: Use a level-independent parallel algorithm to construct an N-balanced minimum spanning tree for each node in the finest layer, where the nodes in the finest layer contain at least one seed node; Step 2, using a thread-safe hash table to merge all N-balanced minimum spanning trees into a single tree to eliminate duplicate nodes, where the duplicate nodes represent nodes that are repeatedly created in the process of building a single tree structure; Step 3: Establish parent-child relationships for all intermediate nodes, construct all leaf nodes based on the intermediate nodes and the parent-child relationships, and complete the balanced tree construction; wherein the intermediate node represents a node including at least one child node, and the leaf node represents a node that does not include any child node.

[0006] Furthermore, the use of a level-independent parallel algorithm to construct an N-balanced minimum spanning tree in step 1 includes the following principles: If you want to refine the leaf nodes, follow , or In each direction of the axis, only the neighbors that are not its sibling nodes, i.e., the off-branch neighbors, need to check the 2:1 balance condition; At the level Refining a leaf node above will not trigger refinement of leaf nodes at or below that level; When a leaf node is refined, along , or Each higher level in each direction of the axis needs to refine at most one leaf node.

[0007] Furthermore, the step 2 comprises: Initialize the hash table; The input value is mapped to the array index using the division and remainder method, and a thread-safe marker is used to indicate whether the index position is occupied. If the index position is not occupied, the input value is stored in the index position. If the index position is occupied, a non-zero value is returned to prompt checking whether the non-zero value has been stored. If the non-zero value exists, it is no longer stored; continue to check the next index position.

[0008] Furthermore, the step 3 comprises: Step 3.1, establish parent-child relationships for all intermediate nodes; Step 3.2, complete the construction by generating all leaf nodes.

[0009] Further, the step 3.1 includes: using Represents two nodes and The length of the longest common prefix between the corresponding Morton codes is related to the level. For any two consecutive nodes, the nodes are determined according to the following two situations The parent node of: (1), Indicates the node The parent node is the root node; (2), When using As a lower bound, perform a binary search to find the node , then the node The index of the parent node is ,in Representation Node The level at which Representation Node The level you are at.

[0010] Further, the step 3.2 includes: allocating a Multiply the new space by the number of intermediate nodes, and then assign a thread to each intermediate node to generate its child nodes, where dim represents the spatial dimension.

[0011] The beneficial effects of the present invention are: The present invention constructs a new balanced tree framework that satisfies the 2:1 balance constraint, and the framework can be applied to the construction of N-balanced octrees, quadtrees or binary trees; proposes a level-independent N-balanced minimum spanning tree parallel construction algorithm to eliminate the tree construction and balance refinement process's dependence on the level; implements a thread-safe hash table to avoid the construction of repeated internal nodes, so that the algorithm is fully compatible with GPU implementation to fully utilize the large-scale parallelism provided by modern GPU architecture. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] Figure 1 Schematic diagram of the structure of a two-dimensional 1-balanced minimum spanning tree based on node o, wherein (a) is a schematic diagram of the spatial grid representation of the two-dimensional 1-balanced minimum spanning tree based on node o, (b) is a schematic diagram of the post-order traversal of the two-dimensional 1-balanced minimum spanning tree based on node o, and (c) is a schematic diagram of the storage representation of the two-dimensional 1-balanced minimum spanning tree based on node o in the GPU; Figure 2 It is a schematic diagram of the 0-balanced minimum spanning tree structure of a binary tree; Figure 3 An example diagram for a thread-safe hash table; Figure 4 This is a pseudo code diagram of a thread-safe hash table; Figure 5 Schematic diagram of constructing an N-balanced tree structure based on sorted intermediate nodes, where (a) is a schematic diagram of the level-dependent longest common prefix between intermediate nodes, and (b) is a schematic diagram of the process of constructing child nodes for each intermediate node; Figure 6 A comparison chart of the computational overhead of the present invention and the prior art; Figure 7 This is the effect diagram of multi-fluid coupling simulation using a 2-balanced octree. DETAILED DESCRIPTION

[0013] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.

[0014] The present invention provides a method for parallel construction of independent balanced trees between layers. -The definition of a balanced minimum spanning tree makes it easy to determine if any two -The union of the balanced minimum spanning tree also meets the balance condition. Applying this principle, construct -The method of balancing the tree can be divided into two steps: Step 1, use a level-independent parallel algorithm to build a -Balanced minimum spanning tree, where the nodes at the finest level contain at least one seed point; Step 2, use a thread-safe hash table to store all -Merge the balanced minimum spanning trees into a single tree to eliminate duplicate nodes. In the actual implementation, the two-stage process is interleaved to speed up the construction of the complete tree. Specifically, the method involves stopping the generation of additional nodes when the current node has already been generated by another GPU thread. Although all - The concept of merging balanced minimum spanning trees into a single tree can pose performance challenges, especially due to potential conflicts caused by duplicate nodes. However, the present invention effectively alleviates this problem by using a level-independent parallel algorithm, which enables dynamic node generation (no need to store nodes during construction). -balanced minimum spanning tree), while carefully designing thread-safe hash tables to minimize conflicts.

[0015] The specific implementation process of each step is introduced below.

[0016] There are two commonly used methods for representing trees in the prior art: pointer-based representation decomposes the domain of interest into a set of unordered nodes and uses pointers to establish parent-child relationships; linear-based representation assigns a unique key to each node and represents the tree as a set of ordered leaf nodes. In the present invention, a combination of pointer and linear representation is used, such as Figure 1 As shown in (c) in the figure, it consists of two parts: the first part, Uniform, stores the ordered set of nodes at the top level, representing a uniform grid; the second part, Adaptive, stores their child nodes, which are arranged in descending order according to the position key, representing the adaptive grid below the top level. In addition, the tree has the following properties: (1) All child nodes of the same parent node are stored consecutively, so only the index of the first child node needs to be stored in the parent node. This property simplifies tree traversal and node access; (2) Using Morton encoding, the tree maintains good data locality for nodes that are close in space.

[0017] To satisfy the above properties, Morton coding is used to interleave the bits of different coordinate components, and then the hierarchical information is attached. Assume that the maximum level of the tree is , at the level has integer coordinates on The node position code is encoded as follows: , in, For binary representation, subscript Represents the binary Position, front The standard Morton code , the middle The last bit is the padding bit. bits represent the hierarchical information. This encoding scheme allows the construction of octrees with a maximum depth of 9 on 32-bit systems and a maximum depth of 19 on 64-bit systems. Given a position code , the Morton code can be easily derived: , in, is the bitwise right shift operator.

[0018] Specifically, Step 1: Use a level-independent parallel algorithm to build a - A balanced minimum spanning tree, where the nodes at the finest level contain at least one seed point; For a given node, construct the corresponding -Balancing the minimum spanning tree is equivalent to finding all the intermediate nodes, such as Figure 1 As shown in (b) in the figure, to construct a two-dimensional 1-balanced minimum spanning tree based on node o, we only need to find all the intermediate nodes (such as Figure 1 The dark-marked nodes in (b) are the intermediate nodes. Figure 1 As shown in (a) of , the internal nodes must satisfy the 2:1 balance constraint. This process needs to deal with the ripple effect, that is, the split of one node will cause the split of another node, even if the other node is not in the immediate neighborhood of the node. Figure 2 The binary tree shown in is used as an example. If we further refine the leaf nodes , then the node is triggered and At the same time, split to maintain the 2:1 balance condition. Therefore, a straightforward implementation method for finding nodes that need to be split is to recursively identify neighbors that do not meet the balance condition. Unfortunately, the recursive implementation will trigger execution divergence in the GPU implementation, which will severely degrade performance.

[0019] In order to solve the above problems, we need to pay attention to several - Principles for leaf node refinement in balanced minimum spanning tree construction: (1) If you want to refine the leaf nodes, along each direction ( , or axis), only the neighbors that are not its sibling nodes, i.e., the off-branch neighbors, need to check the 2:1 balance condition; (2) At the level Refining a leaf node above will not trigger refinement of leaf nodes at or below that level; (3) When a leaf node is refined, at most one leaf node needs to be refined at each higher level in each direction.

[0020] by Figure 2 In -Balanced binary tree as an example. When thinning leaf nodes The first principle states that there is no need to check leaf nodes and The 2:1 balance condition between the nodes is automatically satisfied. Therefore, only the neighbors on the other side need to be checked. In this scenario, since the balance condition is violated, the node Need to be refined. The second principle means that for nodes The refinement of cannot introduce violations of leaf nodes at the same level, which also confirms the third principle, that is, at most one leaf node is refined in each direction at each level at a higher level.

[0021] Step 2: Use a thread-safe hash table to store all - Balanced minimum spanning trees are merged into a single tree to eliminate duplicate nodes; To remove duplicate elements on the GPU, the usual approach is to sort all elements by value and then remove duplicate elements by checking the values ​​of adjacent elements. -The balanced minimum spanning tree is stored in a large array and sorted by value, which will quickly become the efficiency bottleneck of the algorithm due to the large number of repeated nodes. Therefore, the present invention proposes a thread-safe hash table that only stores different Morton codes of generated nodes, with the aim of reducing the number of nodes used for sorting. It should be noted that instead of creating a flexible hash table like that on the CPU, a compromise is made between memory overhead and computational overhead. The basic components of a hash table implementation include hash functions, hash conflicts, and dynamic resizing. Since GPUs do not support dynamic resizing, the solution of the present invention is to allocate a sufficiently large continuous space to reduce hash conflicts. Assuming the array size is , where the remainder division method is used to map the input value to the array index: , Where H(·) represents a hash function, k represents an input value, p represents a prime number, and % represents a modulo operation. When a conflict occurs, an open addressing method with linear probing is used. Figure 3 As shown, if the index The corresponding space is occupied, the index will be checked The corresponding space is filled and the process continues until an empty position is found. If the last position is reached, the index wraps around to the beginning of the array.

[0022] The main concern of GPU implementation of hash table is how to solve the thread conflict problem caused by different threads accessing the same index at the same time. The key is to use thread-safe markers to indicate whether the index is occupied. According to the definition of hash function, the encoding of the root node is ignored, that is, valid nodes can be indexed from 1. Therefore, the position code with a value of 0 can be used as a marker to indicate an empty index. According to this convention, the hash table is first initialized with 0. When the index position is detected and stored, the application Figure 4 The algorithm shown in Figure 1 shows the atomic operation in line 2. This protects the integrity of read and write operations performed on the hash table. If the index position is already occupied, A non-zero value is returned, prompting a check to see if the value has already been stored (line 3). If the value exists, it should not be stored again (line 4); otherwise, continue checking the next index position (line 6). The atomic operation in line 2 also prevents two threads from accessing the same index position at the same time, ensuring data consistency.

[0023] Step 3: Build a complete tree, that is, a complete balanced tree.

[0024] The following process of constructing the complete tree is straightforward and consists of two steps. In step 3.1, parent-child relationships are established for all intermediate nodes. Then, in step 3.2, the construction is completed by generating all leaf nodes.

[0025] Step 3.1, establish the parent-child relationship between the intermediate nodes; First, sort all the intermediate nodes in descending order to get a compact array, which can also be regarded as a post-order traversal of the tree composed of internal nodes. Figure 5 (a) shows Figure 1 An example of an ordered array of quadtree intermediate nodes shown in (b) in Represents two nodes and The length of the longest common prefix between the corresponding Morton codes. Here, "level-related" means that all bits on the same level are regarded as a unit. For example, the longest common prefix between the second node 2 and the third node 3 is (100), and the longest common prefix between the levels is (10). For any two consecutive nodes, The value of the node can be determined according to the following two situations The parent node of: First, : This indicates that the node is a child of the root node. For example, Figure 5 The first node 1, the fifth node 5, and the seventh node 7 in the example belong to this situation. Since no root node is explicitly created, Figure 5 (b) in Figure 1 uses dashed lines to represent parent-child relationships, meaning that they should not actually be generated.

[0026] second, :use As a lower bound to perform a binary search, search for the node .node Is a node Ancestor of node The index of the parent node is ,in Is a node The level at which Is a node The level you are at. For example Figure 5 (b) for the node have , continue searching to get Finally, through calculation, it is found that the parent node of the third node 3 is the fourth node 4.

[0027] Step 3.2, generate missing leaf nodes; Finally, continue to build the complete tree from the internal nodes. Assign a Multiply the new space by the number of intermediate nodes, and then assign a thread to each intermediate node to generate its child nodes, dim represents the spatial dimension, i.e. dim=1 in one dimension, dim=2 in two dimensions, and dim=3 in three dimensions. The middle node of the index, its child nodes are stored in descending order from The position where the index starts. For example, in Figure 5 In the quadtree in (b), the first node 1 generates its four child nodes and stored starting from the fourth index. Note that a thread should also be assigned to the root node to generate all its child nodes. Since the intermediate nodes are already sorted in descending order, the new node array will also be sorted in descending order. Using the parent-child relationship stored in the intermediate node array, it is easy to establish the parent-child relationship for the nodes in the new array. For example, Figure 5 The second node 2 in (b) generates four child nodes , its parent node (the fifth node 5) generates four child nodes , among the children of the fifth node 5, there must be a match with the Morton code of the second node 2, and only the index of its first child node needs to be updated to the node After updating the first child index of all nodes in the array, the complete -Balanced tree.

[0028] Compared with the existing methods, the method proposed in the present invention is fully compatible with GPU and shows a speedup ratio of up to 2 to 5 times in different scenarios. Figure 6 As shown in the figure, the computational efficiency of the method of the present invention and the method in the prior art is compared. Data statistics are performed using a computer with the same experimental specifications, which is equipped with a 6-core Intel i7-8700 CPU and an NVIDIA GeForce RTX 2060 GPU with 1920 CUDA cores and 6 GB memory. The Stanford rabbit model is constructed using the two methods of the present invention and the prior art. -Balanced octree representation. For the maximum level , the minimum level is set to This means that for , the number of layers constructed is , resulting in approximately 400,000 leaf nodes. Similarly, for , the number of layers constructed is , resulting in approximately 900,000 leaf nodes. Figure 6 The results shown clearly show that the algorithm proposed in the present invention has significantly superior efficiency compared with the prior art methods. The speed achieved by the method of the present invention is 5.07 times and 2.23 times faster than that of the prior art method, respectively.

[0029] The present invention can be easily adapted to fluid simulations to handle dynamically moving boundaries. Figure 7 In the hourglass scenario shown, -Balanced octree for multi-fluid coupling simulation, the mixture of water and sand is modeled as an incompressible Newtonian fluid. -The movement of water is solved in the balanced octree, while the movement of sand is handled in particles. By capturing the states of water and sand at different times, we can see -The balanced octree grid is dynamically updated as the sand flows, and the efficient algorithm of the present invention undoubtedly provides strong support for this process.

[0030] The specific embodiments described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for parallel construction of independent balanced trees between layers, characterized in that: The method comprises the following steps: Step 1: Use a level-independent parallel algorithm to construct an N-balanced minimum spanning tree for each node in the finest layer, where the nodes in the finest layer contain at least one seed node; Step 2, using a thread-safe hash table to merge all N-balanced minimum spanning trees into a single tree to eliminate duplicate nodes, where the duplicate nodes represent nodes that are repeatedly created in the process of building a single tree structure; Step 3: Establish parent-child relationships for all intermediate nodes, construct all leaf nodes based on the intermediate nodes and the parent-child relationships, and complete the balanced tree construction; wherein the intermediate node represents a node including at least one child node, and the leaf node represents a node that does not include any child node.

2. The method for parallel construction of independent balanced trees between layers according to claim 1, characterized in that: The step 1 uses a level-independent parallel algorithm to construct an N-balanced minimum spanning tree, including the following principles: If you want to refine the leaf nodes, follow , or In each direction of the axis, only the neighbors that are not its sibling nodes, i.e., the off-branch neighbors, need to check the 2:1 balance condition; At the level Refining a leaf node above will not trigger refinement of leaf nodes at or below that level; When a leaf node is refined, along , or Each higher level in each direction of the axis needs to refine at most one leaf node.

3. The method for parallel construction of independent balanced trees between layers according to claim 1, characterized in that: The step 2 comprises: Initialize the hash table; The input value is mapped to the array index using the division and remainder method, and a thread-safe marker is used to indicate whether the index position is occupied. If the index position is not occupied, the input value is stored in the index position. If the index position is occupied, a non-zero value is returned to prompt checking whether the non-zero value has been stored. If the non-zero value exists, it is no longer stored; continue to check the next index position.

4. The method for parallel construction of independent balanced trees between layers according to claim 1, characterized in that: The step 3 comprises: Step 3.1, establish parent-child relationships for all intermediate nodes; Step 3.2, complete the construction by generating all leaf nodes.

5. The method for parallel construction of independent balanced trees between layers according to claim 4, characterized in that: The step 3.1 includes: using Represents two nodes and The length of the longest common prefix between the corresponding Morton codes is related to the level. For any two consecutive nodes, the nodes are determined according to the following two situations The parent node of: (1), Indicates the node The parent node is the root node; (2), When using As a lower bound, perform a binary search to find the node , then the node The index of the parent node is ,in Representation Node The level at which Representation Node The level you are at.

6. The method for parallel construction of independent balanced trees between layers according to claim 4, characterized in that: The step 3.2 includes: allocating a Multiply the new space by the number of intermediate nodes, and then assign a thread to each intermediate node to generate its child nodes, where dim represents the spatial dimension.