Repository: NVIDIA/cccl

Issue #1467: [BUG]: Attempting to use nested zip iterators fails to compile with main (works with cccl v2.2)
Created: 2024-03-01T05:57:01Z
Is this a duplicate?

 I confirmed there appear to be no duplicate issues for this bug and that I agree to the Code of Conduct

Type of Bug
Compile-time Error
Component
Thrust
Describe the bug
Following code doesn't compile with CCCL main branch but compiles OK with CCCL v2.2
#include <thrust/device_vector.h>
#include <thrust/iterator/zip_iterator.h>
#include <thrust/iterator/permutation_iterator.h>

#include <vector>

struct checkMHPred {
    __host__ __device__ __forceinline__
    bool operator()(const thrust::tuple<uint32_t, thrust::tuple<thrust::tuple<int,int>, thrust::tuple<int,int>>>& idAndPt){
        thrust::tuple<thrust::tuple<int,int>, thrust::tuple<int,int>> ele1 = thrust::get<1>(idAndPt);
        thrust::tuple<int,int> p1 = thrust::get<0>(ele1);
        thrust::tuple<int,int> p2 = thrust::get<1>(ele1);
        return thrust::get<0>(p1) == thrust::get<0>(p2) || thrust::get<1>(p1) == thrust::get<1>(p2);
    } 
};

int main(void)
{

    thrust::device_vector<int> PX(std::vector<int>{0, 1, 2, 3});
    thrust::device_vector<int> PY(std::vector<int>{0, 1, 2, 2});
    thrust::device_vector<uint32_t> SS(std::vector<uint32_t>{0, 1, 2});
    thrust::device_vector<uint32_t> ST(std::vector<uint32_t>{1, 2, 3});
    thrust::device_vector<float> vecC(std::vector<float>{88.0f, 88.0f, 89.0f, 89.0f});

    auto segIt = thrust::make_zip_iterator(
                    thrust::make_zip_iterator(
                        thrust::make_permutation_iterator(PX.begin(), SS.begin()), 
                        thrust::make_permutation_iterator(PY.begin(), SS.begin())
                    ),
                    thrust::make_zip_iterator(
                        thrust::make_permutation_iterator(PX.begin(), ST.begin()), 
                        thrust::make_permutation_iterator(PY.begin(), ST.begin())
                    )
                    );
    auto idAndSegIt = thrust::make_zip_iterator(thrust::make_counting_iterator(0u), segIt);

    thrust::device_vector<bool> isMH(std::vector<bool>{false, false, false});
    thrust::transform(idAndSegIt, idAndSegIt + SS.size(), isMH.begin(), checkMHPred{});

    return 0;
}

How to Reproduce
I tested on CUDA 12.2 with GCC 9.4.0. Command to compile the standalone program:
/usr/local/cuda/bin/nvcc -I/path/to/cccl/thrust/ -I/path/to/cccl/libcudacxx/include/ -I/path/to/cccl/cub test.cu
error: no instance of constructor "cuda::std::__4::tuple<_Tp...>::tuple [with _Tp=<int, int>]" matches the argument list
            argument types are: (const thrust::THRUST_200400_520_NS::detail::tuple_of_iterator_references<int &, int &>, const thrust::THRUST_200400_520_NS::detail::tuple_of_iterator_references<int &, int &>)
        return {get<Id>(*this)...};

Compiles OK with cccl v2.2 but fails with main branch.
Expected behavior
I was expecting the code to compile with new cccl version as well.
Reproduction link
No response
Operating System
No response
nvidia-smi output
NVIDIA-SMI 535.54.03              Driver Version: 535.54.03    CUDA Version: 12.2
NVCC version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Tue_Jun_13_19:16:58_PDT_2023
Cuda compilation tools, release 12.2, V12.2.91
Build cuda_12.2.r12.2/compiler.32965470_0

Duplicate issue #1603: [BUG]: can't compile nested zip_iterators in CUDA toolkit 12.4.1
Created: 2024-04-05T23:06:28Z
Is this a duplicate?

 I confirmed there appear to be no duplicate issues for this bug and that I agree to the Code of Conduct

Type of Bug
Compile-time Error
Component
Thrust
Describe the bug
Nesting zip iterators fails to compile in CUDA toolkit 12.4.1.
How to Reproduce

The godbolt link below succeeds (CTK 12.3.1)
The same code in 12.4.1 errors like this:

$ nvcc --extended-lambda -c /tmp/zip_test.cu -o /tmp/zip_test.cu.o
/usr/local/cuda/include/thrust/iterator/detail/tuple_of_iterator_references.h(124): error: no instance of constructor "cuda::std::__4::tuple<_Tp...>::tuple [with _Tp=<int, int>]" matches the argument list
            argument types are: (const thrust::THRUST_200302_520_NS::detail::tuple_of_iterator_references<int &, int &>, double)
        return {get<Id>(*this)...};
               ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(904): note #3322-D: number of parameters of function template "cuda::std::__4::tuple<_Tp...>::tuple(cuda::std::__4::allocator_arg_t, const _Alloc &, _Tuple &&) [with _Tp=<int, int>]" does not match the call
    __attribute__((host)) __attribute__((device)) explicit tuple(allocator_arg_t,
                                                           ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(897): note #3322-D: number of parameters of function template "cuda::std::__4::tuple<_Tp...>::tuple(cuda::std::__4::allocator_arg_t, const _Alloc &, _Tuple &&) [with _Tp=<int, int>]" does not match the call
    __attribute__((host)) __attribute__((device)) tuple(allocator_arg_t, const _Alloc &__a,
                                                  ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(888): note #3322-D: number of parameters of function template "cuda::std::__4::tuple<_Tp...>::tuple(const _Tuple &) [with _Tp=<int, int>]" does not match the call
        constexpr explicit tuple(
                           ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(879): note #3322-D: number of parameters of function template "cuda::std::__4::tuple<_Tp...>::tuple(_Tuple &&) [with _Tp=<int, int>]" does not match the call
        constexpr explicit tuple(_Tuple &&__t) noexcept(
                           ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(869): note #3322-D: number of parameters of function template "cuda::std::__4::tuple<_Tp...>::tuple(const _Tuple &) [with _Tp=<int, int>]" does not match the call
    tuple(const _Tuple &__t) noexcept(is_nothrow_constructible_v<_BaseT, const _Tuple &>
    ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(860): note #3322-D: number of parameters of function template "cuda::std::__4::tuple<_Tp...>::tuple(_Tuple &&) [with _Tp=<int, int>]" does not match the call
    tuple(_Tuple &&__t) noexcept(is_nothrow_constructible_v<_BaseT, _Tuple>
    ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(841): note #3326-D: function template "cuda::std::__4::tuple<_Tp...>::tuple(cuda::std::__4::allocator_arg_t, const _Alloc &, _Up &&...) [with _Tp=<int, int>]" does not match because argument #1 does not match parameter
    __attribute__((host)) __attribute__((device)) explicit tuple(
                                                           ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(833): note #3326-D: function template "cuda::std::__4::tuple<_Tp...>::tuple(cuda::std::__4::allocator_arg_t, const _Alloc &, _Up &&...) [with _Tp=<int, int>]" does not match because argument #1 does not match parameter
    tuple(allocator_arg_t, const _Alloc &__a,
    ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(823): note #3327-D: candidate function template "cuda::std::__4::tuple<_Tp...>::tuple(_Up &&...) [with _Tp=<int, int>]" failed deduction
        constexpr explicit tuple(_Up &&...__u) noexcept(
                           ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(806): note #3327-D: candidate function template "cuda::std::__4::tuple<_Tp...>::tuple(_Up &&...) [with _Tp=<int, int>]" failed deduction
        constexpr explicit tuple(_Up &&...__u) noexcept(
                           ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(799): note #3327-D: candidate function template "cuda::std::__4::tuple<_Tp...>::tuple(_Up &&...) [with _Tp=<int, int>]" failed deduction
    tuple(_Up &&...__u) noexcept(_Constraints::__nothrow_constructible)
    ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(773): note #3322-D: number of parameters of function template "cuda::std::__4::tuple<_Tp...>::tuple(cuda::std::__4::allocator_arg_t, const _Alloc &, const int &, const int &) [with _Tp=<int, int>]" does not match the call
    __attribute__((host)) __attribute__((device)) explicit tuple(
                                                           ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(765): note #3322-D: number of parameters of function template "cuda::std::__4::tuple<_Tp...>::tuple(cuda::std::__4::allocator_arg_t, const _Alloc &, const int &, const int &) [with _Tp=<int, int>]" does not match the call
    tuple(allocator_arg_t, const _Alloc &__a, const _Tp &...__t) noexcept(
    ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(756): note #3326-D: function template "cuda::std::__4::tuple<_Tp...>::tuple(const int &, const int &) [with _Tp=<int, int>]" does not match because argument #1 does not match parameter
        constexpr explicit tuple(
                           ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(748): note #3326-D: function template "cuda::std::__4::tuple<_Tp...>::tuple(const int &, const int &) [with _Tp=<int, int>]" does not match because argument #1 does not match parameter
    tuple(const _Tp &...__t) noexcept(
    ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(739): note #3327-D: candidate function template "cuda::std::__4::tuple<_Tp...>::tuple(_AllocArgT, const _Alloc &) [with _Tp=<int, int>]" failed deduction
    explicit __attribute__((host)) __attribute__((device)) tuple(
                                                           ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(729): note #3327-D: candidate function template "cuda::std::__4::tuple<_Tp...>::tuple(_AllocArgT, const _Alloc &) [with _Tp=<int, int>]" failed deduction
    __attribute__((host)) __attribute__((device)) tuple(_AllocArgT, _Alloc const &__a) noexcept(
                                                  ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(721): note #3322-D: number of parameters of function "cuda::std::__4::tuple<_Tp...>::tuple(cuda::std::__4::tuple<_Tp...> &&) [with _Tp=<int, int>]" does not match the call
    tuple(tuple &&) = default;
    ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(720): note #3322-D: number of parameters of function "cuda::std::__4::tuple<_Tp...>::tuple(const cuda::std::__4::tuple<_Tp...> &) [with _Tp=<int, int>]" does not match the call
    tuple(tuple const &) = default;
    ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(717): note #3322-D: number of parameters of function template "cuda::std::__4::tuple<_Tp...>::tuple() [with _Tp=<int, int>]" does not match the call
    __attribute__((host)) __attribute__((device)) explicit constexpr tuple() noexcept(
                                                                     ^
/usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple(711): note #3322-D: number of parameters of function template "cuda::std::__4::tuple<_Tp...>::tuple() [with _Tp=<int, int>]" does not match the call
    __attribute__((host)) __attribute__((device)) constexpr tuple() noexcept(
                                                            ^
          detected during:
            instantiation of "thrust::THRUST_200302_520_NS::tuple<Us...> thrust::THRUST_200302_520_NS::detail::tuple_of_iterator_references<Ts...>::to_tuple<Us...,Id...>(cuda::std::__4::__tuple_indices<Id...>) const [with Ts=<thrust::THRUST_200302_520_NS::detail::tuple_of_iterator_references<int &, int &>, double &>, Us=<int, int>, Id=<0UL, 1UL>]" at line 108
            instantiation of "thrust::THRUST_200302_520_NS::detail::tuple_of_iterator_references<Ts...>::operator thrust::THRUST_200302_520_NS::tuple<Us...>() const [with Ts=<thrust::THRUST_200302_520_NS::detail::tuple_of_iterator_references<int &, int &>, double &>, Us=<int, int>, <unnamed>=0]" at line 284 of /usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple
            instantiation of "cuda::std::__4::__tuple_leaf<_Ip, _Hp, <unnamed>>::__tuple_leaf(_Tp &&) [with _Ip=0UL, _Hp=cuda::std::__4::tuple<int, int>, <unnamed>=false, _Tp=thrust::THRUST_200302_520_NS::detail::tuple_of_iterator_references<thrust::THRUST_200302_520_NS::detail::tuple_of_iterator_references<int &, int &>, double &>, <unnamed>=0]" at line 458 of /usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple
            instantiation of "cuda::std::__4::__tuple_impl<cuda::std::__4::__tuple_indices<_Indx...>, _Tp...>::__tuple_impl(cuda::std::__4::__tuple_variadic_constructor_tag, _Up &&...) [with _Indx=<0UL, 1UL>, _Tp=<cuda::std::__4::tuple<int, int>, double>, _Up=<thrust::THRUST_200302_520_NS::detail::tuple_of_iterator_references<thrust::THRUST_200302_520_NS::detail::tuple_of_iterator_references<int &, int &>, double &>, cuda::std::__4::__tuple_leaf_default_constructor_tag>, <unnamed>=0, __all_nothrow_constructible=false]" at line 471 of /usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple
            instantiation of "cuda::std::__4::__tuple_impl<cuda::std::__4::__tuple_indices<_Indx...>, _Tp...>::__tuple_impl(cuda::std::__4::__tuple_variadic_constructor_tag, _Up &&...) [with _Indx=<0UL, 1UL>, _Tp=<cuda::std::__4::tuple<int, int>, double>, _Up=<thrust::THRUST_200302_520_NS::detail::tuple_of_iterator_references<thrust::THRUST_200302_520_NS::detail::tuple_of_iterator_references<int &, int &>, double &>>, <unnamed>=0]" at line 827 of /usr/local/cuda/include/cuda/std/detail/libcxx/include/tuple
            [ 10 instantiation contexts not shown ]
            instantiation of "void thrust::THRUST_200302_520_NS::cuda_cub::core::AgentLauncher<Agent>::launch(_0, _1, _2, _3, _4, _5, _6, _7) const [with Agent=thrust::THRUST_200302_520_NS::cuda_cub::__copy_if::CopyIfAgent<thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<int *, int *>>, double *>>, thrust::THRUST_200302_520_NS::cuda_cub::__copy_if::no_stencil_tag, thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<int *, int *>>, double *>>, lambda [](const auto &)->auto, int, int *>, _0=thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<int *, int *>>, double *>>, _1=thrust::THRUST_200302_520_NS::cuda_cub::__copy_if::no_stencil_tag, _2=thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<int *, int *>>, double *>>, _3=lambda [](const auto &)->auto, _4=int, _5=int *, _6=cub::CUB_200302_520_NS::ScanTileState<int, true>, _7=size_t]" at line 696 of /usr/local/cuda/include/thrust/system/cuda/detail/copy_if.h
            instantiation of "cudaError_t thrust::THRUST_200302_520_NS::cuda_cub::__copy_if::doit_step(void *, size_t &, ItemsIt, StencilIt, OutputIt, Predicate, NumSelectedOutIt, Size, cudaStream_t) [with ItemsIt=thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<int *, int *>>, double *>>, StencilIt=thrust::THRUST_200302_520_NS::cuda_cub::__copy_if::no_stencil_tag, OutputIt=thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<int *, int *>>, double *>>, Predicate=lambda [](const auto &)->auto, Size=int, NumSelectedOutIt=int *]" at line 732 of /usr/local/cuda/include/thrust/system/cuda/detail/copy_if.h
            instantiation of "OutputIt thrust::THRUST_200302_520_NS::cuda_cub::__copy_if::copy_if(thrust::THRUST_200302_520_NS::cuda_cub::execution_policy<Derived> &, InputIt, InputIt, StencilIt, OutputIt, Predicate) [with Derived=thrust::THRUST_200302_520_NS::cuda_cub::par_t, InputIt=thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<int *, int *>>, double *>>, StencilIt=thrust::THRUST_200302_520_NS::cuda_cub::__copy_if::no_stencil_tag, OutputIt=thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<int *, int *>>, double *>>, Predicate=lambda [](const auto &)->auto]" at line 797 of /usr/local/cuda/include/thrust/system/cuda/detail/copy_if.h
            instantiation of "OutputIterator thrust::THRUST_200302_520_NS::cuda_cub::copy_if(thrust::THRUST_200302_520_NS::cuda_cub::execution_policy<Derived> &, InputIterator, InputIterator, OutputIterator, Predicate) [with Derived=thrust::THRUST_200302_520_NS::cuda_cub::par_t, InputIterator=thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<int *, int *>>, double *>>, OutputIterator=thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<int *, int *>>, double *>>, Predicate=lambda [](const auto &)->auto]" at line 49 of /usr/local/cuda/include/thrust/detail/copy_if.inl
            instantiation of "OutputIterator thrust::THRUST_200302_520_NS::copy_if(const thrust::THRUST_200302_520_NS::detail::execution_policy_base<DerivedPolicy> &, InputIterator, InputIterator, OutputIterator, Predicate) [with DerivedPolicy=thrust::THRUST_200302_520_NS::cuda_cub::par_t, InputIterator=thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<int *, int *>>, double *>>, OutputIterator=thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<thrust::THRUST_200302_520_NS::zip_iterator<cuda::std::__4::tuple<int *, int *>>, double *>>, Predicate=lambda [](const auto &)->auto]" at line 10 of /tmp/zip_test.cu

1 error detected in the compilation of "/tmp/zip_test.cu".
Expected behavior
The code should compile.
Reproduction link
https://godbolt.org/z/h3c3fhr4v
Operating System
No response
nvidia-smi output
No response
NVCC version
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Mar_28_02:18:24_PDT_2024
Cuda compilation tools, release 12.4, V12.4.131
Build cuda_12.4.r12.4/compiler.34097967_0

Closing comment (2024-04-05T23:16:44Z): Closing as duplicate of #1467