ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ReduceProd.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 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
29// ------------------------------------------------------------------------------------------------
30
31namespace impl
32{
33
34template <typename T> OMStatus CircleReduceProd(OMRuntimeKernel &rt_kernel)
35{
36 constexpr static T kInitValue = 1;
37
38 core::OMReduceDataContext<T> ctx(rt_kernel);
39 pal::Reducer<T, pal::ReduceProductFn> reducer(ctx, kInitValue);
40
41 bool is_ok = reducer.Reduce();
42 if (!is_ok)
43 {
44 OM_LOG_AND_RETURN(UnknownError, "Unknown error encountered");
45 }
46
47 return Ok;
48}
49
50} // namespace impl
51
52// ------------------------------------------------------------------------------------------------
53
54namespace onert_micro
55{
56namespace execute
57{
58
60{
61 core::OMRuntimeContext &rt_context = execute_args.runtime_context;
62 core::OMRuntimeStorage &rt_storage = execute_args.runtime_storage;
63
64 uint16_t op_index = execute_args.kernel_index;
65
66 OMRuntimeKernel rt_kernel;
67 rt_kernel.readKernel(op_index, rt_context);
68 rt_kernel.getDataFromStorage(op_index, rt_storage, rt_context);
69
70 constexpr static size_t kInputTensorIdx = 0;
71
72 const circle::Tensor *input = rt_kernel.inputs[kInputTensorIdx];
73
74 // TODO: Add ReducerOptions support
75
76 switch (input->type())
77 {
78#ifndef DIS_FLOAT
79 case circle::TensorType_FLOAT32:
80 return impl::CircleReduceProd<float>(rt_kernel);
81#endif // DIS_FLOAT
82
83#ifndef DIS_QUANT
84 case circle::TensorType_INT8:
85 return impl::CircleReduceProd<int8_t>(rt_kernel);
86#endif // DIS_QUANT
87
88 case circle::TensorType_INT32:
89 return impl::CircleReduceProd<int32_t>(rt_kernel);
90
91 case circle::TensorType_INT64:
92 return impl::CircleReduceProd<int64_t>(rt_kernel);
93
94 default:
95 assert(false && "Unsupported type");
96 OM_LOG_AND_RETURN(UnsupportedType, "Unsupported type encountered");
97 }
98
99 return Ok;
100}
101
102} // namespace execute
103} // 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 CircleReduceProd(OMRuntimeKernel &rt_kernel)
OMStatus execute_kernel_CircleReduceProd(const OMExecuteArgs &execute_args)
@ UnsupportedType
Definition OMStatus.h:26
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage