Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Locality Analysis and Optimization

Similar presentations


Presentation on theme: "Data Locality Analysis and Optimization"— Presentation transcript:

1 Data Locality Analysis and Optimization
Hua Lin and Wayne Wolf Dept. of Electrical Engineering Princeton University D E I M V S B N G T VET TES EN NOV TAM TVM

2 Improving Data Locality
Background Cache configuration synthesis Measurement of Data Locality Data reuse, reuse distance Conflicts in cache Approaches Loop transformation: reducing the reuse distance Data layout transformation: creating more possible reuse, reducing conflicts in cache Combination of the above two transformations

3 Affine Representation
j for i = 2, n for j = 2, n y[i,j]=0.5*(x[i-1,j-1]+x[i-1,j]) end (1) 4 3 Two-dimension loop nest: 2 N-dimension loop nest: i 2 3 4 5 Locality space: Non-singular loop transformation: T (1)

4 Previous Work Loop transformation Data layout transformation
A sequence of transformations: the sequence Unimodular or non-singular transformation: legal transformation matrix Tiling: efficiency Loop distribution, fusion Data layout transformation Non-singular transformation: skewed layout Padding, tiling and partitioning: the effective range of data resue The combination Innermost loop?

5 Our Work The starting point Other initiatives
Locality space instead of innermost loop Constructing the legal transformation matrix Unified loop and data layout transformation Other initiatives Dimensionality of the locality space and reuse vector space Individual statement instead of loop body as the atomic unit of the iteration space Locality space for arrays

6 Compacting the Reuse Distance with Non-Singular Transformation
For a reuse vector that is not in the locality space, i.e , a non-singular transformation T can be applied s.t. For a set of reuse vectors The dimensionality of the reuse vector space Choosing among reuse vectors: reuse quality, legal transformation The difficulty: legal transformation matrix To capture more reuse Reducing the dimensionality of the reuse vector space Increasing the dimensionality of the locality space

7 Reducing the Dimensionality of the Reuse Vector Space with Loop Alignment
for i = 2, n for j = 2, n x[i,j]=x[i,j] (S1) y[i,j]=0.5*(x[i-1,j-1]+x[i-1,j]) (S2) z[i,j]=x[i,j-1] (S3) end j 4 3 Before loop alignment Spatial reuse (not shown in the figure): [0, 1]: S1S1, [0, 1]: S2S2, [0, 1]: S3S3 Temporal reuse [1, 0]: S1S2, [1, 1]: S1S2, [0, 1]: S1S3 After loop alignment [1, 0]: S2 [0, 0]: S1S2, [0, 1]: S1S2, [0, 1]: S1S3 2 2 3 4 5 i j 4 3 2 1 2 3 4 5 i

8 Reducing the Dimensionality of the Reuse Vector Space with Loop Alignment (cont’)
for i = 1, n for j = 2, n if i=1 then y[2,j]=0.5*(x[1,j-1]+x[1,j]) else if i=n then x[n,j]=x[n,j]-128 z[n,j]=x[n,j-1] else x[i,j]=x[i,j]-128 y[i+1,j]=0.5*(x[i,j-1]+x[i,j]) z[i,j]=x[i,j-1] endif end Minimizing the Dimensionality of the Reuse Vector Space

9 Increasing the Dimensionality of the Locality Space with Loop Tiling
Tiling the innermost loops The dimensionality of the locality space with loop tiling The integrate procedure: Loop alignment  non-singular transformation  tiling

10 More Spatial Reuse with Non-singular Transformation for Array Layout
Locality space for arrays: span( ) span( ) ( ): the last m columns of the reference matrix A (or AT 1 with affine loop transformation T). Let S = span( ): locality space for the array Creating spatial reuse If the fastest changing dimension of an array is not in its locality space, i.e , a non-singular transformation TA can be applied to the array layout s.t. Dimension interchange:

11 In-dimension Stride Vector
In-dimension Stride Vector (ISV) Distance vector between two iterations that access adjacent data within the same dimension of an array Why ISV? Each dimension of the array has its own ISV space If the dimension is switched to be the fastest changing dimension, its ISV’s become the self-spatial reuse vectors Automate the unification of loop transformation and array dimension interchange How to compute ISV:

12 An Example for i = 1, N for j = 1, N for k = 1, N
c(i,j) = c(i,j) + a(i,k)*b(k,j) end ISV spaces: Array c: 1st ISV space: span{(1, 0, 0)}, 2nd ISV space: span{(0, 1, 0)} Array a: 1st ISV space: span{(1, 0, 0)}, 2nd ISV space: span{(0, 0, 1)} Array b: 1st ISV space: span{(0, 0, 1)}, 2nd ISV space: span{(0, 1, 0)} Transformed loop nest: (1) Assuming row major (2) T : (1, 0, 0)  (0, 0, 1) for l = 1, N for m = 1, N for n = 1, N c(m,n) = c(m,n) + a(l,n)*b(m,l)

13 Padding and Tiling with Locality Space
Considering the cache conflicts with locality space Locality space for the array  subspace of array

14 Experimental Result (Matrix Multiplication)
Cfg1: n=128, l=8, a=1, Cfg2: n=128, l=8, a=2 Cfg3: n=256, l=8, a=1, Cfg4: n=256, l=8, a=2 n : number of line sets, l : line size in words a : degree of associativity Figure: Miss rate for Matrix Multiplication

15 Summary Contributions in this work:
The legal loop transformation matrix Locality space instead of innermost loop Locality space for arrays Dimensionality of the locality space and reuse vector space Individual statement instead of loop body as the atomic unit of the iteration space ISV: automating the unification of loop transformation and array dimension interchange

16 Work in Progress More work in quasi-affine transformation
Parallelization with data locality


Download ppt "Data Locality Analysis and Optimization"

Similar presentations


Ads by Google