Skip to content

[TTIG_PrefetchOp] Add mask argument #4011

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 3 commits into from
Apr 25, 2025
Merged
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
9 changes: 9 additions & 0 deletions test/TritonIntelGPU/tritonintelgpu-invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ tt.func @triton_intel_gpu.extract(%ptr : !tt.ptr<tensor<32x32xf16>>) {

// -----

tt.func @triton_intel_gpu.prefetch(%arg0: !tt.ptr<tensor<2x32xf32>>, %arg1: tensor<4x32xi1>) {
// expected-note@-1 {{prior use here}}
// expected-error@+1 {{use of value '%arg1' expects different type than prior uses: 'tensor<2x32xi1>' vs 'tensor<4x32xi1>'}}
triton_intel_gpu.prefetch %arg0, %arg1 {cache = 1 : i32, evict = 1 : i32, isVolatile = false} : !tt.ptr<tensor<2x32xf32>>
tt.return
}

// -----

#warp = #triton_intel_gpu.warp<{sizePerThread = [16, 64], threadsPerWarp = [1, 1], order = [1, 0]}>

module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 8 : i32, "ttg.threads-per-warp" = 16 : i32, triton_intel_gpu.min_sg_size = 16 : i32, triton_intel_gpu.support_dpas, triton_intel_gpu.support_sg_2d_block} {
Expand Down
11 changes: 11 additions & 0 deletions test/TritonIntelGPU/tritonintelgpu.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ tt.func @simplify_scf_for(%arg0: tensor<16x8xf16>, %arg1: tensor<16x8xf16>, %arg

// -----

tt.func @triton_intel_gpu.prefetch(%arg0: !tt.ptr<tensor<2x32xf32>>, %arg1: tensor<2x32xi1>) {
// CHECK-LABEL: @triton_intel_gpu.prefetch
// CHECK: triton_intel_gpu.prefetch %arg0 {cache = 1 : i32, evict = 1 : i32, isVolatile = false} : !tt.ptr<tensor<2x32xf32>>
triton_intel_gpu.prefetch %arg0 {cache = 1 : i32, evict = 1 : i32, isVolatile = false} : !tt.ptr<tensor<2x32xf32>>
// CHECK: triton_intel_gpu.prefetch %arg0, %arg1 {cache = 1 : i32, evict = 1 : i32, isVolatile = false} : !tt.ptr<tensor<2x32xf32>>
triton_intel_gpu.prefetch %arg0, %arg1 {cache = 1 : i32, evict = 1 : i32, isVolatile = false} : !tt.ptr<tensor<2x32xf32>>
tt.return
}

// -----

module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 8 : i32, "ttg.threads-per-warp" = 16 : i32, triton_intel_gpu.min_sg_size = 16 : i32, triton_intel_gpu.support_dpas, triton_intel_gpu.support_sg_2d_block} {
tt.func @triton_intel_gpu.sub_group_transpose(%local_buffer : !tt.ptr<f16, 3>, %src : tensor<16x16xf16>) -> tensor<16x16xf16> {
// CHECK-LABEL: @triton_intel_gpu.sub_group_transpose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ def TTIG_ExtractOp : TTIG_Op<"extract", [Pure]> {
let hasFolder = 1;
}

def TTIG_PrefetchOp : TTIG_Op<"prefetch"> {
def TTIG_PrefetchOp : TTIG_Op<"prefetch", [
TypesMatchWith<"mask type matches ptr type", "ptr", "mask", "getI1SameShape(getPointeeType($_self))",
"($_op.getOperands().size() <= 1) || std::equal_to<>()">,
]> {
let summary = "Tensor prefetch operation";
let description = [{
The `prefetch` operation prefetches an input tensor.
Expand All @@ -117,11 +120,20 @@ def TTIG_PrefetchOp : TTIG_Op<"prefetch"> {
: !tt.ptr<tensor<256x32xf16>
```
}];
let arguments = (ins AnyTypeOf<[TT_PtrLike, TT_TensorPtr]>:$ptr, TT_CacheModifierAttr:$cache,
TT_EvictionPolicyAttr:$evict, BoolAttr:$isVolatile);
let arguments = (
ins AnyTypeOf<[TT_PtrLike, TT_TensorPtr]>:$ptr,
Optional<TT_BoolLike>:$mask,
TT_CacheModifierAttr:$cache,
TT_EvictionPolicyAttr:$evict,
BoolAttr:$isVolatile
);
let results = (outs);
let builders = [
OpBuilder<(ins "Value":$ptr, "triton::CacheModifier":$cache,
"triton::EvictionPolicy":$evict, "bool":$isVolatile)>
];
let assemblyFormat = [{
operands attr-dict `:` type($ptr)
$ptr (`,` $mask^)? attr-dict `:` type($ptr)
}];
}

Expand Down
6 changes: 6 additions & 0 deletions third_party/intel/lib/Dialect/TritonIntelGPU/IR/Ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ OpFoldResult ExtractOp::fold(FoldAdaptor adaptor) {
return {};
}

void PrefetchOp::build(OpBuilder &builder, OperationState &state, Value ptr,
CacheModifier cache, EvictionPolicy evict,
bool isVolatile) {
PrefetchOp::build(builder, state, ptr, /*mask=*/{}, cache, evict, isVolatile);
}

LogicalResult SubGroupTransposeOp::verify() {
RankedTensorType srcType = getSrc().getType();
auto mod = getOperation()->getParentOfType<mlir::ModuleOp>();
Expand Down