Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

51
PUTTING A HEART INTO A BOX GPGPU simulation of a Cardiac Model on the Xbox 360 Dr Simon Scarle Serious Games Institute Coventry University

description

Talk entitled "Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360" given by Simon Scarle at the Games for Health Conference 2010.

Transcript of Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Page 1: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

PUTTING A HEART INTO A BOX

GPGPU simulation of a Cardiac Model on the Xbox 360 Dr Simon Scarle

Serious Games InstituteCoventry University

Page 2: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Outline

Me : Where I’m from and what I do/did Serious Games: Tito Beco Games with a Purpose & GPGPU

Particles Cardiac Modelling

Previous work XBox 360 GPU

In the News Public Understanding of Science Exchange between research and Games

Page 3: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Who am I?

BSc Mathematical Physics UMIST

PhD Theoretical Physics KCL Substitutional defects in

semiconductors PDRA

Extended linear Defects Thin film delamination Ion motion in a polymer Electro-cardio dynamics

Rare STG Serious Games Project

Senior Programmer

Page 4: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Serious Games Project

Page 5: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Basic Ideas

Childhood Obesity-Serious Games Project NHS funded

To inform children about ideas related to good nutrition and exercise Key stage 2

8-11 years No overt teaching

Information as much as possible presented via Gameplay not “lecturing” (Everand)

Physically Enhanced puzzles Simple and well known puzzle game formats presented in a

motion controlled manner As much as possible all interaction via motion

Not as good a “real” exercise but better than a controller

Page 6: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

GAME DEMO

Page 7: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Games Hardware: Serious Use

University of Illinois 70 PS2 supercomputer

Folding/SETI at Home Folding Game – Games with a Purpose New Scientist Article

Games Consoles Reveal their Hidden Power 16 linked PS3’s calculating gravity waves from

black hole collisions Other researchers using high-end graphics

cards on PC’s to simulate the repulsion between two electrons in an atom

Page 8: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

But it’s only a Games Console?

Almost by definition the current Generation of games consoles and PCs are the most powerful bangs per buck computing hardware you can buy

The cell chip at the heart of the PS3 is the CPU now used in IBM’s high-end systems

XBox 360 Xenon – triple core 3.2 GHz PowerPC processor Custom ATI 500 MHz GPU

Page 9: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

What is GPGPU?

General-Purpose computation on the GPU General-Programming on the GPU Modern Graphical Processing Units are

highly optimised parallel computing devices But highly optimised for graphics But if your problem can be put in a form usable

by the GPU you can still exploit this GPU becoming more programmable

HLSL (cut down C ) Compute Unified Device Architecture (Nvidia)

GPGPU increasingly being used for HPC

Page 10: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Why am I here?

Page 11: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

GPU Coding

VERTEX SHADER PIXEL SHADER

Transform object’s vertex coordinates from its own space to that of viewpoint given by the “camera”

pass this information on to pixel shader also further info normal, (bi-)tangent, UV

coordinates

Rasterisation Three vertices of a

triangle extrapolate given

values of the vertices across this triangle

calculate the required colour of the final pixel using data from vertex shader

Page 12: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

GPGPU example

Particles ancillary or

secondary animation

Basic physics simulation of a large number of non interacting point particles

used for various special effects

sparks fire smoke clouds dust mud

fairy sparkles explosions rain fog snow blood splatter

Page 13: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

PARTICLE VIDEO

Page 14: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Particle GPGPU

simulation vertex struct VS_INPUT

{float4 pos :

POSITION;float4 vel :

TANGENT;};

pos x, y, z Life Time

vel x’, y’, z’ Life Left

Page 15: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

A More Realer World Problem

Abnormal propagation of electrical excitation in the heart

Cardiac arrhythmias Ventricular tachycardia & fibrillation

Leads to sudden cardiac death Largest categorical cause of death in the

industrialized world My previous work used a genetic

algorithm to evolve diseased tissue structures that were increasingly arrhythmic

Page 16: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Product of the GA

Page 17: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

The Mathematical model

Mono-domain equation

Fenton-Karma 4 variable FK4v Vm, v, w & d

ionmm

m IVt

VC

D.

Cm membrane capacitance

Vm voltage across cell membrane

D Diffusion tensor

Iion membrane current flow

DIFFUSIVE PART

INTERNAL PART

Page 18: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Fenton Karma 4 Variable

Well used basic model Jfi fast inward Na+

Jsi slow inward Ca+

Jso slow outward K+

Cardiac cell behaviour excitable refractory recovery

m

sosifiion C

JJJI

Page 19: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

XBox 360 CPU Simulation

As part of the acclimatization process asked to produce a demo using the R1SDK to reimplement a previous project

I did a “gameified” cardiac tissue simulation arena is excitable using the FHN model

Reimplemented research code on the XBox NB just changed enough to get it to work, no

optimization

Page 20: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

CPU v GPU

XBox 360 CPU has three cores 1 vector/scalar op per clock tick i.e. 3 * ( 5 + 1 ) * 2 = 36 flops per clock tic At 3.2 Ghz gives 115.2 Gflops per second

XBox 360 GPU has 3 execution units (ALUs) 16 vector/scalar ops per clock tick i.e. 3 * 16 * ( 4 + 1 ) * 2 = 480 flops per clock tic At 500 Mhz gives 240 Gflops per second

CPU peak impossible to obtain in the real world ( below ~50% )

GPU can get far closer due to its more optimized nature (~80%)

Page 21: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

XBox 360 GPU Simulation

simulation vertex struct vertex{

float4 Position: POSITION;

float4 FK4v: NORMAL;

float4 Neigh:

TEXCOORD0; float4 DVm

: TEXCOORD1; };

Position x, y, z, Vm

FK4v v, w, d, cell type

Neigh indices of the four

neighbours of this cell

DVm calculation space

for diffusion

Page 22: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

XBox 360 GPU Simulation

GPGPU are good for embarrassingly parallel problems and SIMD e.g. rendering 3D

graphics Due to diffusion

cardiac tissue simulation isn’t embarrassingly parallel

require some form of synchronisation multiple vertex shaders pass the vertex buffer

through each in turn Zapp

applies stimulation Diffusion

calculates diffusion terms

Simulation carries out FK4v model

Page 23: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

GPGPU DEMO

Page 24: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

CPU/GPU Comparison

10 30 50 70 90 110

130

150

170

190

0

500

1000

1500

2000

2500

GPU

CPU

side of square

Fra

mes p

er

Secon

d

Page 25: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

CPU/GPU Comparison

Optimisation CPU code wasn’t optimised for running on the

XBox However, neither was the GPU code Optimisation could make both faster but

unlikely CPU could ever beat GPU

Page 26: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

“Free” Visualization

If you wish to do 3D visualisation for a simulation Convert simulation data to a GPU useable

form Vertices Textures

Already done this when using GPGPU Also created a series of different render

shaders to highlight different aspects of the simulation

Page 27: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

VISUALIZATION DEMO

Page 28: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

In The News

Page 29: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

BBC News Technology

Page 31: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Daily Telegraph Website

Page 32: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

CNN

Page 33: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

E-mails

Hi sirSir my name is zarshad khan

from Pakistan sir  I am an SVT patient plz let me know how  I should get this machine for my own treatment

Zarshad khan

Page 34: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

E-mails

Hello Dr Scarle,

My name is Keith and I am a student at Avon Middle School in Connecticut.  I am in Mr. Rand's eighth grade science class. I read the article about how you used an Xbox  GPU to do research modelling for cardiac arrhythmias.  I have 2 questions for you for my school current events. 

1.  Did you actually use an Xbox to do your testing or did you take it apart for the chip and put it in another machine? And did you do all the reworking for the code?

2. What made you switch from a software engineer on games to doing medical research on cardiac arrhythmias? 

 Thank you for your time.  Keith

Page 35: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

PUS

Publicity from my paper shows the use of games technology could be a very powerful tool in the PUS field. Public Understanding of Science

Putting real science into games A fundamental element of a game being

based on research simulation code Demo released to public as well as a website

detailing the research which has inspired the game

XNA / Indie Games on XBox 360

Page 36: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

CARDIAC MODEL : THE VIDEOGAME

Page 37: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Borrowing from Games

The games industry is at the fore front of computer technology Possibly IS the fore

front GPU CPU

Page 38: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Multi-variable display

Use advanced rendering techniques to acquire more understanding from multi-variable data

FK4v RGB Height Filament calculation in real time

Use XBox 360 as a simulation scratchpad Direct use of Game Consoles best

computational fit Cheaply grab that extra bit of computing power

Page 39: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Conclusions

GPGPU is a highly effective way of carrying out quite high end parallel computing on “domestic” hardware

Although major reworking of code framework is required but this can easily be outweighed by the benefits in gained computational power and speed

Games are COOOL! Games consoles are POWERFUL! Let’s borrow some of that fame and technological in more serious work.

Page 40: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Many thanks to everyone previously involved in all the work outlined here.

Page 41: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

THANKSAny Questions?

Simon Scarle [email protected]

If you’d like your simulation to be game-ified, please speak to me afterwards or contact me

at the e-mail address below.

Page 42: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

The Science Bit

Asked by old research group to do seminar talk Made it part of Rare’s

Academic Liaison programme

Old Boss suggested I write this up Wanted one better than

a widget paper Cardiac model GPGPU

Actual do some kind of science with

Cardiac Tissue Logic Circuits

Page 43: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

OR gate

Page 44: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Diode

Page 45: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Diode

Page 46: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Cardiac Side

Something of a Holy grail in cardiac research would be a technique to analyse a structure of diseased/damaged cardiac cells and the in coming excitation and state whether or not you have a re-entrant circuit

Page 47: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Computational Side

Used a train of excitations on the beat to send 1 Train on the half beats to send 0 NOT gate is just a detour

NOR gate is a universal gate Turing Complete system

Halting Problem Impossible to predict whether an arbitrary

programme will terminate or run for ever Thus making the “is their a re-entrant circuit”

question the reverse of the halting problem and hence impossible

Page 48: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Game Controller

Keyboards aren’t very good In fact deliberately

bad Better layouts and

designs just keep failing

Game Controller is almost as bad But gamers are

damn good at using them

Page 49: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

Game Developers Interested in simulations of

Animal Behaviour AI

Physics Movement Fracture &

deformation Fluid dynamics

Perception Vision

Optics & Lighting Gesture recognition

They also want to develop these simulations to work in real time on the current generation of consoles

Game code is some of the most fault tolerant and tested code produced

Requires exceptionally skilled coders to produce

Page 50: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

“Water” GPGPU

Simple dynamic water effect Pixel shader

Water Texture R: Water Height G: Previous Water

Height B: Normal X

component A: Normal Y

component

Page 51: Putting a Heart into a Box:GPGPU simulation of a Cardiac Model on the Xbox 360

WATER DEMO