mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-24 19:43:35 +00:00
[WebNN EP] Release WebNN MLGraphBuilder after Compile to free memory (#21200)
This would help release the constants bound by the MLGraphBuilder.
This commit is contained in:
parent
2c53b4a534
commit
eeb8fc0931
2 changed files with 12 additions and 2 deletions
|
|
@ -81,6 +81,13 @@ WebNNExecutionProvider::GetCapability(const onnxruntime::GraphViewer& graph_view
|
|||
|
||||
const auto& logger = *GetLogger();
|
||||
|
||||
if (!wnn_builder_.as<bool>()) {
|
||||
// The GetCapability function may be called again after Compile due to the logic in the
|
||||
// PartitionOnnxFormatModel function (see onnxruntime/core/framework/graph_partitioner.cc).
|
||||
// We need to re-create the wnn_builder_ here to avoid it's been released in last Compile.
|
||||
wnn_builder_ = emscripten::val::global("MLGraphBuilder").new_(wnn_context_);
|
||||
}
|
||||
|
||||
const auto node_groups = webnn::GetSupportedNodes(graph_viewer, wnn_builder_, wnn_device_type_, logger);
|
||||
|
||||
if (node_groups.empty()) {
|
||||
|
|
@ -322,6 +329,9 @@ common::Status WebNNExecutionProvider::Compile(const std::vector<FusedNodeAndGra
|
|||
node_compute_funcs.push_back(compute_info);
|
||||
}
|
||||
|
||||
// Explictly release the WebNN builder to free memory.
|
||||
wnn_builder_ = emscripten::val::undefined();
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ class WebNNExecutionProvider : public IExecutionProvider {
|
|||
std::shared_ptr<KernelRegistry> GetKernelRegistry() const override;
|
||||
|
||||
private:
|
||||
emscripten::val wnn_context_ = emscripten::val::object();
|
||||
emscripten::val wnn_builder_ = emscripten::val::object();
|
||||
emscripten::val wnn_context_ = emscripten::val::undefined();
|
||||
mutable emscripten::val wnn_builder_ = emscripten::val::undefined();
|
||||
|
||||
DataLayout preferred_layout_;
|
||||
webnn::WebnnDeviceType wnn_device_type_;
|
||||
|
|
|
|||
Loading…
Reference in a new issue