Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thrust::distance does not work with std::ranges::iota_view #787

Open
jeffhammond opened this issue Sep 9, 2021 · 2 comments
Open

thrust::distance does not work with std::ranges::iota_view #787

jeffhammond opened this issue Sep 9, 2021 · 2 comments
Assignees
Labels
thrust For all items related to Thrust.

Comments

@jeffhammond
Copy link

Is it unreasonable for me to expect this to work?

error

$ nvc++  -stdpar=multicore --c++20 -c thrust-ranges.cc 
"thrust-ranges.cc", line 15: error: no instance of function template "thrust::distance" matches the argument list
            argument types are: (std::ranges::iota_view<Index_type, Index_type>::_Iterator, std::ranges::iota_view<Index_type, Index_type>::_Iterator)
    auto d = thrust::distance(begin,end);
             ^

1 error detected in the compilation of "thrust-ranges.cc".

thrust-ranges.cc

#include <ranges>
#include <thrust/distance.h>

typedef std::ptrdiff_t Index_type;

void foo(void)
{
  const Index_type ibegin = 0;
  const Index_type iend   = 100;

  auto range = std::views::iota(ibegin, iend);
  auto begin = std::begin(range);
  auto end   = std::end(range);

  auto d = thrust::distance(begin,end);
}

Note that the type of Index_type doesn't matter. The same error occurs if I #define it to int.

@alliepiper
Copy link
Collaborator

I would expect that to work.

NVIDIA/thrust#1491 updated thrust::iterator_traits to support more types, this may address the issue since thrust::distance requires a valid specialization of those traits.

However, from your slack message, this also fails with std::distance so there may be more at play.

@miscco
Copy link
Collaborator

miscco commented May 2, 2022

I believe this is a bug in totally fine by libstdc++

They are differentiating their implementation based on iterator_category which does not make sense for iota_view with ptrdiff_t as input type (This is because we need __int128 as a difference type there and that breaks some of the usual machinery)

One can see this nicely here: https://godbolt.org/z/Yo86zE4K4

Long story short. Both thrust and libstc++ are perfectly conforming in their implementation. It is just a bad user experience that old machinery does not support new iterator types.

@jrhemstad jrhemstad added the thrust For all items related to Thrust. label Feb 22, 2023
@jarmak-nv jarmak-nv transferred this issue from NVIDIA/thrust Nov 8, 2023
@github-project-automation github-project-automation bot moved this to Todo in CCCL Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
thrust For all items related to Thrust.
Projects
Status: Todo
Development

No branches or pull requests

5 participants