ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Transpose.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "../KernelGenerator.h"
18#include "../Validator.h"
19
20#include <AclKernelGen.h>
21
23{
24
25void Validator::visit(const ir::operation::Transpose &) { _supported = true; }
26
27void KernelGenerator::visit(const ir::operation::Transpose &node)
28{
29 const auto ofm_idx{node.getOutputs().at(0)};
30 const auto ifm_idx{node.getInputs().at(ir::operation::Transpose::Input::INPUT)};
31 const auto perm_idx{node.getInputs().at(ir::operation::Transpose::Input::PERMUTATION)};
32
33 auto ofm_tensor = _tensor_reg->getAclTensor(ofm_idx);
34 const auto ifm_tensor = _tensor_reg->getAclTensor(ifm_idx);
35 const auto rank = _ctx.at(ifm_idx).shape().rank();
36
37 const auto &perms = _ctx.at(perm_idx);
38 std::vector<int32_t> pv;
39 if (perms.shape() == ir::Shape{0})
40 {
41 pv.resize(rank);
42 std::iota(pv.begin(), pv.end(), 0);
43 std::reverse(pv.begin(), pv.end());
44 }
45 else
46 {
47 pv = _ctx.at(perm_idx).asVector<int32_t>();
48 }
49
50 std::unique_ptr<arm_compute::IFunction> fn;
51 if (rank == 1)
52 {
53 fn = acl_common::generateLayer<arm_compute::NECopy>(ifm_tensor->handle(), ofm_tensor->handle());
54 }
55 else if (rank == 2)
56 {
57 assert(pv.size() == 2 && pv.at(0) == 1 && pv.at(1) == 0);
58 fn = acl_common::generateLayer<arm_compute::NETranspose>(ifm_tensor->handle(),
59 ofm_tensor->handle());
60 }
61 else
62 {
63 auto backend_pv = acl_common::getARMComputePermutationVector(rank, pv);
64
65 fn = acl_common::generateLayer<arm_compute::NEPermute>(ifm_tensor->handle(),
66 ofm_tensor->handle(), backend_pv);
67 }
69}
70
71} // namespace onert::backend::acl_neon
std::unique_ptr< exec::IFunction > _return_fn
const Object & at(const Index &index) const
Get the object that is associated with the given index.
inline ::arm_compute::PermutationVector getARMComputePermutationVector(uint32_t rank, const std::vector< int32_t > runtime_pv)
Definition Swizzle.h:68
std::unique_ptr< AclFunction > asAclFunction(std::unique_ptr<::arm_compute::IFunction > &&layer)
Definition Convert.cc:246