Uninitialized global memory read with vector types

I’m observing uninitialized global reads in a kernel that does a simple summation of all of its input elements while also using vector data types to load data from device memory to local memory. I tried getting to the bottom of this using Compute Sanitizer, but so far I was not able to understand what’s causing the uninitialized read.

This is my setup:

  • NVIDIA GeForce GTX 1080 Ti
  • Driver Version: 580.82.07
  • CUDA Version: 13.0
  • NVCC Build: cuda_12.9.r12.9/compiler.36037853_0
  • Compilation command: nvcc host.cpp -o host -lcuda -lnvrtc
  • Execution command: compute-sanitizer --tool initcheck ./host

I have attached the host and kernel code I am using. The kernel might look a bit unintuitive, because it’s automatically generated code. I am aware that it is not properly optimized. Also, I have reduced the thread configuration to a single thread and block to simplify debugging.

What I have found so far:

  • The kernel produces correct results.
  • Some line of the kernel produces instructions that try to read from x_device at index 68, although that index is never written.
  • None of the lines in kernel.cu directly calculate index 68, so it seems to me that something goes wrong during compilation to PTX or onwards.
    • I tried checking this with printfs, interestingly adding certain prints make the uninitialized reads go away.
  • I tried checking the PTX. I am not much familiar with PTX, but as far as I understand, none of the loads from x_device in the PTX code access index 68 either.

Any help to further debug this would be greatly appreciated, many thanks in advance!

kernel.txt (1.5 KB)

host.txt (5.1 KB)

Hi, @r.schulze

We tried to modify your host.txt, and after modification, no sanitizer error reported now. Please have a check.
host.txt (5.4 KB)

Hi @veraj ,

many thanks for your reply! I checked with your host code and the warnings do indeed go away. In fact, it is sufficient to simply initialize and transfer the x_device buffer in the host code. However, as I understand, it should not be necessary (and is therefor inefficient) to initialize x_device, because it is first written and then read in the kernel, no? If it is necessary, could you elaborate why?