Documentation
¶
Overview ¶
Package mockctl holds the pure config override-mutation logic used by the nvml-mock-ctl CLI. It lives outside the engine package so the CLI never links the CGo bridge/build tags, while still reusing engine's Go types and merge/validation helpers for a single source of truth on the schema.
Index ¶
- func ApplicationsClocksPatch(memMHz, graphicsMHz uint32) map[string]any
- func ClearAccountingPids(path string, index int) error
- func ClearEccErrorCounts(path string, index int, scope engine.EccCounterScope) error
- func ClockOffsetPatch(domain engine.ClockDomain, offsetMHz int32) map[string]any
- func ClocksPatch(mhz int) map[string]any
- func FabricHealthPatch(conditions []string) (map[string]any, error)
- func FanControlPatch(controls []engine.FanControlConfig) map[string]any
- func FanPatch(percent, baseCount int) map[string]any
- func LockOverride(path string) (func(), error)
- func LockedClocksPatch(domain engine.ClockDomain, r *engine.ClockRangeConfig) map[string]any
- func MIGAddComputeInstance(path string, index int, giID uint32, rec engine.MIGComputeInstanceRecord) error
- func MIGAddGpuInstance(path string, index int, rec engine.MIGGPUInstanceRecord) error
- func MIGRemoveComputeInstance(path string, index int, giID, ciID uint32) error
- func MIGRemoveGpuInstance(path string, index int, giID uint32) error
- func MIGSeedLayout(path string, index int, records []engine.MIGGPUInstanceRecord) error
- func MIGSetMode(path string, index int, enabled bool) error
- func NVLinkErrorPatch(rate float64, links []int) map[string]any
- func NvlinkBwModePatch(mode uint8) map[string]any
- func NvlinkLowPowerThresholdPatch(threshold uint32) map[string]any
- func PStatePatch(n int) map[string]any
- func ParseSet(pairs []string) (map[string]any, error)
- func PowerLimitPatch(milliwatts uint32) map[string]any
- func PowerPatch(milliwatts uint32) map[string]any
- func ResetDevice(path string, index int) error
- func ResetOverrides(path string) error
- func SetAccountingMode(path string, index int, enabled bool) error
- func SetApplicationsClocks(path string, index int, memMHz, graphicsMHz uint32) error
- func SetClockOffset(path string, index int, domain engine.ClockDomain, offsetMHz int32) error
- func SetDrainState(path string, index int, draining bool) error
- func SetDramEncryptionPending(path string, index int, enabled bool) error
- func SetEccModePending(path string, index int, enabled bool) error
- func SetLockedClocks(path string, index int, domain engine.ClockDomain, r *engine.ClockRangeConfig) error
- func SetNvlinkBwMode(path string, index int, mode uint8, allDevices bool) error
- func SetNvlinkLowPowerThreshold(path string, index int, threshold *uint32) error
- func SetPersistenceMode(path string, index int, enabled bool) error
- func SetPowerLimit(path string, index int, milliwatts uint32) error
- func SetPowerMizerMode(path string, index int, mode string) error
- func SetPowerSmoothingActiveProfile(path string, index int, profileID uint32) error
- func SetPowerSmoothingProfileParam(path string, index int, profileID uint32, param engine.PowerSmoothingParam, ...) error
- func SetPowerSmoothingState(path string, index int, enabled bool) error
- func SetRemoved(path string, index int, removed bool) error
- func SramECCPatch(count uint64, errorType, source string, thresholdExceeded bool) (map[string]any, error)
- func TemperaturePatch(celsius int) map[string]any
- func ThrottlePatch(reasons []string) (map[string]any, error)
- func UpdateFanControl(path string, index int, ...) error
- func UpdateWorkloadProfiles(path string, index int, ...) error
- func UtilizationPatch(percent int) map[string]any
- func Validate(base *engine.DeviceConfig, patch map[string]any) error
- func WorkloadProfilesPatch(requested []uint32) map[string]any
- func WriteAtomic(path string, doc *Doc) error
- type Doc
- func (d *Doc) Bytes() ([]byte, error)
- func (d *Doc) ClearDeviceField(key string)
- func (d *Doc) ClearField(t Target, key string)
- func (d *Doc) Fail(t Target, mode string, afterCalls int, xidCode uint64) error
- func (d *Doc) FailureXid(index int) uint64
- func (d *Doc) FanControls(index int) (controls []engine.FanControlConfig, present bool)
- func (d *Doc) Reset(t Target)
- func (d *Doc) SetFields(t Target, kv map[string]any)
- func (d *Doc) WorkloadRequestedProfiles(index int) (requested []uint32, present bool)
- type MIGTx
- func (tx *MIGTx) AddComputeInstance(giID uint32, rec engine.MIGComputeInstanceRecord) error
- func (tx *MIGTx) AddGpuInstance(rec engine.MIGGPUInstanceRecord) error
- func (tx *MIGTx) Close()
- func (tx *MIGTx) Commit() error
- func (tx *MIGTx) RemoveComputeInstance(giID, ciID uint32) error
- func (tx *MIGTx) RemoveGpuInstance(giID uint32) error
- func (tx *MIGTx) SeedLayout(records []engine.MIGGPUInstanceRecord) error
- func (tx *MIGTx) SetMode(enabled bool) error
- type Target
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplicationsClocksPatch ¶ added in v0.5.0
ApplicationsClocksPatch builds an override patch recording the applications clocks nvmlDeviceSetApplicationsClocks applied.
func ClearAccountingPids ¶ added in v0.6.0
ClearAccountingPids persists the clear nvmlDeviceClearAccountingPids applied. It records an empty list rather than deleting the key, because the records it clears may come from the profile, and only an explicit empty list outranks them in the merge.
func ClearEccErrorCounts ¶ added in v0.6.0
func ClearEccErrorCounts(path string, index int, scope engine.EccCounterScope) error
ClearEccErrorCounts persists the zeroing of one scope of ECC counters.
func ClockOffsetPatch ¶ added in v0.5.0
func ClockOffsetPatch(domain engine.ClockDomain, offsetMHz int32) map[string]any
ClockOffsetPatch builds an override patch recording the offset nvmlDeviceSetClockOffsets applied. Only offset_mhz is written: the range it was validated against belongs to the board and stays the profile's.
func ClocksPatch ¶
ClocksPatch builds an config override patch that pins the reported SM and graphics clocks to mhz. There is no dynamic clock simulator, so this hot-reloads directly from the static clocks block. Memory/video clocks are left at their profile baseline (use `set clocks.memory_current=...` to change those). mhz is an int (the CLI validates it as non-negative); the generic config override map carries it as-is and the JSON round-trip in MergeDeviceConfig decodes it into the uint32 schema field.
func FabricHealthPatch ¶ added in v0.4.0
FabricHealthPatch builds a config override patch that sets a device's NVLink fabric health conditions, so a fabric can degrade under a running workload (#677). conditions are CLI-friendly names (see fabricHealthConditionKeys) plus the incorrect-configuration values the engine accepts (engine.FabricIncorrectConfigNames, e.g. "no_partition"); the special condition "healthy" clears everything and cannot be combined with others.
Like ThrottlePatch the block is authoritative: every condition is written (requested ones faulted, the rest clear) so repeated invocations replace rather than accumulate. It also releases fabric.health_summary to "auto", because a profile that pins a summary would otherwise keep reporting it no matter which condition is injected.
func FanControlPatch ¶ added in v0.5.0
func FanControlPatch(controls []engine.FanControlConfig) map[string]any
FanControlPatch builds an override patch that replaces a device's per-fan control state. A nil list is normalised to an empty one for the same reason WorkloadProfilesPatch does: nil marshals to null, which reads back as "nothing was ever written" and would make a caller who released every fan indistinguishable from one that never wrote.
func FanPatch ¶
FanPatch builds an config override patch that pins the reported fan speed to percent. There is no dynamic fan simulator, so this only touches the static fan block. GetFanSpeed reports ERROR_NOT_SUPPORTED (nvidia-smi shows N/A) whenever count is 0 — the case for every liquid/passively-cooled profile — so we force count to at least 1 (preserving a larger baseCount) to make the speed observable. speed_percent is a string field in the schema, hence the itoa.
func LockOverride ¶
LockOverride takes an exclusive flock on a sibling .lock file so concurrent kubectl exec invocations serialize their read-modify-write.
func LockedClocksPatch ¶ added in v0.5.0
func LockedClocksPatch(domain engine.ClockDomain, r *engine.ClockRangeConfig) map[string]any
LockedClocksPatch builds an override patch recording the range nvmlDeviceSetGpuLockedClocks or nvmlDeviceSetMemoryLockedClocks applied, or for a nil range the unlock their resets applied.
func MIGAddComputeInstance ¶ added in v0.5.0
func MIGAddComputeInstance(path string, index int, giID uint32, rec engine.MIGComputeInstanceRecord) error
MIGAddComputeInstance records a compute instance created inside giID. Both an unrecorded GPU instance and an ID that instance already carries are rejected, for the reasons MIGAddGpuInstance and migRecord give.
func MIGAddGpuInstance ¶ added in v0.5.0
func MIGAddGpuInstance(path string, index int, rec engine.MIGGPUInstanceRecord) error
MIGAddGpuInstance records a newly created GPU instance. The record's compute instances are kept as the caller passed them, empty list included: that is how `nvidia-smi mig -cgi` without -C differs from an unspecified layout.
An ID the layout already carries is rejected: NVML allocates these, so a duplicate means a replayed or mis-sequenced mutation, and appending a second entry would make a later MIGRemoveGpuInstance remove both copies at once.
func MIGRemoveComputeInstance ¶ added in v0.5.0
MIGRemoveComputeInstance records a destroyed compute instance.
Unlike MIGRemoveGpuInstance, an absent list is emptied rather than rejected: absent here means the engine supplies one compute instance spanning the GPU instance, so recording the empty list destroys exactly the instance the conventional `ciID == 0` names — a faithful delta, not a guess. That holds only for that one id; any other id against an absent list names an instance the layout does not hold, and emptying the list would destroy the spanning instance instead of the one asked for.
func MIGRemoveGpuInstance ¶ added in v0.5.0
MIGRemoveGpuInstance records a destroyed GPU instance. The list stays present when it empties: a MIG-enabled board with nothing on it is a real state, and an absent list would fall back to the profile's partitions.
A device with no recorded layout at all is rejected instead. Absent means "the profile's declared counts stand", so there is no delta to take one instance out of; writing the remainder as an empty list would record the destruction of every other instance the profile declares. A caller that records the live layout before mutating it always presents one.
func MIGSeedLayout ¶ added in v0.5.0
func MIGSeedLayout(path string, index int, records []engine.MIGGPUInstanceRecord) error
MIGSeedLayout records records as the device's explicit layout, but only when it has none: a delta writer edits that layout and cannot invent one, so the first runtime mutation on a device has to write down the board it is about to change before it can describe the change as a difference.
Seeding a device that already carries a layout would overwrite what earlier mutations recorded, so it is skipped rather than merged — which is also what makes it safe for every mutation to call unconditionally.
A nil records is nothing to seed rather than an empty layout, the same distinction the document itself draws: an empty list records a MIG-enabled board with every instance destroyed, and writing that for a board that is merely switched off would destroy the partitions its profile declares.
func MIGSetMode ¶ added in v0.5.0
MIGSetMode records a MIG mode change. Disabling clears the recorded layout, because disabling MIG on hardware destroys every instance.
func NVLinkErrorPatch ¶
NVLinkErrorPatch builds a config override patch that injects NVLink DL error accrual on a device's links (nvlink_error block). rate is errors/second; a rate of 0 heals the device by pinning the block to a no-op (the engine reads rate<=0 as "no injection") without disturbing other overrides. links, when non-empty, restricts injection to those link ids; nil injects on every active link. The block is authoritative — it replaces any prior nvlink_error so a stale link filter never lingers — matching the fail/throttle builders.
func NvlinkBwModePatch ¶ added in v0.5.0
NvlinkBwModePatch builds an override patch recording the bandwidth mode nvmlDeviceSetNvlinkBwMode or nvmlSystemSetNvlinkBwMode applied.
func NvlinkLowPowerThresholdPatch ¶ added in v0.5.0
NvlinkLowPowerThresholdPatch builds an override patch recording the threshold nvmlDeviceSetNvLinkDeviceLowPowerThreshold applied.
func PStatePatch ¶
PStatePatch builds an config override patch that pins the reported performance state to P<n>. GetPerformanceState reads the static performance_state string, so it hot-reloads directly.
func ParseSet ¶
ParseSet converts ["a.b=1","c=x"] into a nested map, parsing each value as a YAML scalar so numbers/bools/strings get their natural type.
func PowerLimitPatch ¶ added in v0.5.0
PowerLimitPatch builds an override patch that caps the device at milliwatts, the state nvmlDeviceSetPowerManagementLimit leaves behind.
func PowerPatch ¶
PowerPatch builds an config override patch that pins the reported power draw to milliwatts. Like TemperaturePatch it writes both the static power block and a zero-variation dynamic block so the reading is deterministic in either mode. The engine still clamps the value to the profile's [min_limit_mw, max_limit_mw] envelope, so a value outside that window will read as the nearest bound.
func ResetDevice ¶ added in v0.4.0
ResetDevice returns one device to its healthy baseline by removing its override bucket, taking the same flock as every other writer of this file so a concurrent injection cannot interleave with the reset.
The exception is an ECC mode nvmlDeviceSetEccMode left pending. A GPU reset is what makes a pending mode current on hardware, so the reset writes it back as both modes instead of dropping it with the injected state.
The index is deliberately not a Target: a Target can say "all", and the shared `all:` bucket is not resettable per device. Doc.Reset leaves that bucket alone for a device target (so state injected with `--gpu all` survives, and needs `Doc.Reset(Target{All: true})` to clear), and a caller resetting a single GPU must not be able to ask for something this cannot honour.
A device with nothing injected is reset without touching the file at all — no write and no lock. That is not just an optimisation: resetting a healthy device is the common case, and skipping the write keeps it working where the overrides are not writable. Only a reset that genuinely has state to clear can fail.
func ResetOverrides ¶ added in v0.4.0
ResetOverrides removes the override document so simulated state falls back to the pristine profile. It takes the same lock as WriteAtomic's callers because the allocation watcher publishes on its own interval and would otherwise re-create the file mid-removal. A missing file is already the desired state.
func SetAccountingMode ¶ added in v0.6.0
SetAccountingMode persists whether per-process accounting is enabled on one device. Disabling also records an empty terminated list, because turning accounting off clears every record the driver held.
func SetApplicationsClocks ¶ added in v0.5.0
SetApplicationsClocks persists the applications clocks for one device. A reset writes the board defaults through here too, so the pair is always recorded rather than cleared.
func SetClockOffset ¶ added in v0.5.0
SetClockOffset persists the offset applied to one clock domain.
func SetDrainState ¶ added in v0.5.0
SetDrainState persists the drain state nvmlDeviceModifyDrainState applied.
func SetDramEncryptionPending ¶ added in v0.6.0
SetDramEncryptionPending persists the DRAM encryption mode the next reboot applies.
func SetEccModePending ¶ added in v0.6.0
SetEccModePending persists the ECC mode that applies after the next GPU reset. The current mode is not written: a mode change is a reset away on hardware, so the two diverge until then.
func SetLockedClocks ¶ added in v0.5.0
func SetLockedClocks(path string, index int, domain engine.ClockDomain, r *engine.ClockRangeConfig) error
SetLockedClocks persists the range one clock domain is locked to. A nil range is the reset setters, and records an explicit unlock rather than deleting the device's lock: unlike a power cap, whose reset falls back to the profile's value, an unlocked GPU is the driver default, so a lock inherited from the profile or the `all:` bucket must not reappear through the merge.
func SetNvlinkBwMode ¶ added in v0.5.0
SetNvlinkBwMode persists an NVLink Reduced Bandwidth Mode. allDevices routes the write to the `all:` bucket, which is how the node-wide NVML pair records a mode that belongs to the node rather than to one GPU.
A node-wide write also drops the mode any per-device write left behind, so that every GPU reports the new one. On real hardware the node-wide call moves the whole node, and the per-device field outranks `all:` in the merge — so without this an earlier per-device set would keep masking a later node-wide one. Only the bandwidth mode is cleared; the rest of a device's injected state has nothing to do with this API.
func SetNvlinkLowPowerThreshold ¶ added in v0.5.0
SetNvlinkLowPowerThreshold persists an NVLink low-power threshold for one device. A nil threshold removes the recorded value so the device falls back to the driver default, which is what the setter's reset sentinel means.
func SetPersistenceMode ¶ added in v0.5.0
SetPersistenceMode persists whether persistence mode is enabled on one device.
func SetPowerLimit ¶ added in v0.5.0
SetPowerLimit persists a power cap for one device. The engine still clamps the value to the profile's [min_limit_mw, max_limit_mw] envelope on read, so callers that need the clamped value must read it back.
func SetPowerMizerMode ¶ added in v0.6.0
SetPowerMizerMode persists the PowerMizer mode nvmlDeviceSetPowerMizerMode_v1 applied, spelled the way the profile schema names it.
func SetPowerSmoothingActiveProfile ¶ added in v0.6.0
SetPowerSmoothingActiveProfile persists the preset profile nvmlDevicePowerSmoothingActivatePresetProfile made active.
func SetPowerSmoothingProfileParam ¶ added in v0.6.0
func SetPowerSmoothingProfileParam( path string, index int, profileID uint32, param engine.PowerSmoothingParam, value float64, ) error
SetPowerSmoothingProfileParam persists one preset profile parameter. Only that parameter is written, so the rest of the preset stays the profile's.
func SetPowerSmoothingState ¶ added in v0.6.0
SetPowerSmoothingState persists whether power smoothing is enabled on one device.
func SetRemoved ¶ added in v0.5.0
SetRemoved persists whether a GPU was removed from the driver, the state nvmlDeviceRemoveGpu sets and nvmlDeviceDiscoverGpus clears.
func SramECCPatch ¶ added in v0.4.0
func SramECCPatch(count uint64, errorType, source string, thresholdExceeded bool) (map[string]any, error)
SramECCPatch builds a config override patch that injects count SRAM ECC errors of one type (correctable, uncorrectable parity or uncorrectable SEC-DED), attributed to one reporting unit, optionally raising the SRAM error threshold flag. A count of 0 heals the device.
The count lands in both the volatile and aggregate scopes: hardware that has just taken an SRAM fault reports it in both, and pinning only one would leave the other reading as a GPU whose history disagrees with its present.
Only the ecc.sram sub-block is written, never the whole ecc block: replacing ecc would drop mode_current, and a GPU with ECC off reports no SRAM counters at all, so the injection would erase itself. Within ecc.sram the patch is authoritative — every counter and source is written — so repeated invocations replace rather than accumulate.
func TemperaturePatch ¶
TemperaturePatch builds an config override patch that pins the reported GPU temperature to celsius. It writes both the static thermal block and a zero-variation dynamic block: profiles that enable dynamic metrics (the demo/e2e default) drive temperature.gpu through the simulator, which masks the static thermal reading, so setting only thermal.temperature_gpu_c would have no visible effect. Zeroing ramp_c/variance_c makes the simulator emit base_c verbatim, so the reading is deterministic whether or not the profile runs the simulator. `reset` removes both, restoring the profile baseline.
func ThrottlePatch ¶
ThrottlePatch builds an config override patch that sets the GPU's active clock throttle reasons. reasons are CLI-friendly names (see throttleReasonKeys); the special reason "none" clears all reasons and cannot be combined with others. The patch is authoritative: every known flag is written (requested ones true, the rest false) so repeated invocations replace rather than accumulate state.
func UpdateFanControl ¶ added in v0.5.0
func UpdateFanControl( path string, index int, apply func(base []engine.FanControlConfig, present bool) ([]engine.FanControlConfig, error), ) error
UpdateFanControl persists new per-fan control state for one device, computed by apply from the state already on disk.
apply takes the whole list for the same reason UpdateWorkloadProfiles does: the NVML fan setters address one fan while the recorded state covers every one, so the base has to be read under the same lock as the write or two callers writing different fans lose one of the two writes.
func UpdateWorkloadProfiles ¶ added in v0.5.0
func UpdateWorkloadProfiles( path string, index int, apply func(base []uint32, present bool) ([]uint32, error), ) error
UpdateWorkloadProfiles persists a new requested workload power profile list for one device, computed by apply from the list already on disk.
The caller supplies apply rather than a finished list because the NVML operations are read-modify-write — SET adds to the request — and the base has to be read under the same lock as the write, or two concurrent callers each compute from the same base and one update is lost.
present distinguishes "nothing has been written" from "written, then cleared". Only the former may fall back to the request configured in the profile; the latter is a caller that deliberately asked for none.
func UtilizationPatch ¶
UtilizationPatch builds an config override patch that pins GPU and memory utilization to percent. Profiles that enable dynamic metrics (the demo/e2e default) drive utilization through the simulator, which masks the static UtilizationConfig; unlike temperature/power we cannot pin it with a zero-variation dynamic block because the simulator treats min==max==0 as "unbounded" (0..100), so `util 0` would not be deterministic. Instead we set the static block and disable the dynamic utilization sub-simulator (null), so the static value is authoritative for any percent in [0,100]. `reset` restores the profile baseline.
func Validate ¶
func Validate(base *engine.DeviceConfig, patch map[string]any) error
Validate wraps engine.MergeDeviceConfig and discards the result, surfacing unknown-field/type errors from applying patch over base.
func WorkloadProfilesPatch ¶ added in v0.5.0
WorkloadProfilesPatch builds an override patch that replaces the requested profile list. A nil list is normalised to an empty one: nil marshals to null, which reads back as "nothing was ever requested" and would make a caller who cleared every profile indistinguishable from one who never wrote at all.
func WriteAtomic ¶
WriteAtomic writes the doc via a temp file + rename in the same directory so readers (and the bind-mounted view in consumer containers) never observe a partial file.
Types ¶
type Doc ¶
type Doc struct {
Version int `json:"version,omitzero"`
All map[string]any `json:"all,omitempty"`
Devices map[string]map[string]any `json:"devices,omitempty"`
}
Doc mirrors engine.ConfigOverrideDoc but lives in the CLI package so nvml-mock-ctl never links the CGo bridge/build tags. The on-disk schema is identical.
func Load ¶
Load reads an config override document from path. A missing or empty file yields an empty *Doc (never nil) so callers can mutate and write it back.
func (*Doc) ClearDeviceField ¶ added in v0.5.0
ClearDeviceField removes one field from every per-device bucket, leaving the shared `all:` bucket and the rest of each device's state untouched.
A setter whose scope is the whole node needs it: the merge gives a per-device field precedence over `all:`, so an earlier per-device write would go on masking the node-wide value no matter how recent that value is. Doc.Reset takes the same position for an `all:` target, where it drops the per-device buckets outright.
func (*Doc) ClearField ¶ added in v0.5.0
ClearField removes one top-level field from the target's bucket, so the device falls back to its configured value. A setter that has a driver default to return to needs this: writing a zero would record a real value, and the merge has no way to express "unset".
func (*Doc) Fail ¶
Fail records a failure override for the target. mode "healthy" removes any existing failure block instead of adding one.
func (*Doc) FailureXid ¶ added in v0.4.0
FailureXid reports the Xid code device index would raise under the current overrides, or zero for a device that raises none.
The engine resolves it, rather than a rule restated here reading the raw document, because the answer has to be what the running mock raises — and that includes the mock refusing the document. The merge is a deep one, so a per-device failure block does not replace the shared block: a device singled out by a `fail` that carries no Xid keeps the one the shared bucket holds. It is also typed, so a code that is not a uint64 takes the whole override down and leaves the device as it was, raising nothing; read raw, a hand-written `code: -5` announced 2^64-5 and `79.5` announced 79, neither of which any NVML client would have seen.
func (*Doc) FanControls ¶ added in v0.5.0
func (d *Doc) FanControls(index int) (controls []engine.FanControlConfig, present bool)
FanControls reports the per-fan control state written for device index by a previous fan setter, and whether any setter has written at all.
Like WorkloadRequestedProfiles it resolves through the engine rather than reading the raw document, so the answer is what the running mock would act on — including the mock refusing a malformed document, which leaves the device with the control state its profile declares.
func (*Doc) WorkloadRequestedProfiles ¶ added in v0.5.0
WorkloadRequestedProfiles reports the profiles requested of device index by a previous setter, and whether any setter has written at all.
Like FailureXid it resolves through the engine rather than reading the raw document, so the answer is what the running mock would act on: the merge is a deep one, and a per-device request does not replace a shared `all:` one.
type MIGTx ¶ added in v0.5.0
type MIGTx struct {
// contains filtered or unexported fields
}
MIGTx is one hold of the override lock, spanning a mutation from the layout it will edit, through the change the caller makes in its own engine, to the record of that change.
The three belong under one hold because the instance id the engine assigns is drawn from the layout this document describes. Split across separate holds, two processes read the same layout, assign the same id, and the second one's record is refused as a duplicate — a creation that already happened locally, reported as a failure and then rolled back. Under one hold the second process cannot look until the first has finished writing.
Nothing is written until Commit, so a sequence that fails partway leaves the document as it was rather than a seeded layout with no delta against it.
func BeginMIG ¶ added in v0.5.0
BeginMIG takes the override lock and reads the document the mutation will edit. The document is read inside the lock, so a concurrent writer's work is never overwritten by a view loaded before it ran — the shape ResetDevice uses. The caller must Close the result.
func (*MIGTx) AddComputeInstance ¶ added in v0.5.0
func (tx *MIGTx) AddComputeInstance(giID uint32, rec engine.MIGComputeInstanceRecord) error
AddComputeInstance is MIGAddComputeInstance within a transaction.
func (*MIGTx) AddGpuInstance ¶ added in v0.5.0
func (tx *MIGTx) AddGpuInstance(rec engine.MIGGPUInstanceRecord) error
AddGpuInstance is MIGAddGpuInstance within a transaction.
func (*MIGTx) Close ¶ added in v0.5.0
func (tx *MIGTx) Close()
Close releases the lock. Uncommitted edits are discarded with it, so Close is safe to defer alongside a Commit on the success path.
func (*MIGTx) Commit ¶ added in v0.5.0
Commit writes the accumulated edits, if any changed the document.
func (*MIGTx) RemoveComputeInstance ¶ added in v0.5.0
RemoveComputeInstance is MIGRemoveComputeInstance within a transaction.
func (*MIGTx) RemoveGpuInstance ¶ added in v0.5.0
RemoveGpuInstance is MIGRemoveGpuInstance within a transaction.
func (*MIGTx) SeedLayout ¶ added in v0.5.0
func (tx *MIGTx) SeedLayout(records []engine.MIGGPUInstanceRecord) error
SeedLayout is MIGSeedLayout within a transaction. Seeding here rather than in a hold of its own is what lets the delta be taken against the layout the caller's engine actually saw.
type Target ¶
Target identifies which config override bucket a mutation applies to: the shared "all" block, or a specific device index.
func ResolveTarget ¶
ResolveTarget interprets a --gpu spec: "all", a device index, or a UUID. A numeric index is bounds-checked against cfg.NumDevices when available, so a typo like `--gpu 8` on an 8-GPU node fails loudly instead of silently writing overrides to a bucket no device ever reads.