Detect GPU VRAM

This commit is contained in:
2025-12-24 17:52:00 +02:00
parent 96a2dee0e1
commit db96cd7e5e
2 changed files with 12 additions and 4 deletions
+11 -1
View File
@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"slices" "slices"
"strconv"
"strings" "strings"
"github.com/go-gl/glfw/v3.3/glfw" "github.com/go-gl/glfw/v3.3/glfw"
@@ -23,7 +24,7 @@ type GPU struct {
Product string Product string
Subsystem string Subsystem string
Driver string Driver string
VRAM int64 VRAM string
} }
type Monitor struct { type Monitor struct {
@@ -134,6 +135,14 @@ func GetGPUModels(hiddenGPUs []int) []GPU {
} }
} }
// Get VRAM
vram := "Unknown"
bytes, err := os.ReadFile("/sys/class/drm/card" + strconv.Itoa(gpu.Index) + "/device/mem_info_vram_total")
if err == nil {
vramUint, _ := strconv.ParseUint(strings.TrimSpace(string(bytes)), 10, 64)
vram = FormatBytes(vramUint)
}
ret = append(ret, GPU{ ret = append(ret, GPU{
PCIAddress: gpu.Address, PCIAddress: gpu.Address,
Vendor: vendor, Vendor: vendor,
@@ -141,6 +150,7 @@ func GetGPUModels(hiddenGPUs []int) []GPU {
Product: gpu.DeviceInfo.Product.Name, Product: gpu.DeviceInfo.Product.Name,
Subsystem: gpu.DeviceInfo.Subsystem.Name, Subsystem: gpu.DeviceInfo.Subsystem.Name,
Driver: gpu.DeviceInfo.Driver, Driver: gpu.DeviceInfo.Driver,
VRAM: vram,
}) })
} }
+1 -3
View File
@@ -232,8 +232,6 @@ func initializeModuleMap() {
gpus := GetGPUModels(hiddenGPUs) gpus := GetGPUModels(hiddenGPUs)
for i, gpu := range gpus { for i, gpu := range gpus {
vram := strconv.FormatInt(gpu.VRAM, 10)
expanded := os.Expand(sm.Format, func(s string) string { expanded := os.Expand(sm.Format, func(s string) string {
switch s { switch s {
case "GPU_NUM": case "GPU_NUM":
@@ -249,7 +247,7 @@ func initializeModuleMap() {
case "GPU_DRIVER": case "GPU_DRIVER":
return gpu.Driver return gpu.Driver
case "GPU_VRAM": case "GPU_VRAM":
return vram return gpu.VRAM
default: default:
return "" return ""
} }