-
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathgpu.go
More file actions
40 lines (36 loc) · 1.04 KB
/
gpu.go
File metadata and controls
40 lines (36 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package gpu
import (
"errors"
"os"
)
type GpuVendor string
const (
GpuVendorNone GpuVendor = "none"
GpuVendorNvidia GpuVendor = "nvidia"
GpuVendorAmd GpuVendor = "amd"
GpuVendorIntel GpuVendor = "intel"
GpuVendorTenstorrent GpuVendor = "tenstorrent"
)
func GetGpuVendor() GpuVendor {
// FIXME: There might be errors other than os.ErrNotExist that are ignored silently.
// Propagate and log.
if _, err := os.Stat("/dev/kfd"); !errors.Is(err, os.ErrNotExist) {
return GpuVendorAmd
}
if _, err := os.Stat("/dev/nvidiactl"); !errors.Is(err, os.ErrNotExist) {
return GpuVendorNvidia
}
if _, err := os.Stat("/dev/accel"); !errors.Is(err, os.ErrNotExist) {
return GpuVendorIntel
}
if _, err := os.Stat("/dev/tenstorrent"); !errors.Is(err, os.ErrNotExist) {
return GpuVendorTenstorrent
}
if _, err := os.Stat("/dev/dxg"); !errors.Is(err, os.ErrNotExist) {
// WSL2
if _, err := os.Stat("/usr/lib/wsl/lib/nvidia-smi"); !errors.Is(err, os.ErrNotExist) {
return GpuVendorNvidia
}
}
return GpuVendorNone
}