mirror of
https://github.com/EnumeratedDev/stormfetch.git
synced 2026-09-16 07:56:12 +00:00
Detect GPU VRAM
This commit is contained in:
+11
-1
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-gl/glfw/v3.3/glfw"
|
||||
@@ -23,7 +24,7 @@ type GPU struct {
|
||||
Product string
|
||||
Subsystem string
|
||||
Driver string
|
||||
VRAM int64
|
||||
VRAM string
|
||||
}
|
||||
|
||||
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{
|
||||
PCIAddress: gpu.Address,
|
||||
Vendor: vendor,
|
||||
@@ -141,6 +150,7 @@ func GetGPUModels(hiddenGPUs []int) []GPU {
|
||||
Product: gpu.DeviceInfo.Product.Name,
|
||||
Subsystem: gpu.DeviceInfo.Subsystem.Name,
|
||||
Driver: gpu.DeviceInfo.Driver,
|
||||
VRAM: vram,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -232,8 +232,6 @@ func initializeModuleMap() {
|
||||
gpus := GetGPUModels(hiddenGPUs)
|
||||
|
||||
for i, gpu := range gpus {
|
||||
vram := strconv.FormatInt(gpu.VRAM, 10)
|
||||
|
||||
expanded := os.Expand(sm.Format, func(s string) string {
|
||||
switch s {
|
||||
case "GPU_NUM":
|
||||
@@ -249,7 +247,7 @@ func initializeModuleMap() {
|
||||
case "GPU_DRIVER":
|
||||
return gpu.Driver
|
||||
case "GPU_VRAM":
|
||||
return vram
|
||||
return gpu.VRAM
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user