periscop / cloog

The CLooG Code Generator in the Polyhedral Model
GNU Lesser General Public License v2.1
40 stars 23 forks source link

Apparent bug working with 0.18.5 #34

Closed gabriel-rodriguez closed 6 years ago

gabriel-rodriguez commented 6 years ago

Dear all,

I am struggling with what seems to be a code generation bug working with v0.18.5. I am providing as input the 9-dimensional iteration polyhedron consisting of 51 explicitly defined faces as defined in the CLooG file attached.

bug.cloog.txt

This polyhedron contains 7546 points (confirmed by barvinok). However, the code generated by CLooG runs the perfectly nested statement 7693 times. Upon further investigation, the first 6223 iteration vectors issued are correct, with vector #6223 being [1, 1, 0, 1, 0, -1, 16, 55, 118]. But afterwards, vector #6224, which should be [1, 1, 0, 2, -1, -1, 11, 56, -28], becomes [1,1,0,1,0,0,13,49,147]. Vector #6223 had already reached the 6th-dimension upper bounds (in particular, those defined in rows 13 and 14 of the input matrix) and therefore the generated vector is illegal under the constraints imposed by the original matrix (i.e., M·i < 0 for some elements of the resulting vector).

Sorry if my explanation is not completely descriptive, in which case please let me know if I can provide more details or codes to help with the debugging process.

Syllo commented 6 years ago

Hi Gabriel,

I can not reproduce your described behavior, the code generated on my side does indeed iterate 7546 times and has the right iteration vector at iteration 6224. I get the following code:

for (i=0;i<=1;i++) {
  for (j=ceild(2*i-4,13);j<=floord(-i+18,12);j++) {
    for (k=ceild(-j-1,3);k<=min(floord(3*i+2*j+4,3),floord(-4*i-7*j+15,4));k++) {
      for (l=max(ceild(-k,3),ceild(3*i+4*j+k-6,3));l<=min(min(floord(5*j+2,2),floord(i+j+3*k+2,2)),floord(3*i-4*j-2*k+8,2));l++) {
        for (m=max(max(max(max(-3*i-2*j,-3*i-k),-3*k-1),-4*j-k+l-1),2*i+2*j-2*k-2*l-2);m<=min(min(min(-2*i-k+2,j+k-l+1),-2*i-4*j-4*k-2*l+10),-i-j-k+l+1);m++) {
          for (n=max(max(-2*l,-i-j+l-1),i+3*j+2*k+l-7);n<=min(min(min(min(floord(-12*i-21*j-11*k-11*m+27,11),k+l),3*k-l+1),-i+4*j-l+1),4*i-j-l+1);n++) {
            for (o=max(max(max(0,7*j+6*k+2*l-m-7),12*j+11*k+2*l+4*m-12),11*i+12*j+11*k+3*l+4*m+n-13);o<=min(min(min(min(min(-3*k+24,-2*i+4*l-3*m-n+13),-11*i+12*j+3*l-7*m+n+14),-2*i+11*k+16*l+4*m+2*n+5),10*i+11*k+3*l+4*m+n+5),20*i+18*j+2*k+3*l+4*m+n+1);o++) {
              for (p=28*i+14*j+7*k+7*l;p<=28*i+14*j+7*k+7*l+6;p++) {
                for (q=77*i+49*j-7*k-70*l+35*m+56*n+7*o;q<=77*i+49*j-7*k-70*l+35*m+56*n+7*o+6;q++) {
                  S1(i,j,k,l,m,n,o,p,q);
                }
              }
            }
          }
        }
      }
    }
  }
}

Are you using CLooG altogether with ISL version 0.18 using GMP or another one? Can you please also post the output you get on your side?

harenome commented 6 years ago

Hello,

Neither can I reproduce the aforementioned bug. How did you build or install CLooG (OS, libraries, configure options, etc.) and what CLooG options did you use to generate your code?

If you cloned the git repository, could you also try with the release tarball for version 0.18.5?

$ wget "https://github.com/periscop/cloog/releases/download/cloog-0.18.5/cloog-0.18.5.tar.gz"
$ tar -xf cloog-0.18.5.tar.gz && cd cloog-0.18.5
$ mkdir build && cd build
$ ../configure --with-isl=bundled
$ make -j $(nproc) && make check
$ wget "https://github.com/periscop/cloog/files/1158480/bug.cloog.txt"
$ ./cloog bug.cloog.txt -compilable 1 > a.c
$ cc a.c
$ ./a.out
gabriel-rodriguez commented 6 years ago

Many thanks @Syllo and @Harenome for your replies. The code you posted matches exactly the one which is being generated for me, which led me to discovering that this is not CLooG-related as I initially had thought. I first discovered the bug using PoCC, and I thought I could reproduce it as well using CLooG, hence the report. However, I reused the PoCC-style floord definitions when executing the CLooG-generated loop. I was using:

define floord(x,y) (((x) > 0)? ((x)/(y)): 1 + (((x) -1)/ (y))) //floord as introduced by PoCC

vs

define floord(x,y) (((x) < 0)? -((-(x)+(y)-1)/(y)) : (x)/(y)) //floord as used in CLooG examples

So I guess this might be a bug with PoCC, after all. Sorry for the inconvenience, but many thanks for pointing me in the right direction.