Skip to content

Commit 7b58a3e

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 cdffc99 commit 7b58a3e

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

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

+1
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

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ devices:
7979
hostPath: {{ .driverRoot }}/dev/nvidia0
8080
containerEdits:
8181
env:
82+
- LIBCUDA_SO_PARENT_DIRECTORY_CONTAINER_PATH=/lib/x86_64-linux-gnu
8283
- NVIDIA_VISIBLE_DEVICES=void
8384
deviceNodes:
8485
- path: /dev/nvidiactl

pkg/nvcdi/driver-nvml.go

+17-9
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
}
@@ -115,6 +115,12 @@ func (l *nvcdilib) NewDriverLibraryDiscoverer(version string) (discover.Discover
115115
updateLDCache, _ := discover.NewLDCacheUpdateHook(l.logger, libraries, l.nvidiaCDIHookPath, l.ldconfigPath)
116116
discoverers = append(discoverers, updateLDCache)
117117

118+
environmentVariable := &discover.EnvVar{
119+
Name: "LIBCUDA_SO_PARENT_DIRECTORY_CONTAINER_PATH",
120+
Value: libCudaDirectoryPath,
121+
}
122+
discoverers = append(discoverers, environmentVariable)
123+
118124
d := discover.Merge(discoverers...)
119125

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

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

216222
libraries := lookup.NewFileLocator(
217223
lookup.WithLogger(logger),
218224
lookup.WithSearchPaths(
219-
libRoot,
220-
filepath.Join(libRoot, "vdpau"),
225+
libCudaDirectoryPath,
226+
filepath.Join(libCudaDirectoryPath, "vdpau"),
221227
),
222228
lookup.WithOptional(true),
223229
)
224230

225231
libs, err := libraries.Locate("*.so." + version)
226232
if err != nil {
227-
return nil, fmt.Errorf("failed to locate libraries for driver version %v: %v", version, err)
233+
return nil, "", fmt.Errorf("failed to locate libraries for driver version %v: %v", version, err)
228234
}
229235

230236
if driver.Root == "/" || driver.Root == "" {
231-
return libs, nil
237+
return libs, libCudaDirectoryPath, nil
232238
}
233239

240+
libCudaDirectoryPath = driver.RelativeToRoot(libCudaDirectoryPath)
241+
234242
var relative []string
235243
for _, l := range libs {
236244
relative = append(relative, strings.TrimPrefix(l, driver.Root))
237245
}
238246

239-
return relative, nil
247+
return relative, libCudaDirectoryPath, nil
240248
}

0 commit comments

Comments
 (0)