[exo] Add Circle node summary builder for logging (#8994)
author박천교/On-Device Lab(SR)/Engineer/삼성전자 <ch.bahk@samsung.com>
Mon, 18 Nov 2019 06:52:55 +0000 (15:52 +0900)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Mon, 18 Nov 2019 06:52:55 +0000 (15:52 +0900)
This commit adds Circle node summary builder to log Circle nodes

Signed-off-by: Cheongyo Bahk <ch.bahk@samsung.com>
compiler/exo/src/ExoFormattedGraph.cpp

index 001e127..dd79005 100644 (file)
 #include "Dialect/IR/TFLDialect.h"
 #include "Dialect/IR/TFLNodes.h"
 
+#include "Dialect/IR/CircleDialect.h"
+#include "Dialect/IR/CircleNodes.h"
+
 #include <locoex/Service/COpFormattedGraph.h>
 #include <pepper/str.h>
 
 #include <sstream>
 #include <cassert>
 
+// For TF lite
 namespace
 {
 
@@ -384,6 +388,95 @@ bool TFLNodeSummaryBuilder::summary(const locoex::TFLTransposeConv *node,
 
 } // namespace
 
+// For Circle
+namespace
+{
+
+std::string circle_opname(uint32_t opnum)
+{
+  static std::string prefix{"circle."};
+
+  switch (static_cast<locoex::CircleOpcode>(opnum))
+  {
+#define CIRCLE_NODE(OPCODE, CLASS)   \
+  case locoex::CircleOpcode::OPCODE: \
+    return prefix + #OPCODE;
+#include "Dialect/IR/CircleNodes.lst"
+#undef CIRCLE_NODE
+    default:
+      break;
+  };
+
+  return prefix + "Invalid";
+}
+
+// CircleNodeSummaryBuilder with default implementation
+class CircleNodeSummaryBuilderBase : public locop::NodeSummaryBuilder
+{
+public:
+  CircleNodeSummaryBuilderBase(const locop::SymbolTable *tbl) : _tbl{tbl}
+  {
+    // DO NOTHING
+  }
+
+public:
+  bool build(const loco::Node *, locop::NodeSummary &s) const final;
+
+protected:
+#define CIRCLE_NODE(OPCODE, CLASS)                                      \
+  virtual bool summary(const CLASS *, locop::NodeSummary &s) const      \
+  {                                                                     \
+    s.comments().append("Emitted by Default CircleNodeSummaryBuilder"); \
+    s.state(locop::NodeSummary::State::PartiallyKnown);                 \
+    return true;                                                        \
+  }
+#include "Dialect/IR/CircleNodes.lst"
+#undef CIRCLE_NODE
+
+protected:
+  const locop::SymbolTable *tbl(void) const { return _tbl; }
+
+  // Please do not use _tbl directly and use tbl().
+  // This will be changed to private in near future.
+protected:
+  const locop::SymbolTable *_tbl;
+};
+
+class CircleNodeSummaryBuilder final : public CircleNodeSummaryBuilderBase
+{
+public:
+  CircleNodeSummaryBuilder(const locop::SymbolTable *tbl) : CircleNodeSummaryBuilderBase(tbl)
+  {
+    // DO NOTHING
+  }
+
+private:
+#define IMPLEMENT(CLASS) bool summary(const CLASS *, locop::NodeSummary &) const final;
+// TODO IMPLEMENT(locoex::CircleInstanceNorm)
+#undef IMPLEMENT
+};
+
+bool CircleNodeSummaryBuilderBase::build(const loco::Node *node, locop::NodeSummary &s) const
+{
+  if (node->dialect() != locoex::CircleDialect::get())
+    return false;
+
+#define CIRCLE_NODE(OPCODE, CLASS)                        \
+  if (dynamic_cast<const CLASS *>(node))                  \
+  {                                                       \
+    s.opname(circle_opname(node->opnum()));               \
+    return summary(dynamic_cast<const CLASS *>(node), s); \
+  }
+#include "Dialect/IR/CircleNodes.lst"
+#undef CIRCLE_NODE
+
+  return false;
+}
+
+// TODO summary impl for CircleInstanceNorm
+
+} // namespace
+
 namespace exo
 {
 
@@ -399,6 +492,11 @@ bool NodeSummaryBuilder::build(const loco::Node *node, locop::NodeSummary &s) co
     return true;
   }
 
+  if (CircleNodeSummaryBuilder(_tbl).build(node, s))
+  {
+    return true;
+  }
+
   if (locoex::COpNodeSummaryBuilder(_tbl).build(node, s))
   {
     return true;