Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,36 @@ def NVVM_ReduxOp :
}];
}

//===----------------------------------------------------------------------===//
// NVVM nanosleep
//===----------------------------------------------------------------------===//

def NVVM_NanosleepOp : NVVM_Op<"nanosleep">,
Arguments<(ins
ConfinedAttr<I32Attr, [IntMinValue<1>, IntMaxValue<1000000>]>:$duration)>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grypp Should this be an SSA value instead of an attribute? PTX spec says "t may be a register or an immediate value."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I added this op just by looking at PTX instruction. My bad. Let me change this SSA value.

{
let summary = "Suspends the thread for a specified duration.";

let description = [{
The op suspends the thread for a sleep duration approximately close to the
delay `$duration`, specified in nanoseconds.

The sleep duration is approximated, but guaranteed to be in the
interval [0, 2*t]. The maximum sleep duration is 1 millisecond.
The implementation may reduce the sleep duration for individual threads
within a warp such that all sleeping threads in the warp wake up together.

[For more information, see PTX ISA](https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#miscellaneous-instructions-nanosleep)
}];

string llvmBuilder = [{
createIntrinsicCall(builder,
llvm::Intrinsic::nvvm_nanosleep,
{builder.getInt32($duration)});
}];
let assemblyFormat = "attr-dict $duration";
}

//===----------------------------------------------------------------------===//
// NVVM Performance Monitor events
//===----------------------------------------------------------------------===//
Expand Down
8 changes: 8 additions & 0 deletions mlir/test/Target/LLVMIR/nvvmir-invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,11 @@ llvm.func @ld_matrix(%arg0: !llvm.ptr<3>) {
%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
llvm.return
}

// -----

llvm.func @nanosleep() {
// expected-error@+1 {{integer constant out of range for attribute}}
nvvm.nanosleep 100000000000000
llvm.return
}
9 changes: 9 additions & 0 deletions mlir/test/Target/LLVMIR/nvvmir.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -959,3 +959,12 @@ llvm.func @nvvm_pmevent() {
nvvm.pmevent mask = 4
llvm.return
}

// -----

// CHECK-LABEL: @nanosleep
llvm.func @nanosleep() {
// CHECK: call void @llvm.nvvm.nanosleep(i32 4000)
nvvm.nanosleep 4000
llvm.return
}