Repository navigation
Conversation
|
@llvm/pr-subscribers-backend-amdgpu Author: Jeffrey Byrnes (jrbyrnes) ChangesWe need to resolve hazard between In SIInsertWaitcnts, when simplifying the vm_vsrc, we check to see if an existing s_wait proves that the vm_vsrc is redundant. It does this by comparing the covered events of the existing s_wait with the outstanding events at this position. If the existing s_wait covers all relevant outstanding events, then the wait vm_vsrc is redundant. However, we previously did not include the async_cnt as a relevant event to check. Thus we may have decided our s_wait covers all relevant events, even if there are outstanding global_load_async. For example, in the new test, 2 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
index 7fa33458fa325..8b8e3ddd0978a 100644
--- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
@@ -1314,8 +1314,8 @@ void WaitcntBrackets::simplifyVmVsrc(const AMDGPU::Waitcnt &CheckWait,
// have read its VGPR sources, but only if there are no other outstanding VMEM
// operations that use a different counter (like SAMPLE_CNT).
static constexpr AMDGPU::InstCounterType VmemCounters[] = {
- AMDGPU::LOAD_CNT, AMDGPU::STORE_CNT, AMDGPU::SAMPLE_CNT, AMDGPU::BVH_CNT,
- AMDGPU::DS_CNT};
+ AMDGPU::LOAD_CNT, AMDGPU::STORE_CNT, AMDGPU::SAMPLE_CNT,
+ AMDGPU::BVH_CNT, AMDGPU::DS_CNT, AMDGPU::ASYNC_CNT};
HWEvents VmemEvents = llvm::accumulate(
VmemCounters, HWEvents(), [&](HWEvents Acc, AMDGPU::InstCounterType T) {
return Acc | Context->getWaitEvents(T);
diff --git a/llvm/test/CodeGen/AMDGPU/vsrc-simplify-asynccnt.mir b/llvm/test/CodeGen/AMDGPU/vsrc-simplify-asynccnt.mir
new file mode 100644
index 0000000000000..d73f120611c3f
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/vsrc-simplify-asynccnt.mir
@@ -0,0 +1,31 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1250 --amdgpu-expert-scheduling-mode -run-pass=si-insert-waitcnts -o - %s | FileCheck %s
+
+---
+name: test_vm_vsrc
+machineFunctionInfo:
+ isEntryFunction: true
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: test_vm_vsrc
+ ; CHECK: GLOBAL_WB 0, implicit $exec
+ ; CHECK-NEXT: V_NOP_e32 implicit $exec
+ ; CHECK-NEXT: S_SETREG_IMM32_B32 2, 2074, implicit-def $mode, implicit $mode
+ ; CHECK-NEXT: S_SETREG_IMM32_B32 1, 1601, implicit-def $mode, implicit $mode
+ ; CHECK-NEXT: $vgpr5 = IMPLICIT_DEF
+ ; CHECK-NEXT: $vgpr2_vgpr3 = IMPLICIT_DEF
+ ; CHECK-NEXT: $vgpr4 = IMPLICIT_DEF
+ ; CHECK-NEXT: GLOBAL_LOAD_ASYNC_TO_LDS_B128 killed $vgpr5, $vgpr2_vgpr3, 0, 0, implicit-def dead $asynccnt, implicit $exec, implicit $asynccnt
+ ; CHECK-NEXT: S_WAIT_DSCNT 0
+ ; CHECK-NEXT: S_WAITCNT_DEPCTR .VmVsrc_0
+ ; CHECK-NEXT: renamable $vgpr4_vgpr5_vgpr6_vgpr7 = DS_LOAD_TR16_B128 killed renamable $vgpr4, 0, 0, implicit $exec
+ ; CHECK-NEXT: S_ENDPGM 0
+ S_SETREG_IMM32_B32 1, 1601, implicit-def $mode, implicit $mode
+ $vgpr5 = IMPLICIT_DEF
+ $vgpr2_vgpr3 = IMPLICIT_DEF
+ $vgpr4 = IMPLICIT_DEF
+ GLOBAL_LOAD_ASYNC_TO_LDS_B128 killed $vgpr5, $vgpr2_vgpr3, 0, 0, implicit-def dead $asynccnt, implicit $exec, implicit $asynccnt
+ S_WAIT_DSCNT 0
+ renamable $vgpr4_vgpr5_vgpr6_vgpr7 = DS_LOAD_TR16_B128 killed renamable $vgpr4, 0, 0, implicit $exec
+ S_ENDPGM 0
+...
|
| AMDGPU::LOAD_CNT, AMDGPU::STORE_CNT, AMDGPU::SAMPLE_CNT, AMDGPU::BVH_CNT, | ||
| AMDGPU::DS_CNT}; | ||
| AMDGPU::LOAD_CNT, AMDGPU::STORE_CNT, AMDGPU::SAMPLE_CNT, | ||
| AMDGPU::BVH_CNT, AMDGPU::DS_CNT, AMDGPU::ASYNC_CNT}; |
There was a problem hiding this comment.
Because my memory is having a moment, this runs meaningfully after the asyncmark/asyncwait intrinsics get lowered to real counter usages, yes?
Also, while we're at it, is there a TENSORCNT hazard? That instruction's SGPRs-only, but I thought I might as well ask.
There was a problem hiding this comment.
Because my memory is having a moment, this runs meaningfully after the asyncmark/asyncwait intrinsics get lowered to real counter usages, yes?
No I think not - these are consolidated into ASYNC_CNT when processing WAIT_ASYNCMARK , and recorded as scores when processing the ASYNCMARK. So, it looks possible that we have outstanding ASYNCMARK not encoded into the ASYNC_CNT.
Presumably we would want to treat the outstanding ASYNCMARK as real memory state, and thus this simplification should honor it, right?
Also, while we're at it, is there a TENSORCNT hazard? That instruction's SGPRs-only, but I thought I might as well ask.
VALU can write SGPR via instructions like readlane, which can then be consumed by TDM / other memory instruction. But this would be tracked by va_sdst and not vm_vsrc.
The other concern (aside from VALU) would be LDS, which can't write to SGPR.
There was a problem hiding this comment.
Presumably we would want to treat the outstanding ASYNCMARK as real memory state, and thus this simplification should honor it, right?
The latest just disallows wait based simplifications in the presence of outstanding asyncmarks. The optimization relies on being able to do meaningful comparisons between the wait for the vm_vsrc and the wait for various memory types. Since the outstanding asyncmark are not contained in this structure, we lose the meaningful comparison. This is a conservative approach, and likely can be cleaned up a bit.
Change-Id: Ia835c90c2087d3e7453917a1f62c0d2d7f27d531
Change-Id: Ib8f6c7f73b440b90c80da191ba52980c1f216122
Change-Id: I2d274814df14d5844e05e801facea39d0aa14b4b
Change-Id: Ib55e86ba1c13fc54a64bc8b424dfc50d9c899062
10dc57a to
e92d89a
Compare
|
Superseded by #212481 |
Thanks/sorry -- I had not seen this PR. |
| ; CHECK-NEXT: renamable $vgpr6_vgpr7_vgpr8_vgpr9 = DS_LOAD_TR16_B128 killed renamable $vgpr4, 0, 0, implicit $exec | ||
| ; CHECK-NEXT: ASYNCMARK | ||
| ; CHECK-NEXT: S_WAIT_DSCNT 0 | ||
| ; CHECK-NEXT: S_WAITCNT_DEPCTR .VmVsrc_0 |
There was a problem hiding this comment.
I don't understand why the presence of the ASYNCMARK means we would need to wait on VM_VSRC here?
We need to resolve hazard between
global_load_async <- vgpr <- ldsusing wait vm_vsrc. In cases where we omit this, we are seeing correctness issues.In SIInsertWaitcnts, when simplifying the vm_vsrc, we check to see if an existing s_wait proves that the vm_vsrc is redundant. It does this by comparing the covered events of the existing s_wait with the outstanding events at this position. If the existing s_wait covers all relevant outstanding events, then the wait vm_vsrc is redundant.
However, we previously did not include the async_cnt as a relevant event to check. Thus we may have decided our s_wait covers all relevant events, even if there are outstanding global_load_async.
For example, in the new test,
simplifyVmVsrcthinks there are no outstanding events whatsoever. The presence of the wait dscnt triggers the other part of conditionalUpdateWait.get(AMDGPU::VM_VSRC) >= CheckCountso we simplify the wait vm_vsrc. By also tracking async_cnt, we now have accurate understanding of outstanding events.Partially fixes LCOMPILER-2480