[loco] Input/Output Index from Push/Pull node (#5961)
author박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 29 Jul 2019 11:13:19 +0000 (20:13 +0900)
committer오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 29 Jul 2019 11:13:19 +0000 (20:13 +0900)
* [loco] Input/Output Index from Push/Pull node

This commit revises Push/Pull node to store associated Graph-level
Input/Output index in it.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
* Fix typos

compiler/loco/include/loco/IR/Nodes.h
compiler/loco/src/IR/Nodes.cpp
compiler/loco/src/loco.test.cpp

index a1ce91e..0608c73 100644 (file)
 namespace loco
 {
 
+// TODO Find a proper location for these declarations
+using GraphInputIndex = uint32_t;
+using GraphOutputIndex = uint32_t;
+
 /**
  * @brief Make a value visible to user
  */
@@ -48,6 +52,22 @@ public:
 public:
   Node *from(void) const { return at(0)->node(); }
   void from(Node *node) { at(0)->node(node); }
+
+public:
+  void index(const GraphOutputIndex &index);
+
+  /**
+   * @brief Get associated output index
+   *
+   * The behavior of this method is undefined when "index" is not set before.
+   *
+   * NOTE This method intentionally returns "GraphOutputIndex" instead of "const GraphOutputIndex &"
+   *      not to expose the internal implementation details.
+   */
+  GraphOutputIndex index(void) const;
+
+private:
+  int64_t _index = -1; // Uninitialized
 };
 
 /**
@@ -59,6 +79,22 @@ class Pull /* from user */ final
 {
 public:
   Pull() = default;
+
+public:
+  void index(const GraphInputIndex &index);
+
+  /**
+   * @brief Get associated input index
+   *
+   * The behavior of this method is undefined when "index" is not set before.
+   *
+   * NOTE This method intentionally returns "GraphInputIndex" instead of "const GraphInputIndex &"
+   *      not to expose the internal implementation details.
+   */
+  GraphInputIndex index(void) const;
+
+private:
+  int64_t _index = -1; // Uninitialized
 };
 
 /**
index d9e44f4..0d46dbe 100644 (file)
 #include "loco/IR/Nodes.h"
 
 #include <cassert>
+#include <limits>
 
 // This file validates "Nodes.h". Please DO NOT remove this file.
 
 /**
+ * Push
+ */
+namespace loco
+{
+
+void Push::index(const GraphOutputIndex &index)
+{
+  // Push internally stores "GraphOutputIndex" as int64_t
+  _index = static_cast<int64_t>(index);
+}
+
+GraphOutputIndex Push::index(void) const
+{
+  assert(_index >= std::numeric_limits<GraphOutputIndex>::min());
+  assert(_index <= std::numeric_limits<GraphOutputIndex>::max());
+  return static_cast<GraphOutputIndex>(_index);
+}
+
+} // namespace loco
+
+/**
+ * Pull
+ */
+namespace loco
+{
+
+void Pull::index(const GraphInputIndex &index)
+{
+  // Push internally stores "GraphInputIndex" as int64_t
+  _index = static_cast<int64_t>(index);
+}
+
+GraphInputIndex Pull::index(void) const
+{
+  assert(_index >= std::numeric_limits<GraphInputIndex>::min());
+  assert(_index <= std::numeric_limits<GraphInputIndex>::max());
+  return static_cast<GraphInputIndex>(_index);
+}
+
+} // namespace loco
+
+/**
  * ConstGen
  */
 namespace loco
index 92d2541..31df9b1 100644 (file)
@@ -22,6 +22,8 @@
 //
 // What is "identity" network?
 // - A network simply passes its input as its output
+//
+// TODO Create "Ouput" first and then create "Push" later
 TEST(LOCO, identity_network)
 {
   auto g = loco::make_graph();
@@ -61,4 +63,14 @@ TEST(LOCO, identity_network)
 
   graph_output->name("output");
   graph_output->node(push_node);
+
+  // Set Input Index
+  pull_node->index(0);
+
+  ASSERT_EQ(pull_node->index(), 0);
+
+  // Set Output Index
+  push_node->index(0);
+
+  ASSERT_EQ(push_node->index(), 0);
 }