19.08.2015 Views

Ray Tracing and Molecular Dynamics - GPGPU.org

Ray Tracing and Molecular Dynamics - GPGPU.org

Ray Tracing and Molecular Dynamics - GPGPU.org

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Ray</strong> <strong>Tracing</strong> on GPUsIan BuckGraphics LabStanford University


Techniques UsedData structure navigationTexture memory stores data structuresDependent texture fetches walk through dataFlow controlKernel binding based on occlusion query resultsEfficient selective execution of kernels using early-zocclusion cullingDifficulty in flow control disappearing with newestgraphics cardsPS 3.0<strong>GPGPU</strong>Ian BuckStanford UniversityL5


Efficient Selective ExecutionRendering giant screenfilling quad not idealNot all pixels need toprocess every renderingpassUse early fragment killComputation maskControllable early-Zocclusion cullingTrade computation forb<strong>and</strong>width<strong>GPGPU</strong>Ian BuckStanford UniversityL7


Cornell Box – <strong>Ray</strong> Traced ShadowsRendered using a Radeon 9700 Pro<strong>GPGPU</strong>Ian BuckStanford UniversityL8


Quake 3 – <strong>Ray</strong> Traced ShadowsRendered using a Radeon 9700 Pro<strong>GPGPU</strong>Ian BuckStanford UniversityL10


Performance ResultsRadeon 9700 Pro100M ray-triangle intersections/s300K to 4.0M rays/sBetween 3 – 12 fps @ 256x256 pixelsRadeon X800Brook Version: 187M ray-triangle intersections/sCPU implementation20M intersections/s P3 800 MHz [Wald et al. 2001]800K to 7.1M ray/s 2.5 GHz P4 [Wald et al. 2003]With simple shading: 1.8M to 2.3M rays/s<strong>GPGPU</strong>Ian BuckStanford UniversityL11


<strong>Molecular</strong> <strong>Dynamics</strong> on GraphicsHardwareIan BuckGraphics LabStanford University


Folding@home: Vijay P<strong>and</strong>eWhat does Folding@Home do?Folding@Home is a distributedcomputing project which studiesprotein folding, misfolding,aggregation, <strong>and</strong> related diseases.We use novel computationalmethods <strong>and</strong> large scale distributedcomputing, to simulate timescalesthous<strong>and</strong>s to millions of times longerthan previously achieved. This hasallowed us to simulate folding for thefirst time, <strong>and</strong> to now direct ourapproach to examine folding relateddisease.Results from Folding@Homesimulations of villin<strong>GPGPU</strong>Ian BuckStanford UniversityL13


GROMACS: Erik LindahlGROMACS provides extremely high performancecompared to all other programs.Lot of algorithmic optimizations:Own software routines to calculate the inversesquare root.Inner loops optimized to remove all conditionals.Loops use SSE <strong>and</strong> 3DNow! multimediainstructions for x86 processorsFor Power PC G4 <strong>and</strong> later processors: Altivecinstructions providednormally 3-10 times faster than any otherprogram.<strong>GPGPU</strong>Ian BuckStanford UniversityL14


Nonbonded forcesAccounts for 80% of theruntime in C/Fortran codeMost common form:<strong>GPGPU</strong>Ian BuckStanford UniversityElectrostaticsLennard-JonesL15


Using cutoffs & neighbor listsNeighbor list constructed every 10 steps.In practice: 10,000-100,000 atoms, with100-200 neighbors in each list614711121514192813172059162118310Neighbor list for atom 13 ={ 8, 9, 11, 12, 15, 16, 17}<strong>GPGPU</strong>Ian BuckStanford UniversityL16


What we do in the inner loop?Inner loopFor each i atom {fetch atom i datai_force = 0;For each j atom in our neigborlist {fetch atom j dataCalculate vectorial distance; dr = r i -r jCalculate r 2 =dx*dx+dy*dy+dz*dz, <strong>and</strong> 1/r=1/sqrt(r 2 )Calculate potential <strong>and</strong> vectorial forceSubtract the force from the j atom forcei_force += force;}Store i_force;}<strong>GPGPU</strong>Ian BuckStanford UniversityL17


What we do in the inner loop?For each i atom {fetch atom i datai_force = 0;Reading from memoryFor each j atom in our neigborlist {fetch atom j dataCalculate vectorial distance; dr = r i -r jCalculate r 2 =dx*dx+dy*dy+dz*dz, <strong>and</strong> 1/r=1/sqrt(r 2 )Calculate potential <strong>and</strong> vectorial forceSubtract the force from the j atom forcei_force += force;Writing to memory}Store i_force;}<strong>GPGPU</strong>Ian BuckStanford UniversityL18


What we do in the inner loop?For each i atom {fetch atom i dataTexture Fetchi_force = 0;Reading from memoryFor each j atom in our neigborlist {fetch atom j dataTexture FetchCalculate vectorial distance; dr = r i -r jCalculate r 2 =dx*dx+dy*dy+dz*dz, <strong>and</strong> 1/r=1/sqrt(r 2 )Calculate potential <strong>and</strong> vectorial forceSubtract the force from the j atom forcei_force += force;Writing to memory}Store i_force;}<strong>GPGPU</strong>Ian BuckStanford UniversityL19


What we do in the inner loop?For each i atom { For each fragment {fetch atom i dataTexture Fetchi_force = 0;Reading from memoryFor each j atom in our neigborlist {fetch atom j dataTexture FetchCalculate vectorial distance; dr = r i -r jCalculate r 2 =dx*dx+dy*dy+dz*dz, <strong>and</strong> 1/r=1/sqrt(r 2 )Calculate potential <strong>and</strong> vectorial forceSubtract the force from the j atom forcei_force += force;Writing to memory}Store i_force;Output Color}<strong>GPGPU</strong>Ian BuckStanford UniversityL20


What we do in the inner loop?For each i atom { For each fragment {fetch atom i dataTexture Fetchi_force = 0;Reading from memoryFor each j atom in our neigborlist {fetch atom j dataTexture FetchCalculate vectorial distance; dr = r i -r jCalculate r 2 =dx*dx+dy*dy+dz*dz, <strong>and</strong> 1/r=1/sqrt(r 2 )Calculate potential <strong>and</strong> vectorial forceSubtract the force from the j atom forceSCATTERi_force += force;Writing to memory}Store i_force;Output Color}<strong>GPGPU</strong>Ian BuckStanford UniversityL21


What we do in the inner loop?For each i atom { For each fragment {fetch atom i dataTexture Fetchi_force = 0;Reading from memoryFor each j atom in our neigborlist {fetch atom j dataTexture FetchCalculate vectorial distance; dr = r i -r jCalculate r 2 =dx*dx+dy*dy+dz*dz, <strong>and</strong> 1/r=1/sqrt(r 2 )Calculate potential <strong>and</strong> vectorial forceSubtract the force from the j atom forceSCATTERi_force += force;Writing to memory}Store i_force;Output Color}Perform each force computation twice<strong>GPGPU</strong>Ian BuckStanford UniversityL22


Inner loopC Versionjnr = jjnr[k];j3 = 3*jnr;jx = pos[j3];jy = pos[j3+1];jz = pos[j3+2];dx = ix - jx;dy = iy - jy;dz = iz - jz;rsq = dx*dx+dy*dy+dz*dz;rinv = 1.0/sqrt(rsq);rinvsq = rinv*rinv;rinvsix = rinvsq*rinvsq*rinvsq;tjA = ntiA+2*type[jnr];vnb6 = rinvsix*nbfp[tjA];vnb12 = rinvsix*rinvsix*nbfp[tjA+1];vnbtot = vnbtot + vnb12-vnb6;qq = iqA*charge[jnr];vcoul = qq*rinv;fs = (twelve*vnb12-six*vnb6+vcoul)*rinvsq;vctot = vctot + vcoul;tx = dx*fs;ty = dy*fs;tz = dz*fs;fix = fix + tx;fiy = fiy + ty;fiz = fiz + tz;jnr = f1tex1D (jjnr, k);j = f3tex1D(pos, jnr);d = i - j;rsq = dot(d, d);rinv = rsqrt(rsq);rinvsq = rinv*rinv;rinvsix = rinvsq*rinvsq*rinvsq;tjA = ntiA+2*f1tex1D(type, jnr);vnb6 = rinvsix*f1tex1D(nbfp, tjA);vnb12 = rinvsix*rinvsix*f1tex1D(nbfp, tjA+1);vnbtot = vnbot+vnb12-vnb6;qq = iqA * f1tex1D(charge, jnr);vcoul = qq*rinv;fs = (twelve*vnb12-six*vnb6+vcoul)*rinvsq;vctot = vctot + vcoul;t = d * fs;fi = t;Cg Version<strong>GPGPU</strong>Ian BuckStanford UniversityL23


ChallengesScalar inner loop codeSolution: Perform 4 force calc per loop iterationDuplicate force calculationsBad: 2x computation than CPUGood: Much less b<strong>and</strong>width!!!Don't have to output partial forcesOverall b<strong>and</strong>width much more expensive thancompute on GPUsInner loop unrolling20 interactions before instruction limit<strong>GPGPU</strong>Ian BuckStanford UniversityL24

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!