Skip to content

[BUG]: Uninitialized __global__ memory read of size 2 bytes in cub::DeviceReduce #1889

Closed

Description

@alliepiper

Is this a duplicate?

Type of Bug

Silent Failure

Component

CUB

Describe the bug

One instance: https://github.com/NVIDIA/cccl/actions/runs/9606424817/job/26497169798?pr=1879

-- >> Running:
	compute-sanitizer --tool initcheck --check-device-heap yes --leak-check full --padding 512 --track-stream-ordered-races all --check-warpgroup-mma yes --require-cuda-init no --check-exit-code yes --error-exitcode 1 --nvtx true /home/coder/cccl/build/cuda12.4-gcc13/cub-cpp17/bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0
========= COMPUTE-SANITIZER
========= Uninitialized __global__ memory read of size 2 bytes
=========     at std::iterator_traits<T2>::value_type cub::CUB_200500_600_700_800_NS::ThreadLoad<(cub::CUB_200500_600_700_800_NS::CacheLoadModifier)5, const unsigned long long *>(T2)+0x1fd0 in /home/coder/cccl/cub/cub/thread/thread_load.cuh:263
=========     by thread (32,0,0) in block (0,0,0)
=========     Address 0x7fc918d21b00
=========     Device Frame:void cub::CUB_200500_600_700_800_NS::IterateThreadLoad<(int)0, (int)2>::Load<(cub::CUB_200500_600_700_800_NS::CacheLoadModifier)5, unsigned long long>(const T2 *, T2 *)+0x1fd0 in /home/coder/cccl/cub/cub/thread/thread_load.cuh:122
=========     Device Frame:T1 cub::CUB_200500_600_700_800_NS::ThreadLoad<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, (int)5>(const T1 *, cub::CUB_200500_600_700_800_NS::Int2Type<T2>, cub::CUB_200500_600_700_800_NS::Int2Type<(int)1>)+0x1fd0 in /home/coder/cccl/cub/cub/thread/thread_load.cuh:341
=========     Device Frame:std::iterator_traits<T2>::value_type cub::CUB_200500_600_700_800_NS::ThreadLoad<(cub::CUB_200500_600_700_800_NS::CacheLoadModifier)5, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> *>(T2)+0x1fd0 in /home/coder/cccl/cub/cub/thread/thread_load.cuh:354
=========     Device Frame:thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> cub::CUB_200500_600_700_800_NS::CacheModifiedInputIterator<(cub::CUB_200500_600_700_800_NS::CacheLoadModifier)5, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, int>::operator []<int>(T1) const+0x1fd0 in /home/coder/cccl/cub/cub/iterator/cache_modified_input_iterator.cuh:217
=========     Device Frame:void cub::CUB_200500_600_700_800_NS::AgentReduce<cub::CUB_200500_600_700_800_NS::AgentReducePolicy<(int)256, (int)16, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, (int)4, (cub::CUB_200500_600_700_800_NS::BlockReduceAlgorithm)2, (cub::CUB_200500_600_700_800_NS::CacheLoadModifier)5, cub::CUB_200500_600_700_800_NS::MemBoundScaling<(int)256, (int)16, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>>>, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> *, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> *, int, thrust::THRUST_200500_600_700_800_NS::cuda_cub::__find_if::functor<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>>, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, cuda::std::__4::__identity>::ConsumeTile<(int)1, (int)0>(thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> &, int, int, cub::CUB_200500_600_700_800_NS::Int2Type<(int)0>, cub::CUB_200500_600_700_800_NS::Int2Type<T2>)+0x1fb0 in /home/coder/cccl/cub/cub/agent/agent_reduce.cuh:329
=========     Device Frame:thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> cub::CUB_200500_600_700_800_NS::AgentReduce<cub::CUB_200500_600_700_800_NS::AgentReducePolicy<(int)256, (int)16, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, (int)4, (cub::CUB_200500_600_700_800_NS::BlockReduceAlgorithm)2, (cub::CUB_200500_600_700_800_NS::CacheLoadModifier)5, cub::CUB_200500_600_700_800_NS::MemBoundScaling<(int)256, (int)16, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>>>, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> *, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> *, int, thrust::THRUST_200500_600_700_800_NS::cuda_cub::__find_if::functor<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>>, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, cuda::std::__4::__identity>::ConsumeRange<(int)0>(cub::CUB_200500_600_700_800_NS::GridEvenShare<int> &, cub::CUB_200500_600_700_800_NS::Int2Type<T1>)+0x1f40 in /home/coder/cccl/cub/cub/agent/agent_reduce.cuh:362
=========     Device Frame:cub::CUB_200500_600_700_800_NS::AgentReduce<cub::CUB_200500_600_700_800_NS::AgentReducePolicy<(int)256, (int)16, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, (int)4, (cub::CUB_200500_600_700_800_NS::BlockReduceAlgorithm)2, (cub::CUB_200500_600_700_800_NS::CacheLoadModifier)5, cub::CUB_200500_600_700_800_NS::MemBoundScaling<(int)256, (int)16, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>>>, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> *, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> *, int, thrust::THRUST_200500_600_700_800_NS::cuda_cub::__find_if::functor<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>>, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, cuda::std::__4::__identity>::ConsumeRange(int, int)+0x40 in /home/coder/cccl/cub/cub/agent/agent_reduce.cuh:386
=========     Device Frame:void cub::CUB_200500_600_700_800_NS::DeviceReduceSingleTileKernel<cub::CUB_200500_600_700_800_NS::DeviceReducePolicy<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, unsigned int, thrust::THRUST_200500_600_700_800_NS::cuda_cub::__find_if::functor<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>>>::Policy600, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> *, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> *, int, thrust::THRUST_200500_600_700_800_NS::cuda_cub::__find_if::functor<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>>, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, cuda::std::__4::__identity>(T2, T3, T4, T5, T6, T8)+0x40 in /home/coder/cccl/cub/cub/device/dispatch/dispatch_reduce.cuh:287
=========     Saved host backtrace up to driver entry point at kernel launch time
=========     Host Frame: [0x2ef36f]
=========                in /usr/lib/x86_64-linux-gnu/libcuda.so.1
=========     Host Frame:libcudart_static_4d8b33a106dceb3c07a56e26de61f2d53bb62a68 [0x12810d]
=========                in /home/coder/cccl/build/cuda12.4-gcc13/cub-cpp17/bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0
=========     Host Frame:cudaLaunchKernel [0x18b84d]
=========                in /home/coder/cccl/build/cuda12.4-gcc13/cub-cpp17/bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0
=========     Host Frame:void cub::CUB_200500_600_700_800_NS::DeviceReduceSingleTileKernel<cub::CUB_200500_600_700_800_NS::DeviceReducePolicy<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, unsigned int, thrust::THRUST_200500_600_700_800_NS::cuda_cub::__find_if::functor<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> > >::Policy600, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>*, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>*, int, thrust::THRUST_200500_600_700_800_NS::cuda_cub::__find_if::functor<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> >, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, cuda::std::__4::__identity>(thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>*, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>*, int, thrust::THRUST_200500_600_700_800_NS::cuda_cub::__find_if::functor<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> >, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, cuda::std::__4::__identity) [0xc787c]
=========                in /home/coder/cccl/build/cuda12.4-gcc13/cub-cpp17/bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0
=========     Host Frame:cudaError thrust::THRUST_200500_600_700_800_NS::cuda_cub::launcher::triple_chevron::doit_host<void (*)(thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>*, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>*, int, thrust::THRUST_200500_600_700_800_NS::cuda_cub::__find_if::functor<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> >, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, cuda::std::__4::__identity), thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>*, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>*, int, thrust::THRUST_200500_600_700_800_NS::cuda_cub::__find_if::functor<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> >, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, cuda::std::__4::__identity>(void (*)(thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>*, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>*, int, thrust::THRUST_200500_600_700_800_NS::cuda_cub::__find_if::functor<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> >, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, cuda::std::__4::__identity), thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>* const&, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>* const&, int const&, thrust::THRUST_200500_600_700_800_NS::cuda_cub::__find_if::functor<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> > const&, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> const&, cuda::std::__4::__identity const&) const [clone .isra.0] [0x9957a]
=========                in /home/coder/cccl/build/cuda12.4-gcc13/cub-cpp17/bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0
=========     Host Frame:cudaError cub::CUB_200500_600_700_800_NS::DeviceReduce::Reduce<thrust::THRUST_200500_600_700_800_NS::zip_iterator<thrust::THRUST_200500_600_700_800_NS::tuple<thrust::THRUST_200500_600_700_800_NS::cuda_cub::transform_input_iterator_t<bool, thrust::THRUST_200500_600_700_800_NS::cuda_cub::transform_pair_of_input_iterators_t<bool, thrust::THRUST_200500_600_700_800_NS::detail::normal_iterator<thrust::THRUST_200500_600_700_800_NS::device_ptr<unsigned char const> >, thrust::THRUST_200500_600_700_800_NS::detail::normal_iterator<thrust::THRUST_200500_600_700_800_NS::device_ptr<unsigned char const> >, thrust::THRUST_200500_600_700_800_NS::equal_to<unsigned char> >, thrust::THRUST_200500_600_700_800_NS::detail::unary_negate<thrust::THRUST_200500_600_700_800_NS::cuda_cub::identity> >, thrust::THRUST_200500_600_700_800_NS::cuda_cub::counting_iterator_t<long> > >, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>*, thrust::THRUST_200500_600_700_800_NS::cuda_cub::__find_if::functor<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> >, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, int>(void*, unsigned long&, thrust::THRUST_200500_600_700_800_NS::zip_iterator<thrust::THRUST_200500_600_700_800_NS::tuple<thrust::THRUST_200500_600_700_800_NS::cuda_cub::transform_input_iterator_t<bool, thrust::THRUST_200500_600_700_800_NS::cuda_cub::transform_pair_of_input_iterators_t<bool, thrust::THRUST_200500_600_700_800_NS::detail::normal_iterator<thrust::THRUST_200500_600_700_800_NS::device_ptr<unsigned char const> >, thrust::THRUST_200500_600_700_800_NS::detail::normal_iterator<thrust::THRUST_200500_600_700_800_NS::device_ptr<unsigned char const> >, thrust::THRUST_200500_600_700_800_NS::equal_to<unsigned char> >, thrust::THRUST_200500_600_700_800_NS::detail::unary_negate<thrust::THRUST_200500_600_700_800_NS::cuda_cub::identity> >, thrust::THRUST_200500_600_700_800_NS::cuda_cub::counting_iterator_t<long> > >, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>*, int, thrust::THRUST_200500_600_700_800_NS::cuda_cub::__find_if::functor<thrust::THRUST_200500_600_700_800_NS::tuple<bool, long> >, thrust::THRUST_200500_600_700_800_NS::tuple<bool, long>, CUstream_st*) [clone .isra.0] [0xa3347]
=========                in /home/coder/cccl/build/cuda12.4-gcc13/cub-cpp17/bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0
=========     Host Frame:void C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_6<metal::list<unsigned char> >() [0xb609b]
=========                in /home/coder/cccl/build/cuda12.4-gcc13/cub-cpp17/bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0
=========     Host Frame:Catch::RunContext::invokeActiveTestCase() [0x3f642]
=========                in /home/coder/cccl/build/cuda12.4-gcc13/cub-cpp17/bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0
=========     Host Frame:Catch::RunContext::runCurrentTest(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) [0x57aa7]
=========                in /home/coder/cccl/build/cuda12.4-gcc13/cub-cpp17/bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0
=========     Host Frame:Catch::RunContext::runTest(Catch::TestCase const&) [0x6078a]
=========                in /home/coder/cccl/build/cuda12.4-gcc13/cub-cpp17/bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0
=========     Host Frame:Catch::Session::runInternal() [0x6ac0f]
=========                in /home/coder/cccl/build/cuda12.4-gcc13/cub-cpp17/bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0
=========     Host Frame:Catch::Session::run() [0x6b1fd]
=========                in /home/coder/cccl/build/cuda12.4-gcc13/cub-cpp17/bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0
=========     Host Frame:main [0x2f8c5]
=========                in /home/coder/cccl/build/cuda12.4-gcc13/cub-cpp17/bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0
=========     Host Frame: [0x23a8f]
=========                in /usr/lib/x86_64-linux-gnu/libc.so.6
=========     Host Frame:__libc_start_main [0x23b48]
=========                in /usr/lib/x86_64-linux-gnu/libc.so.6
=========     Host Frame:_start [0x36394]
=========                in /home/coder/cccl/build/cuda12.4-gcc13/cub-cpp17/bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0

How to Reproduce

compute-sanitizer --tool initcheck --check-device-heap yes --leak-check full --padding 512 --track-stream-ordered-races all --check-warpgroup-mma yes --require-cuda-init no --check-exit-code yes --error-exitcode 1 --nvtx true /home/coder/cccl/build/cuda12.4-gcc13/cub-cpp17/bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0

Expected behavior

Uninitialized memory is not read.

Reproduction link

No response

Operating System

No response

nvidia-smi output

No response

NVCC version

No response

Activity

  1. alliepiper commented on Nov 7, 2024

    @alliepiper
    ContributorAuthor

    Looks like we'll have to suppress this, but we're currently blocked by a bug in compute-sanitizer.

    thrust::equal invokes find_if, which turns into a reduce that uses a tuple<bool, OffsetT> as the accumulator type. The uninitialized bytes are coming from the padding bytes in the tuple.

    I've added a suppressions file to my working branch, however, there's a bug in compute-sanitizer that's causing it to crash when using the suppression file, so this is currently blocked on NVBug 4950602.

    To repro the crash:

    #!/bin/bash
    
    # Checkout cccl:
    git clone https://github.com/alliepiper/cccl.git -b compute_sanitizer_crash
    cd cccl
    
    # Configure CUB:
    ci/build_cub.sh -configure -cmake-options "-DCMAKE_CUDA_FLAGS=-lineinfo"
    cd build/cub-cpp17
    
    # Build the test that reproduces the crash:
    ninja cub.cpp17.test.device_adjacent_difference_substract_left.lid_0
    
    # Write out the suppression file:
    cat <<EOF >compute-sanitizer-suppressions.xml
    <?xml version="1.0" encoding="utf-8"?>
    <ComputeSanitizerOutput>
      <!--
      thrust::equal reduces using an accumulator type tuple<bool, OffsetT>.
      The padding bytes inside the tuple are not initialized.
      This causes issues during $(cub::ThreadLoad), which loads the memory as aliased
      machine words that are cast to the tuple type.
      -->
      <record>
        <kind>Initcheck</kind>
        <what>
          <text>Uninitialized __global__ memory read of size 2 bytes</text>
          <size>2</size>
        </what>
        <deviceStack>
          <frame>
            <func>UnrolledThreadLoadImpl</func>
          </frame>
          <frame>
            <func>UnrolledThreadLoad</func>
          </frame>
          <frame>
            <func>ThreadLoad</func>
          </frame>
          <frame>
            <func>ThreadLoad</func>
          </frame>
          <frame>
            <func>operator []&lt;int&gt;(T1) const</func>
          </frame>
          <frame>
            <func>ConsumeTile</func>
          </frame>
          <frame>
            <func>ConsumeRange</func>
          </frame>
          <frame>
            <func>ConsumeRange</func>
          </frame>
          <frame>
            <func>DeviceReduceSingleTileKernel</func>
          </frame>
        </deviceStack>
      </record>
    </ComputeSanitizerOutput>
    EOF
    
    # Run compute-sanitizer:
    compute-sanitizer \
      --suppressions compute-sanitizer-suppressions.xml \
      --tool initcheck bin/cub.cpp17.test.device_adjacent_difference_substract_left.lid_0 \
      --durations yes
  2. alliepiper commented on Nov 15, 2024

    @alliepiper
    ContributorAuthor

    The crash is due to the <where> block missing in the record.

    Added a suppression to #1879.

  3. moved this from Todo to Done in CCCLon Nov 15, 2024
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

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions