Skip to content

Commit 06b3881

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 59a0d10 commit 06b3881

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-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: 4 additions & 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
@@ -164,6 +165,7 @@ devices:
164165
hostPath: {{ .driverRoot }}/dev/nvidia0
165166
containerEdits:
166167
env:
168+
- LIBCUDA_SO_PARENT_DIRECTORY_CONTAINER_PATH=/lib/x86_64-linux-gnu
167169
- NVIDIA_VISIBLE_DEVICES=void
168170
deviceNodes:
169171
- path: /dev/nvidiactl
@@ -240,6 +242,7 @@ devices:
240242
hostPath: {{ .driverRoot }}/dev/nvidia0
241243
containerEdits:
242244
env:
245+
- LIBCUDA_SO_PARENT_DIRECTORY_CONTAINER_PATH=/lib/x86_64-linux-gnu
243246
- NVIDIA_VISIBLE_DEVICES=void
244247
deviceNodes:
245248
- path: /dev/nvidiactl
@@ -307,6 +310,7 @@ devices:
307310
hostPath: {{ .driverRoot }}/dev/nvidia0
308311
containerEdits:
309312
env:
313+
- LIBCUDA_SO_PARENT_DIRECTORY_CONTAINER_PATH=/lib/x86_64-linux-gnu
310314
- NVIDIA_VISIBLE_DEVICES=void
311315
deviceNodes:
312316
- 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
}
@@ -116,6 +116,12 @@ func (l *nvcdilib) NewDriverLibraryDiscoverer(version string) (discover.Discover
116116
disableDeviceNodeModification := l.hookCreator.Create(DisableDeviceNodeModificationHook)
117117
discoverers = append(discoverers, disableDeviceNodeModification)
118118

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

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

209215
libCudaPaths, err := cuda.New(
210216
driver.Libraries(),
211217
).Locate("." + version)
212218
if err != nil {
213-
return nil, fmt.Errorf("failed to locate libcuda.so.%v: %v", version, err)
219+
return nil, "", fmt.Errorf("failed to locate libcuda.so.%v: %v", version, err)
214220
}
215-
libRoot := filepath.Dir(libCudaPaths[0])
221+
libCudaDirectoryPath := filepath.Dir(libCudaPaths[0])
216222

217223
libraries := lookup.NewFileLocator(
218224
lookup.WithLogger(logger),
219225
lookup.WithSearchPaths(
220-
libRoot,
221-
filepath.Join(libRoot, "vdpau"),
226+
libCudaDirectoryPath,
227+
filepath.Join(libCudaDirectoryPath, "vdpau"),
222228
),
223229
lookup.WithOptional(true),
224230
)
225231

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

231237
if driver.Root == "/" || driver.Root == "" {
232-
return libs, nil
238+
return libs, libCudaDirectoryPath, nil
233239
}
234240

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

240-
return relative, nil
248+
return relative, libCudaDirectoryPath, nil
241249
}

0 commit comments

Comments
 (0)