CUB CachingDeviceAllocator::DeviceAllocate calls cudaMalloc internally on cache miss. Without a guard, our intercepted cudaMalloc recurses into DeviceAllocate → cudaMalloc → DeviceAllocate → segfault. thread_local g_in_allocator flag detects reentrant calls and forwards them directly to the real cudaMalloc/cudaFree via dlsym(RTLD_NEXT).