Module 18: Loop Optimizations
  Lecture 36: Cycle Shrinking
 


Loop Tiling

  • Similar to strip mining (Strip mining works for single loops)
  • Loop tiling is used for nested loops
  • Tiling boundaries are parallel to the iteration space axes and not to iteration space boundaries
  • The eventual goal is to interchange tile loops outward and element loops inward
  • Tiling is characterized by tile size ts and a tile offset to (0 ≤ to < ts)
  • Each tile starts an iteration i such that i mod ts = to
  • Each tile iterates from tn-ts+to to (tn+1)-ts+to-1 where tn is tile number
  • The compiler must determine the minimum and maximum tile numbers
  • The compiler must ensure that element loop does not execute outside its original iteration space
  • The general formula for tiling for a loop such as
    for I = lo, hi
    is
    for it = floor((lo-to)/ts)*ts+to, floor((hi-to)/ts)*ts+to, ts
    for I = max(lo,it), min(hi,it+ts-1)
Tile following loops with a tile
size of 20 and an offset of 5
For I = 1, 50
for j = i, 60
A[I,j] = A[I,j]+1
endfor
endfor

just applying the formula produces following loop
For It = -15, 45, 20
for i = max(1,it), min(50,it+19)
for jt=floor((i-5)/20)*20+5, 45, 20
for j=max(I,jt), min(60, jt+19)
A[I,j] = A[I,j]+1
endfor
endfor
endfor
endfor

The Tiled Iteration Space