Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e6c7666
README and CMake changes
Conarnar Jul 8, 2025
b322cb8
Added build test script for wasm example
Conarnar Jul 9, 2025
43561d7
Added CI tests
Conarnar Jul 9, 2025
d19c6b4
Emscripten automatically installs node.js
Conarnar Jul 9, 2025
4b0e1af
Use Emscripten provided version of Node.js
Conarnar Jul 10, 2025
a21942d
Applied suggestions
Conarnar Jul 10, 2025
7d15296
Merge branch 'main' into wasm-bindings
Conarnar Jul 14, 2025
5378272
Module test working
Conarnar Jul 16, 2025
0701996
Added unit tests for wasm bindings
Conarnar Jul 17, 2025
f3e3d54
Merge branch 'main' into wasm-bindings-js
Conarnar Jul 17, 2025
160f15f
Applied suggestions
Conarnar Jul 18, 2025
bbc46df
Cleaned up tensor classes
Conarnar Jul 18, 2025
79d2769
Added loading from Uint8Array
Conarnar Jul 18, 2025
be9c771
Merge branch 'main' into wasm-bindings-js
Conarnar Jul 19, 2025
a838685
Added CI tests
Conarnar Jul 19, 2025
9c2b93b
Merge branch 'main' into wasm-bindings-js
Conarnar Jul 19, 2025
e63961c
Fix CI
Conarnar Jul 19, 2025
bfbbfc5
Build now uses --post-js to test load from buffer
Conarnar Jul 20, 2025
b274dae
Changed JsTensor data to return memory view
Conarnar Jul 24, 2025
7de34b9
Applied suggestions
Conarnar Jul 24, 2025
4aab20f
Add making JsTensor from iterator
Conarnar Jul 24, 2025
da58ab2
to_evalue check for undefined
Conarnar Jul 24, 2025
cfa3d4c
Merge branch 'main' into wasm-bindings-js
Conarnar Jul 24, 2025
fb5ae68
Renamed option to build unit tests
Conarnar Jul 24, 2025
f4e7144
Marked wasm bindings API as experimental
Conarnar Jul 24, 2025
aa48efb
Set enum names for convenience
Conarnar Jul 25, 2025
6f38b89
Module load from ArrayBuffer
Conarnar Jul 25, 2025
5cfbc1d
Bump PytorchTorch pin to 0725
Conarnar Jul 25, 2025
c72e574
Merge remote-tracking branch 'origin/export-D78989384' into wasm-bind…
Conarnar Jul 25, 2025
1040b15
Merge branch 'main' into wasm-bindings-js
Conarnar Jul 26, 2025
7926335
Merge branch 'main' into wasm-bindings-js
Conarnar Jul 28, 2025
3345fe9
Applied suggestions, turned on assertions, added dim order strides to…
Conarnar Jul 28, 2025
f3ba749
Added case for error messages longer than 256 characters
Conarnar Jul 28, 2025
f806259
Added assertion to verify object is tensor
Conarnar Jul 29, 2025
ddbc698
Merge branch 'main' into wasm-bindings-js
Conarnar Jul 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .ci/scripts/setup-emscripten.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

set -ex

# need version >= 17
install_node() {
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
source "$HOME/.nvm/nvm.sh"
nvm install 22
}

install_emscripten() {
git clone https://github.com/emscripten-core/emsdk.git
pushd emsdk || return
Expand All @@ -16,4 +23,5 @@ install_emscripten() {
popd || return
}

install_node
install_emscripten
35 changes: 35 additions & 0 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,41 @@ jobs:
# Test selective build
PYTHON_EXECUTABLE=python bash examples/wasm/test_build_wasm.sh

unittest-wasm-bindings:
name: unittest-wasm-bindings
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
permissions:
id-token: write
contents: read
strategy:
fail-fast: false
with:
runner: linux.2xlarge
docker-image: ci-image:executorch-ubuntu-22.04-clang12
submodules: 'recursive'
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
timeout: 90
script: |
# The generic Linux job chooses to use base env, not the one setup by the image
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
conda activate "${CONDA_ENV}"

BUILD_TOOL="cmake"
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}"

# Install Node.js and Emscripten
source .ci/scripts/setup-emscripten.sh

# Test selective build
bash scripts/build_wasm_tests.sh

# Install Jest
cd cmake-out-wasm/extension/wasm/test
npm install --save-dev jest

# Run unit test
npm test

unittest-nxp-neutron:
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
permissions:
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ if(EXECUTORCH_BUILD_PYBIND)
)
endif()

if(EXECUTORCH_BUILD_WASM)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/wasm)
endif()

if(EXECUTORCH_BUILD_EXTENSION_TRAINING)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/training)
endif()
Expand Down
56 changes: 56 additions & 0 deletions extension/wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 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
# ~~~

cmake_minimum_required(VERSION 3.24)

project(executorch_wasm)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this directory belongs to a new project so should delete this.


if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()

if(NOT EMSCRIPTEN)
message(FATAL_ERROR "Emscripten is required to build this target")
endif()

# Source root directory for executorch.
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
endif()

include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
set(_common_compile_options -Wno-deprecated-declarations -fPIC)
set(_common_include_directories ${EXECUTORCH_ROOT}/..)

set(link_libraries)
list(
APPEND
link_libraries
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should follow the naming convention with a prepending _

embind
executorch_core
extension_data_loader
portable_ops_lib
extension_module_static
extension_tensor
extension_runner_util
)

add_library(executorch_wasm OBJECT wasm_bindings.cpp)

target_compile_options(executorch_wasm PUBLIC ${_common_compile_options})
target_include_directories(
executorch_wasm PUBLIC ${_common_include_directories}
)
target_link_libraries(executorch_wasm PUBLIC ${link_libraries})

Copy link
Contributor

Choose a reason for hiding this comment

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

should there be a default target_link_options for emscripten?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The link options used for the unit tests are specific for that target. I don't think there are link options that would be widely applicable for this.

if(BUILD_TESTING)
add_subdirectory(test)
endif()
60 changes: 60 additions & 0 deletions extension/wasm/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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
# ~~~

set(MODELS_DIR ${CMAKE_CURRENT_BINARY_DIR}/models/)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/models/add_mul.pte
${CMAKE_CURRENT_BINARY_DIR}/models/add.pte
COMMAND ${CMAKE_COMMAND} -E make_directory "${MODELS_DIR}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../..
COMMAND python3 -m examples.portable.scripts.export --model_name="add_mul"
--output_dir="${MODELS_DIR}"
COMMAND python3 -m examples.portable.scripts.export --model_name="add"
--output_dir="${MODELS_DIR}"
)

add_custom_target(
executorch_wasm_test_models DEPENDS ${MODELS_DIR}/add_mul.pte
${MODELS_DIR}/add.pte
)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/package.json
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/package.json
${CMAKE_CURRENT_BINARY_DIR}/package.json
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/package.json
COMMENT "Copying package.json to build output directory"
)

add_custom_target(
executorch_wasm_test_package_json
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/package.json
)

add_executable(executorch_wasm_tests)
target_link_libraries(executorch_wasm_tests PUBLIC executorch_wasm)
target_link_options(
executorch_wasm_tests PUBLIC --embed-file "${MODELS_DIR}@/" --post-js
${CMAKE_CURRENT_SOURCE_DIR}/unittests.js
)
set_target_properties(
executorch_wasm_tests PROPERTIES OUTPUT_NAME "executorch_wasm.test"
)
set_property(
TARGET executorch_wasm_tests
APPEND
PROPERTY LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/unittests.js
)
add_dependencies(
executorch_wasm_tests executorch_wasm_test_models
executorch_wasm_test_package_json
)
5 changes: 5 additions & 0 deletions extension/wasm/test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"scripts": {
"test": "jest"
}
}
Loading
Loading