Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[onert] Remove Permute IR handling in general backend #13594

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Q) Why should not those backends be the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PermutationInsertionPass was introduced for

  1. Layout change between use-def
  2. Backend change between use-def

Now 1) is impossible. So insertPermute is called when backend is changed.


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