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 #include "SplitVLayer.h"
19 #include "OperationUtils.h"
21 #include <cker/operation/SplitV.h>
32 SplitVLayer::SplitVLayer()
33 : _input(nullptr), _size_splits(nullptr), _split_dim(nullptr), _num_splits(0), _outputs()
38 template <typename T> void SplitVLayer::splitV(void)
40 nnfw::cker::SplitVParams op_params;
41 op_params.axis = *getBuffer<int32_t>(_split_dim);
42 op_params.num_split = _num_splits;
44 std::vector<T *> outputPtrs;
45 std::vector<nnfw::cker::Shape> outshape;
47 for (const auto output : _outputs)
49 assert(output->total_size() == sizeOfData(output->data_type(), output->getShape().dims()));
50 outputPtrs.emplace_back(getBuffer<T>(output));
51 outshape.emplace_back(getShape(output));
54 assert(_input->total_size() == sizeOfData(_input->data_type(), _input->getShape().dims()));
55 nnfw::cker::SplitV<T>(op_params, getShape(_input), getBuffer<T>(_input), outshape,
59 void SplitVLayer::configure(const IPortableTensor *input, const IPortableTensor *size_splits,
60 const IPortableTensor *split_dim, uint16_t num_splits,
61 std::vector<IPortableTensor *> &outputs)
63 assert(input != nullptr);
65 _num_splits = num_splits;
66 _size_splits = size_splits;
68 _split_dim = split_dim;
72 void SplitVLayer::run()
74 if (_input->data_type() == OperandType::FLOAT32)
78 else if (_input->data_type() == OperandType::QUANT_UINT8_ASYMM)
82 else if (_input->data_type() == OperandType::INT32)
86 else if (_input->data_type() == OperandType::INT64)
92 throw std::runtime_error{"SplitV: unsupported input type"};
98 } // namespace backend