Environment. Driver 615.78.08, CUDA 13.0, RTX 5080 Laptop (sm_120), Linux x86_64, g++ 16, nvcc 13; host code built with -fsanitize=thread (GCC’s libtsan).
Minimal reproducer (22 lines, nothing shared between the threads):
include <cuda_runtime.h>
include
include
struct Args { float* x; int n; };
global void k(Args a) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < a.n) a.x[i] += 1.f; }
static void worker() {
const int n = 1 << 14; float* d = nullptr; cudaMalloc(&d, n * sizeof(float));
Args a; a.x = d; a.n = n;
for (int it = 0; it < 50; ++it) { k<<<(n + 255) / 256, 256>>>(a); cudaStreamSynchronize(0); }
cudaFree(d);
}
int main() { cudaFree(0); std::thread a(worker), b(worker); a.join(); b.join(); std::printf(“ok\n”); return 0; }
nvcc -std=c++17 -O1 -g -arch=native --default-stream per-thread -Xcompiler “-fsanitize=thread -fPIE” -c repro.cu -o r.o
g++ -fsanitize=thread -pie r.o -o repro -L$CUDA/lib64 -lcudart -lpthread -Wl,-rpath,$CUDA/lib64
TSAN_OPTIONS=halt_on_error=0 ./repro
Observed. One ThreadSanitizer report per run (3 of 3), one per distinct kernel. Both accesses are 8-byte writes by memcpy called from inside libcuda.so.1 (+0x2df964 in 615.78.08) into a 32764-byte heap block the driver itself allocates at the first launch; each writer holds a per-thread mutex the driver creates at the thread’s first CUDA call (+0x1343acd) and the read side of an rwlock created at cudart init (+0x2a758a). No user frame, lock or memory is involved:
WARNING: ThreadSanitizer: data race
Write of size 8 at 0x72b000438000 by thread T5 (mutexes: read M0, write M1):
#0 memcpy (libtsan.so.2)
#1 (libcuda.so.1+0x2df964)
#2 __wrapper__device_stub_k … (the kernel’s launch stub)
Previous write of size 8 at 0x72b000438000 by thread T4 (mutexes: read M0, write M2):
#0 memcpy (libtsan.so.2)
#1 (libcuda.so.1+0x2df964)
Location is heap block of size 32764 at 0x72b000438000 allocated by thread T4:
#1 (libcuda.so.1+0x137ee72)
Mutex M0 created at: pthread_rwlock_init ← libcuda.so.1+0x2a758a ← libcudart.so.13+0x95a58
Mutex M1/M2 created at: pthread_mutex_init ← libcuda.so.1+0x1343acd (in each worker thread)
What changes it. Built without --default-stream per-thread: no report. Kernel arguments as separate scalars (k(float* x, int n)) instead of one struct: no report. CUDA_MODULE_LOADING=EAGER: unchanged. The suppression called_from_lib:libcuda.so.1: no report (what we use). The same shape in a real application (a multi-session inference engine whose kernels all take a struct by value) draws the identical report, offset for offset, with no wrong result ever observed.
Question. Is the 8-byte write at a thread’s first launch of a function ordered by something ThreadSanitizer cannot see (an atomic or a futex inside the driver), that is a known false positive, or is it an unsynchronized write in the driver’s per-function table? If the former, is there a recommended suppression or a documented statement we can cite?