Skip to content

Commit

Permalink
Generate hook to create .so symlinks in CDI
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Lezar <[email protected]>
  • Loading branch information
elezar committed Apr 15, 2024
1 parent 9d7a707 commit 020f598
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
8 changes: 8 additions & 0 deletions cmd/nvidia-ctk/cdi/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type options struct {
files cli.StringSlice
ignorePatterns cli.StringSlice
}

noDotSoSymlinks bool
}

// NewCommand constructs a generate-cdi command with the specified logger
Expand Down Expand Up @@ -166,6 +168,11 @@ func (m command) build() *cli.Command {
Usage: "Specify a pattern the CSV mount specifications.",
Destination: &opts.csv.ignorePatterns,
},
&cli.BoolFlag{
Name: "no-dot-so-symlinks",
Usage: "Skip the generation of a hook for creating .so symlinks to driver files in the container",
Destination: &opts.noDotSoSymlinks,
},
}

return &c
Expand Down Expand Up @@ -270,6 +277,7 @@ func (m command) generateSpec(opts *options) (spec.Interface, error) {
nvcdi.WithLibrarySearchPaths(opts.librarySearchPaths.Value()),
nvcdi.WithCSVFiles(opts.csv.files.Value()),
nvcdi.WithCSVIgnorePatterns(opts.csv.ignorePatterns.Value()),
nvcdi.WithNoDotSoSymlinks(opts.noDotSoSymlinks),
)
if err != nil {
return nil, fmt.Errorf("failed to create CDI library: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/nvcdi/common-nvml.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (l *nvmllib) newCommonNVMLDiscoverer() (discover.Discover, error) {
l.logger.Warningf("failed to create discoverer for graphics mounts: %v", err)
}

driverFiles, err := NewDriverDiscoverer(l.logger, l.driver, l.nvidiaCTKPath, l.ldconfigPath, l.nvmllib)
driverFiles, err := l.newDriverDiscoverer()
if err != nil {
return nil, fmt.Errorf("failed to create discoverer for driver files: %v", err)
}
Expand Down
25 changes: 18 additions & 7 deletions pkg/nvcdi/driver-nvml.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,35 @@ import (
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/root"
)

// NewDriverDiscoverer creates a discoverer for the libraries and binaries associated with a driver installation.
// newDriverDiscoverer creates a discoverer for the libraries and binaries associated with a driver installation.
// The supplied NVML Library is used to query the expected driver version.
func NewDriverDiscoverer(logger logger.Interface, driver *root.Driver, nvidiaCTKPath string, ldconfigPath string, nvmllib nvml.Interface) (discover.Discover, error) {
if r := nvmllib.Init(); r != nvml.SUCCESS {
func (l *nvmllib) newDriverDiscoverer() (discover.Discover, error) {
if r := l.nvmllib.Init(); r != nvml.SUCCESS {
return nil, fmt.Errorf("failed to initialize NVML: %v", r)
}
defer func() {
if r := nvmllib.Shutdown(); r != nvml.SUCCESS {
logger.Warningf("failed to shutdown NVML: %v", r)
if r := l.nvmllib.Shutdown(); r != nvml.SUCCESS {
l.logger.Warningf("failed to shutdown NVML: %v", r)
}
}()

version, r := nvmllib.SystemGetDriverVersion()
version, r := l.nvmllib.SystemGetDriverVersion()
if r != nvml.SUCCESS {
return nil, fmt.Errorf("failed to determine driver version: %v", r)
}

return newDriverVersionDiscoverer(logger, driver, nvidiaCTKPath, ldconfigPath, version)
driver, err := newDriverVersionDiscoverer(l.logger, l.driver, l.nvidiaCTKPath, l.ldconfigPath, version)
if err != nil {
return nil, fmt.Errorf("failed to create discoverer: %w", err)
}
discoverers := []discover.Discover{driver}

if !l.noDotSoSymlinks {
createDotSoSymlinksHook := discover.NewDotSoSymlinksDiscoverer(l.nvidiaCTKPath, version)
discoverers = append(discoverers, createDotSoSymlinksHook)
}

return discover.Merge(discoverers...), nil
}

func newDriverVersionDiscoverer(logger logger.Interface, driver *root.Driver, nvidiaCTKPath, ldconfigPath, version string) (discover.Discover, error) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/nvcdi/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type nvcdilib struct {
infolib info.Interface

mergedDeviceOptions []transform.MergedDeviceOption

noDotSoSymlinks bool
}

// New creates a new nvcdi library
Expand Down
7 changes: 7 additions & 0 deletions pkg/nvcdi/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,10 @@ func WithLibrarySearchPaths(paths []string) Option {
o.librarySearchPaths = paths
}
}

// WithNoDotSoSymlinks sets the no-dot-so-symlinks feature.
func WithNoDotSoSymlinks(noDotSoSymlinks bool) Option {
return func(o *nvcdilib) {
o.noDotSoSymlinks = noDotSoSymlinks
}
}

0 comments on commit 020f598

Please sign in to comment.