From d9819791763d5a029e0a02d361bb113019365c4e Mon Sep 17 00:00:00 2001 From: Vladislav Glinkin Date: Fri, 18 Sep 2026 18:50:44 +0300 Subject: [PATCH] ALT: include NVML alternatives directory in CDI --- internal/lookup/root/root.go | 9 +++++++++ internal/lookup/root/root_test.go | 32 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/internal/lookup/root/root.go b/internal/lookup/root/root.go index 284bafd5..817fafa0 100644 --- a/internal/lookup/root/root.go +++ b/internal/lookup/root/root.go @@ -120,6 +120,15 @@ func (r *Driver) DriverLibraryLocator(additionalDirs ...string) (lookup.Locator, } searchPaths := []string{libcudasoParentDirPath} + // Some distributions expose the driver libraries through an alternatives + // directory that is listed in ld.so.cache but is not the directory that + // contains libcuda.so. Add the resolved NVML directory to the search paths + // used for versioned driver libraries as well. + if nvmlPaths, err := r.Libraries().Locate("libnvidia-ml.so.1"); err == nil { + for _, path := range nvmlPaths { + searchPaths = append(searchPaths, r.RelativeToRoot(filepath.Dir(path))) + } + } for _, dir := range additionalDirs { if strings.HasPrefix(dir, "/") { searchPaths = append(searchPaths, dir) diff --git a/internal/lookup/root/root_test.go b/internal/lookup/root/root_test.go index c256deb6..7778babd 100644 --- a/internal/lookup/root/root_test.go +++ b/internal/lookup/root/root_test.go @@ -17,6 +17,7 @@ package root import ( + "os" "path/filepath" "testing" @@ -79,3 +80,34 @@ func TestDriverLibrariesLocate(t *testing.T) { } } } + +func TestDriverLibraryLocatorIncludesNvmlDirectory(t *testing.T) { + logger, _ := testlog.NewNullLogger() + rootfs := t.TempDir() + + libcudaDir := filepath.Join(rootfs, "usr", "lib64") + nvmlDir := filepath.Join(rootfs, "etc", "libnvidiacurrent") + require.NoError(t, os.MkdirAll(libcudaDir, 0755)) + require.NoError(t, os.MkdirAll(nvmlDir, 0755)) + + const version = "999.88.77" + libcuda := filepath.Join(libcudaDir, "libcuda.so."+version) + require.NoError(t, os.WriteFile(libcuda, nil, 0644)) + + nvml := filepath.Join(nvmlDir, "libnvidia-ml.so."+version) + require.NoError(t, os.WriteFile(nvml, nil, 0644)) + require.NoError(t, os.Symlink("libnvidia-ml.so."+version, filepath.Join(nvmlDir, "libnvidia-ml.so.1"))) + + driver := New( + WithLogger(logger), + WithDriverRoot(rootfs), + WithLibrarySearchPaths(libcudaDir, nvmlDir), + ) + + libraries, err := driver.DriverLibraryLocator() + require.NoError(t, err) + + candidates, err := libraries.Locate("*.so." + version) + require.NoError(t, err) + require.ElementsMatch(t, []string{libcuda, nvml}, candidates) +}