-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BACKEND] Promote tl.atomic_add to PTX ld.acquire when possible (#5187)
To optimize the case tl.atomic_add(ptr, 0) for scalars, there is a new path for lowering to PTX `ld.acquire.scope` (`.cta`, `.gpu`, `.sys`) It does this by lowering to `nvgpu.ld_acquire` from the TTGIR::AtomicRMW lowering, then subsequently lowering to an LLVM inline_ptx of `ld.acquire` for NVGP::LoadAcquireOp lowering. The purpose is to generate better code for synchronizing groups of threads during a cooperative thread launch. - [x] I am not making a trivial change, such as fixing a typo in a comment. - [x] I have written a PR description following these [rules](https://cbea.ms/git-commit/#why-not-how). - [x] I have run `pre-commit run --from-ref origin/main --to-ref HEAD`. - Select one of the following. - [x] I have added tests. - `/python/test` for end-to-end tests
- Loading branch information
Showing
4 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// RUN: triton-opt %s -split-input-file --allocate-shared-memory --convert-triton-gpu-to-llvm=compute-capability=90 2>&1 | FileCheck %s --check-prefix=CHECK-TTG2NVGPU | ||
// RUN: triton-opt %s -split-input-file --allocate-shared-memory --convert-triton-gpu-to-llvm=compute-capability=90 --convert-nv-gpu-to-llvm 2>&1 | FileCheck %s --check-prefix=CHECK-NVGPU2LLVM | ||
module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 4 : i32, "ttg.threads-per-warp" = 32 : i32} { | ||
tt.func public @kernel_r(%arg0: !tt.ptr<f32> {tt.divisibility = 16 : i32}) attributes {noinline = false} { | ||
%cst = arith.constant 0.000000e+00 : f32 | ||
%true = arith.constant true | ||
%c128_i32 = arith.constant 128 : i32 | ||
%c512_i32 = arith.constant 512 : i32 | ||
%0 = tt.get_program_id x : i32 | ||
%1 = arith.muli %0, %c128_i32 : i32 | ||
%2 = arith.cmpi slt, %1, %c512_i32 : i32 | ||
|
||
// CHECK-TTG2NVGPU: nvgpu.ld_acquire acquire, gpu | ||
// CHECK-NVGPU2LLVM: ld.global.gpu.acquire.b32 | ||
%3 = tt.atomic_rmw fadd, acquire, gpu, %arg0, %cst, %2 : (!tt.ptr<f32>, f32, i1) -> f32 | ||
tt.store %arg0, %3 : !tt.ptr<f32> | ||
|
||
// CHECK-TTG2NVGPU: nvgpu.ld_acquire acquire, cta | ||
// CHECK-NVGPU2LLVM: ld.global.cta.acquire.b32 | ||
%4 = tt.atomic_rmw fadd, acquire, cta, %arg0, %cst, %true : (!tt.ptr<f32>, f32, i1) -> f32 | ||
tt.store %arg0, %4 : !tt.ptr<f32> | ||
|
||
// CHECK-TTG2NVGPU: nvgpu.ld_acquire acquire, sys | ||
// CHECK-NVGPU2LLVM: ld.global.sys.acquire.b32 | ||
%5 = tt.atomic_rmw fadd, acquire, sys, %arg0, %cst, %2 : (!tt.ptr<f32>, f32, i1) -> f32 | ||
tt.store %arg0, %5 : !tt.ptr<f32> | ||
tt.return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters