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

[ROCDL] Add the global.atomic.fadd intrinsic in ROCDL #94486

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 15 additions & 2 deletions mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def ROCDL_BallotOp :
let summary = "Vote across thread group";

let description = [{
Ballot provides a bit mask containing the 1-bit predicate value from each lane.
Ballot provides a bit mask containing the 1-bit predicate value from each lane.
giuseros marked this conversation as resolved.
Show resolved Hide resolved
The nth bit of the result contains the 1 bit contributed by the nth warp lane.
}];

Expand Down Expand Up @@ -516,7 +516,7 @@ def ROCDL_RawBufferAtomicCmpSwap :
}

//===---------------------------------------------------------------------===//
// MI-100 and MI-200 buffer atomic floating point add intrinsic
// MI-100, MI-200 and MI-300 global/buffer atomic floating point add intrinsic
giuseros marked this conversation as resolved.
Show resolved Hide resolved

def ROCDL_RawBufferAtomicFAddOp :
ROCDL_Op<"raw.buffer.atomic.fadd">,
Expand All @@ -534,6 +534,19 @@ def ROCDL_RawBufferAtomicFAddOp :
let hasCustomAssemblyFormat = 1;
}

def ROCDL_GlobalAtomicFAddOp :
ROCDL_Op<"global.atomic.fadd">,
Arguments<(ins LLVM_Type:$ptr,
giuseros marked this conversation as resolved.
Show resolved Hide resolved
LLVM_Type:$vdata)>{
string llvmBuilder = [{
auto vdataType = moduleTranslation.convertType(op.getVdata().getType());
auto ptrType = moduleTranslation.convertType(op.getPtr().getType());
createIntrinsicCall(builder,
llvm::Intrinsic::amdgcn_global_atomic_fadd, {$ptr, $vdata}, {vdataType, ptrType, vdataType});
}];
let hasCustomAssemblyFormat = 1;
}

//===---------------------------------------------------------------------===//
// Buffer atomic floating point max intrinsic. GFX9 does not support fp32.

Expand Down
20 changes: 20 additions & 0 deletions mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,26 @@ void RawBufferAtomicFAddOp::print(mlir::OpAsmPrinter &p) {
p << " " << getOperands() << " : " << getVdata().getType();
}

// <operation> ::=
// `llvm.amdgcn.global.atomic.fadd.* %vdata, %ptr
ParseResult GlobalAtomicFAddOp::parse(OpAsmParser &parser,
OperationState &result) {
SmallVector<OpAsmParser::UnresolvedOperand, 5> ops;
Type type;
if (parser.parseOperandList(ops, 2) || parser.parseColonType(type))
return failure();

auto ptrType = LLVM::LLVMPointerType::get(parser.getContext());
if (parser.resolveOperands(ops, {ptrType, type}, parser.getNameLoc(),
result.operands))
return failure();
return success();
}

void GlobalAtomicFAddOp::print(mlir::OpAsmPrinter &p) {
p << " " << getOperands() << " : " << getVdata().getType();
}

// <operation> ::=
// `llvm.amdgcn.raw.buffer.atomic.fmax.* %vdata, %rsrc, %offset,
// %soffset, %aux : result_type`
Expand Down
9 changes: 9 additions & 0 deletions mlir/test/Target/LLVMIR/rocdl.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,15 @@ llvm.func @rocdl.raw.buffer.atomic.f32(%rsrc : vector<4xi32>,
llvm.return
}

// CHECK-LABEL: rocdl.global.atomic
llvm.func @rocdl.global.atomic(%vdata0 : f32, %vdata1 : vector<2xf16>, %ptr : !llvm.ptr) {
// CHECK: call float @llvm.amdgcn.global.atomic.fadd.f32.p0.f32(ptr %{{.*}}, float %{{.*}}
rocdl.global.atomic.fadd %ptr, %vdata0: f32
// CHECK: call <2 x half> @llvm.amdgcn.global.atomic.fadd.v2f16.p0.v2f16(ptr %{{.*}}, <2 x half> %{{.*}})
rocdl.global.atomic.fadd %ptr, %vdata1: vector<2xf16>
llvm.return
}

llvm.func @rocdl.raw.buffer.atomic.i32(%rsrc : vector<4xi32>,
%offset : i32, %soffset : i32,
%vdata1 : i32) {
Expand Down
Loading