[neurun] Move internal Object class into internal/operand (#2365)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 20 Aug 2018 09:23:21 +0000 (18:23 +0900)
committer이춘석/동작제어Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>
Mon, 20 Aug 2018 09:23:21 +0000 (18:23 +0900)
Move internal Object class from internal/Model.h(cc) to internal/operand/Object.h(cc)
Remove internal/Model.cc

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
runtimes/neurun/src/internal/Model.h
runtimes/neurun/src/internal/operand/Object.cc [moved from runtimes/neurun/src/internal/Model.cc with 96% similarity]
runtimes/neurun/src/internal/operand/Object.h [new file with mode: 0644]

index 3419b26..3977cca 100644 (file)
@@ -1,85 +1,12 @@
 #ifndef __INTERNAL_MODEL_H__
 #define __INTERNAL_MODEL_H__
 
-#include "graph/operand/Index.h"
-#include "internal/operand/Data.h"
-#include "internal/operand/Shape.h"
-
-#include <vector>
 #include <cstdint>
-
-#include "util/feature/Shape.h"
-#include "util/kernel/Shape.h"
 #include <algorithm>
 #include <memory>
-#include <cassert>
-
-namespace internal
-{
-namespace tflite
-{
-namespace operand
-{
-
-// Operand usage should be exact one of these
-enum class OperandUsage
-{
-  NOT_DEFINED,
-  MODEL_INPUT,
-  CONSTANT,
-  OPERATION_OUTPUT,
-};
-
-class Object
-{
-public:
-  explicit Object(const Shape &shape) : _shape{shape}, _usage{OperandUsage::NOT_DEFINED}
-  {
-    // DO NOTHING
-  }
-
-public:
-  const Shape &shape(void) const { return _shape; }
-  size_t operandSize(void) const;
-  bool setAsConstant() { return setUsage(OperandUsage::CONSTANT); }
-  bool setAsModelInput() { return setUsage(OperandUsage::MODEL_INPUT); }
-  bool setAsOperationOutput() { return setUsage(OperandUsage::OPERATION_OUTPUT); }
-  bool usageIsDefined(void) const { return _usage != OperandUsage::NOT_DEFINED; }
-  bool isModelInput(void) const { return _usage == OperandUsage::MODEL_INPUT; }
-
-private:
-  bool setUsage(OperandUsage usage);
-
-public:
-  void data(std::unique_ptr<Data> &&data) { _data = std::move(data); }
-  const Data &data(void) const { return *_data; }
-
-public:
-  template <typename T, typename... Args> void data(Args &&... args)
-  {
-    data(std::unique_ptr<T>(new T{std::forward<Args>(args)...}));
-  }
-
-public:
-  template <typename T> T asScalar(void) const
-  {
-    assert((_shape.rank() == 0) || ((_shape.rank() == 1) && (_shape.dim(0) == 1)));
-    assert(_data != nullptr);
-    assert((_data->base() != nullptr) && (_data->size() == sizeof(T)));
-
-    return *(reinterpret_cast<const T *>(_data->base()));
-  }
-
-private:
-  const Shape _shape;
-  std::unique_ptr<Data> _data;
-  OperandUsage _usage;
-};
-
-} // namespace operand
-} // namespace tflite
-} // namespace internal
+#include <vector>
 
+#include "internal/operand/Object.h"
 #include "internal/op/NodeVisitor.h"
 
 namespace internal
similarity index 96%
rename from runtimes/neurun/src/internal/Model.cc
rename to runtimes/neurun/src/internal/operand/Object.cc
index 786bbaa..460e91c 100644 (file)
@@ -1,6 +1,4 @@
-#include "internal/Model.h"
-
-#include <cassert>
+#include "Object.h"
 
 namespace internal
 {
diff --git a/runtimes/neurun/src/internal/operand/Object.h b/runtimes/neurun/src/internal/operand/Object.h
new file mode 100644 (file)
index 0000000..3464527
--- /dev/null
@@ -0,0 +1,78 @@
+#ifndef __NEURUN_INTERNAL_OPERAND_OBJECT_H__
+#define __NEURUN_INTERNAL_OPERAND_OBJECT_H__
+
+#include <cassert>
+#include <cstdint>
+#include <memory>
+#include <algorithm>
+
+#include "Shape.h"
+#include "Data.h"
+
+namespace internal
+{
+namespace tflite
+{
+namespace operand
+{
+
+// Operand usage should be exact one of these
+enum class OperandUsage
+{
+  NOT_DEFINED,
+  MODEL_INPUT,
+  CONSTANT,
+  OPERATION_OUTPUT,
+};
+
+class Object
+{
+public:
+  explicit Object(const Shape &shape) : _shape{shape}, _usage{OperandUsage::NOT_DEFINED}
+  {
+    // DO NOTHING
+  }
+
+public:
+  const Shape &shape(void) const { return _shape; }
+  size_t operandSize(void) const;
+  bool setAsConstant() { return setUsage(OperandUsage::CONSTANT); }
+  bool setAsModelInput() { return setUsage(OperandUsage::MODEL_INPUT); }
+  bool setAsOperationOutput() { return setUsage(OperandUsage::OPERATION_OUTPUT); }
+  bool usageIsDefined(void) const { return _usage != OperandUsage::NOT_DEFINED; }
+  bool isModelInput(void) const { return _usage == OperandUsage::MODEL_INPUT; }
+
+private:
+  bool setUsage(OperandUsage usage);
+
+public:
+  void data(std::unique_ptr<Data> &&data) { _data = std::move(data); }
+  const Data &data(void) const { return *_data; }
+
+public:
+  template <typename T, typename... Args> void data(Args &&... args)
+  {
+    data(std::unique_ptr<T>(new T{std::forward<Args>(args)...}));
+  }
+
+public:
+  template <typename T> T asScalar(void) const
+  {
+    assert((_shape.rank() == 0) || ((_shape.rank() == 1) && (_shape.dim(0) == 1)));
+    assert(_data != nullptr);
+    assert((_data->base() != nullptr) && (_data->size() == sizeof(T)));
+
+    return *(reinterpret_cast<const T *>(_data->base()));
+  }
+
+private:
+  const Shape _shape;
+  std::unique_ptr<Data> _data;
+  OperandUsage _usage;
+};
+
+} // namespace operand
+} // namespace tflite
+} // namespace internal
+
+#endif // __NEURUN_INTERNAL_OPERAND_OBJECT_H__