Introduce ParentInfo class (#3401)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Tue, 30 Oct 2018 07:58:47 +0000 (16:58 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 30 Oct 2018 07:58:47 +0000 (16:58 +0900)
Introduce ParentInfo class to represent parent tensor information
Add field in neurun::graph::operand::Object for ParentInfo

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
runtimes/neurun/src/graph/operand/Object.cc
runtimes/neurun/src/graph/operand/Object.h
runtimes/neurun/src/graph/operand/ParentInfo.h [new file with mode: 0644]

index 06da807..6b0926b 100644 (file)
@@ -114,6 +114,15 @@ const LowerInfo *Object::lower_info() const { return _lower_info.get(); }
 
 LowerInfo *Object::lower_info() { return _lower_info.get(); }
 
+void Object::parent_info(std::unique_ptr<ParentInfo> &&parent_info)
+{
+  _parent_info = std::move(parent_info);
+}
+
+const ParentInfo *Object::parent_info() const { return _parent_info.get(); }
+
+ParentInfo *Object::parent_info() { return _parent_info.get(); }
+
 } // namespace operand
 } // namespace graph
 } // namespace neurun
index c8fb13a..cde1acc 100644 (file)
@@ -26,6 +26,7 @@
 #include "Data.h"
 #include "TypeInfo.h"
 #include "LowerInfo.h"
+#include "ParentInfo.h"
 #include "graph/operation/IndexList.h"
 
 namespace neurun
@@ -98,6 +99,21 @@ public:
   void lower_info(std::unique_ptr<LowerInfo> &&lower_info);
   const LowerInfo *lower_info() const;
   LowerInfo *lower_info();
+  /**
+   * @brief     Set parent information
+   * @param[in] parent_info Parent information
+   */
+  void parent_info(std::unique_ptr<ParentInfo> &&parent_info);
+  /**
+   * @brief   Return parent information pointer as constant
+   * @return  Parent information pointer
+   */
+  const ParentInfo *parent_info() const;
+  /**
+   * @brief   Return parent information pointer
+   * @return  Perent information pointer
+   */
+  ParentInfo *parent_info();
 
 private:
   const Shape _shape;
@@ -109,6 +125,7 @@ private:
   operation::IndexList _def; // size is 0 (constant) or 1 (from def operation)
 
   std::unique_ptr<LowerInfo> _lower_info;
+  std::unique_ptr<ParentInfo> _parent_info;
 };
 
 } // namespace operand
diff --git a/runtimes/neurun/src/graph/operand/ParentInfo.h b/runtimes/neurun/src/graph/operand/ParentInfo.h
new file mode 100644 (file)
index 0000000..74bfe11
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2018 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.
+ */
+
+/**
+ * @file  ParentInfo.h
+ * @brief This file contains ParentInfo class and internal Coordinate4D class
+ *        to represent subsumption between operand
+ */
+
+#ifndef __NEURUN_GRAPH_OPERAND_PARENT_INFO_H__
+#define __NEURUN_GRAPH_OPERAND_PARENT_INFO_H__
+
+#include <stdint.h>
+
+#include "Index.h"
+
+namespace neurun
+{
+namespace graph
+{
+namespace operand
+{
+
+/**
+ * @brief      Class to represent parent operand in child operand
+ */
+class ParentInfo
+{
+public:
+  /**
+   * @brief    Class to represent position(offset) of subtensor.\n
+   *        Assume that parent and child are already lowered (can get Shape4D).
+   */
+  class Coordinate4D
+  {
+  public:
+    /**
+     * @brief Construct a new Coordinate4D object
+     */
+    Coordinate4D(void) : _n{0}, _h{0}, _w{0}, _c{0}
+    {
+      // DO NOTHING
+    }
+    /**
+     * @brief     Construct a new Coordinate4D object
+     * @param[in] n Batch offset
+     * @param[in] h Height offset
+     * @param[in] w Width offset
+     * @param[in] c Channel offset
+     * @return
+     */
+    Coordinate4D(int32_t n, int32_t h, int32_t w, int32_t c) : _n{n}, _h{h}, _w{w}, _c{c}
+    {
+      // DO NOTHING
+    }
+
+  public:
+    /**
+     * @brief   Return batch offset
+     * @return  Batch offset
+     */
+    int32_t n(void) const { return _n; }
+    /**
+     * @brief   Return height offset
+     * @return  Height offset
+     */
+    int32_t h(void) const { return _h; }
+    /**
+     * @brief   Return width offset
+     * @return  Width offset
+     */
+    int32_t w(void) const { return _w; }
+    /**
+     * @brief   Return channel offset
+     * @return  Channel offset
+     */
+    int32_t c(void) const { return _c; }
+
+  private:
+    int32_t _n;
+    int32_t _h;
+    int32_t _w;
+    int32_t _c;
+  };
+
+public:
+  /**
+   * @brief     Construct a new ParentInfo object
+   * @param[in] parent      Index of parent operand
+   * @param[in] coordinate  Offset of child operand in parent operand
+   * @return
+   */
+  ParentInfo(const Index parent, const Coordinate4D &coordinate)
+      : _parent{parent}, _coordinate{coordinate}
+  {
+    // DO NOTHING
+  }
+
+public:
+  /**
+   * @brief   Return parent index
+   * @return  Parent index
+   */
+  Index parent(void) const { return _parent; }
+  /**
+   * @brief   Retern offset in parent
+   * @return  Offset
+   */
+  Coordinate4D offset(void) const { return _coordinate; }
+
+private:
+  Index _parent;
+  Coordinate4D _coordinate;
+};
+
+} // namespace operand
+} // namespace graph
+} // namespace neurun
+
+#endif // __NEURUN_GRAPH_OPERAND_PARENT_INFO_H__