Apple Target IR fusion descriptors — emit + consume (Decision #19) - #63
Merged
Merged
Conversation
… slice 1) The Apple Target IR fusion passes re-discover the matmul→softmax[→matmul] / matmul→gelu / ... chains the canonical compile already recognized (COMPILER_AUDIT "fusion intent is too late"). This lands the flagship slice that makes the fusion decision first-class in Target IR. MatmulSoftmaxMatmulFusionToAppleGPU.cpp now: - EMITS the descriptor on the fused call — tessera.fusion.kernel = "matmul_softmax_matmul" + tessera.fusion.source = "descriptor" | "rediscovered" — so the fusion decision (which kernel, and whether the compiler's intent drove it vs. structural re-discovery) is auditable in the IR (Decision #19). - CONSUMES an upstream tessera.fusion.intent on the tail op: when present the fusion is descriptor-driven (source="descriptor"); absent it, the structural walk re-discovers it (source="rediscovered", back-compat). Both fuse to the same kernel. - On a descriptor/IR disagreement (intent set but structure doesn't match) emits a Decision-#21 warning naming the op instead of silently falling back. Built clean; full tessera-ir lit 119 pass / 0 fail (existing fusion fixtures unaffected by the new call attrs). Tests: tests/tessera-ir/phase8/apple_gpu_fusion_descriptor.mlir (lit) + tests/unit/test_apple_fusion_descriptor.py (2). test_coverage regenerated; COMPILER_AUDIT updated. Follow-on: same template for the other 6 Apple fusion passes + a Python emitter stamping tessera.fusion.intent from the canonical _KNOWN_FUSION_CHAINS. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Completes the Decision #19 follow-on started in the flagship slice. C++ (Tile→Apple fusion passes): - 3 more chain passes (matmul→softmax, matmul→gelu, matmul→rmsnorm) now consume an upstream tessera.fusion.intent (source="descriptor") and fall back to structural re-discovery (source="rediscovered"), with a Decision-#21 warning on descriptor/IR disagreement — same template as matmul→softmax→matmul. - 3 composite passes (swiglu / mla_decode / native_sparse_attn) emit the descriptor with source="composite_op" (they lower a pre-fused op, which is itself the descriptor — no chain re-discovery). All 7 fused calls now carry tessera.fusion.kernel + tessera.fusion.source, so the fusion decision is first-class/auditable in Target IR. Python (emit-half): - canonical_compile.stamp_fusion_intents(module) tags the terminal op of each recognized linear chain with tessera.fusion.intent (from the canonical _KNOWN_FUSION_CHAINS), so the frontend produces descriptor-annotated IR that the C++ passes consume. Idempotent. Built clean; full tessera-ir lit 119 pass / 0 fail. Tests: tests/tessera-ir/phase8/apple_gpu_fusion_descriptor.mlir (extended to gelu + rmsnorm) and tests/unit/test_fusion_intent_emitter.py (6, incl. an emit↔consume contract guard tying the Python intents to the C++ consumers). mypy clean. COMPILER_AUDIT updated. Remaining: auto-wire stamp_fusion_intents into a Target-IR lowering path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Closes the Decision #19 loop end-to-end: the frontend now auto-produces descriptor-annotated Graph IR for Apple targets, which the Target IR fusion passes consume (source="descriptor"). - driver.compile_graph_module calls stamp_fusion_intents(module) before rendering the Graph IR, gated to apple_gpu / apple_cpu (the only Target IR consumers today; the descriptor is backend-agnostic, extends when others consume it). Lazy import avoids the canonical_compile ↔ driver cycle. - Fix: stamp the intent into the op's MLIR `attrs` field, NOT `kwargs`. kwargs are forwarded as the op's real call arguments in the reference/runtime execution path, so a descriptor there leaked into the numpy op call (gelu(**kwargs) got an unexpected 'tessera.fusion.intent'). attrs renders only into the MLIR text the C++ passes read. Verified: apple_gpu/apple_cpu compiles carry tessera.fusion.intent on chain terminals; cpu is gated (unstamped); the previously-broken apple_cpu transformer execution test passes; 116 apple/canonical/strict-dispatch tests green; mypy clean; drift in sync. emitter tests updated to assert via attrs + that the intent never leaks into kwargs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the COMPILER_AUDIT "fusion intent is too late" item for the Apple backend: the Target IR fusion passes re-discovered the same
matmul→softmax[→matmul]/matmul→gelu/matmul→rmsnorm/ swiglu chains the canonical compile already computes (and the runtime already consumes viafusion_groups). This makes the fusion decision first-class in Target IR (Decision #19, "emit backend descriptors").C++ — all 7 Apple fusion passes emit a descriptor
Each fused call now carries
tessera.fusion.kernel+tessera.fusion.source:tessera.fusion.intent→source="descriptor"; absent it, structural re-discovery →source="rediscovered", with a Decision-Apple GPU Tier-3: conv2d via MPSGraph convolution2D #21 warning on descriptor/IR disagreement.source="composite_op"— they lower a pre-fused op (the op is the descriptor).Python — the emit-half
canonical_compile.stamp_fusion_intents(module)stampstessera.fusion.intenton each recognized chain's terminal op (from the canonical_KNOWN_FUSION_CHAINS), so the frontend produces descriptor-annotated IR. Idempotent. An emit↔consume contract test ties the Python intents to the C++ consumers so the halves can't drift.Verification
Rebuilt clean; full tessera-ir lit 119 pass / 0 fail; new lit fixture (descriptor + rediscovered across softmax/gelu/rmsnorm) +
test_apple_fusion_descriptor.py+test_fusion_intent_emitter.pygreen; mypy clean; drift gate in sync.🤖 Generated with Claude Code