Fix a vector argument deallocate assert.
authorYang Rong <rong.r.yang@intel.com>
Fri, 11 Oct 2013 05:50:06 +0000 (13:50 +0800)
committerZhigang Gong <zhigang.gong@linux.intel.com>
Tue, 22 Oct 2013 06:10:55 +0000 (14:10 +0800)
Vector argument will allocate together but deallocate sepelate, when deallocate
will assert. Split the each allocatedBlock in register partitioner to fix it.

Signed-off-by: Yang Rong <rong.r.yang@intel.com>
backend/src/backend/context.cpp
backend/src/backend/context.hpp
backend/src/backend/gen_reg_allocation.cpp

index bc15761..25d4f9c 100644 (file)
@@ -60,6 +60,9 @@ namespace gbe
     /*! Free the given register file piece */
     void deallocate(int16_t offset);
 
+    /*! Spilt a block into 2 blocks */
+    void splitBlock(int16_t offset, int16_t subOffset);
+
   private:
     /*! May need to make that run-time in the future */
     static const int16_t RegisterFileSize = 4*KB;
@@ -268,6 +271,27 @@ namespace gbe
     }
   }
 
+  void RegisterFilePartitioner::splitBlock(int16_t offset, int16_t subOffset) {
+    // Retrieve the size in the allocation map
+    auto it = allocatedBlocks.find(offset);
+    GBE_ASSERT(it != allocatedBlocks.end());
+
+    while(subOffset > it->second) {
+      subOffset -= it->second;
+      offset += it->second;
+      it = allocatedBlocks.find(offset);
+      GBE_ASSERT(it != allocatedBlocks.end());
+    }
+
+    if(subOffset == 0)
+      return;
+    int16_t size = it->second;
+    allocatedBlocks.erase(it);
+    // Track the allocation to retrieve the size later
+    allocatedBlocks.insert(std::make_pair(offset, subOffset));
+    allocatedBlocks.insert(std::make_pair(offset + subOffset, size - subOffset));
+  }
+
   static int
   alignScratchSize(int size){
     int i = 0;
@@ -328,6 +352,10 @@ namespace gbe
 
   void Context::deallocate(int16_t offset) { partitioner->deallocate(offset); }
 
+  void Context::splitBlock(int16_t offset, int16_t subOffset) {
+    partitioner->splitBlock(offset, subOffset);
+  }
+
   int32_t Context::allocConstBuf(uint32_t argID) {
      GBE_ASSERT(kernel->args[argID].type == GBE_ARG_CONSTANT_PTR);
 
index ca2c88d..000612e 100644 (file)
@@ -86,6 +86,8 @@ namespace gbe
     int16_t allocate(int16_t size, int16_t alignment);
     /*! Deallocate previously allocated memory */
     void deallocate(int16_t offset);
+    /*! Spilt a block into 2 blocks, for some registers allocate together but  deallocate seperate */
+    void splitBlock(int16_t offset, int16_t subOffset);
     /* allocate curbe for constant ptr argument */
     int32_t allocConstBuf(uint32_t argID);
     /* allocate a new entry for a specific image's information */
index ab8b7ee..c4cad40 100644 (file)
@@ -149,15 +149,16 @@ namespace gbe
     const Function &fn = ctx.getFunction();
     GBE_ASSERT(fn.getProfile() == PROFILE_OCL);
     const Function::PushMap &pushMap = fn.getPushMap();
-    for (const auto &pushed : pushMap) {
-      const uint32_t argID = pushed.second.argID;
+    for (auto rit = pushMap.rbegin(); rit != pushMap.rend(); ++rit) {
+      const uint32_t argID = rit->second.argID;
       const FunctionArgument arg = fn.getArg(argID);
 
-      const uint32_t subOffset = pushed.second.offset;
-      const Register reg = pushed.second.getRegister();
+      const uint32_t subOffset = rit->second.offset;
+      const Register reg = rit->second.getRegister();
       auto it = this->ctx.curbeRegs.find(arg.reg);
       assert(it != ctx.curbeRegs.end());
       allocatePayloadReg(reg, it->second, subOffset);
+      ctx.splitBlock(it->second, subOffset);
     }
   }