[Beignet] [PATCH 08/21 V3] Backend: Add IVAR OCL_PROFILING_LOG to control profiling log.

junyan.he at inbox.com junyan.he at inbox.com
Mon Nov 16 15:40:10 PST 2015


From: Junyan He <junyan.he at linux.intel.com>

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 at linux.intel.com>
---
 backend/src/backend/gen_context.hpp   |    3 +++
 backend/src/backend/gen_program.cpp   |    9 ++++++++-
 backend/src/backend/gen_program.hpp   |    2 +-
 backend/src/backend/program.cpp       |    9 +++++----
 backend/src/backend/program.hpp       |    3 ++-
 backend/src/llvm/llvm_gen_backend.hpp |    3 +++
 backend/src/llvm/llvm_profiling.cpp   |    4 +++-
 backend/src/llvm/llvm_to_gen.cpp      |    6 +++++-
 backend/src/llvm/llvm_to_gen.hpp      |    3 ++-
 9 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/backend/src/backend/gen_context.hpp b/backend/src/backend/gen_context.hpp
index 870266c..e955807 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 bb22542..8014346 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 75d77ba..cc1d526 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 472734b..d50320c 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 efe192f..d5c6442 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 94a377b..cf601d3 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 cd38df5..8c9157c 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 24d4be7..8a076ca 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 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