[coco] Generate reader/accessor per request (#1573)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 19 Sep 2018 08:50:05 +0000 (17:50 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 19 Sep 2018 08:50:05 +0000 (17:50 +0900)
This commit revises PlainWeightContext to generate kernel
reader/accessor per request.

This allows PlainWeightContext to generate Object-specific reader and
accessor.

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

index 764111a..ca6ad99 100644 (file)
@@ -7,6 +7,8 @@
 #include <nncc/core/ADT/kernel/Accessor.h>
 #include <nncc/core/ADT/kernel/Reader.h>
 
+#include <memory>
+
 namespace coco
 {
 
@@ -20,8 +22,8 @@ template <typename T> struct PlainWeightContext
   // @brief Link pre-allocated blob space (denoted by BlobID) with coco::KernelObject
   virtual void link(const BlobID &, const KernelObject *) = 0;
 
-  virtual nncc::core::ADT::kernel::Accessor<T> *access(const KernelObject *) = 0;
-  virtual const nncc::core::ADT::kernel::Reader<T> *read(const KernelObject *) const = 0;
+  virtual std::unique_ptr<nncc::core::ADT::kernel::Accessor<T>> access(const KernelObject *) = 0;
+  virtual std::unique_ptr<nncc::core::ADT::kernel::Reader<T>> read(const KernelObject *) const = 0;
 };
 
 } // namespace coco
index d38d92e..c10946a 100644 (file)
@@ -51,16 +51,11 @@ public:
 public:
   void link(const coco::BlobID &id, const coco::KernelObject *o)
   {
-    using nncc::core::ADT::kernel::Overlay;
-    using nncc::core::ADT::kernel::NCHWLayout;
-
-    auto base = reinterpret_cast<T *>(_blob->at(id));
-
-    _link[o] = make_unique<Overlay<T, T *>>(o->shape(), NCHWLayout{}, base);
+    _link[o] = reinterpret_cast<T *>(_blob->at(id));
   }
 
 public:
-  kernel::Accessor<T> *access(const coco::KernelObject *o) override
+  std::unique_ptr<kernel::Accessor<T>> access(const coco::KernelObject *o) override
   {
     auto it = _link.find(o);
 
@@ -69,11 +64,16 @@ public:
       return nullptr;
     }
 
-    return it->second.get();
+    auto base = it->second;
+
+    using nncc::core::ADT::kernel::Overlay;
+    using nncc::core::ADT::kernel::NCHWLayout;
+
+    return make_unique<Overlay<T, T *>>(o->shape(), NCHWLayout{}, base);
   }
 
 public:
-  const kernel::Reader<T> *read(const coco::KernelObject *o) const override
+  std::unique_ptr<kernel::Reader<T>> read(const coco::KernelObject *o) const override
   {
     auto it = _link.find(o);
 
@@ -82,14 +82,19 @@ public:
       return nullptr;
     }
 
-    return it->second.get();
+    auto base = it->second;
+
+    using nncc::core::ADT::kernel::Overlay;
+    using nncc::core::ADT::kernel::NCHWLayout;
+
+    return make_unique<Overlay<T, T *>>(o->shape(), NCHWLayout{}, base);
   }
 
 private:
   BlobContext *const _blob;
 
 private:
-  std::map<const coco::KernelObject *, std::unique_ptr<kernel::Overlay<T, T *>>> _link;
+  std::map<const coco::KernelObject *, T *> _link;
 };
 } // namespace