The first CUDA program everyone writes, C[i] = A[i] + B[i], made visible. A vector of N elements is handed to a grid of thread blocks; every thread computes one element, and the only thing it needs to know is its own index i = blockIdx.x × blockDim.x + threadIdx.x. Move the sliders and watch the grid regroup, hover a thread to see the formula filled in with real numbers, switch the if (i < N) guard off to see what an out-of-bounds write looks like. Then run the kernel step by step: cudaMalloc, cudaMemcpy, the launch, waves of blocks on streaming multiprocessors, warps of 32 threads in lockstep, the copy back, and the CPU loop racing the GPU tick by tick. The code panel always shows the real CUDA C with your values. The third tab goes one step further, to the kernel every CUDA course ends with: a tiled matrix multiply that stages tiles of A and B in shared memory with the load, synchronize, compute pattern, next to the naive kernel, with the global-memory loads counted for both.
grid → block → threadLive index formulaBounds guard on / offKernel launch step by stepCPU vs GPU ticksWarps and occupancyTiled matmul · shared memoryCUDA C · NumbaQuiz
Elements of A, B and C. One thread per element.
Hardware limit 1024. Multiples of 32 fill whole warps; try 100 to see idle lanes.
The grid
thread of a block (one colour per block, one row per warp of 32)i ≥ N, skipped by the guardi ≥ N without the guard: out-of-bounds writeidle lane of a partial warpselected (click, or arrow keys)
Index formula hover or click a thread
] ?
Warps and occupancy
Code with your values
CPU loop vs GPU grid, same N
GPU kernel ticks–
CPU loop ticks–
fewer ticks–
GPU · C[] written by 0 threads so fartick 0
CPU · for (i = 0; i < N; i++) C[i] = A[i] + B[i];element 0 of N
Code, current line
C = A × B, one thread per output element. Small integers, so every dot product can be checked by hand.
Why tiles: global memory traffic
Naive · global loads for this block
Tiled · global loads for this block
Measured on real hardware: effective bandwidth, NVIDIA Tesla V100
simpleMultiply, no optimization: the naive kernel of this tab
119.9 GB/s
coalescedMultiply, a tile of A in shared memory, B still read from global memory
144.4 GB/s
sharedABMultiply, tiles of A and B in shared memory: the tiled kernel of this tab
195.5 GB/s
Table 2 of the NVIDIA CUDA C++ Best Practices Guide, "Shared Memory in Matrix Multiplication (C = AB)", measured with 32 × 32 tiles and float operands. The guide's own words: the gain comes from avoiding redundant transfers from global memory, not from better coalescing. The middle row is the half step the tab skips: staging only A already helps, staging both A and B is the kernel the animation plays. Bars scaled to the tiled kernel.
Kernel, current line
Go further
NVIDIA CUDA C++ Programming Guide ↗: the programming model (kernels, thread hierarchy, memory hierarchy) and the execution model (SMs, warps, SIMT) in the vendor's own words.
NVIDIA Training ↗: the Deep Learning Institute courses "Fundamentals of Accelerated Computing with CUDA C/C++" and "... with CUDA Python".
The idea behind the three tabs. GPU performance is two things at once: spreading the work over many threads, and organizing how those threads reach their data. Vector addition shows the first: one thread per element, threads in blocks, blocks in a grid. Matrix multiplication shows the second: one thread per output still parallelizes, but neighbouring threads keep reloading the same inputs from global memory. Tiling lets the threads of a block cooperate, staging small pieces of A and B in shared memory and reusing them, in the rhythm load, synchronize, compute, synchronize. The barriers make sure the data is complete before it is read and not overwritten before everyone is done.
Numba CUDA ↗ and CuPy ↗ if you would rather write the same kernel in Python.
Terms follow the NVIDIA CUDA C++ Programming Guide (grid, block, thread, warp, streaming multiprocessor, cudaMalloc, cudaMemcpy, the <<<gridDim, blockDim>>> execution configuration). The kitchen picture in the captions (global memory = the pantry everybody walks to, shared memory = the workbench of one station, registers = the chef's hands) follows Zachary Huang's CUDA video. Inspired by the CUDA Visualizer and the CUDA Thread Visualizer (both MIT) and the tiled GEMM simulator by Joel Fernandes; nothing was copied, every scene here is drawn by this page. The tick race is a teaching model (one warp instruction per scheduler per tick, no memory latency, no copy time), not a benchmark. GPU profiles list public SM counts and the per-SM limits of their compute capability.Keys: Space play/pause · . next · , back · R replay · arrows move the selected thread in the grid