[Beignet] [PATCH] Add the switch logic for math conformance fast pass

junyan.he at inbox.com junyan.he at inbox.com
Tue Sep 2 07:15:36 PDT 2014


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

Modify the __ocl_math_fastpath_flag init value in the
backend link stage to switch between fast pass and
conformance pass.

Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
 backend/src/backend/program.cpp        |   11 ++++++-----
 backend/src/llvm/llvm_bitcode_link.cpp |   13 ++++++++++---
 backend/src/llvm/llvm_gen_backend.hpp  |    2 +-
 backend/src/llvm/llvm_to_gen.cpp       |    4 ++--
 backend/src/llvm/llvm_to_gen.hpp       |    2 +-
 5 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 714c00c..3cd396c 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -105,6 +105,7 @@ namespace gbe {
 
 #ifdef GBE_COMPILER_AVAILABLE
   BVAR(OCL_OUTPUT_GEN_IR, false);
+  BVAR(OCL_STRICT_CONFORMANCE, false);
 
   bool Program::buildFromLLVMFile(const char *fileName, const void* module, std::string &error, int optLevel) {
     ir::Unit *unit = new ir::Unit();
@@ -112,7 +113,7 @@ namespace gbe {
     if(module){
       cloned_module = llvm::CloneModule((llvm::Module*)module);
     }
-    if (llvmToGen(*unit, fileName, module, optLevel) == false) {
+    if (llvmToGen(*unit, fileName, module, optLevel, OCL_STRICT_CONFORMANCE) == false) {
       error = std::string(fileName) + " not found";
       return false;
     }
@@ -122,9 +123,11 @@ namespace gbe {
       delete unit;   //clear unit
       unit = new ir::Unit();
       if(cloned_module){
-        llvmToGen(*unit, fileName, cloned_module, 0);  //suppose file exists and llvmToGen will not return false.
+        //suppose file exists and llvmToGen will not return false.
+        llvmToGen(*unit, fileName, cloned_module, 0, OCL_STRICT_CONFORMANCE);
       }else{
-        llvmToGen(*unit, fileName, module, 0);  //suppose file exists and llvmToGen will not return false.
+        //suppose file exists and llvmToGen will not return false.
+        llvmToGen(*unit, fileName, module, 0, OCL_STRICT_CONFORMANCE);
       }
     }
     assert(unit->getValid());
@@ -136,8 +139,6 @@ namespace gbe {
     return true;
   }
 
-  BVAR(OCL_STRICT_CONFORMANCE, false);
-
   bool Program::buildFromUnit(const ir::Unit &unit, std::string &error) {
     constantSet = new ir::ConstantSet(unit.getConstantSet());
     const auto &set = unit.getFunctionSet();
diff --git a/backend/src/llvm/llvm_bitcode_link.cpp b/backend/src/llvm/llvm_bitcode_link.cpp
index f9988fa..16a020d 100644
--- a/backend/src/llvm/llvm_bitcode_link.cpp
+++ b/backend/src/llvm/llvm_bitcode_link.cpp
@@ -50,7 +50,7 @@ SVAR(OCL_BITCODE_LIB_PATH, OCL_BITCODE_BIN);
 
 namespace gbe
 {
-  static Module* createOclBitCodeModule(LLVMContext& ctx)
+  static Module* createOclBitCodeModule(LLVMContext& ctx, int mathFastPath)
   {
     std::string bitCodeFiles = OCL_BITCODE_LIB_PATH;
     std::istringstream bitCodeFilePath(bitCodeFiles);
@@ -73,6 +73,13 @@ namespace gbe
       return NULL;
     }
 
+    if (mathFastPath) {
+      llvm::GlobalVariable* mathFastFlag = oclLib->getGlobalVariable("__ocl_math_fastpath_flag");
+      assert(mathFastFlag);
+      Type* intTy = IntegerType::get(ctx, 32);
+      mathFastFlag->setInitializer(ConstantInt::get(intTy, 0));
+    }
+
     return oclLib;
   }
 
@@ -126,11 +133,11 @@ namespace gbe
   }
 
 
-  Module* runBitCodeLinker(Module *mod)
+  Module* runBitCodeLinker(Module *mod, int mathFastPath)
   {
     LLVMContext& ctx = mod->getContext();
     std::set<std::string> materializedFuncs;
-    Module* clonedLib = createOclBitCodeModule(ctx);
+    Module* clonedLib = createOclBitCodeModule(ctx, mathFastPath);
     assert(clonedLib && "Can not create the beignet bitcode\n");
 
     std::vector<const char *> kernels;
diff --git a/backend/src/llvm/llvm_gen_backend.hpp b/backend/src/llvm/llvm_gen_backend.hpp
index ee44a8a..ae21fc4 100644
--- a/backend/src/llvm/llvm_gen_backend.hpp
+++ b/backend/src/llvm/llvm_gen_backend.hpp
@@ -99,7 +99,7 @@ namespace gbe
   llvm::FunctionPass* createPrintfParserPass();
 
   /*! Add all the function call of ocl to our bitcode. */
-  llvm::Module* runBitCodeLinker(llvm::Module *mod);
+  llvm::Module* runBitCodeLinker(llvm::Module *mod, int mathFastPath);
 
   void* getPrintfInfo(llvm::CallInst* inst);
 } /* namespace gbe */
diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp
index 8e49cbb..d59209b 100644
--- a/backend/src/llvm/llvm_to_gen.cpp
+++ b/backend/src/llvm/llvm_to_gen.cpp
@@ -198,7 +198,7 @@ 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 llvmToGen(ir::Unit &unit, const char *fileName,const void* module, int optLevel, int mathFastPath)
   {
     std::string errInfo;
     std::unique_ptr<llvm::raw_fd_ostream> o = NULL;
@@ -223,7 +223,7 @@ namespace gbe
     std::unique_ptr<Module> M;
 
     /* Before do any thing, we first filter in all CL functions in bitcode. */ 
-    M.reset(runBitCodeLinker(cl_mod));
+    M.reset(runBitCodeLinker(cl_mod, mathFastPath));
     if (!module)
       delete cl_mod;
     if (M.get() == 0)
diff --git a/backend/src/llvm/llvm_to_gen.hpp b/backend/src/llvm/llvm_to_gen.hpp
index 41e3477..088877a 100644
--- a/backend/src/llvm/llvm_to_gen.hpp
+++ b/backend/src/llvm/llvm_to_gen.hpp
@@ -32,7 +32,7 @@ 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 llvmToGen(ir::Unit &unit, const char *fileName, const void* module, int optLevel, int mathFastPath);
 
 } /* namespace gbe */
 
-- 
1.7.9.5





More information about the Beignet mailing list