Skip to content

Implement parallel cuda::std::swap_ranges - #8257

Merged
miscco merged 2 commits into
NVIDIA:mainfrom
miscco:parallel_swap_ranges
Apr 2, 2026
Merged

miscco merged 2 commits into
NVIDIA:mainfrom
miscco:parallel_swap_ranges

Conversation

@miscco

@miscco miscco commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

This implements the swap_ranges algorithm for the cuda backend.

It provides tests and benchmarks similar to Thrust and some boilerplate for libcu++

The functionality is publicly available yet and implemented in a private internal header

Fixes #7747

@miscco
miscco requested review from a team as code owners April 1, 2026 10:51
@miscco
miscco requested a review from shwina April 1, 2026 10:51
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Apr 1, 2026
@miscco
miscco requested a review from pciolkosz April 1, 2026 10:52
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Apr 1, 2026
@miscco

miscco commented Apr 1, 2026

Copy link
Copy Markdown
Contributor Author

Benchmarks look ok:

['thrust_swap_ranges.json', 'pstl_swap_ranges.json']
# base

## [1] NVIDIA RTX A6000

|  T{ct}  |  Elements  |   Ref Time |   Ref Noise |   Cmp Time |   Cmp Noise |      Diff |   %Diff |  Status  |
|---------|------------|------------|-------------|------------|-------------|-----------|---------|----------|
|   I8    |    2^16    |   7.540 us |      11.74% |   7.484 us |      10.58% | -0.056 us |  -0.75% |   SAME   |
|   I8    |    2^20    |  14.332 us |       4.03% |  14.347 us |       6.67% |  0.014 us |   0.10% |   SAME   |
|   I8    |    2^24    | 113.753 us |       0.60% | 114.619 us |       0.65% |  0.865 us |   0.76% |   SLOW   |
|   I8    |    2^28    |   1.674 ms |       2.10% |   1.690 ms |       1.84% | 15.965 us |   0.95% |   SAME   |
|   I16   |    2^16    |   7.885 us |      10.82% |   7.831 us |       7.23% | -0.054 us |  -0.69% |   SAME   |
|   I16   |    2^20    |  19.354 us |       2.94% |  19.483 us |       6.83% |  0.129 us |   0.67% |   SAME   |
|   I16   |    2^24    | 203.542 us |       0.51% | 203.828 us |       0.72% |  0.286 us |   0.14% |   SAME   |
|   I16   |    2^28    |   3.163 ms |       1.64% |   3.163 ms |       1.64% |  0.116 us |   0.00% |   SAME   |
|   I32   |    2^16    |   8.378 us |      17.30% |   8.334 us |       5.27% | -0.044 us |  -0.53% |   SAME   |
|   I32   |    2^20    |  31.809 us |       3.45% |  31.760 us |       3.05% | -0.049 us |  -0.15% |   SAME   |
|   I32   |    2^24    | 400.522 us |       0.25% | 400.487 us |       0.22% | -0.035 us |  -0.01% |   SAME   |
|   I32   |    2^28    |   6.307 ms |       0.93% |   6.309 ms |       1.08% |  2.184 us |   0.03% |   SAME   |
|   I64   |    2^16    |   9.802 us |       8.10% |   9.890 us |      15.80% |  0.088 us |   0.90% |   SAME   |
|   I64   |    2^20    |  57.458 us |       8.34% |  57.258 us |       2.23% | -0.199 us |  -0.35% |   SAME   |
|   I64   |    2^24    | 794.268 us |       0.20% | 794.064 us |       0.20% | -0.205 us |  -0.03% |   SAME   |
|   I64   |    2^28    |  12.635 ms |       0.50% |  12.634 ms |       0.57% | -1.348 us |  -0.01% |   SAME   |
|  I128   |    2^16    |  12.253 us |       3.71% |  12.285 us |       4.00% |  0.032 us |   0.26% |   SAME   |
|  I128   |    2^20    | 110.596 us |       1.55% | 111.054 us |       0.95% |  0.458 us |   0.41% |   SAME   |
|  I128   |    2^24    |   1.583 ms |       0.17% |   1.583 ms |       0.17% |  0.208 us |   0.01% |   SAME   |
|  I128   |    2^28    |  25.300 ms |       0.31% |  25.311 ms |       0.31% | 11.136 us |   0.04% |   SAME   |
|   F32   |    2^16    |   8.291 us |       5.35% |   8.341 us |       5.11% |  0.050 us |   0.60% |   SAME   |
|   F32   |    2^20    |  32.558 us |       2.35% |  32.433 us |       1.77% | -0.125 us |  -0.38% |   SAME   |
|   F32   |    2^24    | 410.493 us |       3.10% | 410.818 us |       3.06% |  0.325 us |   0.08% |   SAME   |
|   F32   |    2^28    |   6.307 ms |       0.96% |   6.307 ms |       0.97% | -0.175 us |  -0.00% |   SAME   |
|   F64   |    2^16    |   9.776 us |       7.40% |   9.817 us |       5.19% |  0.041 us |   0.42% |   SAME   |
|   F64   |    2^20    |  56.889 us |       1.99% |  56.999 us |       2.09% |  0.111 us |   0.19% |   SAME   |
|   F64   |    2^24    | 794.077 us |       0.20% | 794.186 us |       0.18% |  0.109 us |   0.01% |   SAME   |
|   F64   |    2^28    |  12.634 ms |       0.53% |  12.633 ms |       0.50% | -1.147 us |  -0.01% |   SAME   |

# with_iter_swap

## [1] NVIDIA RTX A6000

|  T{ct}  |  Elements  |   Ref Time |   Ref Noise |   Cmp Time |   Cmp Noise |      Diff |   %Diff |  Status  |
|---------|------------|------------|-------------|------------|-------------|-----------|---------|----------|
|   I8    |    2^16    |   7.775 us |       6.44% |   7.688 us |       6.51% | -0.087 us |  -1.12% |   SAME   |
|   I8    |    2^20    |  15.728 us |       5.42% |  15.558 us |       5.02% | -0.170 us |  -1.08% |   SAME   |
|   I8    |    2^24    | 137.876 us |       3.34% | 136.965 us |       3.19% | -0.911 us |  -0.66% |   SAME   |
|   I8    |    2^28    |   2.104 ms |       1.40% |   2.098 ms |       1.41% | -5.867 us |  -0.28% |   SAME   |
|   I16   |    2^16    |   7.977 us |       5.22% |   7.976 us |       5.62% | -0.001 us |  -0.01% |   SAME   |
|   I16   |    2^20    |  22.524 us |       4.93% |  22.373 us |       4.45% | -0.151 us |  -0.67% |   SAME   |
|   I16   |    2^24    | 248.232 us |       2.25% | 247.447 us |       2.11% | -0.785 us |  -0.32% |   SAME   |
|   I16   |    2^28    |   3.628 ms |       1.25% |   3.624 ms |       1.34% | -4.417 us |  -0.12% |   SAME   |
|   I32   |    2^16    |   8.438 us |       5.19% |   8.526 us |      18.28% |  0.088 us |   1.04% |   SAME   |
|   I32   |    2^20    |  32.811 us |       2.44% |  32.781 us |       4.06% | -0.031 us |  -0.09% |   SAME   |
|   I32   |    2^24    | 401.790 us |       0.34% | 401.867 us |       0.35% |  0.076 us |   0.02% |   SAME   |
|   I32   |    2^28    |   6.348 ms |       1.04% |   6.349 ms |       1.03% |  0.574 us |   0.01% |   SAME   |
|   I64   |    2^16    |   9.943 us |       5.53% |   9.994 us |      13.52% |  0.051 us |   0.52% |   SAME   |
|   I64   |    2^20    |  58.191 us |       2.18% |  57.978 us |       2.07% | -0.214 us |  -0.37% |   SAME   |
|   I64   |    2^24    | 797.162 us |       0.16% | 797.343 us |       0.17% |  0.180 us |   0.02% |   SAME   |
|   I64   |    2^28    |  12.612 ms |       0.55% |  12.615 ms |       0.65% |  2.460 us |   0.02% |   SAME   |
|  I128   |    2^16    |  12.794 us |       9.59% |  12.858 us |       5.62% |  0.064 us |   0.50% |   SAME   |
|  I128   |    2^20    | 114.186 us |       1.01% | 111.457 us |       2.70% | -2.729 us |  -2.39% |   FAST   |
|  I128   |    2^24    |   1.651 ms |       0.16% |   1.654 ms |       0.16% |  2.865 us |   0.17% |   SLOW   |
|  I128   |    2^28    |  26.354 ms |       0.30% |  26.389 ms |       0.30% | 35.222 us |   0.13% |   SAME   |
|   F32   |    2^16    |   8.391 us |       6.80% |   8.407 us |       5.58% |  0.016 us |   0.19% |   SAME   |
|   F32   |    2^20    |  33.658 us |       1.59% |  33.788 us |       2.00% |  0.130 us |   0.39% |   SAME   |
|   F32   |    2^24    | 412.807 us |       3.09% | 412.330 us |       3.06% | -0.477 us |  -0.12% |   SAME   |
|   F32   |    2^28    |   6.346 ms |       1.06% |   6.346 ms |       1.06% |  0.063 us |   0.00% |   SAME   |
|   F64   |    2^16    |  10.044 us |      12.93% |  10.012 us |       8.73% | -0.032 us |  -0.32% |   SAME   |
|   F64   |    2^20    |  58.355 us |       2.35% |  57.445 us |       1.13% | -0.910 us |  -1.56% |   FAST   |
|   F64   |    2^24    | 797.157 us |       0.16% | 797.276 us |       0.16% |  0.119 us |   0.01% |   SAME   |
|   F64   |    2^28    |  12.614 ms |       0.64% |  12.612 ms |       0.57% | -2.078 us |  -0.02% |   SAME   |

@github-actions

This comment has been minimized.

CHECK(res == nullptr);
}

{ // With contiguous 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.

Consider adding tests for only forward-iterators here as well.

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.

The cuda backend only supported random access

@github-actions

This comment has been minimized.

miscco added 2 commits April 2, 2026 08:42
This implements the `swap_ranges` algorithm for the cuda backend.

* std::swap_ranges see https://en.cppreference.com/w/cpp/algorithm/swap_ranges.html

It provides tests and benchmarks similar to Thrust and some boilerplate for libcu++

The functionality is publicly available yet and implemented in a private internal header

Fixes NVIDIA#7747
@miscco
miscco force-pushed the parallel_swap_ranges branch from 89a3dfe to a54fb61 Compare April 2, 2026 06:49
@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 44m: Pass: 100%/103 | Total: 2d 22h | Max: 1h 56m | Hits: 73%/276827

See results here.

@miscco
miscco merged commit 01dcdfb into NVIDIA:main Apr 2, 2026
119 of 121 checks passed
@miscco
miscco deleted the parallel_swap_ranges branch April 2, 2026 09:38
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Apr 2, 2026
gonidelis pushed a commit to gonidelis/cccl that referenced this pull request Apr 8, 2026
* Implement parallel `cuda::std::swap_ranges`

This implements the `swap_ranges` algorithm for the cuda backend.

* std::swap_ranges see https://en.cppreference.com/w/cpp/algorithm/swap_ranges.html

It provides tests and benchmarks similar to Thrust and some boilerplate for libcu++

The functionality is publicly available yet and implemented in a private internal header

Fixes NVIDIA#7747

* Address review comments
jainishmehta pushed a commit to jainishmehta/cccl that referenced this pull request Apr 19, 2026
* Implement parallel `cuda::std::swap_ranges`

This implements the `swap_ranges` algorithm for the cuda backend.

* std::swap_ranges see https://en.cppreference.com/w/cpp/algorithm/swap_ranges.html

It provides tests and benchmarks similar to Thrust and some boilerplate for libcu++

The functionality is publicly available yet and implemented in a private internal header

Fixes NVIDIA#7747

* Address review comments
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.

[FEA]: Implement CUDA backend for parallel cuda::std::swap_ranges

3 participants