From 3db3b94c37da689989a8c5702040627b796558b9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=84=B8=ED=9D=AC/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Tue, 21 May 2019 14:46:17 +0900 Subject: [PATCH] [moco] remove unused node_names (#3553) This will remove 'not-used-anymore' node_names Signed-off-by: SaeHie Park --- contrib/moco/lib/frontend/tf/src/Frontend.cpp | 3 +- .../lib/frontend/tf/src/GraphBuilderContext.cpp | 43 ---------------------- .../moco/lib/frontend/tf/src/GraphBuilderContext.h | 25 +------------ .../frontend/tf/src/GraphBuilderContext.test.cpp | 22 +---------- contrib/moco/lib/frontend/tf/src/Op/Identity.cpp | 1 - contrib/moco/lib/frontend/tf/src/Op/Relu.cpp | 1 - 6 files changed, 4 insertions(+), 91 deletions(-) diff --git a/contrib/moco/lib/frontend/tf/src/Frontend.cpp b/contrib/moco/lib/frontend/tf/src/Frontend.cpp index ea92d0d..30c782e 100644 --- a/contrib/moco/lib/frontend/tf/src/Frontend.cpp +++ b/contrib/moco/lib/frontend/tf/src/Frontend.cpp @@ -102,10 +102,9 @@ void convert_graph(const moco::tf::ModelSignature &signature, tensorflow::GraphD loco::Graph *graph) { auto nodes = stdex::make_unique(); - auto input_names = stdex::make_unique(); auto updates = stdex::make_unique(); - moco::tf::GraphBuilderContext gb_context(graph, nodes.get(), input_names.get(), updates.get()); + moco::tf::GraphBuilderContext gb_context(graph, nodes.get(), updates.get()); // Building a loco graph // 1. Convert all the nodes to loco::Node diff --git a/contrib/moco/lib/frontend/tf/src/GraphBuilderContext.cpp b/contrib/moco/lib/frontend/tf/src/GraphBuilderContext.cpp index c318f39..e3344df 100644 --- a/contrib/moco/lib/frontend/tf/src/GraphBuilderContext.cpp +++ b/contrib/moco/lib/frontend/tf/src/GraphBuilderContext.cpp @@ -48,49 +48,6 @@ loco::Node *SymbolTable::node(const std::string &node_name) const return iter->second; } -void SymbolTable::list(loco::Node *node, const std::string &name) -{ - MapNodeNames_t::iterator iter = _nodenames.find(node); - - if (iter == _nodenames.end()) - { - // add a new vector for the first name - _nodenames[node] = {name}; - return; - } - - _nodenames[node].push_back(name); -} - -unsigned SymbolTable::size(loco::Node *node) -{ - MapNodeNames_t::iterator iter = _nodenames.find(node); - - if (iter == _nodenames.end()) - { - return 0; - } - - return iter->second.size(); -} - -const std::string &SymbolTable::name(loco::Node *node, unsigned index) -{ - MapNodeNames_t::iterator iter = _nodenames.find(node); - - if (iter == _nodenames.end()) - { - throw std::runtime_error{"Error: Cannot find names given node"}; - } - - if (index >= iter->second.size()) - { - throw std::runtime_error{"Error: Invalid name index for given node"}; - } - - return iter->second.at(index); -} - void UpdateQueue::enroll(std::unique_ptr &&update) { _queue.push_back(std::move(update)); diff --git a/contrib/moco/lib/frontend/tf/src/GraphBuilderContext.h b/contrib/moco/lib/frontend/tf/src/GraphBuilderContext.h index 64aee5b..315b90d 100644 --- a/contrib/moco/lib/frontend/tf/src/GraphBuilderContext.h +++ b/contrib/moco/lib/frontend/tf/src/GraphBuilderContext.h @@ -46,27 +46,9 @@ public: */ loco::Node *node(const std::string &node_name) const; - /** - * @brief Registers multiple (appends) names for a node - * Table is independent with registering with enroll() - */ - void list(loco::Node *node, const std::string &name); - /** - * @brief Returns number of listed(registered) names for a node - */ - unsigned size(loco::Node *node); - /** - * @brief Queries listed(registered) with node and index(from 0 to size-1) - * Will throw runtime_error if node is not found or index is out of bounds - */ - const std::string &name(loco::Node *node, unsigned index); - private: using MapNameNode_t = std::map; - using MapNodeNames_t = std::map>; - MapNameNode_t _namenode; - MapNodeNames_t _nodenames; MapNameNode_t _table; }; @@ -111,9 +93,8 @@ private: class GraphBuilderContext { public: - GraphBuilderContext(loco::Graph *g, SymbolTable *nodes, SymbolTable *input_names, - UpdateQueue *updates) - : _g(g), _nodes(nodes), _input_names(input_names), _updates(updates) + GraphBuilderContext(loco::Graph *g, SymbolTable *nodes, UpdateQueue *updates) + : _g(g), _nodes(nodes), _updates(updates) { // DO NOTHING } @@ -124,13 +105,11 @@ public: public: loco::Graph *graph() { return _g; } SymbolTable *nodes() { return _nodes; } - SymbolTable *input_names() { return _input_names; } UpdateQueue *updates() { return _updates; } private: loco::Graph *_g; SymbolTable *_nodes; - SymbolTable *_input_names; UpdateQueue *_updates; }; diff --git a/contrib/moco/lib/frontend/tf/src/GraphBuilderContext.test.cpp b/contrib/moco/lib/frontend/tf/src/GraphBuilderContext.test.cpp index d5c502d..885d227 100644 --- a/contrib/moco/lib/frontend/tf/src/GraphBuilderContext.test.cpp +++ b/contrib/moco/lib/frontend/tf/src/GraphBuilderContext.test.cpp @@ -24,14 +24,12 @@ TEST(GraphBuilderContext, ctor) { auto graph = loco::make_graph(); moco::tf::SymbolTable nodes; - moco::tf::SymbolTable input_names; moco::tf::UpdateQueue updates; - moco::tf::GraphBuilderContext context(graph.get(), &nodes, &input_names, &updates); + moco::tf::GraphBuilderContext context(graph.get(), &nodes, &updates); ASSERT_EQ(context.graph(), graph.get()); ASSERT_EQ(context.nodes(), &nodes); - ASSERT_EQ(context.input_names(), &input_names); ASSERT_EQ(context.updates(), &updates); } @@ -49,21 +47,3 @@ TEST(SymbolTable, node_name) // unregistered name should throw EXPECT_THROW(table.node(invalid), std::runtime_error); } - -TEST(SymbolTable, name_node) -{ - moco::tf::SymbolTable table; - loco::Push push_node; - std::string in1("in1"); - std::string in2("in2"); - - ASSERT_EQ(table.size(&push_node), 0); - - table.list(&push_node, in1); - table.list(&push_node, in2); - unsigned size = table.size(&push_node); - ASSERT_EQ(size, 2); - ASSERT_EQ(in1, table.name(&push_node, 0)); - ASSERT_EQ(in2, table.name(&push_node, 1)); - EXPECT_THROW(table.name(&push_node, 2), std::runtime_error); -} diff --git a/contrib/moco/lib/frontend/tf/src/Op/Identity.cpp b/contrib/moco/lib/frontend/tf/src/Op/Identity.cpp index e807bb3..2947c88 100644 --- a/contrib/moco/lib/frontend/tf/src/Op/Identity.cpp +++ b/contrib/moco/lib/frontend/tf/src/Op/Identity.cpp @@ -71,7 +71,6 @@ void IdentityGraphBuilder::build(const tensorflow::NodeDef &node, loco::Graph *graph = context->graph(); SymbolTable *nodes = context->nodes(); - SymbolTable *input_names = context->input_names(); UpdateQueue *updates = context->updates(); // Create a "Forward" node for Identity diff --git a/contrib/moco/lib/frontend/tf/src/Op/Relu.cpp b/contrib/moco/lib/frontend/tf/src/Op/Relu.cpp index 52fc68c..7cd9a0d 100644 --- a/contrib/moco/lib/frontend/tf/src/Op/Relu.cpp +++ b/contrib/moco/lib/frontend/tf/src/Op/Relu.cpp @@ -60,7 +60,6 @@ void ReluGraphBuilder::build(const tensorflow::NodeDef &node, GraphBuilderContex loco::Graph *graph = context->graph(); SymbolTable *nodes = context->nodes(); - SymbolTable *input_names = context->input_names(); UpdateQueue *updates = context->updates(); // Create a "ReLU" node for Relu -- 2.7.4