Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions internal/config/image/cuda_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,22 @@ func TestGetDevicesFromEnvvar(t *testing.T) {
},
expectedDevices: []string{anotherGPUID},
},
{
description: "repeated device in NVIDIA_VISIBLE_DEVICES is returned once",
env: map[string]string{
EnvVarNvidiaVisibleDevices: gpuID + "," + anotherGPUID + "," + gpuID,
},
expectedDevices: []string{gpuID, anotherGPUID},
},
{
description: "device repeated across swarm resource envvars is returned once",
preferredVisibleDeviceEnvVars: []string{"DOCKER_RESOURCE_GPUS", "DOCKER_RESOURCE_GPUS_ADDITIONAL"},
env: map[string]string{
"DOCKER_RESOURCE_GPUS": gpuID,
"DOCKER_RESOURCE_GPUS_ADDITIONAL": gpuID,
},
expectedDevices: []string{gpuID},
},
}

for _, tc := range tests {
Expand Down
3 changes: 3 additions & 0 deletions internal/config/image/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func newDevices(idOrCommaSeparated ...string) devices {
i := 0
for _, commaSeparated := range idOrCommaSeparated {
for id := range strings.SplitSeq(commaSeparated, ",") {
if _, exists := lookup[id]; exists {
continue
}
lookup[id] = i
i++
}
Expand Down