feat(vmi): VMIPredicateFold — DCE compile-time expert-pad vcmp/vsel - #581
Open
peanutchan wants to merge 1 commit into
Open
feat(vmi): VMIPredicateFold — DCE compile-time expert-pad vcmp/vsel#581peanutchan wants to merge 1 commit into
peanutchan wants to merge 1 commit into
Conversation
Fold statically proven all-true/all-false vcmp into identity vsel and DCE dead pad work so frontends can always emit expert-pad masking when E is compile-time known (see mouliangyu#580). Co-authored-by: Cursor <cursoragent@cursor.com>
4 tasks
Collaborator
Author
|
Superseded for upstream by hw-native-sys#1151 against |
4 tasks
Collaborator
Author
|
Follow-up generalization (R1–R6 + R4 neutral reduce skip + camodel report) landed on main-based branch:
This |
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.
Summary
VMIPredicateFold(-vmi-predicate-fold) to constant-prove VMI index ranges and fold identity expert-padvcmp_lt+vselbefore unified→legacy lowering.VMIMaskUtils(isAllActiveSeed/isAllInactiveSeed) used by this pass andVMILowerUnifiedToLegacy.topk_gate) to always emit pad masking and drop hand-codedneed_padwhennum_expertsis compile-time known.Closes #580.
Motivation
Padding after VL-aligned
vci/vaddsis a common MoE pattern:When the compare is provably all-true, this is dead work. Hand-gating with
need_pad = (E != aligned_E)misses non-tail chunks and duplicates policy in every kernel.Design
VMILowerUnifiedToLegacyvci,vadds(vci,C),vbrc(C), affineiv*stride+C+ knownscf.forboundsvcmp→ lattice; identity / constantvsel; pure-op DCE--disable-vmi-predicate-fold(PTO_FLAGS)Lit:
test/lit/vmi_new/vmi_predicate_fold_pad.pto.Performance (camodel 950PR, N=4, pad always-on, fold OFF vs ON)
Identity-pad cases match the old hand-
need_pad=Falserooftop after fold; E≪VL correctly keeps pad.Test plan
pto-test-opt test/lit/vmi_new/vmi_predicate_fold_pad.pto -vmi-predicate-fold | FileCheckPTO_FLAGS=--disable-vmi-predicate-foldfor E=16/64/384num_expertsdoes not fold (lit case)Made with Cursor