Skip to content

Commit b39a103

Browse files
committed
OpenXLA-specific changes
1 parent fd02f65 commit b39a103

File tree

49 files changed

+2330
-203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2330
-203
lines changed

BUILD

Lines changed: 904 additions & 0 deletions
Large diffs are not rendered by default.

include/triton/Analysis/AxisInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ class ModuleAxisInfoAnalysis : public CallGraph<AxisInfoMapT> {
180180
for (auto funcOp : llvm::reverse(sortedFuncs)) {
181181
initialize(funcOp);
182182
funcOp.walk([&](CallOpInterface callOp) {
183-
auto callee =
184-
dyn_cast<FunctionOpInterface>(callOp.resolveCallable(&symbolTable));
183+
auto callee = dyn_cast<FunctionOpInterface>(
184+
callOp.resolveCallableInTable(&symbolTable));
185185
update(callOp, callee);
186186
});
187187
}

include/triton/Analysis/Utility.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ template <typename T> class CallGraph {
316316
moduleOp.walk([&](Operation *op) {
317317
auto caller = op->getParentOfType<FunctionOpInterface>();
318318
if (auto callOp = dyn_cast<CallOpInterface>(op)) {
319-
auto *callee = callOp.resolveCallable(&symbolTable);
319+
auto *callee = callOp.resolveCallableInTable(&symbolTable);
320320
auto funcOp = dyn_cast_or_null<FunctionOpInterface>(callee);
321321
if (funcOp) {
322322
graph[caller].emplace_back(

include/triton/Dialect/TritonNvidiaGPU/IR/TritonNvidiaGPUOps.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ def TTNG_WarpGroupDotOp : TTNG_Op<"warp_group_dot", [DeclareOpInterfaceMethods<I
9191
let results = (outs TT_FpIntTensor:$d);
9292

9393
let assemblyFormat = "$a`,` $b`,` $c (`,` $useC^)? attr-dict `:` type($a) `*` type($b) `->` type($d)";
94+
95+
let extraClassDeclaration = [{
96+
bool needsPartialAccumulator();
97+
}];
9498
}
9599

96100
def TTNG_WarpGroupDotWaitOp : TTNG_Op<"warp_group_dot_wait", [DeclareOpInterfaceMethods<InferTypeOpInterface>,

lib/Analysis/Utility.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,11 @@ bool supportMMA(triton::DotOp op, int version) {
488488
if (triton::tools::getBoolEnv("DISABLE_MMA_V3"))
489489
return false;
490490
auto retType = op.getType();
491+
RankedTensorType typeA = op.getA().getType();
492+
int k = typeA.getShape().back();
493+
// If k size is smaller than the native mma size, we cannot use MMA.
494+
if (k < 256 / aElemTy.getIntOrFloatBitWidth())
495+
return false;
491496
auto retShapePerCTA = getShapePerCTA(retType);
492497
auto rank = retShapePerCTA.size();
493498
auto mod = op->getParentOfType<ModuleOp>();

lib/Conversion/TritonGPUToLLVM/ElementwiseOpToLLVM.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ SmallVector<Value> reorderValues(const SmallVector<Value> &values, Type inType,
4040
auto ouEltTy = ouTensorTy.getElementType();
4141
if (inBitWidth == ouBitWidth)
4242
return values;
43-
if (inBitWidth == 16 && ouBitWidth == 32) {
43+
if ((inBitWidth == 16 && ouBitWidth == 32) ||
44+
(inBitWidth == 32 && ouBitWidth == 16)) {
4445
SmallVector<Value> ret;
4546
for (unsigned i = 0; i < values.size(); i += 8) {
4647
ret.push_back(values[i]);
@@ -610,10 +611,9 @@ struct IndexCastOpLowering
610611
if (targetBits == sourceBits)
611612
return {operands[0][0]};
612613
if (targetBits < sourceBits)
613-
return {rewriter.replaceOpWithNewOp<LLVM::TruncOp>(op, elemTy,
614-
operands[0][0])};
615-
return {
616-
rewriter.replaceOpWithNewOp<LLVM::SExtOp>(op, elemTy, operands[0][0])};
614+
return {
615+
rewriter.create<LLVM::TruncOp>(op.getLoc(), elemTy, operands[0][0])};
616+
return {rewriter.create<LLVM::SExtOp>(op.getLoc(), elemTy, operands[0][0])};
617617
}
618618
};
619619

lib/Conversion/TritonGPUToLLVM/ViewOpToLLVM.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ struct ArithConstantSplatOpConversion
8787
// LLVM IR.
8888
if (type::isFloat8(elemType))
8989
elemType = rewriter.getIntegerType(8);
90-
auto constOp = rewriter.create<LLVM::ConstantOp>(loc, elemType, val);
9190
auto typeConverter = getTypeConverter();
91+
auto constOp = rewriter.create<LLVM::ConstantOp>(
92+
loc, typeConverter->convertType(elemType), val);
9293
auto llStruct = SplatOpConversion::convertSplatLikeOp(
9394
elemType, op.getType(), constOp, typeConverter, rewriter, loc);
9495
rewriter.replaceOp(op, llStruct);

lib/Dialect/TritonGPU/IR/Dialect.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,6 +2717,11 @@ struct CanonicalizeConvertFromAlloc
27172717
auto convert = op.getSrc().getDefiningOp<ConvertLayoutOp>();
27182718
if (!convert)
27192719
return failure();
2720+
// LocalAllocOp lowering doesn't support going from DotOperandEncoding
2721+
// to SharedEncoding, so we want to keep this layout conversion.
2722+
if (mlir::isa<triton::gpu::DotOperandEncodingAttr>(
2723+
convert.getSrc().getType().getEncoding()))
2724+
return failure();
27202725
rewriter.replaceOpWithNewOp<triton::gpu::LocalAllocOp>(
27212726
op, op->getResult(0).getType(), convert.getSrc());
27222727
return mlir::success();

lib/Dialect/TritonGPU/Transforms/AccelerateMatmul.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,21 @@ static Value getSharedMemoryMMAOperand(Value v, mlir::PatternRewriter &rewriter,
153153
auto newType = MemDescType::get(argType.getShape(), argType.getElementType(),
154154
newLayout, SharedMemorySpace);
155155
rewriter.setInsertionPointAfterValue(arg);
156+
157+
// LocalAllocOp lowering doesn't support going from DotOperandEncoding
158+
// to SharedEncoding.
159+
if (auto dotOpEnc = mlir::dyn_cast<DotOperandEncodingAttr>(
160+
argType.getEncoding())) {
161+
// Create a layout conversion from DotOperandEncoding to BlockedEncoding
162+
// then pass it to the LocalAllocOp.
163+
auto newArgType = RankedTensorType::get(
164+
argType.getShape(), argType.getElementType(), dotOpEnc.getParent());
165+
auto dotOperandToBlockedCvt =
166+
rewriter.create<ConvertLayoutOp>(arg.getLoc(), newArgType, arg);
167+
return rewriter.create<LocalAllocOp>(arg.getLoc(), newType,
168+
dotOperandToBlockedCvt);
169+
}
170+
156171
return rewriter.create<LocalAllocOp>(arg.getLoc(), newType, arg);
157172
}
158173

@@ -162,6 +177,15 @@ class BlockedToMMA : public mlir::OpRewritePattern<DotOp> {
162177
mutable llvm::DenseMap<Operation *, unsigned> dotOpInstNs;
163178

164179
static bool bwdFilter(Operation *op) {
180+
// Dot operand layout assignment to Predicates are not currently supported
181+
// during lowering from TritonGPU to LLVM in Triton for MMA cases. This
182+
// condition limits visibility of the original bit-width so that predicate
183+
// are not considered, hence, kwidth can never be = 32.
184+
if (isa<arith::UIToFPOp>(op)) {
185+
Type srcType = getElementTypeOrSelf(op->getOperand(0));
186+
if (srcType.isInteger(1))
187+
return false;
188+
}
165189
return op->getNumOperands() == 1 &&
166190
(isa<FpToFpOp, BitcastOp, ConvertLayoutOp>(op) ||
167191
isPureUnaryInlineAsm(op) ||

lib/Dialect/TritonGPU/Transforms/OptimizeAccumulatorInit.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ namespace gpu {
1414
namespace {
1515
bool dotSupportsAccInitFlag(Operation *op) {
1616
assert(op->hasTrait<OpTrait::DotLike>() && "Expected a dot-like operation");
17-
return isa<triton::nvidia_gpu::WarpGroupDotOp>(op);
17+
if (auto wgDotOp = dyn_cast<triton::nvidia_gpu::WarpGroupDotOp>(op)) {
18+
// Partial accumulation would require a select op to handle the
19+
// initialization that would degrade the performance.
20+
return !wgDotOp.needsPartialAccumulator();
21+
}
22+
return false;
1823
}
1924

2025
std::pair<Value, Operation *> getAccumulatorUseAndDef(Operation *op) {

0 commit comments

Comments
 (0)