-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible to lower fp8
tt.splat
.
Before the fix, `tt.splat` was lowered to e.g. ``` %14 = "llvm.mlir.constant"() <{value = 0.000000e+00 : f8E4M3FNUZ}> : () -> f8E4M3FNUZ ``` which LLVM rejected. Translating the result type through typeConverter is what is done in other similar places. It results in ``` %14 = "llvm.mlir.constant"() <{value = 0.000000e+00 : f8E4M3FNUZ}> : () -> i8 ``` and it's accepted by LLVM. During the MLIR to LLVM lowering, the fp8 value is converted to i8 with the correct binary representation. The `isFloat()` function that is updated happened to have just one caller (in ArithConstantSplatOpConversion) PiperOrigin-RevId: 634065311
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
diff --git a/include/triton/Conversion/MLIRTypes.h b/include/triton/Conversion/MLIRTypes.h | ||
--- a/include/triton/Conversion/MLIRTypes.h | ||
+++ b/include/triton/Conversion/MLIRTypes.h | ||
@@ -26,12 +26,6 @@ inline Type f32Ty(MLIRContext *ctx) { re | ||
inline Type f64Ty(MLIRContext *ctx) { return FloatType::getF64(ctx); } | ||
inline Type bf16Ty(MLIRContext *ctx) { return FloatType::getBF16(ctx); } | ||
|
||
-inline bool isFloat(Type type) { | ||
- return type.isF32() || type.isF64() || type.isF16() || type.isF128(); | ||
-} | ||
- | ||
-inline bool isInt(Type type) { return type.isIntOrFloat() && !isFloat(type); } | ||
- | ||
} // namespace type | ||
} // namespace triton | ||
} // namespace mlir | ||
diff --git a/lib/Conversion/TritonGPUToLLVM/ViewOpToLLVM.cpp b/lib/Conversion/TritonGPUToLLVM/ViewOpToLLVM.cpp | ||
--- a/lib/Conversion/TritonGPUToLLVM/ViewOpToLLVM.cpp | ||
+++ b/lib/Conversion/TritonGPUToLLVM/ViewOpToLLVM.cpp | ||
@@ -74,17 +74,18 @@ struct ArithConstantSplatOpConversion | ||
auto values = mlir::dyn_cast<SplatElementsAttr>(op.getValue()); | ||
auto elemType = values.getElementType(); | ||
Attribute val; | ||
- if (elemType.isBF16() || type::isFloat(elemType)) { | ||
+ if (isa<FloatType>(elemType)) { | ||
val = values.getValues<FloatAttr>()[0]; | ||
- } else if (type::isInt(elemType)) { | ||
+ } else if (isa<IntegerType>(elemType)) { | ||
val = values.getValues<IntegerAttr>()[0]; | ||
} else { | ||
llvm::errs() << "ArithConstantSplatOpConversion get unsupported type: " | ||
<< value.getType() << "\n"; | ||
return failure(); | ||
} | ||
- auto constOp = rewriter.create<LLVM::ConstantOp>(loc, elemType, val); | ||
auto typeConverter = getTypeConverter(); | ||
+ auto constOp = rewriter.create<LLVM::ConstantOp>( | ||
+ loc, typeConverter->convertType(elemType), val); | ||
auto llStruct = SplatOpConversion::convertSplatLikeOp( | ||
elemType, op.getType(), constOp, typeConverter, rewriter, loc); | ||
rewriter.replaceOp(op, llStruct); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters