hardware

package
v0.1.11-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinimumVRAMBytes = uint64(8 * 1024 * 1024 * 1024)
	// MinimumRAMBytes is the "16 GB installed" floor. Windows reports usable
	// RAM after hardware reservations, so a real 16 GB machine shows ~15.9 GB;
	// a strict 16 GiB compare would fail every 16 GB gaming PC. 15 GiB usable
	// only admits machines with at least 16 GB installed in practice.
	MinimumRAMBytes  = uint64(15 * 1024 * 1024 * 1024)
	MinimumDiskBytes = uint64(40 * 1024 * 1024 * 1024)
)
View Source
const (
	StatusPass        = "pass"
	StatusFail        = "fail"
	StatusWarn        = "warn"
	StatusUnsupported = "unsupported"
	StatusSkipped     = "skipped"
)
View Source
const (
	VendorNvidia  = "nvidia"
	VendorAMD     = "amd"
	VendorUnknown = "unknown"
)

GPU vendors the host node can serve on. Anything we cannot positively identify stays VendorUnknown rather than being guessed at.

View Source
const VRAMUnknown int64 = -1

VRAMUnknown marks a card whose memory size could not be established reliably. It is deliberately distinct from zero, which would read as "no memory" and silently fail eligibility comparisons.

Variables

View Source
var NvidiaSMIQueryArgs = []string{
	"--query-gpu=name,uuid,memory.total,driver_version,temperature.gpu,power.draw,power.limit,utilization.gpu",
	"--format=csv,noheader,nounits",
}
View Source
var WindowsVideoControllerArgs = []string{
	"-NoProfile",
	"-NonInteractive",
	"-Command",
	"Get-CimInstance Win32_VideoController | Select-Object Name, AdapterRAM, DriverVersion, AdapterCompatibility | ConvertTo-Json -Compress",
}

PowerShell is the no-extra-dependency route to the Windows display adapter inventory. ConvertTo-Json keeps parsing honest; -Compress avoids line wraps.

Functions

func AdapterVRAMBytes

func AdapterVRAMBytes(controller VideoController) (int64, bool)

AdapterVRAMBytes converts the WMI AdapterRAM field, which is a 32-bit value in practice. Anything at or above the 4 GiB boundary has wrapped and cannot be trusted; a modern 8, 16 or 24 GB card commonly reports exactly 4294967295. Reporting unknown is the honest answer: the alternative is telling a host with a 24 GB card that it has 4 GB, which would wrongly fail eligibility.

func DetectGPUVendor

func DetectGPUVendor(ctx context.Context, runner CommandRunner, goos string) string

DetectGPUVendor resolves the host GPU vendor for runtime selection. NVIDIA is probed first because nvidia-smi is authoritative when present; the WMI inventory is the fallback and is Windows-only. Anything unresolved is VendorUnknown, which makes callers use the bare platform artifact.

func VendorForController

func VendorForController(controller VideoController) string

VendorForController classifies an adapter from its vendor string and name.

func WriteHuman

func WriteHuman(w io.Writer, report DoctorReport)

func WriteJSON

func WriteJSON(w io.Writer, report DoctorReport) error

Types

type CheckResult

type CheckResult struct {
	Name        string         `json:"name"`
	Status      string         `json:"status"`
	Message     string         `json:"message"`
	Remediation string         `json:"remediation,omitempty"`
	Details     map[string]any `json:"details,omitempty"`
}

type CommandRunner

type CommandRunner interface {
	Run(ctx context.Context, name string, args ...string) ([]byte, error)
}

type DoctorOptions

type DoctorOptions struct {
	DiskPath string
	HTTPSURL string
	WSSURL   string
	Timeout  time.Duration
	Runner   CommandRunner
}

type DoctorReport

type DoctorReport struct {
	GeneratedAt time.Time     `json:"generated_at"`
	OS          string        `json:"os"`
	Arch        string        `json:"arch"`
	Overall     string        `json:"overall"`
	GPUVendor   string        `json:"gpu_vendor,omitempty"`
	Checks      []CheckResult `json:"checks"`
	GPUs        []GPU         `json:"gpus,omitempty"`
}

func RunDoctor

func RunDoctor(ctx context.Context, opts DoctorOptions) DoctorReport

type ExecRunner

type ExecRunner struct{}

func (ExecRunner) Run

func (ExecRunner) Run(ctx context.Context, name string, args ...string) ([]byte, error)

type GPU

type GPU struct {
	Name               string  `json:"name"`
	UUID               string  `json:"uuid"`
	VRAMTotalMB        int64   `json:"vram_total_mb"`
	DriverVersion      string  `json:"driver_version"`
	TemperatureC       int     `json:"temperature_c"`
	PowerDrawW         float64 `json:"power_draw_w"`
	PowerLimitW        float64 `json:"power_limit_w"`
	UtilizationPercent int     `json:"utilization_percent"`
}

func DetectNvidiaGPUs

func DetectNvidiaGPUs(ctx context.Context, runner CommandRunner) ([]GPU, error)

func GPUsFromControllers

func GPUsFromControllers(controllers []VideoController) []GPU

GPUsFromControllers converts adapters into the report shape. VRAM that could not be established is left as VRAMUnknown for the caller to describe.

func ParseNvidiaSMICSV

func ParseNvidiaSMICSV(input string) ([]GPU, error)

type HostResources

type HostResources struct {
	GPUVendor   string
	GPUName     string
	VRAMTotalMB int64
	RAMTotalMB  int64
	DiskFreeMB  int64
}

HostResources is what the node knows about its own capacity, in megabytes. VRAMTotalMB is VRAMUnknown when it could not be established reliably, which is a normal outcome on AMD (see AdapterVRAMBytes) and must not be treated as "no GPU memory".

func DetectHostResources

func DetectHostResources(ctx context.Context, runner CommandRunner, diskPath, goos string) (HostResources, error)

DetectHostResources gathers what the node can measure about itself. RAM and disk failures are returned as an error because they are measurable on every supported platform; VRAM is allowed to be unknown.

func (HostResources) VRAMKnown

func (h HostResources) VRAMKnown() bool

VRAMKnown reports whether VRAM was established well enough to gate on.

type VideoController

type VideoController struct {
	Name                 string `json:"Name"`
	AdapterRAM           *int64 `json:"AdapterRAM"`
	DriverVersion        string `json:"DriverVersion"`
	AdapterCompatibility string `json:"AdapterCompatibility"`
}

VideoController is one display adapter as Windows reports it.

func DetectWindowsVideoControllers

func DetectWindowsVideoControllers(ctx context.Context, runner CommandRunner) ([]VideoController, error)

DetectWindowsVideoControllers queries WMI through PowerShell.

func ParseVideoControllerJSON

func ParseVideoControllerJSON(input string) ([]VideoController, error)

ParseVideoControllerJSON accepts either a single object or an array, because ConvertTo-Json emits a bare object when exactly one adapter is present.

func SelectPrimaryController

func SelectPrimaryController(controllers []VideoController) (VideoController, string)

SelectPrimaryController picks the adapter the node should serve on: a discrete NVIDIA or AMD card wins over integrated or unknown adapters, which is what a gaming host actually has plugged in.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL