|
| 1 | +// Copyright 2025- FlagOS Contributors |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining |
| 4 | +// a copy of this software and associated documentation files |
| 5 | +// (the "Software"), to deal in the Software without restriction, |
| 6 | +// including without limitation the rights to use, copy, modify, merge, |
| 7 | +// publish, distribute, sublicense, and/or sell copies of the Software, |
| 8 | +// and to permit persons to whom the Software is furnished to do so, |
| 9 | +// subject to the following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be |
| 12 | +// included in all copies or substantial portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 15 | +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 | +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 17 | +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 18 | +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 19 | +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 20 | +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | + |
| 22 | +// RUN: triton-opt %s -split-input-file --allocate-amdgpu-shared-memory --convert-triton-amdgpu-to-llvm=arch=gfx1201 --convert-builtin-func-to-llvm | FileCheck %s |
| 23 | + |
| 24 | +#blocked = #ttg.blocked<{sizePerThread = [1], threadsPerWarp = [32], warpsPerCTA = [1], order = [0]}> |
| 25 | +#shared = #ttg.swizzled_shared<{vec = 1, perPhase = 1, maxPhase = 1, order = [0]}> |
| 26 | +#smem = #ttg.shared_memory |
| 27 | + |
| 28 | +module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 1 : i32, ttg.target = "hip:gfx1201", "ttg.threads-per-warp" = 32 : i32} { |
| 29 | + // CHECK-LABEL: llvm.func @local_pointers_tensor_index |
| 30 | + // The lowered pointers must stay in the shared address space and be reached |
| 31 | + // through plain GEPs, with no NVVM op leaking into the AMD path. |
| 32 | + // CHECK: llvm.mlir.addressof @global_smem : !llvm.ptr<3> |
| 33 | + // CHECK: llvm.getelementptr {{.*}}!llvm.ptr<3> |
| 34 | + // CHECK: llvm.load {{.*}}!llvm.ptr<3> |
| 35 | + // CHECK: llvm.store {{.*}}!llvm.ptr<3> |
| 36 | + // CHECK-NOT: tle.local_pointers |
| 37 | + // CHECK-NOT: nvvm. |
| 38 | + tt.func public @local_pointers_tensor_index(%idx: tensor<32xi32, #blocked>) { |
| 39 | + %buf = ttg.local_alloc : () -> !ttg.memdesc<32xf32, #shared, #smem, mutable> |
| 40 | + %ptrs = "tle.local_pointers"(%buf, %idx) : (!ttg.memdesc<32xf32, #shared, #smem, mutable>, tensor<32xi32, #blocked>) -> tensor<32x!tt.ptr<f32, 3>, #blocked> |
| 41 | + %val = tt.load %ptrs : tensor<32x!tt.ptr<f32, 3>, #blocked> |
| 42 | + tt.store %ptrs, %val : tensor<32x!tt.ptr<f32, 3>, #blocked> |
| 43 | + tt.return |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +// ----- |
| 48 | + |
| 49 | +#blocked = #ttg.blocked<{sizePerThread = [1], threadsPerWarp = [32], warpsPerCTA = [1], order = [0]}> |
| 50 | +#shared = #ttg.swizzled_shared<{vec = 1, perPhase = 1, maxPhase = 1, order = [0]}> |
| 51 | +#smem = #ttg.shared_memory |
| 52 | + |
| 53 | +module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 1 : i32, ttg.target = "hip:gfx1201", "ttg.threads-per-warp" = 32 : i32} { |
| 54 | + // A scalar base pointer broadcast over a tensor of offsets must not be |
| 55 | + // rewritten into buffer ops, which can only address global memory. |
| 56 | + // CHECK-LABEL: llvm.func @local_pointers_scalar_index |
| 57 | + // CHECK: llvm.getelementptr {{.*}}!llvm.ptr<3> |
| 58 | + // CHECK-NOT: tle.local_pointers |
| 59 | + // CHECK-NOT: amdg.buffer_ |
| 60 | + tt.func public @local_pointers_scalar_index(%idx: i32) { |
| 61 | + %buf = ttg.local_alloc : () -> !ttg.memdesc<32xf32, #shared, #smem, mutable> |
| 62 | + %ptr = "tle.local_pointers"(%buf, %idx) : (!ttg.memdesc<32xf32, #shared, #smem, mutable>, i32) -> !tt.ptr<f32, 3> |
| 63 | + %splat = tt.splat %ptr : !tt.ptr<f32, 3> -> tensor<32x!tt.ptr<f32, 3>, #blocked> |
| 64 | + %offs = tt.make_range {end = 32 : i32, start = 0 : i32} : tensor<32xi32, #blocked> |
| 65 | + %ptrs = tt.addptr %splat, %offs : tensor<32x!tt.ptr<f32, 3>, #blocked>, tensor<32xi32, #blocked> |
| 66 | + %val = tt.load %ptrs : tensor<32x!tt.ptr<f32, 3>, #blocked> |
| 67 | + tt.store %ptrs, %val : tensor<32x!tt.ptr<f32, 3>, #blocked> |
| 68 | + tt.return |
| 69 | + } |
| 70 | +} |
0 commit comments