From 9ae1b8491d7d79142ad9465dc6733775b9abd205 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: Mon, 2 Jul 2018 10:24:17 +0900 Subject: [PATCH] Add 'nnsuite' project (#410) This commit adds 'nnsuite' project which will includes various in-memory NN models for testing. Currently, 'nnsuite' includes a simple model consists of one Conv2D operation. Signed-off-by: Jonghyun Park --- contrib/nnsuite/.FORMATCHECKED | 0 contrib/nnsuite/CMakeLists.txt | 1 + contrib/nnsuite/conv/CMakeLists.txt | 6 +++ contrib/nnsuite/conv/include/nnsuite/conv/Model.h | 37 +++++++++++++++ .../conv/include/nnsuite/conv/RandomModel.h | 54 ++++++++++++++++++++++ contrib/nnsuite/conv/src/RandomModel.cpp | 42 +++++++++++++++++ 6 files changed, 140 insertions(+) create mode 100644 contrib/nnsuite/.FORMATCHECKED create mode 100644 contrib/nnsuite/CMakeLists.txt create mode 100644 contrib/nnsuite/conv/CMakeLists.txt create mode 100644 contrib/nnsuite/conv/include/nnsuite/conv/Model.h create mode 100644 contrib/nnsuite/conv/include/nnsuite/conv/RandomModel.h create mode 100644 contrib/nnsuite/conv/src/RandomModel.cpp diff --git a/contrib/nnsuite/.FORMATCHECKED b/contrib/nnsuite/.FORMATCHECKED new file mode 100644 index 0000000..e69de29 diff --git a/contrib/nnsuite/CMakeLists.txt b/contrib/nnsuite/CMakeLists.txt new file mode 100644 index 0000000..5ea6cda --- /dev/null +++ b/contrib/nnsuite/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectories() diff --git a/contrib/nnsuite/conv/CMakeLists.txt b/contrib/nnsuite/conv/CMakeLists.txt new file mode 100644 index 0000000..a2c28ee --- /dev/null +++ b/contrib/nnsuite/conv/CMakeLists.txt @@ -0,0 +1,6 @@ +file(GLOB_RECURSE SOURCES "src/*.cpp") + +add_library(nnsuite_conv STATIC ${SOURCES}) +set_target_properties(nnsuite_conv PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(nnsuite_conv PUBLIC include) +target_link_libraries(nnsuite_conv PUBLIC nncc_core) diff --git a/contrib/nnsuite/conv/include/nnsuite/conv/Model.h b/contrib/nnsuite/conv/include/nnsuite/conv/Model.h new file mode 100644 index 0000000..37e4544 --- /dev/null +++ b/contrib/nnsuite/conv/include/nnsuite/conv/Model.h @@ -0,0 +1,37 @@ +#ifndef __NNSUITE_CONV_MODEL_H__ +#define __NNSUITE_CONV_MODEL_H__ + +#include +#include +#include + +#include + +namespace nnsuite +{ +namespace conv +{ + +struct Model +{ + virtual ~Model() = default; + + virtual const nncc::core::ADT::feature::Shape &ifm_shape(void) const = 0; + virtual const std::string &ifm_name(void) const = 0; + + virtual const nncc::core::ADT::feature::Shape &ofm_shape(void) const = 0; + virtual const std::string &ofm_name(void) const = 0; + + virtual const nncc::core::ADT::kernel::Shape &ker_shape(void) const = 0; + virtual const nncc::core::ADT::kernel::Reader &ker_data(void) const = 0; + + // TODO Support padding configuration + // TODO Support stride configuration +}; + +// TODO Support model validation + +} // namespace conv +} // namespace nnsuite + +#endif // __NNSUITE_CONV_MODEL_H__ diff --git a/contrib/nnsuite/conv/include/nnsuite/conv/RandomModel.h b/contrib/nnsuite/conv/include/nnsuite/conv/RandomModel.h new file mode 100644 index 0000000..a0273ba --- /dev/null +++ b/contrib/nnsuite/conv/include/nnsuite/conv/RandomModel.h @@ -0,0 +1,54 @@ +#ifndef __NNSUITE_CONV2D_RANDOM_MODEL_H__ +#define __NNSUTIE_CONV2D_RANDOM_MODEL_H__ + +#include "nnsuite/conv/Model.h" + +#include + +#include + +namespace nnsuite +{ +namespace conv +{ + +class RandomModel final : public Model +{ +public: + explicit RandomModel(int32_t seed); + +public: + const nncc::core::ADT::feature::Shape &ifm_shape(void) const override { return _ifm_shape; } + const std::string &ifm_name(void) const override { return _ifm_name; } + +public: + const nncc::core::ADT::feature::Shape &ofm_shape(void) const override { return _ofm_shape; } + const std::string &ofm_name(void) const override { return _ofm_name; } + +public: + const nncc::core::ADT::kernel::Shape &ker_shape(void) const override + { + return _ker_buffer.shape(); + } + + const nncc::core::ADT::kernel::Reader &ker_data(void) const override + { + return _ker_buffer; + } + +private: + const nncc::core::ADT::feature::Shape _ifm_shape; + const std::string _ifm_name; + +private: + const nncc::core::ADT::feature::Shape _ofm_shape; + const std::string _ofm_name; + +private: + nncc::core::ADT::kernel::Buffer _ker_buffer; +}; + +} // namespace conv +} // namespace nnsuite + +#endif // __NNSUTIE_CONV2D_RANDOM_MODEL_H__ diff --git a/contrib/nnsuite/conv/src/RandomModel.cpp b/contrib/nnsuite/conv/src/RandomModel.cpp new file mode 100644 index 0000000..f46e600 --- /dev/null +++ b/contrib/nnsuite/conv/src/RandomModel.cpp @@ -0,0 +1,42 @@ +#include "nnsuite/conv/RandomModel.h" + +#include + +#include + +using namespace nncc::core::ADT; + +namespace nnsuite +{ +namespace conv +{ + +RandomModel::RandomModel(int32_t seed) + : _ifm_shape{1, 8, 8}, _ifm_name{"ifm"}, _ofm_name{"ofm"}, _ofm_shape{2, 6, 6}, + _ker_buffer{kernel::Shape{2, 1, 3, 3}, kernel::NCHWLayout{}} +{ + std::default_random_engine gen{seed}; + std::normal_distribution dist{0.0f, 1.0f}; + + const uint32_t N = _ker_buffer.shape().count(); + const uint32_t C = _ker_buffer.shape().depth(); + const uint32_t H = _ker_buffer.shape().height(); + const uint32_t W = _ker_buffer.shape().width(); + + for (uint32_t n = 0; n < N; ++n) + { + for (uint32_t ch = 0; ch < C; ++ch) + { + for (uint32_t row = 0; row < H; ++row) + { + for (uint32_t col = 0; col < W; ++col) + { + _ker_buffer.at(n, ch, row, col) = dist(gen); + } + } + } + } +} + +} // namespace conv +} // namespace nnsuite -- 2.7.4