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

Zhigang Gong zhigang.gong at linux.intel.com
Tue Sep 9 22:50:34 PDT 2014


If we only have two modes, strict and non strict, then use bool is better.
And we definitely should use fast path rathen than fast pass.

On Wed, Sep 10, 2014 at 06:21:02AM +0000, Song, Ruiling wrote:
> I think bool type is better than integer type, what do you think?
> pass or path?
> 
> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of junyan.he at inbox.com
> Sent: Thursday, September 04, 2014 5:11 PM
> To: beignet at lists.freedesktop.org
> Cc: Junyan He
> Subject: [Beignet] [PATCH V2] Add the switch logic for math conformance fast pass
> 
> 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.
> 
> V2:
>     Rename the function prototype parameter name.
> 
> 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 98e8a34..092398c 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..999020a 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 
> + 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, int 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..c31099a 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 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 8e49cbb..b9b590b 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 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..fa31213 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 strictMath);
>  
>  } /* namespace gbe */
>  
> --
> 1.7.9.5
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list