Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VectorDistribution] Add layout analysis for distributing multi-dim reduction (2/4) #18800

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

bangtianliu
Copy link
Contributor

@bangtianliu bangtianliu commented Oct 16, 2024

Splitting #18519 into four patches.

Depends #18784

This is the second one, adding the corresponding layout analysis and especially supporting the case where reduction is performed inside scf.for operation.

Also, the relevant tests are added.

Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
…pport for the case when the reduction is inside scf.for operation

Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
@bangtianliu bangtianliu changed the title [VectorDistribution] PATCH 2: add scalar support for distributing multi-dim reduction (2/3) [VectorDistribution] PATCH 2: add layout analysis for distributing multi-dim reduction (2/3) Oct 16, 2024
Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
@bangtianliu bangtianliu changed the title [VectorDistribution] PATCH 2: add layout analysis for distributing multi-dim reduction (2/3) [VectorDistribution] add layout analysis for distributing multi-dim reduction (2/3) Oct 16, 2024
@bangtianliu bangtianliu changed the title [VectorDistribution] add layout analysis for distributing multi-dim reduction (2/3) [VectorDistribution] Add layout analysis for distributing multi-dim reduction (2/3) Oct 17, 2024
Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
@bangtianliu bangtianliu changed the title [VectorDistribution] Add layout analysis for distributing multi-dim reduction (2/3) [VectorDistribution] Add layout analysis for distributing multi-dim reduction (2/4) Oct 17, 2024
Comment on lines +110 to +112
// Returns a boolean flag indicating whether the input value 'val' is a
// vector, determined by checking its rank.
bool isVector(VectorValue val);
Copy link
Member

Choose a reason for hiding this comment

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

This strikes me as an odd helper: you give 'vector' a new meaning without introducing a name. Instead, I'd either flip it and add a helper like isRank0(VectorValue val), or just expand the check where you need it.

Comment on lines +215 to +219
bool isVector(VectorValue val) {
if (val.getType().getRank() != 0)
return true;
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bool isVector(VectorValue val) {
if (val.getType().getRank() != 0)
return true;
return false;
}
bool isVector(VectorValue val) {
return val.getType().getRank() != 0;
}

Comment on lines +1057 to +1063
// Result lattice not has a layout yet.
if (resultLattices.empty())
return;

// We do not support multiple results yet.
if (resultLattices.size() != 1)
return;
Copy link
Member

Choose a reason for hiding this comment

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

The first check is redundant

return;

for (RegionSuccessor successor : successors) {
if (auto succ = successor.getSuccessor()) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you use the actual type here instead of auto? It's not clear based on the RHS

Comment on lines 712 to 713
assert(isa<VectorType>(inputType) &&
"Scalar broadcast not supported for now.");
Copy link
Member

Choose a reason for hiding this comment

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

This assertion is obsolete now.

Comment on lines +135 to +136
if (isa<VectorType>(replacement.getType()) &&
cast<ShapedType>(replacement.getType()).getRank() != 0) {
Copy link
Member

Choose a reason for hiding this comment

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

replaceOpWithDistributedValues(rewriter, multiReduceOp, accReduced);
} else {
Value accReducedVal = rewriter.create<vector::ExtractOp>(
loc, accReduction, SmallVector<int64_t>{0});
Copy link
Member

Choose a reason for hiding this comment

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

You don't need a vector here, you can do: ArrayRef{int64_t(0)}

if (accVector) {
locallyReduced = dyn_cast<VectorValue>(localReduction.getResult());
} else {
VectorType vecType = VectorType::get(SmallVector<int64_t>{1}, elemTy);
Copy link
Member

Choose a reason for hiding this comment

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

Also here, no need to use a vector

Comment on lines +427 to +428
if (accVector) {
accElemTy = accVector.getType().getElementType();
Copy link
Member

Choose a reason for hiding this comment

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

You can use getElementTypeOrSelf. Also below.

Comment on lines +311 to +312
bool isSrcVector = (srcVector) && (isVector(srcVector));
if (!isSrcVector) {
Copy link
Member

Choose a reason for hiding this comment

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

This is the only use of isSrcVector, so it makes sense to inline it

Suggested change
bool isSrcVector = (srcVector) && (isVector(srcVector));
if (!isSrcVector) {
if (!srcVector || !isVector(srcVector)) {

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.

2 participants