Skip to content

Commit 8c3f59f

Browse files
authored
Revert "[MLIR][GPU] subgroup_mma fp64 extension" (#169049)
Reverts #165873 The revert is triggered by a failing integration test on a couple of buildbots.
1 parent 560b83c commit 8c3f59f

File tree

8 files changed

+20
-146
lines changed

8 files changed

+20
-146
lines changed

mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MMAMatrixType;
2727
#define GEN_PASS_DECL_CONVERTGPUOPSTONVVMOPS
2828
#include "mlir/Conversion/Passes.h.inc"
2929

30-
Type convertMMAToLLVMType(gpu::MMAMatrixType type);
30+
LLVM::LLVMStructType convertMMAToLLVMType(gpu::MMAMatrixType type);
3131

3232
/// Configure target to convert from the GPU dialect to NVVM.
3333
void configureGpuToNVVMConversionLegality(ConversionTarget &target);

mlir/include/mlir/Dialect/GPU/IR/GPUBase.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def GPU_MMAMatrix : DialectType<
114114
GPU_Dialect, IsMMAMatrixTypePred, "MMAMatrix type">;
115115

116116
// Memref type acceptable to gpu.subgroup_mma_{load|store}_matrix ops.
117-
def GPU_MMAMemRef : MemRefOf<[I8, I32, F16, F32, F64, VectorOfRankAndType<[1], [I8, I32, F16, F32, F64]>]>;
117+
def GPU_MMAMemRef : MemRefOf<[I8, I32, F16, F32, VectorOfRankAndType<[1], [I8, I32, F16, F32]>]>;
118118

119119
class MMAMatrixOf<list<Type> allowedTypes> :
120120
ContainerType<AnyTypeOf<allowedTypes>, IsMMAMatrixTypePred,

mlir/include/mlir/Dialect/GPU/IR/GPUOps.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,7 @@ def GPU_SubgroupMmaStoreMatrixOp : GPU_Op<"subgroup_mma_store_matrix",
18721872
```
18731873
}];
18741874

1875-
let arguments = (ins Arg<MMAMatrixOf<[SI8, UI8, I32, F16, F32, F64]>>:$src,
1875+
let arguments = (ins Arg<MMAMatrixOf<[SI8, UI8, I32, F16, F32]>>:$src,
18761876
Arg<GPU_MMAMemRef, "",[MemWriteAt<0, FullEffect>]>:$dstMemref,
18771877
Variadic<Index>:$indices,
18781878
IndexAttr:$leadDimension,
@@ -1919,9 +1919,9 @@ def GPU_SubgroupMmaComputeOp
19191919
```
19201920
}];
19211921

1922-
let arguments = (ins Arg<MMAMatrixOf<[SI8, UI8, F16, F32, F64]>>:$opA,
1923-
Arg<MMAMatrixOf<[SI8, UI8, F16, F32, F64]>>:$opB,
1924-
Arg<MMAMatrixOf<[I32, F16, F32, F64]>>:$opC,
1922+
let arguments = (ins Arg<MMAMatrixOf<[SI8, UI8, F16, F32]>>:$opA,
1923+
Arg<MMAMatrixOf<[SI8, UI8, F16, F32]>>:$opB,
1924+
Arg<MMAMatrixOf<[I32, F16, F32]>>:$opC,
19251925
OptionalAttr<UnitAttr>:$a_transpose,
19261926
OptionalAttr<UnitAttr>:$b_transpose);
19271927

mlir/lib/Conversion/GPUToNVVM/WmmaOpsToNvvm.cpp

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
1818
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
1919
#include "mlir/IR/TypeUtilities.h"
20-
#include "mlir/IR/Types.h"
2120

2221
using namespace mlir;
2322

@@ -58,8 +57,7 @@ static NVVM::MMATypes getElementType(gpu::MMAMatrixType type) {
5857
if (type.getElementType().isF32())
5958
return type.getOperand() == "COp" ? NVVM::MMATypes::f32
6059
: NVVM::MMATypes::tf32;
61-
if (type.getElementType().isF64())
62-
return NVVM::MMATypes::f64;
60+
6361
if (type.getElementType().isSignedInteger(8))
6462
return NVVM::MMATypes::s8;
6563
if (type.getElementType().isUnsignedInteger(8))
@@ -214,13 +212,8 @@ struct WmmaMmaOpToNVVMLowering
214212
// then passed on to the intrinsic call. Emit llvm ops to extract individual
215213
// values form lowered memrefs.
216214
SmallVector<Value> unpackedOps;
215+
217216
auto unpackOp = [&](Value operand) {
218-
// f64 a and b fragments are not structs but scalars.
219-
if (!isa<LLVM::LLVMStructType>(operand.getType())) {
220-
unpackedOps.push_back(operand);
221-
return;
222-
}
223-
// every other type is lowered to an LLVM struct, extract the values.
224217
auto structType = cast<LLVM::LLVMStructType>(operand.getType());
225218
for (size_t i = 0, e = structType.getBody().size(); i < e; ++i) {
226219
Value toUse = LLVM::ExtractValueOp::create(rewriter, loc, operand, i);
@@ -283,16 +276,10 @@ struct WmmaConstantOpToNVVMLowering
283276
return failure();
284277
Location loc = subgroupMmaConstantOp.getLoc();
285278
Value cst = adaptor.getOperands()[0];
286-
Type type = convertMMAToLLVMType(
279+
LLVM::LLVMStructType type = convertMMAToLLVMType(
287280
cast<gpu::MMAMatrixType>(subgroupMmaConstantOp.getType()));
288-
// If the element is not a struct, it means it's a scalar f64.
289-
auto structType = dyn_cast<LLVM::LLVMStructType>(type);
290-
if (!structType) {
291-
rewriter.replaceOp(subgroupMmaConstantOp, cst);
292-
return success();
293-
}
294281
// If the element type is a vector create a vector from the operand.
295-
if (auto vecType = dyn_cast<VectorType>(structType.getBody()[0])) {
282+
if (auto vecType = dyn_cast<VectorType>(type.getBody()[0])) {
296283
Value vecCst = LLVM::PoisonOp::create(rewriter, loc, vecType);
297284
for (int64_t vecEl = 0; vecEl < vecType.getNumElements(); vecEl++) {
298285
Value idx = LLVM::ConstantOp::create(rewriter, loc,
@@ -302,8 +289,8 @@ struct WmmaConstantOpToNVVMLowering
302289
}
303290
cst = vecCst;
304291
}
305-
Value matrixStruct = LLVM::PoisonOp::create(rewriter, loc, structType);
306-
for (size_t i : llvm::seq(size_t(0), structType.getBody().size())) {
292+
Value matrixStruct = LLVM::PoisonOp::create(rewriter, loc, type);
293+
for (size_t i : llvm::seq(size_t(0), type.getBody().size())) {
307294
matrixStruct =
308295
LLVM::InsertValueOp::create(rewriter, loc, matrixStruct, cst, i);
309296
}
@@ -367,24 +354,10 @@ struct WmmaElementwiseOpToNVVMLowering
367354
return failure();
368355
Location loc = subgroupMmaElementwiseOp.getLoc();
369356
size_t numOperands = adaptor.getOperands().size();
370-
Type destType = convertMMAToLLVMType(
357+
LLVM::LLVMStructType destType = convertMMAToLLVMType(
371358
cast<gpu::MMAMatrixType>(subgroupMmaElementwiseOp.getType()));
372-
373-
// If the element is not a struct, it means it's a scalar f64.
374-
LLVM::LLVMStructType structDestTy =
375-
dyn_cast<LLVM::LLVMStructType>(destType);
376-
if (!structDestTy) {
377-
SmallVector<Value> operands;
378-
for (auto operand : adaptor.getOperands()) {
379-
operands.push_back(operand);
380-
}
381-
Value element = createScalarOp(
382-
rewriter, loc, subgroupMmaElementwiseOp.getOpType(), operands);
383-
rewriter.replaceOp(subgroupMmaElementwiseOp, element);
384-
return success();
385-
}
386-
Value matrixStruct = LLVM::PoisonOp::create(rewriter, loc, structDestTy);
387-
for (size_t i = 0, e = structDestTy.getBody().size(); i < e; ++i) {
359+
Value matrixStruct = LLVM::PoisonOp::create(rewriter, loc, destType);
360+
for (size_t i = 0, e = destType.getBody().size(); i < e; ++i) {
388361
SmallVector<Value> extractedOperands;
389362
for (size_t opIdx = 0; opIdx < numOperands; opIdx++) {
390363
extractedOperands.push_back(LLVM::ExtractValueOp::create(
@@ -404,18 +377,13 @@ struct WmmaElementwiseOpToNVVMLowering
404377
} // namespace
405378

406379
/// Return the LLVMStructureType corresponding to the MMAMatrixType `type`.
407-
Type mlir::convertMMAToLLVMType(gpu::MMAMatrixType type) {
380+
LLVM::LLVMStructType mlir::convertMMAToLLVMType(gpu::MMAMatrixType type) {
408381
NVVM::MMAFrag frag = convertOperand(type.getOperand());
409382
NVVM::MMATypes eltType = getElementType(type);
410383
auto nRow = type.getShape()[0];
411384
auto nCol = type.getShape()[1];
412385
std::pair<Type, unsigned> typeInfo =
413386
NVVM::inferMMAType(eltType, frag, nRow, nCol, type.getContext());
414-
// Special handling for f64 a and b fragments
415-
Type f64Ty = Float64Type::get(type.getContext());
416-
if (typeInfo.first == f64Ty && typeInfo.second == 1) {
417-
return f64Ty;
418-
}
419387
return LLVM::LLVMStructType::getLiteral(
420388
type.getContext(), SmallVector<Type, 8>(typeInfo.second, typeInfo.first));
421389
}

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ Type MMAMatrixType::getElementType() const { return getImpl()->elementType; }
208208
StringRef MMAMatrixType::getOperand() const { return getImpl()->getOperand(); }
209209

210210
bool MMAMatrixType::isValidElementType(Type elementType) {
211-
return elementType.isF16() || elementType.isF32() || elementType.isF64() ||
211+
return elementType.isF16() || elementType.isF32() ||
212212
elementType.isUnsignedInteger(8) || elementType.isSignedInteger(8) ||
213213
elementType.isInteger(32);
214214
}
@@ -225,7 +225,7 @@ MMAMatrixType::verifyInvariants(function_ref<InFlightDiagnostic()> emitError,
225225

226226
if (!MMAMatrixType::isValidElementType(elementType))
227227
return emitError()
228-
<< "MMAMatrixType elements must be SI8, UI8, I32, F16, F32, or F64";
228+
<< "MMAMatrixType elements must be SI8, UI8, I32, F16, or F32";
229229

230230
return success();
231231
}

mlir/test/Conversion/GPUToNVVM/wmma-ops-to-nvvm.mlir

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,6 @@ gpu.module @test_module {
8080

8181
// -----
8282

83-
gpu.module @test_module {
84-
85-
// CHECK-LABEL: func @gpu_wmma_f64_load_op() ->
86-
// CHECK-SAME: f64
87-
// CHECK32-LABEL: func @gpu_wmma_f64_load_op() ->
88-
func.func @gpu_wmma_f64_load_op() -> (!gpu.mma_matrix<8x4xf64, "AOp">) {
89-
%wg = memref.alloca() {alignment = 32} : memref<32x32xf64, 3>
90-
%i = arith.constant 16 : index
91-
%j = arith.constant 16 : index
92-
%0 = gpu.subgroup_mma_load_matrix %wg[%i, %j] {leadDimension = 32 : index} : memref<32x32xf64, 3> -> !gpu.mma_matrix<8x4xf64, "AOp">
93-
return %0 : !gpu.mma_matrix<8x4xf64, "AOp">
94-
// CHECK: %[[MUL:.*]] = llvm.mul %{{.*}}, %{{.*}} : i64
95-
// CHECK: %[[ADD:.*]] = llvm.add %[[MUL]], %{{.*}} : i64
96-
// CHECK: %[[GEP:.*]] = llvm.getelementptr %{{.*}}[%[[ADD]]] : (!llvm.ptr<3>, i64) -> !llvm.ptr<3>, f64
97-
// CHECK: %[[C32_I32:.*]] = llvm.mlir.constant(32 : index) : i32
98-
// CHECK: %[[LOAD:.*]] = nvvm.wmma.load %[[GEP]], %[[C32_I32]] {eltype = #nvvm.mma_type<f64>, frag = #nvvm.mma_frag<a>, k = 4 : i32, layout = #nvvm.mma_layout<row>, m = 8 : i32, n = 8 : i32} : (!llvm.ptr<3>) -> f64
99-
// CHECK: llvm.return %[[LOAD]] : f64
100-
}
101-
}
102-
103-
// -----
104-
10583
gpu.module @test_module {
10684

10785
// CHECK-LABEL: func @gpu_wmma_store_op

mlir/test/Dialect/GPU/invalid.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ func.func @mmamatrix_operand_type(){
688688
func.func @mmamatrix_invalid_element_type(){
689689
%wg = memref.alloca() {alignment = 32} : memref<32x32xf16, 3>
690690
%i = arith.constant 16 : index
691-
// expected-error @+1 {{MMAMatrixType elements must be SI8, UI8, I32, F16, F32, or F64}}
691+
// expected-error @+1 {{MMAMatrixType elements must be SI8, UI8, I32, F16, or F32}}
692692
%0 = gpu.subgroup_mma_load_matrix %wg[%i, %i] {leadDimension = 32 : index} : memref<32x32xf16, 3> -> !gpu.mma_matrix<16x16xbf16, "AOp">
693693
return
694694
}
@@ -708,7 +708,7 @@ func.func @mmaLoadOp_identity_layout(){
708708
// -----
709709

710710
func.func @mma_invalid_memref_type(%src: memref<32x4xvector<4x8xf32>>, %i: index) {
711-
// expected-error @+1 {{operand #0 must be memref of 8-bit signless integer or 32-bit signless integer or 16-bit float or 32-bit float or 64-bit float or vector of 8-bit signless integer or 32-bit signless integer or 16-bit float or 32-bit float or 64-bit float values of ranks 1 values}}
711+
// expected-error @+1 {{operand #0 must be memref of 8-bit signless integer or 32-bit signless integer or 16-bit float or 32-bit float or vector of 8-bit signless integer or 32-bit signless integer or 16-bit float or 32-bit float values of ranks 1 values}}
712712
%0 = gpu.subgroup_mma_load_matrix %src[%i, %i] {leadDimension = 4 : index} : memref<32x4xvector<4x8xf32>> -> !gpu.mma_matrix<16x16xf16, "AOp">
713713
return
714714
}

mlir/test/Integration/GPU/CUDA/TensorCore/wmma-matmul-f64.mlir

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)