-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[LAYOUTS] Use LLs for Hopper whenever we wouldn't use ldmatrix #5235
Changes from all commits
2b2032f
cbf00e2
baf6783
91e46b3
68c8513
de18e21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,28 +376,14 @@ struct ConvertLayoutOpUsingLinearLayoutsConversion | |
// completed before we can remove the layoutIsOK check: | ||
// 1. Support for AMD's WMMA | ||
std::function<bool(Attribute)> layoutIsOK = [&](Attribute layout) { | ||
if (isa<NvidiaMmaEncodingAttr, AMDMfmaEncodingAttr>(layout)) { | ||
return !useLegacyMMAConversion; | ||
} | ||
if (auto dotOperand = dyn_cast<DotOperandEncodingAttr>(layout)) { | ||
auto parent = dotOperand.getParent(); | ||
if (isa<MmaEncodingTrait>(parent) && useLegacyMMAConversion) { | ||
return false; | ||
} | ||
if (auto nvidiaMma = dyn_cast<NvidiaMmaEncodingAttr>(parent)) { | ||
if (nvidiaMma.isAmpere()) { | ||
return true; | ||
} | ||
} | ||
if (isa<AMDMfmaEncodingAttr>(parent)) { | ||
return true; | ||
} | ||
return false; | ||
layout = dotOperand.getParent(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure this is a correct change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I agree that blocked FMA has to be fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, right, let me send a fix |
||
} | ||
if (isa<BlockedEncodingAttr>(layout)) { | ||
return true; | ||
|
||
if (isa<NvidiaMmaEncodingAttr, AMDMfmaEncodingAttr>(layout)) { | ||
return !useLegacyMMAConversion; | ||
} | ||
if (isa<LinearEncodingAttr>(layout)) { | ||
if (isa<BlockedEncodingAttr, LinearEncodingAttr>(layout)) { | ||
return true; | ||
} | ||
if (auto slice = dyn_cast<SliceEncodingAttr>(layout)) { | ||
|
@@ -408,6 +394,10 @@ struct ConvertLayoutOpUsingLinearLayoutsConversion | |
if (!layoutIsOK(srcTy.getEncoding()) || !layoutIsOK(dstTy.getEncoding())) { | ||
return failure(); | ||
} | ||
// FIXME [Dot LL] Remove this once we implement this trick in LLs | ||
if (matchMmaV3AndDotOperandLayout(srcTy, dstTy)) { | ||
return failure(); | ||
} | ||
|
||
// The following check can be removed when generalized warp shuffle | ||
// conversions are ready: | ||
|
@@ -504,34 +494,35 @@ struct ConvertLayoutOpUsingLinearLayoutsConversion | |
// don't need to avoid duplicate writes. | ||
// Input dims: [reg, lane, warp] | ||
// Output dims: [offset, iteration] | ||
std::optional<LinearLayout> shmemStoreLayout = | ||
chooseStMatrixLayout(ctx, op.getSrc().getType(), scratchConfig.repShape, | ||
scratchConfig.paddedRepShape, scratchConfig.order, | ||
/*swizzleByteSize=*/0); | ||
bool isStMatrix = shmemStoreLayout.has_value(); | ||
if (!isStMatrix) { | ||
shmemStoreLayout = srcLayout.invertAndCompose(sharedLayout); | ||
} | ||
assert(shmemStoreLayout.has_value()); | ||
bool isStMatrix = targetInfo.canUseStMatrix( | ||
op.getSrc().getType(), scratchConfig.repShape, | ||
scratchConfig.paddedRepShape, scratchConfig.order, | ||
/*swizzleByteSize=*/0); | ||
LinearLayout shmemStoreLayout = | ||
isStMatrix ? chooseStMatrixLayout( | ||
ctx, op.getSrc().getType(), scratchConfig.repShape, | ||
scratchConfig.paddedRepShape, scratchConfig.order, | ||
/*swizzleByteSize=*/0) | ||
: srcLayout.invertAndCompose(sharedLayout); | ||
|
||
const int shmemAllocatedNumElems = | ||
getNumScratchElements(scratchConfig.paddedRepShape); | ||
assert(shmemStoreLayout->getOutDimSize(kOffset) <= shmemAllocatedNumElems); | ||
assert(shmemStoreLayout.getOutDimSize(kOffset) <= shmemAllocatedNumElems); | ||
|
||
// Layout for the load from shmem to registers. | ||
LinearLayout shmemLoadLayout = dstLayout.invertAndCompose(sharedLayout); | ||
|
||
// Check that the `register` fully determines the `iteration`. That is, | ||
// each thread does exactly the same reads and writes to shmem on each | ||
// iteration, just with different input/output registers. | ||
assert(shmemStoreLayout->sublayoutIsZero({kLane, kWarp, kBlock}, | ||
{kIteration})); | ||
assert( | ||
shmemStoreLayout.sublayoutIsZero({kLane, kWarp, kBlock}, {kIteration})); | ||
assert( | ||
shmemLoadLayout.sublayoutIsZero({kLane, kWarp, kBlock}, {kIteration})); | ||
|
||
// iteration -> registers | ||
SmallVector<SmallVector<int>> inRegsForIter = | ||
collectRegsForIter(ctx, *shmemStoreLayout); | ||
collectRegsForIter(ctx, shmemStoreLayout); | ||
SmallVector<SmallVector<int>> outRegsForIter = | ||
collectRegsForIter(ctx, shmemLoadLayout); | ||
|
||
|
@@ -588,7 +579,7 @@ struct ConvertLayoutOpUsingLinearLayoutsConversion | |
return vecAddr; | ||
}; | ||
|
||
auto storeBase = applyLinearLayout(loc, rewriter, *shmemStoreLayout, | ||
auto storeBase = applyLinearLayout(loc, rewriter, shmemStoreLayout, | ||
{{kRegister, i32_val(0)}, | ||
{kLane, laneId}, | ||
{kWarp, warpId}, | ||
|
@@ -611,11 +602,11 @@ struct ConvertLayoutOpUsingLinearLayoutsConversion | |
|
||
// When using `stmatrix`, we can store `inVec` elements even if they are | ||
// not contiguous | ||
auto inVec = isStMatrix ? shmemStoreLayout->getNumConsecutiveInOut() | ||
auto inVec = isStMatrix ? shmemStoreLayout.getNumConsecutiveInOut() | ||
: scratchConfig.inVec; | ||
for (int j = 0; j < inVals.size() / iterations; j += inVec) { | ||
auto inRegSlice = inRegs[j]; | ||
Value vecAddr = getVecAddr(*shmemStoreLayout, storeBase, inRegSlice); | ||
Value vecAddr = getVecAddr(shmemStoreLayout, storeBase, inRegSlice); | ||
SmallVector<Value> inValsVec; | ||
for (int k = 0; k < inVec; k++) | ||
inValsVec.push_back(inVals[inRegSlice + k]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny .gitignore change for
pytest
.