[locomotiv] Support Pull node (#3415)
author박천교/On-Device Lab(SR)/Engineer/삼성전자 <ch.bahk@samsung.com>
Thu, 9 May 2019 01:46:31 +0000 (10:46 +0900)
committer박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 9 May 2019 01:46:31 +0000 (10:46 +0900)
This commit introduces support for Pull node execution. Pull node
basically do nothing, but aborts if input data annotation not ready.

Signed-off-by: Cheongyo Bahk <ch.bahk@samsung.com>
contrib/locomotiv/src/Node/Pull.cpp [new file with mode: 0644]
contrib/locomotiv/src/Node/Pull.test.cpp [new file with mode: 0644]
contrib/locomotiv/src/NodeExecution.cpp
contrib/locomotiv/src/NodeExecution.h

diff --git a/contrib/locomotiv/src/Node/Pull.cpp b/contrib/locomotiv/src/Node/Pull.cpp
new file mode 100644 (file)
index 0000000..b5b49a6
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "NodeExecution.h"
+
+#include "NodeDataImpl.h"
+
+#include <stdexcept>
+
+namespace locomotiv
+{
+
+void NodeExecution::execute(loco::Pull *pull)
+{
+  if (!annot_data(pull))
+  {
+    throw std::runtime_error("Input data for Pull node not ready");
+  }
+}
+
+} // namespace locomotiv
diff --git a/contrib/locomotiv/src/Node/Pull.test.cpp b/contrib/locomotiv/src/Node/Pull.test.cpp
new file mode 100644 (file)
index 0000000..7dd748d
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "NodeExecution.h"
+
+#include "locomotiv/NodeData.h"
+#include "NodeDataImpl.h"
+
+#include <nncc/core/ADT/tensor/Shape.h>
+#include <nncc/core/ADT/tensor/Buffer.h>
+#include <nncc/core/ADT/tensor/LexicalLayout.h>
+
+#include <gtest/gtest.h>
+
+using nncc::core::ADT::tensor::Shape;
+using nncc::core::ADT::tensor::LexicalLayout;
+using nncc::core::ADT::tensor::make_buffer;
+
+TEST(NodeExecution_Pull, check_data_ready)
+{
+  // Make graph with Pull node only
+  auto g = loco::make_graph();
+  auto pull = g->nodes()->create<loco::Pull>();
+
+  // Data not ready yet
+  ASSERT_ANY_THROW(locomotiv::NodeExecution::get().run(pull));
+
+  // Make and assign data to pull node
+  auto pull_buf = make_buffer<float, LexicalLayout>(Shape{1});
+  auto pull_data = locomotiv::make_data(pull_buf);
+  locomotiv::annot_data(pull, std::move(pull_data));
+
+  // Valid run
+  ASSERT_NO_THROW(locomotiv::NodeExecution::get().run(pull));
+}
index 5330810..5cdf787 100644 (file)
@@ -24,14 +24,19 @@ namespace locomotiv
 // TODO Use visitor pattern of loco when available
 void NodeExecution::run(loco::Node *node)
 {
-  if (as<loco::Push>(node))
+  if (as<loco::Pull>(node))
   {
-    execute(as<loco::Push>(node));
+    execute(as<loco::Pull>(node));
+    return;
   }
-  else
+
+  if (as<loco::Push>(node))
   {
-    throw std::runtime_error("Not supported loco::Node type");
+    execute(as<loco::Push>(node));
+    return;
   }
+
+  throw std::runtime_error("Not supported loco::Node type");
 }
 
 } // namespace locomotiv
index 8065bc9..0b3e7a3 100644 (file)
@@ -51,6 +51,7 @@ private:
    *
    * @note Definitions of overloaded execute() are in 'Node/' directory
    */
+  void execute(loco::Pull *);
   void execute(loco::Push *);
 };