GPU Programming
On a GPU whose limit is 1024 threads per thread block, a CUDA kernel is launched with blockDim.x set to 2048. What generally happens?
- AThe GPU automatically splits it into two blocks of 1024 threads each and runs them
- BOnly the first 1024 threads run and the rest are ignored
- CThe launch configuration is treated as invalid, so the kernel does not run and an error is returned
Show answer and explanation
Answer: C. The launch configuration is treated as invalid, so the kernel does not run and an error is returned
All threads of a thread block must reside on one SM at the same time and be able to cooperate through shared memory and __syncthreads(), so the number of threads per block is limited. If a kernel is launched with a configuration above the limit, not a single thread runs, and the launch fails with an error indicating an invalid configuration. A kernel launch returns no value, so unless the error is checked with cudaGetLastError() or similar, it is easy to miss that the result array was never updated. Work for 2048 threads is divided among multiple blocks of 1024 threads or fewer.
- A. There is no automatic splitting. The program decides the number of blocks and threads.
- B. The kernel does not run partially; the launch itself fails.
- C. Correct. Make a habit of checking for errors after a launch.