[Polly] Generating code for changed memory accesses

Tobias Grosser tobias at grosser.es
Mon Jul 28 14:03:34 PDT 2014


On 28/07/2014 20:04, Johannes Doerfert wrote:
> Let's assume we have:
>
>       for (i = 0; i < N; i++)
> S:     A[i] = 3;
>
> Initially our Scop looks like:
>    Domain: { S[i] : i >= 0 and i <= N-1 }
>    Write:
>       { S[i] -> Memref_A[i] : i >= 0 and i <= N-1 }
>
> Now we prevectorize (and change the scattering/domain but not the access relations!):
>    Domain: { S[o, i] : exists (e = floor((o)/4): 4e = o and o <= i and o >= -3 + i and i >= 0 and i <= N-1) }
>    Write:
>       { S[i] -> Memref_A[i] : i >= 0 and i <= N-1 }

There is a difference between scattering and domain. Only the scattering 
is changed, the dimensionality of the domain is _never_ changed and 
consequently the memory access does not need to be updated.

> Now we can either apply the scattering to the access relation when we generate code or not.

What you want to do is the following:

1) Get the schedule map from the isl_ast_build

2) Translate it to an isl_pw_multi_aff

3) Translate the access function to an isl_pw_multi_aff

4) Express the access function in terms of new loop iterators

To do this you use isl_multi_pw_aff_pullback_pw_multi_aff() to
apply the schedule pma to the your access function

5) Build the ast expression

> If we do:
>    The access relation will look like:
>              { S[o, i] -> Memref_A[i] : exists (e = floor((o)/4): 4e = o and o <= i and o >= -3 + i and i >= 0 and i <= N-1)  }
>    Which is fine but if N was a compile time constant less then 4 (e.g., 3) the isl ast codegen will not generate code for the "o-dimension" and the schedule of the isl_ast looks different from the one we have e.g. in ScopInfo:
>             dump(ScopInfo->getSchedule()) =>             { S[i] -> S[o, i] : exists (e = floor((o)/4): 4e = o and o <= i and o >= -3 + i and i >= 0 and i <= 2) }
>             dump(isl_ast_build_get_schedule(..)) =>  { S[i] -> [i] : and i >= 0 and i <= 2) }
>     Now the access relation domain has 2 dimensions but the IslAst schedule has only one output dimension, a missmatch which will cause isl_ast_build_get_access_from... to fail.
>
> If we don't and N is not a compile time constant less then 4:
>    The access relation will look like:
>         { S[i] -> Memref_A[i] : i >= 0 and i <= N-1 }
>    But the schedule (both in ScopInfo and the one of the IslAst) will have two output dimensions and the isl_ast_build_get_access_from... call will fail.
>
> Do you see the problem?

I see that you try to fight disappearing dimensions. This is a problem 
you should not face which means the approach you take is most likely 
incorrect.

The schedule map obtained from the isl build should give you exactly the 
mapping between domains and new loop iterators that you need. If 
dimensions disappear or are newly created, all this should be part of 
this map and if applied correctly the right relations should be made 
automatically.

Cheers,
Tobias



More information about the llvm-commits mailing list