From: 박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 Date: Wed, 12 Jun 2019 04:48:13 +0000 (+0900) Subject: [loco] Introduce CanonicalNode interface (#3743) X-Git-Tag: nncc_backup~432 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=16e0d3bad1f0b8577a905038d27f8d51671b16a7;p=platform%2Fcore%2Fml%2Fnnfw.git [loco] Introduce CanonicalNode interface (#3743) This commit introduces CanonicalNode interface, and rewrites Forward node as an example. Signed-off-by: Jonghyun Park --- diff --git a/contrib/loco/include/loco/IR/CanonicalNode.h b/contrib/loco/include/loco/IR/CanonicalNode.h new file mode 100644 index 0000000..f1dd169 --- /dev/null +++ b/contrib/loco/include/loco/IR/CanonicalNode.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LOCO_IR_CANONICAL_NODE_H__ +#define __LOCO_IR_CANONICAL_NODE_H__ + +#include "loco/IR/Node.h" +#include "loco/IR/Dialect.h" +#include "loco/IR/CanonicalOpcode.h" + +namespace loco +{ + +struct CanonicalNode : public Node +{ + virtual ~CanonicalNode() = default; + + Dialect *dialect(void) const final; + virtual CanonicalOpcode opcode(void) const = 0; +}; + +template struct CanonicalNodeImpl : public CanonicalNode +{ + virtual ~CanonicalNodeImpl() = default; + + CanonicalOpcode opcode(void) const final { return Code; } +}; + +} // namespace loco + +#endif // __LOCO_IR_CANONICAL_NODE_H__ diff --git a/contrib/loco/include/loco/IR/Nodes.h b/contrib/loco/include/loco/IR/Nodes.h index 6094035..a332ea2 100644 --- a/contrib/loco/include/loco/IR/Nodes.h +++ b/contrib/loco/include/loco/IR/Nodes.h @@ -28,6 +28,7 @@ #include "loco/IR/FeatureCodec.h" #include "loco/IR/FilterCodec.h" #include "loco/IR/NodeMixins.h" +#include "loco/IR/CanonicalNode.h" namespace loco { @@ -62,7 +63,7 @@ public: * * This node may encode memory transfer (such as CPU -> GPU or GPU -> CPU) */ -class Forward final : public FixedArityNode<1, Node> +class Forward final : public FixedArityNode<1, CanonicalNodeImpl> { public: Forward() = default; diff --git a/contrib/loco/src/IR/CanonicalNode.cpp b/contrib/loco/src/IR/CanonicalNode.cpp new file mode 100644 index 0000000..42e9cd1 --- /dev/null +++ b/contrib/loco/src/IR/CanonicalNode.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "loco/IR/CanonicalNode.h" +#include "loco/IR/CanonicalDialect.h" + +namespace loco +{ + +Dialect *CanonicalNode::dialect(void) const { return CanonicalDialect::get(); } + +} // namespace loco diff --git a/contrib/loco/src/IR/Nodes.test.cpp b/contrib/loco/src/IR/Nodes.test.cpp index 72d2486..5a04fbc 100644 --- a/contrib/loco/src/IR/Nodes.test.cpp +++ b/contrib/loco/src/IR/Nodes.test.cpp @@ -15,6 +15,7 @@ */ #include "loco/IR/Nodes.h" +#include "loco/IR/CanonicalDialect.h" #include @@ -67,6 +68,9 @@ TEST(ForwardTest, constructor) { loco::Forward forward_node; + ASSERT_EQ(forward_node.dialect(), loco::CanonicalDialect::get()); + ASSERT_EQ(forward_node.opcode(), loco::CanonicalOpcode::Forward); + ASSERT_EQ(forward_node.input(), nullptr); }