Build a GPU-Accelerated Graphics Test Pipeline in Docker
System DesignModel answerLast updated
Design a containerized CI pipeline that runs automated Vulkan/OpenGL render-and-compare tests on a mixed NVIDIA/AMD GPU fleet with reproducibility, security, and fast feedback.
The Problem
Your team maintains a cross-platform graphics engine. Hundreds of automated tests render frames with Vulkan and OpenGL, compare the output pixel-by-pixel against golden images, and run a handful of performance smoke checks. Right now everything runs on bare-metal machines with ad-hoc shell scripts. Tests fail for environmental reasons more than correctness reasons, results are hard to reproduce, and the fleet is a mix of NVIDIA and AMD cards with different driver generations.
You have been asked to redesign the test infrastructure around Docker containers.
What to cover
A strong answer addresses each of the following areas:
Requirements and scale — State your assumptions explicitly. How many runners, how many tests, what throughput do you need, and what does "done" look like in terms of runtime targets?
Architecture — Describe the end-to-end flow from a git push to a stored test result. Which stages run on GPU runners versus ordinary CPU runners?
Base images and GPU runtime integration — What base images do you choose for NVIDIA versus AMD? How does the container access the GPU without bundling a kernel driver? What capability or device flags matter for graphics (not just compute)?
Image layering and caching — How do you order layers to maximize cache reuse? How do you handle large binary assets like golden images?
Reproducibility — What does it mean for a result to be reproducible? What do you pin, and what metadata do you record alongside each result?
Security — How do you run containers with least privilege while still reaching GPU hardware? How do secrets flow into build and test jobs? What changes when a pull request comes from a fork?
Debugging — What artifacts does a failed test produce? How can an engineer reproduce a failure locally from a single command?
Flaky tests — What are the common causes of non-deterministic results in GPU rendering tests, and how do you detect, quarantine, and fix them?
CI runtime — What concrete strategies reduce end-to-end wall time? What metrics would you track to know whether an optimization actually helped?
What the interviewer is looking for
- You understand that the kernel driver lives on the host and cannot go in the image, and you know the mechanism by which user-space libraries are injected.
- You distinguish graphics workloads (Vulkan, OpenGL, EGL) from compute-only workloads (CUDA), and know where that distinction shows up in container configuration.
- Your security model does not rely on
--privileged. - Your reproducibility story is concrete: specific things you pin, a specific result key, not just "we use Docker so it's reproducible."
- Your flakiness strategy is more than "retry three times."
Hints
Hint 1
The single most common 'CUDA works but Vulkan is black' bug comes down to one missing environment variable that controls which GPU capabilities and ICD files the container runtime injects — think about what capabilities a graphics workload needs beyond the default compute/utility set.
Hint 2
GPU runners are your scarcest resource. Think about where in the pipeline you can shift work to cheaper CPU runners, and what that implies about how you split your Docker stages.
Hint 3
'Reproducible' needs an operational definition, not a vibe. Try defining a result as a tuple of specific versioned inputs, and ask yourself which of those inputs you are currently not recording.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
How to approach this answer
This question tests three things at once: understanding of the container-to-GPU boundary, practical CI architecture, and the specific failure modes of graphics workloads. The trap is treating it as a generic "containerize our build" problem. Frame your answer around what makes GPU graphics testing genuinely different.
1. State assumptions with numbers
Do not let the interviewer fill in the scale for you.
- Fleet: ~150 bare-metal runners. Roughly 100 NVIDIA (mixed Turing/Ampere/Ada) and 50 AMD (RDNA2/3), each with 1–4 GPUs.
- Test suite: ~5,000 tests combining Vulkan and OpenGL render-and-compare checks, plus perf smoke tests.
- Load: ~40 PRs per hour at peak; a nightly full-matrix run covers all GPU models and driver versions.
- Targets: PR gate finishes p95 under 20 minutes. Nightly run finishes under 3 hours.
- Non-functional: results are reproducible given the same inputs, secrets never reach fork PRs, and failures are debuggable without SSH access to the runner.
2. End-to-end architecture
git push
└─ CI orchestrator (GitHub Actions / GitLab / Buildkite)
├─ Build stage [CPU pool]
│ BuildKit → image signed + pushed to registry (pinned by digest)
└─ Test stage [GPU pools, labeled by vendor/arch/driver]
runner agent → containerd + NVIDIA Container Toolkit or ROCm device plugin
→ one test container per GPU
→ results + artifacts → object store
└─ Results service
JUnit aggregation, pixel-diff storage, flakiness DB, timing DB → dashboards
Key structural decisions:
- Build on CPU, test on GPU. Compilation never touches a GPU runner. Those machines are the bottleneck and should do nothing but run tests.
- Label runners with vendor, architecture, and driver channel — e.g.
nvidia-ada-r550. The job scheduler targets these labels, giving you explicit control over the test matrix.
3. Base images and GPU runtime
The foundational rule: the kernel driver stays on the host. User-space libraries are injected at container startup by the runtime. If you put driver files in the image, they will almost certainly mismatch the host kernel module.
NVIDIA
- Base image:
nvidia/cuda:12.x-base-ubuntu22.04, pinned by digest. Or plainubuntu:22.04withlibglvndif you want to minimize the CUDA footprint. - Install the NVIDIA Container Toolkit on each host. Run with
--gpus device=Nor use CDI specs (--device nvidia.com/gpu=0). - Set
NVIDIA_DRIVER_CAPABILITIES=graphics,compute,utility,display. The default is compute and utility only. Withoutgraphics, Vulkan ICDs and OpenGL libraries are not injected — this is the single most common cause of "works for CUDA, silent black screen for Vulkan" failures. - Use EGL surfaceless (
EGL_PLATFORM=surfaceless) or Vulkan headless/offscreen for rendering. Avoid Xvfb: it silently falls back to software rendering. Assert the renderer string at the start of every test so a misconfiguration fails loudly.
AMD
- Base image:
rocm/dev-ubuntu-22.04for compute, or Ubuntu with Mesa RADV pinned to a specific package version. - Pass
--device=/dev/dri --device=/dev/kfdand add thevideoandrendergroups with--group-add. - Mesa is user-space, so it can live in the image. This makes AMD runs more reproducible than NVIDIA, but you must pin it explicitly.
Host management
- Provision hosts via Ansible or an immutable image builder with pinned driver versions.
- Roll out driver upgrades with a canary label: run the nightly suite on the new driver before promoting it to the main pool.
- Every test run records
nvidia-smiorrocm-smioutput, the driver version, andvulkaninfo --summaryas run metadata.
4. Image layering and caching
Order layers from slowest-changing to fastest-changing:
- OS base (digest-pinned) with apt packages pinned to versions and a snapshot mirror date.
- Toolchain: compilers, CMake, Vulkan SDK.
- Third-party dependencies from a lockfile (vcpkg, conan, pip with hashes).
- Test binaries, copied from a multi-stage builder stage.
- Test assets. Large binary assets live in object storage versioned by content hash; mount them read-only at runtime rather than baking GBs into every image.
Caching strategies:
- Use BuildKit
--mount=type=cachefor apt, ccache, and sccache. - Use
--cache-to/--cache-from type=registryso ephemeral CI builders share a warm cache. - Rebuild base layers on a weekly schedule for security patches, not on every commit.
5. Reproducibility
"We use Docker so it's reproducible" is not an answer. Define a result as a tuple: (image digest, test commit SHA, GPU model, driver version, Mesa version). A result is only comparable to another result if the tuples match. Store this tuple with every test record.
Additional measures:
- Fixed seeds, fixed resolution, disabled vsync, and pinned shader cache state for all rendering.
- Set
SOURCE_DATE_EPOCHfor deterministic build artifacts. - Pin apt to a snapshot mirror date to prevent silent package drift.
- Generate an SBOM (e.g., with Syft) and sign images with cosign. Runners verify signatures before pulling.
6. Security
Privilege: no --privileged. Pass only the specific device nodes the test needs. Run as a non-root UID, use --cap-drop=ALL --security-opt no-new-privileges, and mount the root filesystem read-only with a tmpfs for scratch.
Secrets at build time: use BuildKit --mount=type=secret. Never use ARG or ENV — both persist in image layers and appear in docker history.
Secrets at runtime: short-lived OIDC-federated tokens from Vault or a cloud IAM, scoped to writing artifacts to a single bucket prefix.
Fork PRs: run on an isolated pool with no secrets injected. Runners are ephemeral and reimaged after every untrusted job. GPU memory and device state can leak across containers, so reset the device between jobs.
7. Debugging
On any failure, preserve and upload:
- The rendered frame, the golden image, and a pixel-diff heatmap.
- stdout/stderr,
dmesgGPU error lines (Xid events for NVIDIA, ring timeouts for AMD), and Vulkan validation layer output. - Core dumps, enabled via
ulimitwith a mounted output directory.
Maintain a debug image variant in the same digest lineage that adds gdb, RenderDoc CLI, Nsight or Radeon GPU Profiler, and debug symbols. A CI flag re-runs a single failing test in this variant with API capture enabled.
Every failure emits a one-line docker run command with the exact digest, test filter, and device flags so any engineer can reproduce it locally without knowing how CI is configured.
8. Flaky tests
Common causes in graphics pipelines:
- Driver-level non-determinism: floating-point precision differences, MSAA resolve order, shader compiler variance across driver versions.
- Resource contention: thermal throttling, memory pressure, PCIe bandwidth variability.
- GPU hangs: timeouts that recover differently depending on driver state.
- Test bugs: missing synchronization barriers, uninitialized memory reads.
Strategies:
- Replace exact pixel comparison with per-test tolerance thresholds (RMSE or a maximum per-channel delta). Track threshold tightness as a metric — loosen it only with justification.
- Record a flakiness rate per test over a rolling window. Automatically quarantine tests whose rate exceeds a threshold and file a tracking ticket.
- For perf tests, collect 5–10 samples per run and report the median rather than a single measurement. Alert on regression from the trailing 14-day median.
- Pin GPU clocks during perf tests (
nvidia-smi -lgc) to reduce thermal variance.
9. Reducing CI runtime
Target the bottleneck first. GPU runners are finite; parallelism is limited by fleet size, not by adding more CPU.
- Test selection: run only tests that could be affected by the changed files on PR gates. Use a coverage map keyed on source files.
- Sharding: distribute the test list across all available GPUs in parallel rather than running serially on one.
- Result caching: if the image digest and test inputs have not changed since the last run, skip re-execution and reuse the stored result.
- Fast feedback ordering: run historically fastest tests first so failures surface early.
Metrics to track: p50/p95 wall time per stage, GPU runner queue depth and wait time, cache hit rate per image layer, and test flakiness rate. Without these numbers, any claim about an optimization is anecdotal.