[nncc.core.ADT] Add 'feature::HWCLayout' (#811)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 26 Jul 2018 01:57:14 +0000 (10:57 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 26 Jul 2018 01:57:14 +0000 (10:57 +0900)
This commit implements 'feature::HWCLayout' class which allows us to
compute the offset on the flat array that uses HWC ordering.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
libs/core/include/nncc/core/ADT/feature/HWCLayout.h [new file with mode: 0644]
libs/core/src/ADT/feature/HWCLayout.cpp [new file with mode: 0644]
libs/core/src/ADT/feature/HWCLayout.test.cpp [new file with mode: 0644]

diff --git a/libs/core/include/nncc/core/ADT/feature/HWCLayout.h b/libs/core/include/nncc/core/ADT/feature/HWCLayout.h
new file mode 100644 (file)
index 0000000..d5dec97
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef __NNCC_CORE_ADT_FEATURE_HWC_LAYOUT_H__
+#define __NNCC_CORE_ADT_FEATURE_HWC_LAYOUT_H__
+
+#include "nncc/core/ADT/feature/Layout.h"
+
+namespace nncc
+{
+namespace core
+{
+namespace ADT
+{
+namespace feature
+{
+
+struct HWCLayout final : public Layout
+{
+  HWCLayout();
+};
+
+} // namespace feature
+} // namespace ADT
+} // namespace core
+} // namespace nncc
+
+#endif // __NNCC_CORE_ADT_FEATURE_HWC_LAYOUT_H__
diff --git a/libs/core/src/ADT/feature/HWCLayout.cpp b/libs/core/src/ADT/feature/HWCLayout.cpp
new file mode 100644 (file)
index 0000000..6487a9f
--- /dev/null
@@ -0,0 +1,27 @@
+#include "nncc/core/ADT/feature/HWCLayout.h"
+
+using nncc::core::ADT::feature::Shape;
+
+static uint32_t HWC_offset(const Shape &shape, uint32_t ch, uint32_t row, uint32_t col)
+{
+  return (row * shape.width() + col) * shape.depth() + ch;
+}
+
+namespace nncc
+{
+namespace core
+{
+namespace ADT
+{
+namespace feature
+{
+
+HWCLayout::HWCLayout() : Layout{HWC_offset}
+{
+  // DO NOTHING
+}
+
+} // namespace feature
+} // namespace ADT
+} // namespace core
+} // namespace nncc
diff --git a/libs/core/src/ADT/feature/HWCLayout.test.cpp b/libs/core/src/ADT/feature/HWCLayout.test.cpp
new file mode 100644 (file)
index 0000000..0e60605
--- /dev/null
@@ -0,0 +1,41 @@
+#include "nncc/core/ADT/feature/HWCLayout.h"
+
+#include <gtest/gtest.h>
+
+using namespace nncc::core::ADT::feature;
+
+TEST(ADT_FEATURE_HWC_LAYOUT, C_increase)
+{
+  const uint32_t C = 4;
+  const uint32_t H = 3;
+  const uint32_t W = 6;
+
+  const Shape shape{C, H, W};
+  const HWCLayout l;
+
+  ASSERT_EQ(l.offset(shape, 1, 1, 1) + 1, l.offset(shape, 2, 1, 1));
+}
+
+TEST(ADT_FEATURE_HWC_LAYOUT, W_increase)
+{
+  const uint32_t C = 4;
+  const uint32_t H = 3;
+  const uint32_t W = 6;
+
+  const Shape shape{C, H, W};
+  const HWCLayout l;
+
+  ASSERT_EQ(l.offset(shape, 1, 2, 1) + C, l.offset(shape, 1, 2, 2));
+}
+
+TEST(ADT_FEATURE_HWC_LAYOUT, H_increase)
+{
+  const uint32_t C = 4;
+  const uint32_t H = 3;
+  const uint32_t W = 6;
+
+  const Shape shape{C, H, W};
+  const HWCLayout l;
+
+  ASSERT_EQ(l.offset(shape, 1, 1, 1) + W * C, l.offset(shape, 1, 2, 1));
+}