manycore-portable multidimensional arrays for finite ... › cfdocs › compresearch › ... ·...

18
Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company, for the United States Department of Energy’s National Nuclear Security Administration under contract DE-AC04-94AL85000. Manycore-Portable Multidimensional Arrays for Finite Element Computations H. Carter Edwards Sandia National Laboratories July 12, 2012 2012 SIAM Annual Meeting Minneapolis, Minnesota SAND2012-5042C

Upload: others

Post on 26-Jun-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000.

Manycore-Portable Multidimensional Arrays

for Finite Element Computations

H. Carter Edwards

Sandia National Laboratories

July 12, 2012

2012 SIAM Annual Meeting

Minneapolis, Minnesota

SAND2012-5042C

Page 2: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000. 1

Strategy / Approach

• Challenge: Manycore Portability with Performance

– Multicore-CPU and manycore-accelerator (e.g., NVIDIA)

– Diverse memory access patterns, shared memory utilization, …

• Via a Library, not a language

– Concise and simple abstractions, API, and runtime

– C++ with template meta-programming

– In spirit of Intel‟s TBB, NVIDIA‟s Thrust & CUSP, MS C++AMP, ...

• Data Parallel Operations (parallel_for & parallel_reduce)

– Deferred task parallelism, pipeline parallelism, ...

• Multidimensional Arrays – intuitive for science & engineering

– “arrays of structs” vs. “structs of arrays” – wrong conversation

– Abstraction for data placement, locality, mapping

Page 3: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000. 2

Kokkos Array Abstractions

• Manycore Device – has separate memory space

– Physically (GPU), Performance (NUMA), Logically (CPU)

• Data Parallel Operations

– Executed by many threads on the manycore device

– Performance can be dominated by memory access pattern

• E.g., NVIDIA coalescing, NUMA regions

• Multidimensional Array

Map array data into a manycore device‟s memory

• Parallel partitioning

• Multi-index computation

– Data parallel operation + map memory access pattern

Page 4: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000. 3

Kokkos Array Abstraction:

Multidimensional Array and its Map

• Homogeneous Collection of Plain-old-data Members

– Members referenced by a multi-index in a multi-index space

• Multi-Index Map

– Bijective map : multi-index space array data members

• [ 0 .. N0 ) x [ 0 .. N1 ) x [ 0 .. N2 ) x … memory locations

– Many valid maps

• E.g., Fortran, „C‟, space-filling-curve, block-cyclic, …

– Map for best memory access pattern is device-dependent

– Transparently introduce the best map at compile-time

• No alteration of the application‟s source code

• C++ template meta-programming

Page 5: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000. 4

Kokkos Array Abstraction:

Parallel Partitioning

• Parallel Partitioning of Data

– Partition into NP atomic units of parallel work

– Index space has parallel work dimensions: ( NP, N1, N2, … )

– Limited to 1D for now; deferred 2D+ parallel partitioning

• Parallel Work on Shared Arrays – NP atomic units of parallel work : ip [ 0 .. NP )

– Parallel thread-safety:

• Update only array members with index ( ip , * , * , … )

• Don‟t query data being updated by different unit of work

• Example: Finite Element Bases Gradients – grad( N-Element , N-Spatial-Dimension , N-Bases-per-Element )

– Parallel function over elements: compute gradients

Page 6: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000. 5

Kokkos Array API:

Multi-index Space and Data Access

• Index space known on the host and device

• Data members accessible only on the device

void my_function( Kokkos::MDArray<double,MapIntoDevice> grad )

{

// Access data member within code running on the device

// using standard multi-index notation

grad( iElem , iSpace , iBases ) = value ;

assert( 3 == grad.rank() ); // Verify index space rank

size_t nBases = grad.dimension(2); // Query index space dimension

size_t nSpace = grad.dimension(1);

size_t nElem = grad.dimension(0);

}

Page 7: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000. 7

Kokkos Array API:

Mirrored Arrays and Deep Copy

• Different Devices have Different Maps

– Need to access array data in Host memory

– However, remapping array data is expensive

• HostMirror

– Array in Host memory space using Device‟s map

– No remapping, fast memory copy

– If Device = Host the mirror can be a view to the same data

array_type X = ... ; // device memory and device’s map

array_type::HostMirror X_host = create_mirror( X );

// host memory with device’s map

deep_copy( X , X_host ); // copy data device <- host

deep_copy( X_host , X ); // copy data host <- device

Page 8: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000. 8

Kokkos Array API: Parallel Functor

• Execute Functors in Parallel on Accelerator Device

– Functor: A user‟s C++ class bundling a function + arguments

– Dispatch

• parallel_for( NP , functor_object );

• parallel_reduce( NP , functor_object , result );

– Called NP times in parallel: ip [0,NP)

• functor_object( ip ); // parallel_for

• functor_object( ip , result ); // parallel_reduce

• NUMA work and data locality affinity

– Work unit „ip‟ performed by thread with NUMA-local data

Page 9: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000.

NUMA? Non-Uniform Memory Access

• Why we worry about NUMA

– A simplified model:

9

CORE CORE CORE CORE

memory controller, shared cache memory

MAIN MEMORY

CORE CORE CORE CORE

memory controller, shared cache memory

MAIN MEMORY

Page 10: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000. 10

Kokkos Array API:

Example Parallel Reduce Functor template< class Device > // template on device

class CentroidFunctor {

public:

typedef Device device_type ;

typedef struct { double coord[3] , mass ; } value_type ;

MDArray<double,device_type> m_coord , m_mass;

void operator()( int ip , value_type & update ) const

{

update.mass += m_mass(ip);

update.coord[k] += m_coord(ip,k) * m_mass(ip,k);

}

static void join( volatile value_type & update ,

volatile const value_type & input )

{ update.mass += input.mass; update.coord[k] += input.coord[k];}

static void init( value_type & output )

{ output.mass = 0; output.coord[k] = 0; }

};

Page 11: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000.

• Single Node Devices

– Westmere: Xeon 2.93 GHz, 2 cpus X 6 cores x 2 hyperthreads

– Magny-Cours: Opteron 2.4 GHz, 2 cpus X 8 cores

– NVIDIA Tesla C2070: 448 cores, 1.2 GHz

• Cray XK6 testbed at Sandia (52 nodes)

– AMD Opteron Interlagos 2.1 GHz, 16 cores / 2 NUMA regions

– NVIDIA Tesla M2090: 512 cores, 1.3 GHz

– Cray Gemini network

• NUMA control via HWLOC

– http://www.open-mpi.org/projects/hwloc/

11

Finite-Element Mini-Applications

Performance Studies

Page 12: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000.

• Explicit Dynamics : computationally intensive

– Element stress and internal force contributions to nodes

– Node gather-assemble forces, apply boundary condition,

compute acceleration, integrate motion

– Accelerator device parallel

• Nonlinear Thermal Conduction : memory intensive

– Newton iteration to solve nonlinear equation

– Element computation of residual and Jacobian

– Gather-assemble sparse linear system; CG iterative solver

– Update nonlinear solution

– MPI + Accelerator device parallel

• Same finite element kernel source code on all devices

– Template instantiation inserts device specific array-maps

12

Performance-Portable

Finite-Element Mini-Applications

Page 13: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000.

Explicit Dynamics Mini-Application

Single Node Performance Comparison

13

4

6

8

10

12

14

16

1,000 10,000 100,000 1,000,000

Mill

ion

Ele

men

ts P

er S

eco

nd

Number of Elements

Element Computation : Single Prec.

NVIDIA Westmere-24 Magny-Cours-16

10

60

110

160

210

1,000 10,000 100,000 1,000,000

Mill

ion

Ele

men

ts P

er S

eco

nd

Number of Elements

Node Update : Single Prec.

NVIDIA Westmere-24 Magny-Cours-16

0

2

4

6

8

10

1,000 10,000 100,000 1,000,000

Mill

ion

Ele

men

ts P

er S

eco

nd

Number of Elements

Element Computation : Double Prec.

Westmere-24 NVIDIA Magny-Cours-16

0

20

40

60

80

100

120

140

1,000 10,000 100,000 1,000,000

Mill

ion

Ele

men

ts P

er S

eco

nd

Number of Elements

Node Update : Double Prec.

NVIDIA Westmere-24 Magny-Cours-16

Page 14: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000.

Explicit Dynamics Mini-Application

NUMA Performance on Westmere

14

3

4

5

6

7

8

9

1,000 10,000 100,000 1,000,000

Mill

ion

Ele

men

ts P

er S

eco

nd

Number of Elements

Element Computation: Impact of NUMA

With HWLOC : float With HWLOC : double

NO HWLOC : float NO HWLOC : double

20

30

40

50

60

70

80

90

100

110

120

1,000 10,000 100,000 1,000,000

Mill

ion

Ele

men

ts P

er S

eco

nd

Number of Elements

Node Update : Impact of NUMA

With HWLOC : float With HWLOC : double

NO HWLOC : float NO HWLOC : double

• NUMA „first touch‟ on data in both cases

• Use HWLOC to explicitly place threads with adjacent data

– Adjacent-rank threads have adjacent data

– Locality: shared core (hyperthreads) and NUMA affinity

Page 15: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000.

Nonlinear Thermal Mini-Application

Element Computation Performance

15

1

10

100

0.1 1 10

Tim

e (

mil

lis

ec

)

Finite Element Mesh Nodes Millions

Element Computation Time Problem Scaling on Cray XK6 / 50nodes

MPI-Node 50x16 MPI-NUMA 100x8

MPI-Core 400x1 MPI-NVIDIA 50xGPU

40

400

10

Tim

e (

mil

lis

ec

)

Cray XK6 Nodes

Element Computation Time Strong Scaling on Cray XK6

for 6.6 Million Finite Element Mesh Nodes

MPI-Node (N)x16 MPI-NUMA (Nx2)x8

MPI-Core (Nx16)x1 MPI-NVIDIA NxGPU

50

• No communication

– Redundant computations at

processor boundaries

• Ideal memory access

– Coalesced

– Cache friendly

– NUMA locality

• Computationally intensive

Page 16: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000.

Nonlinear Thermal Mini-Application

Gather-Assemble Performance

16

0.03

0.3

3

30

0.1 1 10

Tim

e (

mil

lis

ec

)

Finite Element Mesh Nodes Millions

Sparse Matrix Gather-Assemble Time Problem Scaling on Cray XK6 / 50nodes

MPI-Node 50x16 MPI-NUMA 100x8

MPI-Core 400x1 MPI-NVIDIA 50xGPU

10

100

10

Tim

e (

mil

lis

ec

)

Cray XK6 Nodes

Sparse Matrix Gather-Assemble Time Strong Scaling on Cray XK6

for 6.6 Million Finite Element Mesh Nodes

MPI-Node (N)x16 MPI-NUMA (Nx2)x8

MPI-Core (Nx16)x1 MPI-NVIDIA NxGPU

50

• No communication

– Redundant computations at

processor boundaries

• Memory access intensive

• Random access

– NOT Coalesced

– NOT Cache friendly

– Significant cross-NUMA reads

Page 17: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000.

Nonlinear Thermal Mini-Application

Gather-Assemble Performance

17

• Communication intensive

– Sparse matrix row decomposition

– Sparse matrix-vector multiply

imports portion of column vector

– Dot-product reductions

• Random access

– Sparse matrix-vector multiply

read of column vector

– Significant cross-NUMA reads

• To Improve NUMA

– Minimize cross-NUMA reads

– Nested domain decomposition

among NUMA regions

0.2

2

0.1 1 10

Tim

e (

mil

lis

ec

)

Matrix Rows Millions

CG Iterative Solver Time per Iteration Problem Scaling on Cray XK6 / 50nodes

MPI-Node 50x16 MPI-NUMA 100x8MPI-Core 400x1 MPI-NVIDIA 50xGPU

1

10

100

10Tim

e (

mil

lis

ec

)

Cray XK6 Nodes

CG Iterative Solver Time per Iteration Strong Scaling on Cray XK6 for 6.6 Million Matrix Rows

MPI-Node Nx16 MPI-NUMA (Nx2)x8

MPI-Core (Nx16)x1 MPI-NVIDIA NxGPU

50

Page 18: Manycore-Portable Multidimensional Arrays for Finite ... › cfdocs › CompResearch › ... · grad( iElem , iSpace , iBases ) = value ; assert( 3 == grad.rank() ); // Verify index

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,

for the United States Department of Energy’s National Nuclear Security Administration

under contract DE-AC04-94AL85000. 18

Conclusion & Plans

• Performance-Portability

– Data access patterns are critical for performance

– Data parallel functions on multidimensional arrays

– Abstract & separate array map: index space device memory

– Automatically & transparently insert device-optimal array map

– Identical finite element code on all devices

• Plans

– Nested domain decomposition for cross-NUMA kernels

– Rank 2+ parallel extents, array maps with tiling

– Intel MIC accelerator device

– Other dispatch patterns: parallel-scan, heterogeneous functors, …

– Other kernel domains: stochastic finite elements, ...

• Available: http://trilinos.sandia.gov