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] Initial support for asyncify #16694

Merged
merged 1 commit into from
Mar 11, 2024
Merged

Conversation

tqchen
Copy link
Member

@tqchen tqchen commented Mar 10, 2024

This PR enables asyncify support for web runtime.

Asyncify is a feature to allow C++ to call async function in javascript. The emcc compiler will unwind and store the stack, returning control to JS runtime. The JS runtime needs to be able to await the promise and then call rewind to get to the original suspended point.

This feature can be potentially useful when we would like to call WebGPU sync in C++ runtime. As on web platform everything have to be non-blocking. Previously we simply forbid c++ runtime to call sync and have to return to javascript side and let javascript side to call async.

Because asyncify can increase the wams size by 2x, we don't enable it by default in emcc.py and still would need to pass in options.

We will confirm potential benefit tradeoffs before turning it on by default. Another catch is that as of now asyncify is not compatible with wasm exception, so we temporary turn wasm-exception it off for now. This is an item that is being worked on by emscripten so we might be able to turn it back on later.

The testcases are added.

reference: https://emscripten.org/docs/porting/asyncify.html

@tqchen
Copy link
Member Author

tqchen commented Mar 10, 2024

@tqchen
Copy link
Member Author

tqchen commented Mar 10, 2024

To enable it, when calling create_tvmjs_wasm, add ["-s", "ASYNCIFY=1"] to options. Since we are using export_library, we need to do

mod.export_library("name.wasm", tvmjs.create_tvmjs_wasm, options=["-s", "ASYNCIFY=1"])

This PR enables asyncify support for web runtime.

Asyncify is a feature to allow C++ to call async function in javascript.
The emcc compiler will unwind and store the stack, returning control
to JS runtime. The JS runtime needs to be able to await the promise
and then call rewind to get to the original suspended point.

This feature can be potentially useful when we would like to
call WebGPU sync in C++ runtime. As on web platform everything
have to be non-blocking.

Because asyncify can increase the wams size by 2x, we don't enable
it by default in emcc.py and still would need to pass in options.

We will confirm potential benefit tradeoffs before turning it on by default.
Another catch is that as of now asyncify is not compatible with wasm
exception, so we temporary turn wasm-exception it off for now.
This is an item that is being worked on by emscripten so we might
be able to turn it back on later.

The testcases are added.

reference: https://emscripten.org/docs/porting/asyncify.html
Copy link
Contributor

@MasterJH5574 MasterJH5574 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 the support.

@MasterJH5574 MasterJH5574 merged commit 7ac03ca into apache:main Mar 11, 2024
19 checks passed
Lunderberg pushed a commit to Lunderberg/tvm that referenced this pull request Mar 12, 2024
This PR enables asyncify support for web runtime.

Asyncify is a feature to allow C++ to call async function in javascript.
The emcc compiler will unwind and store the stack, returning control
to JS runtime. The JS runtime needs to be able to await the promise
and then call rewind to get to the original suspended point.

This feature can be potentially useful when we would like to
call WebGPU sync in C++ runtime. As on web platform everything
have to be non-blocking.

Because asyncify can increase the wasm size by 2x, we don't enable
it by default in emcc.py and still would need to pass in options.

We will confirm potential benefit tradeoffs before turning it on by default.
Another catch is that as of now asyncify is not compatible with wasm
exception, so we temporary turn wasm-exception it off for now.
This is an item that is being worked on by emscripten so we might
be able to turn it back on later.

The testcases are added.

reference: https://emscripten.org/docs/porting/asyncify.html
thaisacs pushed a commit to thaisacs/tvm that referenced this pull request Apr 3, 2024
This PR enables asyncify support for web runtime.

Asyncify is a feature to allow C++ to call async function in javascript.
The emcc compiler will unwind and store the stack, returning control
to JS runtime. The JS runtime needs to be able to await the promise
and then call rewind to get to the original suspended point.

This feature can be potentially useful when we would like to
call WebGPU sync in C++ runtime. As on web platform everything
have to be non-blocking.

Because asyncify can increase the wasm size by 2x, we don't enable
it by default in emcc.py and still would need to pass in options.

We will confirm potential benefit tradeoffs before turning it on by default.
Another catch is that as of now asyncify is not compatible with wasm
exception, so we temporary turn wasm-exception it off for now.
This is an item that is being worked on by emscripten so we might
be able to turn it back on later.

The testcases are added.

reference: https://emscripten.org/docs/porting/asyncify.html
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