Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2000 Morgan Kaufman Overheads for Computers as Components Program design and analysis zOptimizing for execution time. zOptimizing for energy/power. zOptimizing.

Similar presentations


Presentation on theme: "© 2000 Morgan Kaufman Overheads for Computers as Components Program design and analysis zOptimizing for execution time. zOptimizing for energy/power. zOptimizing."— Presentation transcript:

1 © 2000 Morgan Kaufman Overheads for Computers as Components Program design and analysis zOptimizing for execution time. zOptimizing for energy/power. zOptimizing for program size.

2 © 2000 Morgan Kaufman Overheads for Computers as Components Motivation zEmbedded systems must often meet deadlines. yFaster may not be fast enough. zNeed to be able to analyze execution time. yWorst-case, not typical. zNeed techniques for reliably improving execution time.

3 © 2000 Morgan Kaufman Overheads for Computers as Components Run times will vary zProgram execution times depend on several factors: yInput data values. yState of the instruction, data caches. yPipelining effects.

4 © 2000 Morgan Kaufman Overheads for Computers as Components Measuring program speed zCPU simulator. yI/O may be hard. yMay not be totally accurate. zHardware profiler/timer. yRequires board, instrumented program. zLogic analyzer. yLimited logic analyzer memory depth.

5 © 2000 Morgan Kaufman Overheads for Computers as Components Program performance metrics zAverage-case: yFor typical data values, whatever they are. zWorst-case: yFor any possible input set. zBest-case: yFor any possible input set. zToo-fast programs may cause critical races at system level.

6 © 2000 Morgan Kaufman Overheads for Computers as Components Performance analysis zElements of program performance (Shaw): yexecution time = program path + instruction timing zPath depends on data values. Choose which case you are interested in. zInstruction timing depends on pipelining, cache behavior.

7 © 2000 Morgan Kaufman Overheads for Computers as Components Programs and performance analysis zBest results come from analyzing optimized instructions, not high-level language code: ynon-obvious translations of HLL statements into instructions; ycode may move; ycache effects are hard to predict.

8 © 2000 Morgan Kaufman Overheads for Computers as Components Program paths zConsider for loop: for (i=0, f=0; i<N; i++) f = f + c[i]*x[i]; zLoop initiation block executed once. zLoop test executed N+1 times. zLoop body and variable update executed N times. i<N i=0; f=0; f = f + c[i]*x[i]; i = i+1; N Y

9 © 2000 Morgan Kaufman Overheads for Computers as Components Instruction timing zNot all instructions take the same amount of time. zInstruction execution times are not independent. zExecution time may depend on operand values.

10 © 2000 Morgan Kaufman Overheads for Computers as Components Trace-driven performance analysis zTrace: a record of the execution path of a program. zTrace gives execution path for performance analysis. zA useful trace: yrequires proper input values; yis large (gigabytes).

11 © 2000 Morgan Kaufman Overheads for Computers as Components Trace generation zHardware capture: ylogic analyzer; yhardware assist in CPU. zSoftware: yPC sampling. yInstrumentation instructions. ySimulation.

12 © 2000 Morgan Kaufman Overheads for Computers as Components Loop optimizations zLoops are good targets for optimization. zBasic loop optimizations: ycode motion; yinduction-variable elimination; ystrength reduction (x*2 -> x<<1).

13 © 2000 Morgan Kaufman Overheads for Computers as Components Code motion for (i=0; i<N*M; i++) z[i] = a[i] + b[i]; i<N*M i=0; z[i] = a[i] + b[i]; i = i+1; N Y i<X i=0; X = N*M

14 © 2000 Morgan Kaufman Overheads for Computers as Components Induction variable elimination zInduction variable: loop index. zConsider loop: for (i=0; i<N; i++) for (j=0; j<M; j++) z[i][j] = b[i][j]; zRather than recompute i*M+j for each array in each iteration, share induction variable between arrays, increment at end of loop body.

15 © 2000 Morgan Kaufman Overheads for Computers as Components Cache analysis zLoop nest: set of loops, one inside other. zPerfect loop nest: no conditionals in nest. zBecause loops use large quantities of data, cache conflicts are common.

16 © 2000 Morgan Kaufman Overheads for Computers as Components Array conflicts in cache a[0,0] b[0,0] main memory cache 10244099... 1024 4099

17 © 2000 Morgan Kaufman Overheads for Computers as Components Array conflicts, cont’d. zArray elements conflict because they are in the same line, even if not mapped to same location. zSolutions: ymove one array; ypad array.

18 © 2000 Morgan Kaufman Overheads for Computers as Components Performance optimization hints zUse registers efficiently. zUse page mode memory accesses. zAnalyze cache behavior: yinstruction conflicts can be handled by rewriting code, rescheudling; yconflicting scalar data can easily be moved; yconflicting array data can be moved, padded.

19 © 2000 Morgan Kaufman Overheads for Computers as Components Energy/power optimization zEnergy: ability to do work. yMost important in battery-powered systems. zPower: energy per unit time. yImportant even in wall-plug systems---power becomes heat.

20 © 2000 Morgan Kaufman Overheads for Computers as Components Measuring energy consumption zExecute a small loop, measure current: while (TRUE) a(); I

21 © 2000 Morgan Kaufman Overheads for Computers as Components Sources of energy consumption zRelative energy per operation (Catthoor et al): ymemory transfer: 33 yexternal I/O: 10 ySRAM write: 9 ySRAM read: 4.4 ymultiply: 3.6 yadd: 1

22 © 2000 Morgan Kaufman Overheads for Computers as Components Cache behavior is important zEnergy consumption has a sweet spot as cache size changes: ycache too small: program thrashes, burning energy on external memory accesses; ycache too large: cache itself burns too much power.

23 © 2000 Morgan Kaufman Overheads for Computers as Components Optimizing for energy zFirst-order optimization: yhigh performance = low energy. zNot many instructions trade speed for energy.

24 © 2000 Morgan Kaufman Overheads for Computers as Components Optimizing for energy, cont’d. zUse registers efficiently. zIdentify and eliminate cache conflicts. zModerate loop unrolling eliminates some loop overhead instructions. zEliminate pipeline stalls. zInlining procedures may help: reduces linkage, but may increase cache thrashing.

25 © 2000 Morgan Kaufman Overheads for Computers as Components Optimizing for program size zGoal: yreduce hardware cost of memory; yreduce power consumption of memory units. zTwo opportunities: ydata; yinstructions.

26 © 2000 Morgan Kaufman Overheads for Computers as Components Data size minimization zReuse constants, variables, data buffers in different parts of code. yRequires careful verification of correctness. zGenerate data using instructions.

27 © 2000 Morgan Kaufman Overheads for Computers as Components Reducing code size zAvoid function inlining. zChoose CPU with compact instructions. zUse specialized instructions where possible.

28 © 2000 Morgan Kaufman Overheads for Computers as Components Code compression zUse statistical compression to reduce code size, decompress on-the-fly: CPU decompressor table cache main memory 0101101 LDR r0,[r4]


Download ppt "© 2000 Morgan Kaufman Overheads for Computers as Components Program design and analysis zOptimizing for execution time. zOptimizing for energy/power. zOptimizing."

Similar presentations


Ads by Google