Opt buffer object reuse

From Xilinx/mlir-air · View interactive version

Opt buffer object reuse is an AI agent skill from the GitHub repository Xilinx/mlir-air. Reduce redundant NPU host allocation and transfers when BO input generations, device overwrite coverage and lifetimes permit reuse; validate first-use, repeat and state behavior.

How to use this skill

Skill file

Reuse BOs conditionally

Use when Optimization observes repeated allocation/upload or host handoff. Identify the actual runtime first: the inspected AIR KernelCache is in llms/shared/infra/cache.py; other megakernels may use another ABI. Read project integration and the current implementation before selecting slot options.

Classify slots by value and lifetime

| Slot | Requirement before skipping a host transfer |

|---|---|

| Weight or LUT | Contents are invariant for this BO identity across calls; correct generation has actually been uploaded |

| Kernel output/scratch | Every subsequently read element is initialized by the device before that read; preserved prefix/tail/state is accounted for |

| Changing activation/position/state | Upload or supply the new generation through the actual producer; shape equality is not invariance |

| Shared producer-output/consumer-input | Producer completion, exact layout/size, consumer read interval and final reader permit aliasing |

Build the slot map from the generated function signature and runtime binding, not an old argument list. Per-layer weights need distinct keys/generations; varying shape/precision/artifact also requires a compatible BO set. Do not assume a cached key resizes itself.

Current AIR mechanics

Keep changed activations dynamic, preserve state not wholly overwritten, and check all shared consumers/async completion before extending the sequential-use assumptions. Skipping writes is not a generic corruption remedy.

A host-only BO change can reuse unchanged NPU compilation with the dependency and ABI evidence recorded; a Python builder or changed binary is not covered by that assumption. BO identity, initialization, layer/weight generation, aliases and dynamic supply still invalidate affected runtime evidence. Apply the relevant kernel/full-model gate. Probe first use, repeated calls, changed inputs/layers and reset/carry transitions when needed for diagnosis or an explicit task/interface requirement. Use BO debug on stale/alias failures. Measure actual host and full-call time against the valid baseline; fewer transfers need not improve the target. Return applied/skipped/reverted, identities, coverage and comparable timing to Optimization.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.