Merge branch 'CNT-2973/add-has-nvml' into 'main'

Include HasNVML check in ResolveAutoMode

See merge request nvidia/container-toolkit/container-toolkit!149
This commit is contained in:
Evan Lezar 2022-05-12 11:23:47 +00:00
commit bdb43aa8f2
2 changed files with 21 additions and 1 deletions

View File

@ -35,7 +35,10 @@ func ResolveAutoMode(logger Logger, mode string) (rmode string) {
isTegra, reason := IsTegraSystem()
logger.Debugf("Is Tegra-based system? %v: %v", isTegra, reason)
if isTegra {
hasNVML, reason := HasNVML()
logger.Debugf("Has NVML? %v: %v", hasNVML, reason)
if isTegra && !hasNVML {
return "csv"
}

View File

@ -20,8 +20,25 @@ import (
"fmt"
"os"
"strings"
"github.com/NVIDIA/go-nvml/pkg/dl"
)
// HasNVML returns true if NVML is detected on the sytems
func HasNVML() (bool, string) {
const (
nvmlLibraryName = "libnvidia-ml.so.1"
nvmlLibraryLoadFlags = dl.RTLD_LAZY
)
lib := dl.New(nvmlLibraryName, nvmlLibraryLoadFlags)
if err := lib.Open(); err != nil {
return false, fmt.Sprintf("could not load NVML: %v", err)
}
defer lib.Close()
return true, "found NVML library"
}
// IsTegraSystem returns true if the system is detected as a Tegra-based system
func IsTegraSystem() (bool, string) {
const tegraReleaseFile = "/etc/nv_tegra_release"