[Mlir-commits] [mlir] [ROCDL] Added BallotOp and lit test (PR #84856)

Zahi Moudallal llvmlistbot at llvm.org
Mon Mar 11 17:56:55 PDT 2024


https://github.com/zahimoud updated https://github.com/llvm/llvm-project/pull/84856

>From a95f018e90542a0d2f31538da19b1a38bec8feb1 Mon Sep 17 00:00:00 2001
From: Zahi Moudallal <zahi at openai.com>
Date: Mon, 11 Mar 2024 17:06:23 -0700
Subject: [PATCH] [ROCDL] Added BallotOp and lit test

---
 mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td | 12 ++++++++++++
 mlir/test/Target/LLVMIR/rocdl.mlir           |  7 +++++++
 2 files changed, 19 insertions(+)

diff --git a/mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td b/mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td
index 32b5a1c016b6f8..bf6b85e8da916d 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td
@@ -158,6 +158,18 @@ Arguments<(ins I32:$index,
    }];
 }
 
+def ROCDL_BallotOp :
+  ROCDL_Op<"ballot">,
+  Results<(outs LLVM_Type:$res)>,
+  Arguments<(ins I1:$pred)> {
+  string llvmBuilder = [{
+      $res = createIntrinsicCall(builder,
+            llvm::Intrinsic::amdgcn_ballot, {$pred});
+  }];
+  let assemblyFormat = [{ 
+    $pred attr-dict `:` type($res)
+  }];
+}
 
 //===----------------------------------------------------------------------===//
 // Thread index and Block index
diff --git a/mlir/test/Target/LLVMIR/rocdl.mlir b/mlir/test/Target/LLVMIR/rocdl.mlir
index d35acb0475e6f8..93550f5c7bd5a4 100644
--- a/mlir/test/Target/LLVMIR/rocdl.mlir
+++ b/mlir/test/Target/LLVMIR/rocdl.mlir
@@ -88,6 +88,13 @@ llvm.func @rocdl.bpermute(%src : i32) -> i32 {
   llvm.return %0 : i32
 }
 
+llvm.func @rocdl.ballot(%pred : i1) -> i32 {
+  // CHECK-LABEL: rocdl.ballot
+  // CHECK: call i32 @llvm.amdgcn.ballot
+  %0 = rocdl.ballot %pred : i32
+  llvm.return %0 : i32
+}
+
 llvm.func @rocdl.waitcnt() {
   // CHECK-LABEL: rocdl.waitcnt
   // CHECK-NEXT: call void @llvm.amdgcn.s.waitcnt(i32 0)



More information about the Mlir-commits mailing list