Add useDeviceEnqueue to kernel to indicate the kernel use device enqueue or not.
Signed-off-by: Yang Rong <[email protected]> --- 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 | 39 +++++++++++++++++++++++++++--- backend/src/llvm/llvm_gen_ocl_function.hxx | 5 ++++ 7 files changed, 69 insertions(+), 5 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 1580fe8..4ecb7cb 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()); + enqueueFuncs = unit.enqueueFuncs; 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 e58ddf0..b6f5b06 100644 --- a/backend/src/backend/program.hpp +++ b/backend/src/backend/program.hpp @@ -213,6 +213,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 @@ -233,6 +239,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 }; @@ -269,6 +276,12 @@ namespace gbe { } return kernel; } + + const char *getDeviceEnqueueKernelName(uint32_t index) const { + if(index >= enqueueFuncs.size()) + return NULL; + return enqueueFuncs[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 */ @@ -313,6 +326,8 @@ namespace gbe { ir::ConstantSet *constantSet; /*! relocation table */ ir::RelocTable *relocTable; + /*! device enqueue functions */ + vector<std::string> enqueueFuncs; /*! 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 7c5263a..139a97a 100644 --- a/backend/src/ir/function.hpp +++ b/backend/src/ir/function.hpp @@ -538,6 +538,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 @@ -565,6 +571,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 06d6760..a6ad8fa 100644 --- a/backend/src/llvm/llvm_gen_backend.cpp +++ b/backend/src/llvm/llvm_gen_backend.cpp @@ -1440,9 +1440,6 @@ namespace gbe GBE_ASSERT(c); 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(); @@ -1537,6 +1534,11 @@ namespace gbe offset += sizeof(double); break; } + case Type::TypeID::PointerTyID: + { + //c->dump(); + break; + } default: NOT_IMPLEMENTED; } @@ -2735,6 +2737,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)); } } } @@ -3755,6 +3760,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: @@ -3775,6 +3782,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: break; case GEN_OCL_NOT_FOUND: @@ -4761,6 +4771,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 09feb1a..939cf7f 100644 --- a/backend/src/llvm/llvm_gen_ocl_function.hxx +++ b/backend/src/llvm/llvm_gen_ocl_function.hxx @@ -197,3 +197,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 _______________________________________________ Beignet mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/beignet
