From a015e2896f6e0f4681533d501c11b052433909cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=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: Thu, 11 Oct 2018 12:59:43 +0900 Subject: [PATCH] [coco.generic] Support weight data release (#1826) This commit introduces 'release' method which allows users to deallocated a memory chunk for weight data. Signed-off-by: Jonghyun Park --- contrib/coco/generic/include/coco/IR/Data.h | 7 +++++++ contrib/coco/generic/src/IR/Data.cpp | 8 ++++++++ contrib/coco/generic/src/IR/Data.test.cpp | 3 +++ 3 files changed, 18 insertions(+) diff --git a/contrib/coco/generic/include/coco/IR/Data.h b/contrib/coco/generic/include/coco/IR/Data.h index c4000b0..8c09d0e 100644 --- a/contrib/coco/generic/include/coco/IR/Data.h +++ b/contrib/coco/generic/include/coco/IR/Data.h @@ -20,6 +20,13 @@ struct Data */ virtual bool allocated(const coco::Bag *) const = 0; + /** + * @brief Release a memory chunk allocated for weight data of a given bag + * + * WARN Do NOT invoke release for a bag "b" for which allocated(b) does NOT hold + */ + virtual void release(const coco::Bag *) = 0; + virtual PlainWeightContext *f32(void) = 0; virtual const PlainWeightContext *f32(void) const = 0; diff --git a/contrib/coco/generic/src/IR/Data.cpp b/contrib/coco/generic/src/IR/Data.cpp index c5a5733..6db1906 100644 --- a/contrib/coco/generic/src/IR/Data.cpp +++ b/contrib/coco/generic/src/IR/Data.cpp @@ -22,6 +22,8 @@ public: _data[b] = std::move(buffer); } + void release(const coco::Bag *b) { _data.erase(b); } + public: uint8_t *at(const coco::Bag *b) { @@ -140,6 +142,12 @@ struct DataImpl final : public coco::Data bool allocated(const coco::Bag *b) const override { return _blob->at(b) != nullptr; } + void release(const coco::Bag *b) + { + assert(allocated(b)); + _blob->release(b); + } + coco::PlainWeightContext *f32(void) override { return _fp32.get(); } const coco::PlainWeightContext *f32(void) const override { return _fp32.get(); } }; diff --git a/contrib/coco/generic/src/IR/Data.test.cpp b/contrib/coco/generic/src/IR/Data.test.cpp index f5d038e..5fbae6a 100644 --- a/contrib/coco/generic/src/IR/Data.test.cpp +++ b/contrib/coco/generic/src/IR/Data.test.cpp @@ -72,4 +72,7 @@ TEST(IR_DATA, allocate_and_link_kernel) } } } + + data->release(bag); + ASSERT_FALSE(data->allocated(bag)); } -- 2.7.4