ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PermuteLayer.cc
Go to the documentation of this file.
1
2
3/*
4 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include "PermuteLayer.h"
20
22{
23
24PermuteLayer::PermuteLayer(const std::vector<ITensor *> &src_tensors,
25 const std::vector<ITensor *> &dst_tensors,
26 const std::vector<ITensor *> &input_back_prop_tensors,
27 const std::vector<ITensor *> &output_back_prop_tensors,
28 const std::vector<ir::PermuteType> &types,
29 bool ignore_forward_in_training,
30 const std::shared_ptr<ExternalContext> &external_context)
31 : builtin::kernel::PermuteLayer{src_tensors, dst_tensors, types, external_context},
32 _input_back_prop_tensors{input_back_prop_tensors},
33 _output_back_prop_tensors{output_back_prop_tensors},
34 _ignore_forward_in_training{ignore_forward_in_training}
35{
36 assert(input_back_prop_tensors.size() == output_back_prop_tensors.size());
37 assert(src_tensors.size() == dst_tensors.size());
38}
39
41{
43
44 // TODO Calculate offsets of back propagation tensors if necessary
45}
46
48{
49 if (_ignore_forward_in_training)
50 return;
51
53}
54
56{
57 for (uint32_t i = 0; i < _output_back_prop_tensors.size(); ++i)
58 {
59 auto src_back_prop = _output_back_prop_tensors.at(i);
60 auto dst_back_prop = _input_back_prop_tensors.at(i);
61
62 // NOTE The back propagation tensors corresponding to inputs/outputs of model are nullptr
63 // because permuting those tensors is meaningless
64 if (src_back_prop && dst_back_prop)
65 {
66 const auto rank = src_back_prop->getShape().rank();
67 auto output_offsets = _dst_tensors_offsets.at(i);
68 auto input_offsets = _src_tensors_offsets.at(i);
69 auto permute_type = _permute_types.at(i);
70
71 exec::IPermuteFunction::permute(src_back_prop, dst_back_prop, rank, output_offsets,
72 input_offsets, permute_type);
73 }
74 }
75}
76
77} // namespace onert::backend::builtin::train::kernel
PermuteLayer(const std::vector< ITensor * > &src_tensors, const std::vector< ITensor * > &dst_tensors, const std::vector< ITensor * > &input_back_prop_tensors, const std::vector< ITensor * > &output_back_prop_tensors, const std::vector< ir::PermuteType > &types, bool ignore_forward_in_training, const std::shared_ptr< ExternalContext > &external_context)
std::vector< std::vector< size_t > > _dst_tensors_offsets
std::vector< ir::PermuteType > _permute_types
void permute(backend::ITensor *src_tensor, backend::ITensor *dst_tensor, size_t rank, std::vector< size_t > &src_offsets, std::vector< size_t > &dst_offsets, const ir::PermuteType &permute_type)
std::vector< std::vector< size_t > > _src_tensors_offsets