[coco] Rename GenericFeatureLayout (#1689)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 1 Oct 2018 06:29:21 +0000 (15:29 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 1 Oct 2018 06:29:21 +0000 (15:29 +0900)
This commit renames GenericFeatureLayout as FeatureLayouts::Generic
for naming consistency.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/FeatureLayouts.h
contrib/coco/core/include/coco/IR/FeatureObject.h
contrib/coco/core/include/coco/IR/GenericFeatureLayout.h [deleted file]
contrib/coco/core/src/IR/FeatureLayouts.cpp
contrib/coco/core/src/IR/FeatureObject.cpp
contrib/coco/core/src/IR/GenericFeatureLayout.cpp [deleted file]

index 53e8d81..54f7ad7 100644 (file)
@@ -19,6 +19,9 @@
 
 #include "coco/IR/FeatureLayout.h"
 
+#include <nncc/core/ADT/feature/Layout.h>
+
+#include <vector>
 #include <memory>
 
 namespace coco
@@ -82,6 +85,37 @@ public:
   static std::unique_ptr<BHWC> create(const nncc::core::ADT::feature::Shape &shape);
 };
 
+/**
+ * @brief Generic Feature Layout
+ */
+class Generic final : public FeatureLayout
+{
+public:
+  Generic(const nncc::core::ADT::feature::Shape &shape);
+
+public:
+  static const FeatureLayout::ID *uid(void);
+  const FeatureLayout::ID *id(void) const override { return uid(); }
+
+  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 override;
+
+  void reorder(const nncc::core::ADT::feature::Layout &l);
+
+private:
+  uint32_t offset(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const;
+
+private:
+  uint32_t _batch;
+  nncc::core::ADT::feature::Shape _shape;
+
+private:
+  std::vector<ElemID> _content;
+};
+
 } // namespace FeatureLayouts
 } // namespace coco
 
index aa3d890..e618526 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "coco/IR/Object.h"
 #include "coco/IR/FeatureLayout.h"
-#include "coco/IR/GenericFeatureLayout.h"
 #include "coco/IR/ElemID.h"
 
 #include <nncc/core/ADT/feature/Shape.h>
diff --git a/contrib/coco/core/include/coco/IR/GenericFeatureLayout.h b/contrib/coco/core/include/coco/IR/GenericFeatureLayout.h
deleted file mode 100644 (file)
index 6db0116..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.
- */
-
-#ifndef __COCO_IR_GENERIC_FEATURE_LAYOUT_H__
-#define __COCO_IR_GENERIC_FEATURE_LAYOUT_H__
-
-#include "coco/IR/FeatureLayout.h"
-
-#include <nncc/core/ADT/feature/Layout.h>
-
-#include <vector>
-
-namespace coco
-{
-
-class GenericFeatureLayout final : public FeatureLayout
-{
-public:
-  GenericFeatureLayout(const nncc::core::ADT::feature::Shape &shape);
-
-public:
-  static const FeatureLayout::ID *uid(void);
-  const FeatureLayout::ID *id(void) const override { return uid(); }
-
-  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 override;
-
-  void reorder(const nncc::core::ADT::feature::Layout &l);
-
-private:
-  uint32_t offset(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const;
-
-private:
-  uint32_t _batch;
-  nncc::core::ADT::feature::Shape _shape;
-
-private:
-  std::vector<ElemID> _content;
-};
-
-} // namespace coco
-
-#endif // __COCO_IR_GENERIC_FEATURE_LAYOUT_H__
index fca5124..325dcf5 100644 (file)
@@ -19,6 +19,8 @@
 #include <nncc/core/ADT/feature/CHWLayout.h>
 #include <nncc/core/ADT/feature/HWCLayout.h>
 
+#include <cassert>
+
 using namespace nncc::core::ADT::feature;
 
 //
@@ -93,3 +95,66 @@ std::unique_ptr<BHWC> BHWC::create(const nncc::core::ADT::feature::Shape &shape)
 
 } // namespace FeatureLayouts
 } // namespace coco
+
+//
+// Generic Layout
+//
+namespace coco
+{
+namespace FeatureLayouts
+{
+
+Generic::Generic(const nncc::core::ADT::feature::Shape &shape) : _batch{1}, _shape{shape}
+{
+  _content.resize(_batch * num_elements(_shape));
+}
+
+const FeatureLayout::ID *Generic::uid(void)
+{
+  struct LayoutID final : public FeatureLayout::ID
+  {
+  };
+  static LayoutID id;
+  return &id;
+}
+
+uint32_t Generic::offset(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const
+{
+  static nncc::core::ADT::feature::CHWLayout l{};
+
+  uint32_t res = 0;
+
+  res += b * num_elements(_shape);
+  res += l.offset(shape(), ch, row, col);
+
+  return res;
+}
+
+ElemID &Generic::at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col)
+{
+  return _content.at(offset(b, ch, row, col));
+}
+
+ElemID Generic::at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const
+{
+  return _content.at(offset(b, ch, row, col));
+}
+
+void Generic::reorder(const nncc::core::ADT::feature::Layout &l)
+{
+  assert(_batch == 1);
+
+  for (uint32_t ch = 0; ch < shape().depth(); ++ch)
+  {
+    for (uint32_t row = 0; row < shape().height(); ++row)
+    {
+      for (uint32_t col = 0; col < shape().width(); ++col)
+      {
+        at(0, ch, row, col) = ElemID{l.offset(shape(), ch, row, col)};
+      }
+    }
+  }
+}
+
+} // namespace FeatureLayouts
+} // namespace coco
index 550a0a5..ca1bf5e 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "coco/IR/FeatureObject.h"
+#include "coco/IR/FeatureLayouts.h"
 
 #include <nncc/core/ADT/feature/CHWLayout.h>
 #include <nncc/foundation/Memory.h>
@@ -28,7 +29,7 @@ namespace coco
 
 FeatureObject::FeatureObject(const nncc::core::ADT::feature::Shape &shape)
 {
-  _layout = make_unique<GenericFeatureLayout>(shape);
+  _layout = make_unique<FeatureLayouts::Generic>(shape);
 }
 
 FeatureObject::~FeatureObject()
diff --git a/contrib/coco/core/src/IR/GenericFeatureLayout.cpp b/contrib/coco/core/src/IR/GenericFeatureLayout.cpp
deleted file mode 100644 (file)
index bafab0c..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.
- */
-
-#include "coco/IR/GenericFeatureLayout.h"
-
-#include <nncc/core/ADT/feature/CHWLayout.h>
-
-#include <cassert>
-
-using nncc::core::ADT::feature::num_elements;
-
-namespace coco
-{
-
-GenericFeatureLayout::GenericFeatureLayout(const nncc::core::ADT::feature::Shape &shape)
-    : _batch{1}, _shape{shape}
-{
-  _content.resize(_batch * num_elements(_shape));
-}
-
-const FeatureLayout::ID *GenericFeatureLayout::uid(void)
-{
-  struct LayoutID final : public FeatureLayout::ID
-  {
-  };
-  static LayoutID id;
-  return &id;
-}
-
-uint32_t GenericFeatureLayout::offset(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const
-{
-  static nncc::core::ADT::feature::CHWLayout l{};
-
-  uint32_t res = 0;
-
-  res += b * num_elements(_shape);
-  res += l.offset(shape(), ch, row, col);
-
-  return res;
-}
-
-ElemID &GenericFeatureLayout::at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col)
-{
-  return _content.at(offset(b, ch, row, col));
-}
-
-ElemID GenericFeatureLayout::at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const
-{
-  return _content.at(offset(b, ch, row, col));
-}
-
-void GenericFeatureLayout::reorder(const nncc::core::ADT::feature::Layout &l)
-{
-  assert(_batch == 1);
-
-  for (uint32_t ch = 0; ch < shape().depth(); ++ch)
-  {
-    for (uint32_t row = 0; row < shape().height(); ++row)
-    {
-      for (uint32_t col = 0; col < shape().width(); ++col)
-      {
-        at(0, ch, row, col) = ElemID{l.offset(shape(), ch, row, col)};
-      }
-    }
-  }
-}
-
-} // namespace coco