Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Commit 6dfffc5

Browse files
committed
Only specify nvidia runtime if one exists
Docker may support CUDA GPUs without explicit nvidia runtime. Signed-off-by: Emily Casey <[email protected]>
1 parent cb46972 commit 6dfffc5

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

pkg/gpu/gpu.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,30 @@ const (
1919

2020
// ProbeGPUSupport determines whether or not the Docker engine has GPU support.
2121
func ProbeGPUSupport(ctx context.Context, dockerClient client.SystemAPIClient) (GPUSupport, error) {
22-
info, err := dockerClient.Info(ctx)
23-
if err != nil {
24-
return GPUSupportNone, err
25-
}
26-
if _, hasNvidia := info.Runtimes["nvidia"]; hasNvidia {
22+
// First search for nvidia-container-runtime on PATH
23+
if _, err := exec.LookPath("nvidia-container-runtime"); err == nil {
2724
return GPUSupportCUDA, nil
2825
}
2926

30-
// If nvidia runtime is not listed, try searching for nvidia-container-runtime on PATH
31-
if _, err := exec.LookPath("nvidia-container-runtime"); err == nil {
27+
// Next look for explicitly configured nvidia runtime. This is not required in Docker 19.03+ but
28+
// may be configured on some systems
29+
hasNvidia, err := HasNVIDIARuntime(ctx, dockerClient)
30+
if err != nil {
31+
return GPUSupportNone, err
32+
}
33+
if hasNvidia {
3234
return GPUSupportCUDA, nil
3335
}
3436

3537
return GPUSupportNone, nil
3638
}
39+
40+
// HasNVIDIARuntime determines whether there is an nvidia runtime available
41+
func HasNVIDIARuntime(ctx context.Context, dockerClient client.SystemAPIClient) (bool, error) {
42+
info, err := dockerClient.Info(ctx)
43+
if err != nil {
44+
return false, err
45+
}
46+
_, hasNvidia := info.Runtimes["nvidia"]
47+
return hasNvidia, nil
48+
}

pkg/standalone/containers.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
268268
nat.Port(portStr + "/tcp"): portBindings,
269269
}
270270
if gpu == gpupkg.GPUSupportCUDA {
271-
hostConfig.Runtime = "nvidia"
271+
if ok, err := gpupkg.HasNVIDIARuntime(ctx, dockerClient); err == nil && ok {
272+
hostConfig.Runtime = "nvidia"
273+
}
272274
hostConfig.DeviceRequests = []container.DeviceRequest{{Count: -1, Capabilities: [][]string{{"gpu"}}}}
273275
}
274276

0 commit comments

Comments
 (0)