From 01554ef79f81719a840193a0b89376161275be8e 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, 11 Oct 2018 13:48:54 +0900 Subject: [PATCH] Relocate nnkit backends for nnsuite conv model (#1828) Now, the implementation of nnkit backends for nnsuite conv model lives in nnsuite directory (not in nnkit directory). Signed-off-by: Jonghyun Park --- contrib/nnkit/CMakeLists.txt | 1 - contrib/nnkit/contrib/CMakeLists.txt | 1 - contrib/nnkit/contrib/nnsuite/CMakeLists.txt | 1 - contrib/nnkit/contrib/nnsuite/conv/CMakeLists.txt | 2 -- contrib/nnsuite/conv/CMakeLists.txt | 9 +++------ contrib/nnsuite/conv/model/CMakeLists.txt | 6 ++++++ .../conv/{ => model}/include/nnsuite/conv/Model.h | 0 .../{ => model}/include/nnsuite/conv/RandomModel.h | 0 .../nnsuite/conv/{ => model}/src/RandomModel.cpp | 0 .../conv/nnkit-caffe}/CMakeLists.txt | 0 .../conv/nnkit-caffe}/ConvBackend.cpp | 0 .../conv/nnkit-caffe}/ConvBackend.h | 0 .../conv/nnkit-caffe}/ConvBackend.test.cpp | 23 +++++++++------------- .../caffe => nnsuite/conv/nnkit-caffe}/Entry.cpp | 0 .../conv/nnkit-tflite}/CMakeLists.txt | 0 .../conv/nnkit-tflite}/ConvBackend.cpp | 18 ++++++++--------- .../conv/nnkit-tflite}/ConvBackend.h | 0 .../conv/nnkit-tflite}/ConvBackend.test.cpp | 23 +++++++++------------- .../tflite => nnsuite/conv/nnkit-tflite}/Entry.cpp | 0 19 files changed, 35 insertions(+), 49 deletions(-) delete mode 100644 contrib/nnkit/contrib/CMakeLists.txt delete mode 100644 contrib/nnkit/contrib/nnsuite/CMakeLists.txt delete mode 100644 contrib/nnkit/contrib/nnsuite/conv/CMakeLists.txt create mode 100644 contrib/nnsuite/conv/model/CMakeLists.txt rename contrib/nnsuite/conv/{ => model}/include/nnsuite/conv/Model.h (100%) rename contrib/nnsuite/conv/{ => model}/include/nnsuite/conv/RandomModel.h (100%) rename contrib/nnsuite/conv/{ => model}/src/RandomModel.cpp (100%) rename contrib/{nnkit/contrib/nnsuite/conv/caffe => nnsuite/conv/nnkit-caffe}/CMakeLists.txt (100%) rename contrib/{nnkit/contrib/nnsuite/conv/caffe => nnsuite/conv/nnkit-caffe}/ConvBackend.cpp (100%) rename contrib/{nnkit/contrib/nnsuite/conv/caffe => nnsuite/conv/nnkit-caffe}/ConvBackend.h (100%) rename contrib/{nnkit/contrib/nnsuite/conv/caffe => nnsuite/conv/nnkit-caffe}/ConvBackend.test.cpp (84%) rename contrib/{nnkit/contrib/nnsuite/conv/caffe => nnsuite/conv/nnkit-caffe}/Entry.cpp (100%) rename contrib/{nnkit/contrib/nnsuite/conv/tflite => nnsuite/conv/nnkit-tflite}/CMakeLists.txt (100%) rename contrib/{nnkit/contrib/nnsuite/conv/tflite => nnsuite/conv/nnkit-tflite}/ConvBackend.cpp (83%) rename contrib/{nnkit/contrib/nnsuite/conv/tflite => nnsuite/conv/nnkit-tflite}/ConvBackend.h (100%) rename contrib/{nnkit/contrib/nnsuite/conv/tflite => nnsuite/conv/nnkit-tflite}/ConvBackend.test.cpp (84%) rename contrib/{nnkit/contrib/nnsuite/conv/tflite => nnsuite/conv/nnkit-tflite}/Entry.cpp (100%) diff --git a/contrib/nnkit/CMakeLists.txt b/contrib/nnkit/CMakeLists.txt index 558d393..918d517 100644 --- a/contrib/nnkit/CMakeLists.txt +++ b/contrib/nnkit/CMakeLists.txt @@ -2,4 +2,3 @@ add_subdirectory(libs) add_subdirectory(backends) add_subdirectory(actions) add_subdirectory(tools) -add_subdirectory(contrib) diff --git a/contrib/nnkit/contrib/CMakeLists.txt b/contrib/nnkit/contrib/CMakeLists.txt deleted file mode 100644 index 5ea6cda..0000000 --- a/contrib/nnkit/contrib/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectories() diff --git a/contrib/nnkit/contrib/nnsuite/CMakeLists.txt b/contrib/nnkit/contrib/nnsuite/CMakeLists.txt deleted file mode 100644 index 5ea6cda..0000000 --- a/contrib/nnkit/contrib/nnsuite/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectories() diff --git a/contrib/nnkit/contrib/nnsuite/conv/CMakeLists.txt b/contrib/nnkit/contrib/nnsuite/conv/CMakeLists.txt deleted file mode 100644 index b897d12..0000000 --- a/contrib/nnkit/contrib/nnsuite/conv/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(tflite) -add_subdirectory(caffe) diff --git a/contrib/nnsuite/conv/CMakeLists.txt b/contrib/nnsuite/conv/CMakeLists.txt index a2c28ee..a120de2 100644 --- a/contrib/nnsuite/conv/CMakeLists.txt +++ b/contrib/nnsuite/conv/CMakeLists.txt @@ -1,6 +1,3 @@ -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) +add_subdirectory(model) +add_subdirectory(nnkit-caffe) +add_subdirectory(nnkit-tflite) diff --git a/contrib/nnsuite/conv/model/CMakeLists.txt b/contrib/nnsuite/conv/model/CMakeLists.txt new file mode 100644 index 0000000..a2c28ee --- /dev/null +++ b/contrib/nnsuite/conv/model/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/model/include/nnsuite/conv/Model.h similarity index 100% rename from contrib/nnsuite/conv/include/nnsuite/conv/Model.h rename to contrib/nnsuite/conv/model/include/nnsuite/conv/Model.h diff --git a/contrib/nnsuite/conv/include/nnsuite/conv/RandomModel.h b/contrib/nnsuite/conv/model/include/nnsuite/conv/RandomModel.h similarity index 100% rename from contrib/nnsuite/conv/include/nnsuite/conv/RandomModel.h rename to contrib/nnsuite/conv/model/include/nnsuite/conv/RandomModel.h diff --git a/contrib/nnsuite/conv/src/RandomModel.cpp b/contrib/nnsuite/conv/model/src/RandomModel.cpp similarity index 100% rename from contrib/nnsuite/conv/src/RandomModel.cpp rename to contrib/nnsuite/conv/model/src/RandomModel.cpp diff --git a/contrib/nnkit/contrib/nnsuite/conv/caffe/CMakeLists.txt b/contrib/nnsuite/conv/nnkit-caffe/CMakeLists.txt similarity index 100% rename from contrib/nnkit/contrib/nnsuite/conv/caffe/CMakeLists.txt rename to contrib/nnsuite/conv/nnkit-caffe/CMakeLists.txt diff --git a/contrib/nnkit/contrib/nnsuite/conv/caffe/ConvBackend.cpp b/contrib/nnsuite/conv/nnkit-caffe/ConvBackend.cpp similarity index 100% rename from contrib/nnkit/contrib/nnsuite/conv/caffe/ConvBackend.cpp rename to contrib/nnsuite/conv/nnkit-caffe/ConvBackend.cpp diff --git a/contrib/nnkit/contrib/nnsuite/conv/caffe/ConvBackend.h b/contrib/nnsuite/conv/nnkit-caffe/ConvBackend.h similarity index 100% rename from contrib/nnkit/contrib/nnsuite/conv/caffe/ConvBackend.h rename to contrib/nnsuite/conv/nnkit-caffe/ConvBackend.h diff --git a/contrib/nnkit/contrib/nnsuite/conv/caffe/ConvBackend.test.cpp b/contrib/nnsuite/conv/nnkit-caffe/ConvBackend.test.cpp similarity index 84% rename from contrib/nnkit/contrib/nnsuite/conv/caffe/ConvBackend.test.cpp rename to contrib/nnsuite/conv/nnkit-caffe/ConvBackend.test.cpp index 87b8b32..9bdafd9 100644 --- a/contrib/nnkit/contrib/nnsuite/conv/caffe/ConvBackend.test.cpp +++ b/contrib/nnsuite/conv/nnkit-caffe/ConvBackend.test.cpp @@ -37,9 +37,8 @@ public: TestModel(const std::string &ifm_name, const feature::Shape &ifm_shape, const std::string &ofm_name, const feature::Shape &ofm_shape, const kernel::Shape &ker_shape, const kernel::Layout &ker_layout, float *ker_data) - : _ifm_name(ifm_name), _ifm_shape(ifm_shape), - _ofm_name(ofm_name), _ofm_shape(ofm_shape), - _ker{ker_shape, ker_layout, ker_data} + : _ifm_name(ifm_name), _ifm_shape(ifm_shape), _ofm_name(ofm_name), _ofm_shape(ofm_shape), + _ker{ker_shape, ker_layout, ker_data} { // DO NOTHING } @@ -72,14 +71,14 @@ TEST(CONV_BACKEND, conv_3x3) { const std::string ofm_name{"ofm"}; const feature::Shape ofm_shape{1, 1, 1}; - float ofm_data[1] = { 204.0f }; // EXPECTED + float ofm_data[1] = {204.0f}; // EXPECTED const std::string ifm_name{"ifm"}; const feature::Shape ifm_shape{1, 3, 3}; - float ifm_data[9] = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + float ifm_data[9] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; const kernel::Shape ker_shape{1, 1, 3, 3}; - float ker_data[9] = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + float ker_data[9] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; using kernel::NCHWLayout; using tensor::LexicalLayout; @@ -88,14 +87,12 @@ TEST(CONV_BACKEND, conv_3x3) auto backend = ConvBackend::create(model); - backend->prepare([&] (nnkit::TensorContext &ctx) - { + backend->prepare([&](nnkit::TensorContext &ctx) { ASSERT_EQ(ctx.size(), 1); ASSERT_EQ(ctx.name(0), ifm_name); // TODO Check IFM shape - auto fill = [&] (const nnkit::TensorContext &, uint32_t, tensor::Accessor &t) - { + auto fill = [&](const nnkit::TensorContext &, uint32_t, tensor::Accessor &t) { const auto tensor_shape = morph::caffe::as_tensor_shape(ifm_shape); const auto overlay = tensor::make_overlay(tensor_shape, ifm_data); @@ -111,13 +108,11 @@ TEST(CONV_BACKEND, conv_3x3) backend->run(); - backend->teardown([&] (nnkit::TensorContext &ctx) - { + backend->teardown([&](nnkit::TensorContext &ctx) { ASSERT_EQ(ctx.size(), 1); ASSERT_EQ(ctx.name(0), ofm_name); - auto verify = [&] (const nnkit::TensorContext &, uint32_t, const tensor::Reader &t) - { + auto verify = [&](const nnkit::TensorContext &, uint32_t, const tensor::Reader &t) { const auto tensor_shape = morph::caffe::as_tensor_shape(ofm_shape); const auto overlay = tensor::make_overlay(tensor_shape, ofm_data); diff --git a/contrib/nnkit/contrib/nnsuite/conv/caffe/Entry.cpp b/contrib/nnsuite/conv/nnkit-caffe/Entry.cpp similarity index 100% rename from contrib/nnkit/contrib/nnsuite/conv/caffe/Entry.cpp rename to contrib/nnsuite/conv/nnkit-caffe/Entry.cpp diff --git a/contrib/nnkit/contrib/nnsuite/conv/tflite/CMakeLists.txt b/contrib/nnsuite/conv/nnkit-tflite/CMakeLists.txt similarity index 100% rename from contrib/nnkit/contrib/nnsuite/conv/tflite/CMakeLists.txt rename to contrib/nnsuite/conv/nnkit-tflite/CMakeLists.txt diff --git a/contrib/nnkit/contrib/nnsuite/conv/tflite/ConvBackend.cpp b/contrib/nnsuite/conv/nnkit-tflite/ConvBackend.cpp similarity index 83% rename from contrib/nnkit/contrib/nnsuite/conv/tflite/ConvBackend.cpp rename to contrib/nnsuite/conv/nnkit-tflite/ConvBackend.cpp index 01a7496..8ec9ce4 100644 --- a/contrib/nnkit/contrib/nnsuite/conv/tflite/ConvBackend.cpp +++ b/contrib/nnsuite/conv/nnkit-tflite/ConvBackend.cpp @@ -34,7 +34,7 @@ using namespace ::tflite::ops::builtin; * * NOTE This function throws std::bac_alloc exception on allocation failure */ -template T *typed_malloc(void) +template T *typed_malloc(void) { if (auto res = reinterpret_cast(malloc(sizeof(T)))) { @@ -122,15 +122,13 @@ ConvBackend::ConvBackend(const nnsuite::conv::Model &model) _interp.SetTensorParametersReadWrite(1, kTfLiteFloat32 /* type */, _ifm_name.c_str(), as_dims(model.ifm_shape()), quantization); - _interp.SetTensorParametersReadOnly(2, kTfLiteFloat32 /* type */, "kernel" /* name */, - as_dims(model.ker_shape()), quantization, - reinterpret_cast(_kernel.data()), - _kernel.size() * sizeof(float)); + _interp.SetTensorParametersReadOnly( + 2, kTfLiteFloat32 /* type */, "kernel" /* name */, as_dims(model.ker_shape()), quantization, + reinterpret_cast(_kernel.data()), _kernel.size() * sizeof(float)); - _interp.SetTensorParametersReadOnly(3, kTfLiteFloat32 /* type */, "bias" /* name */, - {static_cast(_bias.size())}, quantization, - reinterpret_cast(_bias.data()), - _bias.size() * sizeof(float)); + _interp.SetTensorParametersReadOnly( + 3, kTfLiteFloat32 /* type */, "bias" /* name */, {static_cast(_bias.size())}, + quantization, reinterpret_cast(_bias.data()), _bias.size() * sizeof(float)); auto param = typed_malloc(); @@ -140,7 +138,7 @@ ConvBackend::ConvBackend(const nnsuite::conv::Model &model) param->activation = kTfLiteActNone; _interp.AddNodeWithParameters({1, 2, 3}, {0}, nullptr, 0, reinterpret_cast(param), - BuiltinOpResolver().FindOp(BuiltinOperator_CONV_2D)); + BuiltinOpResolver().FindOp(BuiltinOperator_CONV_2D)); _interp.SetInputs({1}); _interp.SetOutputs({0}); diff --git a/contrib/nnkit/contrib/nnsuite/conv/tflite/ConvBackend.h b/contrib/nnsuite/conv/nnkit-tflite/ConvBackend.h similarity index 100% rename from contrib/nnkit/contrib/nnsuite/conv/tflite/ConvBackend.h rename to contrib/nnsuite/conv/nnkit-tflite/ConvBackend.h diff --git a/contrib/nnkit/contrib/nnsuite/conv/tflite/ConvBackend.test.cpp b/contrib/nnsuite/conv/nnkit-tflite/ConvBackend.test.cpp similarity index 84% rename from contrib/nnkit/contrib/nnsuite/conv/tflite/ConvBackend.test.cpp rename to contrib/nnsuite/conv/nnkit-tflite/ConvBackend.test.cpp index 38e291e..f4d30db 100644 --- a/contrib/nnkit/contrib/nnsuite/conv/tflite/ConvBackend.test.cpp +++ b/contrib/nnsuite/conv/nnkit-tflite/ConvBackend.test.cpp @@ -40,9 +40,8 @@ public: TestModel(const std::string &ifm_name, const feature::Shape &ifm_shape, const std::string &ofm_name, const feature::Shape &ofm_shape, const kernel::Shape &ker_shape, const kernel::Layout &ker_layout, float *ker_data) - : _ifm_name(ifm_name), _ifm_shape(ifm_shape), - _ofm_name(ofm_name), _ofm_shape(ofm_shape), - _ker{ker_shape, ker_layout, ker_data} + : _ifm_name(ifm_name), _ifm_shape(ifm_shape), _ofm_name(ofm_name), _ofm_shape(ofm_shape), + _ker{ker_shape, ker_layout, ker_data} { // DO NOTHING } @@ -75,14 +74,14 @@ TEST(CONV_BACKEND, conv_3x3) { const std::string ofm_name{"ofm"}; const feature::Shape ofm_shape{1, 1, 1}; - float ofm_data[1] = { 204.0f }; // EXPECTED + float ofm_data[1] = {204.0f}; // EXPECTED const std::string ifm_name{"ifm"}; const feature::Shape ifm_shape{1, 3, 3}; - float ifm_data[9] = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + float ifm_data[9] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; const kernel::Shape ker_shape{1, 1, 3, 3}; - float ker_data[9] = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + float ker_data[9] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; using kernel::NHWCLayout; using tensor::LexicalLayout; @@ -91,14 +90,12 @@ TEST(CONV_BACKEND, conv_3x3) ConvBackend backend{model}; - backend.prepare([&] (nnkit::TensorContext &ctx) - { + backend.prepare([&](nnkit::TensorContext &ctx) { ASSERT_EQ(ctx.size(), 1); ASSERT_EQ(ctx.name(0), ifm_name); // TODO Check IFM shape - auto fill = [&] (const nnkit::TensorContext &, uint32_t, tensor::Accessor &t) - { + auto fill = [&](const nnkit::TensorContext &, uint32_t, tensor::Accessor &t) { const auto tensor_shape = as_tensor_shape(ifm_shape); const auto overlay = tensor::make_overlay(tensor_shape, ifm_data); @@ -114,13 +111,11 @@ TEST(CONV_BACKEND, conv_3x3) backend.run(); - backend.teardown([&] (nnkit::TensorContext &ctx) - { + backend.teardown([&](nnkit::TensorContext &ctx) { ASSERT_EQ(ctx.size(), 1); ASSERT_EQ(ctx.name(0), ofm_name); - auto verify = [&] (const nnkit::TensorContext &, uint32_t, const tensor::Reader &t) - { + auto verify = [&](const nnkit::TensorContext &, uint32_t, const tensor::Reader &t) { const auto tensor_shape = as_tensor_shape(ofm_shape); const auto overlay = tensor::make_overlay(tensor_shape, ofm_data); diff --git a/contrib/nnkit/contrib/nnsuite/conv/tflite/Entry.cpp b/contrib/nnsuite/conv/nnkit-tflite/Entry.cpp similarity index 100% rename from contrib/nnkit/contrib/nnsuite/conv/tflite/Entry.cpp rename to contrib/nnsuite/conv/nnkit-tflite/Entry.cpp -- 2.7.4