From 57dbebb175397fcd1eeaa34bc66883b8a4df09fe Mon Sep 17 00:00:00 2001 From: Wanming Lin Date: Fri, 26 Jul 2024 13:27:37 +0800 Subject: [PATCH] Release WebNN builder after graph built --- onnxruntime/core/providers/webnn/builders/model_builder.cc | 2 ++ onnxruntime/core/providers/webnn/builders/model_builder.h | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/onnxruntime/core/providers/webnn/builders/model_builder.cc b/onnxruntime/core/providers/webnn/builders/model_builder.cc index a65a13e2530c6..b21f717eedc7a 100644 --- a/onnxruntime/core/providers/webnn/builders/model_builder.cc +++ b/onnxruntime/core/providers/webnn/builders/model_builder.cc @@ -338,6 +338,8 @@ Status ModelBuilder::Compile(std::unique_ptr& model) { if (!wnn_graph.as()) { 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_)); diff --git a/onnxruntime/core/providers/webnn/builders/model_builder.h b/onnxruntime/core/providers/webnn/builders/model_builder.h index aeaf434af6eb7..b1561f009aa25 100644 --- a/onnxruntime/core/providers/webnn/builders/model_builder.h +++ b/onnxruntime/core/providers/webnn/builders/model_builder.h @@ -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) ORT_MUST_USE_RESULT;