Loop skew&fusion with polly

47 views
Skip to first unread message

Nana CK

unread,
Sep 22, 2021, 10:09:18 PM9/22/21
to Polly Development
Hi all,
I am dealing this loop with PLUTO and polly:
>>>>>>>>>>>>>>>>>>>>>>>>
for (i = 0; i < nx; i++){
  for (j = 0; j < ny; j++){
    if(i<ny-1)
      A[i+1][j] = A[i][j];
    if(j<ny-1)
      A[i][j+1] = A[i][j];
  }
}
>>>>>>>>>>>>>>>>>>>>>>>>>
in PLUTO, it can be transformed into this:

(part of the output of pluto :)
>>>>>>>>>>>>>>>>>>>>>>>>>
for (t1=2*ny-2;t1<=nx+ny-2;t1++) {
  lbp=max(1,t1-nx+1);
  ubp=ny-1;
#pragma omp parallel for private(lbv,ubv,t3)
  for (t2=lbp;t2<=ubp;t2++) {
    A[(t1-t2)][(t2-1)+1] = A[(t1-t2)][(t2-1)];;
  }
}
>>>>>>>>>>>>>>>>>>>>>>>>>>

as you can see with the "nx+ny-2"  boundary, PLUTO has skewed this loop.

I have tried with these options with polly:

>>>>>>>>>>>>>>>>>>>>>>>>>
clang -S -g -emit-llvm ../test1.cc -Xclang -disable-O0-optnone -o test1.ll
opt -S -polly-canonicalize test1.ll -o beforepolly.ll
opt -polly-allow-nonaffine -polly-opt-fusion=max -polly-tiling=false 
       -polly-detect -polly-scops -polly-simplify -polly-optree -polly-delicm -polly-simplify -polly-dependences -polly-opt-isl -polly-ast -polly-codegen beforepolly.ll
>>>>>>>>>>>>>>>>>>>>>>>>>


But I can not get the similar transform with polly. I checked the llvm IR dumped after this passes, the new loop build by polly has the same structure with the original code.

 Did I miss something ? like options or pragmas?
 

Michael Kruse

unread,
Sep 23, 2021, 6:18:27 PM9/23/21
to Nana CK, Polly Development
Polly uses ISL to optimize the loop aut applies whatever ISL
returns.Try the -polly-opt-outer-coincidence=yes option (which
translates to ISL's --schedule-outer-coincidence option) to give
higher priority to parallelism compared to locality.

Michael



Am Mi., 22. Sept. 2021 um 21:09 Uhr schrieb 'Nana CK' via Polly
Development <poll...@googlegroups.com>:
> --
> You received this message because you are subscribed to the Google Groups "Polly Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to polly-dev+...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/polly-dev/adaa625d-f59c-443a-8082-8bc76ea2b15cn%40googlegroups.com.



--
Tardyzentrismus verboten!

Nana CK

unread,
Sep 24, 2021, 5:54:13 AM9/24/21
to Polly Development
Hi Michael,

Thank you so much! It worked! The loop I posted before has been successfully fused!

But I got a new problem. It seems polly can not deal with more complex loops with just the option "the -polly-opt-outer-coincidence=yes". Is there other options need to be added?

Here is the loop I used, which can be fused to a new loop with the expected boundary "num_step+num_layer-2" by PLUTO.(and again, I can not get this fusion with polly)

屏幕快照 2021-09-24 下午5.48.39.png


Nana.

Michael Kruse

unread,
Sep 24, 2021, 12:11:44 PM9/24/21
to Nana CK, Polly Development
Am Fr., 24. Sept. 2021 um 04:54 Uhr schrieb 'Nana CK' via Polly
Development <poll...@googlegroups.com>:
> Here is the loop I used, which can be fused to a new loop with the expected boundary "num_step+num_layer-2" by PLUTO.(and again, I can not get this fusion with polly)

I don't see how you could fuse any loops to get a loop boundary of
num_step+num_layer-2.

If you want the hidden_size loop to be fused, ISL usually prefers
unrelated computations to be separated. There are a couple of related
options in ISL (such as --polly-isl-arg=--schedule-separate-components
and --polly-isl-arg=--schedule-serialize-sccs,
--polly-isl-arg=--schedule-whole-component), none of which directly
correspond to a min/max fusion option. Please refer to the ISL
documentation. There is no separate handling of fission/fusion in
Polly (other than the recently added llvm.loop.distribute.enable
metadata support).

Michael

--
Tardyzentrismus verboten!

Nana CK

unread,
Sep 24, 2021, 12:25:46 PM9/24/21
to Polly Development
OK !
Thanks a lot ! Have a good day !
Reply all
Reply to author
Forward
0 new messages