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 "UnpackLayer.h"
19 #include "OperationUtils.h"
21 #include <cker/operation/Unpack.h>
32 UnpackLayer::UnpackLayer() : _input(nullptr), _outputs(), _axis(0), _num_output(0)
37 template <typename T> void UnpackLayer::unpackImpl()
39 nnfw::cker::UnpackParams op_params;
40 op_params.axis = _axis;
41 op_params.num_split = _num_output;
43 std::vector<nnfw::cker::Shape *> outputDimsPtr;
44 std::vector<nnfw::cker::Shape> outputDims;
45 outputDimsPtr.reserve(_num_output);
46 outputDims.reserve(_num_output);
48 for (int32_t i = 0; i < _num_output; i++)
50 outputDims.push_back(getShape(_outputs[i]));
51 outputDimsPtr.push_back(&outputDims[i]);
54 std::vector<T *> outputPtrs;
56 for (const auto output : _outputs)
58 outputPtrs.emplace_back(getBuffer<T>(output));
61 nnfw::cker::Unpack<T>(op_params, getShape(_input), getBuffer<T>(_input), getShape(_outputs[0]),
65 void UnpackLayer::configure(const IPortableTensor *input, uint32_t axis, int32_t num,
66 std::vector<IPortableTensor *> &outputs)
68 assert(input != nullptr);
69 assert(outputs.size() > 0);
70 assert(outputs.size() == (size_t)num);
78 void UnpackLayer::run()
80 if (_input->data_type() == OperandType::FLOAT32)
82 else if (_input->data_type() == OperandType::INT32)
83 unpackImpl<int32_t>();
85 throw std::runtime_error{"Unpack: Unsupported data type"};
90 } // namespace backend