Recompute IR flags from efunc when the rewriter changes opcodes.#211
Merged
Conversation
Contributor
Based on the current README it seems it's already roughly +8-9% over cuTile Python, at 46.9 TFLOPS. Is this patching a regression since then, or timing noise? |
Member
Author
Yeah that's wrong; it doesn't by itself improve performance, but unlocks additional rewrites I'm going to push in a next PR. The goal is to enable vectorization for the MoE example, which is missing right now (and will improve performance of that example). |
The `canonicalize!` pass rewrites `Core.Intrinsics.*` to cuTile's `Intrinsics.*` (`sub_int → subi`, etc.). The rewrite driver previously cleared `IR_FLAG_EFFECT_FREE` on opcode change because the inferred flag described the OLD op. Without the flag, downstream CSE and LICM gate-fail on every rewritten call. Plumb effect propagation through the rewriter itself: when the driver changes an opcode or inserts a new sub-call, recompute the IR flags from the new func's declared effects, mirroring inference's `flags_for_effects`. The single source of truth for per-intrinsic effects is the `efunc(...)` overrides — the same hooks that adjust inference results during method-instance compilation (e.g., RNG ops setting `effect_free=ALWAYS_FALSE`). No parallel impurity list to maintain; no post-hoc walk over the SCI. The new `inferred_flags(func)` helper lives next to `classify_memory_op` in `analysis/effects.jl`. It's wired into the three sites that produce new instructions: the substitution and inplace branches of `apply_rewrite!`, the `resolve_rhs` insertion of synthetic sub-calls, and the imperative `commute_arith_transparent` rewriter. Concrete IR impact on the matmul inner loop: 7 → 4 surviving `subi(token_id, 1)` after CSE, and LICM hoists invariant cmpi/bcast/ reshape out of the k-loop.
Contributor
|
Neat! |
fb0756a to
b77d031
Compare
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.
The
canonicalize!pass rewritesCore.Intrinsics.*to cuTile'sIntrinsics.*(sub_int → subi, etc.). The rewrite driver previously clearedIR_FLAG_EFFECT_FREEon opcode change because the inferred flag described the OLD op. Without the flag, downstream CSE and LICM gate-fail on every rewritten call.Plumb effect propagation through the rewriter itself: when the driver changes an opcode or inserts a new sub-call, recompute the IR flags from the new func's declared effects, mirroring inference's
flags_for_effects. The single source of truth for per-intrinsic effects is theefunc(...)overrides — the same hooks that adjust inference results during method-instance compilation (e.g., RNG ops settingeffect_free=ALWAYS_FALSE). No parallel impurity list to maintain; no post-hoc walk over the SCI.The new
inferred_flags(func)helper lives next toclassify_memory_opinanalysis/effects.jl. It's wired into the three sites that produce new instructions: the substitution and inplace branches ofapply_rewrite!, theresolve_rhsinsertion of synthetic sub-calls, and the imperativecommute_arith_transparentrewriter.Concrete IR impact on the matmul inner loop: 7 → 4 surviving
subi(token_id, 1)after CSE, and LICM hoists invariant cmpi/bcast/ reshape out of the k-loop.matmul moves from 43.4 → 47.5 TFLOPS (+9.4% over cuTile Python).