Skip to content

Commit

Permalink
Automerge: [LLVM][NVPTX] Add support for griddepcontrol instruction (…
Browse files Browse the repository at this point in the history
…#123511)

This commit adds support for griddepcontrol PTX instruction with tests
under griddepcontrol.ll
  • Loading branch information
schwarzschild-radius authored and github-actions[bot] committed Jan 24, 2025
2 parents 4ba29f7 + 435609b commit 34f75c6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
23 changes: 23 additions & 0 deletions llvm/docs/NVPTXUsage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,29 @@ including that ``wgmma.mma_async`` instruction is undefined behavior.
For more information, refer PTX ISA
`<https://docs.nvidia.com/cuda/parallel-thread-execution/#asynchronous-warpgroup-level-matrix-instructions-wgmma-wait-group>`_.

'``llvm.nvvm.griddepcontrol.*``'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Syntax:
"""""""

.. code-block:: llvm
declare void @llvm.nvvm.griddepcontrol.launch_dependents()
declare void @llvm.nvvm.griddepcontrol.wait()
Overview:
"""""""""

The ``griddepcontrol`` intrinsics allows the dependent grids and prerequisite grids as defined by the runtime, to control execution in the following way:

``griddepcontrol.launch_dependents`` intrinsic signals that the dependents can be scheduled, before the current grid completes. The intrinsic can be invoked by multiple threads in the current CTA and repeated invocations of the intrinsic will have no additional side effects past that of the first invocation.

``griddepcontrol.wait`` intrinsic causes the executing thread to wait until all prerequisite grids in flight have completed and all the memory operations from the prerequisite grids are performed and made visible to the current grid.

For more information, refer
`PTX ISA <https://docs.nvidia.com/cuda/parallel-thread-execution/#parallel-synchronization-and-communication-instructions-griddepcontrol>`__.

Other Intrinsics
----------------

Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm/IR/IntrinsicsNVVM.td
Original file line number Diff line number Diff line change
Expand Up @@ -5044,4 +5044,7 @@ def int_nvvm_cp_async_bulk_prefetch_L2
NoCapture<ArgIndex<0>>, ReadOnly<ArgIndex<0>>,
ImmArg<ArgIndex<3>>]>;

def int_nvvm_griddepcontrol_launch_dependents: Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects]>;
def int_nvvm_griddepcontrol_wait: Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects]>;

} // let TargetPrefix = "nvvm"
12 changes: 12 additions & 0 deletions llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
Original file line number Diff line number Diff line change
Expand Up @@ -7569,4 +7569,16 @@ def INT_NVVM_WGMMA_WAIT_GROUP_SYNC_ALIGNED : NVPTXInst<(outs), (ins i64imm:$n),
[(int_nvvm_wgmma_wait_group_sync_aligned timm:$n)]>, Requires<[hasSM90a, hasPTX<80>]>;
} // isConvergent = true

def GRIDDEPCONTROL_LAUNCH_DEPENDENTS :
NVPTXInst<(outs), (ins),
"griddepcontrol.launch_dependents;",
[(int_nvvm_griddepcontrol_launch_dependents)]>,
Requires<[hasSM<90>, hasPTX<78>]>;

def GRIDDEPCONTROL_WAIT :
NVPTXInst<(outs), (ins),
"griddepcontrol.wait;",
[(int_nvvm_griddepcontrol_wait)]>,
Requires<[hasSM<90>, hasPTX<78>]>;

def INT_EXIT : NVPTXInst<(outs), (ins), "exit;", [(int_nvvm_exit)]>;
17 changes: 17 additions & 0 deletions llvm/test/CodeGen/NVPTX/griddepcontrol.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc < %s -mcpu=sm_90 -march=nvptx64 | FileCheck %s
; RUN: %if ptxas-11.8 %{ llc < %s -mcpu=sm_90 -march=nvptx64 | %ptxas-verify %}

define void @griddepcontrol() {
; CHECK-LABEL: griddepcontrol(
; CHECK: {
; CHECK-EMPTY:
; CHECK-EMPTY:
; CHECK-NEXT: // %bb.0:
; CHECK-NEXT: griddepcontrol.launch_dependents;
; CHECK-NEXT: griddepcontrol.wait;
; CHECK-NEXT: ret;
call void @llvm.nvvm.griddepcontrol.launch.dependents()
call void @llvm.nvvm.griddepcontrol.wait()
ret void
}

0 comments on commit 34f75c6

Please sign in to comment.