Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / onert-micro / luci-interpreter / src / kernels / ArgMax.cpp
1 /*
2  * Copyright (c) 2020 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
24 namespace luci_interpreter
25 {
26
27 void configure_kernel_CircleArgMax(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
28 {
29   kernels::TISOKernel kernel(cur_op, runtime_graph);
30   // dim tensor must be a scalar or has one element
31   LUCI_INTERPRETER_CHECK(Tensor::num_dims(kernel.input2()) == 0 or
32                          Tensor::num_elements(kernel.input2()) == 1);
33   // value and output type must match
34   LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.output()) == DataType::S32);
35
36   LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input2()) == DataType::S32);
37 }
38
39 void execute_kernel_CircleArgMax(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
40 {
41   kernels::TISOKernel kernel(cur_op, runtime_graph);
42
43   const circle::Tensor *input = kernel.input1();
44   const circle::Tensor *output = kernel.output();
45
46   kernels::TISOData tiso_data = kernel.readData();
47   const auto input_data = tiso_data.input1_data;
48   const auto axis_data = tiso_data.input2_data;
49   auto output_data = tiso_data.output_data;
50
51   switch (Tensor::element_type(input))
52   {
53 #ifndef DIS_FLOAT
54     case DataType::FLOAT32:
55     {
56       luci_interpreter_pal::ArgMinMax(
57         kernels::getTensorRuntimeShape(input, runtime_graph),
58         kernels::getTensorData<float>(input_data), kernels::getTensorData<int32_t>(axis_data),
59         kernels::getTensorRuntimeShape(output, runtime_graph),
60         kernels::getTensorData<int32_t>(output_data), std::greater<float>());
61     }
62     break;
63 #endif // DIS_FLOAT
64     default:
65       assert(false && "Unsupported ArgMax input type");
66   }
67 }
68
69 } // namespace luci_interpreter