28
MAGMA Matrix Algebra on GPU and Multicore Architectures Mark Gates February 2012 1

MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Embed Size (px)

Citation preview

Page 1: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

MAGMAMatrix Algebra on GPU and Multicore Architectures

Mark GatesFebruary 2012

1

Page 2: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Berkeley ParLab

But Clock Frequency Scaling Has Been Replaced by Scaling Cores / Chip

3

1.E-01

1.E+00

1.E+01

1.E+02

1.E+03

1.E+04

1.E+05

1.E+06

1.E+07

1970 1975 1980 1985 1990 1995 2000 2005 2010

Transistors (in Thousands) Frequency (MHz) Cores

Data from Kunle Olukotun, Lance Hammond, Herb Sutter, Burton Smith, Chris Batten, and Krste Asanoviç

• Scale # cores instead of clock speed

• Hardware issue became software issue

• Multicore

• Hybrid

Hardware trends

2

Figure from Kathy Yelick, “Ten Ways to Waste a Parallel Computer.”Data from Kunle Olukotun, Lance Hammond, Herb Sutter, Burton Smith, Chris Batten, and Krste Asanoviç.

1e7

1e6

1e5

1e4

1000

100

10

1

0.1

Page 3: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Future systems• Most likely hybrid design

• Multicore + GPU accelerators

• Today accelerators attached

• Future accelerators integrated• Intel’s MIC Knight’s Corner

• AMD’s Fusion

• Nvidia’s Project Denver

3

Page 4: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Challenges of GPUs• High levels of parallelism

• Hybrid architecture• Small, non-parallelizable tasks on CPU

• Large, parallel tasks on GPU

• Compute vs. communication gap growing• Tesla C2070 has 515 Gflops, 8 GB/s PCIe

4

Chapter 1. Introduction

CUDA C Programming Guide Version 4.0 3

The reason behind the discrepancy in floating-point capability between the CPU and the GPU is that the GPU is specialized for compute-intensive, highly parallel computation – exactly what graphics rendering is about – and therefore designed such that more transistors are devoted to data processing rather than data caching and flow control, as schematically illustrated by Figure 1-2.

Figure 1-2. The GPU Devotes More Transistors to Data Processing

More specifically, the GPU is especially well-suited to address problems that can be expressed as data-parallel computations – the same program is executed on many data elements in parallel – with high arithmetic intensity – the ratio of arithmetic operations to memory operations. Because the same program is executed for each data element, there is a lower requirement for sophisticated flow control, and because it is executed on many data elements and has high arithmetic intensity, the memory access latency can be hidden with calculations instead of big data caches.

Data-parallel processing maps data elements to parallel processing threads. Many applications that process large data sets can use a data-parallel programming model to speed up the computations. In 3D rendering, large sets of pixels and vertices are mapped to parallel threads. Similarly, image and media processing applications such as post-processing of rendered images, video encoding and decoding, image scaling, stereo vision, and pattern recognition can map image blocks and pixels to parallel processing threads. In fact, many algorithms outside the field of image rendering and processing are accelerated by data-parallel processing, from general signal processing or physics simulation to computational finance or computational biology.

1.2 CUDA™: a General-Purpose Parallel Computing Architecture In November 2006, NVIDIA introduced CUDA™, a general purpose parallel computing architecture – with a new parallel programming model and instruction set architecture – that leverages the parallel compute engine in NVIDIA GPUs to

Cache

ALU Control

ALU

ALU

ALU

DRAM

CPU

DRAM

GPU

Chapter 1. Introduction

CUDA C Programming Guide Version 4.0 3

The reason behind the discrepancy in floating-point capability between the CPU and the GPU is that the GPU is specialized for compute-intensive, highly parallel computation – exactly what graphics rendering is about – and therefore designed such that more transistors are devoted to data processing rather than data caching and flow control, as schematically illustrated by Figure 1-2.

Figure 1-2. The GPU Devotes More Transistors to Data Processing

More specifically, the GPU is especially well-suited to address problems that can be expressed as data-parallel computations – the same program is executed on many data elements in parallel – with high arithmetic intensity – the ratio of arithmetic operations to memory operations. Because the same program is executed for each data element, there is a lower requirement for sophisticated flow control, and because it is executed on many data elements and has high arithmetic intensity, the memory access latency can be hidden with calculations instead of big data caches.

Data-parallel processing maps data elements to parallel processing threads. Many applications that process large data sets can use a data-parallel programming model to speed up the computations. In 3D rendering, large sets of pixels and vertices are mapped to parallel threads. Similarly, image and media processing applications such as post-processing of rendered images, video encoding and decoding, image scaling, stereo vision, and pattern recognition can map image blocks and pixels to parallel processing threads. In fact, many algorithms outside the field of image rendering and processing are accelerated by data-parallel processing, from general signal processing or physics simulation to computational finance or computational biology.

1.2 CUDA™: a General-Purpose Parallel Computing Architecture In November 2006, NVIDIA introduced CUDA™, a general purpose parallel computing architecture – with a new parallel programming model and instruction set architecture – that leverages the parallel compute engine in NVIDIA GPUs to

Cache

ALU Control

ALU

ALU

ALU

DRAM

CPU

DRAM

GPU

PCIe

Figure from NVIDIA CUDA C Programming Guide

Page 5: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Software generations

5

criticalpath

LINPACK (70’s)vector operations

Level-1 BLAS

LAPACK (80’s)blocked, cache friendly

Level-3 BLAS

ScaLAPACK (90’s)distributed memory

PBLASmessage passing

PLASMAtiled, multicore

DAG + scheduler

MAGMAhybrid

hybrid kernels

Page 6: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Nvidia’s CUBLAS• Level 1, 2, 3 BLAS kernels

• cublasDgemv

• cublasDgemm

• Copy between CPU ↔ GPU• cublasSetMatrix

• cublasGetMatrix

• Stream support• cublasSetKernelStream, magmablasSetKernelStream

6

Page 7: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

MAGMA 1.1• LAPACK column-wise layout

• LAPACK-like C and Fortran interfaces

• CPU and GPU interfaces

7

Page 8: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

MAGMA 1.1• 50+ hybrid LAPACK algorithms

• 4 precisions (single, double, single complex, double complex)

• 3 mixed precision algorithms

• MAGMA BLAS• Supplements CUBLAS

• Improves some routines

8

Page 9: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Naming: magma_zgesv_gpu• magma_ or magmablas_ prefix

• Precision (single, double, single complex, “z” double complex).Mixed precision (ds and zc)

• Matrix typegeneral symmetric hermetian positive definiteorthogonal unitary triangular

• Operationsv solvetrf triangular factorizationev eigenvalue problemgv generalized eigenvalue problem

• Interface _gpu suffix

9

Page 10: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

• Solve entire problem

Driver routines

10

InterfaceInterfaceMatrix type Operation Routine CPU GPUGeneral Solve dgesv dsgesv ✓ ✓SPD Solve dposv dsposv ✓ ✓Least squares Solve dgeqrs dsgeqrsv ✓

General SVD dgesvd ✓Eigenvalues dgeev ✓

Symmetric Eigenvalues dsyevd* / zheevd* ✓ ✓Generalized eigenvalues

dsygvd* / zhegvd* ✓

* Additional variants; complete list at http://icl.eecs.utk.edu/magma/

Page 11: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Computational routines• Solve one part of problem

11

InterfaceInterfaceMatrix type Operation Routine CPU GPUGeneral LU dgetrf ✓ ✓

Solve (given LU) dgetrs ✓Inverse dgetri ✓

SPD Cholesky dpotrf ✓ ✓Solve (given LLT) dpotrs ✓Inverse dpotri ✓

General QR dgeqrf ✓Generate Q dorgqr / zungqr ✓ ✓Multiply by Q dormqr / zunmqr ✓ ✓

Selected routines; complete list at http://icl.eecs.utk.edu/magma/

Page 12: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Panel Look ahead

Trailing matrixA = QA

One-sided factorization• LU, Cholesky, QR factorizations for solving linear systems

12

Level 2BLAS on

CPU

Level 3 BLAS on

GPU

DAG

Page 13: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Panel Look ahead

Trailing matrixA = QA

One-sided factorization• LU, Cholesky, QR factorizations for solving linear systems

12

Level 2BLAS on

CPU

Level 3 BLAS on

GPU

LookaheadPanel

Trailing matrix

DAG

Page 14: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Panel Look ahead

Trailing matrixA = QA

One-sided factorization• LU, Cholesky, QR factorizations for solving linear systems

12

Level 2BLAS on

CPU

Level 3 BLAS on

GPU

LookaheadPanel

Trailing matrix

DAG

Page 15: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Panel Look ahead

Trailing matrixA = QA

One-sided factorization• LU, Cholesky, QR factorizations for solving linear systems

12

Level 2BLAS on

CPU

Level 3 BLAS on

GPU

LookaheadPanel

Trailing matrix

TrailingmatrixPanel

DAG

Page 16: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Panel Look ahead

Trailing matrixA = QA

One-sided factorization• LU, Cholesky, QR factorizations for solving linear systems

12

Level 2BLAS on

CPU

Level 3 BLAS on

GPU

LookaheadPanel

Trailing matrix

TrailingmatrixPanelPanel

DAG

Page 17: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Panel Look ahead

Trailing matrixA = QA

criticalpath

One-sided factorization• LU, Cholesky, QR factorizations for solving linear systems

12

Level 2BLAS on

CPU

Level 3 BLAS on

GPU

LookaheadPanel

Trailing matrix

TrailingmatrixPanelPanel

DAG

Page 18: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

13

Page 19: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

14

Keeneland system, using one node3 Nvidia GPUs (M2070 @ 1.1 GHz, 5.4 GB)2 x 6 Intel Cores (X5660 @ 2.8 GHz, 23 GB)

Page 20: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Mixed-precision solvers

• Factor in single precision

• Iterative refinement yieldsdouble precision accuracy

15

960 3200 5120 7040 8960 11200 131200

50

100

150

200

250

300

350

400

450

500Single PrecDouble PrecIter Ref

Matrix size

GFl

op/s

MAGMA solve

Page 21: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Two-sided factorization• Hessenberg, tridiagonal factorizations for eigenvalue problems

16

Level 2BLAS on

GPU

Level 2BLAS on

CPU

Level 3 BLAS on

GPU

Panel Trailing matrixA = QTAQyi = Avi

column ai

Page 22: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

17

0

20

40

60

80

100

120

140

160

180

2048 5184 10112 20000

3 GPUs 2 GPUs 1 GPU (MAGMA 1.1) CPU (MKL)

MAGMA Hessenberg in double precision

Gflo

p/s

Matrix size

Keeneland system, using one node3 Nvidia GPUs (M2070 @ 1.1 GHz, 5.4 GB)2 x 6 Intel Cores (X5660 @ 2.8 GHz, 23 GB)

Page 23: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Autotuning kernels

• Parameterize code,e.g., blocksize

• Test 100 – 500 kernels

• Improved zgemm from308 to 341 Gflops/s

• Improved up to 2x on specific rectangular shapes

18

� ���� ���� ���� ���� �����

���

���

���

���

���

���

��

���

��

�� ��������

�������

�����

�����

�����

����

MAGMA BLAS matrix multiply

Page 24: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Scheduling DAGs

19

48 coresMatrix is 4000 x 4000, tile is 200 x 200.

Page 25: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Dynamic scheduling• Parallelism using DAG-based runtime scheduler

• One-sided factorizations and solvers using StarPU

20

// Sequential Tile Choleskyfor k = 1 .. ntiles! dpotrf( Akk )! for i = k+1 .. ntiles! ! dtrsm( Akk, Aik ) ! for i = k+1 .. ntiles! ! dsyrk( Aik, Aii )! ! for j = i+1 .. ntiles! ! ! dgemm( Ajk, Aik, Aij )

// Hybrid Tile Choleskyfor k = 1 .. ntiles! Insert_Task( dpotrf, ... )! for i = k+1 .. ntiles! ! Insert_Task( dtrsm, ... ) ! for i = k+1 .. ntiles! ! Insert_Task( dsyrk, ... )! ! for j = i+1 .. ntiles! ! ! Insert_Task( dgemm, ... )

Page 26: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Documentation• Nvidia Guides

http://developer.nvidia.com/nvidia-gpu-computing-documentation

• MAGMAhttp://icl.eecs.utk.edu/magma

• PLASMAhttp://icl.eecs.utk.edu/plasma

• BLAS and LAPACK indexhttp://web.eecs.utk.edu/~mgates3/docs/lapack.html

21

Page 27: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

Collaborators / Support

• University of Tennessee, Knoxville

• University of California, Berkeley

• University of Colorado, Denver

• INRIA, France

• KAUST, Saudi Arabia

22

Page 28: MAGMA - ICL UTKicl.cs.utk.edu/news_pub/submissions/162-libs-magma.pdf · MAGMA Matrix Algebra on G ... Mark Gates February 2012 1. ParLab Been Chip 3 1.E-01 1.E+00 1.E+01 1.E+02 1.E+03

23