From ae411bed258ae8b5057d144e7b45c7686edd760d Mon Sep 17 00:00:00 2001 From: SeungHui Youn <61981457+zetwhite@users.noreply.github.com> Date: Mon, 2 Sep 2024 14:07:43 +0900 Subject: [PATCH] [onert] Add lifetime enum to LayerScopeTensor (#13861) This PR adds lifetime info to the LayerScopeTensor. Lifetime info will be used to plan and allocate buffer for LayerScopeTensor. ONE-DCO-1.0-Signed-off-by: seunghui youn --- .../include/backend/train/LayerScopeTensor.h | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/runtime/onert/core/include/backend/train/LayerScopeTensor.h b/runtime/onert/core/include/backend/train/LayerScopeTensor.h index febc332f224..f23ba39e7cb 100644 --- a/runtime/onert/core/include/backend/train/LayerScopeTensor.h +++ b/runtime/onert/core/include/backend/train/LayerScopeTensor.h @@ -26,6 +26,12 @@ namespace backend namespace train { +enum class LayerScopeTensorLifeTime : unsigned char +{ + BACKWARD, // alive during backward() + FORWARD_TO_BACKWARD, // alive from forward() to backward() +}; + // LayerScopeTensor is a tensor that is not shown in graph but required by each layer. // It is accessed within one operation layer. class LayerScopeTensor final : public basic::Tensor @@ -34,10 +40,22 @@ class LayerScopeTensor final : public basic::Tensor LayerScopeTensor() = delete; public: - LayerScopeTensor(const ir::OperandInfo &info) : basic::Tensor(info, nullptr) + LayerScopeTensor(const ir::OperandInfo &info, LayerScopeTensorLifeTime lt) + : basic::Tensor(info, nullptr), _lifetime(lt) { // DO NOTHING } + + LayerScopeTensor(const ir::OperandInfo &info) + : basic::Tensor(info, nullptr), _lifetime(LayerScopeTensorLifeTime::BACKWARD) + { + // DO NOTHING + } + + LayerScopeTensorLifeTime lifetime() const { return _lifetime; } + +private: + LayerScopeTensorLifeTime _lifetime; }; } // namespace train