[libc] Fix the `send_n` and `recv_n` utilities under divergent lanes
authorJoseph Huber <jhuber6@vols.utk.edu>
Fri, 19 May 2023 19:58:32 +0000 (14:58 -0500)
committerJoseph Huber <jhuber6@vols.utk.edu>
Tue, 23 May 2023 15:59:47 +0000 (10:59 -0500)
commit29d3da3b86cc4e8d5025602e0d7a290609f44f45
tree7d85adc1253316b8822eba02715531169faace80
parent75eb3bd1a43db7d72be0a12edce4b1f6a2bb1fa7
[libc] Fix the `send_n` and `recv_n` utilities under divergent lanes

We provide the `send_n` and `recv_n` utilities as a generic way to
stream data between both sides of the process. This was previously
tested and performed as expected when using a string of constant size.
However, when the size was allowed to diverge between the threads in the
warp or wavefront this could deadlock. This did not occur on NVPTX
because of the use of the explicit warp sync. However, on AMD one of the
work items in the wavefront could continue executing and hit the next
`recv` call before the other threads, then we would deadlock as we
violated the RPC invariants.

This patch replaces the for loop with a thread ballot. This will cause
every thread in the warp or wavefront to continue executing the loop
until all of them can exit. This acts as a more explicit wavefront sync.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D150992
libc/src/__support/GPU/amdgpu/utils.h
libc/src/__support/GPU/nvptx/utils.h
libc/src/__support/RPC/rpc.h
libc/test/integration/startup/gpu/CMakeLists.txt
libc/test/integration/startup/gpu/rpc_stream_test.cpp