1 / 2

4.2 Blocking

4.2 Blocking. Original Code. Transformed Code. for (jj=0; jj<N; jj = jj+B) for (kk=0; kk<N; kk = kk+B) for (i=0; i<N; i++) for (j=jj; j<min(jj+B,N); j++) {r=0; for(k=kk;j<min(kk+B,N); k++) r = r + y[i][k] * z[k][[j]; x[i][j] = x[i][j] + r; };. for (i=0; i<N; i++)

kalona
Download Presentation

4.2 Blocking

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 4.2 Blocking Original Code Transformed Code for (jj=0; jj<N; jj = jj+B) for (kk=0; kk<N; kk = kk+B) for (i=0; i<N; i++) for (j=jj; j<min(jj+B,N); j++) {r=0; for(k=kk;j<min(kk+B,N); k++) r = r + y[i][k] * z[k][[j]; x[i][j] = x[i][j] + r; }; for (i=0; i<N; i++) for (j=0; j<N; j++) {r=0; for (k=0; k<n; k++) r = r + y[i][k] * z[k][[j]; x[i][j] = r; }; A row in a block One block in a column All blocks in a column All columns of blocks • Restructure the loops to improve • Fit in the cache • Improve temporal locality • Solutions now become machine dependent

  2. 4.2 Blocking (cont.) z[k][j] y[i][k] • What is the miss behavior? • Decompose the computation to operate on BxB blocks such that three blocks fit in the cache • Reduce the overall number of worst case misses by a factor of B Compute the partial product for this block Complete computation of all columns (jj) Compute a row in the block (j and k) Complete computation of Block (0,0) (i) Complete computation of Blocks in a column (kk)

More Related