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 "PackLayer.h"
19 #include "OperationUtils.h"
21 #include <cker/operation/Pack.h>
32 PackLayer::PackLayer() : _inputs(), _output(nullptr), _axis(0)
37 void PackLayer::packFloat32()
39 uint32_t num_inputs = _inputs.size();
40 nnfw::cker::PackParams op_params;
41 op_params.axis = _axis;
42 op_params.inputs_count = num_inputs;
44 std::vector<nnfw::cker::Shape *> inputDimsPtr;
45 std::vector<nnfw::cker::Shape> inputDims;
46 inputDimsPtr.reserve(num_inputs);
47 inputDims.reserve(num_inputs);
49 for (uint32_t i = 0; i < num_inputs; i++)
51 inputDims.push_back(convertTensorToCkerShape(_inputs[i]));
52 inputDimsPtr.push_back(&inputDims[i]);
55 std::vector<const float *> inputFloatPtrs;
57 for (const auto input : _inputs)
59 inputFloatPtrs.emplace_back(reinterpret_cast<const float *>(input->buffer()));
62 nnfw::cker::Pack<float>(op_params, inputFloatPtrs.data(), convertTensorToCkerShape(_output),
63 reinterpret_cast<float *>(_output->buffer()));
66 void PackLayer::packQuant8()
68 // cker quant8 pack is not implemented yet
69 throw std::runtime_error{"NYI"};
72 void PackLayer::configure(const std::vector<const operand::Tensor *> &inputs, int32_t axis,
73 operand::Tensor *output)
75 assert(inputs.size() > 0);
76 assert(output != nullptr);
85 if (_output->data_type() == OperandType::FLOAT32)
89 else if (_output->data_type() == OperandType::QUANT8_ASYMM)
97 } // namespace backend