[Beignet] [PATCH 11/15] Add OCL_PROFILING_LOG environment to control profiling.
junyan.he at inbox.com
junyan.he at inbox.com
Wed Aug 12 01:49:32 PDT 2015
From: Junyan He <junyan.he at linux.intel.com>
Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
backend/src/backend/gen_context.hpp | 3 +++
backend/src/backend/gen_program.cpp | 6 +++++-
backend/src/backend/gen_program.hpp | 2 +-
backend/src/backend/gen_reg_allocation.cpp | 2 +-
backend/src/backend/program.cpp | 10 ++++++----
backend/src/backend/program.hpp | 3 ++-
backend/src/llvm/llvm_to_gen.cpp | 5 ++++-
backend/src/llvm/llvm_to_gen.hpp | 3 ++-
8 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/backend/src/backend/gen_context.hpp b/backend/src/backend/gen_context.hpp
index c086d9e..df461ee 100644
--- a/backend/src/backend/gen_context.hpp
+++ b/backend/src/backend/gen_context.hpp
@@ -204,6 +204,8 @@ namespace gbe
bool relaxMath;
bool getIFENDIFFix(void) const { return ifEndifFix; }
void setIFENDIFFix(bool fix) { ifEndifFix = fix; }
+ bool getProfilingMode(void) const { return inProfilingMode; }
+ void setProfilingMode(bool b) { inProfilingMode = b; }
CompileErrorCode getErrCode() { return errCode; }
protected:
@@ -218,6 +220,7 @@ namespace gbe
private:
CompileErrorCode errCode;
bool ifEndifFix;
+ bool inProfilingMode;
uint32_t regSpillTick;
/*! Build the curbe patch list for the given kernel */
void buildPatchList(void);
diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
index c761a2f..067ee43 100644
--- a/backend/src/backend/gen_program.cpp
+++ b/backend/src/backend/gen_program.cpp
@@ -140,7 +140,8 @@ namespace gbe {
{8, 16, false},
};
- Kernel *GenProgram::compileKernel(const ir::Unit &unit, const std::string &name, bool relaxMath) {
+ Kernel *GenProgram::compileKernel(const ir::Unit &unit, const std::string &name,
+ bool relaxMath, bool profiling) {
#ifdef GBE_COMPILER_AVAILABLE
// 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.
@@ -173,6 +174,9 @@ namespace gbe {
}
GBE_ASSERTM(ctx != NULL, "Fail to create the gen context\n");
+ if (profiling)
+ ctx->setProfilingMode(true);
+
for (; codeGen < codeGenNum; ++codeGen) {
const uint32_t simdWidth = codeGenStrategy[codeGen].simdWidth;
const bool limitRegisterPressure = codeGenStrategy[codeGen].limitRegisterPressure;
diff --git a/backend/src/backend/gen_program.hpp b/backend/src/backend/gen_program.hpp
index af1a9fa..053b152 100644
--- a/backend/src/backend/gen_program.hpp
+++ b/backend/src/backend/gen_program.hpp
@@ -68,7 +68,7 @@ namespace gbe
/*! Clean LLVM resource */
virtual void CleanLlvmResource(void);
/*! Implements base class */
- virtual Kernel *compileKernel(const ir::Unit &unit, const std::string &name, bool relaxMath);
+ virtual Kernel *compileKernel(const ir::Unit &unit, const std::string &name, bool relaxMath, bool profiling);
/*! Allocate an empty kernel. */
virtual Kernel *allocateKernel(const std::string &name) {
return GBE_NEW(GenKernel, name, deviceID);
diff --git a/backend/src/backend/gen_reg_allocation.cpp b/backend/src/backend/gen_reg_allocation.cpp
index 4cb88e9..bed3e60 100644
--- a/backend/src/backend/gen_reg_allocation.cpp
+++ b/backend/src/backend/gen_reg_allocation.cpp
@@ -787,7 +787,7 @@ namespace gbe
return false;
GBE_ASSERT(it != RA.end());
// offset less than 32 means it is not managed by our reg allocator.
- if (it->second < 32)
+ if (it->second < ir::ocl::regNum)
return false;
ctx.deallocate(it->second);
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 9caf1ac..bad3749 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -31,6 +31,7 @@
#include "ir/value.hpp"
#include "ir/unit.hpp"
#include "ir/printf.hpp"
+#include "ir/profiling.hpp"
#ifdef GBE_COMPILER_AVAILABLE
#include "llvm/llvm_to_gen.hpp"
@@ -114,6 +115,7 @@ namespace gbe {
#ifdef GBE_COMPILER_AVAILABLE
BVAR(OCL_OUTPUT_GEN_IR, false);
BVAR(OCL_STRICT_CONFORMANCE, true);
+ IVAR(OCL_PROFILING_LOG, 0, 0, 1); // Int for different profiling types.
bool Program::buildFromLLVMFile(const char *fileName, const void* module, std::string &error, int optLevel) {
ir::Unit *unit = new ir::Unit();
@@ -121,7 +123,7 @@ namespace gbe {
if(module){
cloned_module = llvm::CloneModule((llvm::Module*)module);
}
- if (llvmToGen(*unit, fileName, module, optLevel, OCL_STRICT_CONFORMANCE) == false) {
+ if (llvmToGen(*unit, fileName, module, optLevel, OCL_STRICT_CONFORMANCE, OCL_PROFILING_LOG) == false) {
if (fileName)
error = std::string(fileName) + " not found";
delete unit;
@@ -134,10 +136,10 @@ namespace gbe {
unit = new ir::Unit();
if(cloned_module){
//suppose file exists and llvmToGen will not return false.
- llvmToGen(*unit, fileName, cloned_module, 0, OCL_STRICT_CONFORMANCE);
+ llvmToGen(*unit, fileName, cloned_module, 0, OCL_STRICT_CONFORMANCE, OCL_PROFILING_LOG);
}else{
//suppose file exists and llvmToGen will not return false.
- llvmToGen(*unit, fileName, module, 0, OCL_STRICT_CONFORMANCE);
+ llvmToGen(*unit, fileName, module, 0, OCL_STRICT_CONFORMANCE, OCL_PROFILING_LOG);
}
}
assert(unit->getValid());
@@ -157,7 +159,7 @@ namespace gbe {
if (kernelNum == 0) return true;
for (const auto &pair : set) {
const std::string &name = pair.first;
- Kernel *kernel = this->compileKernel(unit, name, !OCL_STRICT_CONFORMANCE);
+ Kernel *kernel = this->compileKernel(unit, name, !OCL_STRICT_CONFORMANCE, OCL_PROFILING_LOG);
kernel->setSamplerSet(pair.second->getSamplerSet());
kernel->setImageSet(pair.second->getImageSet());
kernel->setPrintfSet(pair.second->getPrintfSet());
diff --git a/backend/src/backend/program.hpp b/backend/src/backend/program.hpp
index cff2463..d533cea 100644
--- a/backend/src/backend/program.hpp
+++ b/backend/src/backend/program.hpp
@@ -302,7 +302,8 @@ namespace gbe {
protected:
/*! Compile a kernel */
- virtual Kernel *compileKernel(const ir::Unit &unit, const std::string &name, bool relaxMath) = 0;
+ virtual Kernel *compileKernel(const ir::Unit &unit, const std::string &name,
+ bool relaxMath, bool profiling) = 0;
/*! Allocate an empty kernel. */
virtual Kernel *allocateKernel(const std::string &name) = 0;
/*! Kernels sorted by their name */
diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp
index 891f2a1..aca91aa 100644
--- a/backend/src/llvm/llvm_to_gen.cpp
+++ b/backend/src/llvm/llvm_to_gen.cpp
@@ -222,7 +222,8 @@ namespace gbe
BVAR(OCL_OUTPUT_LLVM_AFTER_LINK, false);
BVAR(OCL_OUTPUT_LLVM_AFTER_GEN, false);
- bool llvmToGen(ir::Unit &unit, const char *fileName,const void* module, int optLevel, bool strictMath)
+ bool llvmToGen(ir::Unit &unit, const char *fileName,const void* module,
+ int optLevel, bool strictMath, int profiling)
{
std::string errInfo;
std::unique_ptr<llvm::raw_fd_ostream> o = NULL;
@@ -298,6 +299,8 @@ namespace gbe
passes.add(createDeadInstEliminationPass()); // Remove simplified instructions
passes.add(createCFGSimplificationPass()); // Merge & remove BBs
passes.add(createLowerSwitchPass()); // simplify cfg will generate switch-case instruction
+ if (profiling)
+ passes.add(createProfilingInserterPass(profiling)); // insert the time stamp for profiling.
passes.add(createScalarizePass()); // Expand all vector ops
if(OCL_OUTPUT_CFG)
diff --git a/backend/src/llvm/llvm_to_gen.hpp b/backend/src/llvm/llvm_to_gen.hpp
index 22ffcb4..5667197 100644
--- a/backend/src/llvm/llvm_to_gen.hpp
+++ b/backend/src/llvm/llvm_to_gen.hpp
@@ -32,7 +32,8 @@ namespace gbe {
/*! Convert the LLVM IR code to a GEN IR code,
optLevel 0 equal to clang -O1 and 1 equal to clang -O2*/
- bool llvmToGen(ir::Unit &unit, const char *fileName, const void* module, int optLevel, bool strictMath);
+ bool llvmToGen(ir::Unit &unit, const char *fileName, const void* module,
+ int optLevel, bool strictMath, int profiling);
} /* namespace gbe */
--
1.7.9.5
More information about the Beignet
mailing list