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
EfficientNMS plugin: shared blockState is rewritten by the next iteration's lead thread before all threads read it (missing __syncthreads) #4959
We found this with Volta, a verifier we develop for PTX kernels: it symbolically executes a kernel's compiled PTX for a concrete launch and checks the recorded execution for data races, out-of-bounds accesses and synchronization errors. This report comes from that analysis of the sm_100a PTX of TensorRT OSS main at 7fe18f0, not from a GPU run.
Description
In the EfficientNMS kernel, each NMS iteration i is coordinated through the shared variable blockState (efficientNMSInference.cu:199):
Iteration i's lead thread (boxIdx[tile] == i) writes blockState: -1 to skip, -2 to exit, 1 to suppress (:237, :245, :253).
Every thread then reads blockState: the exit and skip tests (:293, :299) and the blockState == 1 test inside the IoU loop (:326).
Nothing orders those reads before iteration i + 1's lead writes blockState again, which it does before the next barrier. A thread that is still in iteration i and reads the new value can:
see -1 and skip suppressing against box i, so an overlapping box is kept;
see -2 and return early;
see 1 and suppress against a box that was dropped.
So the detections can depend on thread scheduling. This happens whenever more than one thread is active, which is the default: the block is numSelectedBoxes / NMS_TILES threads, 819 for the default 4096 (:345).
What Volta reports, for EfficientNMS<float, BoxCorner<float>>, one image, 40 sorted candidates where boxes 2k and 2k + 1 coincide, default parameters otherwise:
a read-write conflict on blockState between thread 0's read in iteration 0's IoU loop and thread 1's blockState = -1 as iteration 1's lead;
write-read conflicts between that write and threads 2 and 3's reads of iteration 0's value.
It also reports the conflict with 24 candidates, all in one warp: since Volta (sm_70), the threads of a warp are not implicitly synchronized either.
Suggested fix
Add a barrier at the start of each iteration, so the lead writes blockState only after every thread has read the previous iteration's value:
for (int i = 0; i < numSelectedBoxes; i++)
{
__syncthreads();
int tile = i / tileSize;
...
With that change, Volta finds the kernel race free at 40 and 24 candidates, and it keeps the 20 expected boxes with their scores.
Environment
TensorRT Version: OSS main at 7fe18f0 (TensorRT 11.5 OSS release)
NVIDIA GPU: none (static analysis of the sm_100a PTX)
CUDA Version: nvcc 13.2, -arch=sm_100a -O3 -std=c++20
Steps To Reproduce
compute-sanitizer --tool racecheck on the EfficientNMS_TRT plugin with more than one candidate box above the score threshold should report the shared-memory hazard on blockState.
We are investigating further and will update this issue.
Activity
Record the TensorRT issues filed for TRT-3 (NVIDIA/TensorRT#4959) and…