ONE - On-device Neural Engine
Loading...
Searching...
No Matches
GRU.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
20
21#include "core/OMUtils.h"
22#include "core/OMKernelData.h"
23
25
26using namespace onert_micro;
27using namespace onert_micro::core;
28
29namespace
30{
31
32constexpr uint32_t inputTensorIdx = 0;
33constexpr uint32_t hiddenHiddenTensorIdx = 1;
34constexpr uint32_t hiddenHiddenBiasTensorIdx = 2;
35constexpr uint32_t hiddenInputTensorIdx = 3;
36constexpr uint32_t hiddenInputBiasTensorIdx = 4;
37constexpr uint32_t stateTensorIdx = 5;
38
39constexpr uint32_t outputTensorIdx = 0;
40
41} // namespace
42
43namespace onert_micro
44{
45namespace import
46{
47
49{
50 core::OMRuntimeContext &runtime_context = config_args.runtime_context;
51 uint16_t op_index = config_args.kernel_index;
52
53 const circle::Tensor *input;
54 const circle::Tensor *hidden_hidden;
55 const circle::Tensor *hidden_hidden_bias;
56 const circle::Tensor *hidden_input;
57 const circle::Tensor *hidden_input_bias;
58 const circle::Tensor *state;
59
60 const circle::Tensor *output;
61
62 // Read kernel
63 execute::OMRuntimeKernel runtime_kernel;
64 runtime_kernel.readKernel(op_index, runtime_context);
65
66 input = runtime_kernel.inputs[inputTensorIdx];
67 hidden_hidden = runtime_kernel.inputs[hiddenHiddenTensorIdx];
68 hidden_hidden_bias = runtime_kernel.inputs[hiddenHiddenBiasTensorIdx];
69 hidden_input = runtime_kernel.inputs[hiddenInputTensorIdx];
70 hidden_input_bias = runtime_kernel.inputs[hiddenInputBiasTensorIdx];
71 state = runtime_kernel.inputs[stateTensorIdx];
72
73 output = runtime_kernel.outputs[outputTensorIdx];
74 assert(input != nullptr);
75 assert(hidden_hidden != nullptr);
76 assert(hidden_input != nullptr);
77 assert(state != nullptr);
78 // Biases can be nullptr
79 assert(output != nullptr);
80
81 OMStatus status = Ok;
82
83 OMRuntimeShape hidden_hidden_shape(hidden_hidden);
84 OMRuntimeShape hidden_input_shape(hidden_input);
86 OMRuntimeShape state_shape(state);
87
88 status = utils::checkCondition(hidden_hidden_shape.dims(0) == hidden_input_shape.dims(0));
89 if (status != Ok)
90 return status;
91
92 const int32_t div_factor = 3;
93 status =
94 utils::checkCondition(hidden_hidden_shape.dims(0) ==
95 (div_factor * output_shape.dims(output_shape.dimensionsCount() - 1)));
96 if (status != Ok)
97 return status;
98
99 status = utils::checkCondition(output_shape.dims(output_shape.dimensionsCount() - 1) ==
100 state_shape.dims(state_shape.dimensionsCount() - 1));
101 if (status != Ok)
102 return status;
103
104 status = utils::checkCondition(input->type() == output->type());
105 if (status != Ok)
106 return status;
107
108 return status;
109}
110
111} // namespace import
112} // namespace onert_micro
int32_t dimensionsCount() const
Definition Tensor.h:106
int32_t dims(int i) const
Definition Tensor.h:108
size_t dimensionsCount() const noexcept
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 configure_kernel_CircleGRU(const OMConfigureArgs &config_args)
Definition GRU.cpp:48
core::OMRuntimeContext & runtime_context