ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
While.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 "core/OMUtils.h"
19#include "OMStatus.h"
21
22using namespace onert_micro;
23using namespace onert_micro::core;
24
25namespace onert_micro
26{
27namespace import
28{
29
31{
32 OMRuntimeModule &runtime_module = config_args.runtime_module;
33 OMRuntimeContext &runtime_context = config_args.runtime_context;
34 uint16_t op_index = config_args.kernel_index;
35
37
38 OMStatus status = runtime_kernel.readKernel(op_index, runtime_context);
39 if (status != Ok)
40 return status;
41
42 auto options = runtime_kernel.first_operator->builtin_options_as_WhileOptions();
43 status = utils::checkCondition(options != nullptr);
44 if (status != Ok)
45 return status;
46
47 // Num of inputs equals to num of outputs
48 status = utils::checkCondition(runtime_kernel.inputs_num == runtime_kernel.outputs_num);
49 if (status != Ok)
50 return status;
51
52 // Obtain conditional and body runtime subgraphs
53 const auto body_subgraph_index = options->body_subgraph_index();
54 const auto cond_subgraph_index = options->cond_subgraph_index();
55 OMRuntimeGraph *cond_runtime_graph = nullptr;
56 OMRuntimeGraph *body_runtime_graph = nullptr;
57 status = runtime_module.getRuntimeGraphAt(cond_subgraph_index, &cond_runtime_graph);
58 if (status != Ok)
59 return status;
60 status = runtime_module.getRuntimeGraphAt(body_subgraph_index, &body_runtime_graph);
61 if (status != Ok)
62 return status;
63
64 OMRuntimeContext &cond_runtime_context = cond_runtime_graph->getRuntimeContext();
65 OMRuntimeContext &body_runtime_context = body_runtime_graph->getRuntimeContext();
66
67 // Check cond runtime graph
68 status =
69 utils::checkCondition(cond_runtime_graph->getNumberOfInputs() == runtime_kernel.inputs_num and
70 cond_runtime_graph->getNumberOfOutputs() == 1);
71 if (status != Ok)
72 return status;
73
74 const auto cond_output_index = cond_runtime_context.getGraphOutputTensorIndex(0);
75 const auto cond_output_tensor =
76 cond_runtime_context.getTensorByIndex(static_cast<int32_t>(cond_output_index));
77 status = utils::checkCondition(cond_output_tensor->type() == circle::TensorType_BOOL);
78
79 // Check body runtime graph
80 status =
81 utils::checkCondition(body_runtime_graph->getNumberOfInputs() == runtime_kernel.inputs_num and
82 body_runtime_graph->getNumberOfOutputs() == runtime_kernel.outputs_num);
83 return status;
84}
85
86} // namespace import
87} // namespace onert_micro
uint32_t getGraphOutputTensorIndex(uint32_t index)
const circle::Tensor * getTensorByIndex(int32_t tensor_index)
OMRuntimeContext & getRuntimeContext()
OMStatus getRuntimeGraphAt(uint32_t pos, OMRuntimeGraph **runtime_graph)
const circle::Operator * first_operator
OMStatus readKernel(uint16_t op_index, core::OMRuntimeContext &runtime_context)
OMStatus configure_kernel_CircleWhile(const onert_micro::import::OMConfigureArgs &config_args)
Definition While.cpp:30
core::OMRuntimeContext & runtime_context
core::OMRuntimeModule & runtime_module