ONE - On-device Neural Engine
Loading...
Searching...
No Matches
GatherND.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2021 The TensorFlow Authors. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "Builders.h"
19#include "kernels/Utils.h"
20#include "TISOKernel.h"
21#include "PALGatherND.h"
22
23#include <cassert>
24
25namespace luci_interpreter
26{
27
28void configure_kernel_CircleGatherND(const circle::Operator *cur_op,
29 BaseRuntimeGraph *runtime_graph)
30{
31 kernels::TISOKernel kernel(cur_op, runtime_graph);
32
33 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input2()) == DataType::S32);
34 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) ==
35 Tensor::element_type(kernel.output()));
36
37 const int params_rank = Tensor::num_dims(kernel.input1());
38 const int indices_rank = Tensor::num_dims(kernel.input2());
39 const int indices_nd = Tensor::dim(kernel.input2(), indices_rank - 1);
40
41 LUCI_INTERPRETER_CHECK(params_rank >= 1);
42 LUCI_INTERPRETER_CHECK(indices_rank >= 1);
43 LUCI_INTERPRETER_CHECK(indices_nd <= params_rank);
45}
46
47void execute_kernel_CircleGatherND(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
48{
49 kernels::TISOKernel kernel(cur_op, runtime_graph);
50
51 const uint8_t *params_data = runtime_graph->getDataByTensor(kernel.input1());
52 const uint8_t *indies_data = runtime_graph->getConstDataByTensor(kernel.input2());
53 uint8_t *output_data = runtime_graph->getDataByTensor(kernel.output());
54
55 switch (Tensor::element_type(kernel.input1()))
56 {
57#ifndef DIS_FLOAT
58 case DataType::FLOAT32:
59 return luci_interpreter_pal::GatherND<float, int32_t>(
60 kernels::getTensorRuntimeShape(kernel.input1(), runtime_graph),
61 kernels::getTensorData<float>(params_data),
62 kernels::getTensorRuntimeShape(kernel.input2(), runtime_graph),
63 kernels::getTensorData<int32_t>(indies_data), kernels::getTensorData<float>(output_data));
64#endif // DIS_FLOAT
65 default:
66 assert(false && "Unsupported type");
67 }
68}
69
70} // namespace luci_interpreter
uint8_t * getConstDataByTensor(const circle::Tensor *raw_tensor)
uint8_t * getDataByTensor(const circle::Tensor *raw_tensor)
const circle::Tensor * output() const
Definition TISOKernel.h:62
const circle::Tensor * input2() const
Definition TISOKernel.h:61
const circle::Tensor * input1() const
Definition TISOKernel.h:60
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
luci_interpreter::RuntimeShape getTensorRuntimeShape(const circle::Tensor *circle_tensor, BaseRuntimeGraph *runtime_graph)
Definition Utils.cpp:29
constexpr int MAX_INDICES_ND
Definition PALGatherND.h:27
void configure_kernel_CircleGatherND(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition GatherND.cpp:28
void execute_kernel_CircleGatherND(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition GatherND.cpp:47
const loco::Dimension & dim(uint32_t axis) const
Definition Tensor.h:44