Skip to content

Commit

Permalink
Merge pull request #801 from elezar/fix-legacy-nvidia-imex-channels
Browse files Browse the repository at this point in the history
Fix NVIDIA_IMEX_CHANNELS handling on legacy images
  • Loading branch information
elezar authored Nov 15, 2024
2 parents 1467f3f + f774cee commit 70ac1e2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/config/image/cuda_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,11 @@ func (i CUDA) CDIDevicesFromMounts() []string {

// ImexChannelsFromEnvVar returns the list of IMEX channels requested for the image.
func (i CUDA) ImexChannelsFromEnvVar() []string {
return i.DevicesFromEnvvars(EnvVarNvidiaImexChannels).List()
imexChannels := i.DevicesFromEnvvars(EnvVarNvidiaImexChannels).List()
if len(imexChannels) == 1 && imexChannels[0] == "all" {
return nil
}
return imexChannels
}

// ImexChannelsFromMounts returns the list of IMEX channels requested for the image.
Expand Down
31 changes: 31 additions & 0 deletions internal/config/image/cuda_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,37 @@ func TestGetVisibleDevicesFromMounts(t *testing.T) {
}
}

func TestImexChannelsFromEnvVar(t *testing.T) {
testCases := []struct {
description string
env []string
expected []string
}{
{
description: "no imex channels specified",
},
{
description: "imex channel specified",
env: []string{
"NVIDIA_IMEX_CHANNELS=3,4",
},
expected: []string{"3", "4"},
},
}

for _, tc := range testCases {
for id, baseEnvvars := range map[string][]string{"": nil, "legacy": {"CUDA_VERSION=1.2.3"}} {
t.Run(tc.description+id, func(t *testing.T) {
i, err := NewCUDAImageFromEnv(append(baseEnvvars, tc.env...))
require.NoError(t, err)

channels := i.ImexChannelsFromEnvVar()
require.EqualValues(t, tc.expected, channels)
})
}
}
}

func makeTestMounts(paths ...string) []specs.Mount {
var mounts []specs.Mount
for _, path := range paths {
Expand Down

0 comments on commit 70ac1e2

Please sign in to comment.