feat: add WAMR WebAssembly engine support for Halide JIT#9116
feat: add WAMR WebAssembly engine support for Halide JIT#9116soldair wants to merge 3 commits intohalide:mainfrom
Conversation
|
I sent this pr a little early but i would love feedback. v8 is a very large dep and is causing issues and we cant use wabt. wamr is a perfect drop in. |
4df6609 to
6223372
Compare
|
I just tried this... it is possible to use standard mechanisms to use WAMR. I would push directly, but I notice you prefer to force-push, @soldair, so to avoid losing work, I'll provide you with a patch file instead. This boils down to two changes:
I've also opened bytecodealliance/wasm-micro-runtime#4932 to nudge upstream into also using standard mechanisms for pulling in dependencies. 0001-Use-standard-mechanisms-to-use-WAMR.patch Patch contentsFrom 6c5c846544ba9e0a3775e3aeefc744705809072f Mon Sep 17 00:00:00 2001
From: Alex Reinking <areinking@adobe.com>
Date: Thu, 30 Apr 2026 15:30:06 -0400
Subject: [PATCH] Use standard mechanisms to use WAMR
- Rather than building WAMR in-line with Halide, add a vcpkg port
to manage building WAMR. The WAMR build uses FetchContent to
acquire simde, which is unnecessary, so we patch around it.
- Use find_package to import WAMR into the build, mirroring the
approach for V8 and wabt.
---
cmake/vcpkg/wamr/portfile.cmake | 21 +++++++++++++++
cmake/vcpkg/wamr/remove-fetchcontent.patch | 19 ++++++++++++++
cmake/vcpkg/wamr/vcpkg.json | 18 +++++++++++++
src/CMakeLists.txt | 30 +++++-----------------
vcpkg.json | 12 ++++++---
5 files changed, 73 insertions(+), 27 deletions(-)
create mode 100644 cmake/vcpkg/wamr/portfile.cmake
create mode 100644 cmake/vcpkg/wamr/remove-fetchcontent.patch
create mode 100644 cmake/vcpkg/wamr/vcpkg.json
diff --git a/cmake/vcpkg/wamr/portfile.cmake b/cmake/vcpkg/wamr/portfile.cmake
new file mode 100644
index 000000000..05593b8de
--- /dev/null
+++ b/cmake/vcpkg/wamr/portfile.cmake
@@ -0,0 +1,21 @@
+vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
+
+vcpkg_from_github(
+ OUT_SOURCE_PATH SOURCE_PATH
+ REPO bytecodealliance/wasm-micro-runtime
+ REF 8c18e3f68b16c4bcaf05996b2636f6ed2b4cf629 # WAMR-2.4.4
+ SHA512 2378ab44e6ea3cd9bfede86a413c5d5503b8cd0d072bbee7099bd149897a58d74b57c06214f6b163242f5ac8bcdbb81a59632016ebd4c12a717786e1c387c9e3
+ PATCHES remove-fetchcontent.patch
+)
+
+vcpkg_cmake_configure(SOURCE_PATH "${SOURCE_PATH}")
+
+vcpkg_cmake_install()
+vcpkg_cmake_config_fixup(PACKAGE_NAME iwasm CONFIG_PATH lib/cmake/iwasm)
+
+vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
+
+file(REMOVE_RECURSE
+ "${CURRENT_PACKAGES_DIR}/debug/include"
+ "${CURRENT_PACKAGES_DIR}/debug/share"
+)
diff --git a/cmake/vcpkg/wamr/remove-fetchcontent.patch b/cmake/vcpkg/wamr/remove-fetchcontent.patch
new file mode 100644
index 000000000..936f4dbf2
--- /dev/null
+++ b/cmake/vcpkg/wamr/remove-fetchcontent.patch
@@ -0,0 +1,19 @@
+diff --git a/core/iwasm/libraries/simde/simde.cmake b/core/iwasm/libraries/simde/simde.cmake
+--- a/core/iwasm/libraries/simde/simde.cmake
++++ b/core/iwasm/libraries/simde/simde.cmake
+@@ -15,14 +15,5 @@ add_definitions (-DWASM_ENABLE_SIMDE=1)
+
+ include_directories(${LIB_SIMDE_DIR} ${LIB_SIMDE_DIR}/simde)
+
+-include(FetchContent)
+-
+-FetchContent_Declare(
+- simde
+- GIT_REPOSITORY https://github.com/simd-everywhere/simde
+- GIT_TAG v0.8.2
+-)
+-
+-message("-- Fetching simde ..")
+-FetchContent_MakeAvailable(simde)
++find_path(simde_SOURCE_DIR simde/wasm/simd128.h)
+ include_directories("${simde_SOURCE_DIR}")
diff --git a/cmake/vcpkg/wamr/vcpkg.json b/cmake/vcpkg/wamr/vcpkg.json
new file mode 100644
index 000000000..b4a61bb6d
--- /dev/null
+++ b/cmake/vcpkg/wamr/vcpkg.json
@@ -0,0 +1,18 @@
+{
+ "name": "wamr",
+ "version-semver": "2.4.4",
+ "description": "WebAssembly Micro Runtime (WAMR)",
+ "homepage": "https://github.com/bytecodealliance/wasm-micro-runtime",
+ "license": "Apache-2.0",
+ "dependencies": [
+ "simde",
+ {
+ "name": "vcpkg-cmake",
+ "host": true
+ },
+ {
+ "name": "vcpkg-cmake-config",
+ "host": true
+ }
+ ]
+}
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1e1f8e9b5..18624abc9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -591,38 +591,20 @@ if (Halide_WASM_BACKEND STREQUAL "wabt")
find_package(wabt REQUIRED)
_Halide_pkgdep(wabt)
- target_link_libraries(Halide PRIVATE wabt::wabt)
target_compile_definitions(Halide PRIVATE WITH_WABT)
+ target_link_libraries(Halide PRIVATE wabt::wabt)
elseif (Halide_WASM_BACKEND STREQUAL "V8")
find_package(V8 REQUIRED)
_Halide_pkgdep(V8)
+
target_compile_definitions(Halide PRIVATE WITH_V8)
target_link_libraries(Halide PRIVATE V8::V8)
elseif (Halide_WASM_BACKEND STREQUAL "WAMR")
- set(Halide_WAMR_ROOT_DIR "" CACHE PATH "Path to root directory of WAMR repository sources")
-
- if ("${Halide_WAMR_ROOT_DIR}" STREQUAL "")
- if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../wasm-micro-runtime/build-scripts/runtime_lib.cmake")
- set(WAMR_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../wasm-micro-runtime")
- else()
- message(FATAL_ERROR "WAMR backend requires specifying Halide_WAMR_ROOT_DIR or cloning wasm-micro-runtime adjacent to the Halide repository.")
- endif()
- else()
- set(WAMR_ROOT_DIR "${Halide_WAMR_ROOT_DIR}")
- endif()
-
- set(WAMR_BUILD_PLATFORM "linux")
- set(WAMR_BUILD_TARGET "X86_64")
- set(WAMR_BUILD_INTERP 1)
- set(WAMR_BUILD_FAST_INTERP 1)
- set(WAMR_BUILD_REF_TYPES 1)
- set(WAMR_BUILD_SIMD 1)
- set(WAMR_BUILD_LIB_SIMDE 1)
- include(${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
- add_library(wamr_lib STATIC ${WAMR_RUNTIME_LIB_SOURCE})
- target_link_libraries(Halide PRIVATE wamr_lib)
+ find_package(iwasm REQUIRED)
+ _Halide_pkgdep(iwasm)
+
target_compile_definitions(Halide PRIVATE WITH_WAMR)
- target_include_directories(Halide PRIVATE "${WAMR_ROOT_DIR}/core/iwasm/include")
+ target_link_libraries(Halide PRIVATE iwasm::vmlib)
elseif (Halide_WASM_BACKEND)
message(FATAL_ERROR "Unknown Halide_WASM_BACKEND `${Halide_WASM_BACKEND}`")
endif ()
diff --git a/vcpkg.json b/vcpkg.json
index 6a404753c..5d7b4c293 100644
--- a/vcpkg.json
+++ b/vcpkg.json
@@ -45,7 +45,7 @@
"default-features": false,
"features": [
"serialization",
- "wasm-executor"
+ "wasm-executor-wabt"
]
}
]
@@ -180,11 +180,17 @@
}
]
},
- "wasm-executor": {
- "description": "Include built-in WASM executor",
+ "wasm-executor-wabt": {
+ "description": "Include wabt-based WASM executor",
"dependencies": [
"wabt"
]
+ },
+ "wasm-executor-wamr": {
+ "description": "Include wamr-based WASM executor",
+ "dependencies": [
+ "wamr"
+ ]
}
}
}
--
2.50.1 (Apple Git-155) |
|
please feel free to push any time. i'm not typically a force pusher just a product of a tool i was using. 😅 i'll apply this patch |
|
Testing this locally, I'm seeing issues with finding Halide's extern funcs feature. Also seeing issues with some surprisingly moderate allocation sizes (e.g. 48KB). |
|
Thanks for looking. If you have a command handy ill make sure everything passes and @ you when i think we're doing ok. I thought i had been running all the tests. I'm very new to this project 😅 |
This PR introduces Wasm Micro Runtime (WAMR) integration as an execution engine backend alternative inside the
WasmModuleJIT runtime harness, in addition to supporting standard co-existence of fallback configurations alongside legacy engines (wabt/v8).Design Background
Halide WebAssembly testing has historically targeted
wabtorV8modules. WAMR provides smaller execution footprint constraints suitable for constrained evaluation targets and embedding environments.Technical Enhancements
src/WasmExecutor.cpp.FetchContentmodule downloads.__extendhfsf2,__truncsfhf2half-float native implementations and mathematical POSIX wrappers.Fixes #
Breaking changes
None. Code coexistence preserves logic paths for previous backends
wabt/v8.Checklist