Real CUDA C programs plus one browser demo. The .cu files need an
actual NVIDIA GPU and the CUDA toolkit — they can't run in a browser or on a Mac. Open them
to view the code, then run them on Google Colab with a free GPU
(see "How to run" below). This is the last session of Unit IV.
Click a thread to watch i = blockIdx.x*blockDim.x + threadIdx.x map onto the data
array — and see the extra "off the end" threads that the if (i < n) bounds
check skips. Runs in-browser — show it live.
The "Hello World" of CUDA: y = a*x + y, one thread per element. The full five-step
pattern — cudaMalloc, cudaMemcpy H2D, kernel launch, cudaMemcpy D2H, cudaFree — with the
launch config and bounds check.
Sum a million numbers on the GPU with a tree reduction in shared memory: each
block halves its active threads every step with __syncthreads(), then partials are
combined. The canonical cooperative GPU pattern.
Image processing as pure data parallelism: one thread per pixel on a synthetic 512×512 image, RGB → grayscale, using a 2D grid of 2D blocks.
The .cu files need an NVIDIA GPU + CUDA
toolkit. Easiest for everyone: Google
Colab — set Runtime → Change runtime type → GPU, then run
!nvcc 01-vector-add.cu -o out && ./out in a cell.
Own an NVIDIA GPU? Locally: nvcc 01-vector-add.cu -o vadd
&& ./vadd. macOS has no CUDA at all — use Colab. Full walkthrough in
README.md.
This closes Unit IV (Programming Models & Tools): OpenMP (S10) → MPI (S11) → CUDA (S12). Unit V turns to where all this power gets used.