Skip to content

[VectorDistribution] Add scalar support for distributing multi-dim reduction (1/4) - #18784

Closed
bangtianliu wants to merge 2 commits into
iree-org:mainfrom
bangtianliu:reduction_vd_patch_1st
Closed

bangtianliu wants to merge 2 commits into
iree-org:mainfrom
bangtianliu:reduction_vd_patch_1st

Conversation

@bangtianliu

@bangtianliu bangtianliu commented Oct 15, 2024 •

Copy link
Copy Markdown
Contributor

Splitting #18519 into four patches.

This is the first one, supporting the case where vector.multi_reduction performs reduction along all dimensions and returns a scalar.

@hanhanW

hanhanW commented Oct 15, 2024

Copy link
Copy Markdown
Contributor

Sharing a tip based on my review experience. I've seen people put (1/n) at the end of PR/commit description, which means that there will be a sequence of PR coming and this is the first one. How about we follow it, so it becomes [VectorDistribution] Add scalar support for distributing multi-dim reduction (1/n)?

@bangtianliu bangtianliu changed the title [VectorDistribution] PATCH 1: add scalar support for distributing multi-dim reduction [VectorDistribution] PATCH 1: add scalar support for distributing multi-dim reduction (1/3) Oct 15, 2024
@hanhanW hanhanW changed the title [VectorDistribution] PATCH 1: add scalar support for distributing multi-dim reduction (1/3) [VectorDistribution] Add scalar support for distributing multi-dim reduction (1/3) Oct 16, 2024
@bangtianliu bangtianliu changed the title [VectorDistribution] Add scalar support for distributing multi-dim reduction (1/3) [VectorDistribution] Add scalar support for distributing multi-dim reduction (1/4) Oct 17, 2024

@kuhar kuhar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I reviewed your PRs out of ordered and left the comments here: #18800

@bangtianliu

Copy link
Copy Markdown
Contributor Author

I reviewed your PRs out of ordered and left the comments here: #18800

Thanks for your code reviews! I appreciate it very much and will see how to apply all of them.

@Groverkss Groverkss 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.

LGTM mostly. Once Jakub's comments are addressed we can land this.

Signed-off-by: Bangtian Liu <[email protected]>
@bangtianliu
bangtianliu requested a review from Groverkss October 21, 2024 15:48
@Groverkss
Groverkss requested a review from kuhar October 28, 2024 15:35
Comment on lines +431 to 434
resElemTy = resVector.getType().getElementType();
} else {
resElemTy = resType;
}

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 getElementTypeOrSelf

if (accVector) {
disAcc = getDistributed(rewriter, accVector, signature[accVector]);
} else {
disAcc = multiReduceOp.getAcc();

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.

Add a comment here that scalars are always distributed to all threads already.

Comment on lines +484 to +487
VectorType vecType = VectorType::get(SmallVector<int64_t>{1}, elemTy);
locallyReduced = rewriter.create<vector::BroadcastOp>(
loc, vecType, localReduction.getResult());
}

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.

Add a comment that we broadcast scalar accumulator to vector.

Comment on lines +511 to +513
if (!accVector) {
disAcc = rewriter.create<vector::BroadcastOp>(loc, shaped, disAcc);
}

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.

Add a comment that we broadcast scalar to vector and why.

Groverkss pushed a commit that referenced this pull request Oct 28, 2024
…ion with scalars (#18800)

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. 

Since patch 2 includes changes from patch #18784, the necessary updates
from the first patch have also been included here.

---------

Signed-off-by: Bangtian Liu <[email protected]>
if (accVector) {
locallyReduced = dyn_cast<VectorValue>(localReduction.getResult());
} else {
VectorType vecType = VectorType::get(SmallVector<int64_t>{1}, elemTy);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should be able to use ArrayRef here instead of constructing a vector

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also here

@bangtianliu

Copy link
Copy Markdown
Contributor Author

All the above comments have been applied to #18800, which includes the content from this patch and has already been merged. This PR can now be closed.

Eliasj42 pushed a commit that referenced this pull request Oct 31, 2024
…ion with scalars (#18800)

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.

Since patch 2 includes changes from patch #18784, the necessary updates
from the first patch have also been included here.

---------

Signed-off-by: Bangtian Liu <[email protected]>
Signed-off-by: Elias Joseph <[email protected]>
giacs-epic pushed a commit to giacs-epic/iree that referenced this pull request Dec 4, 2024
…ion with scalars (iree-org#18800)

Splitting iree-org#18519 into four patches.

Depends iree-org#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.

Since patch 2 includes changes from patch iree-org#18784, the necessary updates
from the first patch have also been included here.

---------

Signed-off-by: Bangtian Liu <[email protected]>
Signed-off-by: Giacomo Serafini <[email protected]>
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.

4 participants