Skip to content

Commit 8481fb1

Browse files
authored
[MLIR][ROCDL] Fix BallotOp LLVM translation and add doc (#85116)
This modifies the return type of the intrinsic call to handle 32 and 64 bits properly and document the MLIR operation.
1 parent 23323e2 commit 8481fb1

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,18 @@ def ROCDL_BallotOp :
162162
ROCDL_Op<"ballot">,
163163
Results<(outs LLVM_Type:$res)>,
164164
Arguments<(ins I1:$pred)> {
165+
let summary = "Vote across thread group";
166+
167+
let description = [{
168+
Ballot provides a bit mask containing the 1-bit predicate value from each lane.
169+
The nth bit of the result contains the 1 bit contributed by the nth warp lane.
170+
}];
171+
165172
string llvmBuilder = [{
166173
$res = createIntrinsicCall(builder,
167-
llvm::Intrinsic::amdgcn_ballot, {$pred}, {llvm::Type::getInt32Ty(moduleTranslation.getLLVMContext())});
174+
llvm::Intrinsic::amdgcn_ballot, {$pred}, {$_resultType});
168175
}];
176+
169177
let assemblyFormat = "$pred attr-dict `:` type($res)";
170178
}
171179

mlir/test/Target/LLVMIR/rocdl.mlir

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,20 @@ llvm.func @rocdl.bpermute(%src : i32) -> i32 {
8888
llvm.return %0 : i32
8989
}
9090

91-
llvm.func @rocdl.ballot(%pred : i1) -> i32 {
92-
// CHECK-LABEL: rocdl.ballot
91+
llvm.func @rocdl.ballot32(%pred : i1) -> i32 {
92+
// CHECK-LABEL: rocdl.ballot32
9393
// CHECK: call i32 @llvm.amdgcn.ballot
9494
%0 = rocdl.ballot %pred : i32
9595
llvm.return %0 : i32
9696
}
9797

98+
llvm.func @rocdl.ballot64(%pred : i1) -> i64 {
99+
// CHECK-LABEL: rocdl.ballot64
100+
// CHECK: call i64 @llvm.amdgcn.ballot
101+
%0 = rocdl.ballot %pred : i64
102+
llvm.return %0 : i64
103+
}
104+
98105
llvm.func @rocdl.waitcnt() {
99106
// CHECK-LABEL: rocdl.waitcnt
100107
// CHECK-NEXT: call void @llvm.amdgcn.s.waitcnt(i32 0)

0 commit comments

Comments
 (0)