[nnop] Use internal PadInfo and StrideInfo (#1260)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Fri, 31 Aug 2018 00:29:19 +0000 (09:29 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Fri, 31 Aug 2018 00:29:19 +0000 (09:29 +0900)
This commit introduces nnop-internal PadInfo and StrideInfo class, and
revises conv method to use these internal classes.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/nnop/include/nnop/Conv2D.h
contrib/nnop/include/nnop/PadInfo.h [new file with mode: 0644]
contrib/nnop/include/nnop/StrideInfo.h [new file with mode: 0644]
contrib/nnop/src/Conv2D.test.cpp
contrib/nnop/src/PadInfo.test.cpp [new file with mode: 0644]
contrib/nnop/src/StrideInfo.test.cpp [new file with mode: 0644]

index 4022a18..ab140c5 100644 (file)
@@ -1,6 +1,9 @@
 #ifndef __NNOP_CONV2D_H__
 #define __NNOP_CONV2D_H__
 
+#include "nnop/PadInfo.h"
+#include "nnop/StrideInfo.h"
+
 #include <nncc/core/ADT/feature/Shape.h>
 #include <nncc/core/ADT/feature/Reader.h>
 #include <nncc/core/ADT/feature/Accessor.h>
@@ -8,9 +11,6 @@
 #include <nncc/core/ADT/kernel/Shape.h>
 #include <nncc/core/ADT/kernel/Reader.h>
 
-#include <nncc/core/ADT/PadInfo.h>
-#include <nncc/core/ADT/StrideInfo.h>
-
 namespace nnop
 {
 
@@ -21,7 +21,7 @@ void conv(const nncc::core::ADT::feature::Shape &out_shape,
           const nncc::core::ADT::feature::Reader<InputDType> &in_data,
           const nncc::core::ADT::kernel::Shape &ker_shape,
           const nncc::core::ADT::kernel::Reader<KernelDType> &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 (file)
index 0000000..e5a902f
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef __NNOP_PAD_INFO_H__
+#define __NNOP_PAD_INFO_H__
+
+#include <cstdint>
+
+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 (file)
index 0000000..ec13491
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef __NNOP_STRIDE_INFO_H__
+#define __NNOP_STRIDE_INFO_H__
+
+#include <cstdint>
+
+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__
index b37aa62..e6f08fa 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <gtest/gtest.h>
 
+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 (file)
index 0000000..62b5943
--- /dev/null
@@ -0,0 +1,18 @@
+#include "nnop/PadInfo.h"
+
+#include <gtest/gtest.h>
+
+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 (file)
index 0000000..802104c
--- /dev/null
@@ -0,0 +1,14 @@
+#include "nnop/StrideInfo.h"
+
+#include <gtest/gtest.h>
+
+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);
+}