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