From fa33a0029c0b1d2270663049a52b6e38978fcb81 Mon Sep 17 00:00:00 2001 From: sseung Date: Fri, 30 Aug 2024 17:30:52 +0900 Subject: [PATCH] [onert] Add lifetime enum to LayerScopeTensor 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