ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ReduceMax.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#include "execute/OMUtils.h"
19#include "OMStatus.h"
21#include "core/OMUtils.h"
22
23#include "core/OMRuntimeShape.h"
24#include "PALReduceCommon.h"
25
26using namespace onert_micro;
27using namespace onert_micro::execute;
28
29namespace impl
30{
31
32template <typename T> OMStatus CircleReduceMax(OMRuntimeKernel &rt_kernel)
33{
34 constexpr static T kInitValue = std::numeric_limits<T>::lowest();
35
36 core::OMReduceDataContext<T> ctx(rt_kernel);
37 pal::Reducer<T, pal::ReduceMaxFn> reducer(ctx, kInitValue);
38
39 bool is_ok = reducer.Reduce();
40 if (!is_ok)
41 {
42 OM_LOG_AND_RETURN(UnknownError, "Unknown error encountered");
43 }
44
45 return Ok;
46}
47
48} // namespace impl
49
50namespace onert_micro
51{
52namespace execute
53{
54
56{
57 core::OMRuntimeContext &rt_context = execute_args.runtime_context;
58 core::OMRuntimeStorage &rt_storage = execute_args.runtime_storage;
59
60 uint16_t op_index = execute_args.kernel_index;
61
62 OMRuntimeKernel rt_kernel;
63 rt_kernel.readKernel(op_index, rt_context);
64 rt_kernel.getDataFromStorage(op_index, rt_storage, rt_context);
65
66 constexpr static size_t kInputTensorIdx = 0;
67
68 const circle::Tensor *input = rt_kernel.inputs[kInputTensorIdx];
69
70 // TODO: Add ReducerOptions support
71
72 switch (input->type())
73 {
74#ifndef DIS_FLOAT
75 case circle::TensorType_FLOAT32:
76 return impl::CircleReduceMax<float>(rt_kernel);
77#endif // DIS_FLOAT
78
79#ifndef DIS_QUANT
80 case circle::TensorType_INT8:
81 return impl::CircleReduceMax<int8_t>(rt_kernel);
82#endif // DIS_QUANT
83
84 case circle::TensorType_INT32:
85 return impl::CircleReduceMax<int32_t>(rt_kernel);
86
87 case circle::TensorType_INT64:
88 return impl::CircleReduceMax<int64_t>(rt_kernel);
89
90 default:
91 assert(false && "Unsupported type");
92 OM_LOG_AND_RETURN(UnsupportedType, "Unsupported type encountered");
93 }
94
95 return Ok;
96}
97
98} // namespace execute
99} // namespace onert_micro
#define OM_LOG_AND_RETURN(err, msg)
Definition OMLog.h:31
OMStatus getDataFromStorage(uint16_t op_index, core::OMRuntimeStorage &storage, core::OMRuntimeContext &context)
OMStatus readKernel(uint16_t op_index, core::OMRuntimeContext &runtime_context)
const circle::Tensor * inputs[maxInputSize]
Definition Mean.cpp:30
OMStatus CircleReduceMax(OMRuntimeKernel &rt_kernel)
Definition ReduceMax.cpp:32
OMStatus execute_kernel_CircleReduceMax(const OMExecuteArgs &execute_args)
Definition ReduceMax.cpp:55
@ UnsupportedType
Definition OMStatus.h:26
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage