ONE - On-device Neural Engine
Loading...
Searching...
No Matches
CircleShapeInferenceRule.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 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
22
23#include "Check.h"
24
25#include <cassert>
26
27namespace
28{
29
35class ShapeInferenceAlgorithm final : public locoex::CircleNodeVisitor<loco::NodeShape>
36{
37public:
39 {
40 auto input_shape = loco::shape_get(node->input()).as<loco::TensorShape>();
41
42 return loco::NodeShape{input_shape};
43 }
44};
45
46} // namespace
47
48namespace locoex
49{
50
52{
53 return CircleDialect::get() == d;
54}
55
57{
58 assert(node->dialect() == CircleDialect::get());
59 assert(dynamic_cast<const CircleNode *>(node) != nullptr);
60
61 ShapeInferenceAlgorithm alg;
62 shape = dynamic_cast<const CircleNode *>(node)->accept(&alg);
63
64 return true;
65}
66
67} // namespace locoex
Dialect interface.
Definition Dialect.h:37
Logical unit of computation.
Definition Node.h:54
virtual const Dialect * dialect(void) const =0
Return "Dialect" identifier that this node belongs to.
ShapeType as(void) const
static loco::Dialect * get(void)
INSTANCE_NORM in circle.
Definition CircleNodes.h:58
NodeShape shape_get(const Node *node)
virtual T visit(const CircleNode *)
Default fallback.
bool infer(const loco::Node *, loco::NodeShape &) const final
Infer node's shape.
bool recognize(const loco::Dialect *) const final
Return true if this rule recognizes a given dialect.