Skip to content

Overload standard iterator functions for cuda iterators - #7738

Merged
davebayer merged 6 commits into
NVIDIA:mainfrom
miscco:cuda_iterator_stl
Feb 23, 2026
Merged

davebayer merged 6 commits into
NVIDIA:mainfrom
miscco:cuda_iterator_stl

Conversation

@miscco

@miscco miscco commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

Our cuda iterators are modern C++20 style iterators

That means they are very versatile, but also that they conform to the C++20 iterator concepts and not the C++17 iterator categories.

This creates the issue that if a user calls e.g. ::std::distance(::cuda::counting_iterator, ::cuda::counting_iterator) that will take the slow increment until equal path, because ::cuda::counting_iterator is not a C++17 random_access_iterator.

We already solve this issue in our own implementations through __has_meow_traversal_v which looks both at the iterator_category and also if needed at the iterator_concept

A relatively simple solution is to provide overloads for the common std iterator functions std::advance, ``std::distance, std::next and std::prev

That should help most use cases and with all the ranges machinery we are save anyway

@miscco
miscco requested a review from a team as a code owner February 23, 2026 16:12
@miscco
miscco requested a review from wmaxey February 23, 2026 16:12
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Feb 23, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Feb 23, 2026
@miscco miscco changed the title Specialize standard iterator functions for cuda iterators Overload standard iterator functions for cuda iterators Feb 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 1h 22m: Pass: 100%/99 | Total: 1d 06h | Max: 1h 05m | Hits: 89%/251637

See results here.

@davebayer
davebayer merged commit 57ac5df into NVIDIA:main Feb 23, 2026
115 checks passed
miscco added a commit to miscco/cccl that referenced this pull request Feb 26, 2026
* Overload standard iterator functions for `cuda::counting_iterator`

* Overload standard iterator functions for `cuda::zip_iterator`

* Overload standard iterator functions for `cuda::zip_transform_iterator`

* Overload standard iterator functions for `cuda::transform_iterator`

* Overload standard iterator functions for `cuda::transform_output_iterator`

* Overload standard iterator functions for `cuda::transform_input_output_iterator`
wmaxey added a commit that referenced this pull request Feb 27, 2026
* Overload standard iterator functions for `cuda` iterators (#7738)

* Overload standard iterator functions for `cuda::counting_iterator`

* Overload standard iterator functions for `cuda::zip_iterator`

* Overload standard iterator functions for `cuda::zip_transform_iterator`

* Overload standard iterator functions for `cuda::transform_iterator`

* Overload standard iterator functions for `cuda::transform_output_iterator`

* Overload standard iterator functions for `cuda::transform_input_output_iterator`

* Make `cuda::zip_iterator` work with proxy iterators (#7787)

We have a lot of proxy iterators that might be valid targets for zip_iterator

However, those conventionally have `void` as their `reference` / `value_type`

In that case, there is no `iter_value_t` available, so we need to deduce it differently

Fixes #7783

---------

Co-authored-by: Wesley Maxey <[email protected]>
@miscco
miscco deleted the cuda_iterator_stl branch June 2, 2026 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants