[Skeleton] Add Tflite interpreter skeleton
authorJihoon Lee <jhoon.it.lee@samsung.com>
Mon, 12 Apr 2021 11:15:30 +0000 (20:15 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Mon, 10 May 2021 08:14:40 +0000 (17:14 +0900)
This patch adds tflite interpreter skeleton

**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/meson.build
nntrainer/compiler/tflite_interpreter.cpp [new file with mode: 0644]
nntrainer/compiler/tflite_interpreter.h

index ff9366e..21d475a 100644 (file)
@@ -44,6 +44,9 @@ TENSORFLOW_ROOT := $(NDK_LIBS_OUT)/tensorflow-$(TENSORFLOW_VERSION)/tensorflow-l
 
 $(info $(shell ($(NNTRAINER_JNI_ROOT)/prepare_tflite.sh $(TENSORFLOW_VERSION) $(NDK_LIBS_OUT))))
 
+$(info $(shell (flatc -c $(NNTRAINER_ROOT)/nntrainer/compiler/tf_schema.fbs)))
+$(info $(shell (mv tf_scehma_generated.h $(NNTRAINER_ROOT)/nntrainer/compiler)))
+
 endif #MAKECMDGOALS
 endif #TENSORFLOW_ROOT
 
@@ -91,7 +94,6 @@ NNTRAINER_SRCS := $(NNTRAINER_ROOT)/nntrainer/models/neuralnet.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/dataset/databuffer_factory.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/dataset/databuffer_func.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/dataset/databuffer_file.cpp \
-                  $(NNTRAINER_ROOT)/nntrainer/compiler/ini_interpreter.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/tensor/tensor.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/tensor/lazy_tensor.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/tensor/manager.cpp \
@@ -130,6 +132,8 @@ NNTRAINER_SRCS := $(NNTRAINER_ROOT)/nntrainer/models/neuralnet.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/utils/parse_util.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/utils/profiler.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/utils/node_exporter.cpp \
+                  $(NNTRAINER_ROOT)/nntrainer/compiler/ini_interpreter.cpp \
+                  $(NNTRAINER_ROOT)/nntrainer/compiler/tflite_interpreter.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/app_context.cpp
 
 # Add tflite backbone building
index d14ca68..039205a 100644 (file)
@@ -14,6 +14,7 @@ if get_option('enable-tflite-interpreter')
                                command: [flatc, '-c', '@INPUT@'])
 
   nntrainer_sources += flat_header
+  compiler_sources += 'tflite_interpreter.cpp'
 endif
 
 foreach s : compiler_sources
diff --git a/nntrainer/compiler/tflite_interpreter.cpp b/nntrainer/compiler/tflite_interpreter.cpp
new file mode 100644 (file)
index 0000000..690eb33
--- /dev/null
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: Apache-2.0
+/**
+ * Copyright (C) 2021 Jihoon Lee <jhoon.it.lee@samsung.com>
+ *
+ * @file tflite_interpreter.cpp
+ * @date 12 April 2021
+ * @brief NNTrainer *.tflite Interpreter
+ * @see        https://github.com/nnstreamer/nntrainer
+ * @author Jihoon Lee <jhoon.it.lee@samsung.com>
+ * @bug No known bugs except for NYI items
+ */
+#include <tflite_interpreter.h>
+
+#include <tf_schema_generated.h>
+
+namespace nntrainer {
+
+void TfliteInterpreter::serialize(
+  std::shared_ptr<const GraphRepresentation> representation,
+  const std::string &out) {
+  /** NYI!! */
+}
+
+std::shared_ptr<GraphRepresentation>
+TfliteInterpreter::deserialize(const std::string &in) { /** NYI! */
+  return nullptr;
+}
+
+} // namespace nntrainer
index b5dcd12..9ab5fee 100644 (file)
@@ -9,5 +9,50 @@
  * @author Jihoon Lee <jhoon.it.lee@samsung.com>
  * @bug No known bugs except for NYI items
  */
+#ifndef __TFLITE_INTERPRETER_H__
+#define __TFLITE_INTERPRETER_H__
 
-#include <tf_schema_generated.h>
+#include <interpreter.h>
+
+#include <app_context.h>
+namespace nntrainer {
+
+/**
+ * @brief tflite graph interpreter class
+ *
+ */
+class TfliteInterpreter : public GraphInterpreter {
+public:
+  /**
+   * @brief Construct a new tflite Graph Interpreter object
+   *
+   * @param app_context_ app context to create layers
+   */
+  TfliteInterpreter(const AppContext &app_context_ = AppContext::Global()) :
+    app_context(app_context_) {}
+
+  /**
+   * @brief Destroy the Tflite Interpreter object
+   *
+   */
+  virtual ~TfliteInterpreter() = default;
+
+  /**
+   * @copydoc GraphInterpreter::serialize(const std::string &out)
+   */
+  void serialize(std::shared_ptr<const GraphRepresentation> representation,
+                 const std::string &out) override;
+
+  /**
+   * @copydoc GraphInterpreter::deserialize(const std::string &in)
+   */
+  std::shared_ptr<GraphRepresentation>
+  deserialize(const std::string &in) override;
+
+private:
+  AppContext app_context;
+};
+
+} // namespace nntrainer
+
+#endif // __TFLITE_INTERPRETER_H__