[Beignet] [PATCH] GBE: refine the llvm multi-thread related code.

Zhigang Gong zhigang.gong at linux.intel.com
Tue Aug 26 22:34:42 PDT 2014


This version LGTM, will push latter. Thanks.

On Tue, Aug 26, 2014 at 03:39:24PM +0800, Ruiling Song wrote:
> LLVM 3.5 remove llvm_start/stop_multithreaded() API, instead multi-thread
> support is determined when build llvm(build option LLVM_ENABLE_THREADS).
> llvm_is_multithreaded() is used to check whether llvm is built with
> muti-thread support.
> 
> If multi-thread is not support(LLVM3.3/3.4 or 3.5 built with LLVM_ENABLE_THREADS off),
> we simply add a mutex when calling clang/llvm related API.
> 
> Signed-off-by: Ruiling Song <ruiling.song at intel.com>
> ---
>  backend/src/backend/program.cpp |   14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
> index 50396c8..d992f7b 100644
> --- a/backend/src/backend/program.cpp
> +++ b/backend/src/backend/program.cpp
> @@ -846,11 +846,14 @@ namespace gbe {
>      // will delete the module and act in GenProgram::CleanLlvmResource().
>      llvm::Module * out_module;
>      llvm::LLVMContext* llvm_ctx = new llvm::LLVMContext;
> +
> +    static std::mutex llvm_mutex;
> +    if (!llvm::llvm_is_multithreaded())
> +      llvm_mutex.lock();
> +
>      if (buildModuleFromSource(clName.c_str(), &out_module, llvm_ctx, clOpt.c_str(),
>                                stringSize, err, errSize)) {
>      // Now build the program from llvm
> -      static std::mutex gbe_mutex;
> -      gbe_mutex.lock();
>        size_t clangErrSize = 0;
>        if (err != NULL) {
>          GBE_ASSERT(errSize != NULL);
> @@ -863,11 +866,14 @@ namespace gbe {
>                                      err, errSize, optLevel);
>        if (err != NULL)
>          *errSize += clangErrSize;
> -      gbe_mutex.unlock();
>        if (OCL_OUTPUT_BUILD_LOG && options)
>          llvm::errs() << options;
>      } else
>        p = NULL;
> +
> +    if (!llvm::llvm_is_multithreaded())
> +      llvm_mutex.unlock();
> +
>      remove(clName.c_str());
>      return p;
>    }
> @@ -1261,11 +1267,9 @@ namespace gbe
>        gbe_release_printf_info = gbe::kernelReleasePrintfSet;
>        gbe_output_printf = gbe::kernelOutputPrintf;
>        genSetupCallBacks();
> -      llvm::llvm_start_multithreaded();
>      }
>  
>      ~CallBackInitializer() {
> -      llvm::llvm_stop_multithreaded();
>  #if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR > 3)
>        llvm::llvm_shutdown();
>  #endif
> -- 
> 1.7.10.4
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list