From ad9ec1efaef8a8b72358a704e9ef1ec0a14a0f40 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 11 May 2022 14:50:24 +0200 Subject: [PATCH 1/2] Add HasNVML function to check if NVML is supported Signed-off-by: Evan Lezar --- internal/info/{tegra.go => info.go} | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) rename internal/info/{tegra.go => info.go} (77%) diff --git a/internal/info/tegra.go b/internal/info/info.go similarity index 77% rename from internal/info/tegra.go rename to internal/info/info.go index 8a0a6687..c4f3676b 100644 --- a/internal/info/tegra.go +++ b/internal/info/info.go @@ -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" From ff86ecb2a5eefe03c3eaa1bd91dd7ff03aaf3b10 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 11 May 2022 14:52:59 +0200 Subject: [PATCH 2/2] Include HasNVML check in ResolveAutoMode Signed-off-by: Evan Lezar --- internal/info/auto.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/info/auto.go b/internal/info/auto.go index 734da448..89d2bbb6 100644 --- a/internal/info/auto.go +++ b/internal/info/auto.go @@ -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" }