ONE - On-device Neural Engine
Loading...
Searching...
No Matches
SpaceToDepth.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
18#include "OMStatus.h"
20
21#include "core/OMRuntimeShape.h"
22#include "PALSpaceToDepth.h"
23
24using namespace onert_micro;
25using namespace onert_micro::execute;
26namespace
27{
28
29constexpr uint32_t inputTensorIdx = 0;
30constexpr uint32_t outputTensorIdx = 0;
31
32} // namespace
33namespace onert_micro
34{
35namespace execute
36{
37
39{
40 core::OMRuntimeContext &runtime_context = execute_args.runtime_context;
41 core::OMRuntimeStorage &runtime_storage = execute_args.runtime_storage;
42 uint16_t op_index = execute_args.kernel_index;
43
44 const circle::Tensor *input;
45 const circle::Tensor *output;
46
47 uint8_t *input_data;
48 uint8_t *output_data;
49
50 // Read kernel
51 execute::OMRuntimeKernel runtime_kernel;
52 OMStatus status = runtime_kernel.readKernel(op_index, runtime_context);
53 if (status != Ok)
54 return status;
55
56 input = runtime_kernel.inputs[inputTensorIdx];
57 output = runtime_kernel.outputs[outputTensorIdx];
58
59 core::OMRuntimeShape input_shape(input);
61
62 assert(input != nullptr);
63 assert(output != nullptr);
64
65 status = runtime_kernel.getDataFromStorage(op_index, runtime_storage, runtime_context);
66 if (status != Ok)
67 return status;
68
69 input_data = runtime_kernel.inputs_data[inputTensorIdx];
70 output_data = runtime_kernel.outputs_data[outputTensorIdx];
71 const auto *options = runtime_kernel.first_operator->builtin_options_as_SpaceToDepthOptions();
72 const int32_t block_size = options->block_size();
73 switch (input->type())
74 {
75#ifndef DIS_FLOAT
76 case circle::TensorType_FLOAT32:
77 {
78 status =
79 pal::SpaceToDepth<float>(block_size, input_shape, reinterpret_cast<float *>(input_data),
80 output_shape, reinterpret_cast<float *>(output_data));
81 }
82 break;
83#endif // DIS_FLOAT
84#ifndef DIS_QUANT
85 case circle::TensorType_INT8:
86 {
87 status =
88 pal::SpaceToDepth<int8_t>(block_size, input_shape, reinterpret_cast<int8_t *>(input_data),
89 output_shape, reinterpret_cast<int8_t *>(output_data));
90 }
91 break;
92#endif // DIS_QUANT
93 default:
94 {
95 status = UnsupportedType;
96 assert(false && "Unsupported type.");
97 }
98 }
99
100 return status;
101}
102
103} // namespace execute
104} // namespace onert_micro
uint8_t * outputs_data[maxOutputSize]
const circle::Operator * first_operator
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 * outputs[maxOutputSize]
const circle::Tensor * inputs[maxInputSize]
const luci_interpreter::RuntimeShape output_shape
constexpr uint32_t outputTensorIdx
OMStatus execute_kernel_CircleSpaceToDepth(const onert_micro::execute::OMExecuteArgs &execute_args)
@ UnsupportedType
Definition OMStatus.h:26
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage