[Beignet] [PATCH] improve multithread calling of llvm

Xing, Homer homer.xing at intel.com
Wed Nov 6 23:31:35 PST 2013


Just sent out version 2. The root cause is llvm::shutdown(). 

-----Original Message-----
From: Zhigang Gong [mailto:zhigang.gong at linux.intel.com] 
Sent: Thursday, November 7, 2013 2:53 PM
To: Xing, Homer
Cc: Yang, Rong R; beignet at lists.freedesktop.org
Subject: Re: [Beignet] [PATCH] improve multithread calling of llvm

Considering that many of us is using clang/llvm 3.3, I will not merge this patch directly.

Two possible options I can think:
1. Use macro to make it not break 3.3.
2. Fix it with 3.3 if there is a easy fix.

What do you think?

On Thu, Nov 07, 2013 at 07:17:28AM +0000, Xing, Homer wrote:
> Oops, I am using llvm 3.4-svn. On llvm 3.4-svn this patch works fine ...
> 
> -----Original Message-----
> From: beignet-bounces at lists.freedesktop.org 
> [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of Zhigang 
> Gong
> Sent: Thursday, November 7, 2013 2:41 PM
> To: Yang, Rong R
> Cc: Xing, Homer; beignet at lists.freedesktop.org
> Subject: Re: [Beignet] [PATCH] improve multithread calling of llvm
> 
> This patch seems introduce a regression. If you run all the utest, it may trigger the following error:
> pure virtual method called
> terminate called without an active exception
> 
> then segfault. I'm using clang/llvm 3.3.
> 
> On Wed, Nov 06, 2013 at 08:09:43AM +0000, Yang, Rong R wrote:
> > LGTM, thanks.
> > 
> > -----Original Message-----
> > From: beignet-bounces at lists.freedesktop.org
> > [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of Homer 
> > Hsing
> > Sent: Tuesday, November 05, 2013 1:28 PM
> > To: beignet at lists.freedesktop.org
> > Subject: [Beignet] [PATCH] improve multithread calling of llvm
> > 
> > call llvm multithread function instead of using a semaphore.
> > also exit llvm multithread mode at the end of life.
> > 
> > Signed-off-by: Homer Hsing <homer.xing at intel.com>
> > ---
> >  backend/src/backend/gen_program.cpp |  7 -------
> >  backend/src/backend/gen_program.h   |  2 --
> >  backend/src/backend/program.cpp     | 11 ++++++++---
> >  3 files changed, 8 insertions(+), 12 deletions(-)
> > 
> > diff --git a/backend/src/backend/gen_program.cpp
> > b/backend/src/backend/gen_program.cpp
> > index 781152d..40ab176 100644
> > --- a/backend/src/backend/gen_program.cpp
> > +++ b/backend/src/backend/gen_program.cpp
> > @@ -159,10 +159,3 @@ void genSetupCallBacks(void)
> > -
> > -sem_t llvm_semaphore;
> >    gbe_program_new_from_binary = gbe::genProgramNewFromBinary;
> 
> >    gbe_program_new_from_llvm = gbe::genProgramNewFromLLVM;  }
> > -
> > -void genSetupLLVMSemaphore(void)
> > -{
> > -  sem_init(&llvm_semaphore, 0, 1);
> > -}
> > diff --git a/backend/src/backend/gen_program.h
> > b/backend/src/backend/gen_program.h
> > index a498a5d..8d37a70 100644
> > --- a/backend/src/backend/gen_program.h
> > +++ b/backend/src/backend/gen_program.h
> > @@ -33,8 +33,6 @@
> >  
> >  /*! This will make the compiler output Gen ISA code */  extern void 
> > genSetupCallBacks(void); -extern sem_t llvm_semaphore; -extern void 
> > genSetupLLVMSemaphore(void);
> >  
> >  #endif /* __GBE_GEN_PROGRAM_H__ */
> >  
> > diff --git a/backend/src/backend/program.cpp 
> > b/backend/src/backend/program.cpp index 937f95b..281b0b8 100644
> > --- a/backend/src/backend/program.cpp
> > +++ b/backend/src/backend/program.cpp
> > @@ -32,6 +32,8 @@
> >  #include "ir/unit.hpp"
> >  #include "llvm/llvm_to_gen.hpp"
> >  #include "llvm/Config/config.h"
> > +#include "llvm/Support/Threading.h"
> > +#include "llvm/Support/ManagedStatic.h"
> >  #include <cstring>
> >  #include <algorithm>
> >  #include <fstream>
> > @@ -557,9 +559,7 @@ namespace gbe {
> >  
> >      // Create an action and make the compiler instance carry it out
> >      llvm::OwningPtr<clang::CodeGenAction> Act(new clang::EmitLLVMOnlyAction());
> > -    sem_wait(&llvm_semaphore);
> >      auto retVal = Clang.ExecuteAction(*Act);
> > -    sem_post(&llvm_semaphore);
> >      if (!retVal)
> >        return;
> >  
> > @@ -854,7 +854,12 @@ namespace gbe
> >        gbe_get_image_base_index = gbe::getImageBaseIndex;
> >        gbe_set_image_base_index = gbe::setImageBaseIndex;
> >        genSetupCallBacks();
> > -      genSetupLLVMSemaphore();
> > +      llvm::llvm_start_multithreaded();
> > +    }
> > +
> > +    ~CallBackInitializer() {
> > +      llvm::llvm_stop_multithreaded();
> > +      llvm::llvm_shutdown();
> >      }
> >    };
> >  
> > --
> > 1.8.3.2
> > 
> > _______________________________________________
> > 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
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list