

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


CS553 Lecture Tiling 2
Announcements
Motivation
Example do i=1,n do i=1,n by 2 A(i) = B(i) + C(i) A(i) = B(i) + C(i) enddo A(i+1) = B(i+1) + C(i+1) enddo Details − When is loop unrolling legal? − Handle end cases with a cloned copy of the loop − Enter this special case if the remaining number of iteration is less than the unrolling factor CS553 Lecture Tiling 5 Problem
− The inner loop has 1 memory operation per iteration and 1 floating point operation per iteration − If our target machine can only support 1 memory operation for every two floating point operations, this loop will be memory bound What can we do? Example do j = 1,2n do i = 1,m A(j) = A(j) + B(i) enddo enddo*
CS553 Lecture Tiling 6 Idea
Example do j = 1,2n do i = 1,m A(j) = A(j) + B(i) enddo enddo Unroll the Outer Loop do j = 1,2n by 2 do i = 1,m A(j) = A(j) + B(i) enddo do i = 1,m A(j+1) = A(j+1) + B(i) enddo enddo** CS553 Lecture Tiling 7 Unroll the Outer Loop do j = 1,2n by 2 do i = 1,m A(j) = A(j) + B(i) enddo do i = 1,m A(j+1) = A(j+1) + B(i) enddo enddo*
Jam the inner loops do j = 1,2n by 2 do i = 1,m A(j) = A(j) + B(i) A(j+1) = A(j+1) + B(i) enddo enddo* − The inner loop has 1 load per iteration and 2 floating point operations per iteration − We reuse the loaded value of B(i) − The Loop Balance matches the machine balance CS553 Lecture Tiling 8 Legality
CS553 Lecture Tiling 9 Original Loop do j = 1,2n do i = 1,m A(j)= A(j) + B(i) enddo enddo*
After Unroll and Jam do jj = 1,2n by 2 do i = 1,m A(j)= A(j)+B(i) A(j+1)= A(j+1)+B(i) enddo enddo After Tiling do jj = 1,2n by 2 do i = 1,m do j = jj, jj+2- A(j)= A(j)+B(i) enddo enddo enddo i j**