From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Wed, 27 Jun 2018 01:23:11 +0000 (+0900) Subject: [core.ADT.feature] Introduce Layout interface (#289) X-Git-Tag: nncc_backup~2572 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4e431d2560c8ce024b57035e337147fde4394a22;p=platform%2Fcore%2Fml%2Fnnfw.git [core.ADT.feature] Introduce Layout interface (#289) This commit introduces 'nncc::core::ADT::feature::Layout' interface which is almost same as tensor::Layout but specialized for feature map that convolution uses. This commit also introduces 'CHWLayout' as an example. Signed-off-by: Jonghyun Park --- diff --git a/libs/core/include/nncc/core/ADT/feature/CHWLayout.h b/libs/core/include/nncc/core/ADT/feature/CHWLayout.h new file mode 100644 index 0000000..2f97755 --- /dev/null +++ b/libs/core/include/nncc/core/ADT/feature/CHWLayout.h @@ -0,0 +1,25 @@ +#ifndef __NNCC_CORE_ADT_FEATURE_CHW_LAYOUT_H__ +#define __NNCC_CORE_ADT_FEATURE_CHW_LAYOUT_H__ + +#include "nncc/core/ADT/feature/Layout.h" + +namespace nncc +{ +namespace core +{ +namespace ADT +{ +namespace feature +{ + +struct CHWLayout final : public Layout +{ + uint32_t offset(const Shape &, uint32_t ch, uint32_t row, uint32_t col) const override; +}; + +} // namespace feature +} // namespace ADT +} // namespace core +} // namespace nncc + +#endif // __NNCC_CORE_ADT_FEATURE_CHW_LAYOUT_H__ diff --git a/libs/core/include/nncc/core/ADT/feature/Layout.h b/libs/core/include/nncc/core/ADT/feature/Layout.h new file mode 100644 index 0000000..85e3174 --- /dev/null +++ b/libs/core/include/nncc/core/ADT/feature/Layout.h @@ -0,0 +1,27 @@ +#ifndef __NNCC_CORE_ADT_FEATURE_LAYOUT_H__ +#define __NNCC_CORE_ADT_FEATURE_LAYOUT_H__ + +#include "nncc/core/ADT/feature/Shape.h" + +namespace nncc +{ +namespace core +{ +namespace ADT +{ +namespace feature +{ + +struct Layout +{ + virtual ~Layout() = default; + + virtual uint32_t offset(const Shape &, uint32_t ch, uint32_t row, uint32_t col) const = 0; +}; + +} // namespace feature +} // namespace ADT +} // namespace core +} // namespace nncc + +#endif // __NNCC_CORE_ADT_FEATURE_LAYOUT_H__ diff --git a/libs/core/src/ADT/feature/CHWLayout.cpp b/libs/core/src/ADT/feature/CHWLayout.cpp new file mode 100644 index 0000000..16ce6c6 --- /dev/null +++ b/libs/core/src/ADT/feature/CHWLayout.cpp @@ -0,0 +1,20 @@ +#include "nncc/core/ADT/feature/CHWLayout.h" + +namespace nncc +{ +namespace core +{ +namespace ADT +{ +namespace feature +{ + +uint32_t CHWLayout::offset(const Shape &shape, uint32_t ch, uint32_t row, uint32_t col) const +{ + return (ch * shape.height() + row) * shape.width() + col; +} + +} // namespace feature +} // namespace ADT +} // namespace core +} // namespace nncc diff --git a/libs/core/src/ADT/feature/CHWLayout.test.cpp b/libs/core/src/ADT/feature/CHWLayout.test.cpp new file mode 100644 index 0000000..292257f --- /dev/null +++ b/libs/core/src/ADT/feature/CHWLayout.test.cpp @@ -0,0 +1,29 @@ +#include "nncc/core/ADT/feature/CHWLayout.h" + +#include + +using namespace nncc::core::ADT::feature; + +TEST(ADT_FEATURE_CHW_LAYOUT, col_increase) +{ + const Shape shape{4, 3, 6}; + const CHWLayout l; + + ASSERT_EQ(l.offset(shape, 1, 2, 1) + 1, l.offset(shape, 1, 2, 2)); +} + +TEST(ADT_FEATURE_CHW_LAYOUT, row_increase) +{ + const Shape shape{4, 3, 6}; + const CHWLayout l; + + ASSERT_EQ(l.offset(shape, 1, 1, 1) + 6, l.offset(shape, 1, 2, 1)); +} + +TEST(ADT_FEATURE_CHW_LAYOUT, ch_increase) +{ + const Shape shape{4, 3, 6}; + const CHWLayout l; + + ASSERT_EQ(l.offset(shape, 1, 1, 1) + 6 * 3, l.offset(shape, 2, 1, 1)); +}