Hard
A loop that reloads base[0] on every iteration while storing through out
Global memory access latency is on the order of several hundred cycles; a register read is effectively free (~1 cycle, no separate instruction-level cost beyond the operation itself). Every iteration of this loop stores one element of out and re-reads the same base[0] from global memory. What is the most accurate prediction?
kernel.cu
__global__ void scaleRows(float* out, const float* in, float* base) {
int i = blockIdx.x * blockDim.x + threadIdx.x;
for (int k = 0; k < 1000; ++k) {
out[i * 1000 + k] = in[i * 1000 + k] * base[0]; // base[0] read again each pass
}
}12 of 46 in GPU / CUDA