-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[AMD] Sink the 2nd tt.load after local_load's #4823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5511fb6
Sink the 2nd tt.load after local_load's
zhanglx13 606c4db
refactor code according to review
zhanglx13 71855ad
Adding lit tests for sched-2nd-load
zhanglx13 0baea7d
Auto generate the lit tests for various tile sizes
zhanglx13 532686f
Address review comment
zhanglx13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,165 @@ | ||
| // RUN: triton-opt %s -split-input-file -tritonamdgpu-reorder-instructions | FileCheck %s | ||
|
|
||
| // Check the logic of sched-2nd-load optimizations | ||
| // The following tile sizes should apply the optimization | ||
| // 256x256x128 | ||
| // 256x256x64 | ||
| // The following tile sizes should NOT apply the optimization | ||
| // 256x64x128 | ||
| // 256x256x32 | ||
| // scf.for loop with two dots should not apply the optimization | ||
|
|
||
|
|
||
| #blocked = #triton_gpu.blocked<{sizePerThread = [1, 8], threadsPerWarp = [8, 8], warpsPerCTA = [1, 1], order = [1, 0]}> | ||
| #blocked1 = #triton_gpu.blocked<{sizePerThread = [8, 1], threadsPerWarp = [8, 8], warpsPerCTA = [1, 1], order = [0, 1]}> | ||
| #mma = #triton_gpu.amd_mfma<{versionMajor = 3, versionMinor = 0, warpsPerCTA = [1, 1], instrShape = [16, 16], isTransposed = true}> | ||
| #shared = #triton_gpu.shared<{vec = 8, perPhase = 1, maxPhase = 8, order = [1, 0], hasLeadingOffset = false}> | ||
| #shared1 = #triton_gpu.shared<{vec = 8, perPhase = 1, maxPhase = 8, order = [0, 1], hasLeadingOffset = false}> | ||
| #dotOp0 = #triton_gpu.dot_op<{opIdx = 0, parent = #mma, kWidth = 8}> | ||
| #dotOp1 = #triton_gpu.dot_op<{opIdx = 1, parent = #mma, kWidth = 8}> | ||
| // Should apply: tile size 256x256x128 with single dot | ||
| // CHECK-LABEL: sink_2nd_load_256x256x128 | ||
| // CHECK: %[[tileA:.*]] = tt.load | ||
| // CHECK-NEXT: local_load | ||
| // CHECK-NEXT: local_load | ||
| // CHECK-NEXT: %[[tileB:.*]] = tt.load | ||
| // CHECK-NEXT: tt.dot | ||
| // CHECK-NEXT: triton_gpu.local_store %[[tileA]] | ||
| // CHECK-NEXT: triton_gpu.local_store %[[tileB]] | ||
| module attributes {"triton_gpu.num-warps" = 1 : i32, "triton_gpu.threads-per-warp" = 64 : i32} { | ||
| tt.func public @sink_2nd_load_256x256x128(%A_ptr: tensor<256x128x!tt.ptr<f16>, #blocked>, %B_ptr: tensor<128x256x!tt.ptr<f16>, #blocked1>, %C_ptr: tensor<256x256x!tt.ptr<f32>, #mma>, %A_LDS: !tt.memdesc<256x128xf16, #shared, #triton_gpu.shared_memory, mutable>, %B_LDS: !tt.memdesc<128x256xf16, #shared1, #triton_gpu.shared_memory, mutable>) { | ||
| %c0 = arith.constant 0 : i32 | ||
| %c1 = arith.constant 1 : i32 | ||
| %cst = arith.constant dense<0.000000e+00> : tensor<256x256xf32, #mma> | ||
| %0:1 = scf.for %arg0 = %c0 to %c1 step %c1 iter_args(%arg1 = %cst) -> (tensor<256x256xf32, #mma>) : i32 { | ||
| %1 = triton_gpu.local_load %A_LDS : !tt.memdesc<256x128xf16, #shared, #triton_gpu.shared_memory, mutable> -> tensor<256x128xf16, #dotOp0> | ||
| %2 = triton_gpu.local_load %B_LDS : !tt.memdesc<128x256xf16, #shared1, #triton_gpu.shared_memory, mutable> -> tensor<128x256xf16, #dotOp1> | ||
| %3 = tt.dot %1, %2, %arg1 : tensor<256x128xf16, #dotOp0> * tensor<128x256xf16, #dotOp1> -> tensor<256x256xf32, #mma> | ||
| %4 = tt.load %A_ptr : tensor<256x128x!tt.ptr<f16>, #blocked> | ||
| %5 = tt.load %B_ptr : tensor<128x256x!tt.ptr<f16>, #blocked1> | ||
| triton_gpu.local_store %4, %A_LDS : tensor<256x128xf16, #blocked> -> !tt.memdesc<256x128xf16, #shared, #triton_gpu.shared_memory, mutable> | ||
| triton_gpu.local_store %5, %B_LDS : tensor<128x256xf16, #blocked1> -> !tt.memdesc<128x256xf16, #shared1, #triton_gpu.shared_memory, mutable> | ||
| scf.yield %3 : tensor<256x256xf32, #mma> | ||
| } | ||
| tt.store %C_ptr, %0#0: tensor<256x256x!tt.ptr<f32>, #mma> | ||
| tt.return | ||
| } | ||
| } | ||
|
|
||
| // Should apply: tile size 256x256x64 with single dot | ||
| // CHECK-LABEL: sink_2nd_load_256x256x64 | ||
| // CHECK: %[[tileA:.*]] = tt.load | ||
| // CHECK-NEXT: local_load | ||
| // CHECK-NEXT: local_load | ||
| // CHECK-NEXT: %[[tileB:.*]] = tt.load | ||
| // CHECK-NEXT: tt.dot | ||
| // CHECK-NEXT: triton_gpu.local_store %[[tileA]] | ||
| // CHECK-NEXT: triton_gpu.local_store %[[tileB]] | ||
| module attributes {"triton_gpu.num-warps" = 1 : i32, "triton_gpu.threads-per-warp" = 64 : i32} { | ||
| tt.func public @sink_2nd_load_256x256x64(%A_ptr: tensor<256x64x!tt.ptr<f16>, #blocked>, %B_ptr: tensor<64x256x!tt.ptr<f16>, #blocked1>, %C_ptr: tensor<256x256x!tt.ptr<f32>, #mma>, %A_LDS: !tt.memdesc<256x64xf16, #shared, #triton_gpu.shared_memory, mutable>, %B_LDS: !tt.memdesc<64x256xf16, #shared1, #triton_gpu.shared_memory, mutable>) { | ||
| %c0 = arith.constant 0 : i32 | ||
| %c1 = arith.constant 1 : i32 | ||
| %cst = arith.constant dense<0.000000e+00> : tensor<256x256xf32, #mma> | ||
| %0:1 = scf.for %arg0 = %c0 to %c1 step %c1 iter_args(%arg1 = %cst) -> (tensor<256x256xf32, #mma>) : i32 { | ||
| %1 = triton_gpu.local_load %A_LDS : !tt.memdesc<256x64xf16, #shared, #triton_gpu.shared_memory, mutable> -> tensor<256x64xf16, #dotOp0> | ||
| %2 = triton_gpu.local_load %B_LDS : !tt.memdesc<64x256xf16, #shared1, #triton_gpu.shared_memory, mutable> -> tensor<64x256xf16, #dotOp1> | ||
| %3 = tt.dot %1, %2, %arg1 : tensor<256x64xf16, #dotOp0> * tensor<64x256xf16, #dotOp1> -> tensor<256x256xf32, #mma> | ||
| %4 = tt.load %A_ptr : tensor<256x64x!tt.ptr<f16>, #blocked> | ||
| %5 = tt.load %B_ptr : tensor<64x256x!tt.ptr<f16>, #blocked1> | ||
| triton_gpu.local_store %4, %A_LDS : tensor<256x64xf16, #blocked> -> !tt.memdesc<256x64xf16, #shared, #triton_gpu.shared_memory, mutable> | ||
| triton_gpu.local_store %5, %B_LDS : tensor<64x256xf16, #blocked1> -> !tt.memdesc<64x256xf16, #shared1, #triton_gpu.shared_memory, mutable> | ||
| scf.yield %3 : tensor<256x256xf32, #mma> | ||
| } | ||
| tt.store %C_ptr, %0#0: tensor<256x256x!tt.ptr<f32>, #mma> | ||
| tt.return | ||
| } | ||
| } | ||
|
|
||
| // Should NOT apply: tile size 256x64x128 with single dot | ||
| // CHECK-LABEL: sink_2nd_load_256x64x128 | ||
| // CHECK: %[[tileA:.*]] = tt.load | ||
| // CHECK-NEXT: %[[tileB:.*]] = tt.load | ||
| // CHECK-NEXT: local_load | ||
| // CHECK-NEXT: local_load | ||
| // CHECK-NEXT: tt.dot | ||
| // CHECK-NEXT: triton_gpu.local_store %[[tileA]] | ||
| // CHECK-NEXT: triton_gpu.local_store %[[tileB]] | ||
| module attributes {"triton_gpu.num-warps" = 1 : i32, "triton_gpu.threads-per-warp" = 64 : i32} { | ||
| tt.func public @sink_2nd_load_256x64x128(%A_ptr: tensor<256x128x!tt.ptr<f16>, #blocked>, %B_ptr: tensor<128x64x!tt.ptr<f16>, #blocked1>, %C_ptr: tensor<256x64x!tt.ptr<f32>, #mma>, %A_LDS: !tt.memdesc<256x128xf16, #shared, #triton_gpu.shared_memory, mutable>, %B_LDS: !tt.memdesc<128x64xf16, #shared1, #triton_gpu.shared_memory, mutable>) { | ||
| %c0 = arith.constant 0 : i32 | ||
| %c1 = arith.constant 1 : i32 | ||
| %cst = arith.constant dense<0.000000e+00> : tensor<256x64xf32, #mma> | ||
| %0:1 = scf.for %arg0 = %c0 to %c1 step %c1 iter_args(%arg1 = %cst) -> (tensor<256x64xf32, #mma>) : i32 { | ||
| %1 = triton_gpu.local_load %A_LDS : !tt.memdesc<256x128xf16, #shared, #triton_gpu.shared_memory, mutable> -> tensor<256x128xf16, #dotOp0> | ||
| %2 = triton_gpu.local_load %B_LDS : !tt.memdesc<128x64xf16, #shared1, #triton_gpu.shared_memory, mutable> -> tensor<128x64xf16, #dotOp1> | ||
| %3 = tt.dot %1, %2, %arg1 : tensor<256x128xf16, #dotOp0> * tensor<128x64xf16, #dotOp1> -> tensor<256x64xf32, #mma> | ||
| %4 = tt.load %A_ptr : tensor<256x128x!tt.ptr<f16>, #blocked> | ||
| %5 = tt.load %B_ptr : tensor<128x64x!tt.ptr<f16>, #blocked1> | ||
| triton_gpu.local_store %4, %A_LDS : tensor<256x128xf16, #blocked> -> !tt.memdesc<256x128xf16, #shared, #triton_gpu.shared_memory, mutable> | ||
| triton_gpu.local_store %5, %B_LDS : tensor<128x64xf16, #blocked1> -> !tt.memdesc<128x64xf16, #shared1, #triton_gpu.shared_memory, mutable> | ||
| scf.yield %3 : tensor<256x64xf32, #mma> | ||
| } | ||
| tt.store %C_ptr, %0#0: tensor<256x64x!tt.ptr<f32>, #mma> | ||
| tt.return | ||
| } | ||
| } | ||
|
|
||
| // Should NOT apply: tile size 256x256x32 with single dot | ||
| // CHECK-LABEL: sink_2nd_load_256x256x32 | ||
| // CHECK: %[[tileA:.*]] = tt.load | ||
| // CHECK-NEXT: %[[tileB:.*]] = tt.load | ||
| // CHECK-NEXT: local_load | ||
| // CHECK-NEXT: local_load | ||
| // CHECK-NEXT: tt.dot | ||
| // CHECK-NEXT: triton_gpu.local_store %[[tileA]] | ||
| // CHECK-NEXT: triton_gpu.local_store %[[tileB]] | ||
| module attributes {"triton_gpu.num-warps" = 1 : i32, "triton_gpu.threads-per-warp" = 64 : i32} { | ||
| tt.func public @sink_2nd_load_256x256x32(%A_ptr: tensor<256x32x!tt.ptr<f16>, #blocked>, %B_ptr: tensor<32x256x!tt.ptr<f16>, #blocked1>, %C_ptr: tensor<256x256x!tt.ptr<f32>, #mma>, %A_LDS: !tt.memdesc<256x32xf16, #shared, #triton_gpu.shared_memory, mutable>, %B_LDS: !tt.memdesc<32x256xf16, #shared1, #triton_gpu.shared_memory, mutable>) { | ||
| %c0 = arith.constant 0 : i32 | ||
| %c1 = arith.constant 1 : i32 | ||
| %cst = arith.constant dense<0.000000e+00> : tensor<256x256xf32, #mma> | ||
| %0:1 = scf.for %arg0 = %c0 to %c1 step %c1 iter_args(%arg1 = %cst) -> (tensor<256x256xf32, #mma>) : i32 { | ||
| %1 = triton_gpu.local_load %A_LDS : !tt.memdesc<256x32xf16, #shared, #triton_gpu.shared_memory, mutable> -> tensor<256x32xf16, #dotOp0> | ||
| %2 = triton_gpu.local_load %B_LDS : !tt.memdesc<32x256xf16, #shared1, #triton_gpu.shared_memory, mutable> -> tensor<32x256xf16, #dotOp1> | ||
| %3 = tt.dot %1, %2, %arg1 : tensor<256x32xf16, #dotOp0> * tensor<32x256xf16, #dotOp1> -> tensor<256x256xf32, #mma> | ||
| %4 = tt.load %A_ptr : tensor<256x32x!tt.ptr<f16>, #blocked> | ||
| %5 = tt.load %B_ptr : tensor<32x256x!tt.ptr<f16>, #blocked1> | ||
| triton_gpu.local_store %4, %A_LDS : tensor<256x32xf16, #blocked> -> !tt.memdesc<256x32xf16, #shared, #triton_gpu.shared_memory, mutable> | ||
| triton_gpu.local_store %5, %B_LDS : tensor<32x256xf16, #blocked1> -> !tt.memdesc<32x256xf16, #shared1, #triton_gpu.shared_memory, mutable> | ||
| scf.yield %3 : tensor<256x256xf32, #mma> | ||
| } | ||
| tt.store %C_ptr, %0#0: tensor<256x256x!tt.ptr<f32>, #mma> | ||
| tt.return | ||
| } | ||
| } | ||
|
|
||
| // Should NOT apply: tile size 128x128x128 with two dots | ||
| // CHECK-LABEL: sink_2nd_load_128x128x128_two_dot | ||
| // CHECK: %[[tileA:.*]] = tt.load | ||
| // CHECK-NEXT: %[[tileB:.*]] = tt.load | ||
| // CHECK-NEXT: local_load | ||
| // CHECK-NEXT: local_load | ||
| // CHECK-NEXT: tt.dot | ||
| // CHECK-NEXT: tt.dot | ||
| // CHECK-NEXT: triton_gpu.local_store %[[tileA]] | ||
| // CHECK-NEXT: triton_gpu.local_store %[[tileB]] | ||
| module attributes {"triton_gpu.num-warps" = 1 : i32, "triton_gpu.threads-per-warp" = 64 : i32} { | ||
| tt.func public @sink_2nd_load_128x128x128_two_dot(%A_ptr: tensor<128x128x!tt.ptr<f16>, #blocked>, %B_ptr: tensor<128x128x!tt.ptr<f16>, #blocked1>, %C_ptr: tensor<128x128x!tt.ptr<f32>, #mma>, %A_LDS: !tt.memdesc<128x128xf16, #shared, #triton_gpu.shared_memory, mutable>, %B_LDS: !tt.memdesc<128x128xf16, #shared1, #triton_gpu.shared_memory, mutable>) { | ||
| %c0 = arith.constant 0 : i32 | ||
| %c1 = arith.constant 1 : i32 | ||
| %cst = arith.constant dense<0.000000e+00> : tensor<128x128xf32, #mma> | ||
| %0:1 = scf.for %arg0 = %c0 to %c1 step %c1 iter_args(%arg1 = %cst) -> (tensor<128x128xf32, #mma>) : i32 { | ||
| %1 = triton_gpu.local_load %A_LDS : !tt.memdesc<128x128xf16, #shared, #triton_gpu.shared_memory, mutable> -> tensor<128x128xf16, #dotOp0> | ||
| %2 = triton_gpu.local_load %B_LDS : !tt.memdesc<128x128xf16, #shared1, #triton_gpu.shared_memory, mutable> -> tensor<128x128xf16, #dotOp1> | ||
| %3 = tt.dot %1, %2, %arg1 : tensor<128x128xf16, #dotOp0> * tensor<128x128xf16, #dotOp1> -> tensor<128x128xf32, #mma> | ||
| %6 = tt.dot %1, %2, %3 : tensor<128x128xf16, #dotOp0> * tensor<128x128xf16, #dotOp1> -> tensor<128x128xf32, #mma> | ||
| %4 = tt.load %A_ptr : tensor<128x128x!tt.ptr<f16>, #blocked> | ||
| %5 = tt.load %B_ptr : tensor<128x128x!tt.ptr<f16>, #blocked1> | ||
| triton_gpu.local_store %4, %A_LDS : tensor<128x128xf16, #blocked> -> !tt.memdesc<128x128xf16, #shared, #triton_gpu.shared_memory, mutable> | ||
| triton_gpu.local_store %5, %B_LDS : tensor<128x128xf16, #blocked1> -> !tt.memdesc<128x128xf16, #shared1, #triton_gpu.shared_memory, mutable> | ||
| scf.yield %6 : tensor<128x128xf32, #mma> | ||
| } | ||
| tt.store %C_ptr, %0#0: tensor<128x128x!tt.ptr<f32>, #mma> | ||
| tt.return | ||
| } | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.