|
| 1 | +// RUN: triton-opt %s -split-input-file --tritonamdgpu-accelerate-matmul='arch-generation-name=gfx940 matrix-instruction-size=16' | FileCheck %s --check-prefixes MFMA16,CHECK |
| 2 | +// RUN: triton-opt %s -split-input-file --tritonamdgpu-accelerate-matmul='arch-generation-name=gfx940 matrix-instruction-size=32' | FileCheck %s --check-prefixes MFMA32,CHECK |
| 3 | + |
| 4 | +// Check the warpsPerCTA parameter of #mma layout of the two dot's. |
| 5 | +// The 1st dot always has warpsPerCTA = [4, 1]. |
| 6 | +// The warpsPerCTA for the 2nd dot depends on mfma instruction size and BLOCK_M size. |
| 7 | + |
| 8 | + |
| 9 | +// BLOCK_M = 128 |
| 10 | +// warpsPerCTA = [4, 1] for mfma16 and mfma32 |
| 11 | +#blocked = #ttg.blocked<{sizePerThread = [1, 4], threadsPerWarp = [16, 4], warpsPerCTA = [4, 1], order = [1, 0]}> |
| 12 | +#dotOp0 = #ttg.dot_op<{opIdx = 0, parent = #blocked}> |
| 13 | +#dotOp1 = #ttg.dot_op<{opIdx = 1, parent = #blocked}> |
| 14 | +// MFMA16{LITERAL}: #mma = #ttg.amd_mfma<{versionMajor = 3, versionMinor = 0, warpsPerCTA = [4, 1], instrShape = [16, 16], isTransposed = true}> |
| 15 | +// MFMA32{LITERAL}: #mma = #ttg.amd_mfma<{versionMajor = 3, versionMinor = 0, warpsPerCTA = [4, 1], instrShape = [32, 32], isTransposed = true}> |
| 16 | +// CHECK-LABEL: mfma_chain_dot_BM128 |
| 17 | +// CHECK: tt.dot {{.*}} : {{.*}} -> tensor<128x16xf32, #mma> |
| 18 | +// CHECK: tt.dot {{.*}} : {{.*}} -> tensor<128x128xf32, #mma> |
| 19 | +module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 4 : i32, ttg.target = "hip:gfx942", "ttg.threads-per-warp" = 64 : i32} { |
| 20 | + tt.func public @mfma_chain_dot_BM128( |
| 21 | + %q: tensor<128x128xf16, #dotOp0>, |
| 22 | + %k: tensor<128x16xf16, #dotOp1>, |
| 23 | + %v: tensor<16x128xf16, #dotOp1>, |
| 24 | + %o_ptr: tensor<128x128x!tt.ptr<f32>, #blocked>) { |
| 25 | + %cst = arith.constant dense<0.000000e+00> : tensor<128x16xf32, #blocked> |
| 26 | + %cst1 = arith.constant dense<0.000000e+00> : tensor<128x128xf32, #blocked> |
| 27 | + %qk = tt.dot %q, %k, %cst : tensor<128x128xf16, #dotOp0> * tensor<128x16xf16, #dotOp1> -> tensor<128x16xf32, #blocked> |
| 28 | + %qk_f16 = arith.truncf %qk : tensor<128x16xf32, #blocked> to tensor<128x16xf16, #blocked> |
| 29 | + %p = ttg.convert_layout %qk_f16 : tensor<128x16xf16, #blocked> -> tensor<128x16xf16, #dotOp0> |
| 30 | + %o = tt.dot %p, %v, %cst1 : tensor<128x16xf16, #dotOp0> * tensor<16x128xf16, #dotOp1> -> tensor<128x128xf32, #blocked> |
| 31 | + tt.store %o_ptr, %o : tensor<128x128x!tt.ptr<f32>, #blocked> |
| 32 | + tt.return |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | + |
| 37 | +// ----- |
| 38 | + |
| 39 | +// BLOCK_M = 64 |
| 40 | +// warpsPerCTA = [4, 1] for mfma16 |
| 41 | +// warpsPerCTA = [2, 2] for mfma32 |
| 42 | +#blocked = #ttg.blocked<{sizePerThread = [1, 4], threadsPerWarp = [16, 4], warpsPerCTA = [4, 1], order = [1, 0]}> |
| 43 | +#dotOp0 = #ttg.dot_op<{opIdx = 0, parent = #blocked}> |
| 44 | +#dotOp1 = #ttg.dot_op<{opIdx = 1, parent = #blocked}> |
| 45 | +// MFMA16{LITERAL}: #mma = #ttg.amd_mfma<{versionMajor = 3, versionMinor = 0, warpsPerCTA = [4, 1], instrShape = [16, 16], isTransposed = true}> |
| 46 | +// MFMA32{LITERAL}: #mma = #ttg.amd_mfma<{versionMajor = 3, versionMinor = 0, warpsPerCTA = [4, 1], instrShape = [32, 32], isTransposed = true}> |
| 47 | +// MFMA32{LITERAL}: #mma1 = #ttg.amd_mfma<{versionMajor = 3, versionMinor = 0, warpsPerCTA = [2, 2], instrShape = [32, 32], isTransposed = true}> |
| 48 | +// CHECK-LABEL: mfma_chain_dot_BM64 |
| 49 | +// CHECK: tt.dot {{.*}} : {{.*}} -> tensor<64x16xf32, #mma> |
| 50 | +// MFMA16: tt.dot {{.*}} : {{.*}} -> tensor<64x128xf32, #mma> |
| 51 | +// MFMA32: tt.dot {{.*}} : {{.*}} -> tensor<64x128xf32, #mma1> |
| 52 | +module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 4 : i32, ttg.target = "hip:gfx942", "ttg.threads-per-warp" = 64 : i32} { |
| 53 | + tt.func public @mfma_chain_dot_BM64( |
| 54 | + %q: tensor<64x128xf16, #dotOp0>, |
| 55 | + %k: tensor<128x16xf16, #dotOp1>, |
| 56 | + %v: tensor<16x128xf16, #dotOp1>, |
| 57 | + %o_ptr: tensor<64x128x!tt.ptr<f32>, #blocked>) { |
| 58 | + %cst = arith.constant dense<0.000000e+00> : tensor<64x16xf32, #blocked> |
| 59 | + %cst1 = arith.constant dense<0.000000e+00> : tensor<64x128xf32, #blocked> |
| 60 | + %qk = tt.dot %q, %k, %cst : tensor<64x128xf16, #dotOp0> * tensor<128x16xf16, #dotOp1> -> tensor<64x16xf32, #blocked> |
| 61 | + %qk_f16 = arith.truncf %qk : tensor<64x16xf32, #blocked> to tensor<64x16xf16, #blocked> |
| 62 | + %p = ttg.convert_layout %qk_f16 : tensor<64x16xf16, #blocked> -> tensor<64x16xf16, #dotOp0> |
| 63 | + %o = tt.dot %p, %v, %cst1 : tensor<64x16xf16, #dotOp0> * tensor<16x128xf16, #dotOp1> -> tensor<64x128xf32, #blocked> |
| 64 | + tt.store %o_ptr, %o : tensor<64x128x!tt.ptr<f32>, #blocked> |
| 65 | + tt.return |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | + |
| 70 | +// ----- |
| 71 | + |
| 72 | +// BLOCK_M = 32 |
| 73 | +// warpsPerCTA = [2, 2] for mfma16 |
| 74 | +// warpsPerCTA = [1, 4] for mfma32 |
| 75 | +#blocked = #ttg.blocked<{sizePerThread = [1, 4], threadsPerWarp = [16, 4], warpsPerCTA = [4, 1], order = [1, 0]}> |
| 76 | +#dotOp0 = #ttg.dot_op<{opIdx = 0, parent = #blocked}> |
| 77 | +#dotOp1 = #ttg.dot_op<{opIdx = 1, parent = #blocked}> |
| 78 | +// MFMA16{LITERAL}: #mma = #ttg.amd_mfma<{versionMajor = 3, versionMinor = 0, warpsPerCTA = [4, 1], instrShape = [16, 16], isTransposed = true}> |
| 79 | +// MFMA32{LITERAL}: #mma = #ttg.amd_mfma<{versionMajor = 3, versionMinor = 0, warpsPerCTA = [4, 1], instrShape = [32, 32], isTransposed = true}> |
| 80 | +// MFMA16{LITERAL}: #mma1 = #ttg.amd_mfma<{versionMajor = 3, versionMinor = 0, warpsPerCTA = [2, 2], instrShape = [16, 16], isTransposed = true}> |
| 81 | +// MFMA32{LITERAL}: #mma1 = #ttg.amd_mfma<{versionMajor = 3, versionMinor = 0, warpsPerCTA = [1, 4], instrShape = [32, 32], isTransposed = true}> |
| 82 | +// CHECK-LABEL: mfma_chain_dot_BM32 |
| 83 | +// CHECK: tt.dot {{.*}} : {{.*}} -> tensor<32x16xf32, #mma> |
| 84 | +// MFMA16: tt.dot {{.*}} : {{.*}} -> tensor<32x128xf32, #mma1> |
| 85 | +// MFMA32: tt.dot {{.*}} : {{.*}} -> tensor<32x128xf32, #mma1> |
| 86 | +module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 4 : i32, ttg.target = "hip:gfx942", "ttg.threads-per-warp" = 64 : i32} { |
| 87 | + tt.func public @mfma_chain_dot_BM32( |
| 88 | + %q: tensor<32x128xf16, #dotOp0>, |
| 89 | + %k: tensor<128x16xf16, #dotOp1>, |
| 90 | + %v: tensor<16x128xf16, #dotOp1>, |
| 91 | + %o_ptr: tensor<32x128x!tt.ptr<f32>, #blocked>) { |
| 92 | + %cst = arith.constant dense<0.000000e+00> : tensor<32x16xf32, #blocked> |
| 93 | + %cst1 = arith.constant dense<0.000000e+00> : tensor<32x128xf32, #blocked> |
| 94 | + %qk = tt.dot %q, %k, %cst : tensor<32x128xf16, #dotOp0> * tensor<128x16xf16, #dotOp1> -> tensor<32x16xf32, #blocked> |
| 95 | + %qk_f16 = arith.truncf %qk : tensor<32x16xf32, #blocked> to tensor<32x16xf16, #blocked> |
| 96 | + %p = ttg.convert_layout %qk_f16 : tensor<32x16xf16, #blocked> -> tensor<32x16xf16, #dotOp0> |
| 97 | + %o = tt.dot %p, %v, %cst1 : tensor<32x16xf16, #dotOp0> * tensor<16x128xf16, #dotOp1> -> tensor<32x128xf32, #blocked> |
| 98 | + tt.store %o_ptr, %o : tensor<32x128x!tt.ptr<f32>, #blocked> |
| 99 | + tt.return |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | + |
| 104 | +// ----- |
| 105 | + |
| 106 | +// BLOCK_M = 16, only check mfma16 since it's too small for mfma32 |
| 107 | +// warpsPerCTA = [1, 4] for mfma16 |
| 108 | +#blocked = #ttg.blocked<{sizePerThread = [1, 4], threadsPerWarp = [16, 4], warpsPerCTA = [4, 1], order = [1, 0]}> |
| 109 | +#dotOp0 = #ttg.dot_op<{opIdx = 0, parent = #blocked}> |
| 110 | +#dotOp1 = #ttg.dot_op<{opIdx = 1, parent = #blocked}> |
| 111 | +// MFMA16{LITERAL}: #mma = #ttg.amd_mfma<{versionMajor = 3, versionMinor = 0, warpsPerCTA = [4, 1], instrShape = [16, 16], isTransposed = true}> |
| 112 | +// MFMA16{LITERAL}: #mma1 = #ttg.amd_mfma<{versionMajor = 3, versionMinor = 0, warpsPerCTA = [1, 4], instrShape = [16, 16], isTransposed = true}> |
| 113 | +// CHECK-LABEL: mfma_chain_dot_BM16 |
| 114 | +// CHECK: tt.dot {{.*}} : {{.*}} -> tensor<16x16xf32, #mma> |
| 115 | +// MFMA16: tt.dot {{.*}} : {{.*}} -> tensor<16x128xf32, #mma1> |
| 116 | +module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 4 : i32, ttg.target = "hip:gfx942", "ttg.threads-per-warp" = 64 : i32} { |
| 117 | + tt.func public @mfma_chain_dot_BM16( |
| 118 | + %q: tensor<16x128xf16, #dotOp0>, |
| 119 | + %k: tensor<128x16xf16, #dotOp1>, |
| 120 | + %v: tensor<16x128xf16, #dotOp1>, |
| 121 | + %o_ptr: tensor<16x128x!tt.ptr<f32>, #blocked>) { |
| 122 | + %cst = arith.constant dense<0.000000e+00> : tensor<16x16xf32, #blocked> |
| 123 | + %cst1 = arith.constant dense<0.000000e+00> : tensor<16x128xf32, #blocked> |
| 124 | + %qk = tt.dot %q, %k, %cst : tensor<16x128xf16, #dotOp0> * tensor<128x16xf16, #dotOp1> -> tensor<16x16xf32, #blocked> |
| 125 | + %qk_f16 = arith.truncf %qk : tensor<16x16xf32, #blocked> to tensor<16x16xf16, #blocked> |
| 126 | + %p = ttg.convert_layout %qk_f16 : tensor<16x16xf16, #blocked> -> tensor<16x16xf16, #dotOp0> |
| 127 | + %o = tt.dot %p, %v, %cst1 : tensor<16x16xf16, #dotOp0> * tensor<16x128xf16, #dotOp1> -> tensor<16x128xf32, #blocked> |
| 128 | + tt.store %o_ptr, %o : tensor<16x128x!tt.ptr<f32>, #blocked> |
| 129 | + tt.return |
| 130 | + } |
| 131 | +} |
0 commit comments