[LLVMdev] Multithreaded code generation

Tobias Grosser grosser at fim.uni-passau.de
Tue Oct 5 01:38:54 PDT 2010


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 at free.fr>/* wrote:
>
>
>     From: Duncan Sands <baldrick at free.fr>
>     Subject: Re: [LLVMdev] Multithreaded code generation
>     To: llvmdev at 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 at cs.uiuc.edu </mc/compose?to=LLVMdev at cs.uiuc.edu>
>     http://llvm.cs.uiuc.edu
>     http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

-------------- next part --------------
A non-text attachment was scrubbed...
Name: seidel.c
Type: text/x-csrc
Size: 1575 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101005/8660bde5/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: seidel.par.c
Type: text/x-csrc
Size: 2863 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101005/8660bde5/attachment-0001.c>


More information about the llvm-dev mailing list