In a GPU kernel, the 32 threads of one warp reach `if (x[i] > 0) { A } else { B }`. Half the threads have x[i] > 0 and half do not. What typically happens?
AThe two halves run A and B at the same time on separate hardware
BThe warp runs A with the else-threads masked off, then runs B with the if-threads masked off
CThe threads that disagree with the first thread are cancelled
DThe compiler rejects the kernel, because warps cannot branch
Threads in a warp share one instruction stream. When they diverge, the hardware executes each path in turn and disables the threads that did not take it. This branch divergence can cut throughput by up to the number of distinct paths.
Question 2 Multiple Choice
How does a GPU mainly keep its arithmetic units busy while some threads wait hundreds of cycles for data from memory?
AIt uses caches large enough to hold all data
BIt switches each cycle to other warps that are ready to execute
CIt predicts the data values and checks them later
DIt raises its clock rate while waiting
A GPU multiprocessor keeps the state of many warps resident. When one warp stalls on memory, the scheduler issues from another warp that is ready. With enough warps, memory latency is hidden by other work, which is why GPU programs launch far more threads than there are cores.
Question 3 True / False
Moving any program to a GPU will make it run faster than on a modern CPU.
TTrue
FFalse
Answer: False
GPUs excel at large, uniform, data-parallel tasks. Programs that are mostly serial, branch unpredictably, or operate on small data can be slower, because each GPU thread is weak on its own and data must be copied between CPU and GPU memory.
Question 4 Short Answer
A student moves the addition of two 10-element arrays to a discrete GPU and finds it is slower than a simple CPU loop. Give the main reason.
Think about your answer, then reveal below.
Model answer: The fixed costs dominate: the arrays must be copied over the bus to GPU memory and the result copied back, and launching a kernel has overhead. Ten additions take almost no time on a CPU, so these costs far exceed any gain from parallelism.
GPU offload pays off when the amount of parallel arithmetic is large compared with the data transfer and launch overhead.