Skip to content

Commit

Permalink
Merge branch 'test-async' of https://github.com/Honry/onnxruntime int…
Browse files Browse the repository at this point in the history
…o test-async
  • Loading branch information
Honry committed Jan 17, 2024
2 parents 9876cc7 + 910efe7 commit 1e1d6bd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmake/onnxruntime_webassembly.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ else()
endif()

if (onnxruntime_USE_WEBNN)
set_property(TARGET onnxruntime_webassembly APPEND_STRING PROPERTY LINK_FLAGS " --bind -sWASM_BIGINT")
set_property(TARGET onnxruntime_webassembly APPEND_STRING PROPERTY LINK_FLAGS " --bind -sWASM_BIGINT -sASYNCIFY=1 -sASYNCIFY_STACK_SIZE=65536")
if (onnxruntime_DISABLE_RTTI)
set_property(TARGET onnxruntime_webassembly APPEND_STRING PROPERTY LINK_FLAGS " -fno-rtti -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0")
endif()
Expand Down
7 changes: 6 additions & 1 deletion onnxruntime/core/providers/webnn/builders/model_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,12 @@ Status ModelBuilder::Compile(std::unique_ptr<Model>& model) {
for (auto& name : output_names_) {
named_operands.set(name, wnn_operands_.at(name));
}
emscripten::val wnn_graph = wnn_builder_.call<emscripten::val>("buildSync", named_operands);

emscripten::val console = emscripten::val::global("console");
console.call<void>("log", emscripten::val("start webnn async build()..."));
emscripten::val wnn_graph = wnn_builder_.call<emscripten::val>("build", named_operands).await();
console.call<void>("log", wnn_builder_);
console.call<void>("log", emscripten::val("Done webnn async build()..."));
if (!wnn_graph.as<bool>()) {
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Failed to build WebNN graph.");
}
Expand Down
6 changes: 5 additions & 1 deletion onnxruntime/core/providers/webnn/webnn_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ WebNNExecutionProvider::WebNNExecutionProvider(const std::string& webnn_device_f
if (webnn_power_flags.compare("default") != 0) {
context_options.set("powerPreference", emscripten::val(webnn_power_flags));
}
wnn_context_ = ml.call<emscripten::val>("createContextSync", context_options);
emscripten::val console = emscripten::val::global("console");
console.call<void>("log", emscripten::val("start webnn async createContext()..."));
wnn_context_ = ml.call<emscripten::val>("createContext", context_options).await();
console.call<void>("log", wnn_context_);
console.call<void>("log", emscripten::val("Done webnn async createContext()..."));
if (!wnn_context_.as<bool>()) {
ORT_THROW("Failed to create WebNN context.");
}
Expand Down

0 comments on commit 1e1d6bd

Please sign in to comment.