Skip to content
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

Set PtrState scalar to 0 for pointer arguments #215

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/AnalysisStructured/PtrAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,12 @@ LogicalResult PtrAnalysis::visitOperand(Value operand, PtrState &state,
llvm_unreachable("Unexpected operand defining operation");
}
} else {
// If the operand comes directly from the kernel argument, set the scalar
// to 0.
OpBuilder::InsertionGuard guard(builder);
builder.setInsertionPointToStart(operand.getParentBlock());
state.scalar =
builder.create<arith::ConstantOp>(loc, builder.getIndexAttr(0));
state.source = operand;
return success();
}
Expand Down Expand Up @@ -1337,7 +1343,7 @@ LogicalResult PtrAnalysis::rewriteOp(Operation *rootOp, bool useUnsafeMask) {
.Case<tts::GetStructuredStateOp>(
[&](tts::GetStructuredStateOp getStateOp) {
// For tensor of indices potentially being used in pointer
// arithmetic sequence, we need to manually populate the state of
// arithmetic sequence, we need to manually populate the state if
// none already exists.
// This process is necessary because unlike triton pointers in a
// loop which always have a `tt.addptr` that triggers the rewrite
Expand Down
18 changes: 18 additions & 0 deletions test/Conversion/TritonToStructured/scalar_store_loop.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: triton-shared-opt --triton-to-structured %s | FileCheck %s

module {
func.func @reduce_kernel_2d_0d(%arg0: !tt.ptr<f32> {tt.divisibility = 16 : i32}, %arg1: i32, %arg2: i32, %arg3: i32, %arg4: i32, %arg5: i32, %arg6: i32) {
%c8_i32 = arith.constant 8 : i32
%c0_i32 = arith.constant 0 : i32
%c1_i32 = arith.constant 1 : i32
%0 = scf.for %arg7 = %c0_i32 to %c8_i32 step %c1_i32 iter_args(%arg8 = %arg0) -> (!tt.ptr<f32>) : i32 {
%1 = arith.sitofp %arg7 : i32 to f32
tt.store %arg8, %1 : !tt.ptr<f32>
%2 = tt.addptr %arg8, %c1_i32 : !tt.ptr<f32>, i32
scf.yield %2 : !tt.ptr<f32>
}
return
}
}

// CHECK-NO: tts
Loading