gpu

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package gpu inventories the physical GPUs on Miabi-managed nodes and resolves a running app's GPU request to concrete devices at deploy time. Inventory rides the Docker API the control plane already speaks to every node through (a one-shot nvidia-smi probe container), so the node agent needs no changes and all three node access modes (local, agent-tunnelled, direct-socket) behave identically. Physical placement (which cards are offered, shared vs dedicated) is the platform admin's job; tenants only ever say "my app needs N GPUs".

Index

Constants

This section is empty.

Variables

View Source
var ErrDeviceNotOnNode = errors.New("gpu device does not belong to this node")

ErrDeviceNotOnNode is returned when an admin GPU mutation targets a device that does not belong to the addressed node.

View Source
var ErrGPUDisabled = errors.New("GPU support is disabled on this platform")

ErrGPUDisabled is returned when a GPU operation is attempted while the master switch (MIABI_GPU_ENABLED) is off.

Functions

This section is empty.

Types

type Config

type Config struct {
	Enabled       bool
	NvidiaRuntime string // container runtime name that signals the NVIDIA toolkit
	ProbeImage    string // one-shot image the inventory probe runs nvidia-smi in
}

Config carries the GPU knobs from the platform config.

type NoDeviceError

type NoDeviceError struct {
	Node      string
	Kind      string
	Requested int
	Available int
}

NoDeviceError is returned by ResolveDevices when a node has fewer enabled devices matching the request than the app asked for. It names the node and the requested kind so the deploy log is actionable.

func (*NoDeviceError) Code

func (e *NoDeviceError) Code() string

func (*NoDeviceError) Error

func (e *NoDeviceError) Error() string

type NodeDocker

type NodeDocker interface {
	For(serverID uint) (docker.Client, error)
	LocalID() uint
}

NodeDocker resolves the Docker client for a node id (0 = local). Satisfied by the node clients manager.

type Service

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

Service drives GPU inventory (scheduled + on-demand) and deploy-time device resolution.

func NewService

NewService builds the GPU service. quota is wired separately via SetQuota.

func (*Service) Devices

func (s *Service) Devices(serverID uint) ([]models.GPUDevice, error)

Devices lists every discovered device on a node (enabled or not).

func (*Service) Enabled

func (s *Service) Enabled() bool

Enabled reports whether GPU support is switched on.

func (*Service) Inventory

func (s *Service) Inventory(ctx context.Context) error

Inventory sweeps every node, refreshing its GPU rows. Per-node failures are logged and skipped (a probe failure must never fail the whole sweep). Safe to call on a schedule; a no-op when GPU support is disabled.

func (*Service) InventoryNode

func (s *Service) InventoryNode(ctx context.Context, serverID uint) (int, error)

InventoryNode refreshes one node's GPU rows and returns how many devices were observed. A node without the NVIDIA runtime, or whose probe fails, yields zero devices (never an error) — most nodes have no GPU. Discovered devices are upserted by UUID (admin flags preserved); new ones arrive disabled.

func (*Service) NodeCapable

func (s *Service) NodeCapable(ctx context.Context, serverID uint) bool

NodeCapable reports whether a node advertises the NVIDIA runtime (the toolkit is installed), so the admin UI can explain a node with no listed GPUs.

func (*Service) Preflight

func (s *Service) Preflight(app *models.Application) error

Preflight validates an app's GPU request against the plan capability and the workspace GPU quota (no device binding). Returns nil when the app requests no GPU. Called on the deploy path before the node is touched.

func (*Service) ResolveDevices

func (s *Service) ResolveDevices(ctx context.Context, app *models.Application, runtimes []string) ([]docker.GPURequest, error)

ResolveDevices binds an app's GPU request to concrete enabled devices on its node, returning the Docker device requests to attach. runtimes is the node's advertised container runtimes (docker info); a node without the NVIDIA runtime is refused up front rather than failing cryptically at container start. Returns nil when the app requests no GPU.

func (*Service) SetDevice

func (s *Service) SetDevice(serverID, gpuID uint, enabled, shared *bool) (*models.GPUDevice, error)

SetDevice applies admin policy (enable/disable, shared/dedicated) to a device on a node. enabled/shared are optional (nil = leave unchanged).

func (*Service) SetQuota

func (s *Service) SetQuota(q *quota.Service)

SetQuota wires the plan/quota enforcer (nil-safe; nil skips capability + quota checks, matching the single-tenant "no gating" stance).

Jump to

Keyboard shortcuts

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