Lesson 17 Particle System
Lesson 17 Particle System
Administrative
• Still missing some design reviews
- Please email to me slides from presentation
L17: Lessons from - And updates to reports
• Grading
Implementations - Lab2 problem 1 graded, problem 2 under construction
- Return exams by Friday AM
1
4/16/09
2
4/16/09
11
L17: Particle Systems L17: Particle Systems
CS6963 L2:Introduction to CUDA
CS6963
11 12
3
4/16/09
3. Cache Particle Data in Shared Memory 4. Use texture cache for read-only data
__shared__ float3 s_pos[N_THREADS]; • Texture memory is special section of device global
memory
__shared__ float3 s_vel[N_THREADS];
- Read only
__shared__ float3 s_force[N_THREADS];
- Cached by spatial location (1D, 2D, 3D)
int tx= threadIdx.x;
• Can achieve high performance
idx= threadIdx.x+ blockIdx.x*blockDim.x;
- If reuse within thread block so access is cached
s_pos[tx] = P[idx].pos;
- Useful to eliminate cost of uncoalesced global memory
s_vel[tx] = P[idx].vel; access
s_force[tx] = P[idx].force; • Requires special mechanisms for defining a texture,
__syncthreads(); and accessing a texture
s_pos[tx] = s_pos[tx] + s_vel[tx] * dt;
s_vel[tx] = s_vel[tx] + s_force[tx]/mass * dt;
P[idx].pos= s_pos[tx];
P[idx].vel= s_vel[tx];
L17: Particle Systems L17: Particle Systems
CS6963 13 CS6963 14
Using Textures: from Finite Difference Example Use of Textures in Particle Simulation
• Declare a texture ref • Macro determines whether texture is used
texture<float, 1, …> fTex; a. Declaration of texture references in
particles_kernel.cu
• Bind f to texture ref via an array
#if USE_TEX
cudaMallocArray(fArray,…) // textures for particle position and velocity
cudaMemcpy2DToArray(fArray, f, …);
cudaBindTextureToArray(fTex, fArray…); texture<float4, 1, cudaReadModeElementType> oldPosTex;
texture<float4, 1, cudaReadModeElementType> oldVelTex;
• Access with array texture functions
f[x,y] = tex2D(fTex, x,y); texture<uint2, 1, cudaReadModeElementType> particleHashTex;
texture<uint, 1, cudaReadModeElementType> cellStartTex;
4
4/16/09
5
4/16/09