From: Junyan He <[email protected]> The struct to store profiling info should accompany each kernel function rather than the whole unit. Sometimes we will write several kernels within one file and we just want to add profiling to one of them.
Signed-off-by: Junyan He <[email protected]> --- backend/src/backend/gen_program.cpp | 4 ++-- backend/src/backend/program.cpp | 2 +- backend/src/ir/function.hpp | 10 ++++++++++ backend/src/ir/lowering.cpp | 6 +++--- backend/src/ir/profiling.hpp | 2 +- backend/src/ir/unit.cpp | 9 ++++++--- backend/src/ir/unit.hpp | 12 ++++-------- backend/src/llvm/llvm_gen_backend.cpp | 4 ++-- backend/src/llvm/llvm_profiling.cpp | 1 - 9 files changed, 29 insertions(+), 21 deletions(-) diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp index e3c2895..48159e5 100644 --- a/backend/src/backend/gen_program.cpp +++ b/backend/src/backend/gen_program.cpp @@ -146,7 +146,7 @@ namespace gbe { // Be careful when the simdWidth is forced by the programmer. We can see it // when the function already provides the simd width we need to use (i.e. // non zero) - const ir::Function *fn = unit.getFunction(name); + ir::Function *fn = unit.getFunction(name); uint32_t codeGenNum = sizeof(codeGenStrategy) / sizeof(codeGenStrategy[0]); uint32_t codeGen = 0; GenContext *ctx = NULL; @@ -178,7 +178,7 @@ namespace gbe { if (profiling) { ctx->setProfilingMode(true); - unit.getProfilingInfo()->setDeviceID(deviceID); + fn->getProfilingInfo()->setDeviceID(deviceID); } ctx->setASMFileName(this->asm_file_name); diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp index 232a79e..b65124a 100644 --- a/backend/src/backend/program.cpp +++ b/backend/src/backend/program.cpp @@ -180,7 +180,7 @@ namespace gbe { return false; } kernel->setSamplerSet(pair.second->getSamplerSet()); - kernel->setProfilingInfo(new ir::ProfilingInfo(*unit.getProfilingInfo())); + kernel->setProfilingInfo(new ir::ProfilingInfo(*(pair.second->getProfilingInfo()))); kernel->setImageSet(pair.second->getImageSet()); kernel->setPrintfSet(pair.second->getPrintfSet()); kernel->setCompileWorkGroupSize(pair.second->getCompileWorkGroupSize()); diff --git a/backend/src/ir/function.hpp b/backend/src/ir/function.hpp index 78250cf..aa89f0b 100644 --- a/backend/src/ir/function.hpp +++ b/backend/src/ir/function.hpp @@ -31,6 +31,7 @@ #include "ir/sampler.hpp" #include "ir/printf.hpp" #include "ir/image.hpp" +#include "ir/profiling.hpp" #include "sys/vector.hpp" #include "sys/set.hpp" #include "sys/map.hpp" @@ -531,6 +532,14 @@ namespace ir { } return insnNum; } + /*! Set in profiling mode */ + void setProfilingMode(uint32_t type) { profInfo.setProfilingType(type); } + /*! Get in profiling mode */ + uint32_t getProfilingMode(void) const { return profInfo.getProfilingType(); } + /*! Get profiling info in this function */ + ProfilingInfo* getProfilingInfo(void) { return &profInfo; } + /*! Set profiling info to the function */ + void setProfilingInfo(const ProfilingInfo &p) { profInfo = p; } /*! Output the control flow graph to .dot file */ void outputCFG(); private: @@ -560,6 +569,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. + ProfilingInfo profInfo; //!< Used to store the profiling info. GBE_CLASS(Function); //!< Use custom allocator }; diff --git a/backend/src/ir/lowering.cpp b/backend/src/ir/lowering.cpp index 1746489..fd53c18 100644 --- a/backend/src/ir/lowering.cpp +++ b/backend/src/ir/lowering.cpp @@ -57,9 +57,9 @@ namespace ir { const BasicBlock *lastBlock = this->bb; /* Append the STORE_PROFILING just before return. */ - if (unit.getInProfilingMode() == true) { - this->STORE_PROFILING(this->getUnit().getProfilingInfo()->getBTI(), - this->getUnit().getProfilingInfo()->getProfilingType()); + if (this->fn->getProfilingMode()) { + this->STORE_PROFILING(this->fn->getProfilingInfo()->getBTI(), + this->fn->getProfilingInfo()->getProfilingType()); } this->RET(); diff --git a/backend/src/ir/profiling.hpp b/backend/src/ir/profiling.hpp index ce9866f..8b7690f 100644 --- a/backend/src/ir/profiling.hpp +++ b/backend/src/ir/profiling.hpp @@ -25,13 +25,13 @@ #include <string.h> #include "sys/map.hpp" #include "sys/vector.hpp" -#include "unit.hpp" namespace gbe { namespace ir { class Context; + class Unit; class ProfilingInfo //: public Serializable { public: diff --git a/backend/src/ir/unit.cpp b/backend/src/ir/unit.cpp index a350c60..1a5c85e 100644 --- a/backend/src/ir/unit.cpp +++ b/backend/src/ir/unit.cpp @@ -28,12 +28,9 @@ namespace gbe { namespace ir { Unit::Unit(PointerSize pointerSize) : pointerSize(pointerSize), valid(true) { - profilingInfo = GBE_NEW(ProfilingInfo); - inProfilingMode = false; } Unit::~Unit(void) { for (const auto &pair : functions) GBE_DELETE(pair.second); - delete profilingInfo; for (const auto &pair : printfs) GBE_DELETE(pair.second); } Function *Unit::getFunction(const std::string &name) const { @@ -48,6 +45,12 @@ namespace ir { return NULL; Function *fn = GBE_NEW(Function, name, *this); functions[name] = fn; + + // Assign the profiling info to each kernel. + if (profMap.find(name) != profMap.end()) { + fn->setProfilingInfo(profMap[name]); + } + return fn; } void Unit::newConstant(const char *data, diff --git a/backend/src/ir/unit.hpp b/backend/src/ir/unit.hpp index 10a1af6..06d15ec 100644 --- a/backend/src/ir/unit.hpp +++ b/backend/src/ir/unit.hpp @@ -79,23 +79,19 @@ namespace ir { ConstantSet& getConstantSet(void) { return constantSet; } /*! Return the constant set */ const ConstantSet& getConstantSet(void) const { return constantSet; } - /*! Get profiling info in this function */ - ProfilingInfo* getProfilingInfo(void) const { return profilingInfo; } - /*! Set in profiling mode */ - void setInProfilingMode(bool b) { inProfilingMode = b; } - /*! Get in profiling mode */ - bool getInProfilingMode(void) const { return inProfilingMode; } void setValid(bool value) { valid = value; } bool getValid() { return valid; } + void setProfilingInfoForKernel(std::string& name, ProfilingInfo& profInfo) { + profMap.insert(std::pair<std::string, ProfilingInfo>(name, profInfo)); + } private: friend class ContextInterface; //!< Can free modify the unit FunctionSet functions; //!< All the defined functions ConstantSet constantSet; //!< All the constants defined in the unit PointerSize pointerSize; //!< Size shared by all pointers - ProfilingInfo *profilingInfo; //!< profilingInfo store the information for profiling. + map<std::string, ProfilingInfo> profMap; //!< Store the profiling info before function generated. GBE_CLASS(Unit); bool valid; - bool inProfilingMode; }; /*! Output the unit string in the given stream */ diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp index 34fc0fa..92ddea8 100644 --- a/backend/src/llvm/llvm_gen_backend.cpp +++ b/backend/src/llvm/llvm_gen_backend.cpp @@ -2682,7 +2682,7 @@ namespace gbe this->newRegister(const_cast<GlobalVariable*>(&v), NULL, true); ctx.CVT(ir::TYPE_U32, ir::TYPE_U64, getRegister(const_cast<GlobalVariable*>(&v)), ir::ocl::printfiptr); } else if(v.getName().equals(StringRef("__gen_ocl_profiling_buf"))) { - ctx.getUnit().getProfilingInfo()->setBTI(BtiMap.find(const_cast<GlobalVariable*>(&v))->second); + ctx.getFunction().getProfilingInfo()->setBTI(BtiMap.find(const_cast<GlobalVariable*>(&v))->second); regTranslator.newScalarProxy(ir::ocl::profilingbptr, const_cast<GlobalVariable*>(&v)); } else if(v.getName().str().substr(0, 4) == ".str") { /* When there are multi printf statements in multi kernel fucntions within the same @@ -4568,7 +4568,7 @@ namespace gbe ConstantInt *CI = dyn_cast<ConstantInt>(*AI); GBE_ASSERT(CI); uint32_t ptype = CI->getZExtValue(); - ctx.getUnit().getProfilingInfo()->setProfilingType(ptype); + ctx.getFunction().getProfilingInfo()->setProfilingType(ptype); break; } case GEN_OCL_SIMD_SIZE: diff --git a/backend/src/llvm/llvm_profiling.cpp b/backend/src/llvm/llvm_profiling.cpp index 211aa43..53aa468 100644 --- a/backend/src/llvm/llvm_profiling.cpp +++ b/backend/src/llvm/llvm_profiling.cpp @@ -206,7 +206,6 @@ namespace gbe FunctionPass* createProfilingInserterPass(int profilingType, ir::Unit &unit) { - unit.setInProfilingMode(true); return new ProfilingInserter(profilingType); } char ProfilingInserter::ID = 0; -- 1.9.1 _______________________________________________ Beignet mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/beignet
