gpulock

package
v0.209.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 5 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 gpulock is the READ-ONLY Go view of the GPU lease that internal/gpulease owns and that every GPU consumer takes. The GPU is shared between llama-swap (the VLM/text tiers) and ComfyUI/Chatterbox (the generation jobs).

LO-1 evidence: while a generation job held the lease, llama-swap could not (re)load the vision model, so EVERY vision call 5xx'd and DEFERRED — 295 of the 337 all-time defers landed inside one such hour. A defer is not a cloud API call: the harness never calls a cloud model (see main.go), it returns a structured defer and the work falls back to Opus, the calling session. The cost is that the harness stops doing the one thing it exists for, silently. This package lets the pipeline SEE the lease before burning a doomed HTTP call: resolve the same path every other consumer uses, report held/not-held plus holder age, and wait (bounded) for the slot to free.

Invariants:

  • Read-only: this package NEVER creates, reclaims, or removes the lease — acquisition and stale-reclaim belong to internal/gpulease.
  • It resolves the SAME path and parses the SAME record as every other participant, and shares one definition of process liveness with them. Each of those was independently wrong once, and each time the symptom was identical: this package reported a live holder's lease as FREE.

Index

Constants

View Source
const DefaultTTL = time.Hour

DefaultTTL mirrors DEFAULT_TTL_MS in render/gpu-lock.mjs (1h — a real video generation can take many minutes; the TTL is only the fallback when the holder pid is unknown, and the backstop against pid recycling).

Variables

This section is empty.

Functions

func EpochIsCurrent added in v0.206.0

func EpochIsCurrent(lockPath string, epoch uint64) bool

EpochIsCurrent is the per-epoch fence for a caller that was handed a lease (an inherited GPU_LEASE_EPOCH): that epoch is still a live lease and still its own. This package never compared epochs itself (it only reports held/free), so the fence lives in gpulease and is delegated to, like the rest of the inspection.

func Path

func Path(override, stateDir string) string

Path resolves the shared GPU lease directory exactly the way every other consumer does: explicit override first (the gpu_lock_path config field — the pipeline also threads it to the runners as the GPU_LOCK env so both sides always contend on ONE path), then the GPU_LOCK env, then <state-root>/gpu/lease.

THE DEFAULT MOVED, AND THIS MUST MOVE WITH IT. The lease used to live under the OS temp dir. When it became machine-wide (%ProgramData%) this function was left behind, so the vision gate watched a path nothing writes and WaitFree answered "free" every time — silently reinstating the LO-1 regression it exists to prevent (a vision call fired into a busy GPU 5xx's and defers, so the harness stops offloading at exactly the moment offloading matters). Resolution is delegated rather than duplicated so the two can never drift apart again.

Types

type Info

type Info struct {
	// Held is true when a claim exists AND the shared staleness rule says it is live.
	Held bool
	// Age is how long the current holder has held the card, from the acquirer's own
	// stamp. NOT time-since-last-heartbeat, which reads as a few seconds for any
	// long-running holder and made the defer message report "(0s)" for a job that had
	// owned the card for an hour.
	Age time.Duration
	// PID is the recorded holder pid (0 when unknown / not held).
	PID int
	// Class is the holder's lease class (media/text), so a caller can say WHICH kind of
	// work holds the card instead of assuming it is a generation job.
	Class string
	// ExpiresAt is the holder's DECLARED window end (zero when it declared none).
	// WaitFree uses it to stop polling a reservation that provably cannot free
	// inside the caller's wait: before 0.113.27 every vision call burned its
	// full vision_gpu_wait_sec (90 s by default) against a multi-hour hold, so
	// a long reservation cost 90 s of dead wait PER CALL for its whole life.
	ExpiresAt time.Time
}

Info is one point-in-time inspection of the lease.

func Inspect

func Inspect(lockPath string) Info

Inspect reports whether the lock at lockPath is currently held, using the same staleness rule as gpu-lock.mjs with the default 1h TTL. A stale lock (dead holder / no meta / over-TTL) reports NOT held — reclaiming it is the runners' job, never ours.

func WaitFree

func WaitFree(ctx context.Context, lockPath string, wait, poll time.Duration) Info

WaitFree polls the lock every poll (min bound 1ms; the pipeline passes 2s) until it is free or wait has elapsed (or ctx is done), returning the FINAL inspection: Held=false means the slot freed (proceed); Held=true means the caller should defer, with Age available for the defer reason.

func WaitFreeScoped added in v0.206.0

func WaitFreeScoped(ctx context.Context, lockPath string, wait, poll time.Duration, read func(dir string) gpulease.Info) Info

WaitFreeScoped is WaitFree for a caller whose work sits on some of the cards, not all of them (plan P4): read is the lease reader, handed the lease directory and returning the leases that matter to the caller (the vision gate passes the seat-narrowed reading the text gate uses), so a render on a card the caller's seat is not pinned to is not a lease to wait for. The held/not-held rule is still gpulease's; only which leases count changes.

Jump to

Keyboard shortcuts

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