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

Enable emscripten build with parallelization #1045

Merged
merged 2 commits into from
Nov 27, 2024
Merged

Conversation

pca006132
Copy link
Collaborator

@pca006132 pca006132 commented Nov 15, 2024

  1. Enabled parallelization when building with emscripten. It turns out we have to warm up the tbb workers in our tests, according to https://github.com/oneapi-src/oneTBB/blob/master/WASM_Support.md#limitations.
  2. Fix nix build. The nixpkg upstream PR is still not updated, so I wrote an overlay to build binaryen instead. Because it can take a while in the CI, I enabled a workflow cache.

Note that the parallel build is still experimental, it seems that things can be a bit finicky and I had to increase the stack size. The build is also a bit finicky, I got errors running "Gyroid module" with npm/browser, will debug that a bit later... But overall the thing works in nodejs and browser.

@pca006132
Copy link
Collaborator Author

Looking at the emscripten bug reports, I feel like the issue we got with gyroid module may be something related to the older version of emscripten that nix currently uses. Maybe building with the latest version will make things work.

@pca006132
Copy link
Collaborator Author

@elalish indeed the gyroid module issue is just due to parallelization being enabled for level set.

@pca006132
Copy link
Collaborator Author

test_manifold is still a bit finicky, disabling test for now so to not block the CI.

@elalish
Copy link
Owner

elalish commented Nov 15, 2024

test_manifold is still a bit finicky, disabling test for now so to not block the CI.

Mind putting this comment on the line of that change that disabled the test? I'm having trouble finding it, and seems like a good one to keep an eye on when we're getting ready to merge this.

How much performance improvement do you see on our npm tests?

flake.nix Outdated
manifold-tbb = manifold { };
manifold-none = manifold { parallel = false; };
manifold-js = manifold-emscripten { parallel = false; };
# disable check for now
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 one with doCheck = false disables the test for nix.

@pca006132
Copy link
Collaborator Author

For timing improvement, overall it is not huge, 11805ms to 9484ms. But for individual tests, I think I saw 2x speedup or something, so this really depends on the specific test. Do note that I limited the number of pthread worker to 4.

@pca006132
Copy link
Collaborator Author

@elalish I rewrote the nix CI to pack everything into one single action with multiple variants.

@elalish
Copy link
Owner

elalish commented Nov 16, 2024

This is looking great - okay if we delay merging this to after v3.0?

@pca006132
Copy link
Collaborator Author

sure

@pca006132 pca006132 mentioned this pull request Nov 16, 2024
pca006132 added a commit to pca006132/manifold that referenced this pull request Nov 17, 2024
elalish added a commit that referenced this pull request Nov 17, 2024
* enable emscripten build with tbb enabled

* nix: fix emscripten build, add tbb build

* browser

* fix python build

* minor

* no parallel sdf for js

* disable test for emscripten-tbb

* add cache for nix python build

* cmake changes

* fix

* update

* update

* update

* update

* move python dependency handling

* more changes

* format

* fix broken format

* fix

* simplify

* allow emscripten with cbind

* build fetched dependencies as static libs

* fix static build

* fix rebuild

* fix extras

* remove parallel.h from public API

* update tests

* make dependencies private

* move parallel.h

* missing utils.h change

* fix

* fix...

* fix wasm tbb

* add more cmake consumer tests

* fix consumer

* add rpath

* Revert "add rpath"

This reverts commit 2e8a96c.

* rpath specific to macos

* use override

* forgot to set rpath...

* remove #1045 related changes

* integrate #1052

* allow version override

* minor improvements

* msvc changes

* fix typo

---------

Co-authored-by: Emmett Lalish <[email protected]>
@pca006132
Copy link
Collaborator Author

@elalish It seems to work reliably now, but IDK why. Maybe some linker flags were not actually applied previously, but are now applied correctly?

Copy link

codecov bot commented Nov 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.72%. Comparing base (3ea3e7e) to head (25e93f4).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1045   +/-   ##
=======================================
  Coverage   91.72%   91.72%           
=======================================
  Files          30       30           
  Lines        5910     5910           
=======================================
  Hits         5421     5421           
  Misses        489      489           

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

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.

How much speedup do you see coming out of this now?

'var workerOptions={type:"module",workerData:"em-pthread",name:"em-pthread"};', ""
)
data = data.replace(
"workerOptions", '{type:"module",workerData:"em-pthread",name:"em-pthread"}'
Copy link
Owner

Choose a reason for hiding this comment

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

What is this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

emscripten generating some non-static worker options that Vite cannot handle, and it can be trivially modified to become static.

@pca006132
Copy link
Collaborator Author

pca006132 commented Nov 27, 2024

How much speedup do you see coming out of this now?

Overall for the c++ test, 4x, probably more for some individual benchmark. For npm test, roughly 11s to 8s, 4x faster in some benchmark.

@pca006132 pca006132 merged commit f8c9dc9 into master Nov 27, 2024
24 checks passed
@pca006132 pca006132 deleted the emscripten-tbb branch November 27, 2024 16:41
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