[exo-tflite] introducing TypeInferencePass (#7225)
author윤현식/On-Device Lab(SR)/Principal Engineer/삼성전자 <hyunsik.yoon@samsung.com>
Thu, 5 Sep 2019 09:35:41 +0000 (18:35 +0900)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Thu, 5 Sep 2019 09:35:41 +0000 (18:35 +0900)
TypeInferencePass annotates dtype of nodes (canonical/TFL/COp nodes).

Signed-off-by: Hyun Sik Yoon <hyunsik.yoon@samsung.com>
compiler/exo-tflite/src/Conversion/TypeInferencePass.cpp [new file with mode: 0644]
compiler/exo-tflite/src/Conversion/TypeInferencePass.h [new file with mode: 0644]

diff --git a/compiler/exo-tflite/src/Conversion/TypeInferencePass.cpp b/compiler/exo-tflite/src/Conversion/TypeInferencePass.cpp
new file mode 100644 (file)
index 0000000..0996828
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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 "TypeInferencePass.h"
+
+#include "Dialect/IR/TFLDialect.h"
+#include "Dialect/Service/TFLTypeInferenceRule.h"
+
+#include <loco.h>
+#include <loco/IR/CanonicalDialect.h>
+#include <loco/Service/TypeInference.h>
+
+#include <locoex/COpDialect.h>
+#include <locoex/Service/COpTypeInference.h>
+
+namespace exo
+{
+
+bool TypeInferencePass::run(loco::Graph *g)
+{
+  loco::CanonicalTypeInferenceRule canonical_rule;
+  locoex::TFLTypeInferenceRule tfl_rule;
+  locoex::COpTypeInferenceRule cop_rule;
+
+  loco::MultiDialectTypeInferenceRule rules;
+
+  rules.bind(loco::CanonicalDialect::get(), &canonical_rule)
+      .bind(locoex::TFLDialect::get(), &tfl_rule)
+      .bind(locoex::COpDialect::get(), &cop_rule);
+
+  return loco::apply(&rules).to(g);
+}
+
+} // namespace exo
diff --git a/compiler/exo-tflite/src/Conversion/TypeInferencePass.h b/compiler/exo-tflite/src/Conversion/TypeInferencePass.h
new file mode 100644 (file)
index 0000000..ecb1ab4
--- /dev/null
@@ -0,0 +1,41 @@
+
+/*
+ * 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_TYPE_INFERENCE_PASS_H__
+#define __CONVERSION_TYPE_INFERENCE_PASS_H__
+
+#include <loco.h>
+#include <logo/Pass.h>
+
+namespace exo
+{
+
+/**
+ * @brief Pass to infer type of nodes
+ */
+class TypeInferencePass : public logo::Pass
+{
+public:
+  virtual const char *name(void) const { return "TypeInferencePass"; }
+
+public:
+  bool run(loco::Graph *graph);
+};
+
+} // namespace exo
+
+#endif //__CONVERSION_TYPE_INFERENCE_PASS_H__