Copyright © 2026 Christopher Snow.
GPU Lab is an interactive CUDA C++ course for AI practitioners who want to understand how GPUs execute their programs. Edit, compile and run complete CUDA examples in your browser using GPU simulation. No installation or GPU is required.
Start with one thread writing one value, then follow memory access, warp execution, synchronisation and the parallel patterns behind AI workloads. The examples assume basic programming and array indexing; each lesson introduces the CUDA concepts it uses. Browser models and simulated execution do not measure physical GPU performance.
- Write your first GPU value: Launch one thread, write one value, and read it back in main().
- One thread, one element: Change a CUDA multiplier and follow each input to its output.
- More threads than elements: Change the block size and see which threads stop at the bounds check.
- From CPU array to GPU result: Change the input length and follow allocation, copies and the kernel launch.
- Same load, different addresses: Change a warp’s input stride and predict which 32-byte sectors its reads touch.
- What runs while a warp waits?: Follow a load dependency and compare what happens with one ready warp or two.
- When lanes take different branches: Change the signs in a warp’s inputs and track which lanes execute each branch.
- Add values across a block: Trace a block reduction and identify the barrier that makes each partial sum safe to read.
- When shared-memory addresses collide: Change the stride of a shared-memory read and group the simultaneous requests by bank.
- Reuse inputs in a matrix tile: Compare a direct CUDA matrix product with a tiled kernel and trace which loads the tile reuses.
- What changes when inputs use fewer bits?: Change the input format and compare rounded operands, storage and the resulting sum.
- How a warp cooperates on a matrix tile: Follow a CUDA warp-level matrix operation and distinguish its input fragments from its accumulator.
- Keep less intermediate data in attention: Compare full score storage with a tiled calculation that carries an online softmax state.
- Follow the key-value cache during inference: Change sequence length and account for the key-value data read and appended during decoding.
- Investigate a matrix multiplication: Choose a tile width, predict its resource trade-off and decide what to measure on a GPU.
- Count token destinations safely: Trace competing updates and compare global atomics with per-block partial counts.
- Build positions from prefix sums: Step through shared-memory scan stages and convert inclusive totals to exclusive offsets.
- Pack surviving tokens in order: Use selection flags and exclusive offsets to explain each surviving token’s write destination.
- Find a parallel program’s progress dependency: Find which threads reach a block barrier and explain why the rest must also arrive.
- Overlap copies with computation: Order copies, kernels and buffer reuse with explicit dependencies.
- Investigate stable token routing: Combine counts, starts and ranks to place every token once, then design a performance measurement.
- Check every GPU result: Compare every output with a CPU reference, then diagnose a safe indexing error.
- Process more inputs than the launch has threads: Give each input one owner with a grid-stride loop, including tails and empty inputs.
- Carry a prefix across blocks: Combine local scans, block totals and block starts in an ordered GPU pipeline.
- Explain an SM resource trade-off: Calculate a residency limit and identify which hardware observation could test an optimisation.
- Measure a GPU kernel fairly: Separate correctness, kernel timing and profiling, then interpret recorded evidence.
- Build and verify a stable softmax: Implement an independent row-wise kernel, verify unseen shapes and explain its bottleneck.
Original book and lab URLs remain available for existing bookmarks. See the model contract for the scope of the teaching models.
The desktop appendix provides complete Python downloads for every chapter, CPU/CUDA setup, and a pinned GPGPU-Sim container for supported CUDA examples without a physical GPU. Complete PyTorch panels also have a Download Python button that preserves the current settings. PyTorch runs separately from GPGPU-Sim. CPU and functional simulator checks do not validate real GPU performance. See setup and coverage.
Choose Install in the course header to add GPU Lab to your apps with its own GPU-chip icon and standalone window. Chrome and Edge offer a native install prompt when available; the dialog also explains Safari’s Add to Dock / Add to Home Screen options. Installed apps use the same offline course. Installation and shortcut placement are controlled by your browser.
Open App status → Offline access and choose Download for offline use. The panel shows the exact file bytes before saving every lesson, simulator, diagram and CUDA/PyTorch example, including lessons you have not visited. Wait for Available offline before disconnecting. External links need internet access; running downloaded examples requires their usual local tools. Installing the app and checking for updates do not automatically download the offline course.
App status compares the running build with the deployed release. Choose Update to prepare it, then Restart to update when ready. All open GPU Lab windows save their experiment state before restarting together; a busy or non-responsive window blocks the restart. Later keeps the pending badge visible. Closing all windows or refreshing does not apply a prepared update automatically.
Cancelled downloads can resume from verified files. Failed replacements leave the previous complete copy usable. App status detects missing/evicted files and offers repair. Remove offline copy asks for confirmation and preserves learner work, preferences and other apps. HTTPS (or localhost) and browser storage are required. See the release contract, migration notes and validation.
Node.js 22 or newer. The application and model tests have no package dependencies.
npm run dev # http://localhost:5173/gpu-lab/
npm run check # model tests and static buildnpm run dev builds once before serving. Re-run npm run build after changing lesson content.
Browser checks run against the built site at /gpu-lab/, at desktop and phone sizes, in both themes:
python -m pip install -r tests/requirements.txt
python -m playwright install chromium
python tests/browser.py
python tests/offline.pyCI runs the model/build and both browser suites before deploying dist/ from main through GitHub Pages Actions.
Pull requests run checks without deployment. All application assets use relative paths.
The build emits release.json, immutable releases/<build-id>/ assets and a stable
sw.js lifecycle engine. Clean Git builds retain their source commit/date in the
footer; archives and dirty development builds identify themselves without a fake
revision. App status uses network-only deployed metadata, never GitHub main.
The worker prepares files only on request and verifies size and SHA-256 before
selection. During development, use App status to update, or unregister the worker
in browser developer tools while iterating. The browser suites exercise both root
and /gpu-lab/ hosting, complete offline access and multiple real built releases.
A separate workflow compiles and runs small CUDA examples in GPGPU-Sim on a CPU runner. It validates outputs against a CPU reference and saves logs; it does not yet compare timing or memory counters. See validation layers.
The browser needs no GPU. examples/gather.cu is an optional standalone CUDA program with input bounds, runtime error checks and CPU-result comparison:
nvcc -O2 examples/gather.cu -o /tmp/gpu-lab-gather
/tmp/gpu-lab-gather 8 0 32It requires the CUDA toolkit and an NVIDIA GPU. It is a correctness exercise, not a benchmark. The initial implementation has not been validated on GPU hardware.
examples/ai-kernels.cu adds self-checking naive matmul, tiled matmul and block reduction.
The GPGPU-Sim workflow compiles and checks those kernels as well as gather. The WMMA sketch
and online-attention pseudocode in the lessons are illustrations rather than executable examples.
src/model.mjs: pure address model; all figure values derive from its result.src/architecture.mjs: scheduling, divergent paths and shared-memory bank models.src/ai-models.mjs: reductions, tiled matmul, numeric conversion, attention and inference budgets.content/v2-course.mjs,content/v2-view.mjs: current course catalogue and page renderer.content/v2-cuda-source-workbench.html: editable CUDA programs and compiler integration.src/v2-model.mjs,src/v2-traces.mjs: teaching models and execution traces.src/theme.mjs: theme persistence.index.html,content/lessons.mjs: original book pages retained for existing URLs.content/memory.html,src/app.mjs,src/style.css: Lab 01 and its interactive views.tests/: model invariants, boundary cases, browser interactions and responsive layout.examples/: optional runnable CUDA exercises.docs/: curriculum, model scope, sources and development rules.
Inspired by the model-driven learning approach in Digital Design
and Assembly Lab. This small standalone prototype does
not yet integrate snowch/learning-platform; migration is a separate curriculum/platform decision.