GPU Persistent State
Skill navigation
Load linked skills only when their trigger applies. Do not duplicate their full workflow here.
Core principle
Define each logical state object before choosing its physical representation. Classify growth, mutation, ownership, sharing, version lineage, retention, reconstruction, and cleanup independently.
Persistent state here means runtime state that survives across kernels, steps, requests, or sessions. It does not mean durable storage, crash recovery, transaction logging, or database consistency.
Separate semantic requirements from buffers, allocation, residency, copying, and reclamation. A physical mechanism must not silently redefine state identity, visibility, or mutation behavior.
State model and audit
Inventory every logical value that survives an invocation boundary.
| Field |
Record |
| Identity |
Semantic purpose, compatibility conditions, producer, consumers, crossed boundaries |
| Schema |
Logical dimensions, fields, size function, representation-independent invariants |
| Growth |
Growth law, bounds, zero-growth case, truncation or compaction semantics |
| Mutation |
Update rule, write set, ordering, visibility boundary, alias behavior |
| Ownership |
Owner, borrowers, sharers, mutation authority, isolation domain |
| Retention |
Required scope, optional performance retention, expiry event, cleanup precondition |
| Versioning |
Version identifier, lineage, active head, dependency epochs |
| Snapshots |
Visibility, immutability, compatibility, outstanding readers |
| Branches |
Fork version, isolation, active heads, cleanup, merge support or explicit exclusion |
| Rollback |
Target, descendant treatment, coupled state, later writes, active readers |
| Checkpoints |
Retained versions, deltas, restore compatibility, coverage, placement-independent identity |
| Reconstruction |
Inputs, exact procedure, equivalence contract, cost, workspace, verification |
| Evidence |
Source, measured or declared status, confidence, unresolved unknowns |
Record logical bytes separately from estimated physical bytes. Sharing, duplication, reserve capacity, metadata, alignment, and fragmentation belong to physical mechanisms.
Classify the mutation and growth model
Do not use one storage policy for states with different semantics.
| State model |
Required contract |
| Append-growing |
Preserve prior regions unless truncation is explicit; define append unit, growth bound, zero append, visibility, and cleanup |
| Fixed-size mutable |
Define update function, write set, overlapping writes, ordering, visibility, and version identity |
| Immutable snapshot |
Preserve the declared version after later updates; do not assume full copy or physical sharing |
| Branched lineage |
Record fork version, branch isolation, active head, branch cleanup, and merge semantics or exclusion |
| Rollback-capable |
Define head movement, coupled state, descendants, readers, and post-rollback writes |
| Sparse checkpoints |
Retain selected versions plus sufficient inputs or deltas for equivalent reconstruction |
Use explicit state equations where helpful:
append: S(t+1) = concatenate(S(t), delta(t))
mutable: S(t+1) = update(S(t), write_set(t), delta(t))
The equations describe semantics, not allocation layout.
Separate mandatory and optional retention
- Mandatory retention preserves program semantics because no equivalent reconstruction path exists within the allowed cost or correctness contract.
- Optional retention avoids future work and must compete under
gpu-state-reuse-eviction.
- Reconstructable state may be discarded only when all reconstruction dependencies remain valid and available.
- Expired state is semantically unreachable after a defined cleanup boundary.
Do not label mandatory state as an eviction candidate. Do not keep optional state indefinitely merely because it remains valid.
Define ownership and visibility
Identify one authority for mutation and one authority for cleanup. Multiple readers or replicas do not imply multiple writers.
Define when an update becomes visible and which version each concurrent consumer observes. Require ordering or snapshot semantics when readers overlap mutation.
Treat owner identity and isolation as semantic fields. Physical co-location never authorizes sharing.
Define cleanup
Specify the event that makes state semantically unreachable and the conditions that must hold before physical reclamation:
- no valid owner retains the state;
- no borrower, snapshot, branch, callback, or in-flight consumer can access it;
- required descendants or rollback targets have been handled;
- pending movement and reconstruction actions have completed or been cancelled.
Delegate exact reclamation timing to lifetime planning and memory scheduling.
Decision workflow
- Inventory every cross-call state object.
- Classify each object by growth, mutation, ownership, and version model.
- Split mixed objects or declare explicit phase transitions.
- Define identity, compatibility, visibility, lineage, retention, reconstruction, and cleanup invariants.
- Enumerate feasible logical policies: retain current state, retain selected versions, reconstruct, or combine checkpoints with deltas.
- Reject policies that violate snapshots, branch isolation, rollback, cleanup, or reconstruction equivalence.
- Compare remaining policies with evidence-backed memory and runtime costs.
- Keep unknown terms explicit and name the measurement that resolves them.
- Hand generic admission and victim ranking to reuse/eviction.
- Hand physical lifetime, backing, placement, movement, and timing to their specialists.
- Validate state transitions and repeated cleanup before accepting the design.
Design snapshots and branches
Define snapshots by logical version and visibility. Do not require a full copy unless the semantic or physical cost model chooses one.
For a branch, record:
- parent version and branch identifier;
- shared immutable ancestry;
- branch-local mutation authority;
- whether sibling writes are invisible;
- cleanup and descendant behavior;
- merge semantics or an explicit statement that merge is unsupported.
For rollback, specify whether descendants become invalid, remain readable snapshots, or move to a detached lineage. Update every coupled state object atomically under the declared contract.
Design sparse checkpoints
For checkpoint set Q and target version t, estimate equivalent reconstruction:
R_Q(t) = min over compatible q in Q, q <= t:
seed_cost(q)
+ sum_{j=q+1..t} apply_cost(j)
+ verify_cost(t)
Do not assume the nearest checkpoint is cheapest. Compatibility, delta availability, movement, and workspace can change the result.
Do not describe runtime checkpoints as durable or crash-recoverable.
Cost model
Compute logical live bytes:
B_logical(t) = sum_{v in logically_live(t)} size(v, t)
Do not infer physical bytes from this expression.
Compare feasible policies P using the declared objective:
cost(P) = w_memory * peak_logical_bytes(P)
+ w_update * E[update_cost(P)]
+ w_reconstruct * E[reconstruction_cost(P)]
+ w_cleanup * E[cleanup_cost(P)]
+ w_latency * E[latency_effect(P)]
Derive weights from the user's objective. If priorities are absent, return Pareto alternatives instead of inventing weights.
Include version metadata, snapshot maintenance, branch divergence, checkpoint creation, reconstruction workspace, and cleanup tails when material.
Retain optional state only when expected avoided reconstruction exceeds holding, maintenance, and cleanup costs under uncertainty.
Specialist handoffs
| This skill defines |
Handoff |
| Logical values, versions, lineage, visibility, ownership, and permitted sharing |
gpu-virtual-memory-fragmentation chooses physical backing and addresses; gpu-memory-scheduling orders copies and synchronization |
| Mandatory and permitted retention |
gpu-state-reuse-eviction chooses admission, ranking, and logical eviction |
| Semantic expiry and cleanup precondition |
gpu-resource-lifetime-allocation and gpu-memory-scheduling reclaim safely |
| Growth requires virtual reservation, segmented backing, page granularity, or compaction |
gpu-virtual-memory-fragmentation chooses the physical backing mechanism |
| Valid reconstruction and discardability |
gpu-memory-tiering-migration chooses placement and movement |
| Cost terms and missing evidence |
gpu-performance-evidence measures them |
| Invariants and edge cases |
gpu-optimization-validation performs acceptance |
Do not let downstream physical choices mutate the state contract without returning for reclassification.
Failure modes and counterexamples
- Append-growing state has no bound, quota, termination rule, or explicit risk decision.
- Reserved capacity is mistaken for logical state size.
- A fixed-size object hides an expanding version history.
- Mutable aliases violate an immutable snapshot.
- A branch update becomes visible to a sibling.
- Rollback moves one head but leaves coupled state inconsistent.
- Reconstruction omits a dependency, delta, ordering rule, or compatibility check.
- A checkpoint cannot restore the claimed target version.
- Cleanup runs while a reader, branch, or movement remains active.
- Cleanup never runs after the final owner releases state.
- Logical sharing is counted as physical savings without evidence.
- Mandatory state becomes evictable without an equivalent reconstruction path.
- A runtime checkpoint is claimed to provide durability or crash recovery.
- One paging, growth, snapshot, or checkpoint policy is applied to every state model.
- A performance claim relies only on design inspection.
State contract record
Record:
- state purpose and crossed runtime boundaries;
- identity, compatibility, schema, and size function;
- growth law, bounds, and phase transitions;
- mutation model, write order, and visibility;
- owner, mutation authority, isolation, and sharing rules;
- required and optional retention scopes;
- expiry event and cleanup precondition;
- version lineage and active head;
- snapshot, branch, merge, and rollback rules;
- checkpoint set and reconstruction contract;
- reconstruction equivalence, cost, workspace, and validation;
- logical costs and clearly labeled physical assumptions;
- evidence, confidence, unknowns, and falsifiers;
- selected policy, rejected alternatives, and specialist handoffs.
Acceptance gate
Keep a persistent-state design only when:
- every cross-call object has an explicit state contract;
- every growth law has a bound or an explicit unbounded-growth decision;
- mutation visibility, ownership, and isolation are unambiguous;
- snapshots remain immutable under later writes;
- branches isolate writes as declared;
- rollback covers coupled state and descendants;
- sparse checkpoints reconstruct every promised target equivalently;
- cleanup is safe under repeated invocation and outstanding sharers;
- mandatory and optional retention remain distinct;
- logical and physical costs remain distinct;
- unknowns produce experiments, not default mechanisms;
- no generic eviction algorithm is embedded here;
- durable storage, crash recovery, and database consistency remain out of scope;
- all unresolved physical choices have named handoffs and validation evidence.
1---2name: gpu-persistent-state3description: Load this skill and follow it when designing runtime GPU state that survives across kernels, steps, requests, or sessions, especially when growth, mutation, snapshots, branching, checkpoint placement, ownership, or reconstruction semantics differ across state objects.4---56# GPU Persistent State78## Skill navigation910- Parent router: [gpu-code-optimizer](../gpu-code-optimizer/SKILL.md)11- Evidence: [gpu-performance-evidence](../gpu-performance-evidence/SKILL.md)12- Logical retention: [gpu-state-reuse-eviction](../gpu-state-reuse-eviction/SKILL.md)13- Lifetime planning: [gpu-resource-lifetime-allocation](../gpu-resource-lifetime-allocation/SKILL.md)14- Physical backing: [gpu-virtual-memory-fragmentation](../gpu-virtual-memory-fragmentation/SKILL.md)15- Placement: [gpu-memory-tiering-migration](../gpu-memory-tiering-migration/SKILL.md)16- Ordering: [gpu-memory-scheduling](../gpu-memory-scheduling/SKILL.md)17- Validation: [gpu-optimization-validation](../gpu-optimization-validation/SKILL.md)1819Load linked skills only when their trigger applies. Do not duplicate their full workflow here.2021## Core principle2223Define each logical state object before choosing its physical representation. Classify growth, mutation, ownership, sharing, version lineage, retention, reconstruction, and cleanup independently.2425Persistent state here means runtime state that survives across kernels, steps, requests, or sessions. It does not mean durable storage, crash recovery, transaction logging, or database consistency.2627Separate semantic requirements from buffers, allocation, residency, copying, and reclamation. A physical mechanism must not silently redefine state identity, visibility, or mutation behavior.2829## State model and audit3031Inventory every logical value that survives an invocation boundary.3233| Field | Record |34|---|---|35| Identity | Semantic purpose, compatibility conditions, producer, consumers, crossed boundaries |36| Schema | Logical dimensions, fields, size function, representation-independent invariants |37| Growth | Growth law, bounds, zero-growth case, truncation or compaction semantics |38| Mutation | Update rule, write set, ordering, visibility boundary, alias behavior |39| Ownership | Owner, borrowers, sharers, mutation authority, isolation domain |40| Retention | Required scope, optional performance retention, expiry event, cleanup precondition |41| Versioning | Version identifier, lineage, active head, dependency epochs |42| Snapshots | Visibility, immutability, compatibility, outstanding readers |43| Branches | Fork version, isolation, active heads, cleanup, merge support or explicit exclusion |44| Rollback | Target, descendant treatment, coupled state, later writes, active readers |45| Checkpoints | Retained versions, deltas, restore compatibility, coverage, placement-independent identity |46| Reconstruction | Inputs, exact procedure, equivalence contract, cost, workspace, verification |47| Evidence | Source, measured or declared status, confidence, unresolved unknowns |4849Record logical bytes separately from estimated physical bytes. Sharing, duplication, reserve capacity, metadata, alignment, and fragmentation belong to physical mechanisms.5051### Classify the mutation and growth model5253Do not use one storage policy for states with different semantics.5455| State model | Required contract |56|---|---|57| Append-growing | Preserve prior regions unless truncation is explicit; define append unit, growth bound, zero append, visibility, and cleanup |58| Fixed-size mutable | Define update function, write set, overlapping writes, ordering, visibility, and version identity |59| Immutable snapshot | Preserve the declared version after later updates; do not assume full copy or physical sharing |60| Branched lineage | Record fork version, branch isolation, active head, branch cleanup, and merge semantics or exclusion |61| Rollback-capable | Define head movement, coupled state, descendants, readers, and post-rollback writes |62| Sparse checkpoints | Retain selected versions plus sufficient inputs or deltas for equivalent reconstruction |6364Use explicit state equations where helpful:6566```text67append: S(t+1) = concatenate(S(t), delta(t))68mutable: S(t+1) = update(S(t), write_set(t), delta(t))69```7071The equations describe semantics, not allocation layout.7273### Separate mandatory and optional retention7475- **Mandatory retention** preserves program semantics because no equivalent reconstruction path exists within the allowed cost or correctness contract.76- **Optional retention** avoids future work and must compete under `gpu-state-reuse-eviction`.77- **Reconstructable state** may be discarded only when all reconstruction dependencies remain valid and available.78- **Expired state** is semantically unreachable after a defined cleanup boundary.7980Do not label mandatory state as an eviction candidate. Do not keep optional state indefinitely merely because it remains valid.8182### Define ownership and visibility8384Identify one authority for mutation and one authority for cleanup. Multiple readers or replicas do not imply multiple writers.8586Define when an update becomes visible and which version each concurrent consumer observes. Require ordering or snapshot semantics when readers overlap mutation.8788Treat owner identity and isolation as semantic fields. Physical co-location never authorizes sharing.8990### Define cleanup9192Specify the event that makes state semantically unreachable and the conditions that must hold before physical reclamation:9394- no valid owner retains the state;95- no borrower, snapshot, branch, callback, or in-flight consumer can access it;96- required descendants or rollback targets have been handled;97- pending movement and reconstruction actions have completed or been cancelled.9899Delegate exact reclamation timing to lifetime planning and memory scheduling.100101## Decision workflow1021031. Inventory every cross-call state object.1042. Classify each object by growth, mutation, ownership, and version model.1053. Split mixed objects or declare explicit phase transitions.1064. Define identity, compatibility, visibility, lineage, retention, reconstruction, and cleanup invariants.1075. Enumerate feasible logical policies: retain current state, retain selected versions, reconstruct, or combine checkpoints with deltas.1086. Reject policies that violate snapshots, branch isolation, rollback, cleanup, or reconstruction equivalence.1097. Compare remaining policies with evidence-backed memory and runtime costs.1108. Keep unknown terms explicit and name the measurement that resolves them.1119. Hand generic admission and victim ranking to reuse/eviction.11210. Hand physical lifetime, backing, placement, movement, and timing to their specialists.11311. Validate state transitions and repeated cleanup before accepting the design.114115### Design snapshots and branches116117Define snapshots by logical version and visibility. Do not require a full copy unless the semantic or physical cost model chooses one.118119For a branch, record:120121- parent version and branch identifier;122- shared immutable ancestry;123- branch-local mutation authority;124- whether sibling writes are invisible;125- cleanup and descendant behavior;126- merge semantics or an explicit statement that merge is unsupported.127128For rollback, specify whether descendants become invalid, remain readable snapshots, or move to a detached lineage. Update every coupled state object atomically under the declared contract.129130### Design sparse checkpoints131132For checkpoint set `Q` and target version `t`, estimate equivalent reconstruction:133134```text135R_Q(t) = min over compatible q in Q, q <= t:136 seed_cost(q)137 + sum_{j=q+1..t} apply_cost(j)138 + verify_cost(t)139```140141Do not assume the nearest checkpoint is cheapest. Compatibility, delta availability, movement, and workspace can change the result.142143Do not describe runtime checkpoints as durable or crash-recoverable.144145## Cost model146147Compute logical live bytes:148149```text150B_logical(t) = sum_{v in logically_live(t)} size(v, t)151```152153Do not infer physical bytes from this expression.154155Compare feasible policies `P` using the declared objective:156157```text158cost(P) = w_memory * peak_logical_bytes(P)159 + w_update * E[update_cost(P)]160 + w_reconstruct * E[reconstruction_cost(P)]161 + w_cleanup * E[cleanup_cost(P)]162 + w_latency * E[latency_effect(P)]163```164165Derive weights from the user's objective. If priorities are absent, return Pareto alternatives instead of inventing weights.166167Include version metadata, snapshot maintenance, branch divergence, checkpoint creation, reconstruction workspace, and cleanup tails when material.168169Retain optional state only when expected avoided reconstruction exceeds holding, maintenance, and cleanup costs under uncertainty.170171## Specialist handoffs172173| This skill defines | Handoff |174|---|---|175| Logical values, versions, lineage, visibility, ownership, and permitted sharing | `gpu-virtual-memory-fragmentation` chooses physical backing and addresses; `gpu-memory-scheduling` orders copies and synchronization |176| Mandatory and permitted retention | `gpu-state-reuse-eviction` chooses admission, ranking, and logical eviction |177| Semantic expiry and cleanup precondition | `gpu-resource-lifetime-allocation` and `gpu-memory-scheduling` reclaim safely |178| Growth requires virtual reservation, segmented backing, page granularity, or compaction | `gpu-virtual-memory-fragmentation` chooses the physical backing mechanism |179| Valid reconstruction and discardability | `gpu-memory-tiering-migration` chooses placement and movement |180| Cost terms and missing evidence | `gpu-performance-evidence` measures them |181| Invariants and edge cases | `gpu-optimization-validation` performs acceptance |182183Do not let downstream physical choices mutate the state contract without returning for reclassification.184185## Failure modes and counterexamples186187- Append-growing state has no bound, quota, termination rule, or explicit risk decision.188- Reserved capacity is mistaken for logical state size.189- A fixed-size object hides an expanding version history.190- Mutable aliases violate an immutable snapshot.191- A branch update becomes visible to a sibling.192- Rollback moves one head but leaves coupled state inconsistent.193- Reconstruction omits a dependency, delta, ordering rule, or compatibility check.194- A checkpoint cannot restore the claimed target version.195- Cleanup runs while a reader, branch, or movement remains active.196- Cleanup never runs after the final owner releases state.197- Logical sharing is counted as physical savings without evidence.198- Mandatory state becomes evictable without an equivalent reconstruction path.199- A runtime checkpoint is claimed to provide durability or crash recovery.200- One paging, growth, snapshot, or checkpoint policy is applied to every state model.201- A performance claim relies only on design inspection.202203## State contract record204205Record:206207- state purpose and crossed runtime boundaries;208- identity, compatibility, schema, and size function;209- growth law, bounds, and phase transitions;210- mutation model, write order, and visibility;211- owner, mutation authority, isolation, and sharing rules;212- required and optional retention scopes;213- expiry event and cleanup precondition;214- version lineage and active head;215- snapshot, branch, merge, and rollback rules;216- checkpoint set and reconstruction contract;217- reconstruction equivalence, cost, workspace, and validation;218- logical costs and clearly labeled physical assumptions;219- evidence, confidence, unknowns, and falsifiers;220- selected policy, rejected alternatives, and specialist handoffs.221222## Acceptance gate223224Keep a persistent-state design only when:225226- every cross-call object has an explicit state contract;227- every growth law has a bound or an explicit unbounded-growth decision;228- mutation visibility, ownership, and isolation are unambiguous;229- snapshots remain immutable under later writes;230- branches isolate writes as declared;231- rollback covers coupled state and descendants;232- sparse checkpoints reconstruct every promised target equivalently;233- cleanup is safe under repeated invocation and outstanding sharers;234- mandatory and optional retention remain distinct;235- logical and physical costs remain distinct;236- unknowns produce experiments, not default mechanisms;237- no generic eviction algorithm is embedded here;238- durable storage, crash recovery, and database consistency remain out of scope;239- all unresolved physical choices have named handoffs and validation evidence.