[Mlir-commits] [mlir] [MLIR-NVVMDialect]: Add cp.async.mbarrier.arrive Op (PR #74241)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Dec 4 07:43:10 PST 2023
https://github.com/durga4github updated https://github.com/llvm/llvm-project/pull/74241
>From 902abe98dad1cc8ccb8b4cfff9b3a9e4ac8ac3f5 Mon Sep 17 00:00:00 2001
From: Durgadoss R <durgadossr at nvidia.com>
Date: Sun, 3 Dec 2023 17:35:00 +0530
Subject: [PATCH] [MLIR][NVVM]: Add cp.async.mbarrier.arrive Op
This patch adds an Op for 'cp.async.mbarrier.arrive',
targeting the nvvm_cp_async_mbarrier_arrive* family of
intrinsics.
Test cases are added to verify the Op as well as the
intrinsic lowering.
v2:
* Separate Op added for the 'shared' variant to be
consistent with the existing MBarrier Ops.
Signed-off-by: Durgadoss R <durgadossr at nvidia.com>
---
mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td | 49 +++++++++++++++++++
.../Conversion/NVVMToLLVM/nvvm-to-llvm.mlir | 13 +++++
mlir/test/Target/LLVMIR/nvvmir.mlir | 13 +++++
3 files changed, 75 insertions(+)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
index ecad1a16eb6c5..7a52020f6e168 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
@@ -592,6 +592,55 @@ def NVVM_CpAsyncWaitGroupOp : NVVM_Op<"cp.async.wait.group">,
let assemblyFormat = "$n attr-dict";
}
+def NVVM_CpAsyncMBarrierArriveOp : NVVM_Op<"cp.async.mbarrier.arrive"> {
+ let summary = "NVVM Dialect Op for cp.async.mbarrier.arrive";
+ let description = [{
+ The `cp.async.mbarrier.arrive` Op makes the mbarrier object track
+ all prior cp.async operations initiated by the executing thread.
+ The `addr` operand specifies the address of the mbarrier object
+ in generic address space. The `noinc` attr impacts how the
+ mbarrier's state is updated.
+ [For more information, refer PTX ISA]
+ (https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-cp-async-mbarrier-arrive)
+ }];
+ let assemblyFormat = "$addr attr-dict `:` type(operands)";
+
+ let arguments = (ins
+ LLVM_AnyPointer:$addr, DefaultValuedAttr<I1Attr, "0">:$noinc);
+
+ string llvmBuilder = [{
+ auto intId = $noinc ?
+ llvm::Intrinsic::nvvm_cp_async_mbarrier_arrive_noinc :
+ llvm::Intrinsic::nvvm_cp_async_mbarrier_arrive;
+
+ createIntrinsicCall(builder, intId, {$addr});
+ }];
+}
+
+def NVVM_CpAsyncMBarrierArriveSharedOp : NVVM_Op<"cp.async.mbarrier.arrive.shared"> {
+ let summary = "NVVM Dialect Op for cp.async.mbarrier.arrive.shared";
+ let description = [{
+ The `cp.async.mbarrier.arrive.shared` Op makes the mbarrier object
+ track all prior cp.async operations initiated by the executing thread.
+ The `addr` operand specifies the address of the mbarrier object in
+ shared memory. The `noinc` attr impacts how the mbarrier's state
+ is updated. [For more information, refer PTX ISA]
+ (https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-cp-async-mbarrier-arrive)
+ }];
+ let assemblyFormat = "$addr attr-dict `:` type(operands)";
+
+ let arguments = (ins
+ LLVM_PointerShared:$addr, DefaultValuedAttr<I1Attr, "0">:$noinc);
+
+ string llvmBuilder = [{
+ auto intId = $noinc ?
+ llvm::Intrinsic::nvvm_cp_async_mbarrier_arrive_noinc_shared :
+ llvm::Intrinsic::nvvm_cp_async_mbarrier_arrive_shared;
+
+ createIntrinsicCall(builder, intId, {$addr});
+ }];
+}
+
/// Helpers to instantiate different version of wmma intrinsics.
/// This matches the hierarchy used in IntrinsicsNVVM.td to define all the
/// combinations of the intrinsics.
diff --git a/mlir/test/Conversion/NVVMToLLVM/nvvm-to-llvm.mlir b/mlir/test/Conversion/NVVMToLLVM/nvvm-to-llvm.mlir
index 5482cc194192d..4f6d90a43efe4 100644
--- a/mlir/test/Conversion/NVVMToLLVM/nvvm-to-llvm.mlir
+++ b/mlir/test/Conversion/NVVMToLLVM/nvvm-to-llvm.mlir
@@ -85,6 +85,19 @@ func.func @async_cp_zfill(%dst: !llvm.ptr<3>, %src: !llvm.ptr<1>, %cpSize: i32)
return
}
+// CHECK-LABEL: @cp_async_mbarrier_arrive
+func.func @cp_async_mbarrier_arrive(%bar_shared: !llvm.ptr<3>, %bar_gen: !llvm.ptr) {
+ // CHECK: nvvm.cp.async.mbarrier.arrive %{{.*}}
+ nvvm.cp.async.mbarrier.arrive %bar_gen : !llvm.ptr
+ // CHECK: nvvm.cp.async.mbarrier.arrive %{{.*}} {noinc = true}
+ nvvm.cp.async.mbarrier.arrive %bar_gen {noinc = true} : !llvm.ptr
+ // CHECK: nvvm.cp.async.mbarrier.arrive.shared %{{.*}}
+ nvvm.cp.async.mbarrier.arrive.shared %bar_shared : !llvm.ptr<3>
+ // CHECK: nvvm.cp.async.mbarrier.arrive.shared %{{.*}} {noinc = true}
+ nvvm.cp.async.mbarrier.arrive.shared %bar_shared {noinc = true} : !llvm.ptr<3>
+ llvm.return
+}
+
// CHECK-LABEL: @tma_load_3d_all
func.func @tma_load_3d_all(%tmaDescriptor: !llvm.ptr, %dest : !llvm.ptr<3>, %barrier: !llvm.ptr<3>, %crd0: i32, %crd1: i32, %crd2: i32, %crd3: i32, %off0: i16, %off1: i16, %ctamask : i16, %cacheHint : i64, %p : i1) {
// CHECK: llvm.inline_asm has_side_effects asm_dialect = att "cp.async.bulk.tensor.3d.shared::cluster.global.mbarrier::complete_tx::bytes.im2col.multicast::cluster.L2::cache_hint [$0], [$1, {$2,$3,$4} ], [$5],{$6}, $7, $8;", "r,l,r,r,r,r,h,h,l"
diff --git a/mlir/test/Target/LLVMIR/nvvmir.mlir b/mlir/test/Target/LLVMIR/nvvmir.mlir
index 76540cc2c3973..3fed2c24b314f 100644
--- a/mlir/test/Target/LLVMIR/nvvmir.mlir
+++ b/mlir/test/Target/LLVMIR/nvvmir.mlir
@@ -352,6 +352,19 @@ llvm.func @cp_async(%arg0: !llvm.ptr<3>, %arg1: !llvm.ptr<1>) {
llvm.return
}
+// CHECK-LABEL: @cp_async_mbarrier_arrive
+llvm.func @cp_async_mbarrier_arrive(%bar_shared: !llvm.ptr<3>, %bar_gen: !llvm.ptr) {
+ // CHECK: call void @llvm.nvvm.cp.async.mbarrier.arrive(ptr %{{.*}})
+ nvvm.cp.async.mbarrier.arrive %bar_gen : !llvm.ptr
+ // CHECK: call void @llvm.nvvm.cp.async.mbarrier.arrive.noinc(ptr %{{.*}})
+ nvvm.cp.async.mbarrier.arrive %bar_gen {noinc = true} : !llvm.ptr
+ // CHECK: call void @llvm.nvvm.cp.async.mbarrier.arrive.shared(ptr addrspace(3) %{{.*}})
+ nvvm.cp.async.mbarrier.arrive.shared %bar_shared : !llvm.ptr<3>
+ // CHECK: call void @llvm.nvvm.cp.async.mbarrier.arrive.noinc.shared(ptr addrspace(3) %{{.*}})
+ nvvm.cp.async.mbarrier.arrive.shared %bar_shared {noinc = true} : !llvm.ptr<3>
+ llvm.return
+}
+
// CHECK-LABEL: @ld_matrix
llvm.func @ld_matrix(%arg0: !llvm.ptr<3>) {
// CHECK: call i32 @llvm.nvvm.ldmatrix.sync.aligned.m8n8.x1.b16.p3(ptr addrspace(3) %{{.*}})
More information about the Mlir-commits
mailing list