12
A preliminary analysis of Cyclops Tensor Framework Edgar Solomonik Jeff Hammond James Demmel Electrical Engineering and Computer Sciences University of California at Berkeley Technical Report No. UCB/EECS-2012-29 http://www.eecs.berkeley.edu/Pubs/TechRpts/2012/EECS-2012-29.html March 9, 2012

A preliminary analysis of Cyclops Tensor Framework · 2012-03-09 · Cyclops Tensor Framework since they are largely orthog-onal components. However, the tuning decisions done by

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: A preliminary analysis of Cyclops Tensor Framework · 2012-03-09 · Cyclops Tensor Framework since they are largely orthog-onal components. However, the tuning decisions done by

A preliminary analysis of Cyclops Tensor Framework

Edgar SolomonikJeff HammondJames Demmel

Electrical Engineering and Computer SciencesUniversity of California at Berkeley

Technical Report No. UCB/EECS-2012-29

http://www.eecs.berkeley.edu/Pubs/TechRpts/2012/EECS-2012-29.html

March 9, 2012

Page 2: A preliminary analysis of Cyclops Tensor Framework · 2012-03-09 · Cyclops Tensor Framework since they are largely orthog-onal components. However, the tuning decisions done by

Copyright © 2012, by the author(s).All rights reserved.

Permission to make digital or hard copies of all or part of this work forpersonal or classroom use is granted without fee provided that copies arenot made or distributed for profit or commercial advantage and that copiesbear this notice and the full citation on the first page. To copy otherwise, torepublish, to post on servers or to redistribute to lists, requires prior specificpermission.

Page 3: A preliminary analysis of Cyclops Tensor Framework · 2012-03-09 · Cyclops Tensor Framework since they are largely orthog-onal components. However, the tuning decisions done by

A preliminary analysis of Cyclops Tensor Framework

Edgar SolomonikUniv. of California, Berkeley

Department of [email protected]

Jeff HammondArgonne National Lab

Leadership Computing Facility

James DemmelUniv. of California, Berkeley

Department of EECS

ABSTRACTCyclops (cyclic-operations) Tensor Framework (CTF) 1 isa distributed library for tensor contractions. CTF aims toscale high-dimensional tensor contractions done in CoupledCluster calculations on massively-parallel supercomputers.The framework preserves tensor symmetry by subdividingtensors cyclically, producing a highly regular parallel de-composition. The parallel decomposition effectively hidesany high dimensional structure of tensors reducing the com-plexity of the distributed contraction algorithm to knownlinear algebra methods for matrix multiplication. We alsodetail the automatic topology-aware mapping framework de-ployed by CTF, which maps tensors of any dimension andstructure onto torus networks of any dimension. We employvirtualization to provide completely general mapping sup-port while maintaining perfect load balance. Performanceof a preliminary version of CTF on the IBM Blue Gene/Pand Cray XE6 supercomputers shows highly efficient weak-scaling, demonstrating the viability of our approach.

1. INTRODUCTIONCoupled Cluster (CC) is a computational method for com-

puting an approximate solution to the time-independentSchrodinger equation of the form

H|Ψ〉 = E|Ψ〉,

where H is the Hamiltonian, E is the energy, and Ψ is thewave-function. In CC, the approximate wave-function is de-fined in exponential form

|Ψ〉 = eT |Φ〉

where Φ〉 is the Slater determinant. For an N -electron sys-

1Software and documentation publicly available under aBSD license: http://www.eecs.berkeley.edu/~solomon/cyclopstf/index.html

Permission to make digital or hard copies of all or part of this work forpersonal or classroom use is granted without fee provided that copies arenot made or distributed for profit or commercial advantage and that copiesbear this notice and the full citation on the first page. To copy otherwise, torepublish, to post on servers or to redistribute to lists, requires prior specificpermission and/or a fee.Copyright 2011 ACM 978-1-4503-0771-0/11/11 ...$10.00.

tem the Slater determinant is

|Φ〉 =1√N !|φ1φ2...φN |〉.

The T operator in CC has the form

T = T1 + T2 + T3 . . .

where Tn is a 2nth rank (dimension) 2 tensor represent-

ing nth level electron excitations. Each Tn is computedvia a series of tensor contractions on tensors of rank r ∈2, 4, . . . 2n. The specific tensor contractions depend onthe variation of the Coupled Cluster method and can bederived differently. Calculating only T1 and T2 gives themethod commonly known as CCSD (Coupled Cluster Sin-

gles and Doubles). Additional calculation of T3 gives the

CCSDT (T - triples) method and T4 gives the CCSDTQ (Q- quadruples) method.

Computationally, tensor contractions can be reduced tomatrix multiplication via index reordering (transposes). Thisapproach is efficient and commonly used for contractionson fully dense tensors. However, the tensors which arisein Coupled Cluster methods usually have high-dimensionalstructure. In particular, permutational symmetry or anti-symmetry among a set of indices implies that any reorderingof the index set within the tensor will give the same value(with a potential sign change for anti-symmetry). For ex-ample, given a 4D tensor A with permutational symmetryamong indices (i, j, and l but not k), we know

A[i, j, k, l] = A[i, l, k, j] = A[j, i, k, l] = A[j, l, k, i]

= A[l, i, k, j] = A[l, j, k, i].

Permutational symmetry is typically physically motivatedin Coupled Cluster, where matrix or tensor elements arerepresentative of interchanges among electrons or orbitals,which may have symmetric or anti-symmetric effects on theenergy.

In general, permutational symmetry of d indices, impliesthat only one of every d! values in the full tensor is unique.This implies that it suffices to store only 1/d! of the tensordata. In higher-order methods such as CCSDT and CCS-DTQ, which have 3-dimensional and 4-dimensional symme-tries as well as multiple symmetric index groups in sometensors, this memory preservation becomes pervasive. Fur-ther, any symmetry preserved within a contraction (e.g. theoutput C contains indices that were symmetric in operands

2We will use the term dimension to refer to tensor rank ororder.

Page 4: A preliminary analysis of Cyclops Tensor Framework · 2012-03-09 · Cyclops Tensor Framework since they are largely orthog-onal components. However, the tuning decisions done by

A or B), allows for a reduction in computational cost withrespect to a non-symmetric contraction.

The challenge in exploiting high-dimensional symmetry isthat the contractions can no longer be trivially reduced tomatrix multiplication. Further, since the number of possibleas well as encountered (partial) permutational symmetriesgrows exponentially with tensor dimension, it is difficult togeneralize and tiresome to specialize. As a result, most im-plementations exploit tensor symmetry to a limited extentand perform redundant work and communication by unpack-ing or padding tensors.

We present a general parallel decomposition of tensorswhich exploits any partial or full tensor symmetry of anydimension, within any contraction. Our method performsminimal padding and has a regular decomposition that al-lows the algorithm to be mapped to a physical networktopology and executed with no load imbalance. Along withthe algorithms, we detail a preliminary implementation ofCyclops Tensor Framework (CTF), a distributed tensor con-traction library suitable for symmetric high-dimensional ten-sors. On 1,536 nodes of a Cray XE6 supercomputer, the par-allel decomposition used by CTF maintains 50% efficiencyfor symmetric 4D tensors and 25% efficiency for symmet-ric 8D tensors with respect to the peak theoretical floating-point performance. By exploiting symmetry for these ten-sors, the memory footprint is reduced by a factor of 4 foreach 4D symmetric tensor, and by a factor of 576 for the 8Dsymmetric tensors (symmetry also reduces computationalcost with respect to a nonsymmetric contraction by a largefactor, but only for certain contractions).

The main contributions of Cyclops Tensor Framework are

• a symmetry-preserving algorithm for parallel tensorcontractions

• a completely load balanced regular communication withminimal padding requirements

• an automatic topology-aware mapping framework forsymmetric tensor contractions

• highly optimized tensor redistribution kernels

• an efficient implementation of virtualized mapping

In Section 2, we detail previous and related work. In Sec-tion 3, we describe the parallel tensor decomposition algo-rithm. We explain the virtualization and mapping frame-work in Section 4. Finally, we give preliminary performanceresults and analysis on IBM Blue Gene/P and Cray XE6architectures in Section 5 and conclude in Section 6.

2. PREVIOUS WORKWe provide an overview of existing applications and known

algorithms for distributed memory Coupled Cluster and ten-sor contractions. We also discuss parallel numerical linearalgebra algorithms, in particular 2.5D algorithms [21], whichwill serve as a design objective and integrand of CyclopsTensor Framework.

2.1 NWChemNWChem [16] is a computational chemistry software pack-

age developed for massively parallel systems. NWChem in-cludes implementations of Coupled Cluster and tensor con-tractions, which are of interest in our analysis. We will detail

the parallelization scheme used inside NWChem and use itas a basis of comparison for the Cyclops Tensor Frameworkdesign.

NWChem uses the Tensor Contraction Engine (TCE) [5,3, 9], to automatically generate sequences of tensor contrac-tions based on a diagrammatic representation of CoupledCluster schemes. TCE attempts to form the most efficientsequence of contractions while minimizing memory usage ofintermediates (computed tensors that are neither inputs noroutputs). We note that TCE or a similar framework canfunction with any distributed library which actually exe-cutes the contractions. Thus, TCE can be combined withCyclops Tensor Framework since they are largely orthog-onal components. However, the tuning decisions done bysuch a contraction-generation layer should be coupled withperformance and memory usage models of the underlyingcontraction framework.

To parallelize and execute each individual contraction,NWChem employs the Global Arrays (GA) framework [17].Global Arrays is a partitioned global-address space model(PGAS) and allows processors to access (fetch) data whichmay be laid out physically on a different processor. Datamovement within GA is performed via one-sided commu-nication, thereby avoiding synchronization among commu-nicating nodes, while fetching distributed data on-demand.NWChem performs different block tensor sub-contractionson all processors using GA as the underlying communicationlayer to satisfy dependencies and obtain the correct blocks.Since this dynamically scheduled scheme is not load bal-anced, NWChem uses dynamic load balancing among theprocessors. Further, since distribution is hidden by GA, thecommunication pattern is irregular and possibly unbalanced.Cyclops Tensor Framework attempts to eliminate the scal-ability bottlenecks of load imbalance and irregular commu-nication, by using a regular decomposition which employs astructured communication pattern well-suited for torus net-work architectures.

2.2 2.5D algorithmsSince tensor contractions are closely related to matrix

multiplication (MM), it is of much interest to consider thebest known distributed algorithms for MM. Ideally, the per-formance achieved by any given tensor contraction shouldapproach the efficiency of matrix multiplication, and gener-ally the latter is an upper-bound. In particular, we wouldlike to minimize the communication (number of words ofdata moved across the network by any given processor) doneto contract tensors. Since any tensor contraction can betransposed and done as a matrix multiplication, a lowerbound on communication for MM is also valid for tensors.

Given a matrix multiplication of square matrices of dimen-sion n on p processors, with M words of memory on eachprocessor, it is known that some process must communicateat least

W = Ω

(n3

p ·√M

)words of data [13, 4, 12]. If M = Ω(n2/p), so the matricesjust fit in memory the communication lower bound is

W2D = Ω

(n2

√p

).

We label this lower bound as W2D because it is achieved

Page 5: A preliminary analysis of Cyclops Tensor Framework · 2012-03-09 · Cyclops Tensor Framework since they are largely orthog-onal components. However, the tuning decisions done by

by algorithms that are most naturally described on a 2Dprocessor grid. In particular, blocked Cannon’s algorithm [7]and SUMMA [22] achieve this communication bandwidthlower bound. We can also see that, assuming the initialdata is not replicated and load-balanced, there is an absolute(memory-size insensitive) lower-bound [2],

W3D = Ω(M) = Ω

(n2

p2/3

).

This communication lower-bound can be achieved by per-forming 3D blocking on the computational graph rather thansimply distributing the matrices. An old algorithm knownas 3D matrix multiplication has been shown to achieve thiscommunication cost [8, 1, 2, 14].

However, in practice, most applications run with somebounded amount of extra available memory. 2.5D algo-rithms minimize communication cost for any amount of phys-ical memory. In particular, given M = O(cn2/p), where

c ∈ [1, p1/3], the communication lower bound is

W2.5D = Ω

(n2

√cp

).

Using adaptive replication this communication lower-boundcan be achieved for matrix multiplication as well as otherdense linear algebra kernels via the algorithms presentedin [21]. Its also important to note that 2.5D algorithmscan map very efficiently to torus network architectures asdemonstrated in [20]. We would like to achieve the samecommunication costs as well as retain good topological prop-erties in the decomposition of tensors.

3. PARALLEL DECOMPOSITION OF SYM-METRIC TENSORS

To consider the computational and communication costsof tensor contractions we will define a model tensor contrac-tion problem. We consider a partially-symmetric tensor ofdimension d with all sides of length n. Both the operandsand the result have 2 partial-symmetries among each half(d/2) of their indices. We can consider the cost of calculat-ing a contraction over d/2 indices, in fully packed form. Wecan reduce the cost of the full contraction to some multipleof the cost of a contraction where all unpacked elements areassumed to be zero (to compute the full symmetric contrac-tion might require one or multiple of such contractions). A4D example of such a contraction looks like

Ck≤la≤b =

∑ij

Ai≤ja≤b ·B

k≤li≤j .

We study this type of contraction because it has the com-bined complexity of high-dimensional symmetry as well aspartial-symmetry. Further, this contraction can actually befolded into a matrix multiplication, so we can convenientlyanalyze the overhead of high-dimensional blocking with re-spect to the completely optimal approach of matrix multi-plication (which is of course not suitable for general sym-metries). In this model contraction, the packed size of eachtensor per processor is

S(n, d, p) = Θ

(nd

p · ((d/2)!)2

)and the total number of multiplications (flops which must

be performed) per processor is

F (n, d, p) = Θ

(n3d/2

p · ((d/2)!)3

).

Efficient parallelization as well as sequential execution re-quires blocking of computation. For matrix multiplication,it is well known that blocking the matrices gives a communication-optimal algorithm when no extra memory is available. Block-ing the computational graph gives communication-optimalitywhen each processor has an unlimited amount of memory.Generally, the blocking should be done to minimize the surface-area to volume ratio of each computational block. For ma-trix multiplication of square matrices, this is achieved bypicking out square blocks. For dense tensor contractions, itis ideal to pick out blocks for which the accumulated block-size of all dimensions which are contracted over is the sameor near the accumulated block-size of all dimensions whichare not contracted over. If half the indices are being con-tracted over (as in our model contraction), then to achieveoptimality, it suffices to pick the same block-size in eachdimension.

3.1 Padding overhead of blockingTensor symmetry complicates the process of blocking, since

a symmetric packed tensor is not decomposable into equiv-alent contiguous blocks. One approach is to decompose thepacked tensor into full and partially-full blocks and dealwith each case-by-case. However, it becomes very difficult tomaintain and specialize for each type of partially-full blockthat arises given some blocking of a tensor of some symme-try. Further, computation on partially-full blocks producesload-imbalance and an irregular decomposition. Therefore,to greatly simplify implementation, partially-full blocks aretypically padded with zeros and treated as fully dense blocks.A block size of b implies that O(b) padding is required alongeach dimension.

In matrix computations, padding is almost always a triv-ially low-order cost but in tensors of high-dimension it canincur a significant computational overhead. Given a paddingthickness of one in each dimension, the padding has a totalsize proportional to the surface area of the tensor. The sur-face area of a tensor is one-dimension less than the tensoritself, so the surface-area to volume ratio grows with respectto tensor dimension. In particular, for our model problem,given blocking (padding) of size b, the computational costgrows in proportion to

Fpadded(n, d, p, b) = O

(b3d/2

(1 + nb

)3d/2

p · ((d/2)!)3

)

= O

(n3d/2

p · ((d/2)!)3+

(3d/2)b · n3d/2−1

p · ((d/2)!)3+ . . .

)= O ((1 + (3d/2)b/n) · F (n, d, p)) .

Thus, padding can increase the computation performed sig-nificantly if b ≈ n.

3.2 Cyclic distribution of blocksA blocked distribution implies each processor owns a con-

tiguous piece of the original tensor, while a cyclic distribu-tion implies that each processor owns every element of thetensor with a defined cyclic phase. In a cyclic distribution,a cyclic phase defines the periodicity of the set of indices

Page 6: A preliminary analysis of Cyclops Tensor Framework · 2012-03-09 · Cyclops Tensor Framework since they are largely orthog-onal components. However, the tuning decisions done by

Figure 1: A cyclic decomposition of a 3D symmetric tensor into symmetric blocks on a 4-by-4-by-4 topology.

whose elements are owned by a single processor. For exam-ple, if a vector is distributed cyclically among 4 processors,each processor owns every fourth element of the vector. Fora tensor of dimension d, we can define a set of cyclic phases(p0, p1, · · · , pd−1), such that processor Pi0,i1,··· ,id−1 owns alltensor elements whose index (j0, j1, · · · , jd−1) satisfies

jk = ikmod(pk)

for all k ∈ 0, 1, · · · , d. A block-cyclic distribution general-izes blocked and cyclic distributions, by distributing contigu-ous blocks of any size b cyclically among processors. Cyclicdecompositions are commonly used in parallel numerical lin-ear algebra algorithms and frameworks such as ScaLAPACK(block-cyclic) [6] and Elemental (cyclic) [18].

Like matrix multiplication, tensor contractions are invari-ant with respect to a similarity permutation on A and B,

PCPT = PA ·BPT = (PAPT ) · (PBPT )

This invariance means that we can permute the ordering ofrows in columns in a matrix or slices of a tensor, so long aswe do it to both A and B and permute PCPT back to C.This property is particularly useful when considering cyclicand blocked distributions of matrices and tensors. We candefine a permutation, P , that permutes a tensor elementsfrom a blocked to a cyclic layout. Conversely, we can runan algorithm on a cyclic distribution and get the answer ina blocked distribution by applying a permutation, or runexactly the same algorithm on a blocked distribution andget the cyclic answer by applying a permutation.

The main idea behind Cyclops Tensor Framework is toemploy a cyclic distribution to preserve symmetry in sub-tensors, minimize padding, and generate a completely reg-ular decomposition, susceptible to classical linear algebraoptimizations. Each processor owns a cyclic sub-tensor,with a symmetric choice of cyclic phases in each dimen-sion. By maintaining the same cyclic phase in each dimen-sion, the algorithm insures that each the sub-tensor ownedby any processor has the same symmetry and structure asthe whole tensor (Figure 1). Further, minimal padding oneach sub-tensor insures that every sub-tensor has the exactsame dimensions, now only with different values. Figure 2demonstrates the difference in padding (or load-imbalance)required to store exactly the same sub-tensors on each pro-cessor. It is evident that only a cyclic layout can preservesymmetry as well as maintain load balance. Overall theamount of padding required for CTF, is equivalent to settingthe block size b = p1/d, since we must add up the paddingon each processor.

3.3 Communication costSince the dense version of this contraction is equivalent

to multiplication, we can employ the matrix multiplicationcommunication lower bound. In particular, given any blockof data of each of A, B, and C of size O(M), no more than

Fblk(M) = O(M3/2)

meaningful computational work can be performed [13, 4,12]. Therefore, the amount of communication required toperform the contraction can be lower bounded by the num-ber of blocks (of size equal to processor memory) needed toperform the contraction

W (n, d, p,M) = Ω(F (n, d, p) ·M/Fblk(M))

= Ω

(n3d/2

p ·M1/2 · ((d/2)!)3

).

If we assume the tensor is the same asymptotic size as theavailable memory, the block size is

M = S(n, d, p)

= Θ

(nd

p · ((d/2)!)2

),

which gives us a lower bound on the number of words movedas a function of n, d and p,

W (n, d, p) = Ω

(nd

√p · ((d/2)!)2

).

3.3.1 Communication in Cyclops Tensor FrameworkFor this model tensor contraction, the number of words

moved by Cyclops Tensor Framework (CTF) the size of apacked tensor block, multiplied by the number of times itis broadcast during the contraction. The CTF decompo-sition employs a d-dimensional processor grid, where eachedge-length of the processor grid is p1/d. The algorithm em-ployed would be a blocked recursive SUMMA (d/2 levels ofrecursion, one per contraction index), with each block of sizeequal to the packed tensor size per processor. The numberof words communicated per processor is then

WCTF(n, d, p) = O(S(n, d, p) · (p1/d)d/2)

= O

(nd

√p · ((d/2)!)2

).

So the amount of data sent is optimal. We note that this isnot necessarily the case for any given tensor contraction, but

Page 7: A preliminary analysis of Cyclops Tensor Framework · 2012-03-09 · Cyclops Tensor Framework since they are largely orthog-onal components. However, the tuning decisions done by

Blocked layout Block-cyclic layout Cyclic layout

Red denotes padding / load imbalanceGreen denotes fill (unique values)

Figure 2: Padding or load-imbalance in tensor mapped with different block-sizes.

is true for the model problem. In general, CTF can have asmall theoretical communication overhead (with respect tothe lower-bound) if the flop-to-byte ratio in the symmetriccontraction is smaller than the flop-to-byte ratio of a densematrix multiplication.

The only other significant communication costs in CyclopsTensor Framework are the all-to-all communication neces-sary for tensors redistribution. Since this communicationrequires no processor to send more words than its local sub-tensor size, it is a low order cost with respect to the con-traction.

3.3.2 Communication in NWChemIn NWChem, a tile-size b is selected in each dimension of

the tensors. For each tile sub-contraction, the data is re-trieved via one-sided communication from its location. Inour model contraction, tiles with edge-length of b in each di-mension can be contracted by performing b3d/2 flops. There-fore, the amount of data communicated by each processoris

WNW(n, d, p) = O

(n3d/2

p · b3d/2 · ((d/2)!)2· bd)

= O

(n3d/2

p · bd/2 · ((d/2)!)2

).

To achieve communication optimality, this block-size mustbe picked to be b = Ω(n/p1/d),

WNW(n, d, p) = O

(n3d/2

p · (n/p1/d)d/2 · ((d/2)!)2

)= O

(nd

√p · ((d/2)!)2

).

However, picking this block size implies that NWChem needsto perform a large amount of padding, increasing the com-putational cost by a factor of

FNW-padded(n, d, p) = O(

(1 + (3d/2)/p1/d) · F (n, d, p)).

This factor grows with tensor dimension and has a significantoverhead for tensors of high dimension in practice. On theother hand, CTF has a padding computational overhead of

FCTF-padded(n, d, p) = O(

(1 + (3d/2)p1/d/n) · F (n, d, p)).

Since n grows proportionally to p1/d with both p as well asd, this overhead is significantly smaller.

4. TOPOLOGY-AWARE MAPPINGTo preserve symmetry in sub-tensor of a tensor we must

ensure that the parallel decomposition uses the same cyclicphase among symmetric dimensions of that tensor. However,simultaneously its necessary to enforce the same cyclic phaseamong a dimension of two tensors which is being contractedover (shared index). Such parameters severely limited thepossible block decompositions that are available. However,we would like to have the flexibility of mapping onto anyphysical topology. This motivates a virtualized mappingof the tensors, which overdecomposes the tensors and thenmaps the blocks onto the processing grid.

4.1 Virtualized mapping schemeCyclops Tensor Framework performs virtualization to cre-

ate a level of indirection between the task decomposition andthe physical network topology. We provide a virtualizationscheme that is guaranteed to generate a load balanced de-composition for any given tensor contraction (tensors of anysymmetry, any dimension, and any index map defining thecontraction). Further, we parameterize the virtual decompo-sition so that it is effectively a multiple of the processor grid,which insures that each processor owns the same number ofsub-blocks. This scheme effectively reduces the problem ofmapping a tensors with symmetry to mapping padded ten-sors with no symmetry. For example, in Figure 3 the 3Dvirtualized mapping is decomposed among the processors sothat each processor is contracting a matrix of symmetrictensors with a vector of symmetric tensors into a matrix ofsymmetric tensors. The mapping is defined so that by thetime the distributed contraction algorithm is executed, itneed not be aware of the symmetry of the sub-tensors butonly of their size.

We do not use a dynamically scheduled virtualization ap-proach such as the overdecomposition embodied by theCharm++ runtime system [15]. Instead, we define the vir-tualization so that its dimensions are a multiple of the phys-ical torus dimensions and generate a regular mapping. Thisapproach maintains perfect load-balance and achieves highcommunication and task granularity by managing each vir-tualized sub-grid explicitly by a single process.

Page 8: A preliminary analysis of Cyclops Tensor Framework · 2012-03-09 · Cyclops Tensor Framework since they are largely orthog-onal components. However, the tuning decisions done by

Figure 3: Virtualization as used in CTF to perform contractions.

A tensor mapping decomposed by Cyclops Tensor Frame-work maintains the following properties

• If two indices i, j belong to a tensor and have symmetry(i ≤ j), they must be mapped with the same cyclicphase.

• If a contraction index i belongs to both tensors A andB, the i-index dimension of A and B must be mappedwith the same cyclic phase and not along the samephysical processor grid dimension.

• If a contraction index i belong to either A and C or Band C the i-index dimension of A and C or B and Cmust have the exact same mapping.

• Each tensor is distributed or along the entire processorgrid.

Obeying the above mapping conditions allows for efficientgeneration of a symmetry-oblivious contraction algorithmthat computes the solution following the redistribution. Thegenerated distributed contraction algorithm simply appliesknown matrix multiplication distributed algorithms recur-sively for each index which is contracted over. Since wedo not allow dimensions of A and B which are contractedover to be mapped onto the same physical dimension, theymust form a 2D decomposition (with one or both dimen-sions potentially virtualized). Further, since each index ofC is mapped onto the same dimension as a correspondingindex of A or B, we know that the answer will end up in theright place.

4.2 Mapping heuristicsCurrently, Cyclops Tensor Framework assumes the phys-

ical topology is a torus and attempts to find the best vir-tualized mapping for the given torus. No assumptions aremade about the dimension of the torus or lengths of anytorus dimension. Further, the torus is folded in all possibleways that maintain the original dimensional ordering (thisassumption is not very restricting and is made for conve-nience). If no topology is specified, the processor count isfully factorized p = p1 · p2 · . . . · pd, to form a d-dimensionaltorus processor grid with edge lengths p1, p2 . . . pd. This

fully unfolded processor grid is then folded back-up so as togenerate the largest amount of different potential decompo-sitions.

Once a tensor is defined or a tensor contraction is in-voked, CTF searches through all topologies and selects thebest mapping which satisfies the constraints. The searchthrough mappings is done entirely in parallel among proces-sors then the best mapping is selected across all processors.The mapping logic is done without reading or moving anyof the tensor data and is generally composed of integer logicthat executes in a trivial amount of time with respect to thecontraction. Once a mapping is decided upon, the tensorsare redistributed.

When trying to select a mapping of a tensor or of a con-traction of tensors onto a physical processor grid, a greedyalgorithm is used. The longest tensor dimension is mappedalong the longest dimension of the processor grid. For eachsuch mapping of a dimension, CTF enforces all other con-straints by mapping all other symmetric or related dimen-sions to available physical or virtual dimensions with thesame phase. For contractions, dimensions which are con-tracted over are mapped first and combined together spanthe entire processor grid (this is necessary to insure A and Bare distributed over the whole processor grid). The remain-ing dimensions (dimensions which are not contracted overand belong to C) are mapped so that C is distributed overthe whole processor grid, again insuring no constraints areviolated. Enforcing the constraints is done by iterating overall dimensions and increasing virtualization when necessary.

The best mapping can be selected according to many con-ditions, such as whether a redistribution of data is required,how much memory the distributed algorithm will use, howmuch virtualization is required and so forth. The currentheuristic is to maximize the amount of computational workdone in each sub-contraction. This heuristic effectively max-imizes the volume of computation in each block, which is acondition that ensures communication optimality.

4.3 Tensor redistributionEach contraction can place unique restrictions on the map-

ping of the tensors. Therefore, to satisfy each new set ofrestrictions the mapping must change and tensor data must

Page 9: A preliminary analysis of Cyclops Tensor Framework · 2012-03-09 · Cyclops Tensor Framework since they are largely orthog-onal components. However, the tuning decisions done by

be reshuffled among processors according to the new map-ping. Since the redistribution can potentially happen be-tween every contraction, an efficient implementation is nec-essary. However, the data must first be given to CTF by theuser application. We detail a scheme for input and output ofdata by key-value pairs, as well as a much more efficient algo-rithm for mapping-to-mapping tensor redistribution. SinceCoupled Cluster and most other scientific applications areiterative and perform sequences of operations (contractions)on the same data, we assume input and output of data willhappen less frequently than contractions.

To support general and simple data entry, CTF allows theuser to write tensor data bulk-synchronously into the tensorobject using key-value pairs. This allows the user to writedata from any distribution that was previously defined, andto do so with any desired granularity (all data at once or bychunks). Redistribution happens by calculating the cyclicphase of each key to determine which processor it belongson. Once counts are assembled the data is redistributedvia all-to-all communication. After this single redistribu-tion phase, each process should receive all data belonging toits sub-tensors, and can simply bin by virtual block then sortit locally to get it into the right order. This key-value bin-ning scheme is essentially as expensive as a parallel sortingalgorithm.

When transitioning between distributions, which we ex-pect to happen much more frequently than between the ap-plication and user, we can take advantage of existing knowl-edge about the distribution. To be more precise, such aredistribution must manipulate the local tensor data, whichis laid out in a a grid of virtual blocks, each of which isa symmetric tensor of the same size. The dimensions andedge-lengths of the virtual and physical processor grid canchange between mappings and therefore must be accountedfor during redistribution. CTF supports such redistributionsgenerally using the following algorithm

1. Iterate over local tensor data and compute the virtualsub-tensor destination of each element.

2. Consider the assignment of virtual sub-tensors to phys-ical processes to compute how many elements are re-ceived by each process into each of its virtual buckets.

3. Iterate over sub-tensor data and the virtual grid (ininverse hierarchical order with respect to the data) soas to preserve global element order, and move eachelement to the correct send buffer.

4. Exchange the data among processes with all-to-all com-munication.

5. Iterate over the new sub-tensor data and the new vir-tual grid (again in inverse hierarchical order with re-spect to data), preserving global element order, andreading out of received buffers (which are accordinglyordered).

The above redistribution algorithm is complex due to thenecessity of maintaining global element order within thebuffers. By maintaining global element ordering, we elim-inate the need for keys, since this ordering is preserved inthe old and the new mapping.

After threading the redistribution algorithm with OpenMP,we found the integer logic running time to be negligible

with respect to contraction time. Threading the redistri-bution kernel required iterating over different parts of thesub-tensor when writing data to and from buffers. Over-all, the redistribution kernels are the most complex part ofCyclops Tensor Framework implementation, because theymust explicitly and efficiently deal with the representationof the symmetric sub-tensors as well as the virtualization.However, after the redistribution, the parallel contractionkernel only takes into account the virtualized grid, whilethe sequential contraction kernels need to only consider thesub-tensor, creating a vitally important software engineeringseparation.

5. PARALLEL PERFORMANCECyclops Tensor Framework is still under development but

much of the infrastructure is in-place and functional. Theframework can already decompose tensors of dimension atleast up to 8 (though no dimensional limit exists in thecode) with partial or full symmetries of at least up to 4indices. However, no optimized sequential symmetric con-traction kernels have been coupled with CTF yet. Further,some optimizations, such as adaptive replication are not yetin-place. We give scalability results for the model contrac-tion problem, using matrix multiplication as the sequentialkernel but employing high-dimensional of parallel decompo-sitions of symmetric tensors of dimension 4,6, and 8. Theframework achieves highly efficient weak-scaling on multiplesupercomputer architectures demonstrating the viability ofour approach.

5.1 ImplementationMuch of the logic and kernels contained by CTF has been

described in the previous sections. Here, we summarize anddescribe the overall work-flow of the contraction library. Ata high-level CTF has the following execution mechanism,

1. Describe or automatically detect the physical networktopology.

2. Define distributed tensor objects with symmetries andmap the tensors.

3. Write data to tensors bulk-synchronously via (globalindex, value) pairs.

4. Invoke contraction/summation/scale/trace operationon tensor(s).

5. In parallel, determine best mapping for the operationand define operational kernel.

6. Redistribute tensors to the selected decomposition andtopology.

7. Run the contraction kernel on the tensors, computingthe solution.

8. When requested, read data out via (global index, value)pairs.

Tensors are treated as first-class objects and direct accessto data is hidden from the user. The data must be writ-ten and read bulk-synchronously by global index. This dataentry mechanism is necessary to be able to remap and ab-stract away the data decomposition from the user. Whilethe initial redistribution is somewhat slower than a mapped

Page 10: A preliminary analysis of Cyclops Tensor Framework · 2012-03-09 · Cyclops Tensor Framework since they are largely orthog-onal components. However, the tuning decisions done by

redistribution, the assumption is that the data will be readand written infrequently and contractions will be done insequences.

The implementation uses no external libraries except forMPI [10], BLAS, and OpenMP. We used vendor provided op-timized BLAS implementations (IBM ESSL and Cray Lib-Sci) on all architectures for benchmarking. All code is tightlyintegrated and written in C/C++. Computationally ex-pensive routines are threaded and/or parallelized with MPI.Performance profiling is done by hand and with TAU [19].

5.2 ArchitecturesCyclops Tensor Framework targets massively parallel ar-

chitectures and is designed to take advantage of networktopologies and communication infrastructure that scale tomillions of nodes. Parallel scalability on commodity clustersshould benefit significantly from the load balanced charac-teristics of the workload, while high-end supercomputers willadditionally benefit from reduced inter-processor communi-cation which typically becomes a bottleneck only at veryhigh degrees of parallelism. We collected performance re-sults on two state-of-the-art supercomputer architectures,IBM Blue Gene/P and Cray XE6.

We benchmarked our implementations on a Blue Gene/P(BG/P) [11] machine located at Argonne National Labo-ratory (Intrepid). BG/P is an interesting target platformbecause it uses few cores per node (four 850 MHz Pow-erPC processors) and relies heavily on its interconnect (abidirectional 3D torus with 375 MB/sec of achievable band-width per link). Therefore, interprocessor communicationand topology-awareness are key considerations on this ar-chitecture.

Our second experimental platform is ‘Hopper’, which isa Cray XE6 supercomputer, built from dual-socket 12-core“Magny-Cours” Opteron compute nodes. This machine islocated at the NERSC supercomputing facility. Each nodecan be viewed as a four-chip compute configuration due toNUMA domains. Each of these four chips have six super-scalar, out-of-order cores running at 2.1 GHz with private64 KB L1 and 512 KB L2 caches. Nodes are connectedthrough Cray’s ‘Gemini’ network, which has a 3D torustopology. Each Gemini chip, which is shared by two Hop-per nodes, is capable of 9.8 GB/s bandwidth. However, theNERSC Cray scheduler does not allocate contiguous parti-tions, so topology-aware mapping onto a torus cannot cur-rently be performed.

5.3 ResultsAll benchmark scaling results are collected for the model

tensor contraction problem with square tensors of dimension2,4, and 8, using matrix multiplication as the sequential sub-contraction kernel. Testing of the parallel decompositionhas been done for all types of contractions using a sequen-tial kernel that unpacks each symmetric sub-tensor. Fullresults for tensor contraction sequences and actual CoupledCluster methods will require integrated sequential symmet-ric contraction kernels. However, the study detailed heretests the full complexity of the parallel component, whichhas no awareness that it is working on a model contractionrather than any given Coupled Cluster contraction (an 8Dmodel contraction has as high dimension and as much sym-metry as any CC contraction done in methods up to CCS-DTQ). Further, we defined the contractions so as to force

each tensor to be redistributed between every contraction,benchmarking the worst case scenario for our redistributionkernels.

Figure 4(a) demonstrates weak scaling performance of CTFon a Blue Gene/P supercomputer. The scalability is good,but a significant amount of extra computation is done for 8Dtensors (less so for 6D and very little for 4D). The amountof padding done for an 8D tensor, quadruples the compu-tational cost in the worst observed case. This overheadis correlated with the fact that each sub-tensor gets to bevery small and the padded/surface area dominates. How-ever, this padding does not grow with processor count andstays bounded. The performance dip for 8D tensors at 512nodes is due to increased virtualization going up from 256nodes (256 nodes can be treated as an 8D hypercube). On512 nodes, the mapping must have more virtualization andtherefore more padding. However, this increase levels offand the virtualization necessary actually decreases from 512nodes onward (it should continue decreasing until reaching2 · 48 = 131, 072 nodes). In this preliminary benchmark,topology-aware mapping is not done onto the torus dimen-sions. In any case, it is difficult to map 6D and 8D tensorsto a 3D physical processor grid. A 5D or 6D processor gridsuch as the ones employed by the newer BG/Q and the K-computer, respectively, will be much more fit for mappingof these tensors.

Weak scaling on the Cray XE6 architecture (Figure 4(b))has similar characteristics as the scaling on BG/P. In fact,the padding overhead for 6D and 8D tensors is significantlydecreased, since each process (4 per node, 6 cores per pro-cess) handles much larger granularity (sub-tensor size) thanBG/P nodes can, due to the difference in on-node memorysize. Despite the lack of precise topology-aware mapping,communication overhead is small at the given node counts.For both BG/P and XE6, most of the execution time is spentinside sequential matrix multiplication, which demonstratesthat the parallel efficiency is very high (≥ 50%).

We do not detail strong scaling performance, since mem-ory replication is not yet fully implemented inside CTF.Given 2.5D-like replication schemes within CTF the strongscalability will significantly improve. When running thesame size problem on more nodes, more memory becomesavailable, allowing for more replication and reduced commu-nication. A theoretical analysis and a detailed performancestudy of strong scaling done in this fashion is given in [20].

6. FUTURE WORKCyclops Tensor Framework is currently in development

with several major components existing and some missing.In particular, there are no integrated efficient symmetric se-quential contraction routines. Currently only unoptimizedroutines are employed for verification and optimized ma-trix multiplication is employed for benchmarking of certaincontractions. Since CTF preserves any tensor symmetry, itallows for any sequential contraction kernel to be seamlesslyparallelized, by using it as a function pointer and callingit many times on sub-tensors. We will explore general andauto-generated routines for sequential tensor contractions.Further, we will couple the sequential contraction designwith the virtual decomposition by exploiting the blockingimplicitly provided by virtualization.

Adaptive replication and memory awareness will be inte-grated into CTF. Part of the mapping process will involve

Page 11: A preliminary analysis of Cyclops Tensor Framework · 2012-03-09 · Cyclops Tensor Framework since they are largely orthog-onal components. However, the tuning decisions done by

512

1024

2048

4096

8192

16384

32768

65536

1024 2048 4096 8192

Gig

aflo

ps

#cores

Cyclops TF weak scaling on BG/P

theoretical peak4D sym (CCSD)

6D sym (CCSDT)8D sym (CCSDTQ)

(a) IBM BG/P

16

64

256

1024

4096

16384

32 64 128 256 512 1024

Gig

aflo

ps

#cores

Cyclops TF weak scaling on XE6

theoretical peak4D sym (CCSD)

6D sym (CCSDT)8D sym (CCSDTQ)

(b) Cray XE6

Figure 4: Preliminary weak scaling results of CTF

calculating the necessary buffer space needed to performa contraction and selecting the algorithm which performsthe least amount of communication without surpassing thememory limits. This methodology has been employed in2.5D algorithms for linear algebra and shown to significantlyimprove strong scaling as well as allow more flexibility in thedecomposition.

Different types of sparsity in tensors will also be consid-ered in Cyclops Tensor Framework. Tensors with bandedsparsity structure can be decomposed cyclically so as to pre-serve band structure in the same way CTF preserves sym-metry. Completely unstructured tensors can also be decom-posed cyclically, though the decomposition would need toperform load balancing in the mapping and execution logic.

Cyclops Tensor Framework will also be integrated with ahigher-level tensor manipulation framework as well as Cou-pled Cluster contraction generation methods. Currently,CTF performs contractions on tensors in a packed symmet-ric layout. However, multiple packed contractions are re-quired to compute the full symmetric contraction and thehigher-level Coupled Cluster equations can be decomposedinto contractions in different ways. We will integrate CTFvertically to build a scalable implementation of CoupledCluster methods. In particular, we are targeting the CCS-DTQ method, which employs tensors of dimension up to8 and gets the highest accuracy of any desirable CoupledCluster method (excitations past quadruples have a negli-gible contribution). In this report we’ve given preliminaryresults demonstrating the scalability of CTF decompositionof 4 to 8-dimensional tensors on massively parallel super-computers. We will implement further optimizations andinfrastructure that will improve strong scalability and allowfor efficient execution of Coupled Cluster methods ratherthan just selected tensor contractions.

AcknowledgmentsThe first author was supported by a Krell Department ofEnergy Computational Science Graduate Fellowship, grantnumber DE-FG02-97ER25308. This research was supportedin part by Microsoft (Award #024263) and Intel (Award#024894) funding and by matching funding by U.C. Discov-

ery (Award #DIG07-10227). It was also supported by U.S.Department of Energy grants numbered DE-SC0003959, DE-SC0004938, DE-FC02-06-ER25786 and DE-SC0001845. Thisresearch used resources of the Argonne Leadership Comput-ing Facility at Argonne National Laboratory, which is sup-ported by the Office of Science of the U.S. Department ofEnergy under contract DE-AC02-06CH11357. This researchused resources of the National Energy Research ScientificComputing Center, which is supported by the Office of Sci-ence of the U.S. Department of Energy under Contract No.DE-AC02-05CH11231.

7. REFERENCES[1] R. C. Agarwal, S. M. Balle, F. G. Gustavson,

M. Joshi, and P. Palkar. A three-dimensional approachto parallel matrix multiplication. IBM J. Res. Dev.,39:575–582, September 1995.

[2] A. Aggarwal, A. K. Chandra, and M. Snir.Communication complexity of PRAMs. TheoreticalComputer Science, 71(1):3 – 28, 1990.

[3] E. A. Auer, G. Baumgartner, D. E. Bernholdt,A. Bibireata, D. Cociorva, X. Gao, R. Harrison,S. Krishnamoorthy, H. Krishnan, C. chung Lam,Q. Lu, M. Nooijen, R. Pitzer, J. Ramanujam, andE. Sibiryakov. Automatic code generation formany-body electronic structure methods: The tensorcontraction engine. 2006.

[4] G. Ballard, J. Demmel, O. Holtz, and O. Schwartz.Minimizing communication in linear algebra. SIAM J.Mat. Anal. Appl., 32(3), 2011.

[5] G. Baumgartner, A. Auer, D. Bernholdt, A. Bibireata,V. Choppella, D. Cociorva, X. Gao, R. Harrison,S. Hirata, S. Krishnamoorthy, S. Krishnan, C. Lam,Q. Lu, M. Nooijen, R. Pitzer, J. Ramanujam,P. Sadayappan, and A. Sibiryakov. Synthesis ofhigh-performance parallel programs for a class of abinitio quantum chemistry models. Proceedings of theIEEE, 93(2):276 –292, feb. 2005.

[6] L. S. Blackford, J. Choi, A. Cleary, E. D’Azeuedo,J. Demmel, I. Dhillon, S. Hammarling, G. Henry,A. Petitet, K. Stanley, D. Walker, and R. C. Whaley.

Page 12: A preliminary analysis of Cyclops Tensor Framework · 2012-03-09 · Cyclops Tensor Framework since they are largely orthog-onal components. However, the tuning decisions done by

ScaLAPACK user’s guide. Society for Industrial andApplied Mathematics, Philadelphia, PA, USA, 1997.

[7] L. E. Cannon. A cellular computer to implement theKalman filter algorithm. PhD thesis, Bozeman, MT,USA, 1969.

[8] E. Dekel, D. Nassimi, and S. Sahni. Parallel matrixand graph algorithms. SIAM Journal on Computing,10(4):657–675, 1981.

[9] X. Gao, S. Krishnamoorthy, S. Sahoo, C.-C. Lam,G. Baumgartner, J. Ramanujam, and P. Sadayappan.Efficient search-space pruning for integrated fusionand tiling transformations. In Languages andCompilers for Parallel Computing, volume 4339 ofLecture Notes in Computer Science, pages 215–229.Springer Berlin / Heidelberg, 2006.

[10] W. Gropp, E. Lusk, and A. Skjellum. Using MPI:portable parallel programming with the message-passinginterface. MIT Press, Cambridge, MA, USA, 1994.

[11] IBM Journal of Research and Development staff.Overview of the IBM Blue Gene/P project. IBM J.Res. Dev., 52:199–220, January 2008.

[12] D. Irony, S. Toledo, and A. Tiskin. Communicationlower bounds for distributed-memory matrixmultiplication. Journal of Parallel and DistributedComputing, 64(9):1017 – 1026, 2004.

[13] H. Jia-Wei and H. T. Kung. I/O complexity: Thered-blue pebble game. In Proceedings of the thirteenthannual ACM symposium on Theory of computing,STOC ’81, pages 326–333, New York, NY, USA, 1981.ACM.

[14] S. L. Johnsson. Minimizing the communication timefor matrix multiplication on multiprocessors. ParallelComput., 19:1235–1257, November 1993.

[15] L. V. Kale and S. Krishnan. CHARM++: a portableconcurrent object oriented system based on C++. InProceedings of the eighth annual conference onObject-oriented programming systems, languages, andapplications, OOPSLA ’93, pages 91–108, New York,NY, USA, 1993. ACM.

[16] R. A. Kendall, E. Apra, D. E. Bernholdt, E. J.Bylaska, M. Dupuis, G. I. Fann, R. J. Harrison, J. Ju,J. A. Nichols, J. Nieplocha, T. Straatsma, T. L.Windus, and A. T. Wong. High performancecomputational chemistry: An overview of NWChem adistributed parallel application. Computer PhysicsCommunications, 128(1-2):260 – 283, 2000.

[17] J. Nieplocha, R. J. Harrison, and R. J. Littlefield.Global arrays: A nonuniform memory accessprogramming model for high-performance computers.The Journal of Supercomputing, 10:169–189, 1996.10.1007/BF00130708.

[18] J. Poulson, B. Maker, J. R. Hammond, N. A. Romero,and R. van de Geijn. Elemental: A new framework fordistributed memory dense matrix computations. ACMTransactions on Mathematical Software. in press.

[19] S. S. Shende and A. D. Malony. The TAU parallelperformance system. International Journal of HighPerformance Computing Applications, 20(2):287–311,Summer 2006.

[20] E. Solomonik, A. Bhatele, and J. Demmel. Improvingcommunication performance in dense linear algebravia topology aware collectives. In Supercomputing,

Seattle, WA, USA, Nov 2011.

[21] E. Solomonik and J. Demmel. Communication-optimal2.5D matrix multiplication and LU factorizationalgorithms. In Lecture Notes in Computer Science,Euro-Par, Bordeaux, France, Aug 2011.

[22] R. A. Van De Geijn and J. Watts. SUMMA: scalableuniversal matrix multiplication algorithm.Concurrency: Practice and Experience, 9(4):255–274,1997.