[Graph/recurrent] Add concept of realizer
authorJihoon Lee <jhoon.it.lee@samsung.com>
Sat, 9 Oct 2021 08:26:47 +0000 (17:26 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Wed, 13 Oct 2021 12:15:56 +0000 (21:15 +0900)
This patch add graph realizer. Graph realizer will preprocess graph
which can be effectively done as a lowering process of compile

**Self evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Jihoon Lee <jhoon.it.lee@samsung.com>
jni/Android.mk
nntrainer/compiler/flatten_realizer.cpp [new file with mode: 0644]
nntrainer/compiler/flatten_realizer.h [new file with mode: 0644]
nntrainer/compiler/interpreter.h
nntrainer/compiler/meson.build
nntrainer/compiler/realizer.h [new file with mode: 0644]

index 8ffb1e7..bfbe3d4 100644 (file)
@@ -190,6 +190,7 @@ NNTRAINER_SRCS := $(NNTRAINER_ROOT)/nntrainer/models/neuralnet.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/utils/node_exporter.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/utils/base_properties.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/compiler/ini_interpreter.cpp \
+                  $(NNTRAINER_ROOT)/nntrainer/compiler/flatten_realizer.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/app_context.cpp
 
 ifeq ($(ENABLE_TFLITE_INTERPRETER), 1)
diff --git a/nntrainer/compiler/flatten_realizer.cpp b/nntrainer/compiler/flatten_realizer.cpp
new file mode 100644 (file)
index 0000000..693ebac
--- /dev/null
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: Apache-2.0
+/**
+ * Copyright (C) 2021 Jihoon Lee <jhoon.it.lee@samsung.com>
+ *
+ * @file flatten_realizer.h
+ * @date 09 October 2021
+ * @brief NNTrainer graph realizer which realizes flatten=true to actual node
+ * @see        https://github.com/nnstreamer/nntrainer
+ * @author Jihoon Lee <jhoon.it.lee@samsung.com>
+ * @bug No known bugs except for NYI items
+ */
+#include <flatten_realizer.h>
+
+#include <layer_node.h>
+
+namespace nntrainer {
+
+FlattenRealizer::~FlattenRealizer() {}
+
+GraphRepresentation
+FlattenRealizer::realize(const GraphRepresentation &reference) {
+  /// NYI
+  return reference;
+}
+} // namespace nntrainer
diff --git a/nntrainer/compiler/flatten_realizer.h b/nntrainer/compiler/flatten_realizer.h
new file mode 100644 (file)
index 0000000..48fa0b5
--- /dev/null
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: Apache-2.0
+/**
+ * Copyright (C) 2021 Jihoon Lee <jhoon.it.lee@samsung.com>
+ *
+ * @file flatten_realizer.h
+ * @date 09 October 2021
+ * @brief NNTrainer graph realizer which realizes flatten=true to actual node
+ * @see        https://github.com/nnstreamer/nntrainer
+ * @author Jihoon Lee <jhoon.it.lee@samsung.com>
+ * @bug No known bugs except for NYI items
+ */
+#ifndef __FLATTEN_REALIZER_H__
+#define __FLATTEN_REALIZER_H__
+
+#include <memory>
+#include <vector>
+
+#include <realizer.h>
+
+namespace nntrainer {
+
+/**
+ * @brief Graph realizer class
+ *
+ */
+class FlattenRealizer final : public GraphRealizer {
+public:
+  /**
+   * @brief Destroy the Graph Realizer object
+   *
+   */
+  ~FlattenRealizer();
+
+  /**
+   * @brief graph realizer creates a new graph based on the reference
+   *
+   */
+  GraphRepresentation realize(const GraphRepresentation &reference) override;
+};
+
+} // namespace nntrainer
+
+#endif // __FLATTEN_REALIZER_H__
index 524d607..9570346 100644 (file)
 
 #include <memory>
 #include <string>
-
-#include <layer_node.h>
+#include <vector>
 
 namespace nntrainer {
 
 class NetworkGraph;
+class LayerNode;
 using GraphRepresentation = std::vector<std::shared_ptr<LayerNode>>;
 
 /**
index 36aa966..0794dfc 100644 (file)
@@ -1,5 +1,6 @@
 compiler_sources = [
-  'ini_interpreter.cpp'
+  'ini_interpreter.cpp',
+  'flatten_realizer.cpp'
 ]
 
 compiler_headers = []
diff --git a/nntrainer/compiler/realizer.h b/nntrainer/compiler/realizer.h
new file mode 100644 (file)
index 0000000..3fe41d6
--- /dev/null
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: Apache-2.0
+/**
+ * Copyright (C) 2021 Jihoon Lee <jhoon.it.lee@samsung.com>
+ *
+ * @file realizer.h
+ * @date 09 October 2021
+ * @brief NNTrainer graph realizer which preprocess graph representation as a
+ * lowering process of compile
+ * @see        https://github.com/nnstreamer/nntrainer
+ * @author Jihoon Lee <jhoon.it.lee@samsung.com>
+ * @bug No known bugs except for NYI items
+ */
+#ifndef __REALIZER_H__
+#define __REALIZER_H__
+
+#include <memory>
+#include <vector>
+
+namespace nntrainer {
+
+class LayerNode;
+using GraphRepresentation = std::vector<std::shared_ptr<LayerNode>>;
+
+/**
+ * @brief Graph realizer class
+ *
+ */
+class GraphRealizer {
+public:
+  /**
+   * @brief Destroy the Graph Realizer object
+   *
+   */
+  virtual ~GraphRealizer() {}
+
+  /**
+   * @brief graph realizer creates a new graph based on the reference
+   *
+   */
+  virtual GraphRepresentation realize(const GraphRepresentation &reference) = 0;
+};
+
+} // namespace nntrainer
+
+#endif // __REALIZER_H__