diff options
author | Junyan He <junyan.he@linux.intel.com> | 2014-09-10 16:10:28 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@intel.com> | 2014-09-10 16:27:19 +0800 |
commit | 077337848a738fe0f9cae7b786b64ad8e5a5782d (patch) | |
tree | 870dc2bfb8138b2caaa2ddfb3f5bbe18c4177487 | |
parent | 423dbb0d2389dea27dd451cf458b06df92c27ecb (diff) |
Add the switch logic for math conformance fast path
Modify the __ocl_math_fastpath_flag init value in the
backend link stage to switch between fast path and
conformance path.
V2:
Rename the function prototype parameter name.
V3:
Modify the parameter to boolean and correct some comment words.
Signed-off-by: Junyan He <junyan.he@linux.intel.com>
Reviewed-by: "Song, Ruiling" <ruiling.song@intel.com>
-rw-r--r-- | backend/src/backend/program.cpp | 11 | ||||
-rw-r--r-- | backend/src/llvm/llvm_bitcode_link.cpp | 13 | ||||
-rw-r--r-- | backend/src/llvm/llvm_gen_backend.hpp | 2 | ||||
-rw-r--r-- | backend/src/llvm/llvm_to_gen.cpp | 4 | ||||
-rw-r--r-- | 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 b9dfc75..0aa5f14 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 7841db2..d845479 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, bool strictMath) { std::string bitCodeFiles = OCL_BITCODE_LIB_PATH; std::istringstream bitCodeFilePath(bitCodeFiles); @@ -73,6 +73,13 @@ namespace gbe return NULL; } + if (strictMath) { + 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, bool strictMath) { LLVMContext& ctx = mod->getContext(); std::set<std::string> materializedFuncs; - Module* clonedLib = createOclBitCodeModule(ctx); + Module* clonedLib = createOclBitCodeModule(ctx, strictMath); 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..f73aafe 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, bool strictMath); 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 3677c7f..67890d1 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, bool strictMath) { 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, strictMath)); 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..b2dfb0d 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, bool strictMath); } /* namespace gbe */ |