Megakernel change analysis

From Xilinx/mlir-air · View interactive version

Megakernel change analysis is an AI agent skill from the GitHub repository Xilinx/mlir-air. Trace which computation, data ownership, lifetime, layout, and supply assumptions change when adapting a spatial NPU megakernel to a new model, shape, execution mode, mapping, or toolchain. Use to select affected objects and validation scope before edits or after a structural change.

How to use this skill

Skill file

Analyze a megakernel change

As part of the megakernel module, produce a source-grounded impact analysis and the next useful check for adaptation, validation or an optimization candidate. Start with the task's seed identity, old/new requirement, allowed edits, fixed acceptance gates, and budget. If already supplied, reuse them. The workflow distinguishes new deployment, valid-seed adaptation, optimization, and recovery; do not reset a valid seed to an unnecessary full deployment.

Find relationships in unfamiliar source

Locate the actual runtime call and its configuration/build entrypoint first. Follow one changed value through its producer, packing/conversion, transfer, storage, and consumer; inspect generated IR or retained artifacts when source cannot settle a question. Search by a called symbol, argument, shape expression, or buffer use rather than assuming file names or tile coordinates.

For each affected relationship, record only what matters:

Bind conclusions to source locations and version/artifact identity. Label facts as extracted, derived, declared, or unknown. Stop tracing unaffected regions once their boundary assumptions and reused evidence are justified; expand across aliases and shared state when those assumptions change.

Decide what must change or be checked

| Change observed | Follow the dependency | Next evidence |

|---|---|---|

| Dimension, partition or layout | Producer framing → packing → consumer indices → transfer addresses/slot phase | Compare symbolic element identity at boundaries, including tail and transition cases; check compiled transfer organization if unresolved |

| Batch, overlap or owner | Concurrent live data, last-use, fill/invalidation, fanout and backpressure | Residency and supply, then the affected resource/protocol evidence |

| Repeated computation is exposed | Input/parameter/state invariance and number of consumers | Reuse or recompute; retain recomputation as a candidate |

| Arithmetic or execution semantics | Reference path, reduction/rounding, mask/position and state updates | Correctness diagnosis; identify existing gate applicability before choosing new tests |

| Device, toolchain or runtime changes | Resource facts, lowering assumptions, artifact/ABI binding | Resource diagnosis; separate hardware facts from version-specific restrictions/workarounds |

Return the coupled edit/check set, still-applicable seed evidence, invalidated evidence, and earliest validation stage needed. If a source pattern is unsupported, state the missing relationship and the file/artifact or observation needed to resolve it; a checker abstention is not PASS. Existing tools and their limits are in tools and evidence.

Use the shared task record only if helpful: observation; hypotheses/evidence; affected objects; candidates/coupled edits; next evidence and expected discrimination; unknowns/acceptance. Do not prescribe an optimization merely because a historical case had a similar shape.

For the AIR Q4NX fused path, read fused-decode compatibility when changing compiler flags, packed weights, instruction templates, or KV ownership. Its source-specific constraints and example complement this skill; they do not choose a new model's implementation.

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.