ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ArgMin.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2019 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
22#include "PALArgMinMax.h"
23
24namespace luci_interpreter
25{
26
27// TODO: reduce code duplication with arg max
28void configure_kernel_CircleArgMin(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
29{
30 kernels::TISOKernel kernel(cur_op, runtime_graph);
31 // dim tensor must be a scalar or has one element
32 LUCI_INTERPRETER_CHECK(Tensor::num_dims(kernel.input2()) == 0 or
33 Tensor::num_elements(kernel.input2()) == 1);
34 // value and output type must match
35 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.output()) == DataType::S32);
36
37 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input2()) == DataType::S32);
38}
39
40void execute_kernel_CircleArgMin(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
41{
42 kernels::TISOKernel kernel(cur_op, runtime_graph);
43
44 const circle::Tensor *input = kernel.input1();
45 const circle::Tensor *output = kernel.output();
46
47 kernels::TISOData tiso_data = kernel.readData();
48 const auto input_data = tiso_data.input1_data;
49 const auto axis_data = tiso_data.input2_data;
50 auto output_data = tiso_data.output_data;
51
52 switch (Tensor::element_type(input))
53 {
54#ifndef DIS_FLOAT
55 case DataType::FLOAT32:
56 {
57 luci_interpreter_pal::ArgMinMax(
58 kernels::getTensorRuntimeShape(input, runtime_graph),
59 kernels::getTensorData<float>(input_data), kernels::getTensorData<int32_t>(axis_data),
60 kernels::getTensorRuntimeShape(output, runtime_graph),
61 kernels::getTensorData<int32_t>(output_data), std::less<float>());
62 }
63 break;
64#endif // DIS_FLOAT
65 default:
66 assert(false && "Unsupported ArgMax input type");
67 }
68}
69
70} // namespace luci_interpreter
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
void configure_kernel_CircleArgMin(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition ArgMin.cpp:28
void execute_kernel_CircleArgMin(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition ArgMin.cpp:40