From 3d196beb5bf29545b2df56291b138a9fe74b7cd5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Fri, 2 Aug 2019 17:21:49 +0900 Subject: [PATCH] [moco-tf] Introduce fmt helper (#6149) This commit introduces fmt helper specialized for moco-tf. Signed-off-by: Jonghyun Park --- compiler/moco-tf/src/LogHelper.cpp | 16 ++++++++++++++++ compiler/moco-tf/src/LogHelper.h | 16 ++++++++++++++++ compiler/moco-tf/src/Phase.cpp | 10 +++------- .../src/Transforms/ConstantFoldingTransform.test.cpp | 15 +++++---------- .../src/Transforms/ResolveFusedBatchNorm.test.cpp | 9 +++------ 5 files changed, 43 insertions(+), 23 deletions(-) diff --git a/compiler/moco-tf/src/LogHelper.cpp b/compiler/moco-tf/src/LogHelper.cpp index 04a4fb0..e9d50ab 100644 --- a/compiler/moco-tf/src/LogHelper.cpp +++ b/compiler/moco-tf/src/LogHelper.cpp @@ -56,3 +56,19 @@ std::ostream &operator<<(std::ostream &os, const std::vector &vi64) } return os; } + +#include "TFFormattedGraph.h" + +namespace moco +{ +namespace tf +{ + +FormattedGraph fmt(loco::Graph *g) +{ + auto node_summary_builder = stdex::make_unique(); + return std::move(locop::fmt(g).with(std::move(node_summary_builder))); +} + +} // namespace tf +} // namespace moco diff --git a/compiler/moco-tf/src/LogHelper.h b/compiler/moco-tf/src/LogHelper.h index 439d856..22d89f0 100644 --- a/compiler/moco-tf/src/LogHelper.h +++ b/compiler/moco-tf/src/LogHelper.h @@ -17,6 +17,8 @@ #ifndef __LOG_HELPER_H__ #define __LOG_HELPER_H__ +#include + #include #include #include @@ -49,4 +51,18 @@ std::ostream &operator<<(std::ostream &os, const loco::TensorShape &tensor_shape */ std::ostream &operator<<(std::ostream &os, const std::vector &vi64); +namespace moco +{ +namespace tf +{ + +using FormattedGraph = locop::FormattedGraphImpl; + +FormattedGraph fmt(loco::Graph *g); + +static inline FormattedGraph fmt(const std::unique_ptr &g) { return fmt(g.get()); } + +} // namespace tf +} // namespace moco + #endif // __LOG_HELPER_H__ diff --git a/compiler/moco-tf/src/Phase.cpp b/compiler/moco-tf/src/Phase.cpp index 96f4654..2f4d0ad 100644 --- a/compiler/moco-tf/src/Phase.cpp +++ b/compiler/moco-tf/src/Phase.cpp @@ -15,11 +15,9 @@ */ #include "Phase.h" - -#include "TFFormattedGraph.h" +#include "LogHelper.h" #include -#include namespace { @@ -41,8 +39,7 @@ void PhaseRunner::run(const Phase &phase) const INFO(l) << "PhaseRunner"; INFO(l) << "Initial graph"; - INFO(l) << locop::fmt(_graph).with( - stdex::make_unique()); + INFO(l) << fmt(_graph); for (bool changed = true; changed;) { @@ -62,8 +59,7 @@ void PhaseRunner::run(const Phase &phase) const } INFO(l) << "After " << transform_name(tr.get()) << " (changed: " << to_char(chg_one) << ")"; - INFO(l) << locop::fmt(_graph).with( - stdex::make_unique()); + INFO(l) << fmt(_graph); } } diff --git a/compiler/moco-tf/src/Transforms/ConstantFoldingTransform.test.cpp b/compiler/moco-tf/src/Transforms/ConstantFoldingTransform.test.cpp index 9a63bba..0c57c9f 100644 --- a/compiler/moco-tf/src/Transforms/ConstantFoldingTransform.test.cpp +++ b/compiler/moco-tf/src/Transforms/ConstantFoldingTransform.test.cpp @@ -16,14 +16,13 @@ #include "ConstantFoldingTransform.h" +#include "LogHelper.h" #include "TestHelper.h" #include "IR/TFFusedBatchNorm.h" #include "Importer.h" #include "Canonicalizer.h" -#include "TFFormattedGraph.h" #include -#include #include #include @@ -97,8 +96,7 @@ TEST(ConstantFolding, case01) canonicalizer.canonicalize(graph.get()); INFO(l) << "Before ConstantFolding"; - INFO(l) << locop::fmt(graph).with( - stdex::make_unique()); + INFO(l) << moco::tf::fmt(graph); moco::tf::ConstantFoldingTransform transform; while (transform.run(graph.get()) == true) @@ -107,8 +105,7 @@ TEST(ConstantFolding, case01) } INFO(l) << "After ConstantFolding "; - INFO(l) << locop::fmt(graph).with( - stdex::make_unique()); + INFO(l) << moco::tf::fmt(graph); auto push = moco::tf::test::find_first_node_bytype(graph.get()); auto const_gen = dynamic_cast(push->from()); @@ -236,8 +233,7 @@ TEST(ConstantFolding, case02) canonicalizer.canonicalize(graph.get()); INFO(l) << "Before ConstantFolding"; - INFO(l) << locop::fmt(graph).with( - stdex::make_unique()); + INFO(l) << moco::tf::fmt(graph); moco::tf::ConstantFoldingTransform transform; while (transform.run(graph.get()) == true) @@ -246,8 +242,7 @@ TEST(ConstantFolding, case02) } INFO(l) << "After ConstantFolding "; - INFO(l) << locop::fmt(graph).with( - stdex::make_unique()); + INFO(l) << moco::tf::fmt(graph); auto push = moco::tf::test::find_first_node_bytype(graph.get()); auto const_gen = dynamic_cast(push->from()); diff --git a/compiler/moco-tf/src/Transforms/ResolveFusedBatchNorm.test.cpp b/compiler/moco-tf/src/Transforms/ResolveFusedBatchNorm.test.cpp index c2ccb80..de4e105 100644 --- a/compiler/moco-tf/src/Transforms/ResolveFusedBatchNorm.test.cpp +++ b/compiler/moco-tf/src/Transforms/ResolveFusedBatchNorm.test.cpp @@ -16,13 +16,12 @@ #include "ResolveFusedBatchNorm.h" +#include "LogHelper.h" #include "TestHelper.h" #include "IR/TFFusedBatchNorm.h" #include "Importer.h" -#include "TFFormattedGraph.h" #include -#include #include #include #include @@ -217,15 +216,13 @@ TEST(ResolveFusedBatchNorm, fbn_resolve_basic) auto graph = importer.import(signature, graph_def); INFO(l) << "Before ResolveFusedBatchNorm"; - INFO(l) << locop::fmt(graph).with( - stdex::make_unique()); + INFO(l) << moco::tf::fmt(graph); moco::tf::ResolveFusedBatchNorm transform; bool changed = transform.run(graph.get()); INFO(l) << "After ResolveFusedBatchNorm " << to_char(changed); - INFO(l) << locop::fmt(graph).with( - stdex::make_unique()); + INFO(l) << moco::tf::fmt(graph); // Output value test will be done with mocotest-tf // Network structure of transformation is not important and may be changed -- 2.7.4