From 0f4df98dc71d2ef2b41b19193f77ce0c69689132 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=98=A4=ED=98=95=EC=84=9D/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Tue, 21 May 2019 12:54:41 +0900 Subject: [PATCH] Merge explicit padding structure (#5229) Merge usage neurun::util::Padding to neurun::model::ExplicitPadding Rename Padding.value to Padding.param Signed-off-by: Hyeongseok Oh --- runtimes/neurun/backend/acl_cl/StageGenerator.cc | 24 +++++++++++----------- runtimes/neurun/backend/acl_common/Convert.cc | 2 +- runtimes/neurun/backend/acl_common/Convert.h | 2 +- runtimes/neurun/backend/acl_neon/StageGenerator.cc | 18 ++++++++-------- runtimes/neurun/backend/cpu/StageGenerator.cc | 16 +++++++-------- runtimes/neurun/core/include/model/InternalType.h | 13 ++++++------ runtimes/neurun/core/include/util/Padding.h | 18 ++++++---------- runtimes/neurun/core/src/util/Padding.cc | 12 +++++------ 8 files changed, 49 insertions(+), 56 deletions(-) diff --git a/runtimes/neurun/backend/acl_cl/StageGenerator.cc b/runtimes/neurun/backend/acl_cl/StageGenerator.cc index 88eef88..8058e17 100644 --- a/runtimes/neurun/backend/acl_cl/StageGenerator.cc +++ b/runtimes/neurun/backend/acl_cl/StageGenerator.cc @@ -44,7 +44,7 @@ using ::neurun::compiler::IExecutionBuilder; template std::unique_ptr make_layer(void) { return std::unique_ptr{new T}; } -::arm_compute::PadStrideInfo asPadStringInfo(const neurun::util::Padding &padding, +::arm_compute::PadStrideInfo asPadStringInfo(const neurun::model::ExplicitPadding &padding, const neurun::util::Stride &stride) { return ::arm_compute::PadStrideInfo{stride.horizontal, @@ -238,7 +238,7 @@ void StageGenerator::visit(const model::operation::Conv2DNode &node) model::OperandIndex ker_index; model::OperandIndex bias_index; - neurun::util::Padding padding; + model::ExplicitPadding padding; neurun::util::Stride stride; model::Activation activation; @@ -268,7 +268,7 @@ void StageGenerator::visit(const model::operation::Conv2DNode &node) } else // explicit padding { - neurun::util::Padding padding; + model::ExplicitPadding padding; padding.left = _ctx.at({node.param().padding_left_index}).asScalar(); padding.right = _ctx.at({node.param().padding_right_index}).asScalar(); padding.top = _ctx.at({node.param().padding_top_index}).asScalar(); @@ -334,7 +334,7 @@ void StageGenerator::visit(const model::operation::DepthwiseConv2DNode &node) model::OperandIndex ker_index; model::OperandIndex bias_index; - neurun::util::Padding padding; + model::ExplicitPadding padding; neurun::util::Stride stride; int multiplier; @@ -366,7 +366,7 @@ void StageGenerator::visit(const model::operation::DepthwiseConv2DNode &node) } else // explicit padding { - neurun::util::Padding padding; + model::ExplicitPadding padding; padding.left = _ctx.at({node.param().padding_left_index}).asScalar(); padding.right = _ctx.at({node.param().padding_right_index}).asScalar(); padding.top = _ctx.at({node.param().padding_top_index}).asScalar(); @@ -431,7 +431,7 @@ void StageGenerator::visit(const model::operation::MaxPool2DNode &node) uint32_t kw; uint32_t kh; - neurun::util::Padding padding; + model::ExplicitPadding padding; neurun::util::Stride stride; model::Activation activation; @@ -462,7 +462,7 @@ void StageGenerator::visit(const model::operation::MaxPool2DNode &node) } else // explicit padding { - neurun::util::Padding padding; + model::ExplicitPadding padding; padding.left = _ctx.at({node.param().padding_left_index}).asScalar(); padding.right = _ctx.at({node.param().padding_right_index}).asScalar(); padding.top = _ctx.at({node.param().padding_top_index}).asScalar(); @@ -538,7 +538,7 @@ void StageGenerator::visit(const model::operation::AvgPool2DNode &node) uint32_t kw; uint32_t kh; - neurun::util::Padding padding; + model::ExplicitPadding padding; neurun::util::Stride stride; model::Activation activation; @@ -569,7 +569,7 @@ void StageGenerator::visit(const model::operation::AvgPool2DNode &node) } else // explicit padding { - neurun::util::Padding padding; + model::ExplicitPadding padding; padding.left = _ctx.at({node.param().padding_left_index}).asScalar(); padding.right = _ctx.at({node.param().padding_right_index}).asScalar(); padding.top = _ctx.at({node.param().padding_top_index}).asScalar(); @@ -2067,7 +2067,7 @@ void StageGenerator::visit(const model::operation::L2Pool2DNode &node) uint32_t kw; uint32_t kh; - neurun::util::Padding padding; + model::ExplicitPadding padding; neurun::util::Stride stride; model::Activation activation; @@ -2097,7 +2097,7 @@ void StageGenerator::visit(const model::operation::L2Pool2DNode &node) } else // explicit padding { - neurun::util::Padding padding; + model::ExplicitPadding padding; padding.left = _ctx.at({node.param().padding_left_index}).asScalar(); padding.right = _ctx.at({node.param().padding_right_index}).asScalar(); padding.top = _ctx.at({node.param().padding_top_index}).asScalar(); @@ -2367,7 +2367,7 @@ void StageGenerator::visit(const model::operation::TransposeConvNode &node) model::OperandIndex ifm_index; model::OperandIndex ker_index; - neurun::util::Padding padding; + model::ExplicitPadding padding; neurun::util::Stride stride; }; diff --git a/runtimes/neurun/backend/acl_common/Convert.cc b/runtimes/neurun/backend/acl_common/Convert.cc index 9787ccb..7420358 100644 --- a/runtimes/neurun/backend/acl_common/Convert.cc +++ b/runtimes/neurun/backend/acl_common/Convert.cc @@ -118,7 +118,7 @@ namespace acl_common return info; } -::arm_compute::PadStrideInfo asPadStrideInfo(const neurun::util::Padding &padding, +::arm_compute::PadStrideInfo asPadStrideInfo(const model::ExplicitPadding &padding, const neurun::util::Stride &stride) { return ::arm_compute::PadStrideInfo{stride.horizontal, diff --git a/runtimes/neurun/backend/acl_common/Convert.h b/runtimes/neurun/backend/acl_common/Convert.h index 40ff4c4..92cc9f8 100644 --- a/runtimes/neurun/backend/acl_common/Convert.h +++ b/runtimes/neurun/backend/acl_common/Convert.h @@ -49,7 +49,7 @@ namespace acl_common const ::neurun::graph::operand::Layout &layout, bool apply_dim_correction = true); -::arm_compute::PadStrideInfo asPadStrideInfo(const neurun::util::Padding &padding, +::arm_compute::PadStrideInfo asPadStrideInfo(const model::ExplicitPadding &padding, const neurun::util::Stride &stride); ::arm_compute::ActivationLayerInfo diff --git a/runtimes/neurun/backend/acl_neon/StageGenerator.cc b/runtimes/neurun/backend/acl_neon/StageGenerator.cc index 6f96e3d..d3b464c 100644 --- a/runtimes/neurun/backend/acl_neon/StageGenerator.cc +++ b/runtimes/neurun/backend/acl_neon/StageGenerator.cc @@ -49,7 +49,7 @@ using ::neurun::compiler::IExecutionBuilder; template std::unique_ptr make_layer(void) { return std::unique_ptr{new T}; } -::arm_compute::PadStrideInfo asPadStringInfo(const neurun::util::Padding &padding, +::arm_compute::PadStrideInfo asPadStringInfo(const neurun::model::ExplicitPadding &padding, const neurun::util::Stride &stride) { return ::arm_compute::PadStrideInfo{stride.horizontal, @@ -205,7 +205,7 @@ void StageGenerator::visit(const model::operation::Conv2DNode &node) model::OperandIndex ker_index; model::OperandIndex bias_index; - neurun::util::Padding padding; + model::ExplicitPadding padding; neurun::util::Stride stride; model::Activation activation; @@ -235,7 +235,7 @@ void StageGenerator::visit(const model::operation::Conv2DNode &node) } else // explicit padding { - neurun::util::Padding padding; + model::ExplicitPadding padding; padding.left = _ctx.at({node.param().padding_left_index}).asScalar(); padding.right = _ctx.at({node.param().padding_right_index}).asScalar(); padding.top = _ctx.at({node.param().padding_top_index}).asScalar(); @@ -301,7 +301,7 @@ void StageGenerator::visit(const model::operation::DepthwiseConv2DNode &node) model::OperandIndex ker_index; model::OperandIndex bias_index; - neurun::util::Padding padding; + model::ExplicitPadding padding; neurun::util::Stride stride; int multiplier; @@ -333,7 +333,7 @@ void StageGenerator::visit(const model::operation::DepthwiseConv2DNode &node) } else // explicit padding { - neurun::util::Padding padding; + model::ExplicitPadding padding; padding.left = _ctx.at({node.param().padding_left_index}).asScalar(); padding.right = _ctx.at({node.param().padding_right_index}).asScalar(); padding.top = _ctx.at({node.param().padding_top_index}).asScalar(); @@ -398,7 +398,7 @@ void StageGenerator::visit(const model::operation::MaxPool2DNode &node) uint32_t kw; uint32_t kh; - neurun::util::Padding padding; + model::ExplicitPadding padding; neurun::util::Stride stride; model::Activation activation; @@ -429,7 +429,7 @@ void StageGenerator::visit(const model::operation::MaxPool2DNode &node) } else // explicit padding { - neurun::util::Padding padding; + model::ExplicitPadding padding; padding.left = _ctx.at({node.param().padding_left_index}).asScalar(); padding.right = _ctx.at({node.param().padding_right_index}).asScalar(); padding.top = _ctx.at({node.param().padding_top_index}).asScalar(); @@ -505,7 +505,7 @@ void StageGenerator::visit(const model::operation::AvgPool2DNode &node) uint32_t kw; uint32_t kh; - neurun::util::Padding padding; + model::ExplicitPadding padding; neurun::util::Stride stride; model::Activation activation; @@ -536,7 +536,7 @@ void StageGenerator::visit(const model::operation::AvgPool2DNode &node) } else // explicit padding { - neurun::util::Padding padding; + model::ExplicitPadding padding; padding.left = _ctx.at({node.param().padding_left_index}).asScalar(); padding.right = _ctx.at({node.param().padding_right_index}).asScalar(); padding.top = _ctx.at({node.param().padding_top_index}).asScalar(); diff --git a/runtimes/neurun/backend/cpu/StageGenerator.cc b/runtimes/neurun/backend/cpu/StageGenerator.cc index 2cf40f0..90ba443 100644 --- a/runtimes/neurun/backend/cpu/StageGenerator.cc +++ b/runtimes/neurun/backend/cpu/StageGenerator.cc @@ -84,7 +84,7 @@ void StageGenerator::visit(const model::operation::Conv2DNode &node) ::neurun::backend::cpu::kernel::Shape ker_shape; ::neurun::backend::cpu::kernel::Shape bias_shape; - util::Padding padding; + model::ExplicitPadding padding; util::Stride stride; model::Activation activation; @@ -121,7 +121,7 @@ void StageGenerator::visit(const model::operation::Conv2DNode &node) } else // explicit padding { - neurun::util::Padding padding; + model::ExplicitPadding padding; padding.left = _ctx.at({node.param().padding_left_index}).asScalar(); padding.right = _ctx.at({node.param().padding_right_index}).asScalar(); padding.top = _ctx.at({node.param().padding_top_index}).asScalar(); @@ -187,7 +187,7 @@ void StageGenerator::visit(const model::operation::DepthwiseConv2DNode &node) ::neurun::backend::cpu::kernel::Shape ker_shape; ::neurun::backend::cpu::kernel::Shape bias_shape; - util::Padding padding; + model::ExplicitPadding padding; util::Stride stride; int multiplier; @@ -226,7 +226,7 @@ void StageGenerator::visit(const model::operation::DepthwiseConv2DNode &node) } else // explicit padding { - neurun::util::Padding padding; + model::ExplicitPadding padding; padding.left = _ctx.at({node.param().padding_left_index}).asScalar(); padding.right = _ctx.at({node.param().padding_right_index}).asScalar(); padding.top = _ctx.at({node.param().padding_top_index}).asScalar(); @@ -289,7 +289,7 @@ void StageGenerator::visit(const model::operation::MaxPool2DNode &node) ::neurun::backend::cpu::kernel::Shape ofm_shape; ::neurun::backend::cpu::kernel::Shape ifm_shape; - util::Padding padding; + model::ExplicitPadding padding; util::Stride stride; model::Activation activation; @@ -325,7 +325,7 @@ void StageGenerator::visit(const model::operation::MaxPool2DNode &node) } else // explicit padding { - neurun::util::Padding padding; + model::ExplicitPadding padding; padding.left = _ctx.at({node.param().padding_left_index}).asScalar(); padding.right = _ctx.at({node.param().padding_right_index}).asScalar(); padding.top = _ctx.at({node.param().padding_top_index}).asScalar(); @@ -384,7 +384,7 @@ void StageGenerator::visit(const model::operation::AvgPool2DNode &node) ::neurun::backend::cpu::kernel::Shape ofm_shape; ::neurun::backend::cpu::kernel::Shape ifm_shape; - util::Padding padding; + model::ExplicitPadding padding; util::Stride stride; model::Activation activation; @@ -420,7 +420,7 @@ void StageGenerator::visit(const model::operation::AvgPool2DNode &node) } else // explicit padding { - neurun::util::Padding padding; + model::ExplicitPadding padding; padding.left = _ctx.at({node.param().padding_left_index}).asScalar(); padding.right = _ctx.at({node.param().padding_right_index}).asScalar(); padding.top = _ctx.at({node.param().padding_top_index}).asScalar(); diff --git a/runtimes/neurun/core/include/model/InternalType.h b/runtimes/neurun/core/include/model/InternalType.h index 7cf9226..532b781 100644 --- a/runtimes/neurun/core/include/model/InternalType.h +++ b/runtimes/neurun/core/include/model/InternalType.h @@ -41,20 +41,19 @@ enum class PaddingType VALID = 2 }; -// TODO merge with neurun::util::Padding struct struct ExplicitPadding { - int32_t left; - int32_t right; - int32_t top; - int32_t bottom; + uint32_t left; + uint32_t right; + uint32_t top; + uint32_t bottom; }; -// TODO Resolve explicit padding value at frontend and save in value field +// TODO Resolve explicit padding param at frontend and save in value field struct Padding { PaddingType type; - ExplicitPadding value; + ExplicitPadding param; }; } // namespace model diff --git a/runtimes/neurun/core/include/util/Padding.h b/runtimes/neurun/core/include/util/Padding.h index 05a14eb..eacc05f 100644 --- a/runtimes/neurun/core/include/util/Padding.h +++ b/runtimes/neurun/core/include/util/Padding.h @@ -21,29 +21,23 @@ #include +#include "model/InternalType.h" + namespace neurun { namespace util { -struct Padding -{ - uint32_t top; - uint32_t bottom; - uint32_t left; - uint32_t right; -}; - struct Stride { uint32_t vertical; uint32_t horizontal; }; -Padding valid_padding(void); -Padding same_padding(const nnfw::misc::feature::Shape &ifm_shape, - const nnfw::misc::feature::Shape &ofm_shape, const Stride &stride, uint32_t kw, - uint32_t kh); +model::ExplicitPadding valid_padding(void); +model::ExplicitPadding same_padding(const nnfw::misc::feature::Shape &ifm_shape, + const nnfw::misc::feature::Shape &ofm_shape, + const Stride &stride, uint32_t kw, uint32_t kh); } // namespace util } // namespace neurun diff --git a/runtimes/neurun/core/src/util/Padding.cc b/runtimes/neurun/core/src/util/Padding.cc index d1735b8..badfb1c 100644 --- a/runtimes/neurun/core/src/util/Padding.cc +++ b/runtimes/neurun/core/src/util/Padding.cc @@ -23,7 +23,7 @@ namespace neurun namespace util { -Padding valid_padding(void) +model::ExplicitPadding valid_padding(void) { // // ANEURALNETWORKS_PADDING_VALID @@ -34,7 +34,7 @@ Padding valid_padding(void) // the input at the end that could not fill the whole filter tile // will simply be ignored. // - Padding padding; + model::ExplicitPadding padding; padding.top = 0; padding.bottom = 0; @@ -44,11 +44,11 @@ Padding valid_padding(void) return padding; } -Padding same_padding(const nnfw::misc::feature::Shape &ifm_shape, - const nnfw::misc::feature::Shape &ofm_shape, const Stride &stride, uint32_t kw, - uint32_t kh) +model::ExplicitPadding same_padding(const nnfw::misc::feature::Shape &ifm_shape, + const nnfw::misc::feature::Shape &ofm_shape, + const Stride &stride, uint32_t kw, uint32_t kh) { - Padding padding; + model::ExplicitPadding padding; // ANEURALNETWORKS_PADDING_SAME (from NNAPI spec) // -- 2.7.4