Op#miza#on of High-Order Stencils* Kevin Stock - - PowerPoint PPT Presentation

op miza on of high order stencils
SMART_READER_LITE
LIVE PREVIEW

Op#miza#on of High-Order Stencils* Kevin Stock - - PowerPoint PPT Presentation

Op#miza#on of High-Order Stencils* Kevin Stock Ohio State University Mar#n Kong Ohio State University Louis-Noel Pouchet


slide-1
SLIDE 1

Op#miza#on ¡of ¡High-­‑Order ¡Stencils*

¡

¡ ¡ ¡ Kevin ¡Stock ¡ ¡ ¡ ¡Ohio ¡State ¡University ¡ Mar#n ¡Kong ¡ ¡ ¡ ¡Ohio ¡State ¡University ¡ Louis-­‑Noel ¡Pouchet ¡ ¡ ¡Ohio ¡State ¡University ¡ Fabrice ¡Rastello ¡ ¡ ¡ ¡INRIA, ¡Grenoble ¡

  • J. ¡(Ram) ¡Ramanujam ¡

¡Louisiana ¡State ¡University ¡ Saday ¡Sadayappan ¡ ¡Ohio ¡State ¡University ¡ * ¡Funded ¡in ¡part ¡by ¡NSF ¡and ¡DOE ¡

slide-2
SLIDE 2

int aFunction(int a, int b) { int c=b; return a; } main() { int a,b,c,d,e; int i=4; for (i=0;i<10;i++) { int j=55; c=i+j; c=aFunction(i,c); a=aFunction(a+1,b); } #pragma SliceTarget a; return 0; }

0% ¡ 20% ¡ 40% ¡ 60% ¡ 80% ¡ 100% ¡ 1 ¡ 4 ¡ 8 ¡12 ¡16 ¡

DSL Technology for Exascale Computing (D-TEC)

Lead ¡PI ¡ ¡ Daniel ¡J. ¡Quinlan ¡ Lawrence ¡Livermore ¡NaGonal ¡Laboratory ¡

Co-­‑PIs ¡and ¡InsGtuGons ¡ Armando ¡Solar-­‑Lezama, ¡Adam ¡Chlipala, ¡Srinivas ¡Devadas, ¡ ¡ Una-­‑May ¡O’Reilly, ¡Nir ¡Shavit, ¡Youssef ¡Marzouk ¡@ ¡MassachuseWs ¡InsGtute ¡of ¡Technology ¡ John ¡Mellor-­‑Crummey ¡& ¡Vivek ¡Sarkar ¡@ ¡Rice ¡University ¡ Vijay ¡Saraswat ¡& ¡David ¡Grove ¡@ ¡IBM ¡Watson ¡

  • P. ¡Sadayappan ¡& ¡Atanas ¡Rountev ¡@ ¡Ohio ¡State ¡University ¡

Ras ¡Bodik ¡@ ¡University ¡of ¡California ¡at ¡Berkeley ¡ Craig ¡Rasmussen ¡@ ¡University ¡of ¡Oregon ¡ Phil ¡Colella ¡@ ¡Lawrence ¡Berkeley ¡NaGonal ¡Laboratory ¡ ScoW ¡Baden ¡@ ¡University ¡of ¡California ¡at ¡San ¡Diego ¡

Deputy ¡PI ¡ Saman ¡Amarasinghe ¡ MIT ¡

slide-3
SLIDE 3
  • Stencil ¡computaGons ¡sweep ¡
  • ver ¡a ¡regular ¡mulG-­‑

dimensional ¡array ¡

  • ComputaGon ¡for ¡each ¡element ¡
  • f ¡result ¡array ¡A ¡uses ¡a ¡fixed ¡

set ¡of ¡neighboring ¡elements ¡ from ¡input ¡array ¡B ¡

  • Ample ¡inherent ¡parallelism, ¡

but ¡performance ¡is ¡oben ¡far ¡ below ¡processor’s ¡peak: ¡ without ¡temporal ¡blocking, ¡ limited ¡by ¡memory ¡bandwidth ¡ ¡

Stencil Example

for (i=1; i<N-1; i++) for (j=1;j<N-1; j++) A[i][j] = c*(B[i][j-1] + B[i][j] + B[i][j+1] + B[i-1][j] + B[i+1][j]);

slide-4
SLIDE 4
  • High-­‑order ¡stencils: ¡

weighted ¡averaging ¡over ¡ wider ¡neighborhood ¡

  • “Box”wxw ¡stencil ¡=> ¡O(w2) ¡

flops ¡per ¡site ¡(w=2*k+1) ¡

  • OperaGonal ¡intensity: ¡O(w2) ¡ ¡

¡

Optimizing High-Order Stencils

for (i=k; i<n-k; i++) for (j=k; j<n-k; j++) // ii,jj loops fully unrolled for (ii=-k; ii<=k; ii++) for (jj=-k; jj<=k; jj++) B[i][j] += W[k+ii][k+jj]*A[i+ii][j+jj];

k=1, ¡w=2k+1 ¡= ¡3 ¡ K=2, ¡w=2k+1 ¡= ¡5 ¡

slide-5
SLIDE 5
  • MulG-­‑core ¡performance ¡

improves ¡from ¡3x3 ¡to ¡5x5 ¡ stencil ¡but ¡drops ¡for ¡higher ¡

  • rder ¡stencils ¡
  • Problem: ¡ ¡

– Not ¡memory-­‑bw ¡bound ¡ – But ¡too ¡many ¡register ¡ loads ¡due ¡to ¡insufficient ¡ registers ¡to ¡get ¡reuse ¡

¡

High-Order Stencils: Baseline Performance

1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 GFLOP/s k base 0.1 0.2 0.3 0.4 0.5 0.6 0.7 1 2 3 4 5 6 Memory Ops / FLOP k base-loads base-stores

for (i=k; i<n-k; i++) for (j=k; j<n-k; j++) // ii,jj loops fully unrolled for (ii=-k; ii<=k; ii++) for (jj=-k; jj<=k; jj++) B[i][j] += W[k+ii][k+jj]*A[i+ii][j+jj];

slide-6
SLIDE 6

Standard Gather-Gather Stencil

w reads from IN 0 reads from OUT 1 write to OUT w 2 − w + 1 registers

Six points reused between iterations

Sweep ¡Direc#on ¡ (innermost ¡loop) ¡

slide-7
SLIDE 7
  • wxw ¡“box” ¡stencil ¡

computaGon ¡over ¡MxN ¡ domain ¡viewed ¡as ¡a ¡total ¡of ¡ w2MN ¡edges ¡

  • Standard ¡stencil ¡execuGon ¡

groups ¡all ¡edges ¡incoming ¡ into ¡a ¡site ¡for ¡consecuGve ¡ execuGon ¡

  • Regrouping ¡of ¡edges ¡forms ¡a ¡

different ¡“stencil” ¡paWern, ¡ with ¡different ¡#loads/stores ¡ and ¡register ¡pressure ¡ ¡ ¡

Reordering Stencil Operations

slide-8
SLIDE 8

Gather-Scatter

1 reads from IN w − 1 reads from OUT w write to OUT w + 1 registers

slide-9
SLIDE 9

Scatter-Gather

w reads from IN 0 reads from OUT 1 write to OUT w + 1 registers

slide-10
SLIDE 10

Performance: Core i7-4770K (4 cores)

slide-11
SLIDE 11

Stencils on Vector-SIMD Processors

  • Fundamental ¡source ¡of ¡

inefficiency ¡with ¡stencil ¡codes ¡

  • n ¡current ¡short-­‑vector ¡SIMD ¡

ISAs ¡(e.g. ¡SSE, ¡AVX ¡…) ¡

– Concurrent ¡operaGons ¡on ¡ conGguous ¡elements ¡ – Each ¡data ¡element ¡is ¡reused ¡in ¡ different ¡“slots” ¡of ¡vector ¡ register ¡ – Redundant ¡loads ¡or ¡shuffle ¡ops ¡ needed ¡

  • Data ¡Layout ¡transforma#on ¡

based ¡on ¡matching ¡ computa#onal ¡characteris#cs ¡of ¡ stencils ¡ ¡to ¡vector-­‑SIMD ¡ architecture ¡characteris#cs ¡

¡

for ¡(i=0; ¡i<H; ¡++i) ¡ ¡ ¡for ¡(j=0; ¡j<W; ¡++j) ¡ ¡ ¡ ¡z[i][j]+=y[i][j]+y[i][j+1]; ¡

a ¡ b ¡ c ¡ d ¡ m ¡ n ¡

  • ¡

p ¡ n ¡

  • ¡

p ¡ q ¡ a ¡ b ¡ c ¡ d ¡ e ¡ f ¡ g ¡ h ¡ i ¡ j ¡ k ¡ l ¡ m ¡ n ¡

  • ¡

p ¡ q ¡ r ¡ s ¡ t ¡ u ¡ v ¡ w ¡ x ¡

Inefficiency: ¡Each ¡element ¡of ¡b ¡is ¡loaded ¡twice ¡

Data ¡in ¡memory ¡ Vector ¡registers ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡

VR0 ¡ VR1 ¡ VR2 ¡ VR3 ¡ VR4 ¡

z[i][j] ¡ ¡ y[i][j] ¡ ¡

slide-12
SLIDE 12

Data Layout Transformation

(a) 1D ¡vector ¡in ¡memory ¡ó ¡(b) ¡2D ¡logical ¡view ¡of ¡same ¡data ¡ (c) ¡Transposed ¡2D ¡array ¡moves ¡interacGng ¡elements ¡into ¡same ¡slot ¡of ¡ different ¡vectors ¡ ¡ó ¡ ¡(d) ¡New ¡1D ¡layout ¡aber ¡transformaGon ¡

  • Boundaries need special handling (details in CC 2011 paper)

for (j = 1; j < W-1; ++j) z[j] = y[j-1] + y[j] + y[j+1];

y[0:23] ¡ yt[0:23] ¡

slide-13
SLIDE 13

Performance: Stencil Rate

slide-14
SLIDE 14

Summary

  • High-­‑order ¡stencils ¡have ¡high ¡operaGonal ¡

intensity: ¡not ¡limited ¡by ¡memory ¡bw, ¡but ¡face ¡a ¡ different ¡challenge: ¡excessive ¡register ¡loads ¡

  • SoluGon ¡via ¡associaGve ¡reordering ¡of ¡

accumulaGon ¡operaGons ¡to ¡change ¡“stencil” ¡ paWern ¡

  • Details ¡in ¡PLDI’14 ¡paper ¡
  • Ongoing/Future ¡Work ¡

– IncorporaGon ¡into ¡DSL ¡for ¡AMRShib ¡Calculus ¡(Collela) ¡