Skip to content

Refactor iterator usage in thrust/cuda find() - #6019

Merged
bernhardmgruber merged 5 commits into
NVIDIA:mainfrom
bernhardmgruber:ref_find
Oct 15, 2025
Merged

bernhardmgruber merged 5 commits into
NVIDIA:mainfrom
bernhardmgruber:ref_find

Conversation

@bernhardmgruber

@bernhardmgruber bernhardmgruber commented Sep 25, 2025 •

Copy link
Copy Markdown
Contributor

@copy-pr-bot

copy-pr-bot Bot commented Sep 25, 2025

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 Sep 25, 2025
Comment on lines -215 to -216
// FIXME(bgruber): we should also be able to use transform_iterator here, but it makes nvc++ hang. See:
// https://github.com/NVIDIA/cccl/issues/3594. The problem does not occur with nvcc, so we could not add a test :/

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.

nvc++ is fine with this code


result_type result = reduce(
const result_type result = reduce(
policy, interval_begin, interval_end, result_type(false, interval_end - begin), __find_if::functor<result_type>());

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.

I get an error here at interval_end - begin because zip_iterator::operator- is disabled because _Constraints::__all_sized_sentinel fails because the transform iterator above is not default constructible (the predicate isn't default constructible). The latter is fine, so I wonder why the constraint on zip_iterator::operator- is needed.

@miscco

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.

This is from ::std::ranges::zip_view

It kind of also boils down to the iterator concepts, because we want a forward iterator to be regular which requires default constructibility

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.

That's a problem now, because if we replace any thrust zip iterator by a cuda one, it can be a source breaking change for a user.

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.

Discussed with @miscco offline: he will relax the constraint on operator-

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.

Put this in #6036 because we had to fix zip_iterator for NVHPC anyway

@bernhardmgruber
bernhardmgruber marked this pull request as ready for review September 25, 2025 17:04
@bernhardmgruber
bernhardmgruber requested a review from a team as a code owner September 25, 2025 17:04
@cccl-authenticator-app cccl-authenticator-app Bot moved this from In Progress to In Review in CCCL Sep 25, 2025
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@bernhardmgruber
bernhardmgruber force-pushed the ref_find branch 2 times, most recently from 87c0680 to dd654b8 Compare September 29, 2025 13:33
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 4h 58m: Pass: 100%/118 | Total: 7d 17h | Max: 4h 57m | Hits: 33%/166765

See results here.

@bernhardmgruber
bernhardmgruber merged commit 1c3c7dd into NVIDIA:main Oct 15, 2025
129 of 130 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Oct 15, 2025
@bernhardmgruber
bernhardmgruber deleted the ref_find branch October 15, 2025 08:55
@bernhardmgruber bernhardmgruber linked an issue Nov 21, 2025 that may be closed by this pull request
Naraenda pushed a commit to ROCm/rocm-libraries that referenced this pull request Oct 26, 2026
…hrust/cuda find() (NVIDIA/cccl#6019)

Upstream: NVIDIA/cccl@1c3c7dd

HIP: system/hip/detail/mismatch.h transform_pair_of_input_iterators_t got the iterator correctness fixes (defaulted default ctor, prefix operator++ returns self_t&, operator<); the find() zip/transform/counting_iterator rewrite is performance-only, so HIP find.h is unchanged. test/: no counterpart (no test change upstream beyond CUDA-only file). testing/: cuda/mismatch.cu unused-parameter cleanup taken. Not compiled, tests not run (per human)

Co-Authored-By: Claude <noreply@anthropic.com>
amd-jmahovsky added a commit to ROCm/rocm-libraries that referenced this pull request Oct 28, 2026
…ind/mismatch

Upstream: NVIDIA/cccl@1c3c7ddee12 (NVIDIA/cccl#6019)
Upstream: NVIDIA/cccl@8ca3dc3 (NVIDIA/cccl#6018)

HIP previously took no change for these (performance-only). Bring system/hip closer to upstream:
- find.h: find_if_n unwraps contiguous iterators and builds the zip/counting iterator with auto +
  variadic thrust::make_zip_iterator. transform_input_iterator_t now calls op(*input) directly instead
  of materializing the value_type (same semantics as ::cuda::transform_iterator; avoids NVIDIA/cccl#3591);
  prefix operator++ returns self_t&. The dedicated iterator is kept because thrust::transform_iterator
  still converts to the value_type and ::cuda::transform_iterator needs libhipcxx.
- mismatch.h: drop transform_pair_of_input_iterators_t and enable the zip_iterator + zip_function
  implementation (thrust:: versions, so it also works without libhipcxx).
Not compiled, tests not run (per human)

Co-Authored-By: Claude <noreply@anthropic.com>
amd-jmahovsky added a commit to ROCm/rocm-libraries that referenced this pull request Oct 28, 2026
…tors in hip find/mismatch

Related upstream commit: 8ca3dc31e90 Refactor thrust::mismatch to use CUDA iterators (NVIDIA/cccl#6018)
Related upstream commit: 1c3c7ddee12 Refactor iterator usage in thrust/cuda find() (NVIDIA/cccl#6019)
Related local port commit: e46dc36

e46dc36 brought the upstream find/mismatch rewrite to system/hip
using thrust:: iterators, plus a local transform_input_iterator_t because
thrust::transform_iterator materializes the value_type before calling the
predicate (NVIDIA/cccl#3591). libhipcxx is now mandatory, so hip now uses
the same libcu++ iterators as upstream's system/cuda:
- find.h: find_if_n zips _THRUST_LIBCXX::make_transform_iterator(
  try_unwrap_contiguous_iterator(first), predicate) with
  _THRUST_LIBCXX::counting_iterator<Size>(0) and uses a
  _THRUST_STD::tuple<bool, Size> result type; __find_if::
  transform_input_iterator_t and the dead !_THRUST_HAS_DEVICE_SYSTEM_STD
  include block are removed; upstream granular includes are taken
  (<thrust/functional.h> kept explicitly for the placeholders in find).
- mismatch.h: _THRUST_LIBCXX::make_zip_iterator and
  _THRUST_LIBCXX::zip_function(binary_pred), with upstream's granular
  includes instead of thrust/{distance,pair,zip_function}.h and
  thrust/iterator/zip_iterator.h.

Not compiled, tests not run (per human)

Co-Authored-By: Claude <noreply@anthropic.com>
Naraenda pushed a commit to ROCm/rocm-libraries that referenced this pull request Oct 29, 2026
…hrust/cuda find() (NVIDIA/cccl#6019)

Upstream: NVIDIA/cccl@1c3c7dd

HIP: system/hip/detail/mismatch.h transform_pair_of_input_iterators_t got the iterator correctness fixes (defaulted default ctor, prefix operator++ returns self_t&, operator<); the find() zip/transform/counting_iterator rewrite is performance-only, so HIP find.h is unchanged. test/: no counterpart (no test change upstream beyond CUDA-only file). testing/: cuda/mismatch.cu unused-parameter cleanup taken. Not compiled, tests not run (per human)

Co-Authored-By: Claude <noreply@anthropic.com>
Naraenda pushed a commit to ROCm/rocm-libraries that referenced this pull request Oct 29, 2026
…hrust/cuda find() (NVIDIA/cccl#6019)

Upstream: NVIDIA/cccl@1c3c7dd

HIP: system/hip/detail/mismatch.h transform_pair_of_input_iterators_t got the iterator correctness fixes (defaulted default ctor, prefix operator++ returns self_t&, operator<); the find() zip/transform/counting_iterator rewrite is performance-only, so HIP find.h is unchanged. test/: no counterpart (no test change upstream beyond CUDA-only file). testing/: cuda/mismatch.cu unused-parameter cleanup taken. Not compiled, tests not run (per human)

Co-Authored-By: Claude <noreply@anthropic.com>
Naraenda pushed a commit to ROCm/rocm-libraries that referenced this pull request Oct 29, 2026
…ind/mismatch

Upstream: NVIDIA/cccl@1c3c7ddee12 (NVIDIA/cccl#6019)
Upstream: NVIDIA/cccl@8ca3dc3 (NVIDIA/cccl#6018)

HIP previously took no change for these (performance-only). Bring system/hip closer to upstream:
- find.h: find_if_n unwraps contiguous iterators and builds the zip/counting iterator with auto +
  variadic thrust::make_zip_iterator. transform_input_iterator_t now calls op(*input) directly instead
  of materializing the value_type (same semantics as ::cuda::transform_iterator; avoids NVIDIA/cccl#3591);
  prefix operator++ returns self_t&. The dedicated iterator is kept because thrust::transform_iterator
  still converts to the value_type and ::cuda::transform_iterator needs libhipcxx.
- mismatch.h: drop transform_pair_of_input_iterators_t and enable the zip_iterator + zip_function
  implementation (thrust:: versions, so it also works without libhipcxx).
Not compiled, tests not run (per human)

Co-Authored-By: Claude <noreply@anthropic.com>
Naraenda pushed a commit to ROCm/rocm-libraries that referenced this pull request Oct 29, 2026
…tors in hip find/mismatch

Related upstream commit: 8ca3dc31e90 Refactor thrust::mismatch to use CUDA iterators (NVIDIA/cccl#6018)
Related upstream commit: 1c3c7ddee12 Refactor iterator usage in thrust/cuda find() (NVIDIA/cccl#6019)
Related local port commit: e46dc36

e46dc36 brought the upstream find/mismatch rewrite to system/hip
using thrust:: iterators, plus a local transform_input_iterator_t because
thrust::transform_iterator materializes the value_type before calling the
predicate (NVIDIA/cccl#3591). libhipcxx is now mandatory, so hip now uses
the same libcu++ iterators as upstream's system/cuda:
- find.h: find_if_n zips _THRUST_LIBCXX::make_transform_iterator(
  try_unwrap_contiguous_iterator(first), predicate) with
  _THRUST_LIBCXX::counting_iterator<Size>(0) and uses a
  _THRUST_STD::tuple<bool, Size> result type; __find_if::
  transform_input_iterator_t and the dead !_THRUST_HAS_DEVICE_SYSTEM_STD
  include block are removed; upstream granular includes are taken
  (<thrust/functional.h> kept explicitly for the placeholders in find).
- mismatch.h: _THRUST_LIBCXX::make_zip_iterator and
  _THRUST_LIBCXX::zip_function(binary_pred), with upstream's granular
  includes instead of thrust/{distance,pair,zip_function}.h and
  thrust/iterator/zip_iterator.h.

Not compiled, tests not run (per human)

Co-Authored-By: Claude <noreply@anthropic.com>
Naraenda pushed a commit to ROCm/rocm-libraries that referenced this pull request Oct 30, 2026
…hrust/cuda find() (NVIDIA/cccl#6019)

Upstream: NVIDIA/cccl@1c3c7dd

HIP: system/hip/detail/mismatch.h transform_pair_of_input_iterators_t got the iterator correctness fixes (defaulted default ctor, prefix operator++ returns self_t&, operator<); the find() zip/transform/counting_iterator rewrite is performance-only, so HIP find.h is unchanged. test/: no counterpart (no test change upstream beyond CUDA-only file). testing/: cuda/mismatch.cu unused-parameter cleanup taken. Not compiled, tests not run (per human)

Co-Authored-By: Claude <noreply@anthropic.com>
Beanavil pushed a commit to ROCm/rocm-libraries that referenced this pull request Oct 30, 2026
…hrust/cuda find() (NVIDIA/cccl#6019)

Upstream: NVIDIA/cccl@1c3c7dd

HIP: system/hip/detail/mismatch.h transform_pair_of_input_iterators_t got the iterator correctness fixes (defaulted default ctor, prefix operator++ returns self_t&, operator<); the find() zip/transform/counting_iterator rewrite is performance-only, so HIP find.h is unchanged. test/: no counterpart (no test change upstream beyond CUDA-only file). testing/: cuda/mismatch.cu unused-parameter cleanup taken. Not compiled, tests not run (per human)

Co-Authored-By: Claude <noreply@anthropic.com>
amd-jmahovsky added a commit to ROCm/rocm-libraries that referenced this pull request Oct 30, 2026
…ind/mismatch

Upstream: NVIDIA/cccl@1c3c7ddee12 (NVIDIA/cccl#6019)
Upstream: NVIDIA/cccl@8ca3dc3 (NVIDIA/cccl#6018)

HIP previously took no change for these (performance-only). Bring system/hip closer to upstream:
- find.h: find_if_n unwraps contiguous iterators and builds the zip/counting iterator with auto +
  variadic thrust::make_zip_iterator. transform_input_iterator_t now calls op(*input) directly instead
  of materializing the value_type (same semantics as ::cuda::transform_iterator; avoids NVIDIA/cccl#3591);
  prefix operator++ returns self_t&. The dedicated iterator is kept because thrust::transform_iterator
  still converts to the value_type and ::cuda::transform_iterator needs libhipcxx.
- mismatch.h: drop transform_pair_of_input_iterators_t and enable the zip_iterator + zip_function
  implementation (thrust:: versions, so it also works without libhipcxx).
Not compiled, tests not run (per human)

Co-Authored-By: Claude <noreply@anthropic.com>
amd-jmahovsky added a commit to ROCm/rocm-libraries that referenced this pull request Oct 30, 2026
…tors in hip find/mismatch

Related upstream commit: 8ca3dc31e90 Refactor thrust::mismatch to use CUDA iterators (NVIDIA/cccl#6018)
Related upstream commit: 1c3c7ddee12 Refactor iterator usage in thrust/cuda find() (NVIDIA/cccl#6019)
Related local port commit: e46dc36

e46dc36 brought the upstream find/mismatch rewrite to system/hip
using thrust:: iterators, plus a local transform_input_iterator_t because
thrust::transform_iterator materializes the value_type before calling the
predicate (NVIDIA/cccl#3591). libhipcxx is now mandatory, so hip now uses
the same libcu++ iterators as upstream's system/cuda:
- find.h: find_if_n zips _THRUST_LIBCXX::make_transform_iterator(
  try_unwrap_contiguous_iterator(first), predicate) with
  _THRUST_LIBCXX::counting_iterator<Size>(0) and uses a
  _THRUST_STD::tuple<bool, Size> result type; __find_if::
  transform_input_iterator_t and the dead !_THRUST_HAS_DEVICE_SYSTEM_STD
  include block are removed; upstream granular includes are taken
  (<thrust/functional.h> kept explicitly for the placeholders in find).
- mismatch.h: _THRUST_LIBCXX::make_zip_iterator and
  _THRUST_LIBCXX::zip_function(binary_pred), with upstream's granular
  includes instead of thrust/{distance,pair,zip_function}.h and
  thrust/iterator/zip_iterator.h.

Not compiled, tests not run (per human)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

Implement thrust::find_if_not with thrust::transform_iterator

2 participants