-
Notifications
You must be signed in to change notification settings - Fork 526
fix: Use system search path when locate driver library #1820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,7 +121,7 @@ func newGraphicsLibrariesDiscoverer(logger logger.Interface, driver *root.Driver | |
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get driver version: %w", err) | ||
| } | ||
| cudaLibRoot, err := driver.GetDriverLibDirectory() | ||
| cudaLibRoots, err := driver.GetDriverLibDirectories() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get libcuda.so parent directory: %w", err) | ||
| } | ||
|
|
@@ -152,7 +152,7 @@ func newGraphicsLibrariesDiscoverer(logger logger.Interface, driver *root.Driver | |
| lookup.NewFileLocator( | ||
| lookup.WithLogger(logger), | ||
| lookup.WithRoot(driver.Root), | ||
| lookup.WithSearchPaths(buildXOrgSearchPaths(cudaLibRoot)...), | ||
| lookup.WithSearchPaths(buildXOrgSearchPaths(cudaLibRoots...)...), | ||
| lookup.WithCount(1), | ||
| ), | ||
| driver.Root, | ||
|
|
@@ -239,8 +239,16 @@ func (d graphicsDriverLibraries) isDriverLibrary(filename string, libraryName st | |
| return match | ||
| } | ||
|
|
||
| func buildXOrgSearchPaths(roots ...string) []string { | ||
| var paths []string | ||
| for _, root := range roots { | ||
| paths = append(paths, buildXOrgSearchPathsForSingle(root)...) | ||
| } | ||
| return paths | ||
| } | ||
|
|
||
| // buildXOrgSearchPaths returns the ordered list of search paths for XOrg files. | ||
| func buildXOrgSearchPaths(libRoot string) []string { | ||
| func buildXOrgSearchPathsForSingle(libRoot string) []string { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we update the comment so it matches the new method name? |
||
| var paths []string | ||
| if libRoot != "" { | ||
| paths = append(paths, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,7 @@ import ( | |||||
| "fmt" | ||||||
| "os" | ||||||
| "path/filepath" | ||||||
| "slices" | ||||||
| "strings" | ||||||
| "sync" | ||||||
|
|
||||||
|
|
@@ -43,8 +44,8 @@ type Driver struct { | |||||
|
|
||||||
| // version caches the driver version. | ||||||
| version string | ||||||
| // driverLibDirectory caches the path to parent of the driver libraries | ||||||
| driverLibDirectory string | ||||||
| // driverLibDirectories caches the paths to parent of the driver libraries | ||||||
| driverLibDirectories []string | ||||||
| } | ||||||
|
|
||||||
| // New creates a new Driver root using the specified options. | ||||||
|
|
@@ -70,13 +71,13 @@ func New(opts ...Option) *Driver { | |||||
| } | ||||||
|
|
||||||
| d := &Driver{ | ||||||
| logger: o.logger, | ||||||
| Root: o.Root, | ||||||
| DevRoot: o.DevRoot, | ||||||
| librarySearchPaths: o.librarySearchPaths, | ||||||
| configSearchPaths: o.configSearchPaths, | ||||||
| version: driverVersion, | ||||||
| driverLibDirectory: "", | ||||||
| logger: o.logger, | ||||||
| Root: o.Root, | ||||||
| DevRoot: o.DevRoot, | ||||||
| librarySearchPaths: o.librarySearchPaths, | ||||||
| configSearchPaths: o.configSearchPaths, | ||||||
| version: driverVersion, | ||||||
| driverLibDirectories: nil, | ||||||
| } | ||||||
|
|
||||||
| return d | ||||||
|
|
@@ -97,34 +98,36 @@ func (r *Driver) Version() (string, error) { | |||||
| return r.version, nil | ||||||
| } | ||||||
|
|
||||||
| // GetDriverLibDirectory returns the cached directory where the driver libs are | ||||||
| // found if possible. | ||||||
| // GetDriverLibDirectories returns the cached directories where the driver libs | ||||||
| // are found if possible. | ||||||
| // If this has not yet been initialized, the path is first detected and then returned. | ||||||
| func (r *Driver) GetDriverLibDirectory() (string, error) { | ||||||
| func (r *Driver) GetDriverLibDirectories() ([]string, error) { | ||||||
| r.Lock() | ||||||
| defer r.Unlock() | ||||||
|
|
||||||
| if r.driverLibDirectory == "" { | ||||||
| if len(r.driverLibDirectories) == 0 { | ||||||
| if err := r.updateInfo(); err != nil { | ||||||
| return "", err | ||||||
| return nil, err | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return r.driverLibDirectory, nil | ||||||
| return r.driverLibDirectories, nil | ||||||
| } | ||||||
|
|
||||||
| func (r *Driver) DriverLibraryLocator(additionalDirs ...string) (lookup.Locator, error) { | ||||||
| libcudasoParentDirPath, err := r.GetDriverLibDirectory() | ||||||
| libcudasoParentDirPaths, err := r.GetDriverLibDirectories() | ||||||
| if err != nil { | ||||||
| return nil, fmt.Errorf("failed to get libcuda.so parent directory: %w", err) | ||||||
| } | ||||||
|
|
||||||
| searchPaths := []string{libcudasoParentDirPath} | ||||||
| searchPaths := slices.Clone(libcudasoParentDirPaths) | ||||||
| for _, dir := range additionalDirs { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already search these paths for As a follow-up question: Could we plumb through the other directories through |
||||||
| if strings.HasPrefix(dir, "/") { | ||||||
| searchPaths = append(searchPaths, dir) | ||||||
| } else { | ||||||
| searchPaths = append(searchPaths, filepath.Join(libcudasoParentDirPath, dir)) | ||||||
| for _, libcudasoParentDirPath := range libcudasoParentDirPaths { | ||||||
| searchPaths = append(searchPaths, filepath.Join(libcudasoParentDirPath, dir)) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -141,16 +144,33 @@ func (r *Driver) DriverLibraryLocator(additionalDirs ...string) (lookup.Locator, | |||||
| } | ||||||
|
|
||||||
| func (r *Driver) updateInfo() error { | ||||||
| driverLibPath, version, err := r.inferVersion() | ||||||
| _, version, err := r.inferVersion() | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| if r.version != "" && r.version != version { | ||||||
| return fmt.Errorf("unexpected version detected: %v != %v", r.version, version) | ||||||
| } | ||||||
|
|
||||||
| versionedDriverLibPaths, err := r.Libraries().Locate("lib*.so." + version) | ||||||
| if err != nil { | ||||||
| return fmt.Errorf("failed to locate versioned driver libraries: %w", err) | ||||||
| } | ||||||
|
|
||||||
| var uniqueDirs []string | ||||||
| seen := make(map[string]bool) | ||||||
|
|
||||||
| for _, path := range versionedDriverLibPaths { | ||||||
| dir := filepath.Dir(path) | ||||||
| if seen[dir] { | ||||||
| continue | ||||||
| } | ||||||
| seen[dir] = true | ||||||
| uniqueDirs = append(uniqueDirs, r.RelativeToRoot(dir)) | ||||||
| } | ||||||
|
|
||||||
| r.version = version | ||||||
| r.driverLibDirectory = r.RelativeToRoot(filepath.Dir(driverLibPath)) | ||||||
| r.driverLibDirectories = uniqueDirs | ||||||
|
|
||||||
| return nil | ||||||
| } | ||||||
|
|
@@ -167,7 +187,7 @@ func (r *Driver) inferVersion() (string, string, error) { | |||||
| for _, driverLib := range []string{"libcuda.so.", "libnvidia-ml.so."} { | ||||||
| driverLibPaths, err := r.Libraries().Locate(driverLib + versionSuffix) | ||||||
| if err != nil { | ||||||
| errs = errors.Join(errs, fmt.Errorf("failed to locate libcuda.so: %w", err)) | ||||||
| errs = errors.Join(errs, fmt.Errorf("failed to locate %v: %w", driverLib, err)) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| continue | ||||||
| } | ||||||
| driverLibPath := driverLibPaths[0] | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment needs to be moved above this method?