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
43OMStatus onert_micro::import::configure_kernel_CircleGRU(const OMConfigureArgs &config_args)
44{
45 core::OMRuntimeContext &runtime_context = config_args.runtime_context;
46 uint16_t op_index = config_args.kernel_index;
47
48 const circle::Tensor *input;
49 const circle::Tensor *hidden_hidden;
50 const circle::Tensor *hidden_hidden_bias;
51 const circle::Tensor *hidden_input;
52 const circle::Tensor *hidden_input_bias;
53 const circle::Tensor *state;
54
55 const circle::Tensor *output;
56
57 // Read kernel
58 execute::OMRuntimeKernel runtime_kernel;
59 runtime_kernel.readKernel(op_index, runtime_context);
60
61 input = runtime_kernel.inputs[inputTensorIdx];
62 hidden_hidden = runtime_kernel.inputs[hiddenHiddenTensorIdx];
63 hidden_hidden_bias = runtime_kernel.inputs[hiddenHiddenBiasTensorIdx];
64 hidden_input = runtime_kernel.inputs[hiddenInputTensorIdx];
65 hidden_input_bias = runtime_kernel.inputs[hiddenInputBiasTensorIdx];
66 state = runtime_kernel.inputs[stateTensorIdx];
67
68 output = runtime_kernel.outputs[outputTensorIdx];
69 assert(input != nullptr);
70 assert(hidden_hidden != nullptr);
71 assert(hidden_input != nullptr);
72 assert(state != nullptr);
73 // Biases can be nullptr
74 assert(output != nullptr);
75
76 OMStatus status = Ok;
77
78 OMRuntimeShape hidden_hidden_shape(hidden_hidden);
79 OMRuntimeShape hidden_input_shape(hidden_input);
81 OMRuntimeShape state_shape(state);
82
83 status = utils::checkCondition(hidden_hidden_shape.dims(0) == hidden_input_shape.dims(0));
84 if (status != Ok)
85 return status;
86
87 const int32_t div_factor = 3;
88 status =
89 utils::checkCondition(hidden_hidden_shape.dims(0) ==
90 (div_factor * output_shape.dims(output_shape.dimensionsCount() - 1)));
91 if (status != Ok)
92 return status;
93
94 status = utils::checkCondition(output_shape.dims(output_shape.dimensionsCount() - 1) ==
95 state_shape.dims(state_shape.dimensionsCount() - 1));
96 if (status != Ok)
97 return status;
98
99 status = utils::checkCondition(input->type() == output->type());
100 if (status != Ok)
101 return status;
102
103 return status;
104}
int32_t dimensionsCount() const
Definition Tensor.h:106
int32_t dims(int i) const
Definition Tensor.h:108
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