2 * Copyright (c) 2019 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 "GatherLayer.h"
19 #include "OperationUtils.h"
21 #include <cker/operation/Gather.h>
32 void GatherLayer::configure(const IPortableTensor *input, const IPortableTensor *indices,
33 IPortableTensor *output, int32_t axis)
41 template <typename InputType> void GatherLayer::runByInputType()
43 using OutputType = InputType;
44 nnfw::cker::GatherParams op_params;
45 op_params.axis = _axis;
47 switch (_indices->data_type())
49 case OperandType::INT32:
51 using IndicesType = int32_t;
53 nnfw::cker::Gather<InputType, IndicesType>(
54 op_params, getShape(_input), getBuffer<InputType>(_input), getShape(_indices),
55 getBuffer<IndicesType>(_indices), getShape(_output), getBuffer<OutputType>(_output));
58 case OperandType::INT64:
60 using IndicesType = int64_t;
62 nnfw::cker::Gather<InputType, IndicesType>(
63 op_params, getShape(_input), getBuffer<InputType>(_input), getShape(_indices),
64 getBuffer<IndicesType>(_indices), getShape(_output), getBuffer<OutputType>(_output));
68 throw std::runtime_error("Gather: unsupported indices data type");
72 void GatherLayer::run()
74 switch (_input->data_type())
76 case OperandType::FLOAT32:
77 runByInputType<float>();
79 case OperandType::QUANT_UINT8_ASYMM:
80 runByInputType<uint8_t>();
82 case OperandType::INT32:
83 runByInputType<int32_t>();
86 throw std::runtime_error("Gather: unsupported input data type");
92 } // namespace backend