[exo-tflite] introducing TFLConverter class (#6986)
author윤현식/On-Device Lab(SR)/Principal Engineer/삼성전자 <hyunsik.yoon@samsung.com>
Wed, 28 Aug 2019 06:54:14 +0000 (15:54 +0900)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 28 Aug 2019 06:54:14 +0000 (15:54 +0900)
* [exo-tflite] introducing TFLConverter class

Children of this class will convert a loco node to TFL node. This class is a parent of those children.

Signed-off-by: Hyun Sik Yoon <hyunsik.yoon@samsung.com>
* remove graph param from

compiler/exo-tflite/src/Conversion/TFLConverter.cpp [new file with mode: 0644]
compiler/exo-tflite/src/Conversion/TFLConverter.h [new file with mode: 0644]

diff --git a/compiler/exo-tflite/src/Conversion/TFLConverter.cpp b/compiler/exo-tflite/src/Conversion/TFLConverter.cpp
new file mode 100644 (file)
index 0000000..7637cdf
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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 "TFLConverter.h"
+
+#include <loco.h>
+#include <loco/IR/CanonicalDialect.h>
+
+namespace exo
+{
+
+template <typename CanonicalType> bool TFLConverter<CanonicalType>::run(loco::Graph *graph)
+{
+  auto active_nodes = loco::active_nodes(loco::output_nodes(graph));
+  bool changed = false;
+
+  for (auto node : active_nodes)
+  {
+    if (node->dialect() == loco::CanonicalDialect::get())
+    {
+      auto the_node = dynamic_cast<CanonicalType *>(node);
+      if (the_node != nullptr)
+      {
+        if (convert(the_node))
+          changed = true;
+      }
+    }
+  }
+
+  return changed;
+}
+
+// Add template instantiation of subclasses
+// E.g.,
+// template bool TFLConverter<loco::AvgPool2D>::run(loco::Graph *graph);
+
+} // namespace exo
diff --git a/compiler/exo-tflite/src/Conversion/TFLConverter.h b/compiler/exo-tflite/src/Conversion/TFLConverter.h
new file mode 100644 (file)
index 0000000..c08396f
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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 __CONVERSION_TFLCONVERTER_H__
+#define __CONVERSION_TFLCONVERTER_H__
+
+#include "Convert.h"
+
+#include <loco.h>
+#include <logo/Pass.h>
+
+namespace exo
+{
+
+/**
+ * @brief Class to convert a canonical node to TFL node
+ */
+template <typename CanonicalType> class TFLConverter : public logo::Pass
+{
+public:
+  virtual const char *name(void) const { return nullptr; }
+
+public:
+  bool run(loco::Graph *graph);
+
+protected:
+  virtual bool convert(CanonicalType *node) = 0;
+};
+
+} // namespace exo
+
+#endif //__CONVERSION_TFLCONVERTER_H__