[Beignet] [PATCH 4/8] OCL20: handle device enqueue helper functions in the backend.
Yang Rong
rong.r.yang at intel.com
Fri May 20 07:46:03 UTC 2016
Add useDeviceEnqueue to kernel to indicate the kernel use device
enqueue or not.
Signed-off-by: Yang Rong <rong.r.yang at intel.com>
---
backend/src/backend/context.cpp | 1 +
backend/src/backend/program.cpp | 5 +++-
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 | 48 +++++++++++++++++++++++++-----
backend/src/llvm/llvm_gen_ocl_function.hxx | 5 ++++
7 files changed, 74 insertions(+), 9 deletions(-)
diff --git a/backend/src/backend/context.cpp b/backend/src/backend/context.cpp
index 40b744f..2e8de1e 100644
--- a/backend/src/backend/context.cpp
+++ b/backend/src/backend/context.cpp
@@ -369,6 +369,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 f862881..a1589f4 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -88,7 +88,9 @@ 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) {}
+ slmSize(0), ctx(NULL), samplerSet(NULL), imageSet(NULL), printfSet(NULL),
+ useDeviceEnqueue(false) {}
+
Kernel::~Kernel(void) {
if(ctx) GBE_DELETE(ctx);
if(samplerSet) GBE_DELETE(samplerSet);
@@ -158,6 +160,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 4d49ead..4ac60d3 100644
--- a/backend/src/backend/program.hpp
+++ b/backend/src/backend/program.hpp
@@ -198,6 +198,12 @@ namespace gbe {
virtual size_t serializeToBin(std::ostream& outs);
virtual size_t deserializeFromBin(std::istream& ins);
virtual void printStatus(int indent, std::ostream& outs);
+ /*! Does it use SLM */
+ INLINE bool getUseDeviceEnqueue(void) const { return this->useDeviceEnqueue; }
+ /*! Change the SLM config for the function */
+ INLINE bool setUseDeviceEnqueue(bool useDeviceEnqueue) {
+ return this->useDeviceEnqueue = useDeviceEnqueue;
+ }
protected:
friend class Context; //!< Owns the kernels
@@ -218,6 +224,7 @@ namespace gbe {
ir::PrintfSet *printfSet; //!< Copy from the corresponding function.
size_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
};
@@ -254,6 +261,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 */
@@ -298,6 +311,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 f09cbe3..1653aec 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 fb6b36b..e2ce537 100644
--- a/backend/src/ir/function.hpp
+++ b/backend/src/ir/function.hpp
@@ -546,6 +546,12 @@ namespace ir {
}
/*! Output the control flow graph to .dot file */
void outputCFG();
+ /*! Does it use SLM */
+ INLINE bool getUseDeviceEnqueue(void) const { return this->useDeviceEnqueue; }
+ /*! Change the SLM config for 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
@@ -573,6 +579,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 1c41207..033e7de 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -1474,9 +1474,6 @@ namespace gbe
return;
}
if (isa<GlobalVariable>(c)) {
- const GlobalVariable *GV = cast<GlobalVariable>(c);
-
- unsigned valueAddrSpace = GV->getType()->getAddressSpace();
ir::Constant cc = unit.getConstantSet().getConstant(c->getName());
unsigned int defOffset = cc.getOffset();
@@ -1582,10 +1579,16 @@ namespace gbe
offset += sizeof(short);
break;
}
- default: {
- c->dump();
- NOT_IMPLEMENTED;
- }
+ case Type::TypeID::PointerTyID:
+ {
+ //c->dump();
+ break;
+ }
+ default:
+ {
+ c->dump();
+ NOT_IMPLEMENTED;
+ }
}
}
static bool isProgramGlobal(const GlobalVariable &v) {
@@ -2786,6 +2789,9 @@ namespace gbe
ctx.ADD(getType(ctx, v.getType()), reg, ir::ocl::constant_addrspace, reg);
}
}
+ } else if(addrSpace == ir::MEM_PRIVATE) {
+ //const_cast<GlobalVariable*>(&v)->dump();
+ this->newRegister(const_cast<GlobalVariable*>(&v));
}
}
}
@@ -3806,6 +3812,8 @@ namespace gbe
case GEN_OCL_WORK_GROUP_SCAN_INCLUSIVE_ADD:
case GEN_OCL_WORK_GROUP_SCAN_INCLUSIVE_MAX:
case GEN_OCL_WORK_GROUP_SCAN_INCLUSIVE_MIN:
+ case GEN_OCL_ENQUEUE_SET_NDRANGE_INFO:
+ case GEN_OCL_ENQUEUE_GET_NDRANGE_INFO:
this->newRegister(&I);
break;
case GEN_OCL_GET_PIPE:
@@ -3826,6 +3834,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:
@@ -4906,6 +4917,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 43c3e00..7135579 100644
--- a/backend/src/llvm/llvm_gen_ocl_function.hxx
+++ b/backend/src/llvm/llvm_gen_ocl_function.hxx
@@ -198,3 +198,8 @@ DECL_LLVM_GEN_FUNCTION(WORK_GROUP_ANY, __gen_ocl_work_group_any)
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)
--
1.9.1
More information about the Beignet
mailing list