GPU Programming

Which processing tends to run inefficiently on a GPU?

  1. AWalking a linked list one node at a time, changing behavior based on each element's value
  2. BElement-wise addition of two large arrays
  3. CDoubling the brightness of every pixel in a large image
Show answer and explanation

Answer: A. Walking a linked list one node at a time, changing behavior based on each element's value

In a linked list the next element's location is unknown until the current one is read, so it cannot be traversed in parallel. If behavior also depends on values, threads within a lockstep group diverge, lowering efficiency, and scattered memory locations prevent combined reads. GPUs suit work that is independent per element and applies the same operation to data at consecutive addresses.

  • A. Correct. It cannot be parallelized and involves many branches.
  • B. Each element is independent, so it suits a GPU.
  • C. Each pixel is independent, so it suits a GPU.
Practice this topic Back to topic

More GPU Programming questions

  1. In GPU programming such as CUDA, what is a "kernel"?
  2. Which correctly orders the CUDA thread hierarchy from largest to smallest?
  3. A CUDA kernel computes each thread's index i with the expression above. What is i for the thread with blockIdx.x = 2, blockDim.x = 256 and threadIdx.x = 5?
  4. To process a 1000-element array with one element per thread and 256 threads per block, how many blocks should be launched?
  5. Why does the CUDA kernel above include "if (i < n)"?