I noticed, that using dynamic indices reduces the speed of CUDA Code by a factor of 12 - see the following example:
__global__ void static3Ops(int start, int end, const float* p, const int* prog_dont_use, float* c)
{
int i = threadIdx.x;
float buf[5];
buf[0] = 1.0e7;
buf[1] = c[i];
const int prog[] = { 0,1,2,3,4,5 };
for (long j = start; j < end; j++) {
buf[2] = p[j];
buf[3] = buf[prog[0]] + buf[prog[1]];
buf[4] = buf[prog[2]] - buf[prog[3]];
buf[1] = buf[prog[4]] * buf[prog[5]];
}
c[i] = buf[1];
}
is 12x faster than
__global__ void static3Ops(int start, int end, const float* p, const int* prog, float* c)
{
int i = threadIdx.x;
float buf[5];
buf[0] = 1.0e7;
buf[1] = c[i];
for (long j = start; j < end; j++) {
buf[2] = p[j];
buf[3] = buf[prog[0]] + buf[prog[1]];
buf[4] = buf[prog[2]] - buf[prog[3]];
buf[1] = buf[prog[4]] * buf[prog[5]];
}
c[i] = buf[1];
}
Any hint how to minimize that overhead? The dynamic nature is a core feature of my code...so I hardly get around without it...
Note, that the overhead on the CPU is just about 20%.