Skip to content

Replace thrust::discard_iterator with cuda::discard_iterator - #8276

Closed
Jacobfaib wants to merge 20 commits into
NVIDIA:mainfrom
Jacobfaib:jacobf/2026-04-02/drop-thrust-discard-iterator
Closed

Jacobfaib wants to merge 20 commits into
NVIDIA:mainfrom
Jacobfaib:jacobf/2026-04-02/drop-thrust-discard-iterator

Conversation

@Jacobfaib

Copy link
Copy Markdown
Contributor

Description

Replaces thrust::discard_iterator with cuda::discard_iterator

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@Jacobfaib Jacobfaib self-assigned this Apr 2, 2026
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Apr 2, 2026
@copy-pr-bot

copy-pr-bot Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Progress in CCCL Apr 2, 2026
@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

1 similar comment
@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

Comment thread thrust/testing/discard_iterator.cu Resolved
@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

3 similar comments
@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

@Jacobfaib
Jacobfaib force-pushed the jacobf/2026-04-02/drop-thrust-discard-iterator branch from 2102745 to 3e05e79 Compare April 2, 2026 20:19
@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

1 similar comment
@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

1 similar comment
@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@Jacobfaib
Jacobfaib force-pushed the jacobf/2026-04-02/drop-thrust-discard-iterator branch from f39b18b to f391578 Compare April 8, 2026 14:11
@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

This comment has been minimized.

@Jacobfaib

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

😬 CI Workflow Results

🟥 Finished in 2h 48m: Pass: 96%/375 | Total: 13d 09h | Max: 2h 44m | Hits: 80%/526850

See results here.

static_assert(::cuda::std::is_invocable_v<Generator>, "The passed generator must be a nullary function object");
static_assert(
::cuda::std::is_assignable_v<detail::it_reference_t<RandomAccessIteratorOut>,
::cuda::std::is_assignable_v<::cuda::std::iter_reference_t<RandomAccessIteratorOut>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important: This is a change in semantics, why is this necessary?

See:

// the following iterator helpers are not named iter_value_t etc, like the C++20 facilities, because they are defined in
// terms of C++17 iterator_traits and not the new C++20 indirectly_readable trait etc. This allows them to detect nested
// value_type, difference_type and reference aliases, which the new C+20 traits do not consider (they only consider
// specializations of iterator_traits). Also, a value_type of void remains supported (needed by some output iterators).
template <typename It>
using it_value_t = typename ::cuda::std::iterator_traits<It>::value_type;
template <typename It>
using it_reference_t = typename ::cuda::std::iterator_traits<It>::reference;
template <typename It>
using it_difference_t = typename ::cuda::std::iterator_traits<It>::difference_type;
template <typename It>
using it_pointer_t = typename ::cuda::std::iterator_traits<It>::pointer;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the other comment. There is a change in value_type between the iterators which is not handled by CUB.

#include <thrust/iterator/constant_iterator.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/discard_iterator.h>
#include <cuda/iterator>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important: Please revert. We want to continue to test the old iterator with NVRTC.

Comment on lines +939 to +940
using InputT = non_void_value_t<InputIteratorT, it_value_t<OutputIteratorT>>;
using OutputT = non_void_value_t<OutputIteratorT, it_value_t<InputIteratorT>>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important: This is probably wrong, since we cannot just take the traits of the input type in case we have no output type.

Why is this necessary? Which test is failing?

@Jacobfaib Jacobfaib Apr 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cuda::discard_iterator::value_type is void, while thrust::discard_iterator::value_type is not. Many CUB algorithms seemingly don't handle this properly and/or had special handling for thrust::discard_iterator (or other proxy iterators) and so failed to compile with the new discard iterator.

@Jacobfaib Jacobfaib mentioned this pull request Apr 16, 2026
@Jacobfaib

Copy link
Copy Markdown
Contributor Author

@bernhardmgruber @miscco given that the cuda::discard_iterator has some fundamental mismatches with thrust::discard_iterator, I'm not sure we can wholesale replace the former with the latter, especially because CUB doesn't play nice with it.

I propose we table this PR until CCCL 4.0.

@Jacobfaib Jacobfaib closed this Apr 16, 2026
@Jacobfaib
Jacobfaib deleted the jacobf/2026-04-02/drop-thrust-discard-iterator branch April 16, 2026 17:17
@bernhardmgruber

Copy link
Copy Markdown
Contributor

@bernhardmgruber @miscco given that the cuda::discard_iterator has some fundamental mismatches with thrust::discard_iterator, I'm not sure we can wholesale replace the former with the latter, especially because CUB doesn't play nice with it.

I propose we table this PR until CCCL 4.0.

We should solve it before CCCL 4.0 I think, because we want to deprecate Thrust iterators several releases before 4.0 and also be sure that CUB works when users start feeding it with CUDA iterators.

Can we slim down this PR and merge pieces which are working?

@bernhardmgruber

Copy link
Copy Markdown
Contributor

Looking through the changeset, can we upstream some of the unit test changes?

@Jacobfaib

Copy link
Copy Markdown
Contributor Author

Ah sorry these got lost in my emails. We can resurrect some of the changes but it would require a lot of silence macros. Let me resurrect this PR and see what can be saved

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.

3 participants