From: 오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Mon, 20 Aug 2018 09:23:21 +0000 (+0900) Subject: [neurun] Move internal Object class into internal/operand (#2365) X-Git-Tag: 0.2~235 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8263a5e0941e81b5471221b9651e9bcd7f0d92d8;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Move internal Object class into internal/operand (#2365) Move internal Object class from internal/Model.h(cc) to internal/operand/Object.h(cc) Remove internal/Model.cc Signed-off-by: Hyeongseok Oh --- diff --git a/runtimes/neurun/src/internal/Model.h b/runtimes/neurun/src/internal/Model.h index 3419b26..3977cca 100644 --- a/runtimes/neurun/src/internal/Model.h +++ b/runtimes/neurun/src/internal/Model.h @@ -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 #include - -#include "util/feature/Shape.h" -#include "util/kernel/Shape.h" #include #include -#include - -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 = std::move(data); } - const Data &data(void) const { return *_data; } - -public: - template void data(Args &&... args) - { - data(std::unique_ptr(new T{std::forward(args)...})); - } - -public: - template 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(_data->base())); - } - -private: - const Shape _shape; - std::unique_ptr _data; - OperandUsage _usage; -}; - -} // namespace operand -} // namespace tflite -} // namespace internal +#include +#include "internal/operand/Object.h" #include "internal/op/NodeVisitor.h" namespace internal diff --git a/runtimes/neurun/src/internal/Model.cc b/runtimes/neurun/src/internal/operand/Object.cc similarity index 96% rename from runtimes/neurun/src/internal/Model.cc rename to runtimes/neurun/src/internal/operand/Object.cc index 786bbaa..460e91c 100644 --- a/runtimes/neurun/src/internal/Model.cc +++ b/runtimes/neurun/src/internal/operand/Object.cc @@ -1,6 +1,4 @@ -#include "internal/Model.h" - -#include +#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 index 0000000..3464527 --- /dev/null +++ b/runtimes/neurun/src/internal/operand/Object.h @@ -0,0 +1,78 @@ +#ifndef __NEURUN_INTERNAL_OPERAND_OBJECT_H__ +#define __NEURUN_INTERNAL_OPERAND_OBJECT_H__ + +#include +#include +#include +#include + +#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 = std::move(data); } + const Data &data(void) const { return *_data; } + +public: + template void data(Args &&... args) + { + data(std::unique_ptr(new T{std::forward(args)...})); + } + +public: + template 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(_data->base())); + } + +private: + const Shape _shape; + std::unique_ptr _data; + OperandUsage _usage; +}; + +} // namespace operand +} // namespace tflite +} // namespace internal + +#endif // __NEURUN_INTERNAL_OPERAND_OBJECT_H__