Knowledge check — answers

Answers

  1. B — host code runs on the CPU, device code on the GPU.

  2. C — 4 · 4 · 1 = 16 blocks, each with 8 · 8 · 1 = 64 threads, gives 16 · 64 = 1024 threads.

  3. C — the triple-chevron syntax <<<blocks, threads>>> launches a kernel.

  4. C — __global__ functions are called from host code and execute on the device.

  5. C — threadIdx.x + blockIdx.x * blockDim.x = 2 + 1 · 256 = 258.

  6. A — each thread processes several elements, so a fixed execution configuration handles any array size.

  7. D — __host__ __device__ compiles the function for both execution spaces.

  8. A — kernels cannot have return values; pointers, device-function calls and branching are all allowed.

  9. C — kernel launches are asynchronous; errors and completion are observed on subsequent CUDA calls or cudaDeviceSynchronize().

  10. B — the macro inspects the returned error code and reports it instead of silently ignoring it.