From 9b62c6eff0713ae5fb51ed1bc61d8bd81dcd365f Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Thu, 26 Jul 2018 10:57:14 +0900 Subject: [PATCH] [nncc.core.ADT] Add 'feature::HWCLayout' (#811) 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 --- .../core/include/nncc/core/ADT/feature/HWCLayout.h | 25 +++++++++++++ libs/core/src/ADT/feature/HWCLayout.cpp | 27 ++++++++++++++ libs/core/src/ADT/feature/HWCLayout.test.cpp | 41 ++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 libs/core/include/nncc/core/ADT/feature/HWCLayout.h create mode 100644 libs/core/src/ADT/feature/HWCLayout.cpp create mode 100644 libs/core/src/ADT/feature/HWCLayout.test.cpp 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 index 0000000..d5dec97 --- /dev/null +++ b/libs/core/include/nncc/core/ADT/feature/HWCLayout.h @@ -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 index 0000000..6487a9f --- /dev/null +++ b/libs/core/src/ADT/feature/HWCLayout.cpp @@ -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 index 0000000..0e60605 --- /dev/null +++ b/libs/core/src/ADT/feature/HWCLayout.test.cpp @@ -0,0 +1,41 @@ +#include "nncc/core/ADT/feature/HWCLayout.h" + +#include + +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)); +} -- 2.7.4