Skip to content
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

parallelize mesh fixup #1148

Merged
merged 12 commits into from
Feb 21, 2025
Merged

parallelize mesh fixup #1148

merged 12 commits into from
Feb 21, 2025

Conversation

pca006132
Copy link
Collaborator

  • SplitPinchedVerts now runs in parallel.
  • Edge deduplication now avoids sorting, so it is much faster now.

Previously:

nTri = 512, time = 0.00387912 sec
nTri = 2048, time = 0.00780949 sec
nTri = 8192, time = 0.00926127 sec
nTri = 32768, time = 0.0170758 sec
nTri = 131072, time = 0.0393845 sec
nTri = 524288, time = 0.135483 sec
nTri = 2097152, time = 0.499138 sec
nTri = 8388608, time = 2.12073 sec

Now:

nTri = 512, time = 0.00200502 sec
nTri = 2048, time = 0.0026148 sec
nTri = 8192, time = 0.020302 sec
nTri = 32768, time = 0.0357589 sec
nTri = 131072, time = 0.0326722 sec
nTri = 524288, time = 0.116826 sec
nTri = 2097152, time = 0.445966 sec
nTri = 8388608, time = 1.86558 sec

About 10% improvement for larger meshes.

@pca006132 pca006132 requested a review from elalish February 19, 2025 06:31
Copy link

codecov bot commented Feb 19, 2025

Codecov Report

Attention: Patch coverage is 98.18182% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.70%. Comparing base (c16b521) to head (0369548).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/edge_op.cpp 97.77% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1148      +/-   ##
==========================================
+ Coverage   91.68%   91.70%   +0.01%     
==========================================
  Files          30       30              
  Lines        5951     5964      +13     
==========================================
+ Hits         5456     5469      +13     
  Misses        495      495              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -223,14 +223,17 @@ void Manifold::Impl::CreateFaces() {
stable_sort(triPriority.begin(), triPriority.end(),
[](auto a, auto b) { return a.area2 > b.area2; });

Vec<int> interiorHalfedges;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It turns out the reallocation is quite significant. I wish the profiler can just give warning when there are many allocator calls within a certain period of time...

@pca006132
Copy link
Collaborator Author

will try to figure out wtf is gcc complaining about later...

src/edge_op.cpp Outdated
auto expected = std::numeric_limits<size_t>::max();
if (!reinterpret_cast<std::atomic<size_t>*>(largestEdge.data() +
vert)
->compare_exchange_strong(expected, largest) &&
Copy link
Owner

Choose a reason for hiding this comment

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

You can just reinterpret a random vector element as an atomic? I guess I'm used to the atomic free functions of CUDA - is this a more idiomatic approach?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is not really idiomatic, but it should work. I need to think about the best way to do this.

src/edge_op.cpp Outdated
} else {
endVerts.push_back(halfedge_[current].endVert);
// switch to hashset for vertices with many neighbors
if (endVerts.size() > 32) {
Copy link
Owner

Choose a reason for hiding this comment

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

6 is normal - 10 is already pretty rare. Still, I suppose it's really a perf cross-over.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this is just some random integer that I think should work.

@@ -204,66 +206,94 @@ void Manifold::Impl::CleanupTopology() {
// verts. They must be removed before edge collapse.
SplitPinchedVerts();

Vec<int> entries;
FlagStore s;
Copy link
Owner

Choose a reason for hiding this comment

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

With your algorithm update, does it still need the while loop? I didn't love having to add that - felt like a cop-out to my algorithm not doing a good enough first pass.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The algorithm is nearly the same as the old one, just parallelized, so I think the loop is still needed.

Copy link
Owner

@elalish elalish left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@pca006132 pca006132 merged commit f178cd1 into master Feb 21, 2025
27 checks passed
@pca006132 pca006132 deleted the faster-fixup branch February 21, 2025 00:21
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.

2 participants