Skip to content

Commit

Permalink
[onert] Remove Permute IR handling in general backend
Browse files Browse the repository at this point in the history
This commit removes Permute IR handling in acl backends.
This IR is handled on builtin backend only because layout changes in backend is not available feature any more.

ONE-DCO-1.0-Signed-off-by: Hyeongseok Oh <[email protected]>
  • Loading branch information
hseok-oh committed Aug 5, 2024
1 parent a42ffba commit b96d147
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 78 deletions.
36 changes: 0 additions & 36 deletions runtime/onert/backend/acl_cl/KernelGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -914,42 +914,6 @@ void KernelGenerator::visit(const ir::operation::Pool2D &node)
ActivationBuilder::generate(activation, ofm_tensor->handle()));
}

void KernelGenerator::visit(const ir::operation::Permute &node)
{
const auto ofm_idx{node.getOutputs().at(0)};
const auto ifm_idx{node.getInputs().at(0)};
const auto permute_type = node.getPermuteType();
auto ofm_tensor = _tensor_reg->getAclTensor(ofm_idx);
auto ifm_tensor = _tensor_reg->getAclTensor(ifm_idx);
const auto rank = _ctx.at(ofm_idx).shape().rank();
assert(_ctx.at(ifm_idx).shape().rank() == _ctx.at(ofm_idx).shape().rank());

std::unique_ptr<::arm_compute::IFunction> fn;
arm_compute::PermutationVector pv;
if (permute_type == ir::operation::Permute::Type::NCHW_TO_NHWC && rank == 4)
{
// WHCN -> CWHN
pv = arm_compute::PermutationVector{2, 0, 1};

fn = acl_common::generateLayer<arm_compute::CLPermute>(ifm_tensor->handle(),
ofm_tensor->handle(), pv);
}
else if (permute_type == ir::operation::Permute::Type::NHWC_TO_NCHW && rank == 4)
{
// CWHN -> WHCN
pv = arm_compute::PermutationVector{1, 2, 0};

fn = acl_common::generateLayer<::arm_compute::CLPermute>(ifm_tensor->handle(),
ofm_tensor->handle(), pv);
}
else
{
fn = acl_common::generateLayer<arm_compute::CLCopy>(ifm_tensor->handle(), ofm_tensor->handle());
}

_return_fn = asAclFunction(std::move(fn));
}

void KernelGenerator::visit(const ir::operation::ResizeBilinear &node)
{
const auto ofm_index{node.getOutputs().at(0)};
Expand Down
1 change: 0 additions & 1 deletion runtime/onert/backend/acl_cl/KernelGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class KernelGenerator : public basic::KernelGeneratorBase
void visit(const ir::operation::OneHot &) override;
void visit(const ir::operation::Pack &) override;
void visit(const ir::operation::Pad &) override;
void visit(const ir::operation::Permute &) override;
void visit(const ir::operation::Pool2D &) override;
void visit(const ir::operation::PReLU &) override;
void visit(const ir::operation::Reduce &) override;
Expand Down
35 changes: 0 additions & 35 deletions runtime/onert/backend/acl_neon/KernelGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -759,41 +759,6 @@ void KernelGenerator::visit(const ir::operation::Pool2D &node)
ActivationBuilder::generate(activation, ofm_tensor->handle()));
}

void KernelGenerator::visit(const ir::operation::Permute &node)
{
const auto ofm_idx{node.getOutputs().at(0)};
const auto ifm_idx{node.getInputs().at(0)};
const auto permute_type = node.getPermuteType();
auto ofm_tensor = _tensor_reg->getAclTensor(ofm_idx);
auto ifm_tensor = _tensor_reg->getAclTensor(ifm_idx);
const auto rank = _ctx.at(ofm_idx).shape().rank();
assert(_ctx.at(ifm_idx).shape().rank() == _ctx.at(ofm_idx).shape().rank());

std::unique_ptr<::arm_compute::IFunction> fn;
arm_compute::PermutationVector pv;
if (permute_type == ir::operation::Permute::Type::NCHW_TO_NHWC && rank == 4)
{
// WHCN -> CWHN
pv = arm_compute::PermutationVector{2, 0, 1};

fn = acl_common::generateLayer<arm_compute::NEPermute>(ifm_tensor->handle(),
ofm_tensor->handle(), pv);
}
else if (permute_type == ir::operation::Permute::Type::NHWC_TO_NCHW && rank == 4)
{
// CWHN -> WHCN
pv = arm_compute::PermutationVector{1, 2, 0};

fn = acl_common::generateLayer<arm_compute::NEPermute>(ifm_tensor->handle(),
ofm_tensor->handle(), pv);
}
else
{
fn = acl_common::generateLayer<arm_compute::NECopy>(ifm_tensor->handle(), ofm_tensor->handle());
}
_return_fn = asAclFunction(std::move(fn));
}

void KernelGenerator::visit(const ir::operation::PReLU &node)
{
const auto ofm_index{node.getOutputs().at(0)};
Expand Down
1 change: 0 additions & 1 deletion runtime/onert/backend/acl_neon/KernelGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class KernelGenerator : public basic::KernelGeneratorBase
void visit(const ir::operation::OneHot &) override;
void visit(const ir::operation::Pack &) override;
void visit(const ir::operation::Pad &) override;
void visit(const ir::operation::Permute &) override;
void visit(const ir::operation::Pool2D &) override;
void visit(const ir::operation::PReLU &) override;
void visit(const ir::operation::Reduce &) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,10 @@ ir::OperationIndex PermutationInsertionPass::insertPermute(const ir::OperandInde

// Find Permute information
auto input_backend = operand_li_map.getRawPtr(operand_index)->def_backends().getOnlyElement();
auto output_backend = backend;
const backend::Backend *permute_node_backend = compiler::BackendManager::get().getBuiltin();
assert(permute_node_backend->config()->id() == onert::backend::builtin::Config::ID);
assert(input_backend != backend);

if (input_backend == output_backend)
{
permute_node_backend = input_backend;
}
// Update LowerInfo of input operand
auto operand_lower_info = operand_li_map.getRawPtr(operand_index);
operand_lower_info->removeUseBackend(backend);
Expand Down

0 comments on commit b96d147

Please sign in to comment.