ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Sum.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 */
18
19#include "OMStatus.h"
20#include "PALReduceCommon.h"
21
22using namespace onert_micro;
23using namespace onert_micro::execute;
24
25// ------------------------------------------------------------------------------------------------
26
27namespace impl
28{
29
30template <typename T> OMStatus CircleSum(OMRuntimeKernel &rt_kernel)
31{
32 constexpr static T kInitValue = 0;
33
34 core::OMReduceDataContext<T> ctx(rt_kernel);
35 pal::Reducer<T, pal::ReduceSumFn> reducer(ctx, kInitValue);
36
37 bool is_ok = reducer.Reduce();
38 if (!is_ok)
39 {
40 OM_LOG_AND_RETURN(UnknownError, "Unknown error encountered");
41 }
42
43 return Ok;
44}
45
46} // namespace impl
47
48// ------------------------------------------------------------------------------------------------
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::CircleSum<float>(rt_kernel);
77#endif // DIS_FLOAT
78
79#ifndef DIS_QUANT
80 case circle::TensorType_INT8:
81 return impl::CircleSum<int8_t>(rt_kernel);
82#endif // DIS_QUANT
83
84 case circle::TensorType_INT32:
85 case circle::TensorType_INT64:
86 default:
87 assert(false && "Unsupported type");
88 OM_LOG_AND_RETURN(UnsupportedType, "Unsupported type encountered");
89 }
90
91 return Ok;
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 CircleSum(OMRuntimeKernel &rt_kernel)
Definition Sum.cpp:30
OMStatus execute_kernel_CircleSum(const OMExecuteArgs &execute_args)
Definition Sum.cpp:55
@ UnsupportedType
Definition OMStatus.h:26
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage