1 / 66

Andrés S. CHARIF-RUBIAL achar@exascale-computing.com

Performance analysis and optimization MAQAO Tool. Andrés S. CHARIF-RUBIAL achar@exascale-computing.com Exascale Computing Research 08/02/2012 – Fréjus – Ecole d’optimisation. Outline. Introduction Methodology MAQAO Tool and Framework Static Analysis Dynamic Analysis Conclusion.

denise
Download Presentation

Andrés S. CHARIF-RUBIAL achar@exascale-computing.com

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. Performance analysis and optimization MAQAO Tool Andrés S. CHARIF-RUBIALachar@exascale-computing.com ExascaleComputingResearch08/02/2012 – Fréjus – Ecole d’optimisation MAQAO Tool

  2. Outline Introduction Methodology MAQAO Tool and Framework Static Analysis Dynamic Analysis Conclusion MAQAO Tool

  3. Introduction Pareto principle : in software engineering 90/10 Programmer view ≠ architecture impact Amdahl’s law : evaluate sequential part Optimisation cost : code quality Optimisation target : execution time Binary VS Source level Compiler is your best friend MAQAO Tool

  4. Methodology Systematic Workflow Define a goal : walltime, memory, scalability Consider target application What we are using / Which accuracy Static + Dynamic approach MAQAO Tool

  5. Methodology Type of code ? CPU or memory bound Approach : Top-Down / Iterative Detect hot spots Focus on specific parts MAQAO Tool

  6. Methodology Exploit Compiler to the maximum IPO and inlining !!! Flags Optimization levels Pragmas : unroll,vectorize Intrinsics Structured code (compiler sensitive) MAQAO Tool

  7. MAQAO Tool and Framework MAQAO Framework Modular approach Reusable components MAQAO Tool Using Framework User feedback User interface Batch interface MAQAO Tool

  8. MAQAO Framework Binary manipulation Set of C libraries (core features) Scripting language on top Plugins MAQAO Tool

  9. MAQAO Framework MADRAS Abstraction layer Disassembler Generator Disassemble libmadras libcore libcommon libasm Re-assemble Patch/Rewrite libaffine libmt MAQAO Lua Plugins API bindings to Abstract And Binarylayers DECAN STAN MIL DDG MTL … MAQAO Profiler MAQAO Tool

  10. MAQAO Tool Built on top of the Framework Exploit existing framework features Produce reports Client/Server approach User interface Batch interface Loop-centric approach Packaging : ONE (static) standalone binary MAQAO Tool

  11. MAQAO Tool overview Modular Assembler Quality Analyzer and Optimizer www.maqao.org Assembly code / (innermost) Loops Assembly code Binary code Code abstraction MADRAS CFG CG Dominatortree DDG Loopdetection Compiler Dynamic Analyses Reports Source code Static Runtime End User Developer ExternalDevelopers => New modules MAQAO Tool

  12. MAQAO Tool Web User interface SCREENSHOT HERE MAQAO Tool

  13. Static analysis Static performance model : STAN Loop-centric Predict performance Take into account microarchitecture Asses code quality Degree of vectorization Impact on micro architecture MAQAO Tool

  14. Static analysis Core2 Pipeline Model IQ can be used as a MIN (64 bytes, 18 instructions) loop buffer MAQAO Tool

  15. Static analysis NHM Pipeline Model IDQ can be used as a MIN (256 bytes, 28 uops) loop buffer MAQAO Tool

  16. Static analysis Sandy Bridge Pipeline Model New ! 16 bytes fetched / cycle, ~ 3 SSE / AVX instructions per cycle 4 instructions decoded per cycle... uop queue can be dynamically reconfigured as loop buffer 1.5 Kuops cache (100% hits for hotspots and 80% hits avg.) MAQAO Tool

  17. Static analysis How can this help me ? Architecture bottlenecks Control unrolling impact Data precision and divison : Newton-Raphson Only applies on single precision Faster to compute 1/x and 1/√x (RCP and RSQRT) From ≈30-60 cyles to a few cycles (≈6cyles) MAQAO Tool

  18. Static analysis How can this help me ? Major improvement lever : vectorization Is code vectorized ? How well is it vectorized ? Guide compiler with pragmas MAQAO Tool

  19. Static analysis Report Example ******************************************************** PROCESSING LOOP 2421 ******************************************************** Function: sparse_full_mm5_ Source file: /mnt/nfs/eoseret/qmc_chem/QmcChem_new/src/IRPF90_temp/mo.irp.F90 Source line: 2121-2126 Address in the binary: 5540a0 ******************************************************** GENERAL LOOP PROPERTIES ******************************************************** nb instructions : 19 nbuops : 19 loop length : 120 used xmm registers : 0 used ymm registers : 15 nb FP arithmetical operations: add-sub 40 mul 40 Ratio ADD-SUB/MUL (instructions): 1 Bytes loaded: 192 Bytes stored: 160 Arith. intensity (FLOP / ld+st bytes): 0.23 FIT IN UOP CACHE ******************************************************** EXECUTION PORTS _ OPTIMAL METHOD ******************************************************** 10.00 cycles ******************************************************** DISPATCH ******************************************************** P0 P1 P2 P3 P4 P5 uops 5.00 5.00 5.50 5.50 5.00 3.00 cycles 5.00 5.00 6.00 6.00 10.00 3.00 ******************************************************** VECTORIZATION RATIOS ******************************************************** all : 100% load : 100% store : 100% mul : 100% add_sub : 100% other = NA (no other SSE or AVX instructions) ******************************************************** IF ALL DATA IN L1 ******************************************************** cycles: 10.00 FP operations per cycle: 8.00 (GFLOPS at 1 GHz) instructions per cycle: 1.90 bytes loaded per cycle: 19.20 (GB/s at 1 GHz) bytes stored per cycle: 16.00 (GB/s at 1 GHz) bytes loaded or stored per cycle: 35.20 (GB/s at 1 GHz) Cycles executing div or sqrt instructions: NA ******************************************************** MAQAO Tool

  20. Dynamic analysis Static analysis is optimistic Data in L1$ Believe architecture Get a real image Coarse grain : find hotspots (MAQAO profiler) DECAN : compute / memory bound MIL : specilized instrumentation MTL : characterize memory behavior MAQAO Tool

  21. MAQAO profiler Method : Sampling VS Tracing Tradeoff : accuracy VS execution time New method : minimizing callsite Instrumentation Loop level : filtering compared to ICC Handles OpenMP codes MAQAO Tool

  22. MIL : Instrumentation Language Why ? Yet another language ? Need to handle coarse and fine grain issues Tool to express such queries DSL : Sufficiently rich for instrumentation purposes Fast prototyping Focus on what (research) and not how (technical) Explore code properties (side effect) What about OpenMP/MPI ? MAQAO Tool

  23. MIL : Instrumentation Language Handling interleaved functions Example Connected components approach (static analysis) MAQAO Tool

  24. MIL : Instrumentation Language Handling masked exits Unconditional jumps to other functions Jumps pointing on returns Indirect jumps Exit handlers list MAQAO Tool

  25. MIL : Instrumentation Language Gobal variables Events Filters Actions Configuration features Output Language behavior (properties) MAQAO Tool

  26. MIL : Instrumentation Language Probes External functions Name Library Parameters : int,strings,macros,cstring Return value Demangling Context saving ASM inline : handles loops _ZN3MPI4CommC2Ev MPI::Comm::Comm() MAQAO Tool

  27. MIL : Instrumentation Language Events Program : Entry/Exit (avoid LD + exit handlers) Functions : Entries/Exists Callsites : Before/After Loops : Entries/Exists/Backedge Blocks : Entries/Exists Instructions : Address MAQAO Tool

  28. MIL : Instrumentation Language Events : Hierarchical evaluation MAQAO Tool

  29. MIL : Instrumentation Language Filters Why ? Lists : whitelist / blacklist (int,string,regexp) Built-in : structural properties attributes (nesting level for a loop) User defined : an actions that returns true/false MAQAO Tool

  30. MIL : Instrumentation Language Actions Why ? Scripting ability Function : current object (this) and patcher Access to MAQAO Plugins API User filters may be used to express very complex constraints MAQAO Tool

  31. MIL : Instrumentation Language Another wayto use the MAQAO Framework : DSL for Building performance evaluation tools Instrumentation File Binaries | Probes | Target Events | Filters |Actions MIL MADRAS Disassembler Process file Hierarchical Events Abstract Layer MAQAO Plugins API Evaluatefilters Probes Actions MAQAO Framework MADRAS Assembler And Rewritter InstrumentedBinary(ies) MAQAO Tool

  32. MIL : Instrumentation Language Example 1 MAQAO Tool

  33. MIL : Instrumentation Language Example 2 MAQAO Tool

  34. MIL : Instrumentation Language • Use case 1 : Loop value profiling MAQAO Tool

  35. MIL : Instrumentation Language • Use case 2 : Function value profiling Before After MAQAO Tool

  36. MIL : Instrumentation Language • Use case 3 : timing short loops 3 most time consuming loops : 224 cycles (QMC==Chem) Probe accuracy Instrumentation overhead MAQAO Tool

  37. MTL : Memory Trace Library Characterizing the memory behavior of an application MAQAO Tool

  38. MTL : Target • Characterize memory behavior (memory bound code) • Complex Shared memory environment : CC-NUMA / NUCA • Architecture specs: Prefetch, PLRU • Scaling issues • Multithread : OpenMP • Loop centric approach • Capture behavior of memory access : tracing • Time • Space MAQAO Tool

  39. MTL : Target Complex shared memory environments : CC-NUMA / NUCA MAQAO Tool

  40. MTL : Motivation NPB and Spec OMP 2001 MAQAO Tool

  41. MTL : Metrics Help user understanding memory related issues Alignement issues Data Architecture Access Pattern issues Data sharing : reuse, false sharing MAQAO Tool

  42. Memory Traces: overview Infrastructure MAQAO Tool

  43. Trace collection Trace collection • Per thread – per instruction • Target instructions: memory operations • Using NLR • Instrumentation time and space consumption MAQAO Tool

  44. Trace collection : instrumentation Blind method : full instrumentation MAQAO Tool

  45. Trace collection : enhancement • Finer method : strength reduction algorithm • Find loop invariants (registers and stack values); • Find induction variables (affine expressions only, since the trace has only Z-polytopes) • Find all memory accesses based on induction variables and loop invariants; • Instrument all loop invariants and all memory accesses that are not built based on induction variables and loop invariants. • Reconstruct address flows and Z-polytopes (NLR) MAQAO Tool

  46. Trace collection : enhancement Finer method : strength reduction algorithm MAQAO Tool

  47. MTL Metrics: Data alignment • Architecture : Even if vectors aligned => up to 10 cycles penalty • Micro benchmarking • Look for (poor) know patterns • Change code : Reduce stores MAQAO Tool

  48. MTL Metrics : Access patterns Inefficient patterns On nested loops, loop interchange can improve spatial locality for strided accesses (column major, row major). The left access pattern uses 512 Bytes strides (one element out of 8) which decreases spatial locality. This transformation is suggested to the user only if it enhances locality (according to the cost function) MAQAO Tool

  49. MTL Metrics : Access patterns Before After • Hardware prefetch can’t work • DTLB Misses 5% Gain Loop interchange : NPB 2.3 C example MAQAO Tool

  50. MTL Metrics : Access patterns Data Layout : Splitting Single FP array Red and Black checkboard example DO IDO=1,NREDD INC = INDINR(IDO) HANB = AM(INC,1)*PHI(INC+1) & + AM(INC,2)*PHI(INC-1) & + AM(INC,3)*PHI(INC+INPD) & + AM(INC,4)*PHI(INC-INPD) & + AM(INC,5)*PHI(INC+NIJ) & + AM(INC,6)*PHI(INC-NIJ) & + SU(INC) DLTPHI = UREL*( HANB/AM(INC,7) - PHI(INC) ) PHI(INC) = PHI(INC) + DLTPHI RESI = RESI + ABS(DLTPHI) RSUM = RSUM + ABS(PHI(INC)) ENDDO) Inefficient pattern : stride 2 accessdetected on wholestructure (FILE:SRC LINE) => You mayconsidersplittingyour data structure Reading 1 element out of 2 (wasting spatial locality) 30% Gain MAQAO Tool

More Related