Merge pull request #2553 from dhiltgen/amdgpu_version

Harden AMD driver lookup logic
This commit is contained in:
Daniel Hiltgen 2024-02-16 17:23:12 -08:00 committed by GitHub
commit 4318e35ee3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View file

@ -2,6 +2,7 @@ package gpu
import (
"bufio"
"errors"
"fmt"
"io"
"log/slog"
@ -24,14 +25,23 @@ const (
)
func AMDDetected() bool {
_, err := AMDDriverVersion()
return err == nil
// Some driver versions (older?) don't have a version file, so just lookup the parent dir
sysfsDir := filepath.Dir(DriverVersionFile)
_, err := os.Stat(sysfsDir)
if errors.Is(err, os.ErrNotExist) {
slog.Debug("amd driver not detected " + sysfsDir)
return false
} else if err != nil {
slog.Debug(fmt.Sprintf("error looking up amd driver %s %s", sysfsDir, err))
return false
}
return true
}
func AMDDriverVersion() (string, error) {
_, err := os.Stat(DriverVersionFile)
if err != nil {
return "", err
return "", fmt.Errorf("amdgpu file stat error: %s %w", DriverVersionFile, err)
}
fp, err := os.Open(DriverVersionFile)
if err != nil {

View file

@ -153,6 +153,9 @@ func GetGPUInfo() GpuInfo {
ver, err := AMDDriverVersion()
if err == nil {
slog.Info("AMD Driver: " + ver)
} else {
// For now this is benign, but we may eventually need to fail compatibility checks
slog.Debug("error looking up amd driver version: %s", err)
}
gfx := AMDGFXVersions()
tooOld := false