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

support bypassing data layout conversion for atomic operator #556

Open
wants to merge 1 commit into
base: triton-mlir
Choose a base branch
from
Open
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
43 changes: 31 additions & 12 deletions lib/Dialect/TritonGPU/Transforms/OptimizeEpilogue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,34 @@ class BypassEpilogueSMEM : public mlir::RewritePattern {

public:
explicit BypassEpilogueSMEM(mlir::MLIRContext *context)
: mlir::RewritePattern(triton::StoreOp::getOperationName(), 1, context) {}
: mlir::RewritePattern(MatchAnyOpTypeTag(), 1, context) {}
mlir::LogicalResult
matchAndRewrite(mlir::Operation *op,
mlir::PatternRewriter &rewriter) const override {

auto stOp = dyn_cast<triton::StoreOp>(op);
if (!stOp)
Value ptr, val, mask;
RankedTensorType ptrType, valType;
triton::gpu::ConvertLayoutOp cvtOp;

if (auto stOp = dyn_cast<triton::StoreOp>(op)){
ptr = stOp.getPtr();
val = stOp.getValue();
mask = stOp.getMask();
} else if (auto atomicRMWOp = dyn_cast<triton::AtomicRMWOp>(op)) {
ptr = atomicRMWOp.getPtr();
val = atomicRMWOp.getVal();
mask = atomicRMWOp.getMask();
} else {
return mlir::failure();
Value ptr = stOp.getPtr();
Value val = stOp.getValue();
Value mask = stOp.getMask();
auto ptrType = ptr.getType().dyn_cast<RankedTensorType>();
auto valType = val.getType().dyn_cast<RankedTensorType>();
}

ptrType = ptr.getType().dyn_cast<RankedTensorType>();
valType = val.getType().dyn_cast<RankedTensorType>();
if (!ptrType || !valType ||
!ptrType.getEncoding().isa<triton::gpu::BlockedEncodingAttr>() ||
!valType.getEncoding().isa<triton::gpu::BlockedEncodingAttr>())
return mlir::failure();

auto cvtOp = dyn_cast<triton::gpu::ConvertLayoutOp>(val.getDefiningOp());
cvtOp = dyn_cast<triton::gpu::ConvertLayoutOp>(val.getDefiningOp());
if (!cvtOp)
return mlir::failure();

Expand Down Expand Up @@ -80,8 +89,18 @@ class BypassEpilogueSMEM : public mlir::RewritePattern {
mask.getLoc(), newMaskType, mask);
}

rewriter.replaceOpWithNewOp<triton::StoreOp>(
stOp, newPtr, newVal, newMask, stOp.getCache(), stOp.getEvict());
if (auto stOp = dyn_cast<triton::StoreOp>(op)) {
rewriter.replaceOpWithNewOp<triton::StoreOp>(
stOp, newPtr, newVal, newMask, stOp.getCache(), stOp.getEvict());
} else if (auto atomicRMWOp = dyn_cast<triton::AtomicRMWOp>(op)) {
auto result = atomicRMWOp.getResult();
auto resultType = result.getType().dyn_cast<RankedTensorType>();
auto newResultType = RankedTensorType::get(
resultType.getShape(), resultType.getElementType(), newEncoding);
rewriter.replaceOpWithNewOp<triton::AtomicRMWOp>(
atomicRMWOp, newResultType, atomicRMWOp.getAtomicRmwOpAttr(), newPtr, newVal, newMask, atomicRMWOp.getSemAttr(), atomicRMWOp.getScopeAttr());
}

return mlir::success();
}
};
Expand Down
Loading