From c30e83139cb1b35009e6c78a673a3fb756e7c2e2 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: Fri, 31 Aug 2018 09:29:19 +0900 Subject: [PATCH] [nnop] Use internal PadInfo and StrideInfo (#1260) This commit introduces nnop-internal PadInfo and StrideInfo class, and revises conv method to use these internal classes. Signed-off-by: Jonghyun Park --- contrib/nnop/include/nnop/Conv2D.h | 8 ++++---- contrib/nnop/include/nnop/PadInfo.h | 33 +++++++++++++++++++++++++++++++++ contrib/nnop/include/nnop/StrideInfo.h | 28 ++++++++++++++++++++++++++++ contrib/nnop/src/Conv2D.test.cpp | 1 + contrib/nnop/src/PadInfo.test.cpp | 18 ++++++++++++++++++ contrib/nnop/src/StrideInfo.test.cpp | 14 ++++++++++++++ 6 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 contrib/nnop/include/nnop/PadInfo.h create mode 100644 contrib/nnop/include/nnop/StrideInfo.h create mode 100644 contrib/nnop/src/PadInfo.test.cpp create mode 100644 contrib/nnop/src/StrideInfo.test.cpp diff --git a/contrib/nnop/include/nnop/Conv2D.h b/contrib/nnop/include/nnop/Conv2D.h index 4022a18..ab140c5 100644 --- a/contrib/nnop/include/nnop/Conv2D.h +++ b/contrib/nnop/include/nnop/Conv2D.h @@ -1,6 +1,9 @@ #ifndef __NNOP_CONV2D_H__ #define __NNOP_CONV2D_H__ +#include "nnop/PadInfo.h" +#include "nnop/StrideInfo.h" + #include #include #include @@ -8,9 +11,6 @@ #include #include -#include -#include - namespace nnop { @@ -21,7 +21,7 @@ void conv(const nncc::core::ADT::feature::Shape &out_shape, const nncc::core::ADT::feature::Reader &in_data, const nncc::core::ADT::kernel::Shape &ker_shape, const nncc::core::ADT::kernel::Reader &ker_data, - const nncc::core::ADT::PadInfo &pad_info, const nncc::core::ADT::StrideInfo &stride_info) + const PadInfo &pad_info, const StrideInfo &stride_info) { for (uint32_t out_ch = 0; out_ch < out_shape.depth(); ++out_ch) { diff --git a/contrib/nnop/include/nnop/PadInfo.h b/contrib/nnop/include/nnop/PadInfo.h new file mode 100644 index 0000000..e5a902f --- /dev/null +++ b/contrib/nnop/include/nnop/PadInfo.h @@ -0,0 +1,33 @@ +#ifndef __NNOP_PAD_INFO_H__ +#define __NNOP_PAD_INFO_H__ + +#include + +namespace nnop +{ + +class PadInfo +{ +public: + PadInfo(uint32_t top, uint32_t bottom, uint32_t left, uint32_t right) + : _top{top}, _bottom{bottom}, _left{left}, _right{right} + { + // DO NOTHING + } + +public: + uint32_t top(void) const { return _top; } + uint32_t bottom(void) const { return _bottom; } + uint32_t left(void) const { return _left; } + uint32_t right(void) const { return _right; } + +private: + uint32_t _top; + uint32_t _bottom; + uint32_t _left; + uint32_t _right; +}; + +} // namespace nnop + +#endif // __NNCC_CORE_PAD_INFO_H__ diff --git a/contrib/nnop/include/nnop/StrideInfo.h b/contrib/nnop/include/nnop/StrideInfo.h new file mode 100644 index 0000000..ec13491 --- /dev/null +++ b/contrib/nnop/include/nnop/StrideInfo.h @@ -0,0 +1,28 @@ +#ifndef __NNOP_STRIDE_INFO_H__ +#define __NNOP_STRIDE_INFO_H__ + +#include + +namespace nnop +{ + +class StrideInfo +{ +public: + StrideInfo(uint32_t vertical, uint32_t horizontal) : _vertical{vertical}, _horizontal{horizontal} + { + // DO NOTHING + } + +public: + uint32_t vertical(void) const { return _vertical; } + uint32_t horizontal(void) const { return _horizontal; } + +private: + uint32_t _horizontal; + uint32_t _vertical; +}; + +} // namespace nncc + +#endif // __NNOP_STRIDE_INFO_H__ diff --git a/contrib/nnop/src/Conv2D.test.cpp b/contrib/nnop/src/Conv2D.test.cpp index b37aa62..e6f08fa 100644 --- a/contrib/nnop/src/Conv2D.test.cpp +++ b/contrib/nnop/src/Conv2D.test.cpp @@ -8,6 +8,7 @@ #include +using namespace nnop; using namespace nncc::core::ADT; TEST(CONV2D, conv_1) diff --git a/contrib/nnop/src/PadInfo.test.cpp b/contrib/nnop/src/PadInfo.test.cpp new file mode 100644 index 0000000..62b5943 --- /dev/null +++ b/contrib/nnop/src/PadInfo.test.cpp @@ -0,0 +1,18 @@ +#include "nnop/PadInfo.h" + +#include + +TEST(PAD_INFO, explicit_constructor) +{ + const uint32_t top = 3; + const uint32_t bottom = 4; + const uint32_t left = 5; + const uint32_t right = 6; + + nnop::PadInfo pad_info{top, bottom, left, right}; + + ASSERT_EQ(pad_info.top(), top); + ASSERT_EQ(pad_info.bottom(), bottom); + ASSERT_EQ(pad_info.left(), left); + ASSERT_EQ(pad_info.right(), right); +} diff --git a/contrib/nnop/src/StrideInfo.test.cpp b/contrib/nnop/src/StrideInfo.test.cpp new file mode 100644 index 0000000..802104c --- /dev/null +++ b/contrib/nnop/src/StrideInfo.test.cpp @@ -0,0 +1,14 @@ +#include "nnop/StrideInfo.h" + +#include + +TEST(STRIDE_INFO, explicit_constructor) +{ + const uint32_t vertical = 3; + const uint32_t horizontal = 4; + + nnop::StrideInfo stride_info{vertical, horizontal}; + + ASSERT_EQ(stride_info.vertical(), vertical); + ASSERT_EQ(stride_info.horizontal(), horizontal); +} -- 2.7.4