Knowledge check — answers¶
Answers
B — host code runs on the CPU, device code on the GPU.
C — 4 · 4 · 1 = 16 blocks, each with 8 · 8 · 1 = 64 threads, gives 16 · 64 = 1024 threads.
C — the triple-chevron syntax
<<<blocks, threads>>>launches a kernel.C —
__global__functions are called from host code and execute on the device.C —
threadIdx.x + blockIdx.x * blockDim.x = 2 + 1 · 256 = 258.A — each thread processes several elements, so a fixed execution configuration handles any array size.
D —
__host__ __device__compiles the function for both execution spaces.A — kernels cannot have return values; pointers, device-function calls and branching are all allowed.
C — kernel launches are asynchronous; errors and completion are observed on subsequent CUDA calls or
cudaDeviceSynchronize().B — the macro inspects the returned error code and reports it instead of silently ignoring it.