Skip to content
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
6 changes: 4 additions & 2 deletions include/triton/Dialect/TritonInstrument/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ mlir_tablegen(Dialect.h.inc -gen-dialect-decls -dialect=tti)
mlir_tablegen(Dialect.cpp.inc -gen-dialect-defs -dialect=tti)
add_mlir_doc(TritonInstrumentDialect TritonInstrumentDialect dialects/ -gen-dialect-doc -dialect=tti)

set(LLVM_TARGET_DEFINITIONS TritonInstrumentAttrDefs.td)
mlir_tablegen(OpsEnums.h.inc -gen-enum-decls)
mlir_tablegen(OpsEnums.cpp.inc -gen-enum-defs)

set(LLVM_TARGET_DEFINITIONS TritonInstrumentOps.td)
mlir_tablegen(Ops.h.inc -gen-op-decls)
mlir_tablegen(Ops.cpp.inc -gen-op-defs)
mlir_tablegen(OpsEnums.h.inc -gen-enum-decls)
mlir_tablegen(OpsEnums.cpp.inc -gen-enum-defs)
add_mlir_doc(TritonInstrumentOps TritonInstrumentOps dialects/ -gen-op-doc -dialect=tti)

add_public_tablegen_target(TritonInstrumentTableGen)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
include "triton/Dialect/TritonInstrument/IR/TritonInstrumentDialect.td"
include "triton/Dialect/TritonGPU/IR/TritonGPUTypes.td"
include "triton/Dialect/Triton/IR/TritonTypes.td"
include "triton/Dialect/Triton/IR/TritonInterfaces.td"
include "triton/Dialect/Triton/IR/TritonAttrDefs.td"
include "mlir/IR/OpBase.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "triton/Dialect/TritonInstrument/IR/TritonInstrumentAttrDefs.td"
Expand Down Expand Up @@ -56,11 +58,6 @@ def TTI_ExperimentalMemDescToI32Op : TTI_Op<"experimental_memdesc_to_i32", [Pure
}];
let arguments = (ins TTG_MemDescType:$memdesc);
let results = (outs I32:$result);
let builders = [
OpBuilder<(ins "Value":$memdesc), [{
build($_builder, $_state, $_builder.getI32Type(), memdesc);
}]>
];
let assemblyFormat = "$memdesc attr-dict `:` type($memdesc)";
}

Expand Down Expand Up @@ -118,6 +115,55 @@ def TTI_ExperimentalGSanTensorAccessOp
}];
}

def TTI_ExperimentalGSanAtomicRMWOp : TTI_Op<"experimental_gsan_atomic_rmw", [
SameOperandsAndResultShape,
SameOperandsAndResultEncoding,
TypesMatchWith<"ptr type matches value type", "val", "ptr",
"getPointerTypeSameShape($_self)">,
TypesMatchWith<"mask type matches value type",
"val", "mask", "getI1SameShape($_self)",
"($_op.getOperands().size() <= 2) || std::equal_to<>()">
]> {
let summary = "Lower a GSan-instrumented atomic rmw";
let arguments = (ins
TT_AtomicRMWAttr:$atomic_rmw_op,
Arg<TT_PtrLike, "", [MemRead<GlobalMemory>, MemWrite<GlobalMemory>]>:$ptr,
TT_Type:$val,
Optional<TT_BoolLike>:$mask,
TT_MemSemanticAttr:$sem,
TT_MemSyncScopeAttr:$scope
);
let results = (outs TT_Type:$result);
let assemblyFormat = [{
$atomic_rmw_op `,` $sem `,` $scope `,` $ptr `,` $val (`,` $mask^)? attr-dict `:`
functional-type(operands, $result)
}];
}

def TTI_ExperimentalGSanAtomicCASOp : TTI_Op<"experimental_gsan_atomic_cas", [
SameOperandsAndResultShape,
SameOperandsAndResultEncoding,
TypesMatchWith<"ptr type matches cmp type", "cmp", "ptr",
"getPointerTypeSameShape($_self)">,
TypesMatchWith<"ptr type matches value type", "val", "ptr",
"getPointerTypeSameShape($_self)">
]> {
let summary = "Lower a GSan-instrumented atomic cas";
let arguments = (ins
Arg<TT_PtrLike, "", [MemRead<GlobalMemory>, MemWrite<GlobalMemory>]>:$ptr,
TT_Type:$cmp,
TT_Type:$val,
TT_MemSemanticAttr:$sem,
TT_MemSyncScopeAttr:$scope
);
let results = (outs TT_Type:$result);
let assemblyFormat = [{
$sem `,` $scope `,` $ptr `,` $cmp `,` $val attr-dict `:`
functional-type(operands, $result)
}];
}


// ===== Critical section lock ops =====


Expand Down
5 changes: 4 additions & 1 deletion lib/Analysis/Allocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "triton/Dialect/Triton/IR/Dialect.h"
#include "triton/Dialect/Triton/IR/Utility.h"
#include "triton/Dialect/TritonGPU/IR/Dialect.h"
#include "triton/Dialect/TritonInstrument/IR/Dialect.h"
#include "triton/Dialect/TritonNvidiaGPU/IR/Dialect.h"
#include "triton/Tools/GenericSwizzling.h"
#include "triton/Tools/LayoutUtils.h"
Expand All @@ -30,6 +31,7 @@ static size_t getPartitionIndex(size_t offset, size_t partitionSize) {
}

namespace ttng = mlir::triton::nvidia_gpu;
namespace tti = mlir::triton::instrument;

namespace mlir {

Expand Down Expand Up @@ -115,7 +117,8 @@ unsigned defaultAllocationAnalysisScratchSizeFn(Operation *op) {
auto elems = getNumScratchElemsSwizzledCvt(srcTy, dstTy);
return elems * getBitwidth(srcTy) / 8;
}
if (isa<AtomicRMWOp, AtomicCASOp>(op)) {
if (isa<AtomicRMWOp, AtomicCASOp, tti::ExperimentalGSanAtomicRMWOp,
tti::ExperimentalGSanAtomicCASOp>(op)) {
auto value = op->getOperand(0);
auto smemShape = getRepShapeForAtomic(op->getResult(0));
auto elems = getNumScratchElements(smemShape);
Expand Down
Loading
Loading