|
| 1 | +// RUN: triton-opt %s -split-input-file --tritonamdgpu-convert-buffer-ops | FileCheck %s |
| 2 | + |
| 3 | +#blocked0 = #triton_gpu.blocked<{sizePerThread = [8], threadsPerWarp = [32], warpsPerCTA = [1], order = [0], CTAsPerCGA = [1], CTASplitNum = [1], CTAOrder = [0]}> |
| 4 | +module attributes {"triton_gpu.num-ctas" = 1 : i32, "triton_gpu.num-warps" = 1 : i32} { |
| 5 | + // CHECK-LABEL: simple |
| 6 | + tt.func @simple(%arg0: !tt.ptr<f32> {tt.divisibility = 16 : i32, tt.pointer_range = 32 :i32}, %arg1: !tt.ptr<f32> {tt.divisibility = 16 : i32}, %arg2: !tt.ptr<f32> {tt.divisibility = 16 : i32}, %arg3: i32) { |
| 7 | + %c256_i32 = arith.constant 256 : i32 |
| 8 | + %0 = tt.get_program_id x : i32 |
| 9 | + %1 = arith.muli %0, %c256_i32 : i32 |
| 10 | + %2 = tt.make_range {end = 256 : i32, start = 0 : i32} : tensor<256xi32, #blocked0> |
| 11 | + %3 = tt.splat %1 : i32 -> tensor<256xi32, #blocked0> |
| 12 | + // CHECK: %[[offset:.*]] = arith.addi |
| 13 | + %4 = arith.addi %3, %2 : tensor<256xi32, #blocked0> |
| 14 | + %5 = tt.splat %arg0 : !tt.ptr<f32> -> tensor<256x!tt.ptr<f32>, #blocked0> |
| 15 | + %6 = tt.addptr %5, %4 : tensor<256x!tt.ptr<f32>, #blocked0>, tensor<256xi32, #blocked0> |
| 16 | + %7 = tt.splat %arg1 : !tt.ptr<f32> -> tensor<256x!tt.ptr<f32>, #blocked0> |
| 17 | + %8 = tt.addptr %7, %4 : tensor<256x!tt.ptr<f32>, #blocked0>, tensor<256xi32, #blocked0> |
| 18 | + // CHECK: buffer_load %arg0[%[[offset]]] |
| 19 | + %9 = tt.load %6 : tensor<256x!tt.ptr<f32>, #blocked0> |
| 20 | + // CHECK: buffer_load %arg1[%[[offset]]] |
| 21 | + %10 = tt.load %8 : tensor<256x!tt.ptr<f32>, #blocked0> |
| 22 | + // CHECK: %[[data:.*]] = arith.addf |
| 23 | + %11 = arith.addf %9, %10 : tensor<256xf32, #blocked0> |
| 24 | + %12 = tt.splat %arg2 : !tt.ptr<f32> -> tensor<256x!tt.ptr<f32>, #blocked0> |
| 25 | + %13 = tt.addptr %12, %4 : tensor<256x!tt.ptr<f32>, #blocked0>, tensor<256xi32, #blocked0> |
| 26 | + // CHECK: buffer_store %[[data]], %arg2[%[[offset]]] |
| 27 | + tt.store %13, %11 : tensor<256x!tt.ptr<f32>, #blocked0> |
| 28 | + tt.return |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +// ----- |
| 33 | + |
| 34 | +#blocked = #triton_gpu.blocked<{sizePerThread = [4], threadsPerWarp = [32], warpsPerCTA = [4], order = [0]}> |
| 35 | +module attributes {"triton_gpu.num-ctas" = 1 : i32, "triton_gpu.num-warps" = 4 : i32} { |
| 36 | + // CHECK-LABEL: assume_positive_offset |
| 37 | + tt.func @assume_positive_offset(%arg0: !tt.ptr<f32> {tt.divisibility = 16 : i32}) -> tensor<1024xf32, #blocked>{ |
| 38 | + %c1024_i32 = arith.constant 1024 : i32 |
| 39 | + %c128_i32 = arith.constant 128 : i32 |
| 40 | + %c0_i32 = arith.constant 0 : i32 |
| 41 | + %0 = tt.get_program_id x : i32 |
| 42 | + %1 = arith.muli %0, %c1024_i32 : i32 |
| 43 | + %sub = arith.subi %1, %c128_i32 : i32 |
| 44 | + %cmp = arith.cmpi sgt, %sub, %c0_i32 : i32 |
| 45 | + "llvm.intr.assume"(%cmp) : (i1) -> () |
| 46 | + %2 = tt.splat %sub : i32 -> tensor<1024xi32, #blocked> |
| 47 | + %3 = tt.make_range {end = 1024 : i32, start = 0 : i32} : tensor<1024xi32, #blocked> |
| 48 | + // CHECK: %[[offset:.*]] = arith.addi |
| 49 | + %4 = arith.addi %2, %3 : tensor<1024xi32, #blocked> |
| 50 | + // CHECK: %[[scalar_ptr:.*]] = tt.addptr %arg0 |
| 51 | + %5 = tt.addptr %arg0, %1 : !tt.ptr<f32>, i32 |
| 52 | + %8 = tt.splat %5 : !tt.ptr<f32> -> tensor<1024x!tt.ptr<f32>, #blocked> |
| 53 | + %9 = tt.addptr %8, %4 : tensor<1024x!tt.ptr<f32>, #blocked>, tensor<1024xi32, #blocked> |
| 54 | + // CHECK: buffer_load %[[scalar_ptr]][%[[offset]]] |
| 55 | + %10 = tt.load %9 : tensor<1024x!tt.ptr<f32>, #blocked> |
| 56 | + tt.return %10 : tensor<1024xf32, #blocked> |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +// ----- |
| 61 | + |
| 62 | +#blocked = #triton_gpu.blocked<{sizePerThread = [4], threadsPerWarp = [32], warpsPerCTA = [4], order = [0]}> |
| 63 | +module attributes {"triton_gpu.num-ctas" = 1 : i32, "triton_gpu.num-warps" = 4 : i32} { |
| 64 | + // CHECK-LABEL: offset_64_bits |
| 65 | + tt.func @offset_64_bits(%arg0: !tt.ptr<f32> {tt.divisibility = 16 : i32}) -> tensor<1024xf32, #blocked> { |
| 66 | + %c1024_i32 = arith.constant 1024 : i32 |
| 67 | + %c128_i32 = arith.constant 128 : i32 |
| 68 | + %0 = tt.get_program_id x : i32 |
| 69 | + %1 = arith.muli %0, %c1024_i32 : i32 |
| 70 | + %sub = arith.subi %1, %c128_i32 : i32 |
| 71 | + %2 = tt.splat %sub : i32 -> tensor<1024xi32, #blocked> |
| 72 | + %3 = tt.make_range {end = 1024 : i32, start = 0 : i32} : tensor<1024xi32, #blocked> |
| 73 | + %ext2 = arith.extsi %2 : tensor<1024xi32, #blocked> to tensor<1024xi64, #blocked> |
| 74 | + %ext3 = arith.extsi %3 : tensor<1024xi32, #blocked> to tensor<1024xi64, #blocked> |
| 75 | + %4 = arith.addi %ext2, %ext3 : tensor<1024xi64, #blocked> |
| 76 | + %5 = tt.addptr %arg0, %1 : !tt.ptr<f32>, i32 |
| 77 | + %8 = tt.splat %5 : !tt.ptr<f32> -> tensor<1024x!tt.ptr<f32>, #blocked> |
| 78 | + %9 = tt.addptr %8, %4 : tensor<1024x!tt.ptr<f32>, #blocked>, tensor<1024xi64, #blocked> |
| 79 | + // CHECK: tt.load |
| 80 | + %10 = tt.load %9 : tensor<1024x!tt.ptr<f32>, #blocked> |
| 81 | + tt.return %10 : tensor<1024xf32, #blocked> |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +// ----- |
| 86 | + |
| 87 | +#blocked = #triton_gpu.blocked<{sizePerThread = [4], threadsPerWarp = [32], warpsPerCTA = [4], order = [0]}> |
| 88 | +module attributes {"triton_gpu.num-ctas" = 1 : i32, "triton_gpu.num-warps" = 4 : i32} { |
| 89 | + // CHECK-LABEL: offset_64_bits_narrow |
| 90 | + tt.func public @offset_64_bits_narrow(%arg0: !tt.ptr<f32> {tt.divisibility = 16 : i32}, %arg1: !tt.ptr<f32> {tt.divisibility = 16 : i32}, %arg2: !tt.ptr<f32> {tt.divisibility = 16 : i32}, %arg3: i32 {tt.divisibility = 16 : i32}) -> tensor<1024xf32, #blocked> { |
| 91 | + %c1024_i32 = arith.constant 1024 : i32 |
| 92 | + %c128_i32 = arith.constant 128 : i32 |
| 93 | + %0 = tt.get_program_id x : i32 |
| 94 | + %1 = arith.muli %0, %c1024_i32 : i32 |
| 95 | + %2 = tt.splat %1: i32 -> tensor<1024xi32, #blocked> |
| 96 | + %3 = tt.make_range {end = 1024 : i32, start = 0 : i32} : tensor<1024xi32, #blocked> |
| 97 | + %ext2 = arith.extsi %2 : tensor<1024xi32, #blocked> to tensor<1024xi64, #blocked> |
| 98 | + %ext3 = arith.extsi %3 : tensor<1024xi32, #blocked> to tensor<1024xi64, #blocked> |
| 99 | + %4 = arith.addi %ext2, %ext3 : tensor<1024xi64, #blocked> |
| 100 | + // CHECK: %[[scalar_ptr:.*]] = tt.addptr %arg0 |
| 101 | + %5 = tt.addptr %arg0, %1 : !tt.ptr<f32>, i32 |
| 102 | + %8 = tt.splat %5 : !tt.ptr<f32> -> tensor<1024x!tt.ptr<f32>, #blocked> |
| 103 | + // CHECK: %[[offset_32_bit:.*]] = arith.trunci |
| 104 | + %narrow4 = arith.trunci %4 : tensor<1024xi64, #blocked> to tensor <1024xi32, #blocked> |
| 105 | + %9 = tt.addptr %8, %narrow4 : tensor<1024x!tt.ptr<f32>, #blocked>, tensor<1024xi32, #blocked> |
| 106 | + // CHECK: buffer_load %[[scalar_ptr]][%[[offset_32_bit]]] |
| 107 | + %10 = tt.load %9 : tensor<1024x!tt.ptr<f32>, #blocked> |
| 108 | + tt.return %10 : tensor<1024xf32, #blocked> |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +// ----- |
| 113 | + |
| 114 | +#blocked = #triton_gpu.blocked<{sizePerThread = [4], threadsPerWarp = [32], warpsPerCTA = [4], order = [0]}> |
| 115 | +module attributes {"triton_gpu.num-ctas" = 1 : i32, "triton_gpu.num-warps" = 4 : i32} { |
| 116 | + // CHECK-LABEL: non_canonical_ptr |
| 117 | + tt.func @non_canonical_ptr(%arg0: !tt.ptr<f32> {tt.divisibility = 16 : i32, tt.pointer_range = 32 : i32}, %arg1: tensor<1024xi32, #blocked>) -> tensor<1024xf32, #blocked>{ |
| 118 | + %8 = tt.splat %arg0 : !tt.ptr<f32> -> tensor<1024x!tt.ptr<f32>, #blocked> |
| 119 | + %9 = tt.addptr %8, %arg1: tensor<1024x!tt.ptr<f32>, #blocked>, tensor<1024xi32, #blocked> |
| 120 | + // CHECK: tt.load |
| 121 | + %10 = tt.load %9 : tensor<1024x!tt.ptr<f32>, #blocked> |
| 122 | + tt.return %10 : tensor<1024xf32, #blocked> |
| 123 | + } |
| 124 | +} |
0 commit comments