[Beignet] [PATCH 14/19] OCL20: handle device enqueue helper functions in the backend.

Yang Rong rong.r.yang at intel.com
Mon Nov 28 11:32:40 UTC 2016


Add useDeviceEnqueue to kernel to indicate the kernel use device
enqueue or not.

V2: Remove and correct debug info.
Signed-off-by: Yang Rong <rong.r.yang at intel.com>
Reviewed-by: Pan Xiuli <xiuli.pan at intel.com>
Reviewed-by: Ruiling Song <ruiling.song at intel.com>
---
 backend/src/backend/context.cpp            |  1 +
 backend/src/backend/program.cpp            |  4 ++-
 backend/src/backend/program.hpp            | 15 +++++++++++
 backend/src/ir/function.cpp                |  2 +-
 backend/src/ir/function.hpp                |  7 +++++
 backend/src/llvm/llvm_gen_backend.cpp      | 43 +++++++++++++++++++++++++++---
 backend/src/llvm/llvm_gen_ocl_function.hxx |  5 ++++
 7 files changed, 71 insertions(+), 6 deletions(-)

diff --git a/backend/src/backend/context.cpp b/backend/src/backend/context.cpp
index 8174954..e9ddd17 100644
--- a/backend/src/backend/context.cpp
+++ b/backend/src/backend/context.cpp
@@ -393,6 +393,7 @@ namespace gbe
     if(this->kernel != NULL) {
       this->kernel->scratchSize = this->alignScratchSize(scratchAllocator->getMaxScatchMemUsed());
       this->kernel->ctx = this;
+      this->kernel->setUseDeviceEnqueue(fn.getUseDeviceEnqueue());
     }
     return this->kernel;
   }
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index e0107dc..dcbaaf4 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -89,7 +89,8 @@ namespace gbe {
   Kernel::Kernel(const std::string &name) :
     name(name), args(NULL), argNum(0), curbeSize(0), stackSize(0), useSLM(false),
         slmSize(0), ctx(NULL), samplerSet(NULL), imageSet(NULL), printfSet(NULL),
-        profilingInfo(NULL) {}
+        profilingInfo(NULL), useDeviceEnqueue(false) {}
+
   Kernel::~Kernel(void) {
     if(ctx) GBE_DELETE(ctx);
     if(samplerSet) GBE_DELETE(samplerSet);
@@ -181,6 +182,7 @@ namespace gbe {
   bool Program::buildFromUnit(const ir::Unit &unit, std::string &error) {
     constantSet = new ir::ConstantSet(unit.getConstantSet());
     relocTable = new ir::RelocTable(unit.getRelocTable());
+    blockFuncs = unit.blockFuncs;
     const auto &set = unit.getFunctionSet();
     const uint32_t kernelNum = set.size();
     if (OCL_OUTPUT_GEN_IR) std::cout << unit;
diff --git a/backend/src/backend/program.hpp b/backend/src/backend/program.hpp
index 35ebad5..1aff8b9 100644
--- a/backend/src/backend/program.hpp
+++ b/backend/src/backend/program.hpp
@@ -232,6 +232,12 @@ namespace gbe {
     virtual uint32_t serializeToBin(std::ostream& outs);
     virtual uint32_t deserializeFromBin(std::istream& ins);
     virtual void printStatus(int indent, std::ostream& outs);
+    /*! Does kernel use device enqueue */
+    INLINE bool getUseDeviceEnqueue(void) const { return this->useDeviceEnqueue; }
+    /*! Change the device enqueue info of the function */
+    INLINE bool setUseDeviceEnqueue(bool useDeviceEnqueue) {
+      return this->useDeviceEnqueue = useDeviceEnqueue;
+    }
 
   protected:
     friend class Context;      //!< Owns the kernels
@@ -254,6 +260,7 @@ namespace gbe {
     ir::ProfilingInfo *profilingInfo;  //!< Copy from the corresponding function.
     uint32_t compileWgSize[3]; //!< required work group size by kernel attribute.
     std::string functionAttributes; //!< function attribute qualifiers combined.
+    bool useDeviceEnqueue;          //!< Has device enqueue?
     GBE_CLASS(Kernel);         //!< Use custom allocators
   };
 
@@ -290,6 +297,12 @@ namespace gbe {
       }
       return kernel;
     }
+
+    const char *getDeviceEnqueueKernelName(uint32_t index) const {
+      if(index >= blockFuncs.size())
+        return NULL;
+      return blockFuncs[index].c_str();
+    }
     /*! Build a program from a ir::Unit */
     bool buildFromUnit(const ir::Unit &unit, std::string &error);
     /*! Buils a program from a LLVM source code */
@@ -336,6 +349,8 @@ namespace gbe {
     ir::ConstantSet *constantSet;
     /*! relocation table */
     ir::RelocTable *relocTable;
+    /*! device enqueue functions */
+    vector<std::string> blockFuncs;
     /*! Use custom allocators */
     GBE_CLASS(Program);
   };
diff --git a/backend/src/ir/function.cpp b/backend/src/ir/function.cpp
index 29be0a4..4c19a42 100644
--- a/backend/src/ir/function.cpp
+++ b/backend/src/ir/function.cpp
@@ -44,7 +44,7 @@ namespace ir {
 
   Function::Function(const std::string &name, const Unit &unit, Profile profile) :
     name(name), unit(unit), profile(profile), simdWidth(0), useSLM(false), slmSize(0), stackSize(0),
-    wgBroadcastSLM(-1), tidMapSLM(-1)
+    wgBroadcastSLM(-1), tidMapSLM(-1), useDeviceEnqueue(false)
   {
     initProfile(*this);
     samplerSet = GBE_NEW(SamplerSet);
diff --git a/backend/src/ir/function.hpp b/backend/src/ir/function.hpp
index 8582508..5fcb14a 100644
--- a/backend/src/ir/function.hpp
+++ b/backend/src/ir/function.hpp
@@ -557,6 +557,12 @@ namespace ir {
     /*! Output the control flow graph to .dot file */
     void outputCFG();
     uint32_t getOclVersion(void) const;
+    /*! Does it use device enqueue */
+    INLINE bool getUseDeviceEnqueue(void) const { return this->useDeviceEnqueue; }
+    /*! Change the device enqueue infor of the function */
+    INLINE bool setUseDeviceEnqueue(bool useDeviceEnqueue) {
+      return this->useDeviceEnqueue = useDeviceEnqueue;
+    }
   private:
     friend class Context;           //!< Can freely modify a function
     std::string name;               //!< Function name
@@ -584,6 +590,7 @@ namespace ir {
     std::string functionAttributes; //!< function attribute qualifiers combined.
     int32_t wgBroadcastSLM;         //!< Used for broadcast the workgroup value.
     int32_t tidMapSLM;              //!< Used to store the map between groupid and hw thread.
+    bool useDeviceEnqueue;          //!< Has device enqueue?
     GBE_CLASS(Function);            //!< Use custom allocator
   };
 
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index e7a8b7f..08a7695 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -1635,10 +1635,15 @@ namespace gbe
           offset += sizeof(short);
           break;
         }
-      default: {
-        c->dump();
-        NOT_IMPLEMENTED;
-               }
+      case Type::TypeID::PointerTyID:
+        {
+          break;
+        }
+      default:
+        {
+          c->dump();
+          NOT_IMPLEMENTED;
+        }
     }
   }
   static bool isProgramGlobal(const GlobalVariable &v) {
@@ -2977,6 +2982,8 @@ namespace gbe
             ctx.ADD(getType(ctx, v.getType()), reg, ir::ocl::constant_addrspace, reg);
           }
         }
+      } else if(addrSpace == ir::MEM_PRIVATE) {
+          this->newRegister(const_cast<GlobalVariable*>(&v));
       }
     }
   }
@@ -4019,6 +4026,8 @@ namespace gbe
       case GEN_OCL_SUB_GROUP_BLOCK_READ_US_IMAGE2:
       case GEN_OCL_SUB_GROUP_BLOCK_READ_US_IMAGE4:
       case GEN_OCL_SUB_GROUP_BLOCK_READ_US_IMAGE8:
+      case GEN_OCL_ENQUEUE_SET_NDRANGE_INFO:
+      case GEN_OCL_ENQUEUE_GET_NDRANGE_INFO:
         this->newRegister(&I);
         break;
       case GEN_OCL_GET_PIPE:
@@ -4039,6 +4048,9 @@ namespace gbe
         regTranslator.newValueProxy(srcValue, dst);
         break;
       }
+      case GEN_OCL_ENQUEUE_GET_ENQUEUE_INFO_ADDR:
+        regTranslator.newScalarProxy(ir::ocl::enqueuebufptr, dst);
+        break;
       case GEN_OCL_PRINTF:
         this->newRegister(&I);  // fall through
       case GEN_OCL_PUTS:
@@ -5441,6 +5453,29 @@ namespace gbe
           {
             break;
           }
+          case GEN_OCL_ENQUEUE_SET_NDRANGE_INFO:
+          {
+            GBE_ASSERT(AI != AE);
+            Value *srcValue = *AI;
+            ++AI;
+            Value *dstValue = &I;
+            regTranslator.newValueProxy(srcValue, dstValue);
+            break;
+          }
+          case GEN_OCL_ENQUEUE_GET_NDRANGE_INFO:
+          {
+            GBE_ASSERT(AI != AE);
+            Value *srcValue = *AI;
+            ++AI;
+            Value *dstValue = &I;
+            regTranslator.newValueProxy(srcValue, dstValue);
+            break;
+          }
+          case GEN_OCL_ENQUEUE_GET_ENQUEUE_INFO_ADDR:
+          {
+            ctx.getFunction().setUseDeviceEnqueue(true);
+            break;
+          }
           default: break;
         }
       }
diff --git a/backend/src/llvm/llvm_gen_ocl_function.hxx b/backend/src/llvm/llvm_gen_ocl_function.hxx
index 08fd1e2..86485da 100644
--- a/backend/src/llvm/llvm_gen_ocl_function.hxx
+++ b/backend/src/llvm/llvm_gen_ocl_function.hxx
@@ -261,3 +261,8 @@ DECL_LLVM_GEN_FUNCTION(LRP, __gen_ocl_lrp)
 DECL_LLVM_GEN_FUNCTION(GET_PIPE, __gen_ocl_get_pipe)
 DECL_LLVM_GEN_FUNCTION(GET_RID, __gen_ocl_get_rid)
 DECL_LLVM_GEN_FUNCTION(MAKE_RID, __gen_ocl_make_rid)
+
+//Enqueue function
+DECL_LLVM_GEN_FUNCTION(ENQUEUE_SET_NDRANGE_INFO, __gen_ocl_set_ndrange_info)
+DECL_LLVM_GEN_FUNCTION(ENQUEUE_GET_NDRANGE_INFO, __gen_ocl_get_ndrange_info)
+DECL_LLVM_GEN_FUNCTION(ENQUEUE_GET_ENQUEUE_INFO_ADDR, __gen_ocl_get_enqueue_info_addr)
-- 
2.1.4



More information about the Beignet mailing list