Easy
A launch configured with dim3(64, 32) threads per block
The program below fills a 256 x 32 buffer with 1.0f using four blocks of 64 x 32 threads, then copies it back and prints the sum of all elements. Nothing in the program checks a CUDA return code. It runs on any current NVIDIA GPU. What does it print?
fill.cu
__global__ void fill(float* out, int width) {
int x = blockIdx.x * blockDim.x + threadIdx.x; // 0..255
int y = threadIdx.y; // 0..31
out[y * width + x] = 1.0f;
}
int main() {
const int width = 256, height = 32; // 8192 elements
const size_t bytes = width * height * sizeof(float);
float* d_out;
cudaMalloc(&d_out, bytes);
cudaMemset(d_out, 0, bytes);
fill<<<4, dim3(64, 32)>>>(d_out, width);
static float h[256 * 32];
cudaMemcpy(h, d_out, bytes, cudaMemcpyDeviceToHost);
float sum = 0.0f;
for (float v : h) sum += v;
printf("%.0f\n", sum);
}32 of 46 in GPU / CUDA