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 core::OMReduceDataContext<T> ctx(rt_kernel);
35
36 bool is_ok = pal::Reduce<T, pal::ReduceSumFn>(ctx, true);
37 if (!is_ok)
38 {
39 return UnknownError;
40 }
41
42 return Ok;
43}
44
45} // namespace impl
46
47// ------------------------------------------------------------------------------------------------
48
49namespace onert_micro
50{
51namespace execute
52{
53
55{
56 core::OMRuntimeContext &runtime_context = execute_args.runtime_context;
57 core::OMRuntimeStorage &runtime_storage = execute_args.runtime_storage;
58 uint16_t op_index = execute_args.kernel_index;
59
60 OMRuntimeKernel runtime_kernel;
61 runtime_kernel.readKernel(op_index, runtime_context);
62 runtime_kernel.getDataFromStorage(op_index, runtime_storage, runtime_context);
63
64 constexpr static size_t kInputTensorIdx = 0;
65 const circle::Tensor *input = runtime_kernel.inputs[kInputTensorIdx];
66
67 switch (input->type())
68 {
69#ifndef DIS_FLOAT
70 case circle::TensorType_FLOAT32:
71 {
72 return impl::CircleMean<float>(runtime_kernel);
73 }
74 break;
75#endif // DIS_FLOAT
76
77#ifndef DIS_QUANT
78 case circle::TensorType_INT8:
79 // FIXME: this is not for QUANTIZED int8
80 return impl::CircleMean<int8_t>(runtime_kernel);
81#endif // DIS_QUANT
82
83 case circle::TensorType_INT32:
84 case circle::TensorType_INT64:
85 default:
86 assert(false && "Unsupported type");
87 return UnsupportedType;
88 }
89}
90
91} // namespace execute
92} // namespace onert_micro
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:54
@ UnsupportedType
Definition OMStatus.h:26
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage