Multithreaded code generation

Hi
I want to use LLVM to automatically translate sequential codes to multithreaded codes for execution on multicore processors.
How should I start?
Best Regards.

|

Hi Hamed,

I want to use LLVM to automatically translate sequential codes to multithreaded
codes for execution on multicore processors.
How should I start?

currently LLVM does not have support for anything like this as far as I know.
But perhaps you meant that you want to implement it, and are asking for advice?

Ciao,

Duncan.

Hi
yes, I’m asking for any advice, I want to implement multithreaded code generator in LLVM.
tnx

— On Tue, 10/5/10, Duncan Sands baldrick@free.fr wrote:


> From: Duncan Sands baldrick@free.fr
> Subject: Re: [LLVMdev] Multithreaded code generation
> To: llvmdev@cs.uiuc.edu
> Date: Tuesday, October 5, 2010, 10:50 AM
>
> Hi Hamed,
>
> > I want to use LLVM to automatically translate sequential codes to multithreaded
> > codes for execution on multicore processors.
> > How should I start?
>
> currently LLVM does not have support for anything like this as far as I know.
> But perhaps you meant that you want to implement it, and are asking for advice?
>
> Ciao,
>
> Duncan.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

|

Hi Hamed,

Do you propose to change codegen for specific IR constructions or generic ones? How would you recognize multi-threaded execution in a code?

There was a thread earlier about OpenMP support in Clang, that would be a good start, and even a good use-case for metadata.

Hi
yes, I'm asking for any advice, I want to implement multithreaded code
generator in LLVM.
tnx

Hi,

this generally depends which kind of code you want to multithread, because generally this is a difficult problem.
However, if you limit yourself for the moment to loops that fit into the polyhedral model, you can take advantage of the existing research in this area, which already produced some nice solutions.

If you are interested in this area I think this is the way to go:

1. Have a look at pluto[1]

Pluto is a source to source compiler that can auto parallelize hand selected code. To check how it works I attached you an example, where it translates normal C code to OpenMP parallelized code.

Compile it like this:

gcc -O3 seidel.c -o seidel_sequential
gcc -O3 -fopenmp -lm seidel.par.c -o seidel_parallel

I tried this on a 2 Core / 4 Thread Intel processor

$ time ./seidel_sequential

real 0m6.923s
user 0m6.890s
sys 0m0.010s

$ time ./seidel_parallel

real 0m2.710s
user 0m10.730s
sys 0m0.010s

One way to get this feature automatically into LLVM is by using polly [2]. Polly can detect and code generate all loops, that can be parallelized by pluto. So there are only two things missing.

1. Connect pluto somehow to polly to automatically parallelize any code that can be compiled by LLVM.

I am planning to work on this during the next six month. The first test cases will probably work a lot faster.

2. Create OpenMP parallel code.

This is not too difficult. We need an OpenMP library http://mpc.sourceforge.net/ has e.g. an acceptable license (LGPL) and generate the relevant library calls.
As a first step this can be done without pluto support in Polly. We just limit ourselves to parallelize only loops, that do not carry dependences.

If you want to work on this I propose to start with step "2.". Ping me for further information.

Cheers
Tobi

[1] http://pluto-compiler.sourceforge.net/
[2] http://wiki.llvm.org/Polyhedral_optimization_framework

seidel.c (1.54 KB)

seidel.par.c (2.8 KB)

Hi,

In fact I have some theory on instruction level parallelism( i have a partitioning algorithm), then first of all, i want to generate a multithreaded code from LLVM IR (in assembly level) with a given partitioning. My problem is how can i use a thread library(like Pthread) or OS system calls in LLVM IR to create and manage threads?

— On Tue, 10/5/10, Tobias Grosser grosser@fim.uni-passau.de wrote:


> From: Tobias Grosser grosser@fim.uni-passau.de
> Subject: Re: [LLVMdev] Multithreaded code generation
> To: llvmdev@cs.uiuc.edu
> Date: Tuesday, October 5, 2010, 12:08 PM
>
> On 10/05/2010 09:42 AM, hamed hamzehi wrote:
> > Hi
> > yes, I’m asking for any advice, I want to implement multithreaded code
> > generator in LLVM.
> > tnx
>
> Hi,
>
> this generally depends which kind of code you want to multithread, because generally this is a difficult problem.
> However, if you limit yourself for the moment to loops that fit into the polyhedral model, you can take advantage of the existing research in this area, which already produced some nice solutions.
>
> If you are interested in this area I think this is the way to go:
>
> 1. Have a look at pluto[1]
>
> Pluto is a source to source compiler that can auto parallelize hand selected code. To check how it works I attached you an example, where it translates normal C code to OpenMP parallelized code.
>
> Compile it like this:
>
> gcc -O3 seidel.c -o seidel_sequential
> gcc -O3 -fopenmp -lm seidel.par.c -o seidel_parallel
>
> I tried this on a 2 Core / 4 Thread Intel processor
>
> $ time ./seidel_sequential
>
> real 0m6.923s
> user 0m6.890s
> sys 0m0.010s
>
> $ time ./seidel_parallel
>
> real 0m2.710s
> user 0m10.730s
> sys 0m0.010s
>
> One way to get this feature automatically into LLVM is by using polly [2]. Polly can detect and code generate all loops, that can be parallelized by pluto. So there are only two things missing.
>
> 1. Connect pluto somehow to polly to automatically parallelize any code that can be compiled by LLVM.
>
> I am planning to work on this during the next six month. The first test cases will probably work a lot faster.
>
> 2. Create OpenMP parallel code.
>
> This is not too difficult. We need an OpenMP library http://mpc.sourceforge.net/ has e.g. an acceptable license (LGPL) and generate the relevant library calls.
> As a first step this can be done without pluto support in Polly. We just limit ourselves to parallelize only loops, that do not carry dependences.
>
> If you want to work on this I propose to start with step “2.”. Ping me for further information.
>
> Cheers
> Tobi
>
> [1] http://pluto-compiler.sourceforge.net/
> [2] http://wiki.llvm.org/Polyhedral_optimization_framework
>
> >
> > — On Tue, 10/5/10, Duncan Sands /baldrick@free.fr/ wrote:
> >
> >
> > From: Duncan Sands baldrick@free.fr
> > Subject: Re: [LLVMdev] Multithreaded code generation
> > To: llvmdev@cs.uiuc.edu
> > Date: Tuesday, October 5, 2010, 10:50 AM
> >
> > Hi Hamed,
> >
> > > I want to use LLVM to automatically translate sequential codes to
> > multithreaded
> > > codes for execution on multicore processors.
> > > How should I start?
> >
> > currently LLVM does not have support for anything like this as far
> > as I know.
> > But perhaps you meant that you want to implement it, and are asking
> > for advice?
> >
> > Ciao,
> >
> > Duncan.
> > _______________________________________________
> > LLVM Developers mailing list
> > LLVMdev@cs.uiuc.edu /mc/compose?to=LLVMdev@cs.uiuc.edu
> > http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> >
> >
> >
> >
> > _______________________________________________
> > LLVM Developers mailing list
> > LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

|

OK. For this I propose to insert calls to libgomp (gnuopenmp) or the mpc openmp library.

If you check out mpc you will find explanations how to use it to create OpenMP constructs by hand in a header file called mpcomp_abi.h located inside the mpc/MPC_OpenMP/include directory.
As a starter I would write C code that does what you expect and compile it to LLVM-IR to see how the libraries are inserted in the LLVM-IR.

Cheers
Tobi

Hi,

OK. For this I propose to insert calls to libgomp (gnuopenmp) or the mpc
openmp library.

you can also compile code using OMP constructs using llvm-gcc or dragonegg,
passing -emit-llvm (llvm-gcc) or -flto (dragonegg) and -S to see the LLVM
IR that is generated.

Ciao,

Duncan.