Skip to content

Commit 2751299

Browse files
committed
Add envvar for libcuda.so parent dir to CDI spec
This change adds a LIBCUDA_SO_PARENT_DIRECTORY_CONTAINER_PATH envvar to a generated CDI specification. This reports where the `libcuda.so.*` libraries will be injected into the container. Signed-off-by: Evan Lezar <[email protected]>
1 parent fc439c7 commit 2751299

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

cmd/nvidia-ctk-installer/toolkit/toolkit_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ devices:
8686
hostPath: /host/driver/root/dev/nvidia-caps-imex-channels/channel2047
8787
containerEdits:
8888
env:
89+
- LIBCUDA_SO_PARENT_DIRECTORY_CONTAINER_PATH=/lib/x86_64-linux-gnu
8990
- NVIDIA_VISIBLE_DEVICES=void
9091
hooks:
9192
- hookName: createContainer

cmd/nvidia-ctk/cdi/generate/generate_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ devices:
8080
hostPath: {{ .driverRoot }}/dev/nvidia0
8181
containerEdits:
8282
env:
83+
- LIBCUDA_SO_PARENT_DIRECTORY_CONTAINER_PATH=/lib/x86_64-linux-gnu
8384
- NVIDIA_VISIBLE_DEVICES=void
8485
deviceNodes:
8586
- path: /dev/nvidiactl

pkg/nvcdi/driver-nvml.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (l *nvcdilib) newDriverVersionDiscoverer(version string) (discover.Discover
8282

8383
// NewDriverLibraryDiscoverer creates a discoverer for the libraries associated with the specified driver version.
8484
func (l *nvcdilib) NewDriverLibraryDiscoverer(version string) (discover.Discover, error) {
85-
libraryPaths, err := getVersionLibs(l.logger, l.driver, version)
85+
libraryPaths, libCudaDirectoryPath, err := getVersionLibs(l.logger, l.driver, version)
8686
if err != nil {
8787
return nil, fmt.Errorf("failed to get libraries for driver version: %v", err)
8888
}
@@ -113,6 +113,12 @@ func (l *nvcdilib) NewDriverLibraryDiscoverer(version string) (discover.Discover
113113
updateLDCache, _ := discover.NewLDCacheUpdateHook(l.logger, libraries, l.hookCreator, l.ldconfigPath)
114114
discoverers = append(discoverers, updateLDCache)
115115

116+
environmentVariable := &discover.EnvVar{
117+
Name: "LIBCUDA_SO_PARENT_DIRECTORY_CONTAINER_PATH",
118+
Value: libCudaDirectoryPath,
119+
}
120+
discoverers = append(discoverers, environmentVariable)
121+
116122
d := discover.Merge(discoverers...)
117123

118124
return d, nil
@@ -200,39 +206,41 @@ func NewDriverBinariesDiscoverer(logger logger.Interface, driverRoot string) dis
200206
// getVersionLibs checks the LDCache for libraries ending in the specified driver version.
201207
// Although the ldcache at the specified driverRoot is queried, the paths are returned relative to this driverRoot.
202208
// This allows the standard mount location logic to be used for resolving the mounts.
203-
func getVersionLibs(logger logger.Interface, driver *root.Driver, version string) ([]string, error) {
209+
func getVersionLibs(logger logger.Interface, driver *root.Driver, version string) ([]string, string, error) {
204210
logger.Infof("Using driver version %v", version)
205211

206212
libCudaPaths, err := cuda.New(
207213
driver.Libraries(),
208214
).Locate("." + version)
209215
if err != nil {
210-
return nil, fmt.Errorf("failed to locate libcuda.so.%v: %v", version, err)
216+
return nil, "", fmt.Errorf("failed to locate libcuda.so.%v: %v", version, err)
211217
}
212-
libRoot := filepath.Dir(libCudaPaths[0])
218+
libCudaDirectoryPath := filepath.Dir(libCudaPaths[0])
213219

214220
libraries := lookup.NewFileLocator(
215221
lookup.WithLogger(logger),
216222
lookup.WithSearchPaths(
217-
libRoot,
218-
filepath.Join(libRoot, "vdpau"),
223+
libCudaDirectoryPath,
224+
filepath.Join(libCudaDirectoryPath, "vdpau"),
219225
),
220226
lookup.WithOptional(true),
221227
)
222228

223229
libs, err := libraries.Locate("*.so." + version)
224230
if err != nil {
225-
return nil, fmt.Errorf("failed to locate libraries for driver version %v: %v", version, err)
231+
return nil, "", fmt.Errorf("failed to locate libraries for driver version %v: %v", version, err)
226232
}
227233

228234
if driver.Root == "/" || driver.Root == "" {
229-
return libs, nil
235+
return libs, libCudaDirectoryPath, nil
230236
}
231237

238+
libCudaDirectoryPath = driver.RelativeToRoot(libCudaDirectoryPath)
239+
232240
var relative []string
233241
for _, l := range libs {
234242
relative = append(relative, strings.TrimPrefix(l, driver.Root))
235243
}
236244

237-
return relative, nil
245+
return relative, libCudaDirectoryPath, nil
238246
}

0 commit comments

Comments
 (0)