[moco] Introduce IR for Add AvgPool BiasAdd (#7890)
author박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 2 Oct 2019 03:38:00 +0000 (12:38 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 2 Oct 2019 03:38:00 +0000 (12:38 +0900)
This will introduce IR for Add, AvgPool and BiasAdd node

Signed-off-by: SaeHie Park <saehie.park@samsung.com>
compiler/moco/lang/include/moco/IR/Nodes/TFAdd.h [new file with mode: 0644]
compiler/moco/lang/include/moco/IR/Nodes/TFAvgPool.h [new file with mode: 0644]
compiler/moco/lang/include/moco/IR/Nodes/TFBiasAdd.h [new file with mode: 0644]
compiler/moco/lang/include/moco/IR/TFNodes.h
compiler/moco/lang/include/moco/IR/TFNodes.lst
compiler/moco/lang/src/IR/Nodes/TFAdd.test.cpp [new file with mode: 0644]
compiler/moco/lang/src/IR/Nodes/TFAvgPool.test.cpp [new file with mode: 0644]
compiler/moco/lang/src/IR/Nodes/TFBiasAdd.test.cpp [new file with mode: 0644]

diff --git a/compiler/moco/lang/include/moco/IR/Nodes/TFAdd.h b/compiler/moco/lang/include/moco/IR/Nodes/TFAdd.h
new file mode 100644 (file)
index 0000000..13b064f
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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_IR_TFADD_H__
+#define __MOCO_IR_TFADD_H__
+
+#include "moco/IR/TFNodeDecl.h"
+
+namespace moco
+{
+
+/// @note TFAdd corresponds to the following GraphDef
+/*
+node {
+  name: "add"
+  op: "Add"
+  input: "x"
+  input: "y"
+  attr {
+    key: "T"
+    value {
+      type: DT_FLOAT
+    }
+  }
+}
+*/
+
+class TFAdd final : public FixedArityNode<2, TFNodeImpl<TFOpcode::Add>>
+{
+public:
+  TFAdd() = default;
+
+public:
+  Node *x(void) const { return at(0)->node(); }
+  void x(Node *node) { at(0)->node(node); }
+
+  Node *y(void) const { return at(1)->node(); }
+  void y(Node *node) { at(1)->node(node); }
+};
+
+} // namespace moco
+
+#endif // __MOCO_IR_TFADD_H__
diff --git a/compiler/moco/lang/include/moco/IR/Nodes/TFAvgPool.h b/compiler/moco/lang/include/moco/IR/Nodes/TFAvgPool.h
new file mode 100644 (file)
index 0000000..65486a6
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * 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_IR_TFAVGPOOL_H__
+#define __MOCO_IR_TFAVGPOOL_H__
+
+#include "moco/IR/TFNodeDecl.h"
+
+#include <vector>
+
+namespace moco
+{
+
+/// @note TFAvgPool corresponds to the following GraphDef
+/*
+node {
+  name: "avgpool"
+  op: "AvgPool"
+  input: "placeholder"
+  attr {
+    key: "T"
+    value {
+      type: DT_FLOAT
+    }
+  }
+  attr {
+    key: "data_format"
+    value {
+      s: "NHWC"
+    }
+  }
+  attr {
+    key: "ksize"
+    value {
+      list {
+        i: 1 i: 3 i: 3 i: 1
+      }
+    }
+  }
+  attr {
+    key: "padding"
+    value {
+      s: "SAME"
+    }
+  }
+  attr {
+    key: "strides"
+    value {
+      list {
+        i: 1 i: 1 i: 1 i: 1
+      }
+    }
+  }
+}
+*/
+
+class TFAvgPool final : public FixedArityNode<1, TFNodeImpl<TFOpcode::AvgPool>>
+{
+public:
+  TFAvgPool() = default;
+
+public:
+  Node *input(void) const { return at(0)->node(); }
+  void input(Node *node) { return at(0)->node(node); }
+
+public:
+  const TFDataLayout &data_layout(void) const { return _data_layout; }
+  void data_layout(const TFDataLayout &data_layout) { _data_layout = data_layout; }
+
+  const TFPadding &padding(void) const { return _padding; }
+  void padding(const TFPadding &padding) { _padding = padding; }
+
+  const std::vector<int64_t> &ksize(void) const { return _ksize; }
+  void ksize(const std::vector<int64_t> &ksize) { _ksize = ksize; }
+
+  const std::vector<int64_t> &strides(void) const { return _strides; }
+  void strides(const std::vector<int64_t> &strides) { _strides = strides; }
+
+private:
+  TFDataLayout _data_layout;
+  TFPadding _padding;
+  std::vector<int64_t> _ksize;
+  std::vector<int64_t> _strides;
+};
+
+} // namespace moco
+
+#endif // __MOCO_IR_TFAVGPOOL_H__
diff --git a/compiler/moco/lang/include/moco/IR/Nodes/TFBiasAdd.h b/compiler/moco/lang/include/moco/IR/Nodes/TFBiasAdd.h
new file mode 100644 (file)
index 0000000..11e309c
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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_IR_TFBIASADD_H__
+#define __MOCO_IR_TFBIASADD_H__
+
+#include "moco/IR/TFNodeDecl.h"
+
+namespace moco
+{
+
+/// @note TFBiasAdd corresponds to the following GraphDef
+/*
+node {
+  name: "bias_add_01"
+  op: "BiasAdd"
+  input: "input_01"
+  input: "bias_add_01/bias"
+  attr {
+    key: "T"
+    value {
+      type: DT_FLOAT
+    }
+  }
+  attr {
+    key: "data_format"
+    value {
+      s: "NHWC"
+    }
+  }
+}
+*/
+
+class TFBiasAdd final : public FixedArityNode<2, TFNodeImpl<TFOpcode::BiasAdd>>
+{
+public:
+  TFBiasAdd() = default;
+
+public:
+  Node *value(void) const { return at(0)->node(); }
+  void value(Node *node) { return at(0)->node(node); }
+
+  Node *bias(void) const { return at(1)->node(); }
+  void bias(Node *node) { return at(1)->node(node); }
+
+  const TFDataLayout data_layout(void) const { return _data_layout; }
+  void data_layout(const TFDataLayout &data_layout) { _data_layout = data_layout; }
+
+private:
+  TFDataLayout _data_layout;
+};
+
+} // namespace moco
+
+#endif // __MOCO_IR_TFBIASADD_H__
index b666acd..cb1d3b1 100644 (file)
@@ -17,9 +17,9 @@
 #ifndef __MOCO_IR_TFNODES_H__
 #define __MOCO_IR_TFNODES_H__
 
-//#include "moco/IR/Nodes/TFAdd.h"
-//#include "moco/IR/Nodes/TFAvgPool.h"
-//#include "moco/IR/Nodes/TFBiasAdd.h"
+#include "moco/IR/Nodes/TFAdd.h"
+#include "moco/IR/Nodes/TFAvgPool.h"
+#include "moco/IR/Nodes/TFBiasAdd.h"
 //#include "moco/IR/Nodes/TFConcatV2.h"
 //#include "moco/IR/Nodes/TFConst.h"
 //#include "moco/IR/Nodes/TFConv2D.h"
index 0e30cd4..9132cd8 100644 (file)
@@ -7,9 +7,9 @@
 //
 
 // TENSORFLOW_NODE(OPCODE, CLASS)
-//TENSORFLOW_NODE(Add, TFAdd)
-//TENSORFLOW_NODE(AvgPool, TFAvgPool)
-//TENSORFLOW_NODE(BiasAdd, TFBiasAdd)
+TENSORFLOW_NODE(Add, TFAdd)
+TENSORFLOW_NODE(AvgPool, TFAvgPool)
+TENSORFLOW_NODE(BiasAdd, TFBiasAdd)
 //TENSORFLOW_NODE(ConcatV2, TFConcatV2)
 //TENSORFLOW_NODE(Const, TFConst)
 //TENSORFLOW_NODE(Conv2D, TFConv2D)
diff --git a/compiler/moco/lang/src/IR/Nodes/TFAdd.test.cpp b/compiler/moco/lang/src/IR/Nodes/TFAdd.test.cpp
new file mode 100644 (file)
index 0000000..d2cfb6a
--- /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 "moco/IR/Nodes/TFAdd.h"
+#include "moco/IR/TFDialect.h"
+
+#include <gtest/gtest.h>
+
+TEST(TFAddTest, constructor)
+{
+  moco::TFAdd add_node;
+
+  ASSERT_EQ(add_node.dialect(), moco::TFDialect::get());
+  ASSERT_EQ(add_node.opcode(), moco::TFOpcode::Add);
+
+  ASSERT_EQ(add_node.x(), nullptr);
+  ASSERT_EQ(add_node.y(), nullptr);
+}
diff --git a/compiler/moco/lang/src/IR/Nodes/TFAvgPool.test.cpp b/compiler/moco/lang/src/IR/Nodes/TFAvgPool.test.cpp
new file mode 100644 (file)
index 0000000..3059855
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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 "moco/IR/Nodes/TFAvgPool.h"
+#include "moco/IR/TFDialect.h"
+
+#include <gtest/gtest.h>
+
+TEST(TFAvgPoolTest, constructor)
+{
+  moco::TFAvgPool avgpool;
+
+  ASSERT_EQ(avgpool.dialect(), moco::TFDialect::get());
+  ASSERT_EQ(avgpool.opcode(), moco::TFOpcode::AvgPool);
+
+  ASSERT_EQ(avgpool.input(), nullptr);
+  ASSERT_EQ(avgpool.data_layout(), "");
+  ASSERT_EQ(avgpool.padding(), "");
+  ASSERT_EQ(avgpool.ksize(), std::vector<int64_t>({}));
+  ASSERT_EQ(avgpool.strides(), std::vector<int64_t>({}));
+}
diff --git a/compiler/moco/lang/src/IR/Nodes/TFBiasAdd.test.cpp b/compiler/moco/lang/src/IR/Nodes/TFBiasAdd.test.cpp
new file mode 100644 (file)
index 0000000..4a15a49
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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 "moco/IR/Nodes/TFBiasAdd.h"
+#include "moco/IR/TFDialect.h"
+
+#include <gtest/gtest.h>
+
+TEST(TFBiasAddTest, constructor)
+{
+  moco::TFBiasAdd bias_add;
+
+  ASSERT_EQ(bias_add.dialect(), moco::TFDialect::get());
+  ASSERT_EQ(bias_add.opcode(), moco::TFOpcode::BiasAdd);
+
+  ASSERT_EQ(bias_add.value(), nullptr);
+  ASSERT_EQ(bias_add.bias(), nullptr);
+  ASSERT_EQ(bias_add.data_layout(), "");
+}