What is CUDA?
NVIDIA's platform for general-purpose computing on its GPUs. Kernels are written in an extended C++, with parallelism expressed as a grid, blocks and threads.
Japanese name: CUDA
NVIDIA's platform for general-purpose computing on its GPUs. Kernels are written in an extended C++, with parallelism expressed as a grid, blocks and threads.
Japanese name: CUDA
In CUDA, the CPU (host) launches a kernel, a function that many GPU threads execute at once. One launch creates a grid of blocks, and each block contains many threads. Each thread computes a unique global index, typically i = blockIdx.x × blockDim.x + threadIdx.x, to choose its data element: thread 5 of block 2 with 256 threads per block handles element 517. Because threads are launched in whole blocks, the last block usually has surplus threads, so kernels guard memory accesses with if (i < n) to avoid writing past the array.
Each block is assigned to one streaming multiprocessor (SM) and runs there to completion, and an SM can hold several blocks at once. Inside, threads execute in warps of 32. Occupancy, the ratio of resident warps to the SM's maximum, is limited by registers per thread, shared memory per block and block size; low occupancy leaves too few warps to hide memory latency. Blocks run independently and in any order, so waiting inside a kernel for all other blocks can deadlock; global synchronization is normally obtained by splitting the work into two kernel launches.
Global memory is the GPU's DRAM: high bandwidth, high latency, and fastest when adjacent threads access adjacent addresses. Shared memory is a small on-chip memory per block, managed explicitly by the program. It is divided into 32 banks, and threads of a warp hitting different addresses in the same bank are serialized. __syncthreads() makes every thread of a block wait until all arrive; placing it inside a branch that some threads skip causes hangs or undefined results. Unified memory lets host and device share one pointer, with pages migrated on demand.
Host-to-device copies cross PCI Express and are often the bottleneck. Streams, ordered queues of transfers and kernels, let work in different streams overlap, so the next chunk of data can be copied while the current one is computed. Each kernel launch also carries a fixed overhead, so programs that launch thousands of tiny kernels benefit from fusing them, which also avoids writing intermediate results to memory, or from submitting recorded launch sequences at once with CUDA Graphs. CUDA itself runs only on NVIDIA GPUs; cross-vendor alternatives such as OpenCL follow a similar kernel-and-work-group model.
Answer: B. A function that many threads execute simultaneously on the GPU
In GPU programming a kernel is a function launched from the CPU-side program in which many GPU threads execute the same code. Each thread uses its own index to choose which data element to handle. For array addition, for example, the kernel is written so that each thread adds one element, and as many threads are launched as there are elements. The word is the same as for an OS kernel, but the meaning differs.
Answer: A. Grid → block → thread
One kernel launch forms a grid, which is divided into many blocks, each containing many threads. A block's threads run on the same SM (a cluster of execution units) and can cooperate through shared memory and synchronize. Different blocks run independently, so the number running at once adapts to the GPU's size, and the same program runs on small and large GPUs.
A block is a programmer-chosen group of threads that runs on one SM and can share memory and synchronize. A warp is the hardware's group of 32 threads within a block that execute instructions together in lockstep.
For a one-dimensional launch, use i = blockIdx.x * blockDim.x + threadIdx.x. Check i < n before accessing arrays, because the last block often contains more threads than remaining elements.
It is fast on-chip memory shared by the threads of one block, used to stage data from global memory for reuse and to exchange intermediate results. Unlike a cache, the program decides what goes into it, and __syncthreads() orders accesses.
CUDA appears in 18 practice questions across 1 topic, including GPU Programming.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.