[neurun] Introduce codegen::Dumper for debugging (#2325)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Fri, 17 Aug 2018 04:09:44 +0000 (13:09 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Fri, 17 Aug 2018 04:09:44 +0000 (13:09 +0900)
Introduce `codegen::Dumper` for debugging which dumps the LIR info in
the order of execution.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/src/codegen/Dumper.cc [new file with mode: 0644]
runtimes/neurun/src/codegen/Dumper.h [new file with mode: 0644]
runtimes/neurun/src/compilation.cc

diff --git a/runtimes/neurun/src/codegen/Dumper.cc b/runtimes/neurun/src/codegen/Dumper.cc
new file mode 100644 (file)
index 0000000..0c04202
--- /dev/null
@@ -0,0 +1,98 @@
+#include "Dumper.h"
+
+#include <string>
+
+#include "logging.h"
+
+namespace neurun
+{
+namespace codegen
+{
+
+using namespace ::internal::tflite::op;
+
+void Dumper::visit(const Conv2D::implicit::Node &node)
+{
+  VERBOSE(LIR) << "* Conv2D(Implicit)" << std::endl;
+  VERBOSE(LIR) << "  - Inputs : IFM(" << node.param().ifm_index << ") Kernel("
+               << node.param().ker_index << ") Bias(" << node.param().bias_index << ")"
+               << std::endl;
+  VERBOSE(LIR) << "  - Output : OFM(" << node.param().ofm_index << ")" << std::endl;
+}
+
+void Dumper::visit(const MaxPool2D::implicit::Node &node)
+{
+  VERBOSE(LIR) << "* MaxPool2D(Implicit)" << std::endl;
+  VERBOSE(LIR) << "  - Inputs : IFM(" << node.param().ifm_index << ")" << std::endl;
+  VERBOSE(LIR) << "  - Output : OFM(" << node.param().ofm_index << ")" << std::endl;
+}
+
+void Dumper::visit(const AvgPool2D::implicit::Node &node)
+{
+  VERBOSE(LIR) << "* AvgPool2D(Implicit)" << std::endl;
+  VERBOSE(LIR) << "  - Inputs : IFM(" << node.param().ifm_index << ")" << std::endl;
+  VERBOSE(LIR) << "  - Output : OFM(" << node.param().ofm_index << ")" << std::endl;
+}
+
+void Dumper::visit(const Concat::Node &node)
+{
+  VERBOSE(LIR) << "* Concat" << std::endl;
+  std::string inputs;
+  for (auto i : node.param().ifm_indexes)
+  {
+    inputs += std::to_string(i) + ",";
+  }
+  VERBOSE(LIR) << "  - Inputs : IFM(" << inputs << ")" << std::endl;
+  VERBOSE(LIR) << "  - Output : OFM(" << node.param().ofm_index << ")" << std::endl;
+}
+
+void Dumper::visit(const FullyConnected::Node &node)
+{
+  VERBOSE(LIR) << "* FullyConnected" << std::endl;
+  VERBOSE(LIR) << "  - Inputs : IFM(" << node.param().input_index << ") Weight("
+               << node.param().weight_index << ") Bias(" << node.param().bias_index << ")"
+               << std::endl;
+  VERBOSE(LIR) << "  - Output : OFM(" << node.param().output_index << ")" << std::endl;
+}
+
+void Dumper::visit(const Reshape::Node &node)
+{
+  VERBOSE(LIR) << "* Reshape" << std::endl;
+  VERBOSE(LIR) << "  - Inputs : IFM(" << node.param().input_index << ") Shape("
+               << node.param().shape_index << ")" << std::endl;
+  VERBOSE(LIR) << "  - Output : OFM(" << node.param().output_index << ")" << std::endl;
+}
+
+void Dumper::visit(const Softmax::Node &node)
+{
+  VERBOSE(LIR) << "* Softmax" << std::endl;
+  VERBOSE(LIR) << "  - Inputs : IFM(" << node.param().input_index << ")" << std::endl;
+  VERBOSE(LIR) << "  - Output : OFM(" << node.param().output_index << ")" << std::endl;
+}
+
+void Dumper::visit(const TensorConvert::CpuFromCommon::Node &node)
+{
+  VERBOSE(LIR) << "CpuFromCommon" << std::endl;
+  // NOTE No details for this node. Soon will be removed.
+}
+
+void Dumper::visit(const TensorConvert::CpuToCommon::Node &node)
+{
+  VERBOSE(LIR) << "CpuToCommon" << std::endl;
+  // NOTE No details for this node. Soon will be removed.
+}
+
+void Dumper::visit(const TensorConvert::AclFromCommon::Node &node)
+{
+  VERBOSE(LIR) << "AclFromCommon" << std::endl;
+  // NOTE No details for this node. Soon will be removed.
+}
+
+void Dumper::visit(const TensorConvert::AclToCommon::Node &node)
+{
+  VERBOSE(LIR) << "AclToCommon" << std::endl;
+  // NOTE No details for this node. Soon will be removed.
+}
+
+} // namespace codegen
+} // namespace neurun
diff --git a/runtimes/neurun/src/codegen/Dumper.h b/runtimes/neurun/src/codegen/Dumper.h
new file mode 100644 (file)
index 0000000..5aa3f61
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef __NEURUN_CODEGEN_DUMPER_H__
+#define __NEURUN_CODEGEN_DUMPER_H__
+
+#include "internal/op/NodeVisitor.h"
+
+namespace neurun
+{
+namespace codegen
+{
+
+class Dumper : public ::internal::tflite::op::NodeVisitor
+{
+public:
+  Dumper() = default;
+
+public:
+  void visit(const ::internal::tflite::op::Conv2D::implicit::Node &node) override;
+  void visit(const ::internal::tflite::op::MaxPool2D::implicit::Node &node) override;
+  void visit(const ::internal::tflite::op::AvgPool2D::implicit::Node &node) override;
+  void visit(const ::internal::tflite::op::Concat::Node &node) override;
+  void visit(const ::internal::tflite::op::FullyConnected::Node &node) override;
+  void visit(const ::internal::tflite::op::Reshape::Node &node) override;
+  void visit(const ::internal::tflite::op::Softmax::Node &node) override;
+  void visit(const ::internal::tflite::op::TensorConvert::CpuFromCommon::Node &node) override;
+  void visit(const ::internal::tflite::op::TensorConvert::CpuToCommon::Node &node) override;
+  void visit(const ::internal::tflite::op::TensorConvert::AclFromCommon::Node &node) override;
+  void visit(const ::internal::tflite::op::TensorConvert::AclToCommon::Node &node) override;
+};
+
+} // namespace codegen
+} // namespace neurun
+
+#endif // __NEURUN_CODEGEN_DUMPER_H__
index 400338e..35286f7 100644 (file)
@@ -22,6 +22,7 @@
 #include "model.h"
 #include "logging.h"
 
+#include "codegen/Dumper.h"
 #include "codegen/IPlanBuilder.h"
 #include "codegen/BackendResolver.h"
 #include "codegen/Planner.h"
@@ -47,6 +48,12 @@ int ANeuralNetworksCompilation::finish()
     std::reverse(std::begin(operations), std::end(operations));
   }
 
+  // Dump ops
+  for (const auto op : operations)
+  {
+    op->accept(neurun::codegen::Dumper{});
+  }
+
   ::internal::BackendManager backend_manager{plan};
   neurun::codegen::BackendResolver backend_resolver{backend_manager};
   neurun::codegen::PlanBuilder plan_builder{plan};