[moco_tf] Introduce TFDialect (#4020)
author박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Mon, 1 Jul 2019 05:13:10 +0000 (14:13 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 1 Jul 2019 05:13:10 +0000 (14:13 +0900)
* [moco_tf] Introduce TFDialect

This will introduce TFDialect inherited from loco::Dialect to provide IRs for TensorFlow dialect.

Signed-off-by: SaeHie Park <saehie.park@samsung.com>
* rename to TFDialect
* fix typo
* fix rename

contrib/moco-tf/src/Dialect/TFDialect.cpp [new file with mode: 0644]
contrib/moco-tf/src/Dialect/TFDialect.h [new file with mode: 0644]
contrib/moco-tf/src/Dialect/TFDialect.test.cpp [new file with mode: 0644]

diff --git a/contrib/moco-tf/src/Dialect/TFDialect.cpp b/contrib/moco-tf/src/Dialect/TFDialect.cpp
new file mode 100644 (file)
index 0000000..7302247
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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 "TFDialect.h"
+
+namespace moco
+{
+namespace tf
+{
+
+loco::Dialect *TFDialect::get(void)
+{
+  static TFDialect d;
+  return &d;
+}
+
+} // namespace tf
+} // namespace moco
diff --git a/contrib/moco-tf/src/Dialect/TFDialect.h b/contrib/moco-tf/src/Dialect/TFDialect.h
new file mode 100644 (file)
index 0000000..9074e18
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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 __MOCO_TF_DIALECT_TFDIALECT_H__
+#define __MOCO_TF_DIALECT_TFDIALECT_H__
+
+#include <loco/IR/Dialect.h>
+
+namespace moco
+{
+namespace tf
+{
+
+/**
+ * @brief A singleton for TensorFlow Dialect
+ */
+class TFDialect final : public loco::Dialect
+{
+private:
+  TFDialect() = default;
+
+public:
+  TFDialect(const TFDialect &) = delete;
+  TFDialect(TFDialect &&) = delete;
+
+public:
+  static loco::Dialect *get(void);
+};
+
+} // namespace tf
+} // namespace moco
+
+#endif // __MOCO_TF_DIALECT_TFDIALECT_H__
diff --git a/contrib/moco-tf/src/Dialect/TFDialect.test.cpp b/contrib/moco-tf/src/Dialect/TFDialect.test.cpp
new file mode 100644 (file)
index 0000000..f89eaaf
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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 "TFDialect.h"
+
+#include <gtest/gtest.h>
+
+TEST(TFDialectTest, get)
+{
+  auto d = moco::tf::TFDialect::get();
+
+  // get() SHOULD return a valid(non-null) pointer
+  ASSERT_NE(d, nullptr);
+  // The return value SHOULD be stable across multiple invocations
+  ASSERT_EQ(d, moco::tf::TFDialect::get());
+}