mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-04-23 15:44:24 +00:00
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 <elezar@nvidia.com>
This commit is contained in:
parent
a103795553
commit
5349a84bdd
@ -86,6 +86,7 @@ devices:
|
|||||||
hostPath: /host/driver/root/dev/nvidia-caps-imex-channels/channel2047
|
hostPath: /host/driver/root/dev/nvidia-caps-imex-channels/channel2047
|
||||||
containerEdits:
|
containerEdits:
|
||||||
env:
|
env:
|
||||||
|
- LIBCUDA_SO_PARENT_DIRECTORY_CONTAINER_PATH=/lib/x86_64-linux-gnu
|
||||||
- NVIDIA_VISIBLE_DEVICES=void
|
- NVIDIA_VISIBLE_DEVICES=void
|
||||||
hooks:
|
hooks:
|
||||||
- hookName: createContainer
|
- hookName: createContainer
|
||||||
|
@ -79,6 +79,7 @@ devices:
|
|||||||
hostPath: {{ .driverRoot }}/dev/nvidia0
|
hostPath: {{ .driverRoot }}/dev/nvidia0
|
||||||
containerEdits:
|
containerEdits:
|
||||||
env:
|
env:
|
||||||
|
- LIBCUDA_SO_PARENT_DIRECTORY_CONTAINER_PATH=/lib/x86_64-linux-gnu
|
||||||
- NVIDIA_VISIBLE_DEVICES=void
|
- NVIDIA_VISIBLE_DEVICES=void
|
||||||
deviceNodes:
|
deviceNodes:
|
||||||
- path: /dev/nvidiactl
|
- path: /dev/nvidiactl
|
||||||
|
@ -82,7 +82,7 @@ func (l *nvcdilib) newDriverVersionDiscoverer(version string) (discover.Discover
|
|||||||
|
|
||||||
// NewDriverLibraryDiscoverer creates a discoverer for the libraries associated with the specified driver version.
|
// NewDriverLibraryDiscoverer creates a discoverer for the libraries associated with the specified driver version.
|
||||||
func (l *nvcdilib) NewDriverLibraryDiscoverer(version string) (discover.Discover, error) {
|
func (l *nvcdilib) NewDriverLibraryDiscoverer(version string) (discover.Discover, error) {
|
||||||
libraryPaths, err := getVersionLibs(l.logger, l.driver, version)
|
libraryPaths, libCudaDirectoryPath, err := getVersionLibs(l.logger, l.driver, version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get libraries for driver version: %v", err)
|
return nil, fmt.Errorf("failed to get libraries for driver version: %v", err)
|
||||||
}
|
}
|
||||||
@ -115,6 +115,12 @@ func (l *nvcdilib) NewDriverLibraryDiscoverer(version string) (discover.Discover
|
|||||||
updateLDCache, _ := discover.NewLDCacheUpdateHook(l.logger, libraries, l.nvidiaCDIHookPath, l.ldconfigPath)
|
updateLDCache, _ := discover.NewLDCacheUpdateHook(l.logger, libraries, l.nvidiaCDIHookPath, l.ldconfigPath)
|
||||||
discoverers = append(discoverers, updateLDCache)
|
discoverers = append(discoverers, updateLDCache)
|
||||||
|
|
||||||
|
environmentVariable := &discover.EnvVar{
|
||||||
|
Name: "LIBCUDA_SO_PARENT_DIRECTORY_CONTAINER_PATH",
|
||||||
|
Value: libCudaDirectoryPath,
|
||||||
|
}
|
||||||
|
discoverers = append(discoverers, environmentVariable)
|
||||||
|
|
||||||
d := discover.Merge(discoverers...)
|
d := discover.Merge(discoverers...)
|
||||||
|
|
||||||
return d, nil
|
return d, nil
|
||||||
@ -202,39 +208,41 @@ func NewDriverBinariesDiscoverer(logger logger.Interface, driverRoot string) dis
|
|||||||
// getVersionLibs checks the LDCache for libraries ending in the specified driver version.
|
// getVersionLibs checks the LDCache for libraries ending in the specified driver version.
|
||||||
// Although the ldcache at the specified driverRoot is queried, the paths are returned relative to this driverRoot.
|
// Although the ldcache at the specified driverRoot is queried, the paths are returned relative to this driverRoot.
|
||||||
// This allows the standard mount location logic to be used for resolving the mounts.
|
// This allows the standard mount location logic to be used for resolving the mounts.
|
||||||
func getVersionLibs(logger logger.Interface, driver *root.Driver, version string) ([]string, error) {
|
func getVersionLibs(logger logger.Interface, driver *root.Driver, version string) ([]string, string, error) {
|
||||||
logger.Infof("Using driver version %v", version)
|
logger.Infof("Using driver version %v", version)
|
||||||
|
|
||||||
libCudaPaths, err := cuda.New(
|
libCudaPaths, err := cuda.New(
|
||||||
driver.Libraries(),
|
driver.Libraries(),
|
||||||
).Locate("." + version)
|
).Locate("." + version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to locate libcuda.so.%v: %v", version, err)
|
return nil, "", fmt.Errorf("failed to locate libcuda.so.%v: %v", version, err)
|
||||||
}
|
}
|
||||||
libRoot := filepath.Dir(libCudaPaths[0])
|
libCudaDirectoryPath := filepath.Dir(libCudaPaths[0])
|
||||||
|
|
||||||
libraries := lookup.NewFileLocator(
|
libraries := lookup.NewFileLocator(
|
||||||
lookup.WithLogger(logger),
|
lookup.WithLogger(logger),
|
||||||
lookup.WithSearchPaths(
|
lookup.WithSearchPaths(
|
||||||
libRoot,
|
libCudaDirectoryPath,
|
||||||
filepath.Join(libRoot, "vdpau"),
|
filepath.Join(libCudaDirectoryPath, "vdpau"),
|
||||||
),
|
),
|
||||||
lookup.WithOptional(true),
|
lookup.WithOptional(true),
|
||||||
)
|
)
|
||||||
|
|
||||||
libs, err := libraries.Locate("*.so." + version)
|
libs, err := libraries.Locate("*.so." + version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to locate libraries for driver version %v: %v", version, err)
|
return nil, "", fmt.Errorf("failed to locate libraries for driver version %v: %v", version, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if driver.Root == "/" || driver.Root == "" {
|
if driver.Root == "/" || driver.Root == "" {
|
||||||
return libs, nil
|
return libs, libCudaDirectoryPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
libCudaDirectoryPath = driver.RelativeToRoot(libCudaDirectoryPath)
|
||||||
|
|
||||||
var relative []string
|
var relative []string
|
||||||
for _, l := range libs {
|
for _, l := range libs {
|
||||||
relative = append(relative, strings.TrimPrefix(l, driver.Root))
|
relative = append(relative, strings.TrimPrefix(l, driver.Root))
|
||||||
}
|
}
|
||||||
|
|
||||||
return relative, nil
|
return relative, libCudaDirectoryPath, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user