Skip to content

[libcu++] Implement P3060R3 Add std::views::indices(n) - #10700

Open
davebayer wants to merge 1 commit into
NVIDIA:mainfrom
davebayer:views_indices
Open

[libcu++] Implement P3060R3 Add std::views::indices(n)#10700
davebayer wants to merge 1 commit into
NVIDIA:mainfrom
davebayer:views_indices

Conversation

@davebayer

Copy link
Copy Markdown
Contributor

Fixes #10356.

@davebayer
davebayer requested a review from a team as a code owner August 7, 2026 06:11
@davebayer
davebayer requested a review from griwes August 7, 2026 06:11
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Aug 7, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added cuda::std::views::indices for creating integer-index ranges from zero to a specified size.
    • Supports integer-like inputs, compile-time evaluation, range indexing, and size queries.
  • Bug Fixes

    • Improved range size calculation for signed starting values, including correct handling of negative values.
  • Compatibility

    • Added a feature-test indicator for detecting views::indices support.

Walkthrough

The PR adds cuda::std::views::indices, updates iota_view::size() for unsigned starts, defines __cccl_lib_ranges_indices, and adds compile-time and runtime tests.

Changes

views::indices

Layer / File(s) Summary
Implement views::indices and iota_view sizing
libcudacxx/include/cuda/std/__ranges/iota_view.h
The implementation adds required headers, limits negative-value handling to signed starts, and constructs an iota_view from zero to an integer-like size.
Publish and test the indices contract
libcudacxx/include/cuda/std/version, libcudacxx/test/libcudacxx/std/ranges/range.factories/range.iota.view/indices.pass.cpp
The version header defines __cccl_lib_ranges_indices as 202506L. Tests cover constraints, values, size, array-size construction, runtime execution, and constexpr execution.

Assessment against linked issues

Objective Addressed Explanation
Implement std::views::indices(n) from P3060R3 [#10356]

Suggested reviewers: griwes


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

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (2)
libcudacxx/include/cuda/std/__ranges/iota_view.h (1)

270-270: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Declare __size as const _Tp __size. Line 270 does not modify this parameter. As per coding guidelines, “All variables that are not modified must be declared const.”

Source: Coding guidelines

libcudacxx/test/libcudacxx/std/ranges/range.factories/range.iota.view/indices.pass.cpp (1)

27-57: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Rename HasIndices, HasIndicesFn, NotIntegerLike, and test_SFINAE to snake_case. These are not template parameters or CUB public API symbols. As per coding guidelines, “Use snake_case for all other symbols.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: dd60016d-4852-4385-8a66-ec1cda5adf54

📥 Commits

Reviewing files that changed from the base of the PR and between 25e6f45 and 237e92b.

📒 Files selected for processing (3)
  • libcudacxx/include/cuda/std/__ranges/iota_view.h
  • libcudacxx/include/cuda/std/version
  • libcudacxx/test/libcudacxx/std/ranges/range.factories/range.iota.view/indices.pass.cpp

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
libcudacxx/test/libcudacxx/std/ranges/range.factories/range.iota.view/indices.pass.cpp (1)

27-46: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Rename HasIndices, HasIndicesFn, NotIntegerLike, and test_SFINAE to snake_case. Keep SizeType and T in PascalCase because they are template parameters. As per coding guidelines, “Use snake_case for all other symbols, except that the CUB public API uses PascalCase.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 9089676e-6bef-4dbb-8a8d-567e84e0a086

📥 Commits

Reviewing files that changed from the base of the PR and between 25e6f45 and 73ea3a2.

📒 Files selected for processing (3)
  • libcudacxx/include/cuda/std/__ranges/iota_view.h
  • libcudacxx/include/cuda/std/version
  • libcudacxx/test/libcudacxx/std/ranges/range.factories/range.iota.view/indices.pass.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • libcudacxx/include/cuda/std/__ranges/iota_view.h
  • libcudacxx/include/cuda/std/version

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

⏱️ CCCL compile-time benchmark comparison: Public headers compile-time bench

Result: 0 regression row(s), 11 improvement row(s) above threshold.

Run Value
Config public-headers-gcc13
Baseline origin/main
Preset all-dev
Targets cub.headers.base, thrust.cpp.cuda.headers.base, libcudacxx.test.public_headers
GPU / launch args rtx2080 / --cuda 13.3 --host gcc13

Artifacts: reports and traces

TU total compilation

-f total-compilation inclusive --sort total

🟢 TU total compilation — Improvements
Rank Improvement impact Selected Δ Baseline Current Event Matched traces
1 3.044159 -3.044159 13.488601 10.444442 Total Compilation Time: cub/device/device_segmented_sort.cuh 1

Direct file processing

-f file-processing exclusive --sort total

🟢 Direct file processing — Improvements
Rank Improvement impact Selected Δ Baseline Current Event Matched traces
1 1.178625 -1.178625 9.630218 8.451593 Processing Header File: libcudacxx/include/cuda/std/__cccl/prologue.h 550
2 1.004304 -1.004304 20.988506 19.984202 Processing Header File: libcudacxx/include/cuda/__device/physical_device.h 94
3 0.478540 -0.478540 3.417435 2.938895 Processing Header File: libcudacxx/include/cuda/std/__cccl/epilogue.h 550
4 0.435249 -0.435249 11.536714 11.101465 Processing Header File: libcudacxx/include/cuda/std/__type_traits/type_list.h 477
5 0.388171 -0.388171 11.095746 10.707575 Processing Header File: libcudacxx/include/cuda/std/__iterator/concepts.h 437
6 0.326840 -0.326840 6.229877 5.903037 Processing Header File: libcudacxx/include/cuda/std/__tuple_dir/vector_types.h 238
7 0.258641 -0.258641 4.205050 3.946409 Processing Header File: libcudacxx/include/cuda/std/__utility/pair.h 404
8 0.256344 -0.256344 5.771235 5.514891 Processing Header File: libcudacxx/include/cuda/std/__iterator/iterator_traits.h 464
9 0.229500 -0.229500 3.791927 3.562427 Processing Header File: libcudacxx/include/cuda/std/__tuple_dir/tuple.h 243
10 0.203049 -0.203049 7.792895 7.589846 Processing Header File: cub/cub/util_type.cuh 279

@davebayer
davebayer enabled auto-merge (squash) August 7, 2026 07:55
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

😬 CI Workflow Results

🟥 Finished in 4h 27m: Pass: 88%/115 | Total: 4d 09h | Max: 4h 27m | Hits: 43%/1225052

See results here.

AI failure analysis

1. Default-initialized SomeInt array breaks NVCC/MSVC constexpr evaluation · 13 jobs

Explanation: The new `indices.pass.cpp` test fails during `static_assert(test())` in every NVCC/MSVC matrix entry. The compiler cannot treat the synthesized default-constructor closure for the test's uninitialized `cuda::std::array<SomeInt, 5>` as constexpr, preventing all 13 Windows builds from completing.

Evidence:

libcu++ nvcc MSVC / [CTK12.0 MSVC14.39 C++20] Build(amd64), step 4

C:\cccl\libcudacxx\test\libcudacxx\std\ranges\range.factories\range.iota.view\indices.pass.cpp(110): error C2131: expression did not evaluate to a constant
C:/cccl/libcudacxx/include\cuda/std/array(224): note: failure was caused by call of undefined function or one not declared 'constexpr'
C:/cccl/libcudacxx/include\cuda/std/array(224): note: see usage of 'SomeInt::__dflt_ctor_closure'

Root cause: The PR declares `cuda::std::array<SomeInt, 5> v;` inside a function evaluated by `static_assert`. Under every tested NVCC/MSVC combination, that default initialization produces a synthesized `SomeInt::__dflt_ctor_closure` that the compiler cannot evaluate as constexpr; the neighboring integer array is explicitly value-initialized with `{}` and does not fail. Sources: libcudacxx/test/libcudacxx/std/ranges/range.factories/range.iota.view/indices.pass.cpp:90, libcudacxx/test/libcudacxx/std/ranges/range.factories/range.iota.view/indices.pass.cpp:110, libcudacxx/test/libcudacxx/std/ranges/range.factories/range.iota.view/types.h:20.

Suggested next steps: Change the declaration at line 90 to `cuda::std::array<SomeInt, 5> v{};`, then run the focused `indices.pass.cpp` libcudacxx lit test with NVCC/MSVC in C++17 and C++20. Verify at least one oldest and one newest failing toolchain before rerunning the Windows matrix.

Copy this prompt into a coding agent
Repository: https://github.com/NVIDIA/cccl
Workflow run: https://github.com/NVIDIA/cccl/actions/runs/31153186384
Failure group: Default-initialized SomeInt array breaks NVCC/MSVC constexpr evaluation
Affected jobs:
- libcu++ nvcc MSVC / [CTK12.0 MSVC14.39 C++20] Build(amd64): https://github.com/NVIDIA/cccl/actions/runs/31153186384/job/92787164850
- libcu++ nvcc MSVC / [CTK12.9 MSVC14.44 C++20] Build(amd64): https://github.com/NVIDIA/cccl/actions/runs/31153186384/job/92787164885
- libcu++ nvcc MSVC / [CTK13.3 MSVC14.50 C++20] Build(amd64): https://github.com/NVIDIA/cccl/actions/runs/31153186384/job/92787164886
- libcu++ nvcc MSVC / [CTK12.0 MSVC14.39 C++17] Build(amd64): https://github.com/NVIDIA/cccl/actions/runs/31153186384/job/92787164889
- libcu++ nvcc MSVC / [CTK13.3 MSVC14.29 C++17] Build(amd64): https://github.com/NVIDIA/cccl/actions/runs/31153186384/job/92787164914
- libcu++ nvcc MSVC / [CTK12.9 MSVC14.29 C++17] Build(amd64): https://github.com/NVIDIA/cccl/actions/runs/31153186384/job/92787164922
- libcu++ nvcc MSVC / [CTK12.9 MSVC14.44 C++17] Build(amd64): https://github.com/NVIDIA/cccl/actions/runs/31153186384/job/92787164935
- libcu++ nvcc MSVC / [CTK13.3 MSVC14.44 C++20] Build(amd64): https://github.com/NVIDIA/cccl/actions/runs/31153186384/job/92787164936
- libcu++ nvcc MSVC / [CTK13.3 MSVC14.50 C++17] Build(amd64): https://github.com/NVIDIA/cccl/actions/runs/31153186384/job/92787164956
- libcu++ nvcc MSVC / [CTK13.0 MSVC14.44 C++17] Build(amd64): https://github.com/NVIDIA/cccl/actions/runs/31153186384/job/92787164976
- libcu++ nvcc MSVC / [CTK13.0 MSVC14.29 C++17] Build(amd64): https://github.com/NVIDIA/cccl/actions/runs/31153186384/job/92787164982
- libcu++ nvcc MSVC / [CTK13.0 MSVC14.44 C++20] Build(amd64): https://github.com/NVIDIA/cccl/actions/runs/31153186384/job/92787164983
- libcu++ nvcc MSVC / [CTK12.0 MSVC14.29 C++17] Build(amd64): https://github.com/NVIDIA/cccl/actions/runs/31153186384/job/92787164998

Reproduce the NVCC/MSVC failure narrowly for `libcudacxx/test/libcudacxx/std/ranges/range.factories/range.iota.view/indices.pass.cpp`. The failure occurs at `static_assert(test())` because line 90 declares `cuda::std::array<SomeInt, 5> v;`, and NVCC/MSVC reports that `SomeInt::__dflt_ctor_closure` is not constexpr. Implement the minimal fix by changing that declaration to `cuda::std::array<SomeInt, 5> v{};`, matching the value-initialized integer-array test above it. Run the focused lit test in C++17 and C++20 with representative NVCC/MSVC configurations, including an older and newer toolkit/compiler pair; only investigate the `views::indices` implementation if the value-initialization fix does not resolve the constexpr failure.

Jobs:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

[FEA]: P3060R3 Add std::views::indices(n)

2 participants