-
Notifications
You must be signed in to change notification settings - Fork 10
LHS Registers Part 1 - DotOp Hoisting and SMEM-RF Copy Lowering #18
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
Changes from all commits
6fa4f50
1ef30e9
330e489
50d80e4
25768b5
4c59f90
9bd98c8
b5c4dbb
dde020b
ae07fbd
cf4598f
142b512
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| df0864e761107b07e38f5503e0cbee0cebb4c5e8 | ||
| 29b92d07746fac26cd64c914bc9c5c3833974f6d |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1022,13 +1022,18 @@ LogicalResult DotOperandEncodingAttr::verify( | |
| return emitError() << "triton_gpu.dot_op parent paramenter cannot be null"; | ||
| } | ||
| if (auto parentAttr = mlir::dyn_cast<NvidiaMmaEncodingAttr>(parent)) { | ||
| if (kWidth != 0 && !parentAttr.isAmpere()) | ||
| if (kWidth != 0 && !(parentAttr.isAmpere() || parentAttr.isHopper())) | ||
| return emitError() << "triton_gpu.dot_op kWidth parameter can only be " | ||
| "non-zero for Ampere MMA parent"; | ||
| if (kWidth == 0 && parentAttr.isAmpere()) | ||
| "non-zero for Ampere or Hopper MMA parent"; | ||
| if (kWidth == 0 && (parentAttr.isAmpere() || parentAttr.isHopper())) | ||
| return emitError() | ||
| << "triton_gpu.dot_op kWidth parameter is mandatory for " | ||
| "Ampere MMA parent"; | ||
| "Ampere or Hopper MMA parent"; | ||
| if (opIdx != 0 && parentAttr.isHopper()) | ||
| return emitError() | ||
| << "triton_gpu.dot_op opIdx parameter must be 0 for " | ||
| "Hopper MMA parent, since Hopper WGMMA only allows first " | ||
| "operand to be in registers"; | ||
| return success(); | ||
| } | ||
|
|
||
|
|
@@ -1957,17 +1962,17 @@ SmallVector<int> NvidiaMmaEncodingAttr::getMMAv1ShapePerWarp(int opIdx) const { | |
| int NvidiaMmaEncodingAttr::getMMAv1Vec(int opIdx) const { | ||
| return 2 * getMMAv1Rep(opIdx)[opIdx]; | ||
| } | ||
| SmallVector<int64_t> NvidiaMmaEncodingAttr::getMMAv2Rep(ArrayRef<int64_t> shape, | ||
| SmallVector<int64_t> NvidiaMmaEncodingAttr::getMMAv2OrV3Rep(ArrayRef<int64_t> shape, | ||
| int bitwidth, | ||
| int opIdx) const { | ||
| assert(isAmpere() || isHopper()); | ||
| auto rank = shape.size(); | ||
| auto warpsPerCTA = getWarpsPerCTA(); | ||
| SmallVector<int> shapePerWarp = {1, 16, 8, 4 * 64 / bitwidth}; | ||
|
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. What about the 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. Ok, after having a thought about this, I guess that in all these places that depend on It would be good to leave a note somewhere in the code and refer to that note in all the places where we use this "trick" (here, in the SharedEncodingAttr, in the shared to dot operand mma, etc).
Author
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. For Hopper actually I can add an assert here for 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. right! Adding an assert would be great. |
||
| int numRepBatch = | ||
| rank == 3 | ||
| ? std::max<int64_t>(1, shape[0] / (shapePerWarp[0] * warpsPerCTA[0])) | ||
| : 1; | ||
| assert(isAmpere()); | ||
|
|
||
| if (opIdx == 0) | ||
| return {numRepBatch, | ||
|
|
@@ -1982,18 +1987,25 @@ SmallVector<int64_t> NvidiaMmaEncodingAttr::getMMAv2Rep(ArrayRef<int64_t> shape, | |
| warpsPerCTA[rank - 1]))}; | ||
| } | ||
| } | ||
|
|
||
| unsigned NvidiaMmaEncodingAttr::getTotalElemsPerThreadForOperands( | ||
| ArrayRef<int64_t> shape, Type eltTy, int kWidth, int opIdx) const { | ||
| auto shapePerCTA = getShapePerCTA(*this, shape); | ||
| int warpsPerCTAM = getWarpsPerCTA()[0]; | ||
| int warpsPerCTAN = getWarpsPerCTA()[1]; | ||
| // H100 | ||
| if (isHopper()) { | ||
| return getTotalElemsPerThread(shape, eltTy); | ||
| assert(opIdx == 0); | ||
Moerafaat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| auto instrMNK = getInstrShape(); | ||
| int repM = ceil<unsigned>(shapePerCTA[0], instrMNK[0] * warpsPerCTAM); | ||
| int repK = ceil<unsigned>(shapePerCTA[1], instrMNK[2]); | ||
| // For each WGMMA instr, a 2x2 matrix fragment is loaded. Each thread holds | ||
| // kWidth elements for each quadrant. WGMMA is repeated repM * repK times. | ||
| return 4 * kWidth * repM * repK; | ||
| } | ||
| // A100 | ||
| if (isAmpere()) { | ||
| auto rep = getMMAv2Rep(shapePerCTA, eltTy.getIntOrFloatBitWidth(), opIdx); | ||
| auto rep = getMMAv2OrV3Rep(shapePerCTA, eltTy.getIntOrFloatBitWidth(), opIdx); | ||
| if (opIdx == 0) | ||
| return 4 * rep[0] * rep[1] * rep[2]; | ||
| if (opIdx == 1) | ||
|
|
@@ -2720,6 +2732,11 @@ struct CanonicalizeConvertFromAlloc | |
| auto convert = op.getSrc().getDefiningOp<ConvertLayoutOp>(); | ||
| if (!convert) | ||
| return failure(); | ||
| // LocalAllocOp lowering doesn't support going from DotOperandEncoding | ||
| // to SharedEncoding, so we want to keep this layout conversion. | ||
| if (mlir::isa<triton::gpu::DotOperandEncodingAttr>( | ||
| convert.getSrc().getType().getEncoding())) | ||
| return failure(); | ||
| rewriter.replaceOpWithNewOp<triton::gpu::LocalAllocOp>( | ||
| op, op->getResult(0).getType(), convert.getSrc()); | ||
| return mlir::success(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.