Merge supported AIR launches
Use when measured dispatch/host handoffs motivate merging and the selected backend supports the composition. This recipe reduces invocation boundaries; it does not by itself establish persistent megakernel residency or progress. Read current helpers and one matching builder from project integration.
- List the actual consecutive kernels, their interfaces, numerical order, host work and state boundaries. Mark unsupported launch/control patterns and data-dependent host decisions. Choose a small group with a real removable boundary. Historical FA-separate groups are worked implementation choices, not a prohibition on every attention fusion.
- Generate/read each sub-kernel's IR with the selected builder. Current worked builders use
shared.infra.stitchingAPIsFuncArg,KernelSliceandstitch_elf; inspectshared/builders/rms_gemms_rope_multi.py,o_ffn_multi.pyoro_gemv_ffn_multi.pyfor the matching composition. - Declare the combined ABI with
FuncArg, then orderedKernelSliceobjects with uniqueprefixandarg_mapmapping launch operands to combined arguments. Usearg_aliasesonly for valid SSA views declared inprelude; include required scratch arguments.stitch_elfextracts/renames/remaps through helpers such as_rename_all_with_externsand_fix_launch_func_args, preserving channel/private declarations. Keep its dangling-argument checks; allow an unreferenced ABI slot only when intentionally retained and explained. Inspect emitted IR, layouts and output/state slots; parser checks do not establish semantic wiring. - If the chosen sub-kernel emits a bare
air.herdbut the lowering requires launch/segment structure, apply_wrap_ir_in_launchbefore stitching. Confirm the path survives lowering. This wrapper requirement belongs to that implementation, not to all AIR programs. - Identify which external symbols must be shared and which shape-specialized objects require distinct names.
KernelSlice.extern_symsand_rename_all_with_externs(..., extern_funcs)list symbols preserved from prefix renaming;stitch_elfpreserves their union. The currento_gemv_ffn_multi.pydeliberately sharesmv_bf16.osymbols across stages 1 and 3, not the old two-K rename example. If two object implementations need distinct shape-specific symbols, coordinate their compile symbol names, declarations and call sites before adding them to the preserved set. Do not assign an incompatible object to another launch. - Compile through the actual
KernelCache.compile_and_cacheor task build interface, preserving the final source/configuration/retained IR/artifact binding. Multi-launch debug handles source/lowering/resource failures. - Run the same operations unmerged and merged at matching input/state. Use the applicable exact output/state comparison if arithmetic and representation are preserved; otherwise the frozen calibrated gate. Inspect repeats, intermediate ownership and output readback as well as first output. Rerun required production gates.
- Verify the production runtime actually loads the merged artifact and reduces the intended invocation/host handoff count. Compare complete target time, compilation cost separately and measurement uncertainty. No fixed dispatch cost or expected percentage is promised.
On a mismatch, undo or isolate the most recent merge boundary to test symbol/argument/layout/scheduling hypotheses; this is localization evidence, not automatically a unique cause. On resource pressure or no net benefit, smaller groups or separate dispatches remain valid options. Return applied/skipped/reverted with coupled changes, gates and timing to Optimization.