Skip to content

Commit

Permalink
Release WebNN builder after graph built
Browse files Browse the repository at this point in the history
  • Loading branch information
Honry committed Aug 1, 2024
1 parent 74c63bb commit 57dbebb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 2 additions & 0 deletions onnxruntime/core/providers/webnn/builders/model_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ Status ModelBuilder::Compile(std::unique_ptr<Model>& model) {
if (!wnn_graph.as<bool>()) {
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Failed to build WebNN graph.");
}
// Explicitly release the WebNN builder to free memory.
wnn_builder_ = emscripten::val::undefined();
model.reset(new Model(std::move(wnn_context_), std::move(wnn_graph), logger_));
model->SetInputs(std::move(input_names_));
model->SetOutputs(std::move(output_names_));
Expand Down
5 changes: 1 addition & 4 deletions onnxruntime/core/providers/webnn/builders/model_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ class ModelBuilder {
ModelBuilder(const GraphViewer& graph_viewer, const logging::Logger& logger,
const emscripten::val& context, const DataLayout preferred_layout,
const WebnnDeviceType wnn_device_type);
~ModelBuilder() {
// Explicitly release the WebNN builder to free memory.
wnn_builder_ = emscripten::val::undefined();
};
~ModelBuilder() = default;

Status Compile(std::unique_ptr<Model>& model) ORT_MUST_USE_RESULT;

Expand Down

0 comments on commit 57dbebb

Please sign in to comment.