[exo-tflite] Introducing TFLRelu class (#6893)
author윤현식/On-Device Lab(SR)/Principal Engineer/삼성전자 <hyunsik.yoon@samsung.com>
Mon, 26 Aug 2019 03:54:57 +0000 (12:54 +0900)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Mon, 26 Aug 2019 03:54:57 +0000 (12:54 +0900)
* [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 <hyunsik.yoon@samsung.com>
* change the way how 'unused variable error' is handled

compiler/exo-tflite/src/Dialect/IR/TFLNodes.h
compiler/exo-tflite/src/Dialect/IR/TFLNodes.lst
compiler/exo-tflite/src/Dialect/IR/TFLNodes.test.cpp [new file with mode: 0644]
compiler/exo-tflite/src/TFLFormattedGraph.cpp

index 5f7910f..5feee48 100644 (file)
 namespace locoex
 {
 
-// TODO define TFLNodes here
+class TFLRelu final : public loco::FixedArityNode<1, TFLNodeImpl<TFLOpcode::RELU>>
+{
+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
 
index 0a45cfd..76f59d4 100644 (file)
@@ -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 (file)
index 0000000..9092068
--- /dev/null
@@ -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 <gtest/gtest.h>
+
+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);
+}
index d2b0c17..13944f8 100644 (file)
@@ -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