Skip to content

[xegpu][examples] Remove replace_with_fused_attention and switch to dependent reduction fusion. - #298

Merged
tkarna merged 10 commits into
llvm:mainfrom
charithaintc:linalg_reduction_fusion_integration
Oct 12, 2026
Merged

tkarna merged 10 commits into
llvm:mainfrom
charithaintc:linalg_reduction_fusion_integration

Conversation

@charithaintc

@charithaintc charithaintc commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

This PR updates xegpu schedules with fuse_dependent_reduction_ops to fuse attention-like workloads instead of relying on manual replace_with_fused_attention op.

Note that apply_attention_tiling also uses the new approach.

Depends on #297

This is a part of landing #274

Assisted by: Claude, Codex

@charithaintc
charithaintc marked this pull request as draft October 9, 2026 16:15
@charithaintc
charithaintc marked this pull request as ready for review October 9, 2026 17:48
@charithaintc
charithaintc marked this pull request as draft October 9, 2026 17:49
@charithaintc
charithaintc marked this pull request as ready for review October 9, 2026 18:10
@tkarna
tkarna requested a balanced review from Copilot October 9, 2026 20:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Fast-math annotations violate masked-infinity semantics, and the exported legacy API is removed without a compatibility period.

2 open findings
What changed in this PR

Replaces the custom fused-attention rewrite with dependent-reduction fusion across XeGPU schedules and payloads.

Changes:

  • Adds shared online-attention fusion and fast-math transforms.
  • Expresses softmax explicitly in attention payloads.
  • Updates nanoGPT and Llama schedules, including causal masking.
File Description
wg_tiling_schedule.py Uses shared attention fusion.
vectorize_schedule.py Removes dead values after vectorization.
fused_attention_schedule.py Adopts dependent-reduction fusion.
attention_fusion.py Adds shared fusion utilities.
gpu_attention_payload.py Emits explicit mixed-precision softmax.
replace_with_fused_attention.py Removes the legacy transform.
transform_ext/​__init__.py Removes the legacy API export.
nanoGPT_schedule.py Migrates attention scheduling.
nanoGPT_payload.py Emits explicit softmax reductions.
llama3.py Passes causal configuration into payload generation.
llama3_schedule.py Migrates causal GQA fusion.
llama3_payload.py Emits explicit causal attention dataflow.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +108 to +115
fast = transform.param_constant(
transform.AnyParamType.get(), ir.Attribute.parse("#arith.fastmath<fast>")
)
for op_name in ("math.exp", "arith.subf"):
unmarked = structured.structured_match(
anytype, func, ops=[op_name], op_attrs={"fastmath": no_fastmath}
)
transform.annotate(unmarked, "fastmath", param=fast)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that fast is more extreme level of fastmath. In my understanding MathToXeVM depends on both having this flag. I would revisit this later to fine tune the fastmath flags required for this case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it turns out the subf does not need the flag here. so I removed it. thanks.

Comment on lines 19 to 21
from .ops.trace_producers import trace_producers
from .ops.reverse_handles import reverse_handles
from .ops.update_address_space import update_address_space

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed PR title to avoid the confusion.

@tkarna tkarna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! Only minor comments.

Comment thread lighthouse/schedule/xegpu/attention_fusion.py Outdated
Comment thread lighthouse/schedule/xegpu/attention_fusion.py Outdated
Comment thread lighthouse/schedule/xegpu/attention_fusion.py Outdated
Comment thread lighthouse/schedule/xegpu/fused_attention_schedule.py
Comment thread lighthouse/schedule/xegpu/attention_fusion.py Outdated
@charithaintc charithaintc changed the title [xegpu][examples] Deprecate replace_with_fused_attention by using dependent reduction fusion. [xegpu][examples] Remove replace_with_fused_attention and switch to dependent reduction fusion. Oct 12, 2026
@tkarna
tkarna merged commit e116b3e into llvm:main Oct 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants