ONE - On-device Neural Engine
Loading...
Searching...
No Matches
CircleDialect.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 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
21
22#include <loco/IR/Graph.h>
25
26#include <cassert>
27#include <memory>
28
29namespace
30{
31
32struct GiiQueryServiceImpl final : public loco::GraphInputIndexQueryService
33{
34 bool associated(const loco::Node *node) const final
35 {
36 if (auto circleinput = dynamic_cast<const luci::CircleInput *>(node))
37 {
38 return circleinput->indexed();
39 }
40 return false;
41 }
42
43 loco::GraphOutputIndex index(const loco::Node *node) const final
44 {
45 assert(associated(node));
46 auto circleinput = loco::must_cast<const luci::CircleInput *>(node);
47 return circleinput->index();
48 }
49};
50
51struct GoiQueryServiceImpl final : public loco::GraphOutputIndexQueryService
52{
53 bool associated(const loco::Node *node) const final
54 {
55 if (auto circleoutput = dynamic_cast<const luci::CircleOutput *>(node))
56 {
57 return circleoutput->indexed();
58 }
59 return false;
60 }
61
62 loco::GraphOutputIndex index(const loco::Node *node) const final
63 {
64 assert(associated(node));
65 auto circleoutput = loco::must_cast<const luci::CircleOutput *>(node);
66 return circleoutput->index();
67 }
68};
69
70} // namespace
71
72namespace luci
73{
74
75CircleDialect::CircleDialect()
76{
77 service<loco::GraphInputIndexQueryService>(std::make_unique<GiiQueryServiceImpl>());
78 service<loco::GraphOutputIndexQueryService>(std::make_unique<GoiQueryServiceImpl>());
79 service<logo::DeadNodeQueryService>(std::make_unique<DeadNodeQueryServiceImpl>());
80}
81
83{
84 static CircleDialect d;
85 return &d;
86}
87
88} // namespace luci
Dialect interface.
Definition Dialect.h:37
Logical unit of computation.
Definition Node.h:54
A singleton for Circle Dialect.
static loco::Dialect * get(void)
CircleNode used for Input of the Graph.
Definition CircleInput.h:36
CircleNode for Output of the Graph.
uint32_t GraphOutputIndex
virtual GraphInputIndex index(const Node *node) const =0
virtual bool associated(const Node *node) const =0
Check whether a given node is associated with any Graph-level input.
virtual GraphOutputIndex index(const Node *node) const =0
virtual bool associated(const Node *node) const =0
Check whether a given node is associated with any Graph-level output.