Skip to content

[VectorDistribute] Allow duplication of operation chains#23937

Open
sommerlukas wants to merge 2 commits intoiree-org:mainfrom
sommerlukas:layout-analysis-duplicate-chains
Open

[VectorDistribute] Allow duplication of operation chains#23937
sommerlukas wants to merge 2 commits intoiree-org:mainfrom
sommerlukas:layout-analysis-duplicate-chains

Conversation

@sommerlukas
Copy link
Copy Markdown
Contributor

If a value gets assigned two different layouts, the VectorLayoutAnalysis tries to duplicate that value if it is easily duplicatable to avoid layout transformation via LDS.

So far, this duplication was limited to single operations. This PR extends this to bounded chains of easy to duplicate/recompute values.

The motivation for this change is masks. CSE will deduplicate create_mask operations. After early materialization of create_mask operations, the mask is transformed to a chain of operations:

%step = vector.step : vector<64xindex>
%limit = vector.broadcast %n : index to vector<64xindex>
%mask_1d = arith.cmpi slt, %step, %limit : vector<64xindex>
%mask = vector.broadcast %mask_1d : vector<64xi1> to vector<16x64xi1>

As the mask is used for different operations, it will receive multiple different layouts. Therefore, we would materialize these masks to LDS for layout transformation.

By allowing chains of cheap operations to be duplicated, we avoid that materialization in LDS.

This is part of #23415.

Assisted-by: Claude Code

Signed-off-by: Lukas Sommer <lukas.sommer@amd.com>
Comment on lines +487 to +488
arith::CmpIOp, arith::SelectOp, arith::ExtSIOp, arith::ExtUIOp,
arith::TruncIOp, arith::IndexCastOp>(op);
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.

use elementwise op traits. all elementwise ops are cheap.

if (isDuplicatableLeaf(op)) {
return true;
}
return op->getNumResults() == 1 && isPure(op) &&
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.

i dont think we should check if num elements == 1. Even if it isn't, these things are cheap.

Comment on lines +498 to +499
// The chain is built bottom-up (from consumer toward producers).
constexpr unsigned kMaxChainLength = 8;
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.

promote this outside the function.

Signed-off-by: Lukas Sommer <lukas.sommer@amd.com>
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