ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Mean.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 */
19
20#include "OMStatus.h"
21#include "PALReduceCommon.h"
22
23using namespace onert_micro;
24using namespace onert_micro::core;
25using namespace onert_micro::execute;
26
27// ------------------------------------------------------------------------------------------------
28
29namespace impl
30{
31
32template <typename T> OMStatus CircleMean(OMRuntimeKernel &rt_kernel)
33{
34 constexpr static T kInitValue = 0;
35
36 core::OMReduceDataContext<T> ctx(rt_kernel);
37 pal::Reducer<T, pal::ReduceSumFn> reducer(ctx, kInitValue);
38
39 bool is_ok = reducer.Mean();
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
50// ------------------------------------------------------------------------------------------------
51
52namespace onert_micro
53{
54namespace execute
55{
56
58{
59 core::OMRuntimeContext &runtime_context = execute_args.runtime_context;
60 core::OMRuntimeStorage &runtime_storage = execute_args.runtime_storage;
61 uint16_t op_index = execute_args.kernel_index;
62
63 OMRuntimeKernel runtime_kernel;
64 runtime_kernel.readKernel(op_index, runtime_context);
65 runtime_kernel.getDataFromStorage(op_index, runtime_storage, runtime_context);
66
67 const size_t kInputTensorIdx = 0;
68 const circle::Tensor *input = runtime_kernel.inputs[kInputTensorIdx];
69
70 switch (input->type())
71 {
72#ifndef DIS_FLOAT
73 case circle::TensorType_FLOAT32:
74 {
75 return impl::CircleMean<float>(runtime_kernel);
76 }
77 break;
78#endif // DIS_FLOAT
79
80#ifndef DIS_QUANT
81 case circle::TensorType_INT8:
82 // FIXME: this is not for QUANTIZED int8
83 return impl::CircleMean<int8_t>(runtime_kernel);
84#endif // DIS_QUANT
85
86 case circle::TensorType_INT32:
87 case circle::TensorType_INT64:
88 default:
89 assert(false && "Unsupported type");
90 OM_LOG_AND_RETURN(UnsupportedType, "Unsupported type encountered");
91 }
92}
93
94} // namespace execute
95} // 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 CircleMean(OMRuntimeKernel &rt_kernel)
Definition Mean.cpp:32
OMStatus execute_kernel_CircleMean(const OMExecuteArgs &execute_args)
Definition Mean.cpp:57
@ UnsupportedType
Definition OMStatus.h:26
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage