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 void UnpackLayer::unpackFloat32()
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(convertTensorToCkerShape(_outputs[i]));
51 outputDimsPtr.push_back(&outputDims[i]);
54 std::vector<float *> outputFloatPtrs;
56 for (const auto output : _outputs)
58 outputFloatPtrs.emplace_back(reinterpret_cast<float *>(output->buffer()));
61 nnfw::cker::Unpack<float>(op_params, convertTensorToCkerShape(_input),
62 reinterpret_cast<float *>(_input->buffer()),
63 convertTensorToCkerShape(_outputs[0]), outputFloatPtrs.data());
66 void UnpackLayer::unpackQuant8()
68 // cker quant8 pack is not implemented yet
69 throw std::runtime_error{"Unpack: NYI quant8 type"};
72 void UnpackLayer::configure(const operand::Tensor *input, uint32_t axis, int32_t num,
73 std::vector<operand::Tensor *> &outputs)
75 assert(input != nullptr);
76 assert(outputs.size() > 0);
77 assert(outputs.size() == (size_t)num);
85 void UnpackLayer::run()
87 if (_input->data_type() == OperandType::FLOAT32)
91 else if (_input->data_type() == OperandType::QUANT8_ASYMM)
97 throw std::runtime_error{"Unpack: Unsupported input type"};
101 } // namespace kernel
103 } // namespace backend