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 const auto rank = _ctx.at(ifm_idx).shape().rank();
34
35 auto ofm_tensor = _tensor_reg->getAclTensor(ofm_idx);
36 auto ifm_tensor = _tensor_reg->getAclTensor(ifm_idx);
37
38 const auto &perms = _ctx.at(perm_idx);
39 std::vector<int32_t> pv;
40 if (perms.shape() == ir::Shape{0})
41 {
42 pv.resize(rank);
43 std::iota(pv.begin(), pv.end(), 0);
44 std::reverse(pv.begin(), pv.end());
45 }
46 else
47 {
48 pv = _ctx.at(perm_idx).asVector<int32_t>();
49 }
50
51 std::unique_ptr<arm_compute::IFunction> fn;
52 if (rank == 1)
53 {
54 fn = acl_common::generateLayer<arm_compute::CLCopy>(ifm_tensor->handle(), ofm_tensor->handle());
55 }
56 else if (rank == 2)
57 {
58 assert(pv.size() == 2 && pv.at(0) == 1 && pv.at(1) == 0);
59 fn = acl_common::generateLayer<arm_compute::CLTranspose>(ifm_tensor->handle(),
60 ofm_tensor->handle());
61 }
62 else
63 {
64 auto backend_pv = acl_common::getARMComputePermutationVector(rank, pv);
65
66 fn = acl_common::generateLayer<arm_compute::CLPermute>(ifm_tensor->handle(),
67 ofm_tensor->handle(), backend_pv);
68 }
69
71}
72
73} // namespace onert::backend::acl_cl
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