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 template <typename T> void PackLayer::packImpl()
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(getShape(_inputs[i]));
52 inputDimsPtr.push_back(&inputDims[i]);
55 std::vector<const T *> inputPtrs;
57 for (const auto input : _inputs)
59 inputPtrs.emplace_back(getBuffer<T>(input));
62 nnfw::cker::Pack<T>(op_params, inputPtrs.data(), getShape(_output), getBuffer<T>(_output));
65 void PackLayer::configure(const std::vector<const IPortableTensor *> &inputs, int32_t axis,
66 IPortableTensor *output)
68 assert(inputs.size() > 0);
69 assert(output != nullptr);
78 if (_output->data_type() == OperandType::FLOAT32)
82 else if (_output->data_type() == OperandType::INT32)
88 throw std::runtime_error{"Pack: unsupported data type"};
94 } // namespace backend