Repository navigation
Closed as not planned
Labels
thrustFor all items related to Thrust.
Description
Hello, thrust team,
I found CUDA-MEMCHECK reported uninitialized access of thrust calls. I made a simple reproducer attached below. Please take a look. This is with cuda 10.1 on P100.
Thanks
-Ruipeng
#include <thrust/extrema.h>
#define N 64
int main()
{
int *h_x, *d_x, i, k;
h_x = (int *) malloc(N*sizeof(int));
for (i = 0; i < N; i++)
{
h_x[i] = i;
}
cudaMalloc(&d_x, N*sizeof(int));
cudaMemcpy(d_x, h_x, N*sizeof(int), cudaMemcpyHostToDevice);
int *ptr = thrust::max_element( thrust::device, d_x, d_x + N);
cudaMemcpy(&k, ptr, sizeof(int), cudaMemcpyDeviceToHost);
printf("max = %d\n", k);
cudaFree(d_x);
free(h_x);
return 0;
}
Output
li50@ray15:~/workspace/tmp/GPU/thrust$ cuda-memcheck --tool initcheck ./a.out
========= CUDA-MEMCHECK
========= Host API memory access error at host access to 0x100030e00600 of size 16 bytes
========= Uninitialized access at 0x100030e00600 on access by cudaMemcopy source.
========= Saved host backtrace up to driver entry point at error
========= Host Frame:/lib64/libcuda.so.1 (cuMemcpyDtoHAsync_v2 + 0x1e4) [0x2ec984]
========= Host Frame:./a.out [0x5357c]
========= Host Frame:./a.out [0x208cc]
========= Host Frame:./a.out [0x787a8]
========= Host Frame:./a.out [0x117f8]
========= Host Frame:./a.out [0x112dc]
========= Host Frame:./a.out [0x10f00]
========= Host Frame:./a.out [0x10608]
========= Host Frame:./a.out [0x10084]
========= Host Frame:./a.out [0x100e0]
========= Host Frame:./a.out [0xe328]
========= Host Frame:./a.out [0xe38c]
========= Host Frame:./a.out [0xcdb0]
========= Host Frame:./a.out [0xc524]
========= Host Frame:./a.out [0xa388]
========= Host Frame:./a.out [0xa314]
========= Host Frame:./a.out [0x9db8]
========= Host Frame:./a.out [0x4e0c]
========= Host Frame:/lib64/libc.so.6 [0x25100]
========= Host Frame:/lib64/libc.so.6 (__libc_start_main + 0xc4) [0x252f4]
=========
max = 63
========= ERROR SUMMARY: 1 error
Activity
hwinkler commentedon Jun 9, 2020
I confirm this behavior on cuda 10.2.
cjnolet commentedon Jan 29, 2021
I can confirm this behavior in CUDA 11 w/ a V100. I notice this issue was opened exactly 1 year ago. Has anyone found a fix for this yet? I've tried explicitly syncing the stream I'm using in the policy but I still get the error.
I'm experiencing this w/ the following code:
divyegala commentedon Jan 29, 2021
Just confirmed this behavior on CUDA 10.2 for
thrust::min_maxalliepiper commentedon Jan 29, 2021
Looks like this fell through the cracks. I'll try to look at this soon.
alliepiper commentedon Jan 29, 2021
Likely related to #860.
viclafargue commentedon Apr 25, 2025
Any updates on this? Still seeing the same error with
cuda-memcheck. Not critical, but would be good to resolve.alliepiper commentedon Apr 25, 2025
I'm slowly working my way through the compute sanitizer checks in #1879.
From a quick review of the issue reported here:
Every single warning I've seen (and I've seen a lot of them!) about an uninitialized access of 16 bytes in
cudaMemcpy/cudaMemcpyAsynchas been an unavoidable (and harmless) copying of padding bits in something like apair<bool, int64_t>, usually insidethrust::find_ifwhich is used internally by a lot of thrust algorithms. I wouldn't worry too much about these -- we won't be able to do anything about them since there's no way to initialize padding bits, all that can be done is to suppress them.alliepiper commentedon Apr 25, 2025
Here's an updated and more detailed
compute-sanitizer --tool initchecktrace of the reproducer in the issue description:The top few frames are Thrust machinery copying a
cuda::std::__4::tuple<int, long>from device -> host as part of thethrust::max_elementimplementation. That tuple is effectively laid out in memory as astruct { int32_t; int64_t; }, and the four bytes of padding between the two members are uninitialized, triggering the warning for the 16-byte-total memcpy operation.This warning can be safely ignored and suppressed if needed.