APPENDIX
Run the examples on your desktop
Use real PyTorch or compile supported CUDA programs with GPGPU-Sim, with a clear check of what ran.
Choose what you want to run
The book still runs in your browser with no installation or GPU required. This appendix is an optional next step: download the source, run it on your desktop and compare the actual output.
| Example | Execution path | What it checks |
|---|---|---|
| PyTorch (.py) | Python + PyTorch; CPU or an NVIDIA GPU | Values and API use; CPU mode does not test GPU execution |
| Supported CUDA C++ (.cu) | GPGPU-Sim container on a CPU | Compilation and simulated output correctness |
| CUDA on real hardware | NVIDIA GPU, driver and CUDA Toolkit | Hardware execution; timing needs a separate measurement design |
A code excerpt needs its surrounding setup. The downloads below provide complete programs. The browser’s deliberately broken kernels remain diagnostic exercises; repair invalid accesses and races before downloading. Documentation-question snippets are excerpts for reading, with links to the complete examples.
Run a PyTorch example first
Install Python and use the official PyTorch installation selector (new tab) for your operating system. In a terminal, create a separate environment in a new working folder:
Terminal · shell commands
python -m venv .venv
# Linux, macOS or a WSL2 shell:
source .venv/bin/activate
# Windows PowerShell instead:
# .venv\Scripts\Activate.ps1Run the installation command supplied by the selector inside that environment. If your system names Python python3, use that name for the first command. CPU execution needs no NVIDIA hardware; CUDA execution needs a compatible NVIDIA GPU, driver and PyTorch build.
Download hello.py into this folder, then run:
Terminal · shell commands
python hello.py --device cpuExpect y: tensor([ 2., 4., 6., 8., 10.]); spacing may vary. CPU mode preserves values and layouts but performs no CPU–GPU transfers. To request the CUDA device used by the chapter:
Terminal · shell commands
python hello.py --device cudaThe download is generated from the displayed snippet. A small wrapper adds the device selector and prints a result when the snippet has no print call. Explicit CPU-only arithmetic, such as the precision accumulation explanation, remains on CPU. The Download Python button beside a complete snippet saves its current settings. GPGPU-Sim does not run these PyTorch files.
Try it
Run the CPU example, change the multiplier in the downloaded file to 3, and predict the new output before running again.
Set up GPGPU-Sim without a GPU
GPGPU-Sim supplies a simulated CUDA runtime. Our functional mode checks what the program computes; it does not measure a physical GPU’s speed. The desktop and CI commands use the same container definition.
Use an x86-64 machine with Docker, Git and a terminal. Linux is the tested CI platform. Windows users can use Docker Desktop with Linux containers and a WSL2 shell. Other desktop setups have not been validated. ARM machines would need amd64 emulation and are outside the tested configuration.
The first build downloads a large CUDA toolchain and compiles the simulator. Plan for tens of GB of free space, including temporary Docker layers; 20 GB may be insufficient. Check both host free space and Docker Desktop’s disk allocation. Allow time for the download and build; later runs reuse the image. No NVIDIA GPU, driver or host CUDA installation is needed for this path.
Terminal · shell commands
docker --version
docker info
git clone https://github.com/snowch/gpu-lab.git
cd gpu-lab
docker build -f docker/cuda-sim.Dockerfile -t gpu-lab-cuda-sim .Exact execution configuration
CUDA Toolkit 12.8; PTX target compute_70; shared CUDA runtime; configuration SM7_QV100; PTX_SIM_MODE_FUNC=1.
GPGPU-Sim commit: c3eeb6d19016960ab66789efdd8a3200cc30222a.
Toolchain image: ghcr.io/accel-sim/accel-sim-framework:ubuntu-24.04-cuda-12.8-minimal@sha256:1ae7da75d01d7b1317621c7a8f8b0f507a6e26182232f0ebfc38beb45ed3362d.
The image is digest-pinned. Updating either pin requires rerunning the checks. This supported setup does not promise compatibility with arbitrary CUDA versions, libraries or GPU features.
Compile, simulate and check one CUDA program
Download hello.cu into a separate folder. Open a terminal in that folder; $PWD below means its absolute path. Keep the filename hello.cu.
Terminal · shell commands
docker run --rm --network none \
--mount "type=bind,src=$PWD,dst=/input,readonly" \
gpu-lab-cuda-sim /input/hello.cu '[2,4,6,8,10]'The runner compiles the source, confirms that the program links to the simulator’s runtime, runs it, then checks every printed output against the supplied JSON array. Look for:
Terminal · expected output
Output: [2, 4, 6, 8, 10]
PASS: verified 5 output values against the CPU referenceA compiler error, runtime failure, missing output, non-finite value or mismatched result makes the command fail. Omitting the expected array runs without that external output comparison. If you edit the calculation, predict and update the expected array yourself; the runner does not derive an answer from the kernel it is testing.
The source folder is read-only inside the container. Compilation and simulator files use a temporary directory; --rm removes the container afterward. Execution needs no network once the image and source are available. To keep a log, append > hello-run.log 2>&1 to the command.
Check the check
Change the multiplier to 3. Predict all five outputs, then run with [3,6,9,12,15]. Deliberately supply the old expected array once and confirm that verification fails.
Find the complete program for a chapter
PyTorch downloads share their source with the displayed examples and are exercised on CPU in CI. The CUDA column lists the supported functional-simulation programs. Arbitrary edited programs and physical NVIDIA GPU execution are not covered by these checks.
To run another CUDA file, replace /input/hello.cu in the first command with its filename. Omit the JSON array for the self-checking gather, matrix/reduction and shared-memory programs; look for their Verified message. Gather uses stride 1, offset 0 and 32 values by default; the full suite below checks its other configurations.
| Chapter | PyTorch downloads | Supported CUDA program |
|---|---|---|
| 1. One operation, many numbers | hello.py | hello.cu Five-input kernel; eight launched threads |
| 2. Where do the numbers live? | devices.pyOther complete examples (3)CPU mode checks values; only CUDA mode performs CPU–GPU transfers. | PyTorch path; no matching CUDA program supplied. |
| 3. Selecting values | reading.pyOther complete examples (2) | PyTorch path; no matching CUDA program supplied. |
| 4. Tensor storage | layout.pyOther complete examples (2) | PyTorch path; no matching CUDA program supplied. |
| 5. Memory requests | requests.pyOther complete examples (3)PyTorch checks values and layouts; this does not validate the browser’s sector counts. | PyTorch path; no matching CUDA program supplied. |
| 6. Work during waits | scheduling.py The PyTorch calculation does not reproduce the teaching scheduler’s cycles. | PyTorch path; no matching CUDA program supplied. |
| 7. Different calculations | divergence.pyOther complete examples (3) | PyTorch path; no matching CUDA program supplied. |
| 8. Cooperation | reduction.pyOther complete examples (2) | ai-kernels.cu Self-checking eight-input reduction |
| 9. Matrix reuse | matmul.pyOther complete examples (2) | ai-kernels.cu Self-checking naive and tiled matrix products |
| 10. Precision | tensor-cores.pyOther complete examples (2)Precision arithmetic is checked on CPU. Tensor-core/WMMA execution is outside this simulator-supported set. | PyTorch path; no matching CUDA program supplied. |
| 11. Attention | attention.pyOther complete examples (2)This is the small PyTorch reference. No production FlashAttention CUDA kernel is supplied. | PyTorch path; no matching CUDA program supplied. |
| 12. Inference | inference.py This runs the small cache operation. The synthetic inference budget is not a runnable language model or benchmark. | PyTorch path; no matching CUDA program supplied. |
| Optional memory-access lab | memory.py | gather.cu Self-checking gather; configurable stride, offset and count |
- shared-memory.cu supplies the complete kernel, launch and host setup for the optional banks lab.
- kernel-scale.cu and kernel-vector-add.cu are safe solutions to the repair workshop. CI also generates safe multiplication, addition and vector-addition variants at four block sizes. Intentionally wrong-but-safe arithmetic is checked against its actual expression, not marked as a correct repair.
- book-opening.py and tensor-layout.py provide additional self-checking value, view and copy exercises.
Tensor-core/WMMA execution, a production attention kernel and a complete inference model are outside the simulator-supported set. The corresponding chapters have runnable PyTorch examples, with their implementation and performance boundaries stated locally.
Run the same CUDA checks as CI
From the repository folder, install Node.js 22 to generate the browser’s CUDA downloads. Then run the suite using the image already built:
Terminal · shell commands
node scripts/generate-cuda-cases.mjs
docker run --rm --network none --entrypoint bash \
--mount "type=bind,src=$PWD,dst=/course" \
gpu-lab-cuda-sim /course/scripts/cuda-sim.shThis suite writes logs and provenance under test-results/cuda-sim/. It checks four chapter-1 multipliers, twelve safe workshop variants, five gather configurations, naive/tiled matrix products, a block sum and the padded shared-memory read. The CUDA workflow also checks the documented desktop entry point. Its public workflow results and artifacts (new tab) record the exact revision checked.
To regenerate the downloadable PyTorch files from a checkout:
Terminal · shell commands
node scripts/export-desktop.mjs
python test-results/desktop-examples/hello.py --device cpuIn a Python environment with PyTorch installed, python tests/chapter_examples.py checks the displayed source templates and their download wrappers against references. These checks do not benchmark a GPU.
Optional: use a real NVIDIA GPU
Install a compatible NVIDIA driver, CUDA Toolkit and host C++ compiler. From a GPU Lab checkout, the same runner can check the downloaded five-input program on hardware:
Terminal · shell commands
bash scripts/run-cuda.sh native /absolute/path/to/hello.cu '[2,4,6,8,10]'Or compile directly with nvcc -std=c++17 hello.cu -o hello, then run ./hello. That direct command does not perform the runner’s external JSON comparison. The supplied examples have simulator/CPU checks; hardware execution remains unvalidated here. Warm-up, synchronisation, repetition and a stated timing scope are needed before making a performance comparison.
Troubleshooting
- Docker cannot connect
- Start Docker and confirm
docker infosucceeds. Use Linux containers; check your account’s Docker access. - No space left during build
- Check host space and Docker’s disk allocation. Temporary unpacked layers can be much larger than the download. Remove only images/cache you recognise and no longer need, or increase the allocation.
- The source file cannot be found
- Run from the folder containing the file. The container sees the mounted folder as
/input; use/input/hello.cuinside it. Keep the quoted mount argument when paths contain spaces. - Compilation or runtime-link check fails
- Start with the unedited supplied example and pinned image. The simulator needs the shared CUDA runtime and supported PTX target; a normal host CUDA installation alone does not select GPGPU-Sim. Keep the complete log.
- Output verification fails or the run times out
- Compare all values, the number of outputs and the selected multiplier. Small examples have a 180-second run limit. A changed kernel may be wrong or use unsupported behaviour; increasing the timeout does not establish correctness.
- PyTorch reports no CUDA device
- Use
--device cpufor value/layout practice, or check the NVIDIA driver and installed PyTorch CUDA build. Building the GPGPU-Sim container does not give ordinary PyTorch a CUDA device.
References
Use these official references to check the concepts and code on this page.
- Docker installation (new tab)
Install Docker with Linux-container support for the CUDA simulator path.
- GPGPU-Sim README (new tab)
Read supported toolchains and the distinction between functional and performance simulation.
- PyTorch installation selector (new tab)
Choose an installation for your operating system and CPU or CUDA execution.
These browser exercises do not run an installed PyTorch or CUDA toolkit. For optional local execution, choose documentation matching your installed tools. Links open online in a new tab; the questions and answer comparisons below work offline.
Use the documentation
Use the references to explain each answer, then apply it to this page’s example. No installation is needed.