Skip to content

[Tile] Avoid internal usage of CPOs - #9023

Merged
davebayer merged 1 commit into
NVIDIA:mainfrom
miscco:tile_cpos
May 15, 2026
Merged

davebayer merged 1 commit into
NVIDIA:mainfrom
miscco:tile_cpos

Conversation

@miscco

@miscco miscco commented May 15, 2026

Copy link
Copy Markdown
Contributor

We cannot use CPOs in tile programs, because they live in device memory and its currently not possible to have __device__ __tile__ variables

So avoid this by constructing the empty struct instead of accessing the global instance

@miscco
miscco requested review from a team as code owners May 15, 2026 13:10
@miscco
miscco requested a review from alliepiper May 15, 2026 13:10
@miscco
miscco requested a review from griwes May 15, 2026 13:10
@github-project-automation github-project-automation Bot moved this to Todo in CCCL May 15, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL May 15, 2026
@coderabbitai

coderabbitai Bot commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 4c142fdf-bd39-4f13-b779-9db45d7b914e

📥 Commits

Reviewing files that changed from the base of the PR and between 07a32cd and 7e06ae8.

📒 Files selected for processing (55)
  • docs/libcudacxx/tile.rst
  • libcudacxx/include/cuda/__container/buffer.h
  • libcudacxx/include/cuda/__iterator/zip_common.h
  • libcudacxx/include/cuda/__iterator/zip_iterator.h
  • libcudacxx/include/cuda/std/__algorithm/iter_swap.h
  • libcudacxx/include/cuda/std/__algorithm/iterator_operations.h
  • libcudacxx/include/cuda/std/__algorithm/ranges_find_if.h
  • libcudacxx/include/cuda/std/__algorithm/ranges_for_each.h
  • libcudacxx/include/cuda/std/__algorithm/ranges_min.h
  • libcudacxx/include/cuda/std/__algorithm/ranges_min_element.h
  • libcudacxx/include/cuda/std/__algorithm/unwrap_range.h
  • libcudacxx/include/cuda/std/__concepts/swappable.h
  • libcudacxx/include/cuda/std/__expected/expected_base.h
  • libcudacxx/include/cuda/std/__iterator/access.h
  • libcudacxx/include/cuda/std/__iterator/advance.h
  • libcudacxx/include/cuda/std/__iterator/common_iterator.h
  • libcudacxx/include/cuda/std/__iterator/concepts.h
  • libcudacxx/include/cuda/std/__iterator/counted_iterator.h
  • libcudacxx/include/cuda/std/__iterator/distance.h
  • libcudacxx/include/cuda/std/__iterator/iter_move.h
  • libcudacxx/include/cuda/std/__iterator/iter_swap.h
  • libcudacxx/include/cuda/std/__iterator/move_iterator.h
  • libcudacxx/include/cuda/std/__iterator/next.h
  • libcudacxx/include/cuda/std/__iterator/prev.h
  • libcudacxx/include/cuda/std/__iterator/reverse_access.h
  • libcudacxx/include/cuda/std/__iterator/reverse_iterator.h
  • libcudacxx/include/cuda/std/__iterator/variant_like.h
  • libcudacxx/include/cuda/std/__memory/construct_at.h
  • libcudacxx/include/cuda/std/__pstl/reverse.h
  • libcudacxx/include/cuda/std/__pstl/swap_ranges.h
  • libcudacxx/include/cuda/std/__ranges/access.h
  • libcudacxx/include/cuda/std/__ranges/common_view.h
  • libcudacxx/include/cuda/std/__ranges/concepts.h
  • libcudacxx/include/cuda/std/__ranges/data.h
  • libcudacxx/include/cuda/std/__ranges/drop_view.h
  • libcudacxx/include/cuda/std/__ranges/drop_while_view.h
  • libcudacxx/include/cuda/std/__ranges/empty.h
  • libcudacxx/include/cuda/std/__ranges/filter_view.h
  • libcudacxx/include/cuda/std/__ranges/owning_view.h
  • libcudacxx/include/cuda/std/__ranges/rbegin.h
  • libcudacxx/include/cuda/std/__ranges/ref_view.h
  • libcudacxx/include/cuda/std/__ranges/rend.h
  • libcudacxx/include/cuda/std/__ranges/reverse_view.h
  • libcudacxx/include/cuda/std/__ranges/size.h
  • libcudacxx/include/cuda/std/__ranges/subrange.h
  • libcudacxx/include/cuda/std/__ranges/take_view.h
  • libcudacxx/include/cuda/std/__ranges/take_while_view.h
  • libcudacxx/include/cuda/std/__ranges/transform_view.h
  • libcudacxx/include/cuda/std/__ranges/unwrap_end.h
  • libcudacxx/include/cuda/std/__ranges/view_interface.h
  • libcudacxx/include/cuda/std/__simd/basic_vec.h
  • libcudacxx/include/cuda/std/__type_traits/type_list.h
  • libcudacxx/include/cuda/std/inplace_vector
  • libcudacxx/include/cuda/std/span
  • libcudacxx/include/cuda/std/string_view
✅ Files skipped from review due to trivial changes (10)
  • libcudacxx/include/cuda/std/__algorithm/unwrap_range.h
  • libcudacxx/include/cuda/std/__algorithm/ranges_min.h
  • libcudacxx/include/cuda/std/string_view
  • libcudacxx/include/cuda/std/__type_traits/type_list.h
  • libcudacxx/include/cuda/std/__algorithm/ranges_min_element.h
  • libcudacxx/include/cuda/__iterator/zip_iterator.h
  • libcudacxx/include/cuda/std/__iterator/concepts.h
  • libcudacxx/include/cuda/std/__pstl/swap_ranges.h
  • docs/libcudacxx/tile.rst
  • libcudacxx/include/cuda/std/__memory/construct_at.h
🚧 Files skipped from review as they are similar to previous changes (40)
  • libcudacxx/include/cuda/std/__iterator/counted_iterator.h
  • libcudacxx/include/cuda/std/__pstl/reverse.h
  • libcudacxx/include/cuda/std/__algorithm/ranges_for_each.h
  • libcudacxx/include/cuda/std/__ranges/ref_view.h
  • libcudacxx/include/cuda/std/__ranges/filter_view.h
  • libcudacxx/include/cuda/std/__iterator/advance.h
  • libcudacxx/include/cuda/std/__simd/basic_vec.h
  • libcudacxx/include/cuda/std/__iterator/variant_like.h
  • libcudacxx/include/cuda/__iterator/zip_common.h
  • libcudacxx/include/cuda/std/__iterator/move_iterator.h
  • libcudacxx/include/cuda/std/__iterator/distance.h
  • libcudacxx/include/cuda/std/__iterator/reverse_iterator.h
  • libcudacxx/include/cuda/std/__ranges/owning_view.h
  • libcudacxx/include/cuda/std/__algorithm/iter_swap.h
  • libcudacxx/include/cuda/std/__ranges/data.h
  • libcudacxx/include/cuda/std/__ranges/reverse_view.h
  • libcudacxx/include/cuda/__container/buffer.h
  • libcudacxx/include/cuda/std/__iterator/iter_move.h
  • libcudacxx/include/cuda/std/__algorithm/iterator_operations.h
  • libcudacxx/include/cuda/std/__ranges/view_interface.h
  • libcudacxx/include/cuda/std/__iterator/next.h
  • libcudacxx/include/cuda/std/__ranges/common_view.h
  • libcudacxx/include/cuda/std/__ranges/drop_view.h
  • libcudacxx/include/cuda/std/span
  • libcudacxx/include/cuda/std/__ranges/concepts.h
  • libcudacxx/include/cuda/std/__iterator/reverse_access.h
  • libcudacxx/include/cuda/std/__ranges/subrange.h
  • libcudacxx/include/cuda/std/__expected/expected_base.h
  • libcudacxx/include/cuda/std/__ranges/size.h
  • libcudacxx/include/cuda/std/__ranges/transform_view.h
  • libcudacxx/include/cuda/std/__ranges/take_while_view.h
  • libcudacxx/include/cuda/std/__iterator/iter_swap.h
  • libcudacxx/include/cuda/std/__ranges/take_view.h
  • libcudacxx/include/cuda/std/__iterator/common_iterator.h
  • libcudacxx/include/cuda/std/__ranges/access.h
  • libcudacxx/include/cuda/std/__iterator/prev.h
  • libcudacxx/include/cuda/std/__ranges/empty.h
  • libcudacxx/include/cuda/std/__iterator/access.h
  • libcudacxx/include/cuda/std/__ranges/rend.h
  • libcudacxx/include/cuda/std/inplace_vector

📝 Walkthrough

Summary by CodeRabbit

  • Documentation

    • Clarified that standard library customization point objects (CPOs) are not available in tile kernels and added a concise workaround example.
  • Chores

    • Internal refactor: range/iterator/view/algorithm internals routed through internal CPO entry points to improve correctness and compatibility in tile/kernel contexts.

Walkthrough

important: Add internal __*_cpo aliases and migrate internal call-sites across iterators, ranges, views, algorithms, and containers to invoke those CPO objects instead of public ranges free-functions/CPOs; update noexcept/decltype and concept expressions accordingly.

Changes

Internal CPO Infrastructure for Tile Compatibility

Layer / File(s) Summary
CPO alias definitions and wiring
libcudacxx/include/cuda/std/__iterator/advance.h, libcudacxx/include/cuda/std/__iterator/iter_move.h, libcudacxx/include/cuda/std/__iterator/access.h, libcudacxx/include/cuda/std/__iterator/reverse_access.h, libcudacxx/include/cuda/std/__ranges/access.h
Introduce internal aliases such as __advance_cpo, __iter_move_cpo, __begin_cpo, __end_cpo, __data_cpo, __size_cpo, etc., bound to underlying __fn objects for internal invocation.
Iterator move/swap and hidden-friend updates
libcudacxx/include/cuda/std/__iterator/*, libcudacxx/include/cuda/__iterator/*, zip_common.h, zip_iterator.h
Hidden-friend iter_move/iter_swap, move/swap implementations, and noexcept checks now dispatch via __iter_move_cpo / __iter_swap_cpo / __swap_cpo instead of calling public ranges::iter_move/iter_swap/swap.
Advance/next/prev/distance/size changes
libcudacxx/include/cuda/std/__iterator/next.h, prev.h, distance.h, __ranges/size.h, __ranges/unwrap_end.h
Advance/next/prev/distance/size call sites and internal detections now use __advance_cpo, __next_cpo, __distance_cpo, __size_cpo instead of public free functions/CPOs.
Range access, data, empty, concepts
libcudacxx/include/cuda/std/__ranges/access.h, __ranges/data.h, __ranges/empty.h, __ranges/concepts.h
iterator_t, data, empty, and range concept checks compute results via internal __*_cpo call objects; cdata/data implementations now route through __data_cpo/__begin_cpo.
Views and view_interface changes
__ranges/common_view.h, drop_view.h, filter_view.h, take_view.h, take_while_view.h, drop_while_view.h, transform_view.h, reverse_view.h, rbegin.h, rend.h, view_interface.h
Begin/end/size/data/empty/front/back/operator[] implementations and associated noexcept/decltype expressions now use internal CPOs for iterator/sentinel/size calculations.
Containers and range-based constructors
libcudacxx/include/cuda/__container/buffer.h, libcudacxx/include/cuda/std/inplace_vector, libcudacxx/include/cuda/std/span, libcudacxx/include/cuda/std/string_view, __simd/basic_vec.h
Range constructors and range-modifier paths obtain iterators/data/size via __begin_cpo/__data_cpo/__size_cpo and use __iter_move_cpo/__distance_cpo where appropriate.
Algorithms and PSTL
libcudacxx/include/cuda/std/__algorithm/*, __pstl/*
Algorithm call sites (find_if, for_each, min, swap_ranges, iter_swap uses) updated to use internal CPOs for begin/end/iter_move/iter_swap.
Supporting type/impl changes
__expected/expected_base.h, __type_traits/type_list.h, __memory/construct_at.h, variant_like.h, reverse_iterator.h
Internal placeholder renames (__empty_t → __empty_cpo), recursive alias rename (__next_t → __next_cpo), and internal implementations updated to call __*_cpo aliases; public APIs unchanged.
Docs
docs/libcudacxx/tile.rst
Document that public CPO objects (e.g., cuda::std::begin) are inaccessible in tile kernels and show workaround (construct empty CPO instance: decltype(cuda::std::begin){}(...)).

suggestion: Suggested reviewers

  • alliepiper
  • griwes

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]

This comment was marked as outdated.

@miscco

miscco commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

We cannot use CPOs in tile programs, because they live in device memory and its currently not possible to have `__device__ __tile__` variables

So avoid this by constructing the empty struct instead of accessing the global instance

@davebayer davebayer left a comment

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.

Image

@davebayer
davebayer enabled auto-merge (squash) May 15, 2026 17:25
@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 3h 49m: Pass: 100%/114 | Total: 5d 20h | Max: 3h 49m | Hits: 37%/2785152

See results here.

@davebayer
davebayer merged commit b4bf1a5 into NVIDIA:main May 15, 2026
134 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL May 15, 2026
wmaxey pushed a commit that referenced this pull request May 21, 2026
* [libcu++] Fix `__detectably_invalid` value returned during constant evaluations (#8987)

* Fix nightly GCC8 build regressions in bit_cast and DeviceReduce (#8924)

* Fix nightly GCC8 build regressions in bit_cast and DeviceReduce

Two unrelated regressions surfaced together in the 2026-05-12 nightly run on
`main`. Both block all GCC builds on older CTKs (12.0, 12.X) for libcu++, and
all GCC 8 CUB builds.

libcu++: bit_cast<__float128>
  The memcpy fallback path in `__bit_cast_memcpy` is reached on GCC 8/9/10
  because those host compilers don't provide `__builtin_bit_cast`. Commit
  8b28e1d (#8265) replaced the previous `is_trivially_default_constructible_v`
  trait with the C++20-style `default_initializable` concept; the concept's
  emulation evaluates false for `__float128` in C++17 mode, even though the
  built-in scalar is in fact default-initializable. Restore an equivalent type
  trait (`is_default_constructible_v`), which queries the compiler builtin
  directly and works on every supported GCC. The GCC<=7 gate around the
  static_assert is no longer needed and is removed.

CUB: DeviceReduce reduction_op
  Commit b60f063 (#8851) merged the three determinism overloads of
  `reduce_impl` into a single `if constexpr` template. The `__gpu_to_gpu`
  branch dispatches to RFA, which hardcodes `deterministic_sum_t<accum_t>`
  internally and does not accept a reduction operator. GCC 8's
  `-Werror=unused-but-set-parameter` flags `reduction_op` because that branch
  never references it. The parameter must remain in the signature (the other
  two branches use it), so the invariant -- enforced upstream by
  `__transform_reduce`'s `float_double_plus` check -- is acknowledged with
  `(void) reduction_op` plus a one-line note inside the branch.

[skip-vdc][skip-docs][skip-tpt]

* Fix unbound-variable error in build_and_test_targets.sh

`${#ARRAY}` is syntactic sugar for `${#ARRAY[0]}` -- the length of element 0.
Under `set -u`, when an array is empty (no `--ctest-targets`, `--lit-tests`,
etc. on the command line), this errors with "unbound variable" before the
guard can short-circuit. Use `${#ARRAY[@]}` (total element count), which is
defined as 0 on an empty array.

* Skip simd::basic_mask generator-ctor noexcept assert on GCC 8

GCC 8 infers noexcept on the generator constructor more permissively
than GCC 9+, so `static_assert(!noexcept(Mask(is_even{})))` fires.
Widen the existing GCC 7 skip to also cover GCC 8.

* Skip pointer compare in __constexpr_tail_overlap when is_constant_evaluated is faked

On GCC 8 there is no __builtin_is_constant_evaluated, so
cuda::std::is_constant_evaluated() always returns false. That makes
`if (!is_constant_evaluated())` look statically true, so the compiler
takes the runtime branch even in a constant expression and trips over
the pointer compare, which is not allowed there.

Only enable the runtime branch on compilers that actually provide the
builtin; everyone else falls through to the constexpr-safe path.

* Fix copy runtime optimization

* clear override

* Update libcudacxx/include/cuda/std/__bit/bit_cast.h

Co-authored-by: Federico Busato <[email protected]>

* Fix missing include for default_initializable in bit_cast.h

---------

Co-authored-by: Michael Schellenberger Costa <[email protected]>
Co-authored-by: Federico Busato <[email protected]>

* [Tile] avoid returns in switch statements in logarithm (#9001)

tile currently does not support returning directly from a switch statement, so turn those into if chains

* [Tile] Avoid returns inside loops in `mdspan` (#9004)

* [Tile] Avoid returning from a loop in `extents`

* [Tile] Avoid returns inside loops in `mdspan`

* [Tile] avoid return in switch statement in `assume_aligned` (#9002)

tile currently does not support returning directly from a switch statement, so turn those into if chains

* [Tile] Avoid returning in a loop in `env` (#9007)

tile does not support return statements inside a loop

* [Tile] Avoid return in loop in `charconv` (#9010)

tile does not allow return statemetns in loops, so avoid them

* [Tile] avoid use of CPO in variant (#9012)

We cannot access device variables in a tile program, so we should just create the empty CPO in place

* [Tile] Mark `simd` as `_CCCL_HOST_DEVICE` (#9013)

* [Tile] avoid use of CPO in variant

We cannot access device variables in a tile program, so we should just create the empty CPO in place

* [Tile] Mark `simd` as `_CCCL_HOST_DEVICE`

it relies on asm and manuall loop unrolling a lot

* [Tile] Avoid return in loop in `variant` (#9011)

tile does not allow return statements in loops, so avoid them

* [Tile] Mark threading support as `_CCCL_HOST_DEVICE_API` (#9006)

In tile all the concurency is done by compiler

* [Tile] Avoid unused variable warning (#9009)

* [Tile] Avoid returns in loops in various algorithms (#9014)

tile does not allow return statements in loops so try to avoid them

* [libcu++] Fix device fp128 functions test (#9015)

* Revert "[libcu++] Fix concurent return value writes during device testing (#8957)" (#9003)

This reverts commit d2f9824.

In tile mode we cannot use atommicCAS, so this breaks all our tests

* [Tile] Make `arch_id` `_CCCL_HOST_DEVICE_API` (#9005)

* [Tile] Avoid returns in loops in string functions (#9008)

* [Tile] Avoid return from loop in string_view

* [Tile] Avoid returns in loops in constexpr c functions

* [Tile] Avoid return in loops in string helper functions

* [libcu++] avoid warning about pointless comparison (#9016)

Looks like newer NVCC warns about it despite our workarounds

* [Tile] Avoid unused variable warnings (#9017)

* [Tile] Mark some algorithms as `_CCCL_HOST_DEVICE_API` (#9018)

tile does not support return statements inside loops. For some algorithms its really invasive to rewrite them correctly, so just diable them.

* [Tile] Avoid use of `in_place` global (#9024)

tile does not allow access to `__device__` variables, so construct an instance via `in_place_t{}`

* [Tile] Avoid returns in loops in some algorithms (#9025)

* [Tile] Avoid loops in bitset (#9027)

* [Tile] Do not access global in tile mode (#9026)

* [Tile] Avoid internal usage of CPOs (#9023)

We cannot use CPOs in tile programs, because they live in device memory and its currently not possible to have `__device__ __tile__` variables

So avoid this by constructing the empty struct instead of accessing the global instance

* [Tile] Avoid calling a device only function in tile mode (#9031)

* [Tile] Mark format tests as unsupported (#9033)

tile does not allow bit fields

* [Tile] Avoid return in switch statements in `variant` (#9032)

tile does not allow a return statement inside a switch

* [Tile] Try to appease tile compiler (#9035)

* [Tile] enable some more tests (#9034)

* [Tile] reenable tests that have been fixed recently

* [Tile] Reenable tests that were failing to validate MLIR

We avoided return statements in loops which made them fail

* [Tile] Reenable tests that relied on `__builtin_unreachable`

* [Tile] enable some more tests

---------

Co-authored-by: David Bayer <[email protected]>
Co-authored-by: alliepiper <[email protected]>
Co-authored-by: Federico Busato <[email protected]>
@miscco
miscco deleted the tile_cpos branch June 2, 2026 08:41
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