[loco] Simplify ReLU Graph Testcase (#6392)
author박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 8 Aug 2019 07:39:37 +0000 (16:39 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 8 Aug 2019 07:39:37 +0000 (16:39 +0900)
Let's simplify ReLU Graph Testcase using GraphBuilder.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
compiler/loco/src/Service/GraphBuilder.h
compiler/loco/src/Service/GraphTestcase.h

index 8c48755..5c517a3 100644 (file)
@@ -209,4 +209,35 @@ struct OutputLayer final
   }
 };
 
+struct ReLULayer final
+{
+  // This "Return" is unnecessary for ReLU as ReLU has no attributes), but
+  // introduced for consistency.
+  class Return
+  {
+  public:
+    Return(loco::ReLU *node) : _node{node}
+    {
+      // DO NOTHING
+    }
+
+  public:
+    loco::ReLU *node(void) { return _node; }
+
+  private:
+    loco::ReLU *_node = nullptr;
+  };
+
+  std::unique_ptr<Return> operator()(GraphBuilder::Context *ctx)
+  {
+    auto relu_node = ctx->graph()->nodes()->create<loco::ReLU>();
+
+    relu_node->input(ctx->stack()->pop());
+
+    ctx->stack()->push(relu_node);
+
+    return stdex::make_unique<Return>(relu_node);
+  }
+};
+
 #endif // __GRAPH_BUILDER_H__
index 37cac41..ac23c59 100644 (file)
@@ -128,6 +128,17 @@ public:
     // Create a sample network
     _graph = loco::make_graph();
 
+    auto graph_builder = make_graph_builder(_graph.get());
+
+    pull_node = graph_builder->push<InputLayer>()->name("input")->node();
+    relu_node = graph_builder->push<ReLULayer>()->node();
+    push_node = graph_builder->push<OutputLayer>()->name("output")->node();
+
+// TODO Remove deprecated code
+#if 0
+    // Create a sample network
+    _graph = loco::make_graph();
+
     // Create Nodes
     pull_node = _graph->nodes()->create<loco::Pull>();
 
@@ -150,6 +161,7 @@ public:
     graph_output->name("output");
     loco::link(graph_output, push_node);
     push_node->index(0);
+#endif
   }
 
 public: