From cc3db967869d17a39612ad4fb99fe45e0b038c6c Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=98=A4=ED=98=95=EC=84=9D/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Tue, 30 Oct 2018 16:58:47 +0900 Subject: [PATCH] Introduce ParentInfo class (#3401) Introduce ParentInfo class to represent parent tensor information Add field in neurun::graph::operand::Object for ParentInfo Signed-off-by: Hyeongseok Oh --- runtimes/neurun/src/graph/operand/Object.cc | 9 ++ runtimes/neurun/src/graph/operand/Object.h | 17 ++++ runtimes/neurun/src/graph/operand/ParentInfo.h | 133 +++++++++++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 runtimes/neurun/src/graph/operand/ParentInfo.h diff --git a/runtimes/neurun/src/graph/operand/Object.cc b/runtimes/neurun/src/graph/operand/Object.cc index 06da807..6b0926b 100644 --- a/runtimes/neurun/src/graph/operand/Object.cc +++ b/runtimes/neurun/src/graph/operand/Object.cc @@ -114,6 +114,15 @@ const LowerInfo *Object::lower_info() const { return _lower_info.get(); } LowerInfo *Object::lower_info() { return _lower_info.get(); } +void Object::parent_info(std::unique_ptr &&parent_info) +{ + _parent_info = std::move(parent_info); +} + +const ParentInfo *Object::parent_info() const { return _parent_info.get(); } + +ParentInfo *Object::parent_info() { return _parent_info.get(); } + } // namespace operand } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operand/Object.h b/runtimes/neurun/src/graph/operand/Object.h index c8fb13a..cde1acc 100644 --- a/runtimes/neurun/src/graph/operand/Object.h +++ b/runtimes/neurun/src/graph/operand/Object.h @@ -26,6 +26,7 @@ #include "Data.h" #include "TypeInfo.h" #include "LowerInfo.h" +#include "ParentInfo.h" #include "graph/operation/IndexList.h" namespace neurun @@ -98,6 +99,21 @@ public: void lower_info(std::unique_ptr &&lower_info); const LowerInfo *lower_info() const; LowerInfo *lower_info(); + /** + * @brief Set parent information + * @param[in] parent_info Parent information + */ + void parent_info(std::unique_ptr &&parent_info); + /** + * @brief Return parent information pointer as constant + * @return Parent information pointer + */ + const ParentInfo *parent_info() const; + /** + * @brief Return parent information pointer + * @return Perent information pointer + */ + ParentInfo *parent_info(); private: const Shape _shape; @@ -109,6 +125,7 @@ private: operation::IndexList _def; // size is 0 (constant) or 1 (from def operation) std::unique_ptr _lower_info; + std::unique_ptr _parent_info; }; } // namespace operand diff --git a/runtimes/neurun/src/graph/operand/ParentInfo.h b/runtimes/neurun/src/graph/operand/ParentInfo.h new file mode 100644 index 0000000..74bfe11 --- /dev/null +++ b/runtimes/neurun/src/graph/operand/ParentInfo.h @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file ParentInfo.h + * @brief This file contains ParentInfo class and internal Coordinate4D class + * to represent subsumption between operand + */ + +#ifndef __NEURUN_GRAPH_OPERAND_PARENT_INFO_H__ +#define __NEURUN_GRAPH_OPERAND_PARENT_INFO_H__ + +#include + +#include "Index.h" + +namespace neurun +{ +namespace graph +{ +namespace operand +{ + +/** + * @brief Class to represent parent operand in child operand + */ +class ParentInfo +{ +public: + /** + * @brief Class to represent position(offset) of subtensor.\n + * Assume that parent and child are already lowered (can get Shape4D). + */ + class Coordinate4D + { + public: + /** + * @brief Construct a new Coordinate4D object + */ + Coordinate4D(void) : _n{0}, _h{0}, _w{0}, _c{0} + { + // DO NOTHING + } + /** + * @brief Construct a new Coordinate4D object + * @param[in] n Batch offset + * @param[in] h Height offset + * @param[in] w Width offset + * @param[in] c Channel offset + * @return + */ + Coordinate4D(int32_t n, int32_t h, int32_t w, int32_t c) : _n{n}, _h{h}, _w{w}, _c{c} + { + // DO NOTHING + } + + public: + /** + * @brief Return batch offset + * @return Batch offset + */ + int32_t n(void) const { return _n; } + /** + * @brief Return height offset + * @return Height offset + */ + int32_t h(void) const { return _h; } + /** + * @brief Return width offset + * @return Width offset + */ + int32_t w(void) const { return _w; } + /** + * @brief Return channel offset + * @return Channel offset + */ + int32_t c(void) const { return _c; } + + private: + int32_t _n; + int32_t _h; + int32_t _w; + int32_t _c; + }; + +public: + /** + * @brief Construct a new ParentInfo object + * @param[in] parent Index of parent operand + * @param[in] coordinate Offset of child operand in parent operand + * @return + */ + ParentInfo(const Index parent, const Coordinate4D &coordinate) + : _parent{parent}, _coordinate{coordinate} + { + // DO NOTHING + } + +public: + /** + * @brief Return parent index + * @return Parent index + */ + Index parent(void) const { return _parent; } + /** + * @brief Retern offset in parent + * @return Offset + */ + Coordinate4D offset(void) const { return _coordinate; } + +private: + Index _parent; + Coordinate4D _coordinate; +}; + +} // namespace operand +} // namespace graph +} // namespace neurun + +#endif // __NEURUN_GRAPH_OPERAND_PARENT_INFO_H__ -- 2.7.4