2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __ONERT_BACKEND_CONTROLFLOW_KERNEL_PERMUTELAYER_H__
18 #define __ONERT_BACKEND_CONTROLFLOW_KERNEL_PERMUTELAYER_H__
20 #include "backend/ITensorBuilder.h"
21 #include "exec/IPermuteFunction.h"
22 #include "exec/IExecutor.h"
33 class PermuteLayer : public onert::exec::IPermuteFunction
36 PermuteLayer(const std::vector<std::shared_ptr<ITensor>> &src_tensors,
37 const std::vector<std::shared_ptr<ITensor>> &dst_tensors,
38 const exec::DynAllocInfoMap &dst_dyn_alloc_info_map)
39 : _dst_dyn_alloc_info_map{dst_dyn_alloc_info_map}
41 assert(src_tensors.size() == dst_tensors.size());
42 _src_tensors = src_tensors;
43 _dst_tensors = dst_tensors;
46 void optimize() override
48 // Remove copying of tensor as nullptr
49 auto src_it = _src_tensors.begin();
50 auto dst_it = _dst_tensors.begin();
51 while (src_it != _src_tensors.end())
53 if ((*src_it == *dst_it) || (*src_it == nullptr || *dst_it == nullptr))
55 src_it = _src_tensors.erase(src_it);
56 dst_it = _dst_tensors.erase(dst_it);
69 const exec::DynAllocInfoMap _dst_dyn_alloc_info_map;
73 } // namespace controlflow
74 } // namespace backend
77 #endif // __ONERT_BACKEND_CONTROLFLOW_KERNEL_PERMUTELAYER_H__