26
Blasting Sand with CUDA: MPM Sand Simulation for VFX Gergely Klár DreamWorks Animation

Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

  • Upload
    others

  • View
    41

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

Blasting Sand with CUDA:

MPM Sand Simulation for VFX Gergely Klár

DreamWorks Animation

Page 2: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX
Page 3: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

tn tn+1

Page 4: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

tn tn+1

Page 5: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

tn tn+1

Page 6: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

Grid influence

Page 7: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

Naïve Particles-to-Grid

Page 8: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

Gather Particles-to-Grid

Page 9: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

Our Solution

• Each particle is read only once,

• We efficiently use shared memory for the grids,

• We significantly reduce the number of atomic operations,

• And our secret sauce: a special data structure for particle queries.

Page 10: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX
Page 11: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX
Page 12: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX
Page 13: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

1 CUDA

Block 1 CUDA

Block

1 CUDA

Block

1 CUDA

Block 1 CUDA

Block

1 CUDA

Block

1 CUDA

Block 1 CUDA

Block

1 CUDA

Block

Page 14: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX
Page 15: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

CellBins

ParticleIDs

Actual particle data

Page 16: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

TileBins

CellBins

ParticleIDs

Actual particle data

Page 17: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

• In each block/tile: – Get blockIdx

– Cells in the tile are TileBins[blockIdx-1].. TileBins[blockIdx]-1

– Get a cellId for each warp from this list • Each thread works on two affected grid nodes

• Particles of a cell are CellBins[cellId-1]..CellBins[cellId]-1

• Compute the contribution from the particle

• Store in shared

– Write back to global

Page 18: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

Tile & Cell Keys

●Particle coordinates: (px, py, pz)

●Cell coordinates: (ci, cj, ck) = ⌊(px, py, pz)/Δx⌋

●Tile and in-tile coordinates: (ci, cj, ck) = (ti, tj, tk)∙TILE_SIZE + (ri, rj, rk)

Δx

tj ti tk rj rk ri 7 bits 7 bits 7 bits 3 bits 3 bits 3 bits

32 bit unsigned integer

Page 19: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

Tile Bins

sort

Initial Particle IDs

Particle IDs

RLE

inc. sum Cell Bins

masked RLE

inc. sum

Tile & Cell Keys ● When sorted as uint32s, keys of the

same tile will be consecutive

● RLE encoding counts the number of

particles per cell

● The running sum of the counts gives

the offsets to particles

● RLE encoding with a mask for the

tile bits counts the number of non-

empty cells per tile

● The running sum of these counts

gives the offsets to cells

Page 20: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

Results

Page 21: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

Overall

0

200

400

600

800

1000

262K 884K 2,097K 7,000K

# of particles

GPU

CPU

Milliseconds per time step. Smaller is better.

nVidia Quadro K5200 Intel Xeon CPU E5-2697 v3 @ 2.60GHz w/ 28 cores

Page 22: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

Particles to Grids

0

100

200

300

400

500

600

262K 884K 2,097K 7,000K

Grids to Particles

0

100

200

300

400

500

600

262K 884K 2,097K 7,000K

Milliseconds per time step. Smaller is better.

Page 23: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

Summary

• Particle binning with sort-RLE-scan

• Breaking the domain to tiles fitting to shared memory

• Processing particles of a cell by a single warp

Page 24: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

Special thanks to:

• Ken Museth

• Stephen Jones

• Jeff Budsberg

• Lawrence Lee

• Rob Tesdahl

• David Tonnesen

• Ibrahim Sani

Page 25: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX
Page 26: Blasting Sand with MPM - GPU Technology Conferenceon-demand.gputechconf.com/...greg-klar-blasting-sand-with-nvidia-cuda.pdf · Blasting Sand with CUDA: MPM Sand Simulation for VFX

Thank you!