Skip to content

Commit 5128007

Browse files
committed
Explicitly disable nvidia device injection for --gpus=0
This change ensures that when --gpus=0 is selected, the injection of NVIDIA device nodes and libraries is disabled by setting the NVIDIA_VISIBLE_DEVICES environment variable to void instead of leaving this unspecfied. Signed-off-by: Evan Lezar <[email protected]>
1 parent 09044f8 commit 5128007

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

daemon/nvidia_linux.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ func setNvidiaGPUs(s *specs.Spec, dev *deviceInstance) error {
5151
return errConflictCountDeviceIDs
5252
}
5353

54-
if len(req.DeviceIDs) > 0 {
54+
switch {
55+
case len(req.DeviceIDs) > 0:
5556
s.Process.Env = append(s.Process.Env, "NVIDIA_VISIBLE_DEVICES="+strings.Join(req.DeviceIDs, ","))
56-
} else if req.Count > 0 {
57+
case req.Count > 0:
5758
s.Process.Env = append(s.Process.Env, "NVIDIA_VISIBLE_DEVICES="+countToDevices(req.Count))
58-
} else if req.Count < 0 {
59+
case req.Count < 0:
5960
s.Process.Env = append(s.Process.Env, "NVIDIA_VISIBLE_DEVICES=all")
61+
case req.Count == 0:
62+
s.Process.Env = append(s.Process.Env, "NVIDIA_VISIBLE_DEVICES=void")
6063
}
6164

6265
var nvidiaCaps []string

0 commit comments

Comments
 (0)