You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG]: Potential race in merge sort due to PDL #3131
So we can overlap BlockSort with a previous kernel (outside CUB). However, I just saw that I missed launching the kernel with the PDL flag.
Partition (secondary for block sort / primary for merge):
4. No explicit triggering of the next launch, so happens implicitly on last block exit
I tried adding one, but I always ended up crashing. Under compute-sanitizer, the bug disappeared. I discussed with @ahendriksen and it seems the workaround was to __syncthreads() before triggering the next launch.
I documented this here:
// TODO(bgruber): if we put a call to cudaTriggerProgrammaticLaunchCompletion inside this kernel, the tests fail with
However, the entire kernel is divergent until it exits (because it branches based on whether the thread id is smaller then the problem size), so we could only trigger the next launch at the end of the kernel, which is also done implicitly. Therefore, such a call is missing.
Since each pair of primary / secondary kernels is concurrent, we should have a data race between:
2.ii and 1.v
4.ii and 3.v
...
We likely want to trigger dependent launch after we write the data, not before.
I think you may have fallen for the same misconception as I did, but @ahendriksen could help me out here:
At the end of a kernel, there is something called a "grid-ending membar". cudaGridDependencySynchronize waits for that membar to finish.
cudaGridDependencySynchronize does not wait for cudaTriggerProgrammaticLaunchCompletion, but for the end of the previous kernel. cudaTriggerProgrammaticLaunchCompletion allows the next kernel to ramp-up, but then wait for the previous kernel to complete.
The only data race I could introduce is if I would put the cudaGridDependencySynchronizeafter reading the first data and enabling PDL for that kernel. Then the kernel could start reading while a previous kernel is still writing.
Activity
bernhardmgruber commentedon Dec 12, 2024
So we can overlap BlockSort with a previous kernel (outside CUB). However, I just saw that I missed launching the kernel with the PDL flag.
I tried adding one, but I always ended up crashing. Under compute-sanitizer, the bug disappeared. I discussed with @ahendriksen and it seems the workaround was to
__syncthreads()before triggering the next launch.I documented this here:
cccl/cub/cub/device/dispatch/dispatch_merge_sort.cuh
Line 215 in 53f69a4
However, the entire kernel is divergent until it exits (because it branches based on whether the thread id is smaller then the problem size), so we could only trigger the next launch at the end of the kernel, which is also done implicitly. Therefore, such a call is missing.
I think you may have fallen for the same misconception as I did, but @ahendriksen could help me out here:
cudaGridDependencySynchronizedoes not wait forcudaTriggerProgrammaticLaunchCompletion, but for the end of the previous kernel.cudaTriggerProgrammaticLaunchCompletionallows the next kernel to ramp-up, but then wait for the previous kernel to complete.bernhardmgruber commentedon Dec 12, 2024
The only data race I could introduce is if I would put the
cudaGridDependencySynchronizeafter reading the first data and enabling PDL for that kernel. Then the kernel could start reading while a previous kernel is still writing.gevtushenko commentedon Dec 12, 2024
My bad, I completely missed that. Thank you for elaborating!