Skip to content

Bump CGAL → Boolean + remesh_*intersections performance boost#1895

Merged
alecjacobson merged 23 commits intomainfrom
parallel-cgal
Apr 1, 2022
Merged

Bump CGAL → Boolean + remesh_*intersections performance boost#1895
alecjacobson merged 23 commits intomainfrom
parallel-cgal

Conversation

@alecjacobson
Copy link
Copy Markdown
Contributor

@alecjacobson alecjacobson commented Sep 20, 2021

  1. Bumps the CGAL to v5.4
  2. adds a bunch of parallel_fors to CGAL routines
  3. relaxes floating-point rounding in assign_scalar
  4. removes some (but not all) of the vector<vector<vector... types used in edge-adjacency navigation

Before getting too excited, there are a couple good reasons why we should wait to merge this:

  • the CGAL version is not an official release yet. They're pretty regular and this change looks stable. So, we might just wait for when it's in a release.
  • @qnzhou and I would like to rerun the Thingi10k gauntlet on the Boolean code to be sure these changes don't break anything
  • using this branch for a while in some other projects will flesh out missing templates

1.

The downside to this bump is that the auto-generated template prototypes for CGAL::Epeck related things seems to have changed which means this PR has deleted all the old /cgal template instantiations. This PR should contain the (non Windows specific) template instantiations needed by the tutorial and tests.

2.

CGAL/cgal#5402 recently fixed the thread safety issues with the CGAL::Epeck::FT type. This immediately enables a lot of opportunities for parallelism in the mesh_boolean and remesh_intersection routines. Previously, due to reference counting, even read operations were not threadsafe, so we had some extreme std::mutex usage and barely any benefit of parallelism.

For example, on my 56-core macpro I'm seeing:

  • ~14x speed up for remesh_self_intersections
  • ~7x speed up for mesh_boolean

3.

While profiling and improving the performance of these routines, I've fixed other bottlenecks. Most notably, the assign related conversions to and from CGAL's exact type are quite costly. We previously used a rounding from float→rational, which could be best thought of as "round to nearest float" in the absolute sense. After some tests (not exhaustive yet; see above), I'm coming to the conclusion this is overkill and using CGAL::to_double( .exact() ) is a safe and faster alternative (vaguely think of as "arbitrarily round down/up"). (see also CGAL/cgal#6000)

4.

Unrelated to CGAL, the mesh_boolean code uses many vector<vector<vector<... type lists of lists. We've been previously trying to encourage use of the uEC and uEE serialized arrays for edge-to-half-edge equivalence. This makes that change in relevant places related to mesh_booleaning. There are still a number of vector<vector<vector<..., notably in triangle_triangle_adjacency that are an eyesore (thought nowhere near the bottleneck of mesh_boolean.

other.

Various other clean up, documentation, function splittings, templates, etc. made along the way.

@alecjacobson alecjacobson requested a review from qnzhou September 20, 2021 03:44
@jdumas
Copy link
Copy Markdown
Collaborator

jdumas commented Sep 20, 2021

Cool! I suspect there will be some incompatibilities with #1413 (which has been under review since forever), and #1805 (for the cgal::assign file). Would be great to get those sorted first.

@alecjacobson
Copy link
Copy Markdown
Contributor Author

Great points, Jeremie! I believe this should be compatible with #1413 , when @qnzhou and I do the test, we should start with that one, then re-run this PR.

Re our favorite #1805 , Daniele and I discussed a strategy for moving ahead this morning. We'll be in touch shortly. In terms of compatibility, I hope this PR is just bumping the commit hash, so easy merge but should be tested of course.

@alecjacobson
Copy link
Copy Markdown
Contributor Author

Update:

CGAL v5.4 has been officially released.

I've re-run the PWN subset of Thingi10k "self-union" stress test for the booleans. So far, 8595 out of 8621 have finished (a few take 10+ hours 🤯 ). All looks good in the sense of exactly matching rational output of the previous code. I'm content declaring success here (I'll try to squeeze out the last few models).

I'd also like to test the success rate of the float conversion. This was never guaranteed and the heuristic we used in the paper was never implemented fully in C++ anyway. In any case, I'd like to get a sense of whether we significantly more often get poor snap rounding results with the new code.

@alecjacobson
Copy link
Copy Markdown
Contributor Author

alecjacobson commented Mar 31, 2022

I'm nearly ready to declare success on this. I've run self-unions all 8620 valid PWN models from thingi10k. The new code produces exact (as in CGAL::Epeck) results that are the same (w.r.t. exactly equivalent triangles).

The new code also introduces new, faster rounding. Of these 8620 exact outputs, I first detect any self-intersections in the exact representations. After the #2019 fix, the new and old code agree there are no intersections. Then I convert to double (via assign) and check for intersections. Here we expect that some models have intersections. We could be worried that the new code has significantly more intersections after rounding to double. This is happily not the case. There are 109 (edit: still computing these, there may be a few more coming) out of 8620 models which produce intersections-after-rounding in either the new or old code. Of those, 29% have no intersections in the old code but ≥1 intersections in the new code. Conversely, 18% have no intersections in the new code but ≥1 intersections in the old code. In this sense, the old code is better, but I think it's roughly random. For 50% of the 109, the new code has more intersections than the old code. Putting in the larger context of the 8620 models, this means for only 0.006% would the new code output more intersections-after-rounding than the old code. And similarly, the old code would only 0.006% of the time output more intersections-after-rounding than the new code. My conclusion is that it's a wash and we should take the newer, simpler, faster rounding (the old code is still there behind a flag).

@alecjacobson
Copy link
Copy Markdown
Contributor Author

I've put my scripts for the batch jobs at https://github.com/alecjacobson/thingi10k-bool-test , we can also use this test and merge #1413.

Copy link
Copy Markdown
Collaborator

@qnzhou qnzhou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@alecjacobson alecjacobson merged commit 4498aa8 into main Apr 1, 2022
@alecjacobson alecjacobson deleted the parallel-cgal branch April 1, 2022 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants