From 46c5a3f9bb65ba081d0ae18c15b3b1b4ccf5a981 Mon Sep 17 00:00:00 2001 From: kahmed10 <15948690+kahmed10@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:21:01 -0600 Subject: [PATCH] change program from_value to free nodes and modules as parsed --- src/include/migraphx/program.hpp | 2 +- src/include/migraphx/value.hpp | 2 +- src/program.cpp | 14 ++++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/include/migraphx/program.hpp b/src/include/migraphx/program.hpp index 2a82f381c21..ae06b556a6b 100644 --- a/src/include/migraphx/program.hpp +++ b/src/include/migraphx/program.hpp @@ -115,7 +115,7 @@ struct MIGRAPHX_EXPORT program void mark(const parameter_map& params, marker m); value to_value() const; - void from_value(const value& v); + void from_value(value v); void debug_print() const; void debug_print(instruction_ref ins) const; diff --git a/src/include/migraphx/value.hpp b/src/include/migraphx/value.hpp index 5efb8017679..a668532f321 100644 --- a/src/include/migraphx/value.hpp +++ b/src/include/migraphx/value.hpp @@ -194,7 +194,7 @@ struct MIGRAPHX_EXPORT value }; value() = default; - + value(value&& rhs) = default; value(const value& rhs); value& operator=(value rhs); value(const std::string& pkey, const value& rhs); diff --git a/src/program.cpp b/src/program.cpp index 5cfb62baf39..30cfe5d7faa 100644 --- a/src/program.cpp +++ b/src/program.cpp @@ -720,12 +720,12 @@ value program::to_value() const } static void mod_from_val(module_ref mod, - const value& v, + value& v, std::unordered_map& instructions, const std::unordered_map& map_mods) { - const auto& module_val = v.at(mod->name()); - for(const value& node : module_val.at("nodes")) + auto& module_val = v.at(mod->name()); + for(value& node : module_val.at("nodes")) { instruction_ref output; auto name = node.at("name").to(); @@ -764,7 +764,7 @@ static void mod_from_val(module_ref mod, std::back_inserter(module_inputs), [&](const value& i) { return map_mods.at(i.to()); }); - for(const auto& smod : module_inputs) + for(auto& smod : module_inputs) { mod_from_val(smod, v, instructions, map_mods); } @@ -785,10 +785,12 @@ static void mod_from_val(module_ref mod, } output->set_normalized(normalized); instructions[node.at("output").to()] = output; + node = nullptr; } + module_val = nullptr; } -void program::from_value(const value& v) +void program::from_value(value v) { auto version = v.at("version").to(); if(version != program_file_version) @@ -816,7 +818,7 @@ void program::from_value(const value& v) this->impl->contexts.back().from_value(v.at("contexts")[i]); } - auto module_vals = v.at("modules"); + auto& module_vals = v.at("modules"); for(const auto& vv : module_vals) { const auto& name = vv.get_key();