summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunyan He <junyan.he@linux.intel.com>2015-11-17 07:40:10 +0800
committerYang Rong <rong.r.yang@intel.com>2015-11-17 16:23:30 +0800
commit0f831d584110950f8738e634121f1e3501397c50 (patch)
tree6f91102bc06af504c84c70d6c045c92f64daedbc
parent228de1e01fa8eb1036396be373406c581216c297 (diff)
Backend: Add IVAR OCL_PROFILING_LOG to control profiling log.
We add OCL_PROFILING_LOG as a int type, because there may be different types of profiling format in the future. Signed-off-by: Junyan He <junyan.he@linux.intel.com> Reviewed-by: Yang Rong <rong.r.yang@intel.com>
-rw-r--r--backend/src/backend/gen_context.hpp3
-rw-r--r--backend/src/backend/gen_program.cpp9
-rw-r--r--backend/src/backend/gen_program.hpp2
-rw-r--r--backend/src/backend/program.cpp9
-rw-r--r--backend/src/backend/program.hpp3
-rw-r--r--backend/src/llvm/llvm_gen_backend.hpp3
-rw-r--r--backend/src/llvm/llvm_profiling.cpp4
-rw-r--r--backend/src/llvm/llvm_to_gen.cpp6
-rw-r--r--backend/src/llvm/llvm_to_gen.hpp3
9 files changed, 32 insertions, 10 deletions
diff --git a/backend/src/backend/gen_context.hpp b/backend/src/backend/gen_context.hpp
index 870266c7..e9558072 100644
--- a/backend/src/backend/gen_context.hpp
+++ b/backend/src/backend/gen_context.hpp
@@ -209,6 +209,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:
@@ -223,6 +225,7 @@ namespace gbe
private:
CompileErrorCode errCode;
bool ifEndifFix;
+ bool inProfilingMode;
uint32_t regSpillTick;
const char* asmFileName;
/*! Build the curbe patch list for the given kernel */
diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
index bb225424..80143463 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, int 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.
@@ -172,6 +173,12 @@ namespace gbe {
ctx = GBE_NEW(Gen9Context, unit, name, deviceID, relaxMath);
}
GBE_ASSERTM(ctx != NULL, "Fail to create the gen context\n");
+
+ if (profiling) {
+ ctx->setProfilingMode(true);
+ unit.getProfilingInfo()->setDeviceID(deviceID);
+ }
+
ctx->setASMFileName(this->asm_file_name);
for (; codeGen < codeGenNum; ++codeGen) {
diff --git a/backend/src/backend/gen_program.hpp b/backend/src/backend/gen_program.hpp
index 75d77ba2..cc1d5269 100644
--- a/backend/src/backend/gen_program.hpp
+++ b/backend/src/backend/gen_program.hpp
@@ -69,7 +69,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, int profiling);
/*! Allocate an empty kernel. */
virtual Kernel *allocateKernel(const std::string &name) {
return GBE_NEW(GenKernel, name, deviceID);
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 472734ba..d50320ce 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -114,6 +114,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 +122,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 +135,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 +158,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 efe192f4..d5c64428 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, int 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_gen_backend.hpp b/backend/src/llvm/llvm_gen_backend.hpp
index 94a377b1..cf601d37 100644
--- a/backend/src/llvm/llvm_gen_backend.hpp
+++ b/backend/src/llvm/llvm_gen_backend.hpp
@@ -142,6 +142,9 @@ namespace gbe
/*! Passer the printf function call. */
llvm::FunctionPass* createPrintfParserPass();
+ /*! Insert the time stamp for profiling. */
+ llvm::FunctionPass* createProfilingInserterPass(int profilingType, ir::Unit &unit);
+
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
/* customized loop unrolling pass. */
llvm::LoopPass *createCustomLoopUnrollPass();
diff --git a/backend/src/llvm/llvm_profiling.cpp b/backend/src/llvm/llvm_profiling.cpp
index cd38df54..8c9157c3 100644
--- a/backend/src/llvm/llvm_profiling.cpp
+++ b/backend/src/llvm/llvm_profiling.cpp
@@ -61,6 +61,7 @@
#include "llvm/llvm_gen_backend.hpp"
#include "sys/map.hpp"
+#include "ir/unit.hpp"
#include <iostream>
#include <vector>
@@ -200,8 +201,9 @@ namespace gbe
return changed;
}
- FunctionPass* createProfilingInserterPass(int profilingType)
+ FunctionPass* createProfilingInserterPass(int profilingType, ir::Unit &unit)
{
+ unit.setInProfilingMode(true);
return new ProfilingInserter(profilingType);
}
char ProfilingInserter::ID = 0;
diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp
index 24d4be79..8a076ca2 100644
--- a/backend/src/llvm/llvm_to_gen.cpp
+++ b/backend/src/llvm/llvm_to_gen.cpp
@@ -206,7 +206,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;
@@ -286,6 +287,9 @@ 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, unit)); // 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 22ffcb44..56671973 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 */