hwdetect

package
v0.207.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hwdetect classifies a machine into a hardware tier.

The classifier lived in setup/detect.ps1, which begins by refusing to run:

if ($os -ne 'windows') { Write-Error 'This detector targets Windows.' ; exit 1 }

So a Linux box could not be told what it IS, and everything downstream — the serving template, the resident tier, the media seed — had to be hand-derived. The two hand-derivations on the measured Linux node were both wrong in ways that broke chat, which is what a classifier exists to prevent.

Classify is a straight port of Get-Profile, boundaries included, and is verified against the SAME table detect.tests.ps1 asserts (classify_test.go). Porting the rules rather than reinventing them keeps one answer per machine while both implementations exist; detect.ps1 stays the Windows install path until the wrapper work lands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcceleratorsFromHailortcli

func AcceleratorsFromHailortcli(scanOut, identifyOut string) []string

AcceleratorsFromHailortcli classifies the Hailo device from hailortcli's own output: `scan` must list at least one "Device:" line and `identify` must report the 8L architecture. A full Hailo-8 is deliberately NOT matched — its model-zoo HEFs are a different build (hailo8/ vs hailo8l/) and would be rejected at load with an architecture mismatch.

func ArchFromName

func ArchFromName(name string) string

ArchFromName maps a GPU product name to the architecture the tier bands key on. A straight port of detect.ps1's Get-Arch, rule order included — the order IS the logic (an "RTX PRO 5000 Blackwell" must not fall through to the RTX-50xx rule it does not match, and a future non-Blackwell "RTX PRO" generation needs a new rule ABOVE that one).

func DetectAccelerators

func DetectAccelerators(run func(args ...string) (string, error)) []string

DetectAccelerators probes for accelerators with an injected runner so the decision stays pure and testable. run executes `hailortcli <args...>`; any error (tool absent, driver down) means "no accelerator" — never a failure, because a missing NPU is the normal case on most boxes.

func DetectAllAccelerators

func DetectAllAccelerators(run func(args ...string) (string, error), read func(path string) (string, error)) []string

DetectAllAccelerators is the union of every device probe, in the order the ids will be listed in config.Accelerators — Hailo first, then Coral, then the RKNPU. Order is load-bearing: the tool surface's shared-name rule (Coral D5) gives a name to the FIRST listed accelerator that owns it.

func DetectCoral

func DetectCoral(read func(path string) (string, error)) []string

DetectCoral reports ["coral-edgetpu"] iff the apex device's sysfs status reads ALIVE (Coral design D4). One id for the whole Edge TPU family — USB, M.2 and Dual all run the same _edgetpu.tflite artifacts. read is injected so the rule is testable without a device; any read error is "no accelerator".

func DetectRknpu

func DetectRknpu(read func(path string) (string, error)) []string

DetectRknpu reports ["rknpu"] iff one of the candidate uevent files (both kernel layouts, see rknpuUeventPaths) carries the DRIVER=RKNPU line. A successful read alone proves nothing (any DRM card reads, and so does the Mali GPU's), so the driver token is the whole rule; an unreadable candidate is skipped, and no match is "no accelerator", never a failure. read is injected so the rule is testable without a device.

func RAMTier

func RAMTier(ramGb int) string

RAMTier maps RAM size to the tier name the installers gate on.

func VendorFromName

func VendorFromName(name string) string

VendorFromName reports the GPU vendor a product name belongs to. "none" when the name is empty or unrecognised — never a guess, since the vendor selects the whole serving backend.

Types

type Facts

type Facts struct {
	// Vendor is nvidia|amd|rockchip|none. Arch is
	// blackwell|ampere|ada|volta|maxwell|rdna3|gcn|rk3588|other|none.
	Vendor string `json:"vendor"`
	Arch   string `json:"arch"`
	// VRAMGb is the DEDICATED VRAM of the primary GPU. On an AMD iGPU this is the
	// BIOS carve-out (0.5-4 GB), not the usable UMA pool — which is exactly why the
	// AMD branch bands on it rather than trusting it as capacity.
	VRAMGb   float64 `json:"vram_gb"`
	GPUCount int     `json:"gpu_count"`
	RAMGb    int     `json:"ram_gb"`
	// UMA marks a GPU with no memory of its own: an SoC whose GPU and NPU allocate
	// from the same RAM as the CPU. VRAMGb is 0 there and the usable capacity is a
	// share of RAMGb — which is what separates it from an AMD iGPU, whose BIOS
	// carve-out is small but real. Carried for the report; it never decides a tier.
	UMA bool `json:"uma,omitempty"`
	// GPUName and DriverVersion are carried for the report; they never decide a tier.
	GPUName       string `json:"gpu_name,omitempty"`
	DriverVersion string `json:"driver_version,omitempty"`
	OS            string `json:"os,omitempty"`
	// Archs lists EVERY detected GPU's architecture, in nvidia-smi row order. Arch
	// above is the primary (largest) card's; a homogeneity decision — "one sm_120
	// build serves both cards" — needs all of them, not the biggest.
	Archs []string `json:"archs,omitempty"`
}

Facts are what a machine reports about itself. Everything the classifier needs and nothing it does not — so it stays pure and testable against synthetic tuples.

func Detect

func Detect() Facts

Detect reports what THIS machine is. nvidia-smi is authoritative when present (it names the card, its dedicated VRAM and the driver); otherwise a per-OS fallback finds an AMD or unknown adapter, because a box that cannot be classified must not be silently called "cpu" — that would hand an AMD laptop the weakest possible profile. A board with no PCI adapter at all is last asked whether the device tree names a supported SoC (DetectSoC).

Every probe is read-only and bounded: no model is loaded and nothing is written.

func DetectSoC

func DetectSoC(read func(path string) ([]byte, error)) (Facts, bool)

DetectSoC recognises a supported SoC from the device tree and reports the Facts it implies. ok is false — and the machine left exactly as the PCI probes found it — for anything else: an x86 or Windows box (no device tree, so the read fails), another ARM board, or a property that cannot be read. read is injected so the rule is testable without a board.

An SoC has no PCI adapter for probeFallbackGPU to find (its Mali GPU and NPU sit on the platform bus), so without this an RK3588 fell through to "cpu" and was handed a CPU-inference serving config, which no model on this fleet may run. Its GPU and NPU draw from the same RAM as the CPU: VRAMGb stays 0 and UMA is true.

type Verdict

type Verdict struct {
	Profile string `json:"profile"`
	// BigRAM marks the >=120 GB RAM variant of the multi-GPU tiers (dual-gpu's
	// config #4 and blackwell-2x16): detection cannot see the Optane drive that
	// really distinguishes config #4, so RAM approximates it.
	BigRAM bool   `json:"big_ram"`
	Reason string `json:"reason"`
	// RAMTier gates the RAM-hungry 26B placements, the RAM-spill agent seat and the
	// RAM-gated config_seed overlays (config_seed_ram_low_up from low up,
	// config_seed_ram_mid_high from mid up). detect.ps1 has always emitted it; this side
	// reported raw ram_gb only, so the Linux installer had nothing to pass and the gates
	// were inert there — a tier served the 26B on a box with no RAM path for it, and the
	// mid/high image seed never applied.
	RAMTier string `json:"ram_tier"`
	// Accelerators lists additive devices found BESIDE the GPU (ADR 0024), e.g.
	// "hailo-8l". Classify never fills it — detection is a separate probe
	// (DetectAccelerators) the installers run and merge, so a box with no NPU
	// serialises exactly as before (omitempty).
	Accelerators []string `json:"accelerators,omitempty"`
}

Verdict is the classification plus why, so an operator can see the band that caught their machine instead of taking the answer on faith.

func Classify

func Classify(f Facts) Verdict

Classify maps facts to a tier and its RAM tier. The RAM tier is stamped HERE, in one place, rather than at each return: the profile logic has early returns and a verdict that silently carried an empty ram_tier would leave both RAM gates inert without anything failing.

Jump to

Keyboard shortcuts

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