From e9d8711438d50172b599535d3bf2e5175598c5c1 Mon Sep 17 00:00:00 2001 From: SaeHie Park Date: Tue, 13 Aug 2024 07:15:30 +0900 Subject: [PATCH] [tflchef] Revise cook with symbol_table(s) (#13643) This will revise cook method to have symbol_table as parameter instead of return value and symbol_tables as ModelChef member. ONE-DCO-1.0-Signed-off-by: SaeHie Park Co-authored-by: Hyukjin Jeong --- compiler/tflchef/core/src/ModelChef.cpp | 36 +++++++++++++------------ 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/compiler/tflchef/core/src/ModelChef.cpp b/compiler/tflchef/core/src/ModelChef.cpp index b3d3b5c836e..b857e3ce5c9 100644 --- a/compiler/tflchef/core/src/ModelChef.cpp +++ b/compiler/tflchef/core/src/ModelChef.cpp @@ -186,7 +186,8 @@ class ModelChef void init(void); void cook(const ::tflchef::ModelRecipe &model_recipe); - template std::map cook_graph(const T &graph); + template + void cook_graph(const T &graph, std::map &symbol_table); public: const char *get_buffer_pointer(void) const; @@ -201,6 +202,10 @@ class ModelChef std::vector> _subgraph_vec; std::map _builtin_code_map; std::vector _custom_code_vec; + // _symbol_tables stores symbol_table of each sub graph + // this is used to find tensor ID(index) with tensor name + std::vector> _symbol_tables; + std::string _graph_name; }; @@ -245,10 +250,13 @@ make_dim_metadata_vec(flatbuffers::FlatBufferBuilder *flatbuffer_builder, int32_ return dim_metadata_vec; } -template std::map ModelChef::cook_graph(const T &graph) +template +void ModelChef::cook_graph(const T &graph, std::map &symbol_table) { LOGGER(l); + assert(symbol_table.empty()); // FIX_CALLER_UNLESS + // Operand-related std::vector> tensor_vec; @@ -260,9 +268,6 @@ template std::map ModelChef::cook_graph(const if (graph.has_name()) graph_name = graph.name(); - // Tensor Name -> Tensor ID mapping (per Graph) - std::map symbol_table; - auto lookup = [&symbol_table, &graph_name](const std::string &name) { if (symbol_table.find(name) != symbol_table.end()) return symbol_table.at(name); @@ -699,8 +704,6 @@ template std::map ModelChef::cook_graph(const subgraph_builder.add_name(name); _subgraph_vec.emplace_back(subgraph_builder.Finish()); - - return symbol_table; } void ModelChef::cook(const ::tflchef::ModelRecipe &model_recipe) @@ -755,17 +758,15 @@ void ModelChef::cook(const ::tflchef::ModelRecipe &model_recipe) _buffer_vec.emplace_back(buffer_builder.Finish()); } - // symbol_tables stores symbol_table of each sub graph - // this is used to find tensor ID(index) with tensor name - std::vector> symbol_tables; - // // Create Main graph // _graph_name = "main"; - auto table = cook_graph<::tflchef::ModelRecipe>(model_recipe); - symbol_tables.push_back(table); + // Tensor Name -> Tensor ID mapping (per Graph) + std::map symbol_table; + cook_graph<::tflchef::ModelRecipe>(model_recipe, symbol_table); + _symbol_tables.push_back(symbol_table); // // Create subgraphs if exist @@ -779,8 +780,9 @@ void ModelChef::cook(const ::tflchef::ModelRecipe &model_recipe) _graph_name = stringStream.str(); - auto table = cook_graph<::tflchef::Graph>(graph); - symbol_tables.push_back(table); + symbol_table.clear(); + cook_graph<::tflchef::Graph>(graph, symbol_table); + _symbol_tables.push_back(symbol_table); } // Create Signature-Def @@ -799,8 +801,8 @@ void ModelChef::cook(const ::tflchef::ModelRecipe &model_recipe) { subgraph_index = rec_signature_def.subgraph_index(); } - assert(subgraph_index < symbol_tables.size()); - auto &symbol_table = symbol_tables[subgraph_index]; + assert(subgraph_index < _symbol_tables.size()); + auto &symbol_table = _symbol_tables[subgraph_index]; // cook for inputs for (int si = 0; si < rec_signature_def.inputs_size(); ++si)