NCA CUDA Programming & Parallel Computing 2 — Questions and Answers
Question 1: Which CUDA memory type offers the lowest latency access for threads within the same block?
- Global memory
- Shared memory (Correct answer)
- Constant memory
- Texture memory
Correct answer: Shared memory
Shared memory is on-chip and accessible by all threads in a block with very low latency compared to off-chip global memory.
Question 2: What is a CUDA warp?
- A group of 64 threads that execute in lockstep
- A group of 32 threads that execute in lockstep (Correct answer)
- A single thread block
- A set of thread blocks on one SM
Correct answer: A group of 32 threads that execute in lockstep
A warp consists of 32 threads that are scheduled and executed together in SIMT fashion on an SM.
Question 3: What does the __syncthreads() intrinsic do in CUDA?
- Synchronizes all threads across the entire GPU
- Flushes global memory writes
- Acts as a barrier for all threads within a block (Correct answer)
- Waits for host-device memory transfers to complete
Correct answer: Acts as a barrier for all threads within a block
__syncthreads() inserts a barrier so all threads in the same block must reach that point before any can proceed.
Question 4: Which kernel launch configuration parameter controls the number of threads per block?
- gridDim
- blockIdx
- blockDim (Correct answer)
- threadIdx
Correct answer: blockDim
blockDim specifies the dimensions (and thus total count) of threads within each block.
Question 5: When does warp divergence occur?
- When two warps access the same global memory address
- When threads within a warp follow different branches of an if-else (Correct answer)
- When shared memory bank conflicts arise
- When grid dimensions exceed SM limits
Correct answer: When threads within a warp follow different branches of an if-else
Warp divergence happens when threads in the same warp take different code paths, causing serial execution of each path.
Question 6: What is the maximum number of threads per block on modern NVIDIA GPUs?
- 256
- 512
- 1024 (Correct answer)
- 2048
Correct answer: 1024
Modern NVIDIA architectures support up to 1024 threads per block.
Question 7: Which CUDA API call is used to allocate memory on the device?
- cudaMallocHost()
- cudaMalloc() (Correct answer)
- cudaMemAlloc()
- cudaDeviceAlloc()
Correct answer: cudaMalloc()
cudaMalloc() allocates memory in GPU global memory and returns a device pointer.
Which CUDA memory type offers the lowest latency access for threads within the same block?