[moco/tf] Introduce TFRsqrt IR (#4317)
author박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 17 Jul 2019 04:58:55 +0000 (13:58 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 17 Jul 2019 04:58:55 +0000 (13:58 +0900)
This will introduce TFRsqrt IR and related codes

Signed-off-by: SaeHie Park <saehie.park@samsung.com>
contrib/moco-tf/src/Dialect/TFNodes.h
contrib/moco-tf/src/Dialect/TFNodes.lst
contrib/moco-tf/src/IR/TFRsqrt.h [new file with mode: 0644]
contrib/moco-tf/src/IR/TFRsqrt.test.cpp [new file with mode: 0644]
contrib/moco-tf/src/Transforms/FixPaddingTransform.cpp
contrib/moco-tf/src/Transforms/FixShapeTransform.cpp

index 799aeb4..a59c188 100644 (file)
@@ -23,5 +23,6 @@
 #include "IR/TFConv2D.h"
 #include "IR/TFFusedBatchNorm.h"
 #include "IR/TFMul.h"
+#include "IR/TFRsqrt.h"
 
 #endif // __MOCO_TF_DIALECT_TFNODES_H__
index fb908d7..6f5f4b6 100644 (file)
@@ -13,3 +13,4 @@ TENSORFLOW_NODE(Const, TFConst)
 TENSORFLOW_NODE(Conv2D, TFConv2D)
 TENSORFLOW_NODE(FusedBatchNorm, TFFusedBatchNorm)
 TENSORFLOW_NODE(Mul, TFMul)
+TENSORFLOW_NODE(Rsqrt, TFRsqrt)
diff --git a/contrib/moco-tf/src/IR/TFRsqrt.h b/contrib/moco-tf/src/IR/TFRsqrt.h
new file mode 100644 (file)
index 0000000..3fde404
--- /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 __MOCO_TF_IR_TFRSQRT_H__
+#define __MOCO_TF_IR_TFRSQRT_H__
+
+#include "Dialect/TFNodeDecl.h"
+
+namespace moco
+{
+namespace tf
+{
+
+class TFRsqrt final : public loco::FixedArityNode<1, TFNodeImpl<TFOpcode::Rsqrt>>
+{
+public:
+  TFRsqrt() = default;
+
+public:
+  Node *x(void) const { return at(0)->node(); }
+  void x(Node *node) { at(0)->node(node); }
+};
+
+} // namespace tf
+} // namespace moco
+
+#endif // __MOCO_TF_IR_TFRSQRT_H__
diff --git a/contrib/moco-tf/src/IR/TFRsqrt.test.cpp b/contrib/moco-tf/src/IR/TFRsqrt.test.cpp
new file mode 100644 (file)
index 0000000..7f92704
--- /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 "IR/TFRsqrt.h"
+
+#include "Dialect/TFDialect.h"
+
+#include <gtest/gtest.h>
+
+TEST(TFRsqrtTest, constructor)
+{
+  moco::tf::TFRsqrt rsqrt_node;
+
+  ASSERT_EQ(rsqrt_node.dialect(), moco::tf::TFDialect::get());
+  ASSERT_EQ(rsqrt_node.opcode(), moco::tf::TFOpcode::Rsqrt);
+
+  ASSERT_EQ(rsqrt_node.x(), nullptr);
+}
index a275db5..920a469 100644 (file)
@@ -451,6 +451,12 @@ bool fix_padding(moco::tf::TFMul *node)
   return false;
 }
 
+bool fix_padding(moco::tf::TFRsqrt *node)
+{
+  // Nothing to do with padding
+  return false;
+}
+
 } // namespace
 
 namespace moco
index d396e23..83c2968 100644 (file)
@@ -736,6 +736,13 @@ bool fix_shape(moco::tf::TFMul *node)
   return copy_shapedata(x, node);
 }
 
+bool fix_shape(moco::tf::TFRsqrt *node)
+{
+  // Output shape is same as the input x
+  auto x = node->x();
+  return copy_shapedata(x, node);
+}
+
 } // namespace
 
 namespace moco