gpustats

package
v0.4.154 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0 Imports: 18 Imported by: ? 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 gpustats reads the usage of graphics cards. A figure the box does not measure is absent (nil), never 0.

Index

Constants

View Source
const (
	VendorNVIDIA = "nvidia"
	VendorAMD    = "amd"
	VendorIntel  = "intel"

	StateOK         = "ok"
	StateReserved   = "reserved"
	StateAsleep     = "asleep"
	StateUnreadable = "unreadable"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Card

type Card struct {
	Index       int      `json:"index"`
	Address     string   `json:"address"` // 0000:08:00.0
	Vendor      string   `json:"vendor"`  // nvidia | amd | intel
	Name        string   `json:"name"`
	State       string   `json:"state"`                  // ok | reserved | asleep | unreadable
	Load        *float64 `json:"load,omitempty"`         // percent
	Load3D      *float64 `json:"load_3d,omitempty"`      // percent, 3D/compute engines
	LoadVideo   *float64 `json:"load_video,omitempty"`   // percent, video engines
	MemoryUsed  *float64 `json:"memory_used,omitempty"`  // bytes
	MemoryTotal *float64 `json:"memory_total,omitempty"` // bytes
	Temperature *float64 `json:"temperature,omitempty"`  // °C
	Power       *float64 `json:"power,omitempty"`        // watts
}

type Config

type Config struct {
	PCIDir       string                                                  // "" -> /sys/bus/pci/devices
	ReservedFile string                                                  // "" -> /var/lib/casaos/gpu-reserved
	SMI          func(ctx context.Context, query string) ([]byte, error) // nil -> nvidia-smi from the PATH; query is the whole --query-gpu=... argument; absent from the PATH = no NVIDIA figures
	NameOf       func(vendor, device string) string                      // pci.ids; nil -> generic names
	Now          func() time.Time                                        // nil -> time.Now
	EventDir     string                                                  // "" -> /sys/bus/event_source/devices
	OpenCounter  OpenCounter                                             // nil -> openPerf
}

type Counter added in v0.4.154

type Counter interface {
	Read() (uint64, error)
	Close() error
}

Counter is one opened perf counter, in nanoseconds of engine busy time.

type OpenCounter added in v0.4.154

type OpenCounter func(typ uint32, config uint64, cpu int) (Counter, error)

OpenCounter opens a perf counter of the given event source type on one cpu.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service reads the cards in its own goroutine and keeps the last reading in memory: Latest never waits for a read.

var Default *Service

Default is the service of the running core; nil until wired.

func New

func New(cfg Config) *Service

func (*Service) Latest

func (s *Service) Latest() []Card

Latest returns copies of the cards seen so far, by rank; nil when none was ever seen.

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run reads now, then every 5 s, until ctx ends; it then closes the Intel counters.

Jump to

Keyboard shortcuts

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