Skip to content

Commit 508ba41

Browse files
arsenmPravin Jagtap
authored andcommitted
AMDGPU: Add first gfx950 mfma instructions (llvm#116312)
Scheduling info and hazards are wrong and TBD.
1 parent a006beb commit 508ba41

File tree

16 files changed

+596
-3
lines changed

16 files changed

+596
-3
lines changed

clang/include/clang/Basic/BuiltinsAMDGPU.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,12 @@ TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_fp8_f32, "iffiIb", "nc", "fp8-conversion-
431431
TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_bf8_f32, "ifiiIi", "nc", "fp8-conversion-insts")
432432
TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_fp8_f32, "ifiiIi", "nc", "fp8-conversion-insts")
433433

434+
//===----------------------------------------------------------------------===//
435+
// GFX950 only builtins.
436+
//===----------------------------------------------------------------------===//
437+
TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_16x16x32_f16, "V4fV8hV8hV4fIiIiIi", "nc", "gfx950-insts")
438+
TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_32x32x16_f16, "V16fV8hV8hV16fIiIiIi", "nc", "gfx950-insts")
439+
434440
//===----------------------------------------------------------------------===//
435441
// GFX12+ only builtins.
436442
//===----------------------------------------------------------------------===//

clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx908 -DMFMA_GFX908_TESTS -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-GFX908
33
// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx90a -DMFMA_GFX90A_TESTS -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-GFX90A
44
// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx940 -DMFMA_GFX940_TESTS -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-GFX940
5+
// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx950 -DMFMA_GFX950_TESTS -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-GFX950
56

67
#pragma OPENCL EXTENSION cl_khr_fp64:enable
78

@@ -222,7 +223,7 @@ void test_mfma_f64_4x4x4f64(global double* out, double a, double b, double c)
222223

223224
#endif // MFMA_GFX90A_TESTS
224225

225-
#ifdef MFMA_GFX940_TESTS
226+
#if defined(MFMA_GFX940_TESTS) || defined(MFMA_GFX950_TESTS)
226227
// CHECK-GFX940-LABEL: @test_mfma_i32_16x16x32_i8
227228
// CHECK-GFX940: call <4 x i32> @llvm.amdgcn.mfma.i32.16x16x32.i8(i64 %a, i64 %b, <4 x i32> %c, i32 0, i32 0, i32 0)
228229
void test_mfma_i32_16x16x32_i8(global v4i* out, long a, long b, v4i c)
@@ -404,4 +405,24 @@ void test_smfmac_f32_32x32x32_fp8_fp8(global v16f* out, v2i a, v4i b, v16f c, in
404405
{
405406
*out = __builtin_amdgcn_smfmac_f32_32x32x32_fp8_fp8(a, b, c, idx, 0, 0);
406407
}
407-
#endif // MFMA_GFX940_TESTS
408+
#endif // defined(MFMA_GFX940_TESTS) || defined(MFMA_GFX950_TESTS)
409+
410+
#ifdef MFMA_GFX950_TESTS
411+
412+
// CHECK-GFX950-LABEL: @test_mfma_f32_16x16x32_f16(
413+
// CHECK-GFX950: tail call <4 x float> @llvm.amdgcn.mfma.f32.16x16x32.f16(<8 x half> %a, <8 x half> %b, <4 x float> %c, i32 1, i32 2, i32 3)
414+
415+
v4f test_mfma_f32_16x16x32_f16(v8h a, v8h b, v4f c)
416+
{
417+
return __builtin_amdgcn_mfma_f32_16x16x32_f16(a, b, c, 1, 2, 3);
418+
}
419+
420+
// CHECK-GFX950-LABEL: @test_mfma_f32_32x32x16_f16
421+
// CHECK-GFX950: tail call <16 x float> @llvm.amdgcn.mfma.f32.32x32x16.f16(<8 x half> %a, <8 x half> %b, <16 x float> %c, i32 1, i32 2, i32 3)
422+
v16f test_mfma_f32_32x32x16_f16(v8h a, v8h b, v16f c)
423+
{
424+
return __builtin_amdgcn_mfma_f32_32x32x16_f16(a, b, c, 1, 2, 3);
425+
}
426+
427+
428+
#endif
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// REQUIRES: amdgpu-registered-target
2+
// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx950 -verify -S -o - %s
3+
4+
typedef float float4 __attribute__((ext_vector_type(4)));
5+
typedef float float16 __attribute__((ext_vector_type(16)));
6+
typedef half half8 __attribute__((ext_vector_type(8)));
7+
8+
9+
void test_mfma_f32_16x16x32_f16(__global float4* out, half8 a, half8 b, float4 c, int X) {
10+
11+
*out = __builtin_amdgcn_mfma_f32_16x16x32_f16(a, b, c, X, 0, 0); // expected-error{{argument to '__builtin_amdgcn_mfma_f32_16x16x32_f16' must be a constant integer}}
12+
*out = __builtin_amdgcn_mfma_f32_16x16x32_f16(a, b, c, 0, X, 0); // expected-error{{argument to '__builtin_amdgcn_mfma_f32_16x16x32_f16' must be a constant integer}}
13+
*out = __builtin_amdgcn_mfma_f32_16x16x32_f16(a, b, c, 0, 0, X); // expected-error{{argument to '__builtin_amdgcn_mfma_f32_16x16x32_f16' must be a constant integer}}
14+
}
15+
16+
17+
void test_mfma_f32_32x32x16_f16(__global float16* out, half8 a, half8 b, float16 c, int X) {
18+
*out = __builtin_amdgcn_mfma_f32_32x32x16_f16(a, b, c, X, 0, 0); // expected-error{{argument to '__builtin_amdgcn_mfma_f32_32x32x16_f16' must be a constant integer}}
19+
*out = __builtin_amdgcn_mfma_f32_32x32x16_f16(a, b, c, 0, X, 0); // expected-error{{argument to '__builtin_amdgcn_mfma_f32_32x32x16_f16' must be a constant integer}}
20+
*out = __builtin_amdgcn_mfma_f32_32x32x16_f16(a, b, c, 0, 0, X); // expected-error{{argument to '__builtin_amdgcn_mfma_f32_32x32x16_f16' must be a constant integer}}
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// REQUIRES: amdgpu-registered-target
2+
// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx940 -verify -S -o - %s
3+
4+
typedef float float4 __attribute__((ext_vector_type(4)));
5+
typedef float float16 __attribute__((ext_vector_type(16)));
6+
typedef half half8 __attribute__((ext_vector_type(8)));
7+
8+
void test(__global float4* out0, half8 a0, half8 b0, float4 c0,
9+
__global float16* out1, half8 a1, half8 b1, float16 c1) {
10+
*out0 = __builtin_amdgcn_mfma_f32_16x16x32_f16(a0, b0, c0, 0, 0, 0); // expected-error{{'__builtin_amdgcn_mfma_f32_16x16x32_f16' needs target feature gfx950-insts}}
11+
*out1 = __builtin_amdgcn_mfma_f32_32x32x16_f16(a1, b1, c1, 0, 0, 0); // expected-error{{'__builtin_amdgcn_mfma_f32_32x32x16_f16' needs target feature gfx950-insts}}
12+
}

llvm/include/llvm/IR/IntrinsicsAMDGPU.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3139,6 +3139,15 @@ def int_amdgcn_cvt_sr_fp8_f32 : ClangBuiltin<"__builtin_amdgcn_cvt_sr_fp8_f32">,
31393139
[llvm_float_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
31403140
[IntrNoMem, ImmArg<ArgIndex<3>>]>;
31413141

3142+
//===----------------------------------------------------------------------===//
3143+
// gfx950 intrinsics
3144+
//===----------------------------------------------------------------------===//
3145+
3146+
defset list<Intrinsic> AMDGPUMFMAIntrinsics950 = {
3147+
def int_amdgcn_mfma_f32_16x16x32_f16 : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_v8f16_ty>;
3148+
def int_amdgcn_mfma_f32_32x32x16_f16 : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_v8f16_ty>;
3149+
}
3150+
31423151
//===----------------------------------------------------------------------===//
31433152
// Special Intrinsics for backend internal use only. No frontend
31443153
// should emit calls to these.

llvm/lib/Target/AMDGPU/AMDGPU.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,14 @@ def isGFX940Plus :
19801980
Predicate<"Subtarget->hasGFX940Insts()">,
19811981
AssemblerPredicate<(all_of FeatureGFX940Insts)>;
19821982

1983+
def isNotGFX940Plus :
1984+
Predicate<"!Subtarget->hasGFX940Insts()">,
1985+
AssemblerPredicate<(all_of (not FeatureGFX940Insts))>;
1986+
1987+
def HasGFX950Insts :
1988+
Predicate<"Subtarget->hasGFX950Insts()">,
1989+
AssemblerPredicate<(all_of FeatureGFX950Insts)>;
1990+
19831991
def isGFX8GFX9NotGFX940 :
19841992
Predicate<"!Subtarget->hasGFX940Insts() &&"
19851993
"(Subtarget->getGeneration() == AMDGPUSubtarget::VOLCANIC_ISLANDS ||"

llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4724,7 +4724,9 @@ AMDGPURegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
47244724
case Intrinsic::amdgcn_mfma_f32_32x32x16_bf8_bf8:
47254725
case Intrinsic::amdgcn_mfma_f32_32x32x16_bf8_fp8:
47264726
case Intrinsic::amdgcn_mfma_f32_32x32x16_fp8_bf8:
4727-
case Intrinsic::amdgcn_mfma_f32_32x32x16_fp8_fp8: {
4727+
case Intrinsic::amdgcn_mfma_f32_32x32x16_fp8_fp8:
4728+
case Intrinsic::amdgcn_mfma_f32_16x16x32_f16:
4729+
case Intrinsic::amdgcn_mfma_f32_32x32x16_f16: {
47284730
// Default for MAI intrinsics.
47294731
// srcC can also be an immediate which can be folded later.
47304732
// FIXME: Should we eventually add an alternative mapping with AGPR src

llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ foreach intr = AMDGPUMFMAIntrinsics90A in
341341
def : SourceOfDivergence<intr>;
342342
foreach intr = AMDGPUMFMAIntrinsics940 in
343343
def : SourceOfDivergence<intr>;
344+
foreach intr = AMDGPUMFMAIntrinsics950 in
345+
def : SourceOfDivergence<intr>;
344346
foreach intr = AMDGPUWMMAIntrinsicsGFX11 in
345347
def : SourceOfDivergence<intr>;
346348
foreach intr = AMDGPUWMMAIntrinsicsGFX12 in

llvm/lib/Target/AMDGPU/GCNSubtarget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,10 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
12841284
// hasGFX90AInsts is also true.
12851285
bool hasGFX940Insts() const { return GFX940Insts; }
12861286

1287+
// GFX950 is a derivation to GFX940. hasGFX950Insts() implies that
1288+
// hasGFX940Insts and hasGFX90AInsts are also true.
1289+
bool hasGFX950Insts() const { return GFX950Insts; }
1290+
12871291
bool hasSALUFloatInsts() const { return HasSALUFloatInsts; }
12881292

12891293
bool hasVGPRSingleUseHintInsts() const { return HasVGPRSingleUseHintInsts; }

llvm/lib/Target/AMDGPU/SIInstrInfo.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,6 +2645,10 @@ def VOP_V16I32_V2I32_V4I32_I32 : VOPProfile <[v16i32, v2i32, v4i32, i32]>;
26452645
def VOP_V4F32_V2I32_V4I32_I32 : VOPProfile <[v4f32, v2i32, v4i32, i32]>;
26462646
def VOP_V16F32_V2I32_V4I32_I32 : VOPProfile <[v16f32, v2i32, v4i32, i32]>;
26472647

2648+
def VOP_V4F32_V8F16_V8F16_V4F32 : VOPProfile <[v4f32, v8f16, v8f16, v4f32]>;
2649+
def VOP_V16F32_V8F16_V8F16_V16F32 : VOPProfile <[v16f32, v8f16, v8f16, v16f32]>;
2650+
2651+
26482652
class Commutable_REV <string revOp, bit isOrig> {
26492653
string RevOp = revOp;
26502654
bit IsOrig = isOrig;

0 commit comments

Comments
 (0)