From b96d1477ab72f902334fcce7ef97de57e2958ac6 Mon Sep 17 00:00:00 2001 From: Hyeongseok Oh Date: Mon, 5 Aug 2024 20:30:25 +0900 Subject: [PATCH] [onert] Remove Permute IR handling in general backend 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 --- .../onert/backend/acl_cl/KernelGenerator.cc | 36 ------------------- .../onert/backend/acl_cl/KernelGenerator.h | 1 - .../onert/backend/acl_neon/KernelGenerator.cc | 35 ------------------ .../onert/backend/acl_neon/KernelGenerator.h | 1 - .../compiler/pass/PermutationInsertionPass.cc | 6 +--- 5 files changed, 1 insertion(+), 78 deletions(-) diff --git a/runtime/onert/backend/acl_cl/KernelGenerator.cc b/runtime/onert/backend/acl_cl/KernelGenerator.cc index f791bc17f00..c32c298a11e 100644 --- a/runtime/onert/backend/acl_cl/KernelGenerator.cc +++ b/runtime/onert/backend/acl_cl/KernelGenerator.cc @@ -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(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(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)}; diff --git a/runtime/onert/backend/acl_cl/KernelGenerator.h b/runtime/onert/backend/acl_cl/KernelGenerator.h index 71ccc7a7dc6..d8f580f854f 100644 --- a/runtime/onert/backend/acl_cl/KernelGenerator.h +++ b/runtime/onert/backend/acl_cl/KernelGenerator.h @@ -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; diff --git a/runtime/onert/backend/acl_neon/KernelGenerator.cc b/runtime/onert/backend/acl_neon/KernelGenerator.cc index 5b04c3eb655..f0b10399613 100644 --- a/runtime/onert/backend/acl_neon/KernelGenerator.cc +++ b/runtime/onert/backend/acl_neon/KernelGenerator.cc @@ -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(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(ifm_tensor->handle(), - ofm_tensor->handle(), pv); - } - else - { - fn = acl_common::generateLayer(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)}; diff --git a/runtime/onert/backend/acl_neon/KernelGenerator.h b/runtime/onert/backend/acl_neon/KernelGenerator.h index e03e9dc46e0..5721cb123ea 100644 --- a/runtime/onert/backend/acl_neon/KernelGenerator.h +++ b/runtime/onert/backend/acl_neon/KernelGenerator.h @@ -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; diff --git a/runtime/onert/core/src/compiler/pass/PermutationInsertionPass.cc b/runtime/onert/core/src/compiler/pass/PermutationInsertionPass.cc index 586e97f9686..c95d07b421e 100644 --- a/runtime/onert/core/src/compiler/pass/PermutationInsertionPass.cc +++ b/runtime/onert/core/src/compiler/pass/PermutationInsertionPass.cc @@ -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);