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 ¶
- Variables
- type Config
- type NoDeviceError
- type NodeDocker
- type Service
- func (s *Service) Devices(serverID uint) ([]models.GPUDevice, error)
- func (s *Service) Enabled() bool
- func (s *Service) Inventory(ctx context.Context) error
- func (s *Service) InventoryNode(ctx context.Context, serverID uint) (int, error)
- func (s *Service) NodeCapable(ctx context.Context, serverID uint) bool
- func (s *Service) Preflight(app *models.Application) error
- func (s *Service) ResolveDevices(ctx context.Context, app *models.Application, runtimes []string) ([]docker.GPURequest, error)
- func (s *Service) SetDevice(serverID, gpuID uint, enabled, shared *bool) (*models.GPUDevice, error)
- func (s *Service) SetQuota(q *quota.Service)
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
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 ¶
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 ¶
func NewService(devices *repositories.GPUDeviceRepository, servers *repositories.ServerRepository, apps *repositories.ApplicationRepository, clients NodeDocker, cfg Config) *Service
NewService builds the GPU service. quota is wired separately via SetQuota.
func (*Service) Inventory ¶
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 ¶
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 ¶
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.