NCA CUDA Programming & Parallel Computing 5 — Questions and Answers
Question 1: Which CUDA profiling tool provides detailed kernel performance metrics such as memory throughput and warp efficiency?
- nvcc
- nvidia-smi
- Nsight Compute (Correct answer)
- cuBLAS
Correct answer: Nsight Compute
Nsight Compute is NVIDIA's kernel-level profiler that reports metrics like memory bandwidth utilization, warp efficiency, and occupancy.
Question 2: What is the difference between cudaMemcpy and cudaMemcpyAsync?
- cudaMemcpy works only for host-to-device; Async works for all directions
- cudaMemcpyAsync is non-blocking and can overlap with kernel execution in a stream (Correct answer)
- cudaMemcpy uses pinned memory; Async uses pageable memory
- They are identical in behavior
Correct answer: cudaMemcpyAsync is non-blocking and can overlap with kernel execution in a stream
cudaMemcpyAsync returns immediately and can be issued to a stream, enabling overlap with compute or other transfers.
Question 3: Which of the following correctly computes a global thread index for a 1D grid of 1D blocks in CUDA?
- threadIdx.x + blockIdx.x
- threadIdx.x * blockDim.x + blockIdx.x
- blockIdx.x * blockDim.x + threadIdx.x (Correct answer)
- gridDim.x * blockIdx.x + threadIdx.x
Correct answer: blockIdx.x * blockDim.x + threadIdx.x
The standard formula blockIdx.x * blockDim.x + threadIdx.x maps each thread to a unique global index across the entire grid.
Question 4: What happens when a CUDA kernel accesses global memory at an unaligned address?
- A hardware exception is thrown
- The access may require multiple memory transactions, reducing throughput (Correct answer)
- The data is silently corrupted
- The warp is terminated
Correct answer: The access may require multiple memory transactions, reducing throughput
Unaligned global memory access can break coalescing, requiring additional transactions and lowering effective memory bandwidth.
Question 5: What is the purpose of the CUDA occupancy calculator (cudaOccupancyMaxActiveBlocksPerMultiprocessor)?
- To compute the optimal grid size for a given problem
- To determine how many blocks can simultaneously run on an SM given resource usage (Correct answer)
- To measure live warp count during execution
- To predict memory bandwidth utilization
Correct answer: To determine how many blocks can simultaneously run on an SM given resource usage
This API computes the maximum number of active blocks per SM based on register and shared memory usage of the kernel.
Question 6: In CUDA, what is local memory used for?
- Fast storage shared by threads in a block
- Per-thread storage for register spills and large arrays that don't fit in registers (Correct answer)
- A cache for constant data
- Temporary storage managed by the CUDA runtime for kernel arguments
Correct answer: Per-thread storage for register spills and large arrays that don't fit in registers
Local memory is private to each thread and resides in global memory; it is used when a thread's register usage exceeds the hardware limit (register spilling).
Question 7: Which statement best describes the SIMT execution model used by CUDA GPUs?
- Each thread executes a different instruction on different data simultaneously
- All threads execute the same instruction on different data, but can independently branch (Correct answer)
- All threads must follow identical control flow with no divergence
- Threads execute independently with no relation to other threads in the warp
Correct answer: All threads execute the same instruction on different data, but can independently branch
SIMT (Single Instruction, Multiple Threads) allows threads to execute the same instruction on separate data while supporting per-thread branching, though divergence reduces efficiency.
Which CUDA profiling tool provides detailed kernel performance metrics such as memory throughput and warp efficiency?