From d1115519539b45297aa7421ddee07d87b9cc6941 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9C=A4=ED=98=84=EC=8B=9D/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 26 Aug 2019 12:54:57 +0900 Subject: [PATCH] [exo-tflite] Introducing TFLRelu class (#6893) * [exo-tflite] Introducing TFLRelu class This adds TFLRelu class. summary() of TFLFormattedGraph is also added (without this warning will occurs) Signed-off-by: Hyun Sik Yoon * change the way how 'unused variable error' is handled --- compiler/exo-tflite/src/Dialect/IR/TFLNodes.h | 12 +++++++- compiler/exo-tflite/src/Dialect/IR/TFLNodes.lst | 3 +- .../exo-tflite/src/Dialect/IR/TFLNodes.test.cpp | 32 ++++++++++++++++++++++ compiler/exo-tflite/src/TFLFormattedGraph.cpp | 20 ++++++++++---- 4 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 compiler/exo-tflite/src/Dialect/IR/TFLNodes.test.cpp diff --git a/compiler/exo-tflite/src/Dialect/IR/TFLNodes.h b/compiler/exo-tflite/src/Dialect/IR/TFLNodes.h index 5f7910f..5feee48 100644 --- a/compiler/exo-tflite/src/Dialect/IR/TFLNodes.h +++ b/compiler/exo-tflite/src/Dialect/IR/TFLNodes.h @@ -26,7 +26,17 @@ namespace locoex { -// TODO define TFLNodes here +class TFLRelu final : public loco::FixedArityNode<1, TFLNodeImpl> +{ +public: + TFLRelu() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } +}; + +// TODO define more children of TFLNode } // namespace locoex diff --git a/compiler/exo-tflite/src/Dialect/IR/TFLNodes.lst b/compiler/exo-tflite/src/Dialect/IR/TFLNodes.lst index 0a45cfd..76f59d4 100644 --- a/compiler/exo-tflite/src/Dialect/IR/TFLNodes.lst +++ b/compiler/exo-tflite/src/Dialect/IR/TFLNodes.lst @@ -5,5 +5,4 @@ // // PLEASE SORT NODE DECLS IN ALPHABETICAL ORDER // -// Example) -// TFL_NODE(Relu, locoex::TFLRelu) +TFL_NODE(RELU, locoex::TFLRelu) diff --git a/compiler/exo-tflite/src/Dialect/IR/TFLNodes.test.cpp b/compiler/exo-tflite/src/Dialect/IR/TFLNodes.test.cpp new file mode 100644 index 0000000..9092068 --- /dev/null +++ b/compiler/exo-tflite/src/Dialect/IR/TFLNodes.test.cpp @@ -0,0 +1,32 @@ +/* + * 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 "TFLNodes.h" + +#include "TFLDialect.h" +#include "TFLOpcode.h" + +#include + +TEST(TFLReluTest, constructor) +{ + locoex::TFLRelu relu_node; + + ASSERT_EQ(relu_node.dialect(), locoex::TFLDialect::get()); + ASSERT_EQ(relu_node.opcode(), locoex::TFLOpcode::RELU); + + ASSERT_EQ(relu_node.input(), nullptr); +} diff --git a/compiler/exo-tflite/src/TFLFormattedGraph.cpp b/compiler/exo-tflite/src/TFLFormattedGraph.cpp index d2b0c17..13944f8 100644 --- a/compiler/exo-tflite/src/TFLFormattedGraph.cpp +++ b/compiler/exo-tflite/src/TFLFormattedGraph.cpp @@ -39,12 +39,12 @@ public: bool build(const loco::Node *, locop::NodeSummary &s) const final; protected: -#define TFL_NODE(OPCODE, CLASS) \ - virtual bool summary(const CLASS *node, locop::NodeSummary &s) const \ - { \ - s.opname("NYI " #CLASS); \ - s.state(locop::NodeSummary::State::PartiallyKnown); \ - return true; \ +#define TFL_NODE(OPCODE, CLASS) \ + virtual bool summary(const CLASS *, locop::NodeSummary &s) const \ + { \ + s.opname("NYI " #CLASS); \ + s.state(locop::NodeSummary::State::PartiallyKnown); \ + return true; \ } #include "Dialect/IR/TFLNodes.lst" #undef TFL_NODE @@ -90,6 +90,14 @@ bool TFLNodeSummaryBuilderBase::build(const loco::Node *node, locop::NodeSummary return false; } +bool TFLNodeSummaryBuilder::summary(const locoex::TFLRelu *node, locop::NodeSummary &s) const +{ + s.opname("TFL.RELU"); + s.args().append("input", tbl()->lookup(node->input())); + s.state(locop::NodeSummary::State::Complete); + return true; +} + } // namespace namespace exo -- 2.7.4