ONE - On-device Neural Engine
Loading...
Searching...
No Matches
CircleIfOut.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 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
19
20#include "CircleCloneNode.h"
21
22namespace
23{
24
25struct CircleIfOutGraphs
26{
27 loco::GraphOutput *then_graph_output;
28 loco::GraphOutput *else_graph_output;
29};
30
31} // namespace
32
33namespace
34{
35
36CircleIfOutGraphs get_out_graphs(const luci::CircleIfOut *node)
37{
38 CircleIfOutGraphs ret_out;
39
44 auto circle_if = loco::must_cast<const luci::CircleIf *>(node->input());
45
46 auto index = node->index();
47 auto then_graph = circle_if->then_graph();
48 auto else_graph = circle_if->else_graph();
49 assert(then_graph != nullptr);
50 assert(else_graph != nullptr);
51
52 // shape and type are assumed to be same
53 // these are checked at post_import_graph() in Import
54 auto then_outputs = loco::output_nodes(then_graph);
55 auto else_outputs = loco::output_nodes(else_graph);
56 assert(then_outputs.size() == else_outputs.size());
57 assert(index < static_cast<int32_t>(then_outputs.size()));
58
59 auto then_out = loco::must_cast<luci::CircleOutput *>(then_outputs.at(index));
60 auto else_out = loco::must_cast<luci::CircleOutput *>(else_outputs.at(index));
61
62 auto then_graph_outputs = then_graph->outputs(); // loco::GraphOutput items
63 auto else_graph_outputs = else_graph->outputs();
64 assert(then_graph_outputs->size() == else_graph_outputs->size());
65
66 ret_out.then_graph_output = then_graph_outputs->at(then_out->index());
67 ret_out.else_graph_output = else_graph_outputs->at(else_out->index());
68
69 return ret_out;
70}
71
72} // namespace
73
74namespace luci
75{
76namespace sinf
77{
78
80{
81 auto graphs = get_out_graphs(node);
82 assert(*graphs.then_graph_output->shape() == *graphs.else_graph_output->shape());
83 return *graphs.then_graph_output->shape();
84}
85
86} // namespace sinf
87
89{
90 auto graphs = get_out_graphs(node);
91 assert(graphs.then_graph_output->dtype() == graphs.else_graph_output->dtype());
92 return graphs.then_graph_output->dtype();
93}
94
95} // namespace luci
96
97namespace luci
98{
99
101{
102 auto *cloned = _graph->nodes()->create<luci::CircleIfOut>();
103 if (cloned != nullptr)
104 cloned->index(node->index());
105 return cloned;
106}
107
108} // namespace luci
NodeContext * nodes(void)
Definition Graph.h:218
Graph-level Output Metadata.
Definition Graph.h:135
Derived * create(Args &&...args)
Definition NodePool.h:37
Virtual CIRCLEIFOUT in Circle.
Definition CircleIfOut.h:32
loco::Node * input(void) const
Definition CircleIfOut.h:34
int32_t index(void) const
Definition CircleIfOut.h:38
luci::CircleNode * visit(const luci::CircleBCQFullyConnected *) final
loco::Graph * _graph
loco::TensorShape visit(const luci::CircleNode *node) final
Default fallback.
loco::DataType visit(const luci::CircleNode *node) final
Default fallback.
std::vector< Node * > output_nodes(Graph *)
Definition Graph.cpp:101
DataType
"scalar" value type
Definition DataType.h:27
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54