Tuning Sparse Matrix Vector Multiplication for multicore SMPs

  • Slides: 35
Download presentation
Tuning Sparse Matrix Vector Multiplication for multi-core SMPs (paper to appear at SC 07)

Tuning Sparse Matrix Vector Multiplication for multi-core SMPs (paper to appear at SC 07) Sam Williams samw@cs. berkeley. edu

Other Authors (for the SC 07 Paper) • • • Rich Vuduc Lenny Oliker

Other Authors (for the SC 07 Paper) • • • Rich Vuduc Lenny Oliker John Shalf Kathy Yelick Jim Demmel

Outline • Background – Sp. MV – OSKI • Test Suite – Matrices –

Outline • Background – Sp. MV – OSKI • Test Suite – Matrices – Systems • Results – Naïve performance – Performance with tuning/optimizations • Comments

Background

Background

Dense Matrix Vector Multiplication • • Evaluate y=Ax x & y are dense vectors

Dense Matrix Vector Multiplication • • Evaluate y=Ax x & y are dense vectors A is a dense matrix Each element is required to A x y access the source vector(X) = trivial address calculation Each row is required to access the destination vector (Y) = trivial address calculation Trivial to exploit ILP, DLP, TLP Friendly access to the vectors Low computational intensity - likely memory bound

Sparse Matrix Vector Multiplication • • • Evaluate y=Ax x & y are still

Sparse Matrix Vector Multiplication • • • Evaluate y=Ax x & y are still dense vectors A is a sparse matrix Unlike a dense matrix, only the A x the nonzeros are stored and operated on. Unlike dense matrix multiplication, significant meta data is required to tag the coordinates of each nonzero. Nonzeros normally laid out in rows (CSR) Difficult to exploit ILP, DLP, TLP Unfriendly access to the source vector Even lower computational intensity - likely to be heavily memory bound y

OSKI & PETSc • Register Blocking reorganizes the matrix into tiles by adding nonzeros

OSKI & PETSc • Register Blocking reorganizes the matrix into tiles by adding nonzeros • better ILP/DLP at the potential expense of extra memory traffic. • OSKI is a serial auto-tuning library for sparse matrix operations developed at UCB • OSKI is primarily focused on searching for the optimal register blocking • For parallelism, it can be included in the PETSc parallel library using a shared memory version of MPICH • We include these 2 configurations as a baseline comparison for the x 86 machines.

Exhaustive search in the multi-core world? • Search space is increasing rapidly (register/cache/TLB blocking,

Exhaustive search in the multi-core world? • Search space is increasing rapidly (register/cache/TLB blocking, BCSR/BCOO, loop structure, data size, parallelization, prefetching, etc…) • Seemingly intractable • Pick your battles: – use heuristics when you feel confident you can predict the benefit – search when you can’t.

Test Suite

Test Suite

Sparse Matrices 2 K x 2 K Dense matrix stored in sparse format Dense

Sparse Matrices 2 K x 2 K Dense matrix stored in sparse format Dense Well Structured (sorted by nonzeros/row) Protein FEM / Spheres FEM / Cantilever FEM / Accelerator Circuit webbase Wind Tunnel FEM / Harbor QCD FEM / Ship Economics Epidemiology Poorly Structured hodgepodge Extreme Aspect Ratio (linear programming) LP • • Pruned original Be. BOP suite down to 14 Subdivided them into 4 categories None should fit in an Opteron’s cache. Rank ranges from 2 K to 1 M

Multi-core SMP Systems Core 2 Core 2 4 MB Shared L 2 1 MB

Multi-core SMP Systems Core 2 Core 2 4 MB Shared L 2 1 MB victim Opteron 8 GB/s FSB 10. 6 GB/s Memory Controller / HT 10. 6 GB/s Chipset (4 x 64 b controllers) 21. 3 GB/s(read) DDR 2 DRAM 10. 6 GB/s(write) DDR 2 DRAM Fully Buffered DRAM Intel Clovertown AMD Opteron FPU MT Ultra. Sparc 8 K D$ 4 x 128 b FBDIMM memory controllers 42. 7 GB/s (read), 21. 3 GB/s (write) Fully Buffered DRAM PPE 512 K L 2 MFC 256 K SPE SPE 256 K MFC MFC 256 K SPE SPE 256 K MFC BIF XDR 25. 6 GB/s XDR DRAM Sun Niagara 2 PPE <<20 GB/s each direction BIF XDR 25. 6 GB/s XDR DRAM IBM Cell Blade EIB (Ring Network) FPU MT Ultra. Sparc 8 K D$ 90 GB/s (writethru) FPU MT Ultra. Sparc 8 K D$ Crossbar Switch FPU MT Ultra. Sparc 8 K D$ 4 MB Shared L 2 (16 way) 512 K L 2 179 GB/s (fill) FPU MT Ultra. Sparc 8 K D$

Multi-core SMP Systems Core 2 Core 2 4 MB Shared L 2 FSB 10.

Multi-core SMP Systems Core 2 Core 2 4 MB Shared L 2 FSB 10. 6 GB/s Blackford Chipset 10. 6 GB/s(write) Fully Buffered DRAM 4 MB Shared L 2 (16 way) FPU MT Ultra. Sparc 8 K D$ 90 GB/s (writethru) FPU MT Ultra. Sparc 8 K D$ 4 FBDIMM memory controllers 42. 7 GB/s (read), 21. 3 GB/s (write) Fully Buffered DRAM Sun Niagara 2 1 MB victim Opteron 8 GB/s Memory Controller / HT 10. 6 GB/s DDR 2 DRAM AMD Opteron PPE 512 K L 2 MFC 256 K SPE SPE 256 K MFC MFC 256 K SPE SPE 256 K MFC BIF XDR 25. 6 GB/s XDR DRAM <<20 GB/s each direction BIF XDR 25. 6 GB/s XDR DRAM IBM Cell Blade EIB (Ring Network) w o o l i t y a r r Ve yte ) b : 6 p 2. o l f (0 FPU MT Ultra. Sparc 8 K D$ Opteron EIB (Ring Network) FPU MT Ultra. Sparc 8 K D$ Crossbar Switch FPU MT Ultra. Sparc 8 K D$ Opteron 512 K L 2 179 GB/s (fill) FPU MT Ultra. Sparc 8 K D$ 1 MB victim Mo 21. 3 GB/s(read) 1 MB victim de rat (0. e fl 83 op , a : by nd te 0. 5 ra 7) tio h g i tio H a y r r Ve byte ) : . 52 p flo Clovertown Intel (3 Core 2

Multi-core SMP Systems Core 2 Core 2 4 MB Shared L 2 1 MB

Multi-core SMP Systems Core 2 Core 2 4 MB Shared L 2 1 MB victim Opteron ed 1 MB victim Opteron s a b e y h c ch a C rar l a ie Intel Clovertown AMD Opteron n o H i t y n r e o v n em e r o o C t M S y 8 GB/s FSB 10. 6 GB/s Memory Controller / HT 10. 6 GB/s Blackford Chipset 21. 3 GB/s(read) DDR 2 DRAM 10. 6 GB/s(write) DDR 2 DRAM Fully Buffered DRAM FPU MT Ultra. Sparc 8 K D$ 4 FBDIMM memory controllers 42. 7 GB/s (read), 21. 3 GB/s (write) Fully Buffered DRAM PPE 512 K L 2 MFC 256 K SPE SPE 256 K MFC l h a c c r o a L ier t n i H o j y r s i D emo M IBM Cell Blade MFC 256 K SPE SPE 256 K MFC MFC 256 K SPE SPE 256 K MFC BIF XDR 25. 6 GB/s XDR DRAM Sun Niagara 2 PPE <<20 GB/s each direction BIF XDR 25. 6 GB/s XDR DRAM EIB (Ring Network) FPU MT Ultra. Sparc 8 K D$ 90 GB/s (writethru) FPU MT Ultra. Sparc 8 K D$ Crossbar Switch FPU MT Ultra. Sparc 8 K D$ 4 MB Shared L 2 (16 way) 512 K L 2 179 GB/s (fill) FPU MT Ultra. Sparc 8 K D$

Core 2 4 MB Shared L 2 FSB 1 MB victim Opteron 10. 6

Core 2 4 MB Shared L 2 FSB 1 MB victim Opteron 10. 6 GB/s DDR 2 DRAM ry Fully Buffered DRAM 4 FBDIMM memory controllers 42. 7 GB/s (read), 21. 3 GB/s (write) Fully Buffered DRAM Sun Niagara 2 PPE 512 K L 2 SPE 256 K MFC MFC 256 K SPE SPE 256 K MFC MFC 256 K SPE SPE 256 K MFC 256 K SPE 256 K MFC orm MFC 256 K SPE n-U nif Un FPU MT Ultra. Sparc 8 K D$ BIF XDR 25. 6 GB/s No ifo FPU MT Ultra. Sparc 8 K D$ 4 MB Shared L 2 (16 way) FPU MT Ultra. Sparc 8 K D$ 90 GB/s (writethru) rm FPU MT Ultra. Sparc 8 K D$ EIB (Ring Network) FPU MT Ultra. Sparc 8 K D$ Crossbar Switch FPU MT Ultra. Sparc 8 K D$ 512 K L 2 179 GB/s (fill) FPU MT Ultra. Sparc 8 K D$ Me mo AMD Opteron XDR DRAM <<20 GB/s each direction BIF XDR 25. 6 GB/s XDR DRAM IBM Cell Blade EIB (Ring Network) Me mo ry Intel Clovertown FPU MT Ultra. Sparc 8 K D$ 10. 6 GB/s DDR 2 DRAM 10. 6 GB/s(write) Opteron Memory Controller / HT 10. 6 GB/s Ac 21. 3 GB/s(read) 1 MB victim Opteron Memory Controller / HT 10. 6 GB/s Blackford Chipset 1 MB victim 8 GB/s ce FSB 1 MB victim ce Core 2 Ac Core 2 ss Multi-core SMP Systems

Multi-core SMP Systems s e k a m e r a w ) d

Multi-core SMP Systems s e k a m e r a w ) d ? r ( a y H s a e g n i m m a r g Intel Clovertown AMD Opteron o r p Core 2 Core 2 4 MB Shared L 2 1 MB victim Opteron 8 GB/s FSB 10. 6 GB/s Memory Controller / HT 10. 6 GB/s Blackford Chipset 21. 3 GB/s(read) DDR 2 DRAM 10. 6 GB/s(write) DDR 2 DRAM FPU MT Ultra. Sparc 8 K D$ 4 MB Shared L 2 (16 way) FPU MT Ultra. Sparc 8 K D$ 4 FBDIMM memory controllers 42. 7 GB/s (read), 21. 3 GB/s (write) Pr Fully Buffered DRAM Sun Niagara 2 512 K L 2 EIB (Ring Network) FPU MT Ultra. Sparc 8 K D$ 90 GB/s (writethru) FPU MT Ultra. Sparc 8 K D$ Crossbar Switch FPU MT Ultra. Sparc 8 K D$ 179 GB/s (fill) FPU MT Ultra. Sparc 8 K D$ PPE 512 K L 2 MFC 256 K SPE SPE 256 K MFC MFC 256 K SPE SPE 256 K MFC EIB (Ring Network) ne og ed ra Pa s t mm ra o e er lle xp ju lis re st m ss Fully Buffered DRAM r g e n i m h m t a y r r e g o ev r P he t s e o d BIF XDR 25. 6 GB/s XDR DRAM <<20 GB/s each direction BIF XDR 25. 6 GB/s XDR DRAM IBM Cell Blade

Results Most optimizations on cache-based machines are necessities on Cell.

Results Most optimizations on cache-based machines are necessities on Cell.

Speedup over OSKI • PETSc used to parallelize OSKI Clovertown Opteron 1 core 1.

Speedup over OSKI • PETSc used to parallelize OSKI Clovertown Opteron 1 core 1. 66 x 1. 44 x All cores 2. 22 x 3. 33 x • New serial optimizations can help some • Parallelization optimizations are an essential

Naïve Single Thread Performance ~3. 6 GB/s Intel Clovertown 10 x Slower Sun Niagara

Naïve Single Thread Performance ~3. 6 GB/s Intel Clovertown 10 x Slower Sun Niagara 2 ~3. 0 GB/s AMD Opteron Naïve Single Thread

Parallelization • Row parallelization based on nonzeros • Row granularity is a cache line

Parallelization • Row parallelization based on nonzeros • Row granularity is a cache line • Load balancing can be challenging since source vector communication was not x included. A • Exhaustive search using powers of 2 number of threads • Explore outward (SMT, multi-core, multi-socket) y

Naïve Parallel Performance 2 x performance with 8 x threads ~6 GB/s Intel Clovertown

Naïve Parallel Performance 2 x performance with 8 x threads ~6 GB/s Intel Clovertown 40 x performance with 64 x threads ~16 GB/s Sun Niagara 2 1. 4 x performance with 4 x threads ~4. 2 GB/s AMD Opteron Naïve all sockets, cores, threads Naïve Single Thread

Exploit NUMA / Affinity • Allocate each thread’s work separately. • Bind each block

Exploit NUMA / Affinity • Allocate each thread’s work separately. • Bind each block to that core’s NUMA node. Bind to Node 0 x • Pin processes to respective cores. Execute on core 0 Execute on core 1 Execute on core 2 Execute on core 3 A y Bind to Node 1 • Use routines in Linux, Solaris, and libnuma.

Performance with NUMA / Affinity ~6 GB/s Intel Clovertown ~16 GB/s 2 x performance

Performance with NUMA / Affinity ~6 GB/s Intel Clovertown ~16 GB/s 2 x performance ~9. 6 GB/s AMD Opteron +NUMA/Affinity Naïve all sockets, cores, threads Naïve Single Thread Sun Niagara 2

Software Prefetching • Memory Latency is significant • Memory access pattern is easily expressible

Software Prefetching • Memory Latency is significant • Memory access pattern is easily expressible • Hardware prefetchers should be able to infer the patterns and hide the latency • They cannot infer the temporal locality (none for the matrix) • Use software prefetch intrinsics • Exhaustive search for the optimal distance • On Cell, use double buffered DMAs

Performance with SW Prefetch Benefit of nta hint? 1. 4 x performance ~8 GB/s

Performance with SW Prefetch Benefit of nta hint? 1. 4 x performance ~8 GB/s Intel Clovertown ~16 GB/s ~12 GB/s AMD Opteron +Software Prefetching +NUMA/Affinity Naïve all sockets, cores, threads Naïve Single Thread Sun Niagara 2

Memory Traffic Minimization Heuristic • Propose that any machine with enough threads/cores should be

Memory Traffic Minimization Heuristic • Propose that any machine with enough threads/cores should be memory bound. • We can do better than just being memory bound - we can try to minimize the memory traffic • Heuristic: select the power of 2 register blocking, CSR/COO format, 16 b/32 b indices, etc… that minimizes the matrix size. • Side effect: matrix may be minimized to the point where it fits entirely in cache

Code Generation • • Write a Perl script to generate all kernel variants. For

Code Generation • • Write a Perl script to generate all kernel variants. For generic C, x 86/Niagara used the same generator Separate generator for SSE Separate generator for Cell’s SIMD • Produce a configuration file for each architecture that limits the optimizations that can be made in the data structure, and their requisite kernels

Memory Traffic Minimization Performance up to 2 x performance up to 1. 6 x

Memory Traffic Minimization Performance up to 2 x performance up to 1. 6 x performance ~11 GB/s Intel Clovertown up to 1. 7 x performance ~19 GB/s ~13 GB/s AMD Opteron +Memory Traffic Minimization +Software Prefetching +NUMA/Affinity Naïve all sockets, cores, threads Naïve Single Thread Sun Niagara 2

Cache and TLB Blocking • • • Access to the destination vector is streaming

Cache and TLB Blocking • • • Access to the destination vector is streaming Access to the source vector can be random Reorganize matrix (and thus access pattern) to maximize reuse. • Heuristic: block destination, then keep adding more columns as long as the number of source vector cache lines(or pages) touched is less than the cache(or TLB). Apply all previous optimizations individually to each cache block. • Search: neither, cache&TLB • Better locality at the expense of confusing the hardware prefetchers. For Cell, express this as a DMA list • x A y

Performance with Cache Blocking Intel Clovertown AMD Opteron +Cache/TLB Blocking +Memory Traffic Minimization +Software

Performance with Cache Blocking Intel Clovertown AMD Opteron +Cache/TLB Blocking +Memory Traffic Minimization +Software Prefetching +NUMA/Affinity Naïve all sockets, cores, threads Naïve Single Thread Sun Niagara 2

Banks, Ranks, and DIMMs • As the number of threads increases, so to does

Banks, Ranks, and DIMMs • As the number of threads increases, so to does the number of streams. • Most memory controllers have finite capability to reorder the requests. (DMA can avoid or minimize this) • Bank conflicts become increasingly likely • More DIMMs, configuration of ranks can help

Performance with more DIMMs/Ranks up to 1. 5 x from extra DIMMs ~11 GB/s

Performance with more DIMMs/Ranks up to 1. 5 x from extra DIMMs ~11 GB/s Intel Clovertown up to 1. 3 x from firmware fix ~23 GB/s ~14 GB/s AMD Opteron +More DIMMs, Rank configuration, etc… +Cache/TLB Blocking ~47 GB/s +Memory Traffic Minimization +Software Prefetching +NUMA/Affinity Naïve all sockets, cores, threads Naïve Single Thread Sun Niagara 2 IBM Cell Blade

Heap Management with NUMA • New pages added to the heap can be pinned

Heap Management with NUMA • New pages added to the heap can be pinned to specific NUMA nodes (system control) • However, if that page is ever free()’d and reallocated (library control), then affinity cannot be changed. • As a result, you shouldn’t free() pages bound under some NUMA policy.

Bandwidth Summary • The dense matrix is a tool for understanding memory performance Clovertown

Bandwidth Summary • The dense matrix is a tool for understanding memory performance Clovertown Opteron Niagara 2 Cell • • GB/s(1 P) 5. 4 7. 2 23. 2 24. 7 GB/s(2 P) 11. 2 14. 0 N/A 47. 3 Clovertown gets only 50%, but Kentsfield can get >85% 2. 2 GHz Opteron gets 66%, but 3. 0 GHz Opteron gets 75% Niagara 2 gets ~50% of both GB/s and GFlop/s Cell gets >90% for virtually every matrix (not just dense)

Comments • Machines with a large number simple cores performed very well (independent of

Comments • Machines with a large number simple cores performed very well (independent of clock rate) • Machines with complex cores required significant tuning/optimization • Niagara 2 and Clovertown likely suffer from Little’s law (need sufficient concurrency to cover bandwidth x latency) • Niagara 2 delivers good (single socket) performance and productivity • Cell delivers good efficiency and performance • Single thread performance was as good or better performance than OSKI despite using heuristics. • Parallel Performance was significantly better than PETSc+OSKI

Questions?

Questions?