Algorithms as Multilinear Tensor Equations

48
Algorithms as Multilinear Tensor Equations Edgar Solomonik Department of Computer Science ETH Zurich University of Colorado, Boulder February 23, 2016 Edgar Solomonik Algorithms as Multilinear Tensor Equations 1/32

Transcript of Algorithms as Multilinear Tensor Equations

Page 1: Algorithms as Multilinear Tensor Equations

Algorithms as Multilinear Tensor Equations

Edgar Solomonik

Department of Computer ScienceETH Zurich

University of Colorado, Boulder

February 23, 2016

Edgar Solomonik Algorithms as Multilinear Tensor Equations 1/32

Page 2: Algorithms as Multilinear Tensor Equations

Pervasive paradigms in scientific computing

What commonalities exist in simulation and data analysis applications?

multidimensional datasets (observations, discretizations)

higher-order relations: equations, maps, graphs, hypergraphs

sparsity and symmetry in structure of relations

relations lead to solution directly or as an iterative criterion

algebraic descriptions of datasets and relations

Edgar Solomonik Algorithms as Multilinear Tensor Equations 2/32

Page 3: Algorithms as Multilinear Tensor Equations

Pervasive paradigms in scientific computing

What abstractions are needed in high performance computing?

data abstractions reflecting native dimensionality and structure

functions orchestrating communication and synchronization

provably efficient building-block algorithms

Edgar Solomonik Algorithms as Multilinear Tensor Equations 3/32

Page 4: Algorithms as Multilinear Tensor Equations

Outline

1 Motivating applications

2 Symmetry-preserving tensor algorithms

3 Communication-avoiding parallel algorithms

4 A massively-parallel tensor framework

5 Applications to electronic structure calculations

6 Conclusion

Edgar Solomonik Algorithms as Multilinear Tensor Equations 4/32

Page 5: Algorithms as Multilinear Tensor Equations

Matrix computations ⊂ tensor computations

Tensors are convenient abstractions for multidimensional data

one type of object for any homogeneous dataset

enable expression of symmetries

reveal sparsity structure of relations in multidimensional space

Tensor computations naturally extend numerical linear algebra

= often reduce to or employ matrix algorithms

can leverage high performance matrix libraries

+ high-order tensors can ‘act’ as many matrix unfoldings

+ symmetries lower memory footprint and cost

+ tensor factorizations (CP, Tucker, tensor train, ...)

Edgar Solomonik Algorithms as Multilinear Tensor Equations 5/32

Page 6: Algorithms as Multilinear Tensor Equations

Applications of high-order tensor representations

Numerical solution to differential equations

nonlinear terms and differential operators

truncated Taylor series expansions

Computer vision and graphics

2D image ⊗ angle ⊗ time

compression (tensor factorizations, sparsity)

Machine learning

sparse multi-feature discrete datasets

reduced-order models (tensor factorizations)

Graph computations

hypergraphs, time-dependent graphs

clustering/partitioning/path-finding (eigenvector computations)

Divide-and-conquer algorithms representable by tensor folding

bitonic sort, FFT, scans

Edgar Solomonik Algorithms as Multilinear Tensor Equations 6/32

Page 7: Algorithms as Multilinear Tensor Equations

Applications to quantum systems

Manybody Schrodinger equation

“curse of dimensionality” – exponential state space

Condensed matter physics

tensor network models (e.g. DMRG), tensor per lattice site

highly symmetric multilinear tensor representation

exponential state space localized → factorized tensor form

Quantum chemistry (electronic structure calculations)

models of molecular structure and chemical reactions

methods for calculating electronic correlation:

“Post Hartree-Fock”: configuration interaction, coupled cluster,Møller-Plesset perturbation theory

multi-electron states as tensors,e.g. electron ⊗ electron ⊗ orbital ⊗ orbital

nonlinear equations of partially (anti)symmetric tensors

interactions diminish with distance → sparsity, low rankEdgar Solomonik Algorithms as Multilinear Tensor Equations 7/32

Page 8: Algorithms as Multilinear Tensor Equations

Exploiting symmetry in tensors

Tensor symmetry (e.g. Aij = Aji ) reduces memory and cost

for order d tensor, d! less memory

dot product∑

i ,j AijBij = 2∑

i<j AijBij +∑

i AiiBii

matrix-vector multiplication1

ci =∑j

Aijbj =∑j

Aij(bi + bj)−(∑

j

Aij

)bi

rank-2 vector outer product1

Cij = aibj + ajbi = (ai + aj)(bi + bj)− aibi − ajbj

squaring a symmetric matrix (or AB + BA)1

Cij =∑k

AikAkj =∑k

(Aik + Akj + Aij)2 − . . .

for order ω contraction, ω! fewer multiplies 1

1S., Demmel; Technical Report, ETH Zurich, 2015.

Edgar Solomonik Algorithms as Multilinear Tensor Equations 8/32

Page 9: Algorithms as Multilinear Tensor Equations

Symmetry preserving algorithms

By exploiting symmetry, reduce multiplies (but increase adds)2

partially symmetric contractions

symmetry preserving algorithm can be nested over each index groupreduction in multiplies → reduction in nested callscost reductions in coupled cluster:2X-9X for select contractions, 1.3X-2.1X for methods

algorithms generalize to most antisymmetric tensor contractions

for Hermitian tensors, multiplies cost 3X more than adds

Hermitian matrix multiplication and tridiagonal reduction (BLAS andLAPACK routines) with 25% fewer ops

(2/3)n3 bilinear rank for squaring a nonsymmetric matrix

allows blocking of symmetric contractions into smaller symmetriccontractions

2S., Demmel; Technical Report, ETH Zurich, 2015.

Edgar Solomonik Algorithms as Multilinear Tensor Equations 9/32

Page 10: Algorithms as Multilinear Tensor Equations

Beyond computation cost

Algorithms should minimize communication, not just computation

data movement and synchronization cost more energy than flops

two types of data movement:

vertical (intranode memory–cache)horizontal (internode network transfers)

parallel algorithm design involves tradeoffs: computation vscommunication vs synchronization

lower bounds and parameterized algorithms provide optimal solutionswithin a well-defined tuning space

Edgar Solomonik Algorithms as Multilinear Tensor Equations 10/32

Page 11: Algorithms as Multilinear Tensor Equations

Cost model for parallel algorithms

Given a schedule of work and communication tasks on p processors,consider the following costs, accumulated along chains of tasks (as inα− β, BSP, and LogGP models),

F – computation cost

Q – vertical communication cost

W – horizontal communication cost

S – synchronization cost

Edgar Solomonik Algorithms as Multilinear Tensor Equations 11/32

Page 12: Algorithms as Multilinear Tensor Equations

Communication lower bounds: previous work

Multiplication of n × n matrices

horizontal communication lower bound3

WMM = Ω

(n2

p2/3

)memory-dependent horizontal communication lower bound4

WMM = Ω

(n3

p√M

)with M = cn2/p memory, hope to obtain communication cost

W = O(n2/√cp)

libraries like ScaLAPACK, Elemental optimal only for c = 1

3Aggarwal, Chandra, Snir, TCS, 1990

4Irony, Toledo, Tiskin, JPDC, 2004

Edgar Solomonik Algorithms as Multilinear Tensor Equations 12/32

Page 13: Algorithms as Multilinear Tensor Equations

Communication-efficient matrix multiplication

Communication-avoiding algorithms for matrix multiplication have beenstudied extensively5

They continue to be attractive on modern architectures6

0

20

40

60

80

100

256 512 1024 2048

Per

cent

age

of m

achi

ne p

eak

#nodes

2.5D MM on BG/P (n=65,536)

2.5D SUMMA2D SUMMA

ScaLAPACK PDGEMM

0

50

100

150

200

256 512 1024 2048 4096G

igaf

lop/

s/no

de

#nodes

Matrix multiplication strong scaling on Mira (BG/Q)

2.5D MM n=65,5362D MM n=65,536

2.5D MM n=16,3842D MM n=16,384

5Berntsen, Par. Comp., 1989; Agarwal, Chandra, Snir, TCS, 1990; Agarwal, Balle, Gustavson, Joshi, Palkar, IBM, 1995;

McColl, Tiskin, Algorithmica, 1999; ...6

S., Bhatele, Demmel, SC, 2011

Edgar Solomonik Algorithms as Multilinear Tensor Equations 13/32

Page 14: Algorithms as Multilinear Tensor Equations

Synchronization cost lower bounds

Unlike matrix multiplication, many algorithms in numerical linear algebrahave polynomial depth (contain a long dependency path)

matrix multiplication synchronization cost bound7

SMM = Θ

(n3

pM3/2

)algorithms for Cholesky, LU, QR, SVD do not attain this bound

low granularity computation increases synchronization cost

7Ballard, Demmel, Holtz, Schwartz, SIAM JMAA, 2011

Edgar Solomonik Algorithms as Multilinear Tensor Equations 14/32

Page 15: Algorithms as Multilinear Tensor Equations

Tradeoffs in the diamond DAG

Computation vs synchronization tradeoff for the n × n diamond DAG,8

F · S = Ω(n2)

We generalize this idea9

additionally consider horizontal communication

allow arbitrary (polynomial or exponential) interval expansion

8Papadimitriou, Ullman, SIAM JC, 1987

9S., Carson, Knight, Demmel, SPAA 2014 (extended version, JPDC 2016)

Edgar Solomonik Algorithms as Multilinear Tensor Equations 15/32

Page 16: Algorithms as Multilinear Tensor Equations

Tradeoffs involving synchronization

We apply tradeoff lower bounds to dense linear algebra algorithms,represented via dependency hypergraphs:a

For triangular solve with an n × n matrix,

FTRSV · STRSV = Ω(n2)

For Cholesky of an n × n matrix,

FCHOL · S2CHOL = Ω

(n3)

WCHOL · SCHOL = Ω(n2)

Proof employs classical Loomis-Whitney inequality:

for any R ⊂ N× N× N, three projections of R onto N× N have total sizeat least |R|2/3

aS., Carson, Knight, Demmel, SPAA 2014 (extended version, JPDC 2016)

Edgar Solomonik Algorithms as Multilinear Tensor Equations 16/32

Page 17: Algorithms as Multilinear Tensor Equations

Communication-efficient LU factorization

For any c ∈ [1, p1/3], use cn2/p memory per processor and obtain

WLU = O(n2/√cp), SLU = O(

√cp)

0

20

40

60

80

100

256 512 1024 2048

Per

cent

age

of m

achi

ne p

eak

#nodes

LU with tournament pivoting on BG/P (n=65,536)

ideal scaling2.5D LU

2D LUScaLAPACK PDGETRF

LU with pairwise pivoting10 extended to tournament pivoting11

first implementation of a communication-optimal LU algorithm11

10Tiskin, FGCS, 2007

11S., Demmel, Euro-Par, 2011

Edgar Solomonik Algorithms as Multilinear Tensor Equations 17/32

Page 18: Algorithms as Multilinear Tensor Equations

Communication-efficient QR factorization

WQR = O(n2/√cp),SQR = O(

√cp) using Givens rotations12

Householder form can be reconstructed quickly from TSQR13

optimal QR communication and synchronization (modulo log factors)costs can be obtained with Householder representation14

Householder aggregation yields performance improvements

0

5

10

15

20

144 288 576 1152 2304 4608 9216

Tera

flops

#cores

QR weak scaling on Cray XE6 (n=15K to n=131K)

Two-Level CAQR-HRElemental QR

ScaLAPACK QR

12Tiskin, FGCS, 2007

13Ballard, Demmel, Grigori, Jacquelin, Nguyen, S., IPDPS, 2014

14S., UCB, 2014

Edgar Solomonik Algorithms as Multilinear Tensor Equations 18/32

Page 19: Algorithms as Multilinear Tensor Equations

Communication-efficient eigenvalue computation

For the dense symmetric matrix eigenvalue problema

WSE = O(n2/√cp), SQR = O(

√cp log2 p)

above costs obtained by left-looking algorithm with Householderaggregation, however, with increased vertical communication

successive band reduction minimizes both communication costs

aS., UCB, 2014. S., Hoefler, Demmel, in preparation

Edgar Solomonik Algorithms as Multilinear Tensor Equations 19/32

Page 20: Algorithms as Multilinear Tensor Equations

Synchronization tradeoffs in stencils

Our lower bound analysis extends to sparse iterative methods:15

For computing s applications of a (2m + 1)d -point stencil

FSt · SdSt = Ω

(m2d · sd+1

)WSt · Sd−1

St = Ω(md · sd

)proof requires generalization of Loomis-Whitney inequality to order dset and order d − 1 projections

time-blocking lowers synchronization and vertical communication costs,but raises horizontal communication

we suggest alternative approach that minimizes vertical and horizontalcommunication, but not synchronization

15S., Carson, Knight, Demmel, SPAA 2014 (extended version, JPDC 2016)

Edgar Solomonik Algorithms as Multilinear Tensor Equations 20/32

Page 21: Algorithms as Multilinear Tensor Equations

Beyond the Loomis-Whitney inequalities

Loomis-Whitney inequalities are not sufficient for all computations

symmetry preserving tensor contraction algorithms have arbitrary orderprojections from order d set

bilinear algorithms16 provide a more general framework

a bilinear algorithm is defined by matrices F (A),F (B),F (C),

c = F (C)[(F (A)Ta) (F (B)Tb)]

where is the Hadamard (pointwise) product

communication lower bounds derived based on matrix rank17

16Pan, Springer, 1984

17S., Hoefler, Demmel, in preparation

Edgar Solomonik Algorithms as Multilinear Tensor Equations 21/32

Page 22: Algorithms as Multilinear Tensor Equations

Communication cost of symmetry preserving algorithms

For contraction of order s + v tensor with order v + t tensor18

symmetry preserving algorithm requires (s+v+t)!s!v !t! fewer multiplies

matrix-vector-like algorithms (min(s, v , t) = 0)

vertical communication dominated by largest tensorhorizontal communication asymptotically greater if only unique elementsare stored and s 6= v 6= t

matrix-matrix-like algorithms (min(s, v , t) > 0)

vertical and horizontal communication costs asymptotically greater forsymmetry preserving algorithm when s 6= v 6= t

18S., Hoefler, Demmel; Technical Report, ETH Zurich, 2015.

Edgar Solomonik Algorithms as Multilinear Tensor Equations 22/32

Page 23: Algorithms as Multilinear Tensor Equations

Tensor algebra as a programming abstraction

Cyclops Tensor Framework19

contraction/summation/functions of tensors

distributed symmetric-packed/sparse storage via cyclic layout

parallelization via MPI+OpenMP(+CUDA)

19S., Hammond, Demmel, UCB, 2011. S., Matthews, Hammond, Demmel, IPDPS, 2013

Edgar Solomonik Algorithms as Multilinear Tensor Equations 23/32

Page 24: Algorithms as Multilinear Tensor Equations

Tensor algebra as a programming abstraction

Cyclops Tensor Framework

contraction/summation/functions of tensors

distributed symmetric-packed/sparse storage via cyclic layout

parallelization via MPI+OpenMP(+CUDA)

Jacobi iteration (solves Ax = b iteratively) example code snippet

Vector <> Jacobi(Matrix <> A, Vector <> b, int n)Matrix <> R(A);R["ii"] = 0.0;Vector <> x(n), d(n), r(n);Function <> inv ([]( double & d) return 1./d; );d["i"] = inv(A["ii"]); // set d to inverse of diagonal of Ado

x["i"] = d["i"]*(b["i"]-R["ij"]*x["j"]);r["i"] = b["i"]-A["ij"]*x["j"]; // compute residual

while (r.norm2() > 1.E-6); // check for convergencereturn x;

Edgar Solomonik Algorithms as Multilinear Tensor Equations 23/32

Page 25: Algorithms as Multilinear Tensor Equations

Tensor algebra as a programming abstraction

Cyclops Tensor Framework

contraction/summation/functions of tensors

distributed symmetric-packed/sparse storage via cyclic layout

parallelization via MPI+OpenMP(+CUDA)

Møller-Plesset perturbation theory (MP3) code snippet

Z["abij"] += Fab["af"]*T["fbij"];Z["abij"] -= Fij["ni"]*T["abnj"];Z["abij"] += 0.5*Vabcd["abef"]*T["efij"];Z["abij"] += 0.5*Vijkl["mnij"]*T["abmn"];Z["abij"] -= Vaibj["amei"]*T["ebmj"];

Edgar Solomonik Algorithms as Multilinear Tensor Equations 23/32

Page 26: Algorithms as Multilinear Tensor Equations

Betweenness centrality

Betweenness centrality code snippet, for k of n nodes

void btwn_central(Matrix <int > A, Matrix <path > P, int n, int k)Monoid <path > mon(...,

[]( path a, path b)if (a.w<b.w) return a;else if (b.w<a.w) return b;else return path(a.w, a.m+b.m);

, ...);

Matrix <path > Q(n,k,mon); // shortest path matrixQ["ij"] = P["ij"];

Function <int ,path > append ([]( int w, path p)return path(w+p.w, p.m);

; );

for (int i=0; i<n; i++)Q["ij"] = append(A["ik"],Q["kj"]);

...

Edgar Solomonik Algorithms as Multilinear Tensor Equations 24/32

Page 27: Algorithms as Multilinear Tensor Equations

Performance of CTF for dense computations

CTF is highly tuned for massively-parallel machines

virtualized multidimensional processor grids

topology-aware mapping and collective communication

performance-model-driven decomposition done at runtime

optimized redistribution kernels for tensor transposition

8

16

32

64

128

256

512

1024

2048

4096 8192 16384 32768 65536 131072 262144

Tera

flop/

s

#cores

BG/Q matrix multiplication

CTFScalapack

Edgar Solomonik Algorithms as Multilinear Tensor Equations 25/32

Page 28: Algorithms as Multilinear Tensor Equations

Performance of CTF for sparse computations

MP3 leveraging sparse-dense tensor contractionsa

0 4 8

12 16 20 24 28 32 36 40 44

24 48 96 192 384

seco

nds/

itera

tion

#cores

Weak scaling of MP3 (m=40, n=160 on 24 cores)

dense16% sparse8% sparse4% sparse2% sparse1% sparse

0

2

4

6

8

10

12

14

16

24 48 96 192 384 768

seco

nds/

itera

tion

#cores

Strong scaling of MP3 with m=40, n=160

dense16% sparse8% sparse4% sparse2% sparse1% sparse

All-pairs shortest-paths based on path doubling with sparsificationa

0

20

40

60

80

100

120

140

24 48 96 192 384

seco

nds

#cores

Weak scaling of APSP (n=2K on 24 cores)

regular path doublingsparse path doubling

0

4

8

12

16

20

24

24 48 96 192 384 768

seco

nds

#cores

Strong scaling of APSP with n=2K

regular path doublingsparse path doubling

aS., Hoefler, Demmel, arXiv, 2015

Edgar Solomonik Algorithms as Multilinear Tensor Equations 26/32

Page 29: Algorithms as Multilinear Tensor Equations

Coupled cluster methods

Coupled cluster provides a systematically improvable approximation to themanybody time-independent Schrodinger equation HΨ = EΨ

the Hamiltonian has one- and two- electron components H = F + V

Hartree-Fock (SCF) computes mean-field Hamiltonian: F , V

Coupled-cluster methods (CCSD, CCSDT, CCSDTQ) considertransitions of (doubles, triples, and quadruples) of electrons tounoccupied orbitals, encoded by tensors T1, T2, T3, T4

they use an exponential ansatz for the wavefunction,

Ψ = eT1+T2+T3+T4φ

where φ is a fully-antisymmetric simple Slater determinant

expanding Ψ as a Taylor series → nonlinear equations in T ,F ,V

Edgar Solomonik Algorithms as Multilinear Tensor Equations 27/32

Page 30: Algorithms as Multilinear Tensor Equations

CCSD using CTF

Extracted from Aquarius (Devin Matthews’ code,https://github.com/devinamatthews/aquarius)

FMI["mi"] += 0.5*WMNEF["mnef"]*T2["efin"];WMNIJ["mnij"] += 0.5*WMNEF["mnef"]*T2["efij"];FAE["ae"] -= 0.5*WMNEF["mnef"]*T2["afmn"];WAMEI["amei"] -= 0.5*WMNEF["mnef"]*T2["afin"];

Z2["abij"] = WMNEF["ijab"];Z2["abij"] += FAE["af"]*T2["fbij"];Z2["abij"] -= FMI["ni"]*T2["abnj"];Z2["abij"] += 0.5*WABEF["abef"]*T2["efij"];Z2["abij"] += 0.5*WMNIJ["mnij"]*T2["abmn"];Z2["abij"] -= WAMEI["amei"]*T2["ebmj"];

CTF-based CCSD codes exist in Aquarius, QChem, VASP, and Psi4

Edgar Solomonik Algorithms as Multilinear Tensor Equations 28/32

Page 31: Algorithms as Multilinear Tensor Equations

Comparison with NWChem

NWChem is the most commonly-used distributed-memory quantumchemistry method suite

provides CCSD and CCSDT

derives equations via Tensor Contraction Engine (TCE)

generates contractions as blocked loops leveraging Global Arrays

4

16

64

256

1024

1 2 4 8 16 32 64 128 256

seco

nds

#nodes

Strong scaling CCSD on Edison

NWChem w20w15w10w8

Aquarius-CTF w20w15w10w8

4

16

64

256

1024

1 2 4 8 16 32 64 128 256

seco

nds

#nodes

Strong scaling CCSDT on Edison

NWChem w3w2

Aquarius-CTF w4w3w2

Edgar Solomonik Algorithms as Multilinear Tensor Equations 29/32

Page 32: Algorithms as Multilinear Tensor Equations

Coupled cluster on IBM BlueGene/Q and Cray XC30

CCSD up to 55 (50) water molecules with cc-pVDZCCSDT up to 10 water molecules with cc-pVDZa

4

8

16

32

64

128

256

512

1024

512 1024 2048 4096 8192 16384 32768

Tera

flops

#nodes

Weak scaling on BlueGene/Q

Aquarius-CTF CCSDAquarius-CTF CCSDT

10

20

30

40

50

60

512 1024 2048 4096 8192 16384

Gig

aflo

ps/n

ode

#nodes

Weak scaling on BlueGene/Q

Aquarius-CTF CCSDAquarius-CTF CCSDT

1

2 4

8 16

32 64

128 256

512

32 64 128 256 512 1024 2048 4096

Tera

flops

#nodes

Weak scaling on Edison

Aquarius-CTF CCSDAquarius-CTF CCSDT

50

100

150

200

250

300

350

32 64 128 256 512 1024 2048 4096

Gig

aflo

ps/n

ode

#nodes

Weak scaling on Edison

Aquarius-CTF CCSDAquarius-CTF CCSDT

aS., Matthews, Hammond, Demmel, JPDC, 2014

Edgar Solomonik Algorithms as Multilinear Tensor Equations 30/32

Page 33: Algorithms as Multilinear Tensor Equations

Summary of contributions

Novel results described in this talk:symmetry preserving algorithms

reduce number of multiplications in symmetric contractions by ω!reduce cost of basic Hermitian matrix operations by 25%reduce cost of some contractions in coupled cluster by 2X in CCSD (1.3Xoverall), 4X in CCSDT (2.1X overall), 9X in CCSDTQ

communication and synchronization lower boundstradeoffs: synchronization vs computation or communication in TRSV,Cholesky, and stencilsrank-based lower bounds to analyze symmetric contractions

communication avoiding dense matrix factorizationsnew algorithms and implementations with up to p1/6 less communicationfor LU, QR, symmetric eigenvalue problemspeed-ups of up to 2X for LU and QR over vendor-optimized libraries

Cyclops Tensor Frameworkfirst fully robust distributed-memory tensor contraction librarysupports symmetry, sparsity, general algebraic structurescoupled cluster performance more than 10X faster than state-of-the-art,reaching 1 petaflop/s performance

Edgar Solomonik Algorithms as Multilinear Tensor Equations 31/32

Page 34: Algorithms as Multilinear Tensor Equations

Future work

open theoretical problems

relation of symmetry preserving algorithms to displacement rank andbilinear algorithm complexityexploiting symmetry across tensors (e.g. in tensor networks)synchronization lower bounds for QR and SVDtight communication lower bounds for sparse–dense multiplycommunication-avoiding algorithms for tensor factorizations

high performance implementations

nested symmetry preserving algorithmscommunication-optimal QR, improvements to symmetric eigensolvertensor factorizations as part of CTFoptimized evaluation and scheduling of tensor expressionsextensions to sparsity and algebraic structure support in CTF

programming abstractions for applications

representations for factorized tensors (tensor networks)block-sparsity and block-factorization of tensorsexpansion of application-based feedback loop

Edgar Solomonik Algorithms as Multilinear Tensor Equations 32/32

Page 35: Algorithms as Multilinear Tensor Equations

Backup slides

Edgar Solomonik Algorithms as Multilinear Tensor Equations 33/32

Page 36: Algorithms as Multilinear Tensor Equations

Symmetry preserving algorithm vs Strassen’s algorithm

1

2

4

8

16

32

64

10 100 1000 10000 100000 1e+06

[nω/(s

!t!v!

)] / #

mul

tiplic

atio

ns(s

peed

-up

over

cla

ssic

al d

irect

eva

luat

ion

alg.

)

ns/s! (matrix dimension)

Symmetry preserving alg. vs Strassen’s alg. (s=t=v=ω/3)

Strassen’s algorithmSym. preserving ω=6Sym. preserving ω=3

Edgar Solomonik Algorithms as Multilinear Tensor Equations 34/32

Page 37: Algorithms as Multilinear Tensor Equations

Nesting of bilinear algorithms

Given two bilinear algorithms:

Λ1 =(F(A)1 ,F

(B)1 ,F

(C)1 )

Λ2 =(F(A)2 ,F

(B)2 ,F

(C)2 )

We can nest them by computing their tensor product

Λ1 ⊗ Λ2 :=(F(A)1 ⊗ F

(A)2 ,F

(B)1 ⊗ F

(B)2 ,F

(C)1 ⊗ F

(C)2 )

rank(Λ1 ⊗ Λ2) = rank(Λ1) · rank(Λ2)

Edgar Solomonik Algorithms as Multilinear Tensor Equations 35/32

Page 38: Algorithms as Multilinear Tensor Equations

Block-cyclic algorithm for s-step methods

For s-steps of a (2m + 1)d -point stencil with block-size of H1/d/m,

WKr = O

(msnd

H1/dp

)SKr = O(snd/(pH)) QKr = O

(msnd

H1/dp

)which are good when H = Θ(nd/p), so the algorithm is useful when thecache size is a bit smaller than nd/p

Edgar Solomonik Algorithms as Multilinear Tensor Equations 36/32

Page 39: Algorithms as Multilinear Tensor Equations

2.5D LU on MIC

100

150

200

250

300

350

400

450

16 32 64 128 256

Gig

aflo

p/s/

node

#nodes

LU factorization strong scaling on Stampede (MIC + Sandy Bridge)

2.5D hybrid LU n=131,0722D hybrid LU n=131,072

2.5D pure-cpu LU n=131,0722.5D hybrid LU n=65,536

2D hybrid LU n=65,5362.5D pure-cpu LU n=65,536

Edgar Solomonik Algorithms as Multilinear Tensor Equations 37/32

Page 40: Algorithms as Multilinear Tensor Equations

Topology-aware mapping on BG/Q

0

20

40

60

80

100

256 512 1024 2048 4096

Gig

aflo

p/s/

node

#nodes

LU factorization strong scaling on Mira (BG/Q), n=65,536

2D LU, custom mapping2D LU, default mapping

Edgar Solomonik Algorithms as Multilinear Tensor Equations 38/32

Page 41: Algorithms as Multilinear Tensor Equations

Symmetric matrix representation

Edgar Solomonik Algorithms as Multilinear Tensor Equations 39/32

Page 42: Algorithms as Multilinear Tensor Equations

Blocked distributions of a symmetric matrix

Edgar Solomonik Algorithms as Multilinear Tensor Equations 40/32

Page 43: Algorithms as Multilinear Tensor Equations

Cyclic distribution of a symmetric matrix

Edgar Solomonik Algorithms as Multilinear Tensor Equations 41/32

Page 44: Algorithms as Multilinear Tensor Equations

Our CCSD factorization

Credit to John F. Stanton and Jurgen Gauss

τ abij = tabij +1

2PabP

ij t

ai t

bj ,

Fme = f me +

∑fn

vmnef t fn ,

F ae = (1− δae)f ae −

∑m

Fme tam −

1

2

∑mnf

vmnef tafmn +

∑fn

vanef tfn ,

Fmi = (1− δmi )f

mi +

∑e

Fme tei +

1

2

∑nef

vmnef tefin +

∑fn

vmnif t fn ,

Edgar Solomonik Algorithms as Multilinear Tensor Equations 42/32

Page 45: Algorithms as Multilinear Tensor Equations

Our CCSD factorization

Wmnei = vmn

ei +∑f

vmnef t fi ,

Wmnij = vmn

ij + P ij

∑e

vmnie tej +

1

2

∑ef

vmnef τ

efij ,

W amie = v am

ie −∑n

Wmnei tan +

∑f

vmaef t fi +

1

2

∑nf

vmnef tafin ,

W amij = v am

ij + P ij

∑e

v amie tej +

1

2

∑ef

v amef τ

efij ,

zai = f ai −∑m

Fmi tam +

∑e

f ae tei +

∑em

vmaei tem +

∑em

v aeim F

me +

1

2

∑efm

v amef τ

efim

− 1

2

∑emn

Wmnei teamn,

zabij = v abij + P i

j

∑e

v abie tej + Pa

bPij

∑me

W amie tebmj − Pa

b

∑m

W amij tbm

+ Pab

∑e

F ae t

ebij − P i

j

∑m

Fmi tabmj +

1

2

∑ef

v abef τ

efij +

1

2

∑mn

Wmnij τ abmn,

Edgar Solomonik Algorithms as Multilinear Tensor Equations 43/32

Page 46: Algorithms as Multilinear Tensor Equations

Stability of symmetry preserving algorithms

Edgar Solomonik Algorithms as Multilinear Tensor Equations 44/32

Page 47: Algorithms as Multilinear Tensor Equations

Performance breakdown on BG/Q

Performance data for a CCSD iteration with 200 electrons and 1000orbitals on 4096 nodes of Mira4 processes per node, 16 threads per processTotal time: 18 minsv -orbitals, o-electrons

kernel % of time complexity architectural bounds

DGEMM 45% O(v4o2/p) flops/mem bandwidth

broadcasts 20% O(v4o2/p√M) multicast bandwidth

prefix sum 10% O(p) allreduce bandwidth

data packing 7% O(v2o2/p) integer ops

all-to-all-v 7% O(v2o2/p) bisection bandwidth

tensor folding 4% O(v2o2/p) memory bandwidth

Edgar Solomonik Algorithms as Multilinear Tensor Equations 45/32

Page 48: Algorithms as Multilinear Tensor Equations

Tiskin’s path doubling algorithm

Tiskin gives a way to do path-doubling in F = O(n3/p) operations. Wecan partition each Ak by path size (number of edges)

Ak = I⊕ Ak(1)⊕ Ak(2)⊕ . . .⊕ Ak(k)

where each Ak(l) contains the shortest paths of up to k ≥ l edges, whichhave exactly l edges. We can see that

Al(l) ≤ Al+1(l) ≤ . . . ≤ An(l) = A∗(l),

in particular A∗(l) corresponds to a sparse subset of Al(l).The algorithm works by picking l ∈ [k/2, k] and computing

(I⊕ A)3k/2 ≤ (I⊕ Ak(l))⊗ Ak ,

which finds all paths of size up to 3k/2 by taking all paths of size exactlyl ≥ k/2 followed by all paths of size up to k .

Edgar Solomonik Algorithms as Multilinear Tensor Equations 46/32