J'ai créé un système de particules simple. J'ai un appareil avec la capacité de calcul 2.1. Que pourrais-je changer pour optimiser le noyau?cuda - optimisation du noyau
Je suppose que les variables tPos
et tVel
sont stockées dans les registres.
__global__ void particles_kernel(float4 *vbo, float4 *pos, float4 *vel)
{
int tid = blockIdx.x * blockDim.x + threadIdx.x;
float4 tPos = pos[tid];
float4 tVel = vel[tid];
tPos.x += tVel.x;
tPos.y += tVel.y;
tPos.z += tVel.z;
if(tPos.x < -2.0f)
{
tVel.x = -tVel.x;
}
else if(tPos.x > 2.0f)
{
tVel.x = -tVel.x;
}
if(tPos.y < -2.0f)
{
tVel.y = -tVel.y;
}
else if(tPos.y > 2.0f)
{
tVel.y = -tVel.y;
}
if(tPos.z < -2.0f)
{
tVel.z = -tVel.z;
}
else if(tPos.z > 2.0f)
{
tVel.z = -tVel.z;
}
pos[tid] = tPos;
vel[tid] = tVel;
vbo[tid] = make_float4(tPos.x, tPos.y, tPos.z, tPos.w);
}
Cela va être vraiment difficile de répondre sans tomber dans les généralités. Vous voudrez peut-être jeter un coup d'œil à "[Optimisation CUDA partie I (PDF)] (http://developer.download.nvidia.com/CUDA/training/NVIDIA_GPU_Computing_Webinars_CUDA_Optimization_April-2009.pdf)" et "[Optimiser CUDA partie II (PDF)] (http://developer.download.nvidia.com/CUDA/training/NVIDIA_GPU_Computing_Webinars_Further_CUDA_Optimization.pdf) "pour des conseils et astuces générales. D'autres excellentes ressources sont "Programmation Massively Parallel Processors" et "CUDA par exemple". – Bart