Skip to content

DeviceFor instantiates contiguous iterator trait for tabulate output iterators #8779

Closed

Description

@bdice

Summary

A RAPIDS cuDF build failed after #8565 with a tuple<..., void> compilation error while compiling cpp/src/join/sort_merge_join.cu. The failure appears to be caused by cub::DeviceFor::__for_each_n evaluating thrust::is_contiguous_iterator_v<RandomAccessIteratorT> even when vectorization is disabled.

A fix is proposed in #8778.

Failure

From https://github.com/NVIDIA/cccl/actions/runs/25033689578/job/73320636248:

/home/coder/cudf/cpp/src/join/sort_merge_join.cu:338:20:   required from 'std::pair<std::unique_ptr<rmm::device_uvector<int> >, std::unique_ptr<rmm::device_uvector<int> > > cudf::_GLOBAL__N__e951d515_18_sort_merge_join_cu_7bed6c89::merge<LargerIterator, SmallerIterator>::inner(rmm::cuda_stream_view, rmm::device_async_resource_ref) [with LargerIterator = const int*; SmallerIterator = const int*; rmm::device_async_resource_ref = cuda::mr::__4::__version_bump_ver4_::resource_ref<cuda::mr::__4::device_accessible>]'
/home/coder/cudf/cpp/src/join/sort_merge_join.cu:833:73:   required from 'cudf::detail::sort_merge_join::inner_join(const cudf::table_view&, cudf::sorted, rmm::cuda_stream_view, rmm::device_async_resource_ref) const::<lambda(auto:235&)> [with auto:235 = cudf::_GLOBAL__N__e951d515_18_sort_merge_join_cu_7bed6c89::merge<const int*, const int*>]'
/home/coder/cudf/cpp/src/join/sort_merge_join.cu:774:10:   required from 'auto cudf::detail::sort_merge_join::invoke_merge(const preprocessed_table&, cudf::table_view, cudf::table_view, MergeOperation&&, rmm::cuda_stream_view) const [with MergeOperation = cudf::detail::sort_merge_join::inner_join(const cudf::table_view&, cudf::sorted, rmm::cuda_stream_view, rmm::device_async_resource_ref) const::<lambda(auto:235&)>]'
/home/coder/cudf/cpp/src/join/sort_merge_join.cu:828:26:   required from here
/home/coder/cudf/cpp/build/conda/cuda-13.0/release/_deps/cccl-src/lib/cmake/libcudacxx/../../../libcudacxx/include/cuda/std/__tuple_dir/sfinae_helpers.h:46:5: error: 'cuda::std::__4::_TestSynthesizeAssignment<_Tp>::__dummy' has incomplete type
/home/coder/cudf/cpp/build/conda/cuda-13.0/release/_deps/cccl-src/lib/cmake/libcudacxx/../../../libcudacxx/include/cuda/std/__tuple_dir/sfinae_helpers.h:46:5: error: invalid use of 'void'

The diagnostic continues with the void tuple instantiation:

/home/coder/cudf/cpp/build/conda/cuda-13.0/release/_deps/cccl-src/lib/cmake/libcudacxx/../../../libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h: In instantiation of 'class cuda::std::__4::__tuple_leaf<1, void, cuda::std::__4::__tuple_leaf_specialization::__default>':
/home/coder/cudf/cpp/build/conda/cuda-13.0/release/_deps/cccl-src/lib/cmake/libcudacxx/../../../libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h:376:8:   required from 'struct cuda::std::__4::__tuple_impl<cuda::std::__4::__tuple_indices<0, 1>, cudf::detail::row::rhs_index_type, void>'
/home/coder/cudf/cpp/build/conda/cuda-13.0/release/_deps/cccl-src/lib/cmake/libcudacxx/../../../libcudacxx/include/cuda/std/__tuple_dir/tuple.h:52:8:   required from 'class cuda::std::__4::tuple<cudf::detail::row::rhs_index_type, void>'
/home/coder/cudf/cpp/build/conda/cuda-13.0/release/_deps/cccl-src/lib/cmake/libcudacxx/../../../libcudacxx/include/cuda/std/__type_traits/common_reference.h:75:70:   required by substitution of 'template<class _Ap, class _Bp> struct cuda::std::__4::__common_ref<_Ap&, _Bp&, typename cuda::std::__4::enable_if<is_reference_v<decltype ((false ?  declval<typename decltype (__apply_cv<_From>)::__call<_Yp>& (&)(), void>()() : declval<typename decltype (__apply_cv<_Yp>)::__call<_Xp>& (&)(), void>()()))>, void>::type> [with _Ap = thrust::detail::tuple_of_iterator_references<cudf::detail::row::rhs_index_type, thrust::detail::tabulate_output_iterator_proxy<...> >; _Bp = cuda::std::__4::tuple<cudf::detail::row::rhs_index_type, void>]'
/home/coder/cudf/cpp/build/conda/cuda-13.0/release/_deps/cccl-src/lib/cmake/libcudacxx/../../../libcudacxx/include/cuda/std/__type_traits/common_reference.h:198:8:   required from 'struct cuda::std::__4::common_reference<thrust::detail::tuple_of_iterator_references<cudf::detail::row::rhs_index_type, thrust::detail::tabulate_output_iterator_proxy<...> >&&, cuda::std::__4::tuple<cudf::detail::row::rhs_index_type, void>&>'
/home/coder/cudf/cpp/build/conda/cuda-13.0/release/_deps/cccl-src/lib/cmake/thrust/../../../thrust/thrust/type_traits/is_contiguous_iterator.h:100:86:   required from 'constexpr const bool thrust::detail::is_contiguous_iterator_impl_v<thrust::zip_iterator<cuda::std::__4::tuple<cuda::__4::transform_iterator<...>, thrust::tabulate_output_iterator<...> > > >'
/home/coder/cudf/cpp/build/conda/cuda-13.0/release/_deps/cccl-src/lib/cmake/thrust/../../../thrust/thrust/type_traits/is_contiguous_iterator.h:133:36:   required from 'constexpr const bool thrust::is_contiguous_iterator_v<thrust::zip_iterator<cuda::std::__4::tuple<cuda::__4::transform_iterator<...>, thrust::tabulate_output_iterator<...> > > >'
/home/coder/cudf/cpp/build/conda/cuda-13.0/release/_deps/cccl-src/lib/cmake/cub/../../../cub/cub/device/device_for.cuh:125:48:   [ skipping 6 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]

And later:

/home/coder/cudf/cpp/build/conda/cuda-13.0/release/_deps/cccl-src/lib/cmake/libcudacxx/../../../libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h:97:5: error: 'cuda::std::__4::__tuple_leaf<_Ip, _Hp, cuda::std::__4::__tuple_leaf_specialization::__default>::__value_' has incomplete type
/home/coder/cudf/cpp/build/conda/cuda-13.0/release/_deps/cccl-src/lib/cmake/libcudacxx/../../../libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h:97:5: error: invalid use of 'void'
/home/coder/cudf/cpp/build/conda/cuda-13.0/release/_deps/cccl-src/lib/cmake/libcudacxx/../../../libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h:177:70: error: forming reference to void
/home/coder/cudf/cpp/build/conda/cuda-13.0/release/_deps/cccl-src/lib/cmake/libcudacxx/../../../libcudacxx/include/cuda/std/__tuple_dir/tuple_leaf.h:181:76: error: forming reference to void
/home/coder/cudf/cpp/build/conda/cuda-13.0/release/_deps/cccl-src/lib/cmake/libcudacxx/../../../libcudacxx/include/cuda/std/__tuple_dir/tuple.h: In instantiation of 'class cuda::std::__4::tuple<cudf::detail::row::rhs_index_type, void>':

Root cause

#8565 refactored DeviceFor to route ForEachN through __for_each_n. In that function, the vectorization check is written as a single if constexpr condition:

allow_vectorization &&
THRUST_NS_QUALIFIER::is_contiguous_iterator_v<RandomAccessIteratorT>

For ForEachN, allow_vectorization is currently false. However, the compiler still has to form the full constant expression and therefore instantiates thrust::is_contiguous_iterator_v<RandomAccessIteratorT>.

That trait is not safe to instantiate for the iterator type generated by thrust::lower_bound in the failing cuDF path: a thrust::zip_iterator containing a tabulate output iterator. The output iterator has value_type = void, so the trait path attempts to form cuda::std::tuple<..., void>, which is ill-formed.

Expected behavior

If vectorization is disabled, DeviceFor::__for_each_n should not instantiate the contiguous-iterator trait at all.

Proposed fix

Nest the if constexpr blocks:

if constexpr (allow_vectorization) {
  if constexpr (THRUST_NS_QUALIFIER::is_contiguous_iterator_v<RandomAccessIteratorT>) {
    // vectorized path
  }
}

This preserves the vectorized path when it is enabled while avoiding invalid trait instantiations when vectorization is disabled.

Reproducer

#8778 adds two regression tests:

  • A Thrust test for thrust::lower_bound writing to cuda::tabulate_output_iterator.
  • A targeted CUB test for cub::DeviceFor::ForEachN over a thrust::zip_iterator containing cuda::tabulate_output_iterator.

Activity

  1. moved this from Todo to In Progress in CCCLon May 1, 2026
  2. moved this from In Progress to In Review in CCCLon May 1, 2026
  3. miscco commented on May 4, 2026

    @miscco
    Contributor

    Ok this is a bug in the C++17 emulation. The issue is that the value type is void and it should not try to instantiate the reference for that

    Will look into this

  4. moved this from In Review to In Progress in CCCLon May 6, 2026
  5. moved this from In Progress to In Review in CCCLon May 6, 2026
  6. moved this from In Review to Done in CCCLon May 6, 2026
  7. added a commit that references this issue on May 6, 2026
    799f466
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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