|
| 1 | +// RUN: triton-opt %s -split-input-file --tritonamdgpu-coalesce-async-copy=arch-generation-name=gfx950 | FileCheck %s |
| 2 | + |
| 3 | +#blocked = #ttg.blocked<{sizePerThread = [4], threadsPerWarp = [32], warpsPerCTA = [4], order = [0]}> |
| 4 | +#shared = #ttg.swizzled_shared<{vec = 1, perPhase = 1, maxPhase = 1, order = [0]}> |
| 5 | +#smem = #ttg.shared_memory |
| 6 | +module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 4 : i32} { |
| 7 | +// sizePerThread = [1] because we have no information about contiguity of src pointers |
| 8 | +// CHECK: #[[NEW_BLOCKED:.*]] = #ttg.blocked<{sizePerThread = [1], threadsPerWarp = [32], warpsPerCTA = [4], order = [0]}> |
| 9 | +tt.func @async_copy_1d(%input: tensor<1024x!tt.ptr<f16>, #blocked>, |
| 10 | + %view: !ttg.memdesc<1024xf16, #shared, #smem, mutable>) { |
| 11 | + // CHECK: %{{.*}} = ttg.convert_layout %{{.*}} : {{.*}} -> tensor<1024x!tt.ptr<f16>, #[[NEW_BLOCKED]]> |
| 12 | + // CHECK: %{{.*}} = ttg.async_copy_global_to_local %{{.*}}: tensor<1024x!tt.ptr<f16>, #[[NEW_BLOCKED]]> |
| 13 | + %token = ttg.async_copy_global_to_local %input, %view: tensor<1024x!tt.ptr<f16>, #blocked> -> <1024xf16, #shared, #smem, mutable> |
| 14 | + tt.return |
| 15 | +} |
| 16 | +} |
| 17 | + |
| 18 | +// ----- |
| 19 | + |
| 20 | +#blocked = #ttg.blocked<{sizePerThread = [1, 4], threadsPerWarp = [4, 8], warpsPerCTA = [4, 1], order = [1, 0]}> |
| 21 | +#shared = #ttg.swizzled_shared<{vec = 1, perPhase = 1, maxPhase = 1, order = [1, 0]}> |
| 22 | +#smem = #ttg.shared_memory |
| 23 | +module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 4 : i32} { |
| 24 | +// sizePerThread = [1, 1] because we have no information about contiguity of src pointers |
| 25 | +// CHECK: #[[NEW_BLOCKED:.*]] = #ttg.blocked<{sizePerThread = [1, 1], threadsPerWarp = [1, 32], warpsPerCTA = [2, 2], order = [1, 0]}> |
| 26 | +tt.func @async_copy_2d(%input: tensor<64x64x!tt.ptr<f16>, #blocked>, |
| 27 | + %view: !ttg.memdesc<64x64xf16, #shared, #smem, mutable>) { |
| 28 | + // CHECK: %{{.*}} = ttg.convert_layout %{{.*}} : {{.*}} -> tensor<64x64x!tt.ptr<f16>, #[[NEW_BLOCKED]]> |
| 29 | + // CHECK: %{{.*}} = ttg.async_copy_global_to_local %{{.*}}: tensor<64x64x!tt.ptr<f16>, #[[NEW_BLOCKED]]> |
| 30 | + %token = ttg.async_copy_global_to_local %input, %view: tensor<64x64x!tt.ptr<f16>, #blocked> -> <64x64xf16, #shared, #smem, mutable> |
| 31 | + tt.return |
| 32 | +} |
| 33 | +} |
| 34 | + |
| 35 | +// ----- |
| 36 | + |
| 37 | +#blocked = #ttg.blocked<{sizePerThread = [8, 1, 1], threadsPerWarp = [32, 1, 1], warpsPerCTA = [1,2,2], order = [0,1,2]}> |
| 38 | +#shared = #ttg.swizzled_shared<{vec = 1, perPhase = 1, maxPhase = 1, order = [0,1,2]}> |
| 39 | +#smem = #ttg.shared_memory |
| 40 | +module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 4 : i32} { |
| 41 | +// sizePerThread = [1, 1, 1] because we have no information about contiguity of src pointers |
| 42 | +// CHECK: #[[NEW_BLOCKED:.*]] = #ttg.blocked<{sizePerThread = [1, 1, 1], threadsPerWarp = [32, 1, 1], warpsPerCTA = [4, 1, 1], order = [0, 1, 2]}> |
| 43 | +tt.func @async_copy_3d(%input: tensor<1024x1024x1024x!tt.ptr<f16>, #blocked>, |
| 44 | + %view: !ttg.memdesc<1024x1024x1024xf16, #shared, #smem, mutable>) { |
| 45 | + // CHECK: %{{.*}} = ttg.convert_layout %{{.*}} : {{.*}} -> tensor<1024x1024x1024x!tt.ptr<f16>, #[[NEW_BLOCKED]]> |
| 46 | + // CHECK: %{{.*}} = ttg.async_copy_global_to_local %{{.*}}: tensor<1024x1024x1024x!tt.ptr<f16>, #[[NEW_BLOCKED]]> |
| 47 | + %token = ttg.async_copy_global_to_local %input, %view: tensor<1024x1024x1024x!tt.ptr<f16>, #blocked> -> <1024x1024x1024xf16, #shared, #smem, mutable> |
| 48 | + tt.return |
| 49 | +} |
| 50 | +} |
| 51 | + |
| 52 | +// ----- |
| 53 | + |
| 54 | +#blocked = #ttg.blocked<{sizePerThread = [1, 4], threadsPerWarp = [4, 8], warpsPerCTA = [4, 1], order = [1, 0]}> |
| 55 | +#shared = #ttg.swizzled_shared<{vec = 1, perPhase = 1, maxPhase = 1, order = [1, 0]}> |
| 56 | +#smem = #ttg.shared_memory |
| 57 | +module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 4 : i32} { |
| 58 | +// CHECK: #[[NEW_BLOCKED:.*]] = #ttg.blocked<{sizePerThread = [1, 1], threadsPerWarp = [1, 32], warpsPerCTA = [2, 2], order = [1, 0]}> |
| 59 | +tt.func @async_copy_with_mask_and_other(%input: tensor<64x64x!tt.ptr<f16>, #blocked>, |
| 60 | + %view: !ttg.memdesc<64x64xf16, #shared, #smem, mutable>, |
| 61 | + %mask: tensor<64x64xi1, #blocked>, |
| 62 | + %other: tensor<64x64xf16, #blocked>) { |
| 63 | + // CHECK: %{{.*}} = ttg.convert_layout %{{.*}} : {{.*}} -> tensor<64x64x!tt.ptr<f16>, #[[NEW_BLOCKED]]> |
| 64 | + // CHECK: %{{.*}} = ttg.convert_layout %{{.*}} : {{.*}} -> tensor<64x64xi1, #[[NEW_BLOCKED]]> |
| 65 | + // CHECK: %{{.*}} = ttg.convert_layout %{{.*}} : {{.*}} -> tensor<64x64xf16, #[[NEW_BLOCKED]]> |
| 66 | + // CHECK: %{{.*}} = ttg.async_copy_global_to_local %{{.*}}: tensor<64x64x!tt.ptr<f16>, #[[NEW_BLOCKED]]> |
| 67 | + %token = ttg.async_copy_global_to_local %input, %view mask %mask other %other: tensor<64x64x!tt.ptr<f16>, #blocked> -> <64x64xf16, #shared, #smem, mutable> |
| 68 | + tt.return |
| 69 | +} |
| 70 | +} |
| 71 | + |
| 72 | +// ----- |
| 73 | + |
| 74 | +#blocked = #ttg.blocked<{sizePerThread = [1, 4], threadsPerWarp = [4, 16], warpsPerCTA = [4, 1], order = [1, 0]}> |
| 75 | +#shared = #ttg.swizzled_shared<{vec = 1, perPhase = 1, maxPhase = 1, order = [1, 0]}> |
| 76 | +#smem = #ttg.shared_memory |
| 77 | +module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 4 : i32, ttg.shared = 8192 : i32, ttg.target = "hip:gfx942", "ttg.threads-per-warp" = 64 : i32} { |
| 78 | + // Clip to vector size 2 (32bit) because we do not support 64 bit loads to lds |
| 79 | + // CHECK: #[[NEW_BLOCKED:.*]] = #ttg.blocked<{sizePerThread = [1, 2], threadsPerWarp = [2, 32], warpsPerCTA = [4, 1], order = [1, 0]}> |
| 80 | + tt.func public @async_copy_vector_size_2(%arg0: !tt.ptr<f16> {tt.divisibility = 16 : i32, tt.pointer_range = 32 : i32}, |
| 81 | + %arg1: i32 {tt.divisibility = 16 : i32}, |
| 82 | + %arg2: !ttg.memdesc<32x64xf16, #shared, #smem, mutable>) { |
| 83 | + // We need the index calculation so AxisAnalysis sees that we can vectorize the load |
| 84 | + %1 = tt.make_range {end = 64 : i32, start = 0 : i32} : tensor<64xi32, #ttg.slice<{dim = 0, parent = #blocked}>> |
| 85 | + %2 = tt.expand_dims %1 {axis = 0 : i32} : tensor<64xi32, #ttg.slice<{dim = 0, parent = #blocked}>> -> tensor<1x64xi32, #blocked> |
| 86 | + %3 = tt.broadcast %2 : tensor<1x64xi32, #blocked> -> tensor<32x64xi32, #blocked> |
| 87 | + %4 = tt.splat %arg0 : !tt.ptr<f16> -> tensor<32x64x!tt.ptr<f16>, #blocked> |
| 88 | + %5 = tt.addptr %4, %3 : tensor<32x64x!tt.ptr<f16>, #blocked>, tensor<32x64xi32, #blocked> |
| 89 | + |
| 90 | + // CHECK: %{{.*}} = ttg.convert_layout %{{.*}} : {{.*}} -> tensor<32x64x!tt.ptr<f16>, #[[NEW_BLOCKED]]> |
| 91 | + // CHECK: %{{.*}} = ttg.async_copy_global_to_local %{{.*}}: tensor<32x64x!tt.ptr<f16>, #[[NEW_BLOCKED]]> |
| 92 | + %6 = ttg.async_copy_global_to_local %5, %arg2 : tensor<32x64x!tt.ptr<f16>, #blocked> -> <32x64xf16, #shared, #smem, mutable> |
| 93 | + tt.return |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +// ----- |
| 98 | + |
| 99 | +#blocked = #ttg.blocked<{sizePerThread = [1, 16], threadsPerWarp = [32, 2], warpsPerCTA = [4, 1], order = [1, 0]}> |
| 100 | +#shared = #ttg.swizzled_shared<{vec = 1, perPhase = 1, maxPhase = 1, order = [1, 0]}> |
| 101 | +#smem = #ttg.shared_memory |
| 102 | +module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 4 : i32, ttg.shared = 8192 : i32, ttg.target = "hip:gfx942", "ttg.threads-per-warp" = 64 : i32} { |
| 103 | + // Clip to vector size 4 (128bit) which is the largest supported load width |
| 104 | + // CHECK: #[[NEW_BLOCKED:.*]] = #ttg.blocked<{sizePerThread = [1, 8], threadsPerWarp = [8, 8], warpsPerCTA = [4, 1], order = [1, 0]}> |
| 105 | + tt.func public @async_copy_vector_size_8(%arg0: !tt.ptr<f16> {tt.divisibility = 16 : i32, tt.pointer_range = 32 : i32}, |
| 106 | + %arg1: i32 {tt.divisibility = 16 : i32}, |
| 107 | + %arg2: !ttg.memdesc<32x64xf16, #shared, #smem, mutable>) { |
| 108 | + // We need the index calculation so AxisAnalysis sees that we can vectorize the load based on the src contiguity |
| 109 | + %1 = tt.make_range {end = 64 : i32, start = 0 : i32} : tensor<64xi32, #ttg.slice<{dim = 0, parent = #blocked}>> |
| 110 | + %2 = tt.expand_dims %1 {axis = 0 : i32} : tensor<64xi32, #ttg.slice<{dim = 0, parent = #blocked}>> -> tensor<1x64xi32, #blocked> |
| 111 | + %3 = tt.broadcast %2 : tensor<1x64xi32, #blocked> -> tensor<32x64xi32, #blocked> |
| 112 | + %4 = tt.splat %arg0 : !tt.ptr<f16> -> tensor<32x64x!tt.ptr<f16>, #blocked> |
| 113 | + %5 = tt.addptr %4, %3 : tensor<32x64x!tt.ptr<f16>, #blocked>, tensor<32x64xi32, #blocked> |
| 114 | + |
| 115 | + // CHECK: %{{.*}} = ttg.convert_layout %{{.*}} : {{.*}} -> tensor<32x64x!tt.ptr<f16>, #[[NEW_BLOCKED]]> |
| 116 | + // CHECK: %{{.*}} = ttg.async_copy_global_to_local %{{.*}}: tensor<32x64x!tt.ptr<f16>, #[[NEW_BLOCKED]]> |
| 117 | + %6 = ttg.async_copy_global_to_local %5, %arg2 : tensor<32x64x!tt.ptr<f16>, #blocked> -> <32x64xf16, #shared, #smem, mutable> |
| 118 | + tt.return |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | +// ----- |
| 123 | + |
| 124 | +#blocked = #ttg.blocked<{sizePerThread = [1, 16], threadsPerWarp = [32, 2], warpsPerCTA = [4, 1], order = [1, 0]}> |
| 125 | +#shared = #ttg.swizzled_shared<{vec = 1, perPhase = 1, maxPhase = 1, order = [0, 1]}> |
| 126 | +#smem = #ttg.shared_memory |
| 127 | +module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 4 : i32, ttg.shared = 8192 : i32, ttg.target = "hip:gfx942", "ttg.threads-per-warp" = 64 : i32} { |
| 128 | + // The order of #blocked and #shared are different so we need to clip to 1 element |
| 129 | + // CHECK: #[[NEW_BLOCKED:.*]] = #ttg.blocked<{sizePerThread = [1, 1], threadsPerWarp = [1, 64], warpsPerCTA = [4, 1], order = [1, 0]}> |
| 130 | + tt.func public @async_copy_different_order(%arg0: !tt.ptr<f16> {tt.divisibility = 16 : i32, tt.pointer_range = 32 : i32}, |
| 131 | + %arg1: i32 {tt.divisibility = 16 : i32}, |
| 132 | + %arg2: !ttg.memdesc<32x64xf16, #shared, #smem, mutable>) { |
| 133 | + // We need the index calculation so AxisAnalysis sees that we can vectorize the load based on the src contiguity |
| 134 | + %1 = tt.make_range {end = 64 : i32, start = 0 : i32} : tensor<64xi32, #ttg.slice<{dim = 0, parent = #blocked}>> |
| 135 | + %2 = tt.expand_dims %1 {axis = 0 : i32} : tensor<64xi32, #ttg.slice<{dim = 0, parent = #blocked}>> -> tensor<1x64xi32, #blocked> |
| 136 | + %3 = tt.broadcast %2 : tensor<1x64xi32, #blocked> -> tensor<32x64xi32, #blocked> |
| 137 | + %4 = tt.splat %arg0 : !tt.ptr<f16> -> tensor<32x64x!tt.ptr<f16>, #blocked> |
| 138 | + %5 = tt.addptr %4, %3 : tensor<32x64x!tt.ptr<f16>, #blocked>, tensor<32x64xi32, #blocked> |
| 139 | + |
| 140 | + // CHECK: %{{.*}} = ttg.convert_layout %{{.*}} : {{.*}} -> tensor<32x64x!tt.ptr<f16>, #[[NEW_BLOCKED]]> |
| 141 | + // CHECK: %{{.*}} = ttg.async_copy_global_to_local %{{.*}}: tensor<32x64x!tt.ptr<f16>, #[[NEW_BLOCKED]]> |
| 142 | + %6 = ttg.async_copy_global_to_local %5, %arg2 : tensor<32x64x!tt.ptr<f16>, #blocked> -> <32x64xf16, #shared, #smem, mutable> |
| 143 | + tt.return |
| 144 | + } |
| 145 | +} |
0 commit comments