Skip to content

Commit 6a075a9

Browse files
authored
[MLIR][NVVM]: Update setmaxregister NVVM Op (#77594)
This patch updates the setmaxregister NVVM Op to use the intrinsics instead of inline-ptx. * The interface remains same (as expected). * Tests are added to verify the lowered intrinsics in Target/LLVMIR/nvvmir.mlir. Signed-off-by: Durgadoss R <[email protected]>
1 parent e203968 commit 6a075a9

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -463,17 +463,17 @@ def SetMaxRegisterAction : I32EnumAttr<"SetMaxRegisterAction", "NVVM set max reg
463463
}
464464
def SetMaxRegisterActionAttr : EnumAttr<NVVM_Dialect, SetMaxRegisterAction, "action">;
465465

466-
def NVVM_SetMaxRegisterOp : NVVM_PTXBuilder_Op<"setmaxregister"> {
466+
def NVVM_SetMaxRegisterOp : NVVM_Op<"setmaxregister"> {
467467
let arguments = (ins I32Attr:$regCount, SetMaxRegisterActionAttr:$action);
468468
let assemblyFormat = "$action $regCount attr-dict";
469-
let extraClassDefinition = [{
470-
std::string $cppClass::getPtx() {
471-
if(getAction() == NVVM::SetMaxRegisterAction::increase)
472-
return std::string("setmaxnreg.inc.sync.aligned.u32 %0;");
473-
return std::string("setmaxnreg.dec.sync.aligned.u32 %0;");
474-
}
475-
}];
476469
let hasVerifier = 1;
470+
string llvmBuilder = [{
471+
auto intId = (op.getAction() == NVVM::SetMaxRegisterAction::increase) ?
472+
llvm::Intrinsic::nvvm_setmaxnreg_inc_sync_aligned_u32 :
473+
llvm::Intrinsic::nvvm_setmaxnreg_dec_sync_aligned_u32;
474+
475+
createIntrinsicCall(builder, intId, builder.getInt32($regCount));
476+
}];
477477
}
478478

479479
def NVVM_FenceMbarrierInitOp : NVVM_PTXBuilder_Op<"fence.mbarrier.init"> {

mlir/test/Conversion/NVVMToLLVM/nvvm-to-llvm.mlir

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,10 @@ llvm.func @init_mbarrier_arrive_expect_tx(%desc : !llvm.ptr, %pred : i1) {
628628
// -----
629629

630630
func.func @set_max_register() {
631-
//CHECK: llvm.inline_asm has_side_effects asm_dialect = att "setmaxnreg.inc.sync.aligned.u32 $0;", "n"
631+
// CHECK: nvvm.setmaxregister increase 232
632632
nvvm.setmaxregister increase 232
633-
//CHECK: llvm.inline_asm has_side_effects asm_dialect = att "setmaxnreg.dec.sync.aligned.u32 $0;", "n"
633+
634+
// CHECK: nvvm.setmaxregister decrease 40
634635
nvvm.setmaxregister decrease 40
635636
func.return
636637
}

mlir/test/Target/LLVMIR/nvvmir.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,15 @@ llvm.func @cp_async_mbarrier_arrive(%bar_shared: !llvm.ptr<3>, %bar_gen: !llvm.p
369369
llvm.return
370370
}
371371

372+
// CHECK-LABEL: @llvm_nvvm_setmaxregister
373+
llvm.func @llvm_nvvm_setmaxregister() {
374+
// CHECK-LLVM: call void @llvm.nvvm.setmaxnreg.inc.sync.aligned.u32(i32 256)
375+
nvvm.setmaxregister increase 256
376+
// CHECK-LLVM: call void @llvm.nvvm.setmaxnreg.dec.sync.aligned.u32(i32 24)
377+
nvvm.setmaxregister decrease 24
378+
llvm.return
379+
}
380+
372381
// CHECK-LABEL: @ld_matrix
373382
llvm.func @ld_matrix(%arg0: !llvm.ptr<3>) {
374383
// CHECK: call i32 @llvm.nvvm.ldmatrix.sync.aligned.m8n8.x1.b16.p3(ptr addrspace(3) %{{.*}})

0 commit comments

Comments
 (0)