Skip to content

Commit

Permalink
Merge branch 'fix-ld-library-path' into 'main'
Browse files Browse the repository at this point in the history
Use LD_PRELOAD to set path to libnvidia-ml.so.1 for nvidia-smi

See merge request nvidia/cloud-native/k8s-dra-driver!26
  • Loading branch information
Evan Lezar committed Nov 3, 2023
2 parents c3662ef + c53420e commit fe94758
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cmd/nvidia-dra-plugin/nvlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type deviceLib struct {
}

func newDeviceLib(driverRoot root) (*deviceLib, error) {
libraryPath, err := driverRoot.getDriverLibraryPath()
driverLibraryPath, err := driverRoot.getDriverLibraryPath()
if err != nil {
return nil, fmt.Errorf("failed to locate driver libraries: %w", err)
}
Expand All @@ -47,15 +47,15 @@ func newDeviceLib(driverRoot root) (*deviceLib, error) {
}

// In order for nvidia-smi to run, we need to set the PATH to the parent of
// the nvidia-smi executable and update the LD_LIBRARY_PATH to be able to
// locate libnvidia-ml.so.1
updatePathListEnvvar("LD_LIBRARY_PATH", filepath.Dir(libraryPath))
// the nvidia-smi executable and update LD_PRELOAD to include the path to
// libnvidia-ml.so.1
updatePathListEnvvar("LD_PRELOAD", driverLibraryPath)
updatePathListEnvvar("PATH", filepath.Dir(nvidiaSMIPath))

// We construct an NVML library specifying the path to libnvidia-ml.so.1 explicitly
// so that we don't have to rely on the library path.
// We construct an NVML library specifying the path to libnvidia-ml.so.1
// explicitly so that we don't have to rely on the library path.
nvmllib := nvml.New(
nvml.WithLibraryPath(libraryPath),
nvml.WithLibraryPath(driverLibraryPath),
)
d := deviceLib{
Interface: nvdev.New(nvdev.WithNvml(nvmllib)),
Expand Down

0 comments on commit fe94758

Please sign in to comment.