ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ZerosLike.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 "OMStatus.h"
18
19#include "core/OMUtils.h"
20
23
24using namespace onert_micro;
25using namespace onert_micro::execute;
26
27namespace
28{
29
30constexpr uint32_t inputTensorIdx = 0;
31constexpr uint32_t outputTensorIdx = 0;
32
33template <typename T> void resetZeros(T *out, const int num_elements)
34{
35 for (int i = 0; i < num_elements; ++i)
36 {
37 out[i] = static_cast<T>(0);
38 }
39}
40
41} // namespace
42
43namespace onert_micro
44{
45namespace execute
46{
47
49{
50 core::OMRuntimeContext &runtime_context = execute_args.runtime_context;
51 core::OMRuntimeStorage &runtime_storage = execute_args.runtime_storage;
52 uint16_t op_index = execute_args.kernel_index;
53
54 const circle::Tensor *input = nullptr;
55 uint8_t *output_data = nullptr;
56
57 OMStatus status = Ok;
58 {
59 OMRuntimeKernel runtime_kernel;
60 runtime_kernel.readKernel(op_index, runtime_context);
61
62 input = runtime_kernel.inputs[inputTensorIdx];
63
64 assert(input != nullptr);
65
66 status = runtime_kernel.getDataFromStorage(op_index, runtime_storage, runtime_context);
67 if (status != Ok)
68 return status;
69
70 output_data = runtime_kernel.outputs_data[outputTensorIdx];
71 }
72
73 assert(output_data != nullptr);
74
75 core::OMRuntimeShape input_shape(input);
76 const int flat_size = input_shape.flatSize();
77
78 switch (input->type())
79 {
80#ifndef DIS_FLOAT
81 case circle::TensorType_FLOAT32:
82 {
83 resetZeros(core::utils::castOutputData<float>(output_data), flat_size);
84 }
85 break;
86#endif // DIS_FLOAT
87#ifndef DIS_QUANT
88 case circle::TensorType_INT8:
89 {
90 resetZeros(core::utils::castOutputData<int8_t>(output_data), flat_size);
91 }
92 break;
93#endif // DIS_QUANT
94
95 default:
96 {
97 status = UnsupportedType;
98 assert(false && "Unsupported type.");
99 break;
100 }
101 }
102
103 return status;
104}
105
106} // namespace execute
107} // namespace onert_micro
uint8_t * outputs_data[maxOutputSize]
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]
constexpr uint32_t outputTensorIdx
uint32_t num_elements(const Shape &shape)
The number of elements of a feature map of a given shape.
Definition Shape.h:59
OMStatus execute_kernel_CircleZerosLike(const OMExecuteArgs &execute_args)
Definition ZerosLike.cpp:48
@ UnsupportedType
Definition OMStatus.h:26
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage