CS 560 Colorado State University ======================================================== Automating Polyhedral Transformations: omega ======================================================== 2/21/12 references @inproceedings{Kelly95, Address = {London, UK}, Author = {Wayne Kelly and William Pugh}, Booktitle = {Proceedings of the 7th International Workshop on Languages and Compilers for Parallel Computing}, Pages = {107--124}, Publisher = {Springer-Verlag}, Title = {Finding Legal Reordering Transformations using Mappings}, Volume = {892}, Year = {1995}} @techreport{frameworkKP95, Author = {Wayne Kelly and William Pugh}, Institution = {University of Maryland, College Park}, Month = {February}, Number = {CS-TR-3430}, Title = {A Unifying Framework for Iteration Reordering Transformations}, Type = {Technical Report}, Year = {1995}} @techreport{Wonnacott10, Author = {David G. Wonnacott}, Institution = {Haverford College Computer Science Tech Report 2010-01}, Month = {June}, Title = {A Retrospective of the Omega Project}, Year = {2010}} @misc{omegaCalc, Author = {Wayne Kelly and Vadim Maslov and William Pugh and Evan Rosser and Tatiana Shpeisman and Dave Wonnacott}, Month = {November}, Title = {The Omega Calculator and Library, version 1.1.0}, Year = {1996}} -------------------- Outline Some Omega history - group that started it - research goals - how it is still being used (basis for Chill) Downloading and installing omega Petit Omega syntax Using omega for dependence analysis Omega example with transformations and code generation Using Omega to debug purple dragon book issue ================================ Some Omega history - Developed in the 90s by Bill Pugh's group at University of Maryland. - The main algorithm is the omega test, which can check the satisfiability of Z-polyhedra. - Its popularity is due to the petit tool, omega calculator tool, and the omega library itself being put in the public domain. - Now maintained by Dave Wonnacott at Haverford. - Is the basis for CHILL tool being developed at the University of Utah. ================================ Downloading and Installing Omega Omega can be found at https://github.com/davewathaverford/the-omega-project/. To get a clone, do the following: git clone git://github.com/davewathaverford/the-omega-project The README and INSTALL files are somewhat out-of-date but still worth reading. To build on the CS linux machines type: make depend make oc make petit The above commands create the petit and oc executables in the petit/obj/ and oc/obj/ subdirectories. I recommend creating a different subdirectory at the same level as the-omega-project/ called omegaWork/ and copying the executables into that subdirectory. cd .. svn mkdir omegaWork cp the-omega-project/petit/obj/petit omegaWork/ cp the-omega-project/omega_calc/obj/oc omegaWork/ ================================ petit petit is a tool that uses the omega library to do dependence analysis for a language that is a subset of Fortran. The manual for petit is entitled "The New User Interface for Petit and Other Extensions" and it can be found in the the-omega-project/petit/doc/petit.ps file. There are many command line options described in this file that can be used in the batch mode use of petit. Computing the dependences for the input file: ./petit -b deptest.t !!!!!!!!!!! deptest.t integer iter,i,j,n,R real b(0:99,0:99),a(0:99) for i=0,(R-1) do for j=0,(R-1) do a(i) = a(i-1) endfor endfor for i=(4-1),(R-1) do a(i) = a(4*i-1) endfor !!!!!!!!!!!!!!!!!!!!!! anti 8: a(i-1) --> 13: a(i) [ MZ] {[i,j] -> [i-1] : 4 <= i < R && 0 <= j < R} exact dd: {[-1]} flow 8: a(i) --> 8: a(i-1) (1,0-) [ VO] {[i,R-1] -> [i+1,j'] : 0 <= i <= R-2 && 0 <= j' < R} may dd: {[1,In_2]: In_2 <= 0} ================================ omega calculator Enables the manipulation of sets and relations. # declare symbolic constants symbolic N,M; # define a set S := { [i,j] : 0 <= i <= N && 3 <= j <= M }; # print out a set S; # define a relation T := { [i,j] -> [i',j'] : i' = j && j'=i }; T; # Apply a relation/transformation to a set T(S); # generate code codegen S; codegen T(S); codegen T:S; /**************** * Compiling and executing the resulting code as C code ****************/ #include // need a statement macro for each statement #define s1(i,j) A[(i)][(j)] = A[(i)][(j)-2]; #define N 10 #define M 10 int A[N+1][M+1]; int main() { // initializing the input array int i; for (i=0; i<=N; i++) { A[i][0] = 42; A[i][1] = 7; A[i][2] = 13; } // the code generated by omega int t1, t2; if (N >= 0) { for(t1 = 3; t1 <= M; t1++) { for(t2 = 0; t2 <= N; t2++) { s1(t2,t1); } } } // the results of the computation int j; for (i=0; i<=N; i++) { printf("\n"); for (j=0; j<=M; j++) { printf("%d\t", A[i][j]); } } } ================================ other omega operations # compose two relations R1 := { [i,j] -> [j] }; R2 := { [x,y] -> [x+1,y+2] }; R1 compose R2; R1 ( R2 ); inverse R2; # projecting a variable out of a set Sxy := {[y,x] : x <= y <= N && 1 <= x <= M }; R2 := {[i,j] -> [i]}; R2( Sxy ); # set and relation intersection S1 := { [i,j] : 0 <= i <= N && 3 <= j <= M }; S2 := {[x,y] : x <= y <= N && 1 <= x <= M }; S1 intersection S2; T := { [i,j] -> [i',j'] : i' = i && j'=j }; R2 := { [x,y] -> [x+1,y+2] }; T intersection R2; # set and relation union S1 union S2; T union R2; ================================ Setting up a data dependence problem in omega For example usage, let's set up some of the dependence problems for deptest.t. !!!!!!!!!!! deptest.t integer iter,i,j,n,R real b(0:99,0:99),a(0:99) for i=0,(R-1) do for j=0,(R-1) do a(i) = a(i-1) endfor endfor for i=(4-1),(R-1) do a(i) = a(4*i-1) endfor !!!!!!!!!!!!!!!!!!!!!! First the flow dependence between the write to a(i) and the read to a(i-1). # declare symbolic constants symbolic R; # specify dependence relation D_S1_to_S1_flow := { [i,j] -> [i',j'] : # equality constraint(s) i = i'-1 # loop bounds && 0 <= i,i',j,j' <= (R-1) # precedence constraints && ( (i [i',j'] : # equality constraint(s) i = i'-1 # loop bounds && 0 <= i,i',j,j' <= (R-1) # precedence constraints && ( (i [i+1,j'] : 0 <= i <= R-2 && 0 <= j' < R} ================================ Performing Transformations and Generating Code in Omega The fusion example from pg. 848 in the dragon book. http://dragonbook.stanford.edu/ for (i=1; i<=N; i++) { Y[i] = Z[i]; /* s1 */ } for (j=1; j<=N; j++) { X[j] = Z[j]; /* s2 */ } S1 := {[0,i,0] : 1<=i<=N }; S2 := {[1,j,0] : 1<=j<=N }; T := {[0,i,0] -> [0,i,0]} union {[1,j,0] -> [0,j,1]}; codegen T:S1, T:S2; --> Do a perfectly nested loop example. ================================ Using the omega calculator to debug a textbook --> Do the skewing example on the handout. ============== Report sent to authors On page 849, the Skewing example has incorrect bounds for the original loop, the constants in the affine transform need to be switched, and the array access functions in the transformed code are incorrect. The source code should be for (i=1; i<=N+M-1; i++) for (j=max(1,i-N+1); j<=min(i,M); j++ ) // Notice the change in the j lower bound. ... Also, the partition should be p = i - j + 1 q = j The array access functions for the transformed code were incorrect with the incorrect partition function. For the new partition functions above, they should be as follows (note that j=q and i=p+q-1: Z[p+q-1,p] = Z[p+q-2,q-1] Note that when I use the new lower bound for j and the new affine partition, I am able to get the desired loop bounds in the resulting code. # Omega Calculator v1.2 (based on Omega Library 1.2, August, 2000): # symbolic N, M; # # # D := {[p,q,i,j] : 1 <= i <= N+M-1 && 1 <= j && j <= i && # i-N+1 <= j && j <= M && p=i-j + 1 && q=j}; # # D; {[p,q,p+q-1,q]: 1 <= p <= N && 1 <= q <= M} # # # codegen D; if (M >= 1) { for(t1 = 1; t1 <= N; t1++) { for(t2 = 1; t2 <= M; t2++) { s1(t1,t2,t1+t2-1,t2); } } } Using the bounds provided in the book with the affine partition in the book, the bounds for p and q are quite different than those shown in the transformed code in the book. # D := {[p,q,i,j] : 1 <= i <= N+M-1 && i+N <= j && j <= i && 1 <= j && j <= M # && p = i-j && q = j+1 }; # # D; {[p,q,p+q-1,q-1]: 0 <= p < M && 2 <= q <= M+1 && p+q <= M+N} ================================ Handy little C program to build intuition #include #define N 3 #define M 2 #define max(x,y) ((x)<(y)?(y):(x)) #define min(x,y) ((x)<(y)?(x):(y)) int main() { int i, j; for (i=1; i<=N+M-1; i++) { printf("i = %d, max(1,i-N+1)=%d, min(i,M)=%d\n", i,max(1,i-N+1),min(i,M) ); for (j=max(1,i-N+1); j<=min(i,M); j++) { printf("(%d, %d)\n", i,j); } printf("\n"); } return 0; } ------------------------ mstrout@cs.colostate.edu, 2/21/12