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

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

diff --git a/compiler/exo-tflite/src/Conversion/ShapeInferencePass.cpp b/compiler/exo-tflite/src/Conversion/ShapeInferencePass.cpp
new file mode 100644 (file)
index 0000000..8b9416e
--- /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 "ShapeInferencePass.h"
+
+#include "Dialect/IR/TFLDialect.h"
+#include "Dialect/Service/TFLShapeInferenceRule.h"
+
+#include <loco.h>
+#include <loco/IR/CanonicalDialect.h>
+#include <loco/Service/CanonicalShapeInferenceRule.h>
+#include <loco/Service/ShapeInference.h>
+#include <loco/Service/MultiDialectShapeInferenceRule.h>
+
+#include <locoex/COpDialect.h>
+#include <locoex/Service/COpShapeInferenceRule.h>
+
+namespace exo
+{
+
+bool ShapeInferencePass::run(loco::Graph *g)
+{
+  loco::CanonicalShapeInferenceRule canonical_rule;
+  locoex::TFLShapeInferenceRule tfl_rule;
+  locoex::COpShapeInferenceRule cop_rule;
+
+  loco::MultiDialectShapeInferenceRule 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/ShapeInferencePass.h b/compiler/exo-tflite/src/Conversion/ShapeInferencePass.h
new file mode 100644 (file)
index 0000000..a05ea75
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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_SHAPE_INFERENCE_PASS_H__
+#define __CONVERSION_SHAPE_INFERENCE_PASS_H__
+
+#include <loco.h>
+#include <logo/Pass.h>
+
+namespace exo
+{
+
+/**
+ * @brief Pass to infer shape of nodes
+ */
+class ShapeInferencePass : public logo::Pass
+{
+public:
+  virtual const char *name(void) const { return "ShapeInferencePass"; }
+
+public:
+  bool run(loco::Graph *graph);
+};
+
+} // namespace exo
+
+#endif //__CONVERSION_SHAPE_INFERENCE_PASS_H__