3d adi method for fluid simulation on multiple gpuson- .adi method – iterations use global...

Post on 12-Feb-2019

213 views

Category:

Documents

Embed Size (px)

TRANSCRIPT

3D ADI Method for Fluid Simulation on Multiple GPUs

Nikolai Sakharnykh, NVIDIA

Nikolay Markovskiy, NVIDIA

Introduction

Fluid simulation using direct numerical methods

Gives the most accurate result

Requires lots of memory and computational power

GPUs are very suitable for direct methods

Have great instruction throughput and high memory bandwidth

How will it scale on multiple GPUs?

cmc-fluid-solver

Open source project on Google Code

Started at CMC faculty of MSU, Russia

CPU: OpenMP, GPU: CUDA

3D fluid simulation using ADI solver

Key people:

NVIDIA: Nikolay Sakharnykh, Nikolay Markovskiy

Outline

Fluid Simulation in 3D domain

Problem statement, applications

GPU implementation details, optimizations

Performance analysis

Multi-GPU implementation

Problem Statement

Viscid incompressible fluid in 3D domain

Arbitrary closed geometry for boundaries

Euler coordinates: velocity and temperature

free

injection

no-slip

Applications

Sea and ocean simulation

Low-speed gas flow

Inside 3D channel

Around objects

Definitions

Equation of state

Describe relation between and

Example:

Density

Velocity

Temperature

Pressure

gas constant for air

Governing equations

Continuity equation

For incompressible fluids:

Navier-Stokes equations:

Dimensionless form, use equation of state

Reynolds number (= inertia/viscosity ratio)

Governing equations

Energy equation:

Dimensionless form, use equation of state

heat capacity ratio

Prandtl number

dissipative function

X Y

Z

Fixed Y, Z Fixed X, Z Fixed X, Y

X Y Z

Benefits

Doesnt have hard requirements on time step

Domain decomposition each step can be well parallelized

Many applications

Computational Fluid Dynamics

Computational Finance

Linear 3D PDE

Use global iterations for the whole system of equations

Some equations are not linear:

Use local iterations to approximate the non-linear term

previous

time step

Solve X-dir equations

Solve Y-dir equations

Solve Z-dir equations

Updating all variables next

time step global iterations

Discretization

Use regular grid, implicit finite difference scheme

Second order in space

First order in time

Leads to a tridiagonal system for

Independent system for each fixed pair (j, k)

Need to solve lots of tridiagonal systems

Sizes of systems may vary across the grid

Tridiagonal systems

Outside cell

Inside cell

Boundary cell

system 1

system 2

system 3

Implementation details

{

{

{

build tridiagonal matrices and rhs

solve tridiagonal systems

}

update non-linear terms

}

}

GPU implementation

Store all data arrays entirely in GPU memory

Reduce number of PCI-E transfers to minimum

Map 3D arrays to linear memory

Main kernel

Build matrix coefficients

Solve tridiagonal systems

(X, Y, Z)

Z + Y * dimZ + X * dimY * dimZ

Z fastest-changing dimension

Building matrices

Input data:

Previous/non-linear 3D layers

Coefficients of a tridiagonal matrix

Right-hand side vector

Use C++ templates for direction and equation

a b c

d

Building matrices performance

Poor Z direction performance compared to X/Y

Memory access is uncoalesced, lots of cache misses

Tesl

a C

2050 (

SP)

sec

0.0

0.5

1.0

1.5

2.0

Build Build + Solve

X dir

Y dir

Z dir

Dir Requests

per warp

L1 global

IPC

X 2 3 25 45 1.4

Y 2 3 33 44 1.4

Z 32 0 15 0.2

Build kernels Total time

Building matrices optimization

Run Z phase in transposed XZY space

Better locality for memory accesses

XYZ XYZ

X local iterations Y local iterations Z local iterations

Transpose input arrays

Transpose output arrays

Y local iterations

XZY XZY

Building matrices - optimization

Tridiagonal solver time dominates over transpose

Transpose will takes less % with more local iterations

0.0

0.5

1.0

1.5

2.0

X dir Y dir Z dir Z dirOPT

Transpose

Build + Solve

Tesl

a C

2050 (

SP)

sec

2.5x

Total time

Z dir Requests

per warp

L1 global

IPC

Original 32 0 15 0.2

Transposed 2 3 30 38 1.3

Build kernels

Solving tridiagonal systems

Number of tridiagonal systems ~ grid size squared

Sweep algorithm is the most efficient in this case

for( int p = 1; p < end; p++ ) {

// .. compute tridiagonal coefficients a_val, b_val, c_val, d_val ..

get(c,p) = c_val / (b_val - a_val * get(c,p-1));

get(d,p) = (d_val - get(d,p-1) * a_val) / (b_val - a_val * get(c,p-1));

}

for( int i = end-1; i >= 0; i-- )

get(x,i) = get(d,i) - get(c,i) * get(x, i+1);

Solving tridiagonal systems

Matrix layout is crucial for performance

X, Y directions matrices are interleaved by default

Z is interleaved as well if doing in transposed space

Interleaved layout

a0 a0 a0 a0 a1 a1 a1 a1

Sweep friendly Thre

Thre

Thre

similar as ELLPACK

for sparse matrices

Solving tridiagonal systems

L1/L2 effect on performance

Using 48K L1 instead of 16K gives 10-15% speed-up

Turning L1 off reduces performance by 10%

Really help on misaligned accesses and spatial reuse

Occupancy >= 50%

26-42 registers per thread (different for u, v, w, T)

No shared memory

Performance benchmark

CPU configuration:

Intel Core i7-3930K CPU @ 3.2 GHz, 12 cores

Use OpenMP for CPU parallelization

Mostly memory bandwidth bound

Some parts achieves ~4x speed-up vs 1 core

GPU configuration:

NVIDIA Tesla C2070

Test cases

Box Pipe

Simple geometry

Systems of the same size

Need to compute in all rectangular grid points

Y

X

X

Y

Z 1

1

L

Test cases

White Sea

Complex geometry

Big divergence for system sizes

Need to compute only inside the area

Y

X

Performance results Box Pipe

Grid 128x128x128

0

500

1000

1500

2000

2500

Solve X Solve Y Solve Z Total

CPU

GPU

0

500

1000

1500

2000

2500

Solve X Solve Y Solve Z Total

CPU

GPU

SINGLE DOUBLE segments/ms segments/ms

9.3x

8.4x

Performance results White Sea

Grid 256x192x160

SINGLE DOUBLE segments/ms segments/ms

0

500

1000

1500

2000

2500

3000

3500

4000

Solve X Solve Y Solve Z Total

CPU

GPU

0

500

1000

1500

2000

2500

3000

3500

4000

Solve X Solve Y Solve Z Total

CPU

GPU10.3x

9.5x

Outline

Fluid Simulation in 3D domain

Multi-GPU implementation

General splitting algorithm

Running computations using CUDA

Benchmarking and performance analysis

Improving weak scaling

Multi-GPU motivation

Limited available amount of memory

3D arrays: grid, temporary arrays, matrices

Max size of grid that can fit into Tesla M2050 ~ 2243

Distribute the computations between multiple GPUs and

multiple nodes

Can compute large grids

Speed-up computations

Main Idea of mGPU

Systems along Y/Z are solved independently in

parallel on each GPU

No data transfer

Along X data must be synchronized

X Y

Z

GPU 0 GPU 1 GPU 2

Computing alternating directions:

X Y Z

CUDA - parallelization

Split the grid along X (the longest stride)

Z + Y * dimZ + X * dimY * dimZ

Launch kernels on several GPUs from one host threa

Recommended