Skip to content

Commit b0cc8bd

Browse files
author
TA Sync Bot
committed
Merge commit '1c2e9bb563ca61672dd72d4fc2bb802fd1d1c781' into auto/upstream-sync-20260712-052224
2 parents d0b4d00 + 1c2e9bb commit b0cc8bd

38 files changed

Lines changed: 1493 additions & 685 deletions

File tree

include/triton/Dialect/Triton/IR/TritonOpInterfaces.td

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ def DotOpInterface : OpInterface<"DotOpInterface"> {
4949
/*retType=*/"::mlir::Value",
5050
/*methodName=*/"getB",
5151
/*args=*/(ins)>,
52-
InterfaceMethod<
52+
InterfaceMethod<
53+
/*desc=*/"Get the output tensor",
54+
/*retType=*/"::mlir::Value",
55+
/*methodName=*/"getD",
56+
/*args=*/(ins)>,
57+
InterfaceMethod<
5358
/*desc=*/"Verify the dimensions of the A and B DotOp operands.",
5459
/*retType=*/"bool",
5560
/*methodName=*/"verifyDims",
@@ -64,6 +69,7 @@ def DotOpInterface : OpInterface<"DotOpInterface"> {
6469
auto aTy = cast<ShapedType>($_op.getA().getType());
6570
auto bTy = cast<ShapedType>($_op.getB().getType());
6671
auto cTy = cast<ShapedType>($_op->getOperand(2).getType());
72+
auto dTy = cast<ShapedType>($_op.getD().getType());
6773
auto aShape = aTy.getShape();
6874
auto bShape = bTy.getShape();
6975
auto cShape = cTy.getShape();

include/triton/Dialect/TritonGPU/IR/LinearLayoutConversions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class AMDRotatingSharedEncodingAttr;
1919
class AMDMfmaEncodingAttr;
2020
class TensorOrMemDesc;
2121
class MemDescType;
22+
class CTALayoutAttr;
2223

2324
// - BlockedEncodingAttrs have the following input dimensions.
2425
//
@@ -126,6 +127,13 @@ LinearLayout chooseScaledMfmaScaleLayout(MLIRContext *ctx, int dotOperandIdx,
126127
ArrayRef<unsigned> tilesPerWarp,
127128
ArrayRef<unsigned> warpsPerCTA);
128129

130+
LinearLayout getSM120DotScaledScaleLayout(MLIRContext *ctx, int dotOperandIdx,
131+
ArrayRef<int64_t> dotOperandShape,
132+
ArrayRef<unsigned> tilesPerWarp,
133+
ArrayRef<unsigned> warpsPerCTA,
134+
unsigned instrM, unsigned instrN,
135+
CTALayoutAttr ctaLayoutAttr);
136+
129137
// Create LinearLayout for nvidia mma tile.
130138
LinearLayout nvidiaMmaTile(MLIRContext *ctx, ArrayRef<unsigned> tileShape,
131139
unsigned kWidth, ArrayRef<unsigned> order,

lib/Dialect/TritonGPU/IR/Dialect.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,12 +1335,6 @@ AMDWmmaEncodingAttr::verify(function_ref<mlir::InFlightDiagnostic()> emitError,
13351335
if (version != 1 && version != 2) {
13361336
return emitError() << "WMMA version must be in the [1, 2] range";
13371337
}
1338-
// Transposed layout is needed for bypassing LDS between multiple dots.
1339-
// Version 1 tt.dot results and tt.dot operand layouts are different,
1340-
// therefore we test and support transposed only for version 2.
1341-
if (version != 2 && isTransposed) {
1342-
return emitError() << "Transposed WMMA is supported only for version 2";
1343-
}
13441338
return success();
13451339
}
13461340

lib/Dialect/TritonGPU/IR/LinearLayoutConversions.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,83 @@ LinearLayout chooseDsReadB64TrLayout(Attribute enc, ArrayRef<int64_t> shape,
14031403
return chooseDotDsReadB64TrLayout(dot, shape, elemBitWidth);
14041404
}
14051405

1406+
// Warp-level block scaling (sm_120, m16n8k32)
1407+
// Reference: NVIDIA PTX ISA "Warp-level block scaling"
1408+
// https://docs.nvidia.com/cuda/parallel-thread-execution/#warp-level-block-scaling
1409+
//
1410+
// Semantics:
1411+
// D = (A * SF_A) * (B * SF_B) + C
1412+
// scale_vec::1X -> SF_A shape Mx1 (per-row), SF_B shape 1xN (per-col)
1413+
//
1414+
// Providers (within each warp quad of 4 lanes):
1415+
// - A scales are provided by a lane-pair selected by thread-id-a ∈ {0,1}
1416+
// (0 => lanes {0,1}, 1 => lanes {2,3} in the quad).
1417+
// - B scales are provided by a single lane selected by thread-id-b ∈
1418+
// {0,1,2,3}.
1419+
//
1420+
// Byte selectors (which subfield of the 32-bit metadata is used):
1421+
// - 1X: 1 byte => byte-id ∈ {0,1,2,3}
1422+
//
1423+
// Implementation notes:
1424+
// - We support only scale_vec::1X for now.
1425+
// - We choose a fixed provider for A (thread-id-a = 0) and B (thread-id-b =
1426+
// 0)
1427+
// - In this implementation, each lane in a quad has the same scale factor.
1428+
LinearLayout getSM120DotScaledScaleLayout(
1429+
MLIRContext *ctx, int dotOperandIdx, ArrayRef<int64_t> dotOperandShape,
1430+
ArrayRef<unsigned> tilesPerWarp, ArrayRef<unsigned> warpsPerCTA,
1431+
unsigned mmaInstrM, unsigned mmaInstrN, CTALayoutAttr ctaLayoutAttr) {
1432+
unsigned rank = dotOperandShape.size();
1433+
auto outDims = standardOutDimNames(ctx, rank);
1434+
1435+
StringAttr kRegister = StringAttr::get(ctx, "register");
1436+
StringAttr kLane = StringAttr::get(ctx, "lane");
1437+
StringAttr kWarp = StringAttr::get(ctx, "warp");
1438+
1439+
const unsigned mIndex = 0;
1440+
const unsigned nIndex = 1;
1441+
const int instrM = mmaInstrM;
1442+
const int instrN = mmaInstrN;
1443+
const int kSize = dotOperandShape[1];
1444+
const int mWarps = warpsPerCTA[mIndex];
1445+
const int nWarps = warpsPerCTA[nIndex];
1446+
const int totalWarps = mWarps * nWarps;
1447+
const unsigned mRep_warp = tilesPerWarp[mIndex];
1448+
const unsigned nRep_warp = tilesPerWarp[nIndex];
1449+
const unsigned kRep = std::min<unsigned>(kSize, 2);
1450+
1451+
std::vector<std::vector<int32_t>> registerBase;
1452+
std::vector<std::vector<int32_t>> laneBase;
1453+
std::vector<std::vector<int32_t>> warpBase;
1454+
if (dotOperandIdx == 0) { // per-row A-scale
1455+
laneBase = {{0, 8}, {0, 0}, {0, 1}, {0, 2}, {0, 4}};
1456+
for (int offset = instrM * mWarps; offset < instrM * mWarps * mRep_warp;
1457+
offset <<= 1)
1458+
registerBase.push_back({0, offset});
1459+
for (int w = mWarps; w < totalWarps; w <<= 1)
1460+
warpBase.push_back({0, 0});
1461+
for (int offset = instrM; offset < instrM * mWarps; offset <<= 1)
1462+
warpBase.push_back({0, offset});
1463+
} else { // per-col B-scale
1464+
laneBase = {{0, 0}, {0, 0}, {0, 1}, {0, 2}, {0, 4}};
1465+
if (nRep_warp > 1)
1466+
registerBase.push_back({0, nWarps * instrN});
1467+
for (int k = 1; k < kRep; k += 1)
1468+
registerBase.push_back({1 << (k - 1), 0});
1469+
for (int offset = instrN; offset < instrN * nWarps; offset <<= 1)
1470+
warpBase.push_back({0, offset});
1471+
for (int w = nWarps; w < totalWarps; w <<= 1)
1472+
warpBase.push_back({0, 0});
1473+
}
1474+
1475+
const unsigned kIdx = (dotOperandShape[0] == 1) ? 0 : 1;
1476+
const unsigned mnIdx = 1 - kIdx;
1477+
LinearLayout ctaLayout(
1478+
{{kRegister, registerBase}, {kLane, laneBase}, {kWarp, warpBase}},
1479+
{outDims[kIdx], outDims[mnIdx]});
1480+
return combineCtaCgaWithShape(ctaLayout, ctaLayoutAttr, dotOperandShape);
1481+
}
1482+
14061483
LinearLayout chooseScaledMfmaScaleLayout(MLIRContext *ctx, int dotOperandIdx,
14071484
ArrayRef<int64_t> dotOperandShape,
14081485
unsigned mfmaMDim,

0 commit comments

Comments
 (0)