[coco.generic] Introduce allocate for KernelObject (#1715)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 2 Oct 2018 04:35:12 +0000 (13:35 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 2 Oct 2018 04:35:12 +0000 (13:35 +0900)
This commit introduces allocate method in PlaingWeightContext as the
first step toward Bag-level data management.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/generic/include/coco/IR/Data.h
contrib/coco/generic/include/coco/IR/PlainWeightContext.h
contrib/coco/generic/src/IR/Data.cpp

index 38268a3..9a05ae6 100644 (file)
@@ -17,6 +17,8 @@ struct Data
   virtual ~Data() = default;
 
   // @brief Allocate blob space of 'size' bytes
+  //
+  // WARN Deprecated
   virtual coco::BlobID allocate(uint32_t size) = 0;
 
   virtual PlainWeightContext<float> *f32(void) = 0;
index ca6ad99..0354a26 100644 (file)
@@ -19,6 +19,8 @@ template <typename T> struct PlainWeightContext
 {
   virtual ~PlainWeightContext() = default;
 
+  virtual void allocate(const KernelObject *) = 0;
+
   // @brief Link pre-allocated blob space (denoted by BlobID) with coco::KernelObject
   virtual void link(const BlobID &, const KernelObject *) = 0;
 
index c10946a..c3b3671 100644 (file)
@@ -49,6 +49,17 @@ public:
   PlainWeightContextImpl(PlainWeightContextImpl &&) = delete;
 
 public:
+  void allocate(const coco::KernelObject *obj)
+  {
+    assert(obj != nullptr);
+    auto bag = obj->bag();
+    assert(bag != nullptr);
+
+    auto id = _blob->allocate(sizeof(T) * bag->size());
+    link(id, obj);
+  }
+
+public:
   void link(const coco::BlobID &id, const coco::KernelObject *o)
   {
     _link[o] = reinterpret_cast<T *>(_blob->at(id));