Skip to content

CUDA-MEMCHECK reports Uninitialized access #725

Closed as not planned
Closed as not planned

Description

@liruipeng

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

  1. hwinkler commented on Jun 9, 2020

    @hwinkler

    I confirm this behavior on cuda 10.2.

  2. cjnolet commented on Jan 29, 2021

    @cjnolet

    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:

      thrust::device_ptr<value_idx> d_ptr_indptr =
        thrust::device_pointer_cast(indptr);
    
      thrust::device_ptr<value_idx> d_ptr_diff =
        thrust::device_pointer_cast(diff.data());
      ML::thrustAllocatorAdapter alloc(allocator, stream);
      thrust::adjacent_difference(thrust::cuda::par(alloc).on(stream),
                                  d_ptr_indptr, d_ptr_indptr + n_rows, d_ptr_diff);
    
      return *(thrust::max_element(thrust::cuda::par(alloc).on(stream), d_ptr_diff,
                                   d_ptr_diff + n_rows));
  3. divyegala commented on Jan 29, 2021

    @divyegala

    Just confirmed this behavior on CUDA 10.2 for thrust::min_max

  4. alliepiper commented on Jan 29, 2021

    @alliepiper
    Contributor

    Looks like this fell through the cracks. I'll try to look at this soon.

  5. alliepiper commented on Jan 29, 2021

    @alliepiper
    Contributor

    Likely related to #860.

  6. added
    thrust
    on Feb 22, 2023
  7. transferred this issue fromNVIDIA/thruston Nov 8, 2023
  8. viclafargue commented on Apr 25, 2025

    @viclafargue
    Contributor

    Any updates on this? Still seeing the same error with cuda-memcheck. Not critical, but would be good to resolve.

  9. alliepiper commented on Apr 25, 2025

    @alliepiper
    Contributor

    I'm slowly working my way through the compute sanitizer checks in #1879.

    From a quick review of the issue reported here:

    Host API memory access error at host access to 0x100030e00600 of size 16 bytes
        Uninitialized access at 0x100030e00600 on access by cudaMemcopy source.
    

    Every single warning I've seen (and I've seen a lot of them!) about an uninitialized access of 16 bytes in cudaMemcpy / cudaMemcpyAsync has been an unavoidable (and harmless) copying of padding bits in something like a pair<bool, int64_t>, usually inside thrust::find_if which 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.

  10. alliepiper commented on Apr 25, 2025

    @alliepiper
    Contributor

    Here's an updated and more detailed compute-sanitizer --tool initcheck trace of the reproducer in the issue description:

    ========= COMPUTE-SANITIZER
    ========= Host API memory access error at host access to 0x131b000400 of size 16 bytes
    =========     Uninitialized access at 0x131b000400 on access by cudaMemcpy source
    =========     Saved host backtrace up to driver entry point at error
    =========         Host Frame: cudaMemcpyAsync [0x82120] in a.out
    =========         Host Frame: void thrust::THRUST_300100_SM_520_NS::cuda_cub::detail::cross_system_assign_host_path::operator()<thrust::THRUST_300100_SM_520_NS::system::cpp::detail::tag, thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t, cuda::std::__4::tuple<int, long>*, cuda::std::__4::tuple<int, long>*>(thrust::THRUST_300100_SM_520_NS::system::cpp::detail::tag&, thrust::THRUST_300100_SM_520_NS::cuda_cub::execution_policy<thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t>&, cuda::std::__4::tuple<int, long>*, cuda::std::__4::tuple<int, long>*) [0x16625] in a.out
    =========         Host Frame: void thrust::THRUST_300100_SM_520_NS::cuda_cub::assign_value<thrust::THRUST_300100_SM_520_NS::system::cpp::detail::tag, thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t, cuda::std::__4::tuple<int, long>*, cuda::std::__4::tuple<int, long>*>(thrust::THRUST_300100_SM_520_NS::cuda_cub::cross_system<thrust::THRUST_300100_SM_520_NS::system::cpp::detail::tag, thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t>&, cuda::std::__4::tuple<int, long>*, cuda::std::__4::tuple<int, long>*) [0x15285] in a.out
    =========         Host Frame: thrust::THRUST_300100_SM_520_NS::cuda_cub::get_value<thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t, cuda::std::__4::tuple<int, long>*>(thrust::THRUST_300100_SM_520_NS::cuda_cub::execution_policy<thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t>&, cuda::std::__4::tuple<int, long>*)::HostPath::operator()(thrust::THRUST_300100_SM_520_NS::cuda_cub::execution_policy<thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t>&, cuda::std::__4::tuple<int, long>*) [0x140dd] in a.out
    =========         Host Frame: cuda::std::__4::iterator_traits<cuda::std::__4::tuple<int, long>*, void>::value_type thrust::THRUST_300100_SM_520_NS::cuda_cub::get_value<thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t, cuda::std::__4::tuple<int, long>*>(thrust::THRUST_300100_SM_520_NS::cuda_cub::execution_policy<thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t>&, cuda::std::__4::tuple<int, long>*) [0x1414b] in a.out
    =========         Host Frame: cuda::std::__4::tuple<int, long> thrust::THRUST_300100_SM_520_NS::cuda_cub::__extrema::extrema<thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t, thrust::THRUST_300100_SM_520_NS::zip_iterator<cuda::std::__4::tuple<int*, thrust::THRUST_300100_SM_520_NS::counting_iterator<long, thrust::THRUST_300100_SM_520_NS::use_default, thrust::THRUST_300100_SM_520_NS::use_default, thrust::THRUST_300100_SM_520_NS::use_default> > >, long, thrust::THRUST_300100_SM_520_NS::cuda_cub::__extrema::arg_max_f<int, long, cuda::std::__4::less<int> >, cuda::std::__4::tuple<int, long> >(thrust::THRUST_300100_SM_520_NS::cuda_cub::execution_policy<thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t>&, thrust::THRUST_300100_SM_520_NS::zip_iterator<cuda::std::__4::tuple<int*, thrust::THRUST_300100_SM_520_NS::counting_iterator<long, thrust::THRUST_300100_SM_520_NS::use_default, thrust::THRUST_300100_SM_520_NS::use_default, thrust::THRUST_300100_SM_520_NS::use_default> > >, long, thrust::THRUST_300100_SM_520_NS::cuda_cub::__extrema::arg_max_f<int, long, cuda::std::__4::less<int> >, cuda::std::__4::tuple<int, long>*) [0x1228c] in a.out
    =========         Host Frame: int* thrust::THRUST_300100_SM_520_NS::cuda_cub::__extrema::element<thrust::THRUST_300100_SM_520_NS::cuda_cub::__extrema::arg_max_f, thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t, int*, cuda::std::__4::less<int> >(thrust::THRUST_300100_SM_520_NS::cuda_cub::execution_policy<thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t>&, int*, int*, cuda::std::__4::less<int>) [0x11d20] in a.out
    =========         Host Frame: int* thrust::THRUST_300100_SM_520_NS::cuda_cub::max_element<thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t, int*, cuda::std::__4::less<int> >(thrust::THRUST_300100_SM_520_NS::cuda_cub::execution_policy<thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t>&, int*, int*, cuda::std::__4::less<int>) [0x11c53] in a.out
    =========         Host Frame: int* thrust::THRUST_300100_SM_520_NS::cuda_cub::max_element<thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t, int*>(thrust::THRUST_300100_SM_520_NS::cuda_cub::execution_policy<thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t>&, int*, int*) [0x11bfe] in a.out
    =========         Host Frame: int* thrust::THRUST_300100_SM_520_NS::max_element<thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t, int*>(thrust::THRUST_300100_SM_520_NS::detail::execution_policy_base<thrust::THRUST_300100_SM_520_NS::cuda_cub::par_t> const&, int*, int*) [0x11672] in a.out
    =========         Host Frame: main [0xae80] in a.out
    

    The top few frames are Thrust machinery copying a cuda::std::__4::tuple<int, long> from device -> host as part of the thrust::max_element implementation. That tuple is effectively laid out in memory as a struct { 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.

  11. moved this from Todo to Done in CCCLon Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    thrust

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions