ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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
21namespace onert
22{
23namespace backend
24{
25namespace builtin
26{
27namespace train
28{
29namespace kernel
30{
31
32PermuteLayer::PermuteLayer(const std::vector<ITensor *> &src_tensors,
33 const std::vector<ITensor *> &dst_tensors,
34 const std::vector<ITensor *> &input_back_prop_tensors,
35 const std::vector<ITensor *> &output_back_prop_tensors,
36 const std::vector<ir::PermuteType> &types,
37 bool ignore_forward_in_training,
38 const std::shared_ptr<ExternalContext> &external_context)
39 : builtin::kernel::PermuteLayer{src_tensors, dst_tensors, types, external_context},
40 _input_back_prop_tensors{input_back_prop_tensors},
41 _output_back_prop_tensors{output_back_prop_tensors},
42 _ignore_forward_in_training{ignore_forward_in_training}
43{
44 assert(input_back_prop_tensors.size() == output_back_prop_tensors.size());
45 assert(src_tensors.size() == dst_tensors.size());
46}
47
49{
51
52 // TODO Calculate offsets of back propagation tensors if necessary
53}
54
56{
57 if (_ignore_forward_in_training)
58 return;
59
61}
62
64{
65 for (uint32_t i = 0; i < _output_back_prop_tensors.size(); ++i)
66 {
67 auto src_back_prop = _output_back_prop_tensors.at(i);
68 auto dst_back_prop = _input_back_prop_tensors.at(i);
69
70 // NOTE The back propagation tensors corresponding to inputs/outputs of model are nullptr
71 // because permuting those tensors is meaningless
72 if (src_back_prop && dst_back_prop)
73 {
74 const auto rank = src_back_prop->getShape().rank();
75 auto output_offsets = _dst_tensors_offsets.at(i);
76 auto input_offsets = _src_tensors_offsets.at(i);
77 auto permute_type = _permute_types.at(i);
78
79 exec::IPermuteFunction::permute(src_back_prop, dst_back_prop, rank, output_offsets,
80 input_offsets, permute_type);
81 }
82 }
83}
84
85} // namespace kernel
86} // namespace train
87} // namespace builtin
88} // namespace backend
89} // namespace onert
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