Skip to content

core: add Container.withGPU, deprecate experimental GPU fields - #14320

Merged
tiborvass merged 3 commits into
dagger:mainfrom
grouville:grouville/gpu-api-cleanup
Sep 24, 2026
Merged

tiborvass merged 3 commits into
dagger:mainfrom
grouville:grouville/gpu-api-cleanup

Conversation

@grouville

Copy link
Copy Markdown
Member

Refs #13668. This is the last item on that list, after nesting landed in #14082.

What's wrong

Container has two GPU fields, both still named experimental:

  • experimentalWithAllGPUs gives the container every GPU on the host.
  • experimentalWithGPU(devices: [String!]!) gives it a chosen list.

The issue asked two questions: did the experiment succeed, and do we need both? I went through the code and the history to answer them.

Did the experiment succeed?

Partly. Nothing has changed at runtime since the setup moved into the executor in 2024. All the engine does is add NVIDIA's nvidia-container-runtime-hook as an OCI prestart hook and set NVIDIA_VISIBLE_DEVICES on the process. But:

  • It works with NVIDIA only.
  • No CI job ever runs the GPU tests. They skip unless DAGGER_GPU_TESTS_ENABLED is set, and 🐞 Experimental support for NVIDIA is broken #9015 was the bit-rot that caused.
  • The docs section was dropped in the 1.0 docs cleanup.
  • Outside this repo, the only hand-written use I could find calls ExperimentalWithAllGPUs().

Do we need both?

No. experimentalWithGPU(devices) passes its strings straight into NVIDIA_VISIBLE_DEVICES, so the IDs are NVIDIA UUIDs or indexes that don't carry over between machines. That is the portability concern @marcosnils raised. Following @shykes' suggestion, this PR ships withGPU with no arguments and leaves device selection for later.

What this does

  • New field. Container.withGPU takes no arguments and exposes all host GPUs. It appears from API view v1.0.0-beta.15.
  • Old fields kept. experimentalWithGPU and experimentalWithAllGPUs still work in every view. From beta.15 on they are marked @deprecated, and older views see them exactly as before.
  • Saved containers. withGPU is registered as a persisted container recipe, so a saved withGPU container decodes after an engine restart.
  • Out of scope. The engine switch _EXPERIMENTAL_DAGGER_GPU_SUPPORT and the -gpu image tag are unchanged. That belongs with the runner-host env cleanup.

Why not remove the experimental fields from the new view?

Views drop the prerelease suffix, so every released v1.0.0-beta.N module resolves to the v1.0.0 view. Removing the fields there would break those modules. #14082 hit exactly this with experimentalPrivilegedNesting and had to put the argument back as deprecated (33c00b2). This PR follows the same pattern from the start.

Behavior change to flag

There is no runtime change. Go SDK users calling ExperimentalWithAllGPUs() or ExperimentalWithGPU() will now get staticcheck SA1019 warnings. There is no non-deprecated replacement for choosing specific devices yet. I'd rather flag that than hide it. If anyone relies on device selection, this PR is the place to say so.

Tests without a GPU

Real GPU passthrough still needs an NVIDIA machine, and there is no emulator that can run CUDA work. But everything the engine itself controls can be tested on the ordinary CI engine:

  • Gate. An engine without GPU support refuses a withGPU exec with GPU support is not enabled.
  • Device list. A nested engine with GPU support enabled and a stub script in place of nvidia-container-runtime-hook runs echo $NVIDIA_VISIBLE_DEVICES. It gets all for withGPU and for experimentalWithAllGPUs, and GPU-aaaa,GPU-bbbb for experimentalWithGPU(devices: [...]).
  • Hook injection. The same nested engine without the stub fails the exec on the missing hook. This proves the engine injects the hook, not just the env var.

Schema unit tests check that withGPU and the deprecation markers appear only from beta.15, and that every spelling produces the same container state. The base-schema golden file is unchanged.

Commits

  1. Schema, persistence, unit tests and changelog. This is the one to review closely.
  2. Regenerated SDKs and GraphQL schema, with no hand edits.
  3. Integration tests. This commit comes after the regeneration because the tests call the new Go SDK method.

Each commit builds and passes the schema tests on its own.

Try it yourself

dagger api call engine-dev test --pkg ./core/integration --run='TestGPU'
go test ./core/schema -run 'TestBaseSchemaAllowlist|TestGPU'

@grouville
grouville force-pushed the grouville/gpu-api-cleanup branch 2 times, most recently from 0df87ab to 4fe9a6c Compare September 24, 2026 01:11
@grouville
grouville marked this pull request as ready for review September 24, 2026 17:04
@grouville
grouville requested review from a team as code owners September 24, 2026 17:04
@grouville
grouville force-pushed the grouville/gpu-api-cleanup branch 3 times, most recently from 0299e5c to 06c00ad Compare September 24, 2026 19:20
The experimental GPU API shipped in 2023 and has not changed behavior
since. Only the "all GPUs" form is used in practice. The device list
form passes vendor-specific IDs straight into NVIDIA_VISIBLE_DEVICES,
so it is not portable across hosts or vendors.

Add Container.withGPU with no arguments, exposing all host GPUs, from
API view v1.0.0-beta.15. Keep experimentalWithGPU and
experimentalWithAllGPUs working in every view and mark them deprecated
from beta.15 on. Views drop the prerelease suffix, so removing them
would break released v1.0.0-beta modules. Per-device selection is
deferred until a portable design is settled.

Register withGPU as a persisted container recipe so saved containers
decode.

Refs dagger#13668

Signed-off-by: Guillaume de Rouville <[email protected]>
Generated with dagger generate (docs:references and the six client
generators). No hand edits.

Signed-off-by: Guillaume de Rouville <[email protected]>
Switch the hardware-gated tests to withGPU, keeping one call to each
deprecated field.

Add tests that need no GPU and run on the ordinary CI engine:
- an engine without GPU support refuses a GPU exec;
- with a stubbed NVIDIA hook in a nested engine, every spelling of the
  API reaches NVIDIA_VISIBLE_DEVICES;
- without the stub, the missing hook fails the exec, proving the engine
  injects it.

Signed-off-by: Guillaume de Rouville <[email protected]>
@tiborvass
tiborvass merged commit e8b1bed into dagger:main Sep 24, 2026
86 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants