Skip to content

Commit 7439d22

Browse files
authored
[MLIR][NVVM] Add nanosleep (#154697)
1 parent 4da6972 commit 7439d22

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,36 @@ def NVVM_ReduxOp :
401401
}];
402402
}
403403

404+
//===----------------------------------------------------------------------===//
405+
// NVVM nanosleep
406+
//===----------------------------------------------------------------------===//
407+
408+
def NVVM_NanosleepOp : NVVM_Op<"nanosleep">,
409+
Arguments<(ins
410+
ConfinedAttr<I32Attr, [IntMinValue<1>, IntMaxValue<1000000>]>:$duration)>
411+
{
412+
let summary = "Suspends the thread for a specified duration.";
413+
414+
let description = [{
415+
The op suspends the thread for a sleep duration approximately close to the
416+
delay `$duration`, specified in nanoseconds.
417+
418+
The sleep duration is approximated, but guaranteed to be in the
419+
interval [0, 2*t]. The maximum sleep duration is 1 millisecond.
420+
The implementation may reduce the sleep duration for individual threads
421+
within a warp such that all sleeping threads in the warp wake up together.
422+
423+
[For more information, see PTX ISA](https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#miscellaneous-instructions-nanosleep)
424+
}];
425+
426+
string llvmBuilder = [{
427+
createIntrinsicCall(builder,
428+
llvm::Intrinsic::nvvm_nanosleep,
429+
{builder.getInt32($duration)});
430+
}];
431+
let assemblyFormat = "attr-dict $duration";
432+
}
433+
404434
//===----------------------------------------------------------------------===//
405435
// NVVM Performance Monitor events
406436
//===----------------------------------------------------------------------===//

mlir/test/Target/LLVMIR/nvvmir-invalid.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,11 @@ llvm.func @ld_matrix(%arg0: !llvm.ptr<3>) {
495495
%l = nvvm.ldmatrix %arg0 {num = 1 : i32, layout = #nvvm.mma_layout<col>, shape = #nvvm.ld_st_matrix_shape<m = 16, n = 16>, eltType = #nvvm.ld_st_matrix_elt_type<b8>} : (!llvm.ptr<3>) -> i32
496496
llvm.return
497497
}
498+
499+
// -----
500+
501+
llvm.func @nanosleep() {
502+
// expected-error@+1 {{integer constant out of range for attribute}}
503+
nvvm.nanosleep 100000000000000
504+
llvm.return
505+
}

mlir/test/Target/LLVMIR/nvvmir.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,3 +959,12 @@ llvm.func @nvvm_pmevent() {
959959
nvvm.pmevent mask = 4
960960
llvm.return
961961
}
962+
963+
// -----
964+
965+
// CHECK-LABEL: @nanosleep
966+
llvm.func @nanosleep() {
967+
// CHECK: call void @llvm.nvvm.nanosleep(i32 4000)
968+
nvvm.nanosleep 4000
969+
llvm.return
970+
}

0 commit comments

Comments
 (0)