[coco] Introduce FeatureLayout interface (#1592)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 20 Sep 2018 02:25:22 +0000 (11:25 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 20 Sep 2018 02:25:22 +0000 (11:25 +0900)
This commit introduces FeatureLayout interface, and revises
FeatureObject to depend on this new interface instead of
GenericFeatureLayout.

Besides, this commit also revises GenericFeatureLayout to inherit
FeatureLayout interface, which removes the need for external code
update.

This change allows us to impliment and use optimized FeatureLayouts to
speed up compilation.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/FeatureLayout.h [new file with mode: 0644]
contrib/coco/core/include/coco/IR/FeatureObject.h
contrib/coco/core/include/coco/IR/GenericFeatureLayout.h

diff --git a/contrib/coco/core/include/coco/IR/FeatureLayout.h b/contrib/coco/core/include/coco/IR/FeatureLayout.h
new file mode 100644 (file)
index 0000000..5e5b0e1
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef __COCO_IR_FEATURE_LAYOUT_H__
+#define __COCO_IR_FEATURE_LAYOUT_H__
+
+#include "coco/IR/ElemID.h"
+
+#include <nncc/core/ADT/feature/Shape.h>
+
+namespace coco
+{
+
+/**
+ * @brief A FeatureLayout connects each feature index to a Bag element
+ *
+ * NOTE FeatureLayout is an immutable interface
+ */
+struct FeatureLayout
+{
+  virtual ~FeatureLayout() = default;
+
+  virtual uint32_t batch(void) const = 0;
+  virtual const nncc::core::ADT::feature::Shape &shape(void) const = 0;
+
+  virtual ElemID at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const = 0;
+};
+
+} // namespace coco
+
+#endif // __COCO_IR_FEATURE_LAYOUT_H__
index eb2437a..664e5f0 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "coco/IR/Object.h"
 #include "coco/IR/FeatureObjectInfo.h"
+#include "coco/IR/FeatureLayout.h"
 #include "coco/IR/GenericFeatureLayout.h"
 #include "coco/IR/ElemID.h"
 
@@ -36,12 +37,12 @@ public:
   ElemID at(uint32_t ch, uint32_t row, uint32_t col) const;
 
 public:
-  const GenericFeatureLayout *layout(void) const { return _layout.get(); }
-  void layout(std::unique_ptr<GenericFeatureLayout> &&l) { _layout = std::move(l); }
+  const FeatureLayout *layout(void) const { return _layout.get(); }
+  void layout(std::unique_ptr<FeatureLayout> &&l) { _layout = std::move(l); }
 
 private:
   std::unique_ptr<FeatureObjectInfo> _info;
-  std::unique_ptr<GenericFeatureLayout> _layout;
+  std::unique_ptr<FeatureLayout> _layout;
 };
 
 } // namespace coco
index 24aeab4..29179f1 100644 (file)
@@ -1,9 +1,8 @@
 #ifndef __COCO_IR_GENERIC_FEATURE_LAYOUT_H__
 #define __COCO_IR_GENERIC_FEATURE_LAYOUT_H__
 
-#include "coco/IR/ElemID.h"
+#include "coco/IR/FeatureLayout.h"
 
-#include <nncc/core/ADT/feature/Shape.h>
 #include <nncc/core/ADT/feature/Layout.h>
 
 #include <vector>
 namespace coco
 {
 
-class GenericFeatureLayout
+class GenericFeatureLayout final : public FeatureLayout
 {
 public:
   GenericFeatureLayout(const nncc::core::ADT::feature::Shape &shape);
 
 public:
-  uint32_t batch(void) const { return _batch; }
-  const nncc::core::ADT::feature::Shape &shape(void) const { return _shape; }
+  uint32_t batch(void) const override { return _batch; }
+  const nncc::core::ADT::feature::Shape &shape(void) const override { return _shape; }
 
   ElemID &at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col);
-  ElemID at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const;
+  ElemID at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const override;
 
   void reorder(const nncc::core::ADT::feature::Layout &l);