Hard
An interleaved-addressing reduction keyed on threadIdx.x % (2*s)
This is the classic 'naive' shared-memory reduction taught in early CUDA tutorials. blockDim.x == 256, and s is a runtime loop variable. What are its two distinct performance problems, beyond just being 'not optimal'?
kernel.cu
__shared__ float sdata[256];
sdata[threadIdx.x] = input[blockIdx.x * blockDim.x + threadIdx.x];
__syncthreads();
for (int s = 1; s < blockDim.x; s *= 2) {
if (threadIdx.x % (2 * s) == 0) {
sdata[threadIdx.x] += sdata[threadIdx.x + s];
}
__syncthreads();
}
// result in sdata[0]21 of 46 in GPU / CUDA