61
Approaches and Tools for Understanding and Improving the Performance of Scientific Applications

Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Embed Size (px)

Citation preview

Page 1: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Approaches and Tools for Understanding and Improving the Performance of Scientific Applications

Page 2: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Acknowledgments

  Funding:–  DOEScien0ficDiscoverythroughAdvancedCompu0ng(SciDAC)

program

–  Na0onalScienceFounda0on–  Tech‐XCorpora0on

  Collaborators:–  Dr.S.H.K.NarayananandP.Hovland,ArgonneNa0onalLaboratory–  Dr.AlbertHartono,ReservoirLabs–  Prof.P.(Saday)Sadayappan,OhioStateUniversity–  Prof.WilliamGropp,UniversityofIllinoisatUrbana‐Champaign

–  Prof.ElizabethJessupandProf.JeremySiek,UniversityofColoradoatBoulder

2

Page 3: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Outline

  Mo0va0on

  PartI:Understandingperformance–  Genera0ngperformancemodelsfromsourcecode

  PartII:Automa0callyop0mizingperformance–  SimpleExample

–  Approach:Annota0on‐drivenempiricaltuning

–  PerformanceExperiments

  Summary

3

Page 4: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

At t = 1 At t = 3

Application examples

4

Page 5: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Part I: Understanding performance

  Threemainapproachestoanalyzingperformance:–  Empirical

–  Sta0c(sourceorobjectcode‐based)–  Analy0cal

  Inthistalk:–  Focusonahybridsta0c/empiricalapproachforgenera0ng

performancemodelsofcomputa0onalkernels

–  Es0mateupperperformancebounds

5

Page 6: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

6 6

What are performance bounds?  Performanceboundsgivetheupperlimitinperformancethatcanbeexpectedforagivenapplica0ononagivensystem

 Currentapproaches:–  Fullyalgorithmic

•  Ignores machine information –  Theore0calpeakofthemachine

•  Based only on available floating point units –  Fullydynamicwithprofiling

•  Profiling overheads, time consuming

 Ourapproach–  Applica0onsignatures+ArchitecturalInforma0on=>Bounds

Page 7: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

7 7

How does this help us?

 Determinestheefficiencyoftheapplica0on–  Efficiency=ObservedPerformance/PerformanceBound

 Providesinsightonhowtoimproveperformance–  Lowefficiency:

•  Re‐engineer/tunetheimplementa0on

–  Highefficiencybutlowperformance:•  Change algorithm or architecture

Page 8: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

8 8

Related work

 Gropp,Kaushiketal.–  Providedthemo0va0onforthiswork–  Determinedtheperformanceboundbycoun0ngthenumberof

arithme0copera0onsandmemoryaccessesperstatement.–  Performedtheanalysisonarepresenta0onofthesourcecode

 Vuducetal.–  Manualboundses0ma0onforsparseATAxcomputa0onkernel

Page 9: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

9 9

Related work : Roofline model

 Showsthe‘region’ofpossibleapplica0onperformance

 Determineshowop0miza0onsaffectapplica0onperformance

 Theperformancespaceisdeterminedthroughrun0memeans.

Source : S. Williams, A. Waterman and D. Patterson CACM 2009

Page 10: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

10 10

So what is PBound?

 Ourtooltogenerateperformanceboundsfromsourcecode

 Usessta0c(sourcecode)analysis–  Producesparameterizedclosed‐formexpressionsexpressingthe

computa0onalanddataload/storerequirementsofapplica0onkernels.

 Coupledwitharchitecturalinforma0on–  Producesupperboundsontheperformanceoftheapplica0on

Page 11: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

11 11

Pbound implementation

 BuiltontopoftheROSECompilerFrameworkfromLLNL

 hep://www.rosecompiler.org

Page 12: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

12 12

AST Representation void axpy4(int n, double *y, double a1, double *x1, double a2,

double *x2, double a3, double *x3, double a4, double *x4) { register int i; for (i=0; i<=n-1; i++) y[i]=y[i]+a1*x1[i]+a2*x2[i]+a3*x3[i]+a4*x4[i]; }

axpy4

Body

ForLoopStatement

i=0 i<N i++ Assignment Stmt

Page 13: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

13 13

Assignment Stmt

[ ]

x1 i

A Closer Look at the AST

Page 14: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

14 14

Assignment Stmt

*

[ ]

x1 i

a1

A Closer Look at the AST

Page 15: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

15 15

Assignment Stmt

[ ]

y i

*

[ ]

x1 i

a1

A Closer Look at the AST

Page 16: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

16 16

Assignment Stmt

+

[ ]

y i

*

[ ]

x1 i

a1

A Closer Look at the AST

Page 17: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

17 17

Assignment Stmt

+ +

[ ]

y i

*

[ ]

x1 i

a1

*

[ ]

x2 i

a2

A Closer Look at the AST

Page 18: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

18 18

Assignment Stmt

+

+ +

+

[ ]

y i

*

[ ]

x1 i

a1

*

[ ]

x2 i

a2

*

[ ]

x3 i

a3

*

[ ]

x4 i

a4

[ ]

y i

A Closer Look at the AST

Page 19: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

19 19

Assignment Stmt

+

+ +

+

[ ]

y i

*

[ ]

x1 i

a1

*

[ ]

x2 i

a2

*

[ ]

x3 i

a3

*

[ ]

x4 i

a4

[ ]

y i

=

A Closer Look at the AST

Page 20: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

20 20

Assignment Stmt

+

+ +

+

[ ]

y i

*

[ ]

x1 i

a1

*

[ ]

x2 i

a2

*

[ ]

x3 i

a3

*

[ ]

x4 i

a4

[ ]

y i

=

LOAD

LOAD LOAD LOAD

LOAD

STORE

5 LOADs, 1 STORE, 8FLOPs

Counting Operations (1/2)

Page 21: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

21 21

Counting Operations (2/2)

axpy4

Body

ForLoopStatement

i=0 i<N i++ Assignment Stmt 5 LOADs, 1 STORE, 8 FLOPs N iterations

5N LOADs, N STOREs, 8N FLOPs

Page 22: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

22 22

Generated output void axpy4(int n, double *y, double a1, double *x1, double a2, double *x2, double a3, double *x3, double a4, double *x4) {

register int i; for (i=0; i<=n-1; i++) y[i]=y[i]+a1*x1[i]+a2*x2[i]+a3*x3[i]+a4*x4[i]; }

#include "pbound_list.h” void axpy4(int n, double *y, double a1, double *x1, double a2, double *x2, double a3, double *x3, double a4, double *x4){

#ifdef pbound_log pboundLogInsert("axpy.c@6@5",8,0,40 * ((n - 1) + 1) + 32, 8 * ((n - 1) + 1),3 * ((n - 1) + 1) + 1,4 * ((n - 1) + 1));

#endif }

Page 23: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

23

Architecture details

23

  SIMD–  Specifyvectorlength–  Requirements

•  Typesofallopera0onsinvolvedmustbethesame

•  Alignmentofallvaluesmustbethesame

•  Loopincrement/decrementmustbe1

  FusedOpera0ons–  fp_mul_add

–  fp_mul_sub–  fp_div_add–  fp_div_sub

Page 24: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

24 24

Example: Xeon Loads Stores

FLOPs  TuningandAnalysisU0li0esfromUOregonusedforprofiling

 Barsshowra0oofobservedvaluetopredictedvalue

Page 25: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

25 25

Example: BG/P Loads Stores

FLOPs  UsedtheHardwarePerformanceMonitorToolkit

Page 26: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

26 26

Using the data - Generating Performance Bound

UpperBound = N *Pm N‐Ra0oofFLOPstoBytesasdeterminedbyPBound

 Pm‐PeakReadsBandwidthdeterminedbyLMBenchN (FLOPs/Byte)

UB GFLOP/s

UB/Pc

Axpy 1.60 6.01 53.70%

STREAM 1.00 3.76 33.56%

SPMV 0.67 2.51 22.38%

Page 27: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

27 27

Using the data: Predicting wallclock time  Expected0mebasedonpeakFLOPcounts

=4FLOPs/cycle*2.8*1e9cycles/second

Ratio of Predicted time vs. Measured Time

Page 28: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

28 28

Using the data – Predicting wallclock time  ModelsassumethatallthedataispresentinL1cache,L2cache,L3cache,mainmemory

 Applica0onsweredeterminedtobememoryboundbyPboundandLMBench–  Thedegreeofaffectstheresult

Page 29: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

29

Ongoing Work - Aggressive Slicing

  UseAliasAnalysistodetermineunique/non‐uniquememoryaccesses.

  Usedataflowanalysestodeterminestatementsneededforpar0culartargetstatements.

  Removeallotherstatements.

29

Page 30: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

30

Ongoing work: Reuse distance analysis

  Basedones0ma0ngcachereusedistance

  Therearetwoapproachescurrently–  Tracebased–  Sta0canalysisbased

  OurApproach–  Sta0cAnalysisbasedapproachbuttakesadvantageofonesliced

execu0on.30

Page 31: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

31

Ongoing work: Analyzing parallel (MPI) codes

  Goal:Communica0onmatrixtocontainparametrizedexpressionsofbytesofdatasentfromoneprocesstoanother.

  Ini0allywanttosupportpoint‐to‐pointcommunica0on

  Approach–  Calculatecountsofdifferentcontrolflowpaths.–  Generateparametrizedexpressions.

–  Sliceawaystatementsnotaffec0ngexpressions.

–  Runslicedcode‐doesnotactuallyperformanycommunica0on.

31

Page 32: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Part II: Optimizing performance

Challenges:

  Abstrac0onsprovidedbyHPCprogramminglanguagesorenvironmentsarenotcloseenoughtothescien0st–  Desireforhighlevelsofabstrac0onandhighperformance–  Successoflibrariesthatofferdomain‐specificabstrac0ons–  Datastructures

  Lackofperformanceportability–  Tuningforapar0culararchitecturepoten0allyhindersperformanceon

differentarchitectures

  Compilerop0miza0onsinsufficient–  Compilerlagfornewarchitectures–  Lossofinforma0onwhenusinggeneral‐purposelanguages

  Highperformanceooenmeansdecreaseddeveloperproduc0vity32

Page 33: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

  Howdoweachievegoodperformanceondifferentarchitectureswithoutsacrificingportability,readability,andmaintainabilityofsooware?

One answer: Use a simpler language (restricted or domain-specific), e.g., simplified C or MATLAB, and figure out how to optimize its performance.

Page 34: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Numerical Kernel Examples

  Forexample,densematrix‐matrixproduct(DGEMM)–  Examplecodefrom“SuperscalarGEMM‐basedLevel3BLAS”,Gustavsonetal.

(nextslide)

  BLAS‐likeopera0onsforwhichtherearenovendor‐op0mizedlibraries–  JacobianandHessianaccumula0oncodeinAD‐generatedderiva0ve

computa0ons–  Tensorproducts–  Composedlinearalgebraopera0ons,e.g.,y = a(Ax) + b(Bx) whereaandb

arescalarvariables,xandyarecolumnvectors,andAandBarematrices

  PETSccodeforsparsematrixopera0ons–  Manualop0miza0onsIncludeunrollinganduseofregisters–  Codefordiagonalmatrixformatisfastoncache‐basedsystemsbutslowon

vectorsystems•  Toomuchcodetorewritebyhandfornewarchitectures

34

Page 35: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

A Fast DGEMM (Sample)

35

Why not just

do i=1,n

do j=1,m

c(i,j) = 0

do k=1,p

c(i,j) = c(i,j) + a(i,k)*b(k,j)

enddo

enddo

enddo

Or even

C = A * B

Page 36: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Our Approach: Annotation-Based Performance Tuning

  Meta‐languageforexpressing–  Seman0cinforma0on

–  Performancetuningop0ons

  Exploit(domain‐specific)knowledge;alleviatecostsassociatedwithgenerality

36

Page 37: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Example void axpy_4(int n, double *y, double a1, double *x1, double a2, double *x2, double a3, double *x3, double a4, double *x4)

{

int i;

for (i = 0; i < n; i++) y[i] = y[i] + a1*x1[i] + a2*x2[i] + a3*x3[i] + a4*x4[i];

}

37

Page 38: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Example void axpy_4(int n, double *y, double a1, double *x1, double a2, double *x2, double a3, double *x3, double a4, double *x4)

{ /*@ begin PerfTuning( import spec axpy4_tune_spec; ) @*/ int i; /*@ begin Align (x1[],x2[],x3[],x4[],y[]) @*/

for (i = 0; i < n; i++) y[i] = y[i] + a1*x1[i] + a2*x2[i] + a3*x3[i] + a4*x4[i];

/*@ end @*/ }

38

Page 39: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Example void axpy_4(int n, double *y, double a1, double *x1, double a2, double *x2, double a3, double *x3, double a4, double *x4)

{ /*@ begin PerfTuning( import spec axpy4_tune_spec; ) @*/ int i; /*@ begin Align (x1[],x2[],x3[],x4[],y[]) @*/ /*@ begin Loop ( transform Unroll(ufactor=UF, parallize=PAR, simd=SIMD_TYPE) for (i=0; I <= N-1 ; i++) y[i] = y[i] + a1*x1[i] + a2*x2[i] + a3*x3[i] + a4*x4[i];

) @*/ for (i = 0; i < n; i++) y[i] = y[i] + a1*x1[i] + a2*x2[i] + a3*x3[i] + a4*x4[i]; /*@ end @*/ /*@ end @*/ }

39

Page 40: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Example (cont.) spec axpy4_tune_spec { def build { arg build_command = 'mpixlc_r -O3 -qstrict -qhot -qsmp=omp:noauto'; arg batch_command = 'qsub -n 128 -t 20 --env "OMP_NUM_THREADS=4"'; arg status_command = 'qstat'; arg num_procs = 128; } def performance_counter { arg method = 'basic timer'; arg repetitions = 10000; } def performance_params { param UF[] = range(1,33); param PAR[] = [True,False]; param SIMD_TYPE[] = ['none','xlc']; constraint simd_unroll_factor = (SIMD_TYPE=='none'

or UNROLL_FAC_IN%2==0); } def input_params {

param N[] = [10,100,1000,10**4,10**5, 10**6,10**7]; } 40

def input_vars { decl dynamic double y[N] = 0; decl dynamic double x1[N] = random;

decl double a1 = random; decl double a2 = random; # ... omitted ... } def search { arg algorithm = 'Exhaustive'; arg time_limit = 20; } }

Page 41: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Generated Code Fragment (full code > 100 lines)

41

for ((i = 0); (i <= (n - 1) - 3); (i += 4)) {

{

double _Complex _i_541, _i_542, _i_543, _i_544, _i_545, _i_555, _i_556, _i_664, _i_665;

_i_541 = __lfpd(&y[i]);

_i_542 = __lfpd(&x4[i]);

_i_543 = __fxcpmadd(_i_541, _i_542, a4);

_i_544 = __lfpd(&x3[i]);

_i_545 = __fxcpmadd(_i_543, _i_544, a3);

_i_555 = __lfpd(&x2[i]);

_i_556 = __fxcpmadd(_i_545, _i_555, a2);

_i_664 = __lfpd(&x1[i]);

_i_665 = __fxcpmadd(_i_556, _i_664, a1);

__stfpd(&y[i], _i_665);

}

{

double _Complex _i_541, _i_542, _i_543, _i_544, _i_545, _i_555, _i_556, _i_664, _i_665;

_i_541 = __lfpd(&y[(i + 2)]);

_i_542 = __lfpd(&x4[(i + 2)]);

_i_543 = __fxcpmadd(_i_541, _i_542, a4);

_i_544 = __lfpd(&x3[(i + 2)]);

_i_545 = __fxcpmadd(_i_543, _i_544, a3);

_i_555 = __lfpd(&x2[(i + 2)]);

_i_556 = __fxcpmadd(_i_545, _i_555, a2);

_i_664 = __lfpd(&x1[(i + 2)]);

_i_665 = __fxcpmadd(_i_556, _i_664, a1);

__stfpd(&y[(i + 2)], _i_665);

}

}

Page 42: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

More Complex Annotation Example (Matrix-Matrix Product)

/*@ begin Loop( transform Composite( tile = [('i',T1_I,'ii'),('j',T1_J,'jj'),('k',T1_K,'kk'), (('ii','i'),T2_I,'iii'),(('jj','j'),T2_J,'jjj'),(('kk','k'),T2_K,'kkk')], permut = [PERMUTS], arrcopy = [(ACOPY_A,'A[i][k]',[(T1_I if T1_I>1 else T2_I),(T1_K if T1_K>1 else T2_K)],'_copy'), (ACOPY_B,'B[k][j]',[(T1_K if T1_K>1 else T2_K),(T1_J if T1_J>1 else T2_J)],'_copy'), (ACOPY_C,'C[i][j]',[(T1_I if T1_I>1 else T2_I),(T1_J if T1_J>1 else T2_J)],'_copy')], unrolljam = [('k',U_K),('j',U_J),('i',U_I)], scalarreplace = (SCREP, 'double', 'scv_'), vector = (VEC, ['ivdep','vector always']), openmp = (OMP, 'omp parallel for private(iii,jjj,kkk,ii,jj,kk,i,j,k,A_copy,B_copy,C_copy)') )

for(i=0; i<=M-1; i++) for(j=0; j<=N-1; j++) for(k=0; k<=K-1; k++) C[i][j] = C[i][j] + A[i][k] * B[k][j];

) @*/ 42

Page 43: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Approach (cont.)

  Designaflexiblesystemtoenablenon‐expertstodefineannota0onsthatdirectperformance‐tuningsourcetransforma0ons

  Goals1.  Supportsourcetransforma0onsbetweendomain‐specificorspecial‐

purposelanguagesandgeneral‐purposelanguages(C/C++andFortran).2.  Provideaneffec0veapproachforaddressingperformanceissuesby

permitng(butnotrequiring)accessbytheapplica0onscien0sttolow‐leveldetails.

3.  Improveperformanceportabilitybyabstrac0ngplauorm‐specificlow‐levelop0miza0oncode.

4.  Preserveapplica0oninvestmentincurrentlanguages.

  Soowareinfrastructure:Orio–  hep://0nyurl.com/OrioTool–  Extensibledesign,fewprerequisites,portable

43

Page 44: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Orio Workflow orcc –spec=foo-bgp.spec –output=foo.bgp.c foo.c

TuningSpecifica7ons(foo‐bgp.spec)

Sequenceof(Nested)AnnotatedRegions

CodeGenerator

GeneratedCCodeVersions

Op7mizedCCode(foo.bgp.c)

EmpiricalPerformanceEvalua0on

CodeTransforma0ons

AnnotatedCCode(foo.c)

iterate

CCodePerformanceAnnota7ons

Annota0onParser

Page 45: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Orio Design

  OrioisimplementedinPythonandconsistsof–  Op0miza0onmodulesthatprovide

•  Annota0onparsing•  Transforma0on•  Codegenera0onModulescancontainsubmodules.

–  Empiricaltuningmodulesthatprovide•  Tuningspecparsing•  Searchspaceexplora0on•  Testexecu0on(sequen0alandparallel)

45

Name-based dynamic loading enables flexibility and easy extensibility

Page 46: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Search Engine

  Inputs:–  Transforma0onspecifica0on

–  Performanceexperimentdefini0on•  Programinputs

•  Performanceparameters

•  Constraints•  Searchmethod

•  Buildandexecu0onenvironmentdescrip0on

  Currentsearchstrategies:–  Exhaus0ve–  Random

–  Nelder‐MeadSimplexalgorithmwitha0melimitconstraint

–  Simulatedannealing

–  Deriva0ve‐freeglobalop0miza0on(inprogress)

46

Page 47: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Experiments

  BlueGene/P(four850MHzIBMPowerPC450processorswithadualfloa0ng‐pointunitand2GBtotalmemorypernode,privateL1(32KB)andL2(4MB)caches,asharedL3cache(8MB))

  Xeonworksta0on(dualquad‐coreE5462Xeonprocessors(8corestotal)runningat2.8GHz(1600MHzFSB)with32KBL1cache,12MBofL2cache(6MBsharedpercorepair),and2GBofDDR2FBDIMMRAM,runningLinuxkernelversion2.6.25(x86‐64))

  Transforma0ons•  Simpleloopunrolling

•  Loopunroll/jamming•  Loop0ling•  Looppermuta0on

•  Scalarreplacement

51

•  Register0ling•  Loop‐boundreplacement

•  Arraycopyop0miza0on

• Mul0coreparalleliza0on(usingOpenMP)

•  SIMDinstruc0ons(BG/P)

Page 48: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Streaming Operations

  Streamtriadopera0on:for(i=0;i<n;i++)

z[i]=x[i]+ss*y[i];

  AXPY‐4:for(i=0;i<=N‐1;i++)

y[i]=y[i]+a1*x1[i]+a2*x2[i]+a3*x3[i]+a4*x4[i];

53

AXPY_N-type operations occur frequently in derivative codes generated using automatic differentiation tools.

Page 49: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Stream Triad Results: BG/P

0

1,000

2,000

3,000

4,000

5,000

6,000

7,000

8,000

9,000

Mem

oryBa

ndwidth(M

B/s)

ArraySize

NoAnnota0ons

Disjoint/Align

Disjoint/Align/Unroll

  Blue Gene/P

Page 50: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Streaming Operation: AXPY4

Sequential Parallel (four cores) Problem size (N) Problem size (N)

Mflo

ps/se

c

Mflo

ps/se

c

for(i=0;i<=N‐1;i++)y[i]=y[i]+a1*x1[i]+a2*x2[i]+a3*x3[i]+a4*x4[i];

  Blue Gene/P

Page 51: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Stencil Computations and Dense Linear Algebra

  Finite‐DifferenceTime‐Domain(FDTD)methods

  Composeddenselinearalgebraopera0ons–  ATAX

y ← AT (A x) –  GEMVER

A ← A + u1 v1 + u2 v2 x ← β AT y + z w ← α A x

56

Moreonthatlater

Page 52: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

for(t=0; t<tmax; t++) { for (j=0; j<ny; j++) ey[0][j] = t; for (i=1; i<nx; i++) for (j=0; j<ny; j++)

ey[i][j] = ey[i][j] - 0.5*(hz[i][j]-hz[i-1][j]); for (i=0; i<nx; i++) for (j=1; j<ny; j++)

ex[i][j] = ex[i][j] - 0.5*(hz[i][j]-hz[i][j-1]); for (i=0; i<nx; i++) for (j=0; j<ny; j++)

hz[i][j]=hz[i][j]- 0.7*(ex[i][j+1]-ex[i][j] + ey[i+1][j]-ey[i][j]); }

2D FDTD: MFLOPs/sec. vs. Array Size (1 Core, tmax=500)

0

500

1000

1500

2000

2500

3000

3500

4000

125 250 500 1000 2000 4000

NoAnnota0ons

PLuTo(L1)

Orio

57

 Xeonworksta0on(dualquad‐coreE5462Xeonprocessors(8corestotal)runningat2.8GHz(1600MHzFSB)with32KBL1cache,12MBofL2cache(6MBsharedpercorepair),and2GBofDDR2FBDIMMRAM,runningLinuxkernelversion2.6.25(x86‐64))

Page 53: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

2D FDTD: MFLOPs/sec. vs. Number of Cores (tmax=500, N=2000)

0

2000

4000

6000

8000

10000

12000

14000

16000

1 2 3 4 5 6 7 8

NoAnnota0ons

PLuTo(L1)

Orio

58

 Xeonworksta0on(dualquad‐coreE5462Xeonprocessors(8corestotal)runningat2.8GHz(1600MHzFSB)with32KBL1cache,12MBofL2cache(6MBsharedpercorepair),and2GBofDDR2FBDIMMRAM,runningLinuxkernelversion2.6.25(x86‐64))

Page 54: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Composed dense linear algebra computations

  Produc0vity:–  Leverageexis0ngMATLAB

compilertechnology1

  Performance:–  Annota0onlanguageusesslightly

extendedMATLABsyntax–  Useexis0ngMATLABcompilerto

generateCcode

–  PerformanalysisoftheCcode

–  TunewithOrio

60

1Jessup,E.,Karlin,I.,,Siek,J.:Buildtoorderlinearalgebrakernels.In:ProceedingsoftheIEEEInterna7onalSymposiumonParallelandDistributed(IPDPS2008),IEEE(2008)1–8.

ExtendedMATLABCode

BuildtoOrderBLASCompiler

CCode

AnnotatedCCode

PerformanceAnnota7ons

OrioEmpiricalTuning

Op7mizedCCode

Page 55: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Composed linear algebra: ATAX

ATAXinA:rowmatrix,x:vectorouty:vector{y=A’*(A*x)}

61

  Xeonworksta0on(dualquad‐coreE5462Xeonprocessors(8corestotal)runningat2.8GHz(1600MHzFSB)with32KBL1cache,12MBofL2cache(6MBsharedpercorepair),and2GBofDDR2FBDIMMRAM,runningLinuxkernelversion2.6.25(x86‐64))

Page 56: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Composed linear algebra: BiCG Kernel

BiCG

in

A:rowmatrix,p:vector,r:vector

out

q:vector,s:vector

{

q=A*p

s=A'*r

}

62

  Xeonworksta0on(dualquad‐coreE5462Xeonprocessors(8corestotal)runningat2.8GHz(1600MHzFSB)with32KBL1cache,12MBofL2cache(6MBsharedpercorepair),and2GBofDDR2FBDIMMRAM,runningLinuxkernelversion2.6.25(x86‐64))

Page 57: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Composed Linear Algebra: GEMVER

GEMVER

in

A:columnmatrix,u1:vector,u2:vector,

v1:vector,v2:vector,

a:scalar,b:scalar,

y:vector,z:vector

out

B:columnmatrix,

x:vector,w:vector

{

B=A+u1*v1’

+u2*v2'

x=b*(B'*y)+z

w=a*(B*x)}

63

  Xeonworksta0on(dualquad‐coreE5462Xeonprocessors(8corestotal)runningat2.8GHz(1600MHzFSB)with32KBL1cache,12MBofL2cache(6MBsharedpercorepair),and2GBofDDR2FBDIMMRAM,runningLinuxkernelversion2.6.25(x86‐64))

Page 58: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Sparse Linear Algebra

  PETSc(hep://www.mcs.anl.gov/petsc):atoolkitfortheparallelnumericalsolu0onofpar0aldifferen0alequa0ons

  Sparsematrix‐vectormul0plica0ondominatestheperformanceofmanyapplica0ons

∀Ai,j ≠ 0 : yi ← yi + Ai,j · xj

whereAisasparsematrixandx, y aredensevectors.

64

for(i=0;i<num_rows;i++)for(j=Aptr[i];j<Aptr[i+1];j++)y[i]+=Aval[j]*x[Aind[j]];

Page 59: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

SpMV in 2D Driven Cavity Flow (8 Nodes)

  Blue Gene/P

0

100

200

300

400

500

600

700

800

900

8x8 16x16 32x32 64x64 96x96 128x128

MFLOP/s

GridSize

Compiler‐op0mized(4p/1t)

Hand‐tuned(4p/1t)

Orio(1p/4t)The matrix dimension is based on the grid size and the number of field components computed for each grid point; for example, an 8×8 problem involves sparse matrices of dimension 900 with 17,040 nonzero entries.

Page 60: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

SpMV in a 2D driven cavity flow

66

  Xeonworksta0on

0

1000

2000

3000

4000

5000

6000

7000

8x8 16x16 32x32 64x64 96x96 128x128

MFLOP/s

GridSize

Compiler-optimized (1p/4t)

Hand-tuned (4p/1t)

Orio (1p/4t)

Page 61: Approaches and Tools for Understanding and Improving …ix.cs.uoregon.edu/~norris/performance-PBound-Orio.pdfApproaches and Tools for Understanding and Improving the Performance of

Summary

  Usefulperformanceinforma0oncanbegeneratedautoma0callythroughsourcecodeanalysis–  PBound:hep://0nyurl.com/PBound

  Bothhighproduc0vityandhighperformancecanbesupportedthroughannota0on‐basedempiricaltuning–  Pbound:hep://0nyurl.com/OrioTool

  Thankyou!

67