ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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
25OMStatus onert_micro::import::configure_kernel_CircleWhile(
26 const onert_micro::import::OMConfigureArgs &config_args)
27{
28 OMRuntimeModule &runtime_module = config_args.runtime_module;
29 OMRuntimeContext &runtime_context = config_args.runtime_context;
30 uint16_t op_index = config_args.kernel_index;
31
33
34 OMStatus status = runtime_kernel.readKernel(op_index, runtime_context);
35 if (status != Ok)
36 return status;
37
38 auto options = runtime_kernel.first_operator->builtin_options_as_WhileOptions();
39 status = utils::checkCondition(options != nullptr);
40 if (status != Ok)
41 return status;
42
43 // Num of inputs equals to num of outputs
44 status = utils::checkCondition(runtime_kernel.inputs_num == runtime_kernel.outputs_num);
45 if (status != Ok)
46 return status;
47
48 // Obtain conditional and body runtime subgraphs
49 const auto body_subgraph_index = options->body_subgraph_index();
50 const auto cond_subgraph_index = options->cond_subgraph_index();
51 OMRuntimeGraph *cond_runtime_graph = nullptr;
52 OMRuntimeGraph *body_runtime_graph = nullptr;
53 status = runtime_module.getRuntimeGraphAt(cond_subgraph_index, &cond_runtime_graph);
54 if (status != Ok)
55 return status;
56 status = runtime_module.getRuntimeGraphAt(body_subgraph_index, &body_runtime_graph);
57 if (status != Ok)
58 return status;
59
60 OMRuntimeContext &cond_runtime_context = cond_runtime_graph->getRuntimeContext();
61 OMRuntimeContext &body_runtime_context = body_runtime_graph->getRuntimeContext();
62
63 // Check cond runtime graph
64 status =
65 utils::checkCondition(cond_runtime_graph->getNumberOfInputs() == runtime_kernel.inputs_num and
66 cond_runtime_graph->getNumberOfOutputs() == 1);
67 if (status != Ok)
68 return status;
69
70 const auto cond_output_index = cond_runtime_context.getGraphOutputTensorIndex(0);
71 const auto cond_output_tensor =
72 cond_runtime_context.getTensorByIndex(static_cast<int32_t>(cond_output_index));
73 status = utils::checkCondition(cond_output_tensor->type() == circle::TensorType_BOOL);
74
75 // Check body runtime graph
76 status =
77 utils::checkCondition(body_runtime_graph->getNumberOfInputs() == runtime_kernel.inputs_num and
78 body_runtime_graph->getNumberOfOutputs() == runtime_kernel.outputs_num);
79 return status;
80}
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)
core::OMRuntimeContext & runtime_context
core::OMRuntimeModule & runtime_module