-
Notifications
You must be signed in to change notification settings - Fork 7
Wasm build demo #45
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
Merged
Merged
Wasm build demo #45
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
897545a
Copied demo files
0598119
Added more instructions
Conarnar 23297c7
Moved error checking to separate function
Conarnar 4f85431
Clarified the readme
Conarnar 3e23111
Simplified installation instructions
Conarnar d499be6
Removed unnecessary options
Conarnar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
# Please this file formatted by running: | ||
# ~~~ | ||
# cmake-format -i CMakeLists.txt | ||
# ~~~ | ||
|
||
add_subdirectory("executorch") | ||
|
||
add_executable(executorch_wasm_demo_lib) | ||
target_link_libraries(executorch_wasm_demo_lib PUBLIC executorch_wasm) | ||
target_link_options( | ||
executorch_wasm_demo_lib PUBLIC -sALLOW_MEMORY_GROWTH | ||
) | ||
|
||
add_custom_command( | ||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/demo.js | ||
COMMAND | ||
${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/demo.js | ||
${CMAKE_CURRENT_BINARY_DIR}/demo.js | ||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/demo.js | ||
COMMENT "Copying demo.js to build output directory" | ||
) | ||
|
||
add_custom_command( | ||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/classes.js | ||
COMMAND | ||
${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/classes.js | ||
${CMAKE_CURRENT_BINARY_DIR}/classes.js | ||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/classes.js | ||
COMMENT "Copying classes.js to build output directory" | ||
) | ||
|
||
add_custom_command( | ||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/demo.html | ||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/demo.html | ||
${CMAKE_CURRENT_BINARY_DIR}/demo.html | ||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/demo.html | ||
COMMENT "Copying demo.html to build output directory" | ||
) | ||
|
||
add_custom_target( | ||
executorch_wasm_demo | ||
DEPENDS executorch_wasm_demo_lib | ||
${CMAKE_CURRENT_BINARY_DIR}/classes.js | ||
${CMAKE_CURRENT_BINARY_DIR}/demo.js | ||
${CMAKE_CURRENT_BINARY_DIR}/demo.html | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# ExecuTorch JavaScript Bindings Demo | ||
|
||
This demo showcases the capabilities of ExecuTorch's JavaScript bindings. It is able to load a model, run inference, and classify an image natively in the browser. | ||
|
||
## Prerequisites | ||
|
||
- [Emscripten](https://emscripten.org/docs/getting_started/Tutorial.html) | ||
- Refer to the [Wasm example Readme](https://github.com/pytorch/executorch/blob/main/examples/wasm/README.md) for a quick setup guide. | ||
Conarnar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Building and Running | ||
|
||
``` | ||
# Clone executorch submodule | ||
git submodule update --init | ||
|
||
# Set up Executorch | ||
cd executorch | ||
./install_executorch.sh | ||
Conarnar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
./install_executorch.sh --clean | ||
Conarnar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
cd .. | ||
|
||
# Build the demo | ||
bash build.sh | ||
|
||
# Run the demo | ||
python3 -m http.server --directory build/ | ||
``` | ||
|
||
The page will be available at http://localhost:8000/demo.html. | ||
|
||
## Demo Features | ||
|
||
- Load a model from a file | ||
- It currently only supports the MobileNetv2 model. Passing in a model with different input/output shapes will result in an error. | ||
- You can generate the model file by following the instructions in the [Portable Mode Readme](https://github.com/pytorch/executorch/blob/main/examples/portable/README.md). | ||
- Run inference on an image | ||
Conarnar marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
CMAKE_OUT=build | ||
|
||
emcmake cmake . -DEXECUTORCH_BUILD_WASM=ON \ | ||
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ | ||
-DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \ | ||
-DEXECUTORCH_BUILD_DEVTOOLS=ON \ | ||
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ | ||
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \ | ||
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \ | ||
-DEXECUTORCH_BUILD_WASM_DEMO=ON \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-B"${CMAKE_OUT}" | ||
|
||
if [ "$(uname)" == "Darwin" ]; then | ||
CMAKE_JOBS=$(( $(sysctl -n hw.ncpu) - 1 )) | ||
else | ||
CMAKE_JOBS=$(( $(nproc) - 1 )) | ||
fi | ||
|
||
cmake --build ${CMAKE_OUT} --target executorch_wasm_demo -j ${CMAKE_JOBS} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a link to your readme?
'Refer to the wasm readme for setup guide.'