-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STL optimization: Bounding volume hierarchy #4140
Conversation
Speed up EB geometry generation with STL by using the bounding volume hierarchy (BVH) method. The BVH tree is stored in a contiguous chunk of memory making it easier for GPUs. Using a fixed size stack, recursion is avoided when traversing the tree.
It is also possible to build the BVH from the bottom and upwards using space-filling curves. This leads to a worse tree, but construction is much faster and without recursion. Would you like some timing results to see if you want to support both construction methods? |
Yes, it would be great if you can share your timing results. For the max number of children of the tree, 2 would be too small because the stack (needed for every GPU threads) would need to quite big. So I use 4. What's your experience of how that affects performance in CPU code? |
Ok, I've tested on an STL with 1.2 million triangles on the Adirondack STL (https://github.com/rmrsk/EBGeometry/tree/main/Examples/Resources) Timing results on a single CPU showed that bottom-up construction took about 60% of the time of the top-down construction. Bottom-up construction works by doing a single sort using an SFC index as comparator, as opposed to top-down construction which is sorted each time a leaf node is split. The performance difference decreases as the mesh size decreases (probably due to sorting of triangles which becomes gradually cheaper). We have yet to hit a case where bottom-up construction is better, but we don't do moving geometries so there's that... We generally use factor 4 branching ratios for the trees, with factor 2 being only slightly slower. |
The performance seems to be very good. For big STL files, the new version is 100x faster on CPU and 10x faster on GPU. The GPU kernel for BVH has thread divergence issue. That's probably why the performance gap between CPU and GPU has shrunk with the new version.
|
I repeated the test on my desktop with a less powerful GPU. Here are the results.
|
@WeiqunZhang Do you have the BVH build times? |
|
Speed up EB geometry generation with STL by using the bounding volume hierarchy (BVH) method. The BVH tree is stored in a contiguous chunk of memory making it easier for GPUs. Using a fixed size stack, recursion is avoided when traversing the tree.
X-Ref: https://rmrsk.github.io/EBGeometry/Concepts.html#bounding-volume-hierarchies