Skip to content

Commit 1cd87e0

Browse files
committed
use jspi
1 parent 56d02f6 commit 1cd87e0

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

ggml/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ option(GGML_VULKAN_VALIDATE "ggml: enable Vulkan validation"
189189
option(GGML_VULKAN_RUN_TESTS "ggml: run Vulkan tests" OFF)
190190
option(GGML_WEBGPU "ggml: use WebGPU" OFF)
191191
option(GGML_WEBGPU_DEBUG "ggml: enable WebGPU debug output" OFF)
192+
option(GGML_WEBGPU_JSPI "ggml: use JSPI for WebGPU" ON)
192193
option(GGML_ZDNN "ggml: use zDNN" OFF)
193194
option(GGML_METAL "ggml: use Metal" ${GGML_METAL_DEFAULT})
194195
option(GGML_METAL_USE_BF16 "ggml: use bfloat if available" OFF)

ggml/src/ggml-webgpu/CMakeLists.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,19 @@ if(EMSCRIPTEN)
4242
if(NOT EMDAWNWEBGPU_DIR)
4343
# default built-in port
4444
target_compile_options(ggml-webgpu PRIVATE "--use-port=emdawnwebgpu")
45-
target_link_options(ggml-webgpu INTERFACE "--use-port=emdawnwebgpu" "-sASYNCIFY=1")
45+
target_link_options(ggml-webgpu INTERFACE "--use-port=emdawnwebgpu")
4646
else()
4747
# custom port
4848
target_compile_options(ggml-webgpu PRIVATE "--use-port=${EMDAWNWEBGPU_DIR}/emdawnwebgpu.port.py")
49-
target_link_options(ggml-webgpu INTERFACE "--use-port=${EMDAWNWEBGPU_DIR}/emdawnwebgpu.port.py" "-sASYNCIFY=1")
49+
target_link_options(ggml-webgpu INTERFACE "--use-port=${EMDAWNWEBGPU_DIR}/emdawnwebgpu.port.py")
50+
endif()
51+
52+
if (GGML_WEBGPU_JSPI)
53+
target_compile_options(ggml-webgpu PRIVATE "-fwasm-exceptions")
54+
target_link_options(ggml-webgpu INTERFACE "-sJSPI" "-fwasm-exceptions")
55+
else()
56+
target_compile_options(ggml-webgpu PRIVATE "-fexceptions")
57+
target_link_options(ggml-webgpu INTERFACE "-sASYNCIFY" "-exceptions")
5058
endif()
5159

5260
set(DawnWebGPU_TARGET webgpu_cpp)
@@ -58,8 +66,7 @@ endif()
5866
if (GGML_WEBGPU_DEBUG)
5967
target_compile_definitions(ggml-webgpu PRIVATE GGML_WEBGPU_DEBUG=1)
6068
if(EMSCRIPTEN)
61-
target_compile_options(ggml-webgpu PRIVATE "-fexceptions")
62-
target_link_options(ggml-webgpu INTERFACE "-sASSERTIONS=2" "-fexceptions")
69+
target_link_options(ggml-webgpu INTERFACE "-sASSERTIONS=2")
6370
endif()
6471
endif()
6572

ggml/src/ggml-webgpu/ggml-webgpu.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,12 +1297,8 @@ ggml_backend_reg_t ggml_backend_webgpu_reg() {
12971297
webgpu_ctx->instance = wgpu::CreateInstance(&instance_descriptor);
12981298

12991299
#ifdef __EMSCRIPTEN__
1300-
#ifndef __EMSCRIPTEN_PTHREADS__
1301-
GGML_LOG_WARN("ggml_webgpu: pthread is disabled. This may cause bugs\n");
1302-
#endif
1303-
13041300
if (webgpu_ctx->instance == nullptr) {
1305-
GGML_LOG_ERROR("ggml_webgpu: Failed to create WebGPU instance. Make sure -sASYNCIFY is set\n");
1301+
GGML_LOG_ERROR("ggml_webgpu: Failed to create WebGPU instance. Make sure either -sASYNCIFY or -sJSPI is set\n");
13061302
return nullptr;
13071303
}
13081304
#endif

0 commit comments

Comments
 (0)