From: Vladimir Plazun/AI Tools Lab /SRR/Engineer/삼성전자 Date: Tue, 10 Jul 2018 07:29:28 +0000 (+0300) Subject: [nnc backend] Add Reshape operation implementation (#443) X-Git-Tag: nncc_backup~2463 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1824f5c8f76aa0704962280cf98c568f3ea45fff;p=platform%2Fcore%2Fml%2Fnnfw.git [nnc backend] Add Reshape operation implementation (#443) Add Reshape operation implementation Used by model IR interpreter Signed-off-by: Vladimir Plazun --- diff --git a/contrib/nnc/libs/backend/interpreter/core/include/interpreter/ops/Reshape.h b/contrib/nnc/libs/backend/interpreter/core/include/interpreter/ops/Reshape.h new file mode 100644 index 0000000..0962e01 --- /dev/null +++ b/contrib/nnc/libs/backend/interpreter/core/include/interpreter/ops/Reshape.h @@ -0,0 +1,58 @@ +#ifndef _NNC_CORE_BACKEND_INTERPRETER_RESHAPE_IMPL_ +#define _NNC_CORE_BACKEND_INTERPRETER_RESHAPE_IMPL_ + +#include "nnc/core/IR/model/operations/reshape_op.h" + +#include "interpreter/ops/OperationImpl.h" +#include "interpreter/ops/Fill.h" + +namespace nncc +{ +namespace contrib +{ +namespace backend +{ +namespace interpreter +{ +namespace impl +{ + +using nncc::contrib::core::IR::model::ops::ReshapeOp; + +template class Reshape : public OperationImpl +{ +public: + Reshape(const TensorVariant &input, const ReshapeOp &op) : _input(input), _op(op) + { + assert(num_elements(_op.getInputShape(0)) == num_elements(_op.getOutputShape(0))); + } + + std::vector operator()() override + { + const Shape &outShape = _op.getOutputShape(0); + const Shape &inShape = _op.getInputShape(0); + + ShapeRange inRange(inShape); + ShapeRange outRange(outShape); + + auto inIter = inRange.begin(); + + auto out = OperationImpl::allocate_tensor(outShape); + + Tensor outAccessor(out); + // Shapes element count compared in Reshape ctor + return Fill(outShape, [this, &inIter](const Index &) -> float { return _input.at(*inIter++); })(); + } + +private: + Tensor _input; + const ReshapeOp &_op; +}; + +} // namespace impl +} // namespace interpreter +} // namespace backend +} // namespace contrib +} // namespace nncc + +#endif //_NNC_CORE_BACKEND_INTERPRETER_RESHAPE_IMPL_ diff --git a/contrib/nnc/libs/backend/interpreter/core/src/ops/Reshape.cpp b/contrib/nnc/libs/backend/interpreter/core/src/ops/Reshape.cpp new file mode 100644 index 0000000..6e3ab17 --- /dev/null +++ b/contrib/nnc/libs/backend/interpreter/core/src/ops/Reshape.cpp @@ -0,0 +1 @@ +#include "interpreter/ops/Reshape.h"