Skip to content

[MLIR][XeGPU] Add unroll patterns for XeGPU (1/N) #137010

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

Merged
merged 45 commits into from
May 12, 2025

Conversation

chencha3
Copy link
Contributor

@chencha3 chencha3 commented Apr 23, 2025

Similar to vector ops, XeGPU ops need to be unrolled into smaller shapes such that they can be dispatched into a hardware instruction. This PR marks the initial phase of a series dedicated to incorporating unroll patterns for XeGPU operations. In this installment, we introduce patterns for the following operations:

  1. createNd
  2. updateNd
  3. prefetchNd
  4. loadNd
  5. storeNd
  6. dpas

Copy link

github-actions bot commented Apr 23, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@chencha3 chencha3 marked this pull request as ready for review April 30, 2025 16:16
@chencha3 chencha3 changed the title [MLIR][XeGPU] Add unroll pass for XeGPU [MLIR][XeGPU] Add unroll patterns for XeGPU (1/N) Apr 30, 2025
@Garra1980
Copy link

This PR marks the initial phase of a series dedicated to incorporating unroll patterns for XeGPU operations.

Can you please add some justification/explanation regarding those unroll patterns

Comment on lines 436 to 441
for (int64_t i = 0; i < mIters; i++) {
for (int64_t j = 0; j < nIters; j++) {
Value tmpC;
if (c)
tmpC = cVals[i * nIters + j]; // init with acc
for (int64_t k = 0; k < kIters; k++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

LLVM coding standards want preincrements (++i): https://llvm.org/docs/CodingStandards.html#prefer-preincrement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Fixed.

auto targetShape = *maybeTargetShape;

auto convertedTdescTypes = getUnrolledTypes(tdescTy, targetShape);
auto convertedTdesc =
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@fschlimb fschlimb May 7, 2025

Choose a reason for hiding this comment

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

Many places in this code might be more readable with explicit types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Fixed.

Comment on lines 423 to 426
if (any_of(ranges, [](auto &v) { return v.size() == 0; }) ||
all_of(ranges, [](auto &v) { return v.size() == 1; })) {
return failure();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Fixed.

}
}

if (isa<xegpu::DpasOp>(op)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

no {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks! fixed.

@fschlimb
Copy link
Contributor

fschlimb commented May 7, 2025

Added a few minor comments. On the monkey-level this looks good to me.
You might want to capitalize the first words in paragraphs and enums/bullet lists within comments.

@chencha3 chencha3 force-pushed the users/chencha3/xegpu/xegpu_unroll_patterns branch from e24d75f to e873d59 Compare May 7, 2025 20:29
@chencha3
Copy link
Contributor Author

chencha3 commented May 7, 2025

Added a few minor comments. On the monkey-level this looks good to me. You might want to capitalize the first words in paragraphs and enums/bullet lists within comments.

Thanks @fschlimb, I made the changes according to your feedback. I hope I addressed all of your concerns.

Copy link
Contributor

@charithaintc charithaintc left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@adam-smnk adam-smnk left a comment

Choose a reason for hiding this comment

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

It'll be interesting to later see if we could generalize and reuse vector unrolling to achieve the same. For now, I think it's a good addition to xegpu infrastructure and we'll see in practice how it holds up.

I take it depends on #138701?

@chencha3
Copy link
Contributor Author

chencha3 commented May 8, 2025

It'll be interesting to later see if we could generalize and reuse vector unrolling to achieve the same. For now, I think it's a good addition to xegpu infrastructure and we'll see in practice how it holds up.

I take it depends on #138701?

Yeah. these patterns are supposed to be companions to vector unrolling patterns. They share the same idea, one is for XeGPU ops only, and one is for vector ops. A pass are supposed to use both of them.

}

private:
const char *const packAttrName = "__xetile_blocking_pack__";

Choose a reason for hiding this comment

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

xetile->xegpu I guess, here and in tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch. fixed it

/// provide a way to customize the native shape of the operation.
struct UnrollOptions {
using FilterConstraintFnType = std::function<LogicalResult(Operation *op)>;
/// Callback function that indicates whether vector unrolling should be

Choose a reason for hiding this comment

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

nit: let's place this comment above "using" to have uniform look :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed it

@chencha3
Copy link
Contributor Author

chencha3 commented May 9, 2025

It'll be interesting to later see if we could generalize and reuse vector unrolling to achieve the same. For now, I think it's a good addition to xegpu infrastructure and we'll see in practice how it holds up.

I take it depends on #138701?

#138701 has been merged, and this PR is rebased too.

@chencha3
Copy link
Contributor Author

chencha3 commented May 9, 2025

Hi @fschlimb and @adam-smnk, do you have more suggestions?

@fschlimb
Copy link
Contributor

fschlimb commented May 9, 2025

Hi @fschlimb and @adam-smnk, do you have more suggestions?

no, LGTM!

@chencha3
Copy link
Contributor Author

Hi @adam-smnk, I am going to merge this first. If you have more suggestions, feel free to let me know. Thanks for your help!

@chencha3 chencha3 merged commit db42345 into main May 12, 2025
11 checks passed
@chencha3 chencha3 deleted the users/chencha3/xegpu/xegpu_unroll_patterns branch May 12, 2025 14:16
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.

5 participants