From: Junyan He <[email protected]>

We need to use forward message to send data and sync
threads within the same work group. The HW lack the
feature to get the TID and EUID of other threads. So
we need to establish a map for this usage.

Signed-off-by: Junyan He <[email protected]>
---
 backend/src/llvm/llvm_gen_backend.cpp |   22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/backend/src/llvm/llvm_gen_backend.cpp 
b/backend/src/llvm/llvm_gen_backend.cpp
index 21738e9..ff60d86 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -490,6 +490,7 @@ namespace gbe
     LoopInfo *LI;
     const Module *TheModule;
     int btiBase;
+    int32_t tidMapSLM;
     int32_t wgBroadcastSLM;
   public:
     static char ID;
@@ -501,6 +502,7 @@ namespace gbe
         LI(0),
         TheModule(0),
         btiBase(BTI_RESERVED_NUM),
+        tidMapSLM(-1),
         wgBroadcastSLM(-1)
     {
       initializeLoopInfoPass(*PassRegistry::getPassRegistry());
@@ -2850,6 +2852,22 @@ namespace gbe
   }
 
   void GenWriter::emitWorkGroupInst(CallInst &I, CallSite &CS, 
ir::WorkGroupOps opcode) {
+    if (tidMapSLM < 0 && opcode >= ir::WORKGROUP_OP_REDUCE_ADD && opcode <= 
ir::WORKGROUP_OP_EXCLUSIVE_MAX) {
+      /* Because we can not know the thread ID and the EUID for every physical
+         thead which the work items execute on before the run time. We need to
+         sync the thread execution order when using work group functions. We
+         create the workitems/threadID map table in slm.
+         When we come to here, the global thread local vars should have all 
been
+         allocated, so it's safe for us to steal a piece of SLM for this 
usage. */
+      ir::Function &f = ctx.getFunction();
+      uint32_t mapSize = sizeof(uint16_t) * 64;// at most 64 thread for all 
EUs.
+      f.setUseSLM(true);
+      uint32_t oldSlm = f.getSLMSize();
+      f.setSLMSize(oldSlm + mapSize);
+      tidMapSLM = oldSlm;
+      GBE_ASSERT(tidMapSLM >= 0);
+    }
+
     if (wgBroadcastSLM < 0 && opcode == ir::WORKGROUP_OP_BROADCAST) {
       ir::Function &f = ctx.getFunction();
       uint32_t mapSize = 8;
@@ -2868,7 +2886,7 @@ namespace gbe
       GBE_ASSERT(getType(ctx, (*AI)->getType()) == ir::TYPE_S32);
       const ir::Register src = this->getRegister(*(AI++));
       const ir::Tuple srcTuple = ctx.arrayTuple(&src, 1);
-      ctx.WORKGROUP(opcode, (uint32_t)0, getRegister(&I), srcTuple, 1, 
ir::TYPE_S32);
+      ctx.WORKGROUP(opcode, (uint32_t)tidMapSLM, getRegister(&I), srcTuple, 1, 
ir::TYPE_S32);
     } else if (opcode == ir::WORKGROUP_OP_BROADCAST) {
       int argNum = CS.arg_size();
       ir::Register src[argNum];
@@ -2881,7 +2899,7 @@ namespace gbe
     } else {
       const ir::Register src = this->getRegister(*(AI++));
       const ir::Tuple srcTuple = ctx.arrayTuple(&src, 1);
-      ctx.WORKGROUP(opcode, (uint32_t)0, getRegister(&I), srcTuple, 1, 
getType(ctx, (*AI)->getType()));
+      ctx.WORKGROUP(opcode, (uint32_t)tidMapSLM, getRegister(&I), srcTuple, 1, 
getType(ctx, (*AI)->getType()));
     }
 
     GBE_ASSERT(AI == AE);
-- 
1.7.9.5



_______________________________________________
Beignet mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/beignet

Reply via email to