[coco/generic] Return allocated span (#2630)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 12 Dec 2018 01:54:37 +0000 (10:54 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 12 Dec 2018 01:54:37 +0000 (10:54 +0900)
Now, allocate method in PlainWeightContext<T> returns the allocated span
as its return.

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

index be50c39..9f84092 100644 (file)
@@ -43,12 +43,11 @@ template <typename T> struct PlainWeightContext
    * @require the following code SHOULD work for any bag "b":
    *   PlainWeightContext<T> ctx;
    *
-   *   ctx.allocate(b);
-   *   auto span = ctx.weight(b);
+   *   auto span = ctx.allocate(b);
    *   assert(span.data() != nullptr);
    *   assert(span.size() == bag->size());
    */
-  virtual void allocate(const Bag *) = 0;
+  virtual Span<T> allocate(const Bag *) = 0;
   // WARN Depercated
   virtual void allocate(const KernelObject *) = 0;
 
index 19fd23a..557666d 100644 (file)
@@ -122,10 +122,11 @@ public:
   PlainWeightContextImpl(PlainWeightContextImpl &&) = delete;
 
 public:
-  void allocate(const coco::Bag *bag) override
+  coco::Span<T> allocate(const coco::Bag *bag) override
   {
     assert(bag != nullptr);
     _blob->allocate(bag, sizeof(T));
+    return weight(bag);
   }
 
   void allocate(const coco::KernelObject *obj) override
index cd3bea6..6cd54b0 100644 (file)
@@ -50,14 +50,16 @@ TEST(IR_DATA, allocate_and_link_bag)
   }
 
   // Allocate a weight space
-  d->f32()->allocate(bag);
-
-  // weight(...) SHOULD return a valid for a valid bag
   {
-    auto span = d->f32()->weight(bag);
+    auto allocated_span = d->f32()->allocate(bag);
 
-    ASSERT_NE(span.data(), nullptr);
-    ASSERT_EQ(span.size(), bag->size());
+    ASSERT_NE(allocated_span.data(), nullptr);
+    ASSERT_EQ(allocated_span.size(), bag->size());
+
+    auto retrieved_span = d->f32()->weight(bag);
+
+    ASSERT_EQ(allocated_span.data(), retrieved_span.data());
+    ASSERT_EQ(allocated_span.size(), retrieved_span.size());
   }
 }