Skip to content

Commit 14fd9cb

Browse files
[AMD] Add BufferOp interface (#8600)
This PR introduces a common interface for buffer ops. --------- Co-authored-by: Alexander Efimov <[email protected]>
1 parent de8e715 commit 14fd9cb

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

third_party/amd/include/Dialect/TritonAMDGPU/IR/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ mlir_tablegen(TritonAMDGPUEnums.h.inc -gen-enum-decls)
1515
mlir_tablegen(TritonAMDGPUEnums.cpp.inc -gen-enum-defs)
1616
mlir_tablegen(TritonAMDGPUAttrDefs.h.inc -gen-attrdef-decls)
1717
mlir_tablegen(TritonAMDGPUAttrDefs.cpp.inc -gen-attrdef-defs)
18+
19+
set(LLVM_TARGET_DEFINITIONS TritonAMDGPUOpInterfaces.td)
20+
mlir_tablegen(TritonAMDGPUOpInterfaces.h.inc -gen-op-interface-decls)
21+
mlir_tablegen(TritonAMDGPUOpInterfaces.cpp.inc -gen-op-interface-defs)
22+
1823
add_public_tablegen_target(TritonAMDGPUAttrDefsIncGen)

third_party/amd/include/Dialect/TritonAMDGPU/IR/Dialect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#define GET_ATTRDEF_CLASSES
4242
#include "amd/include/Dialect/TritonAMDGPU/IR/TritonAMDGPUAttrDefs.h.inc"
4343

44+
#include "amd/include/Dialect/TritonAMDGPU/IR/TritonAMDGPUOpInterfaces.h.inc"
4445
#define GET_OP_CLASSES
4546
#include "amd/include/Dialect/TritonAMDGPU/IR/Ops.h.inc"
4647

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef TRITON_AMDGPU_OP_INTERFACES
2+
#define TRITON_AMDGPU_OP_INTERFACES
3+
4+
include "mlir/IR/OpBase.td"
5+
6+
def BufferOpInterface : OpInterface<"BufferOpInterface"> {
7+
let description = [{
8+
This interface is implemented by buffer load/store operations.
9+
It provides methods to access common properties such base pointer, offset, mask and others.
10+
}];
11+
12+
let cppNamespace = "::mlir::triton::amdgpu";
13+
14+
let methods = [
15+
InterfaceMethod<
16+
/*desc=*/"Get operation base ptr.",
17+
/*retType=*/"::mlir::TypedValue<::mlir::triton::PointerType>",
18+
/*methodName=*/"getPtr">,
19+
InterfaceMethod<
20+
/*desc=*/"Get mutable operation base ptr.",
21+
/*retType=*/"::mlir::OpOperand &",
22+
/*methodName=*/"getPtrMutable">,
23+
InterfaceMethod<
24+
/*desc=*/"Get operation offset tensor.",
25+
/*retType=*/"::mlir::TypedValue<::mlir::TensorType>",
26+
/*methodName=*/"getOffsets">,
27+
InterfaceMethod<
28+
/*desc=*/"Get mutable operation offset tensor.",
29+
/*retType=*/"::mlir::OpOperand &",
30+
/*methodName=*/"getOffsetsMutable">,
31+
InterfaceMethod<
32+
/*desc=*/"Get operation stride.",
33+
/*retType=*/"::mlir::TypedValue<::mlir::IntegerType>",
34+
/*methodName=*/"getStride">,
35+
InterfaceMethod<
36+
/*desc=*/"Get mutable operation stride.",
37+
/*retType=*/"::mlir::MutableOperandRange ",
38+
/*methodName=*/"getStrideMutable">
39+
];
40+
}
41+
42+
#endif // TRITON_AMDGPU_OP_INTERFACES

third_party/amd/include/Dialect/TritonAMDGPU/IR/TritonAMDGPUOps.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ include "mlir/Interfaces/InferTypeOpInterface.td"
4141
include "mlir/Interfaces/SideEffectInterfaces.td" // Pure
4242
include "TritonAMDGPUDialect.td"
4343
include "TritonAMDGPUAttrDefs.td"
44+
include "TritonAMDGPUOpInterfaces.td"
4445

4546

4647
class TT_AMDGPU_Op<string mnemonic, list<Trait> traits = []> :
@@ -283,6 +284,7 @@ def CondBarrierOp : TT_AMDGPU_Op<"cond_barrier"> {
283284
def BufferLoadOp : TT_AMDGPU_Op<"buffer_load", [
284285
SameLoadStoreOperandsAndResultEncoding,
285286
AttrSizedOperandSegments,
287+
BufferOpInterface,
286288
TypesMatchWith<"result element type matches the pointed type of ptr", "result", "ptr", "getPointerTypeToElement($_self)">,
287289
TypesMatchWith<"result and offsets have the same shape", "result", "offsets", "getI32SameShape($_self)">,
288290
TypesMatchWith<"result and mask have the same shape", "result", "mask", "getI1SameShape($_self)",
@@ -328,6 +330,7 @@ def BufferLoadOp : TT_AMDGPU_Op<"buffer_load", [
328330

329331
def BufferLoadToLocalOp : TT_AMDGPU_Op<"buffer_load_to_local", [
330332
AttrSizedOperandSegments,
333+
BufferOpInterface,
331334
TypesMatchWith<"dest element type matches pointee type of ptr", "dest", "ptr", "getPointerTypeToElement($_self)">,
332335
TypesMatchWith<"infer mask shape from offsets",
333336
"offsets", "mask", "getI1SameShape($_self)",
@@ -364,6 +367,7 @@ def BufferLoadToLocalOp : TT_AMDGPU_Op<"buffer_load_to_local", [
364367
def BufferAtomicRMWOp : TT_AMDGPU_Op<"buffer_atomic_rmw", [
365368
AttrSizedOperandSegments,
366369
SameLoadStoreOperandsAndResultEncoding,
370+
BufferOpInterface,
367371
TypesMatchWith<"result element type matches the value type", "result", "value", "$_self">,
368372
TypesMatchWith<"result element type matches the pointed type of ptr", "result", "ptr", "getPointerTypeToElement($_self)">,
369373
TypesMatchWith<"result and offsets have the same shape", "result", "offsets", "getI32SameShape($_self)">,
@@ -410,6 +414,7 @@ def BufferAtomicRMWOp : TT_AMDGPU_Op<"buffer_atomic_rmw", [
410414
//===----------------------------------------------------------------------===//
411415
def BufferAtomicCASOp : TT_AMDGPU_Op<"buffer_atomic_cas", [
412416
SameLoadStoreOperandsAndResultEncoding,
417+
BufferOpInterface,
413418
TypesMatchWith<"result element type matches the val type", "result", "val", "$_self">,
414419
TypesMatchWith<"result element type matches the cmp type", "result", "cmp", "$_self">,
415420
TypesMatchWith<"result element type matches the pointed type of ptr", "result", "ptr", "getPointerTypeToElement($_self)">,
@@ -452,6 +457,7 @@ def BufferAtomicCASOp : TT_AMDGPU_Op<"buffer_atomic_cas", [
452457
def BufferStoreOp : TT_AMDGPU_Op<"buffer_store", [
453458
AttrSizedOperandSegments,
454459
SameLoadStoreOperandsEncoding,
460+
BufferOpInterface,
455461
TypesMatchWith<"value element type matches the pointed type of ptr", "value", "ptr", "getPointerTypeToElement($_self)">,
456462
TypesMatchWith<"value and offsets have the same shape", "value", "offsets", "getI32SameShape($_self)">,
457463
TypesMatchWith<"value and mask have the same shape", "value", "mask", "getI1SameShape($_self)",

third_party/amd/lib/Dialect/TritonAMDGPU/IR/Dialect.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void mlir::triton::amdgpu::TritonAMDGPUDialect::initialize() {
6262

6363
#define GET_OP_CLASSES
6464
#include "Dialect/TritonAMDGPU/IR/Ops.cpp.inc"
65+
#include "Dialect/TritonAMDGPU/IR/TritonAMDGPUOpInterfaces.cpp.inc"
6566

6667
namespace mlir::triton::amdgpu {
6768

0 commit comments

Comments
 (0)