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

[Web] Add flag to enable SIMD instructions in WASM #1376

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Skylion007
Copy link
Contributor

@Skylion007 Skylion007 commented Jul 8, 2021

Motivation and Context

  • Adds a flag that can enable building the Web build of Habitat to use SIMD. This should speed up physics and other linalg heavy vectorization hopefully quite significantly. The browser must support SIMD in WASM like modern versions of Chrome though.
  • To enable pass the --simd flag to build_js.sh
  • Also fixes a small bug with pre-commit that prevented shell check from running on build.sh and build_js.sh .

How Has This Been Tested

  • Locally and with CI.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • New feature (non-breaking change which adds functionality)

Checklist

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jul 8, 2021
@mosra
Copy link
Collaborator

mosra commented Jul 8, 2021

quite significantly

(With my skeptical hat on.) Do you have some numbers to back this? I'm interested in how much this helps in a codebase of this size.

@Skylion007
Copy link
Contributor Author

Skylion007 commented Jul 8, 2021

@mosra Probably not on Magnum, but WASM doesn't even enable SSE2 instructions without this flag for Bullet so it should give a speed up there.

Regardless, point taken retracting my claim slightly.

@Skylion007 Skylion007 requested a review from mosra July 8, 2021 18:11
@mosra
Copy link
Collaborator

mosra commented Jul 8, 2021

It's not as simple as "enabling SSE2" since WASM has to work on ARM as well -- and that's why I'm skeptical, because different platforms have different instructions and what could directly map to a SSE instruction might have to be emulated on NEON and vice versa.

But in any case I really want to know how this helps, seriously :) Did you try it out? I know from certain projects that hand-coded WASM SIMD can be four to six times times faster than scalar code, but have no idea about autovectorization, especially when combined with everything else we're running here. Is it 1%? 10%? 2x faster?

Copy link
Contributor

@eundersander eundersander left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for doing this! I'm also curious to evaluate the speedup. @ldcWV It would be cool to try this with your upcoming JS physics benchmark.

@@ -4,12 +4,14 @@
set -e

BULLET=false
USE_SIMD=false
Copy link
Contributor

Choose a reason for hiding this comment

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

Some documentation would be nice; even just linking back to this PR.

@ldcWV
Copy link
Contributor

ldcWV commented Jul 15, 2021

I tried this on my webxr hand demo benchmark, which drops a lot of objects in a big pile and tries to step physics 60 times per second (or 16.7 ms per stepWorld() call). I repeated the benchmark 3 times with and without the --simd flag and here were the results:

without --simd:
78.76ms
72.60ms
82.87ms

with --simd:
79.75ms
84.07ms
83.48ms

These numbers are the average ms between stepWorld() calls. Note that it's trying to achieve 16.67ms per stepWorld() call but cannot keep up. So it doesn't seem like this SIMD optimization has helped much in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants