Skip to content

Commit

Permalink
[onert] Move PermuteType (#13749)
Browse files Browse the repository at this point in the history
This commit changes PermuteType from IPermuteFunction's protected enum class to public enum class and move into Layout.h.
It will be used on outside of IPermuteFunction's derived classes.

ONE-DCO-1.0-Signed-off-by: Hyeongseok Oh <[email protected]>
  • Loading branch information
hseok-oh authored Aug 26, 2024
1 parent 6e70506 commit 6ffbc44
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
7 changes: 7 additions & 0 deletions runtime/onert/core/include/ir/Layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ enum class Layout
NCHW
};

enum class PermuteType
{
NHWC_TO_NCHW,
NCHW_TO_NHWC,
COPY
};

inline std::string to_string(Layout layout)
{
switch (layout)
Expand Down
14 changes: 7 additions & 7 deletions runtime/onert/core/src/backend/builtin/kernel/PermuteLayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@ void PermuteLayer::optimize()
dst_offsets_it->resize(0);
if (underlying_type(src->data_type()) != underlying_type(dst->data_type()))
continue;
const auto permute_type = [&]() -> PermuteType {
const auto permute_type = [&]() -> ir::PermuteType {
if (src->getShape().rank() == 4 && src->layout() == ir::Layout::NHWC &&
dst->layout() == ir::Layout::NCHW)
{
return PermuteType::NHWC_TO_NCHW;
return ir::PermuteType::NHWC_TO_NCHW;
}
else if (src->getShape().rank() == 4 && src->layout() == ir::Layout::NCHW &&
dst->layout() == ir::Layout::NHWC)
{
return PermuteType::NCHW_TO_NHWC;
return ir::PermuteType::NCHW_TO_NHWC;
}
else
{
return PermuteType::COPY;
return ir::PermuteType::COPY;
}
}();

Expand All @@ -88,7 +88,7 @@ void PermuteLayer::optimize()
// NOTE The buffer of both tensor can be nullptr in this step
const auto data_size = ir::sizeOfDataType(src_tensor.data_type());

if (permute_type == PermuteType::COPY)
if (permute_type == ir::PermuteType::COPY)
{
if ((!src_tensor.has_padding() && !dst_tensor.has_padding()))
{
Expand Down Expand Up @@ -125,8 +125,8 @@ void PermuteLayer::optimize()
else
{
assert(src_tensor.getShape().rank() == 4 &&
(permute_type == PermuteType::NHWC_TO_NCHW ||
permute_type == PermuteType::NCHW_TO_NHWC));
(permute_type == ir::PermuteType::NHWC_TO_NCHW ||
permute_type == ir::PermuteType::NCHW_TO_NHWC));
const auto loop_shape = src_tensor.getShape();
const auto copy_len = data_size;

Expand Down
22 changes: 7 additions & 15 deletions runtime/onert/core/src/exec/IPermuteFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ inline void CopyDynamic(const ::onert::backend::ITensor *src, const ::onert::bac

class IPermuteFunction : public IFunction
{
protected:
enum class PermuteType
{
NHWC_TO_NCHW,
NCHW_TO_NHWC,
COPY
};

public:
virtual void run() override;

Expand Down Expand Up @@ -138,25 +130,25 @@ class IPermuteFunction : public IFunction
assert(dst_buffer != nullptr);
assert(dst_size == dst->total_size());

const auto permute_type = [&]() -> PermuteType {
const auto permute_type = [&]() -> ir::PermuteType {
if (src->layout() == ir::Layout::NHWC && dst->layout() == ir::Layout::NCHW)
{
return PermuteType::NHWC_TO_NCHW;
return ir::PermuteType::NHWC_TO_NCHW;
}
else if (src->layout() == ir::Layout::NCHW && dst->layout() == ir::Layout::NHWC)
{
return PermuteType::NCHW_TO_NHWC;
return ir::PermuteType::NCHW_TO_NHWC;
}
else
{
return PermuteType::COPY;
return ir::PermuteType::COPY;
}
}();
if (rank == 4 && permute_type != PermuteType::COPY)
if (rank == 4 && permute_type != ir::PermuteType::COPY)
{
switch (permute_type)
{
case PermuteType::NHWC_TO_NCHW:
case ir::PermuteType::NHWC_TO_NCHW:
{
ir::FeatureShape shape;
auto dst_shape = dst->getShape();
Expand All @@ -181,7 +173,7 @@ class IPermuteFunction : public IFunction
};
break;
}
case PermuteType::NCHW_TO_NHWC:
case ir::PermuteType::NCHW_TO_NHWC:
{
ir::FeatureShape shape;
auto dst_shape = dst->getShape();
Expand Down

0 comments on commit 6ffbc44

Please sign in to comment.