Skip to content

[FEA]: PoC fancy iterator unpacking facility #11917

Closed
0 of 1 issue completed
Closed

Description

@gevtushenko

Is this a duplicate?

Area

Thrust

Is your feature request related to a problem? Please describe.

We want a prototype for packing and unpacking of fancy iterators into underlying raw pointers.

We want to do this unpacking for zip, but it's out of scope of PoC.

Describe the solution you'd like

This issue can be closed when an implementation-detail helper utility is merged and does the following for transform input and output iterators only:

  • unpacks transform thrust:: and cuda:: iterators into underlying raw pointers recursively
  • unpacking in leaf transform iterators into raw pointers if they wrap raw pointers or contiguous iterators
  • a bool variable template that says if unpacking is possible

Describe alternatives you've considered

No response

Additional context

No response

Sub-issues

Sub-issues

0 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. miscco commented on Oct 9, 2026

    @miscco
    Contributor

    I implemented the iterator unpacking in a branch and made DeviceReduce and DeviceTransform use it. the results are

    Contiguous adaptor unwrap: integer types

    Vectorized loads of a cuda::transform_iterator over a device pointer, compared with the same algorithm on a raw pointer. The new path unwraps the base pointer, vector-loads that storage, and rebases the adaptor so the functor still runs. A raw pointer uses the same load and is retargeted onto the staged values.

    Types are the CCCL integer list: int8_t, int16_t, int32_t, int64_t, and __int128_t (int128_t). The load path depends on the storage size, not the sign, so each unsigned type matches the signed type of the same width.

    DeviceReduce vectorizes only when the stored element is at most 8 bytes, so __int128_t stays on the scalar load. DeviceTransform takes the new vector load only when sizeof(T) * VecSize is a power of two and at most 32 bytes. With the default vector width of 4 elements, __int128_t is 64 bytes and stays on the scalar loop.

    Setup

    • Algorithms: cub::DeviceReduce::Sum and cub::DeviceTransform::Transform
    • Input: raw pointer, or cuda::transform_iterator of that pointer with a same-type + 1 functor. DeviceTransform applies + 1 either in the algorithm (pointer) or in the iterator (adaptor), so both sides do one add
    • Sizes: 2^24 (16,777,216) and 2^28 (268,435,456) elements
    • nvbench cold samples, 6 second timeout per configuration, clocks unlocked
    • Change is (before - after) / before. Positive means the new load is faster. Noise is the larger of the two relative standard deviations
    • GPUs:
      • NVIDIA RTX A6000, sm_86, 768 GB/s bus
      • NVIDIA RTX PRO 6000 Blackwell, sm_120, 1792 GB/s bus

    Findings

    The win is DeviceReduce of a transform iterator on Blackwell, and it shrinks as the element gets wider. __int128_t is unchanged because it is not vectorized.

    Type 2^24 2^28 After matches the pointer
    int8_t +17.0% +9.4% yes (1024 and 1436 GB/s)
    int16_t +7.0% +4.6% yes (1259 and 1512 GB/s)
    int32_t +0.1% +2.6% yes at 2^28 (1566 GB/s)
    int64_t +0.0% +0.0% already matched (1589 GB/s)
    __int128_t −0.0% −0.0% already matched (1607 GB/s)

    The 2^24 int8_t sample has 5.0% noise; 17% is still outside it. The other Blackwell reduction gains above are outside their noise (0.2% to 1.1%).

    On the A6000, only the large int8_t reduction is above noise: +2.8% at 2^28 (noise 1.9%), from 666 GB/s to 686 GB/s, matching the pointer. Wider reductions, including __int128_t, were already at the pointer time (about 710 GB/s at 2^28).

    DeviceTransform does not close a gap for 1- to 8-byte types. Pointer and transform iterator were already within noise of each other on both GPUs, except two A6000 slowdowns:

    • int64_t: −1.6% at 2^24 (noise 0.3%) and −1.4% at 2^28 (noise 1.0%)
    • __int128_t: −1.2% at 2^24 (noise 0.7%) and −1.1% at 2^28 (noise 0.7%)

    __int128_t DeviceTransform of a transform iterator is also far below the pointer on both GPUs, and this change does not move it. On the A6000 it is about 360 GB/s against a pointer at 681 GB/s. On Blackwell it is about 1100 GB/s against a pointer at 1465 GB/s.

    Raw-pointer times do not change on either GPU, for either algorithm.

    DeviceReduce

    Bandwidth counts the input bytes only.

    DeviceReduce measurements

    A6000, raw pointer

    Type Elements Before (µs) After (µs) Change Noise Before (GB/s) After (GB/s)
    int8_t 2^24 35.79 35.80 −0.0% 1.57% 468.7 468.6
    int8_t 2^28 391.20 391.24 −0.0% 1.88% 686.2 686.1
    int16_t 2^24 59.76 59.73 +0.1% 0.88% 561.5 561.7
    int16_t 2^28 767.73 767.85 −0.0% 1.31% 699.3 699.2
    int32_t 2^24 106.79 106.81 −0.0% 0.48% 628.4 628.3
    int32_t 2^28 1520.83 1520.85 −0.0% 0.98% 706.0 706.0
    int64_t 2^24 200.98 200.96 +0.0% 0.56% 667.8 667.9
    int64_t 2^28 3028.31 3028.36 −0.0% 0.69% 709.1 709.1
    __int128_t 2^24 390.31 390.32 −0.0% 0.14% 687.8 687.7
    __int128_t 2^28 6041.65 6041.79 −0.0% 0.61% 710.9 710.9

    A6000, transform iterator

    Type Elements Before (µs) After (µs) Change Noise Before (GB/s) After (GB/s)
    int8_t 2^24 36.12 35.67 +1.2% 1.55% 464.5 470.3
    int8_t 2^28 402.97 391.62 +2.8% 1.86% 666.1 685.5
    int16_t 2^24 59.72 59.58 +0.2% 0.91% 561.9 563.2
    int16_t 2^28 770.21 768.10 +0.3% 1.40% 697.0 699.0
    int32_t 2^24 106.66 106.62 +0.0% 0.51% 629.2 629.4
    int32_t 2^28 1522.95 1521.01 +0.1% 1.01% 705.0 705.9
    int64_t 2^24 200.87 201.07 −0.1% 0.28% 668.2 667.5
    int64_t 2^28 3029.83 3029.44 +0.0% 0.86% 708.8 708.9
    __int128_t 2^24 390.30 390.38 −0.0% 0.15% 687.8 687.6
    __int128_t 2^28 6047.03 6047.72 −0.0% 1.01% 710.3 710.2

    Blackwell, raw pointer

    Type Elements Before (µs) After (µs) Change Noise Before (GB/s) After (GB/s)
    int8_t 2^24 16.39 16.39 +0.0% 0.46% 1023.8 1023.9
    int8_t 2^28 186.69 186.72 −0.0% 0.59% 1437.9 1437.6
    int16_t 2^24 26.64 26.64 +0.0% 0.76% 1259.4 1259.5
    int16_t 2^28 355.16 355.12 +0.0% 0.29% 1511.7 1511.8
    int32_t 2^24 49.16 49.16 −0.0% 0.26% 1365.2 1365.1
    int32_t 2^28 686.73 686.72 +0.0% 0.15% 1563.6 1563.6
    int64_t 2^24 93.26 93.25 +0.0% 1.13% 1439.1 1439.3
    int64_t 2^28 1351.24 1351.41 −0.0% 0.12% 1589.3 1589.1
    __int128_t 2^24 182.50 182.50 +0.0% 0.38% 1470.9 1470.9
    __int128_t 2^28 2672.19 2672.13 +0.0% 0.05% 1607.3 1607.3

    Blackwell, transform iterator

    Type Elements Before (µs) After (µs) Change Noise Before (GB/s) After (GB/s)
    int8_t 2^24 19.73 16.38 +17.0% 5.01% 850.3 1024.0
    int8_t 2^28 206.37 186.92 +9.4% 0.64% 1300.7 1436.1
    int16_t 2^24 28.68 26.66 +7.0% 1.06% 1170.1 1258.8
    int16_t 2^28 372.16 355.04 +4.6% 0.47% 1442.6 1512.1
    int32_t 2^24 49.25 49.19 +0.1% 0.87% 1362.7 1364.2
    int32_t 2^28 703.92 685.62 +2.6% 0.19% 1525.4 1566.1
    int64_t 2^24 93.88 93.84 +0.0% 0.87% 1429.7 1430.3
    int64_t 2^28 1351.07 1350.99 +0.0% 0.13% 1589.5 1589.6
    __int128_t 2^24 182.19 182.20 −0.0% 0.35% 1473.4 1473.3
    __int128_t 2^28 2671.85 2671.97 −0.0% 0.05% 1607.5 1607.4

    DeviceTransform

    Bandwidth counts the input bytes plus the output bytes.

    DeviceTransform measurements

    A6000, raw pointer

    Type Elements Before (µs) After (µs) Change Noise Before (GB/s) After (GB/s)
    int8_t 2^24 53.26 53.30 −0.1% 1.01% 630.0 629.5
    int8_t 2^28 792.22 792.35 −0.0% 1.52% 677.7 677.6
    int16_t 2^24 102.17 102.19 −0.0% 0.62% 656.9 656.7
    int16_t 2^28 1577.27 1577.29 −0.0% 1.09% 680.8 680.8
    int32_t 2^24 200.21 200.25 −0.0% 0.55% 670.4 670.3
    int32_t 2^28 3145.88 3146.66 −0.0% 0.75% 682.6 682.5
    int64_t 2^24 397.62 397.55 +0.0% 0.96% 675.1 675.2
    int64_t 2^28 6293.38 6292.96 +0.0% 0.68% 682.5 682.5
    __int128_t 2^24 788.77 788.84 −0.0% 0.16% 680.6 680.6
    __int128_t 2^28 12584.97 12585.33 −0.0% 0.58% 682.6 682.5

    A6000, transform iterator

    Type Elements Before (µs) After (µs) Change Noise Before (GB/s) After (GB/s)
    int8_t 2^24 53.64 53.86 −0.4% 1.03% 625.5 623.0
    int8_t 2^28 790.75 791.34 −0.1% 1.56% 678.9 678.4
    int16_t 2^24 102.07 102.11 −0.0% 0.56% 657.5 657.2
    int16_t 2^28 1579.42 1580.11 −0.0% 1.08% 679.8 679.5
    int32_t 2^24 200.57 200.59 −0.0% 0.49% 669.2 669.1
    int32_t 2^28 3176.24 3173.32 +0.1% 0.93% 676.1 676.7
    int64_t 2^24 396.46 402.96 −1.6% 0.26% 677.1 666.2
    int64_t 2^28 6295.68 6385.21 −1.4% 1.03% 682.2 672.6
    __int128_t 2^24 1497.47 1515.51 −1.2% 0.65% 358.5 354.3
    __int128_t 2^28 23582.44 23840.76 −1.1% 0.67% 364.3 360.3

    Blackwell, raw pointer

    Type Elements Before (µs) After (µs) Change Noise Before (GB/s) After (GB/s)
    int8_t 2^24 21.85 21.84 +0.1% 4.45% 1535.6 1536.4
    int8_t 2^28 365.90 365.67 +0.1% 0.35% 1467.3 1468.2
    int16_t 2^24 44.37 44.38 −0.0% 2.29% 1512.5 1512.3
    int16_t 2^28 731.70 731.73 −0.0% 0.22% 1467.5 1467.4
    int32_t 2^24 89.51 89.52 −0.0% 1.21% 1499.5 1499.3
    int32_t 2^28 1466.20 1466.48 −0.0% 0.15% 1464.7 1464.4
    int64_t 2^24 182.04 182.08 −0.0% 0.56% 1474.6 1474.3
    int64_t 2^28 2932.48 2932.69 −0.0% 0.11% 1464.6 1464.5
    __int128_t 2^24 365.23 365.23 −0.0% 0.32% 1470.0 1470.0
    __int128_t 2^28 5868.27 5862.12 +0.1% 0.09% 1463.8 1465.3

    Blackwell, transform iterator

    Type Elements Before (µs) After (µs) Change Noise Before (GB/s) After (GB/s)
    int8_t 2^24 20.48 20.49 −0.0% 0.64% 1638.5 1637.8
    int8_t 2^28 364.57 364.30 +0.1% 0.32% 1472.6 1473.7
    int16_t 2^24 42.45 42.31 +0.3% 2.60% 1581.0 1586.0
    int16_t 2^28 730.63 729.87 +0.1% 0.17% 1469.6 1471.1
    int32_t 2^24 89.95 89.69 +0.3% 1.16% 1492.2 1496.4
    int32_t 2^28 1465.09 1464.98 +0.0% 0.14% 1465.8 1465.9
    int64_t 2^24 183.78 182.13 +0.9% 0.63% 1460.6 1473.8
    int64_t 2^28 2928.17 2927.12 +0.0% 0.12% 1466.8 1467.3
    __int128_t 2^24 504.81 504.67 +0.0% 0.38% 1063.5 1063.8
    __int128_t 2^28 7823.89 7828.97 −0.1% 0.12% 1097.9 1097.2
  2. miscco commented on Oct 9, 2026

    @miscco
    Contributor

    Blackwell DeviceTransform with ublockcopy

    The tables above keep the vectorized load for a transform iterator. This run selects ublockcopy for that iterator on the Blackwell GPU. A raw pointer was already on ublockcopy, so its column is a rerun of the same path. Positive means this run is faster. Same sizes, cold GPU time, 6 second timeout, clocks unlocked. The stopping rule is nvbench's entropy criterion.

    The __int128_t transform iterator is the change. It now matches the pointer. The other outside-noise movements are the noisy int16_t 2^24 samples (pointer +5.4%, iterator −4.2%, noise about 3%) and a few 2^28 samples under 0.5%.

    Blackwell ublockcopy measurements

    Raw pointer

    Type Elements Previous (µs) Ublockcopy (µs) Change Noise Previous (GB/s) Ublockcopy (GB/s)
    int8_t 2^24 21.84 21.90 −0.3% 4.46% 1536.4 1531.8
    int8_t 2^28 365.67 365.71 −0.0% 0.35% 1468.2 1468.0
    int16_t 2^24 44.38 42.00 +5.4% 2.87% 1512.3 1598.0
    int16_t 2^28 731.73 733.81 −0.3% 0.22% 1467.4 1463.2
    int32_t 2^24 89.52 89.54 −0.0% 1.21% 1499.3 1499.0
    int32_t 2^28 1466.48 1466.15 +0.0% 0.15% 1464.4 1464.7
    int64_t 2^24 182.08 181.01 +0.6% 0.67% 1474.3 1483.0
    int64_t 2^28 2932.69 2933.86 −0.0% 0.12% 1464.5 1463.9
    __int128_t 2^24 365.23 365.23 −0.0% 0.32% 1470.0 1469.9
    __int128_t 2^28 5862.12 5867.49 −0.1% 0.10% 1465.3 1464.0

    Transform iterator

    Type Elements Vectorized (µs) Ublockcopy (µs) Change Noise Vectorized (GB/s) Ublockcopy (GB/s)
    int8_t 2^24 20.49 20.45 +0.2% 0.63% 1637.8 1640.5
    int8_t 2^28 364.30 365.88 −0.4% 0.32% 1473.7 1467.3
    int16_t 2^24 42.31 44.07 −4.2% 2.60% 1586.0 1522.7
    int16_t 2^28 729.87 732.99 −0.4% 0.22% 1471.1 1464.9
    int32_t 2^24 89.69 88.95 +0.8% 1.24% 1496.4 1508.9
    int32_t 2^28 1464.98 1466.91 −0.1% 0.15% 1465.9 1463.9
    int64_t 2^24 182.13 181.39 +0.4% 0.66% 1473.8 1479.9
    int64_t 2^28 2927.12 2932.20 −0.2% 0.12% 1467.3 1464.8
    __int128_t 2^24 504.67 365.10 +27.7% 0.34% 1063.8 1470.5
    __int128_t 2^28 7828.97 5868.14 +25.0% 0.09% 1097.2 1463.8
  3. miscco commented on Oct 9, 2026

    @miscco
    Contributor

    DeviceScan segment reset

    Same cold-sample setup as the example in #11840: entropy stopping, 6 second timeout, clocks unlocked. Sizes are 2^20, 2^24, 2^28, and 2^31. Bandwidth is the bytes that configuration actually moves. For int8_t that is 2 bytes per element on both sides, so the time gap is the comparison. For wider T the iterator side reads the symbol and writes uint8_t, and the time gap is the extra traffic. A positive gap means the iterator scan was faster. Noise is the larger relative standard deviation of the two GPU times. A 2^20 run is launch overhead on both GPUs.

    Performance analysis

    The int8_t case is the direct comparison with issue 11840 because both paths move one input byte and one output byte per element. On Blackwell, the original fancy-iterator path was slower than the pointer path by 34.4% at 2^24, 8.0% at 2^28, and 3.4% at 2^31. After enabling lookahead for the adaptors, those gaps are 5.6%, 0.04%, and 0.04%, respectively. The 2^28 and 2^31 iterator times now match the pointer within noise. The remaining 2^24 difference is slightly outside noise (5.6% versus 4.3%); it is much smaller than the original gap but is not fully closed.

    The absolute Blackwell iterator time improves against the original issue measurement from 32.36 to 24.67 µs at 2^24 (23.8%), from 392.18 to 363.57 µs at 2^28 (7.3%), and from 2.996 to 2.898 ms at 2^31 (3.3%). The pointer measurements at 2^28 and 2^31 are effectively unchanged, so the convergence comes from accelerating the iterator path rather than slowing the baseline. The 2^20 result is launch-bound and does not show a useful change.

    For wider input types, elapsed time alone is not an iterator-overhead comparison: the pointer baseline always transfers 2 bytes per element, while the iterator transfers sizeof(T) + 1. If both paths have the same memory efficiency, their expected time ratios are therefore 1.5× for int16_t, 2.5× for int32_t, 4.5× for int64_t, and 8.5× for __int128_t.

    At 2^31 on Blackwell, the measured ratios are 1.46×, 2.37×, 4.62×, and 8.94×. Equivalently, iterator bandwidth is 103%, 106%, 97%, and 95% of pointer bandwidth. This is close to traffic scaling across all widths: rebasing and applying the input/output functors adds little cost once the scan is bandwidth-bound. __int128_t has the largest residual, about 5%, after the lookahead tile is reduced to fit its 16-byte input storage in shared memory.

    The A6000 uses classic lookback rather than the new lookahead adaptor path. Its int8_t pointer and iterator times remain equal within noise, confirming that iterator dispatch itself has no material penalty there. Wider iterator cases report 1.20× to 1.39× the pointer bandwidth at 2^31. That does not make them faster in elapsed time: the wider cases still transfer 1.5× to 8.5× more data. It shows that the 1-byte pointer scan underutilizes memory bandwidth and that wider accesses amortize the lookback scan's fixed per-item work more effectively.

    DeviceScan measurements

    Blackwell, lookahead

    Type Elements Pointer (µs) Iterator (µs) Gap Noise Pointer (GB/s) Iterator (GB/s)
    int8_t 2^20 8.19 8.18 +0.2% 0.22% 256.0 256.4
    int8_t 2^24 23.36 24.67 −5.6% 4.34% 1436.5 1360.2
    int8_t 2^28 363.43 363.57 −0.0% 0.58% 1477.2 1476.7
    int8_t 2^31 2897.46 2898.48 −0.0% 0.13% 1482.3 1481.8
    int16_t 2^20 6.15 10.21 −66.1% 2.31% 341.1 308.1
    int16_t 2^24 23.32 35.72 −53.2% 4.28% 1439.0 1409.1
    int16_t 2^28 363.13 532.96 −46.8% 0.52% 1478.4 1511.0
    int16_t 2^31 2899.15 4225.13 −45.7% 0.12% 1481.5 1524.8
    int32_t 2^20 8.19 10.24 −25.1% 0.21% 256.1 512.0
    int32_t 2^24 23.82 58.98 −147.6% 4.16% 1408.8 1422.3
    int32_t 2^28 363.65 870.59 −139.4% 0.54% 1476.3 1541.7
    int32_t 2^31 2898.81 6862.16 −136.7% 0.20% 1481.6 1564.7
    int64_t 2^20 8.19 12.79 −56.1% 6.93% 256.0 738.0
    int64_t 2^24 23.26 104.96 −351.2% 4.24% 1442.5 1438.5
    int64_t 2^28 363.45 1622.14 −346.3% 2.25% 1477.2 1489.3
    int64_t 2^31 2897.53 13395.71 −362.3% 2.01% 1482.3 1442.8
    __int128_t 2^20 8.19 17.22 −110.2% 6.59% 256.0 1035.1
    __int128_t 2^24 24.08 198.69 −725.2% 3.65% 1393.6 1435.5
    __int128_t 2^28 363.19 3150.16 −767.4% 2.24% 1478.2 1448.6
    __int128_t 2^31 2897.66 25908.94 −794.1% 1.22% 1482.2 1409.1

    A6000, classic lookback

    Type Elements Pointer (µs) Iterator (µs) Gap Noise Pointer (GB/s) Iterator (GB/s)
    int8_t 2^20 12.12 11.98 +1.1% 4.69% 173.1 175.0
    int8_t 2^24 70.55 70.68 −0.2% 1.69% 475.6 474.8
    int8_t 2^28 1038.57 1036.57 +0.2% 1.36% 516.9 517.9
    int8_t 2^31 8296.11 8355.27 −0.7% 0.68% 517.7 514.0
    int16_t 2^20 11.48 12.48 −8.7% 5.31% 182.6 252.0
    int16_t 2^24 77.64 89.00 −14.6% 2.31% 432.2 565.5
    int16_t 2^28 1041.08 1299.73 −24.8% 0.74% 515.7 619.6
    int16_t 2^31 8365.15 10407.90 −24.4% 0.72% 513.4 619.0
    int32_t 2^20 11.59 16.38 −41.3% 5.07% 180.9 320.1
    int32_t 2^24 76.56 135.50 −77.0% 2.37% 438.3 619.1
    int32_t 2^28 1048.97 1961.99 −87.0% 0.60% 511.8 684.1
    int32_t 2^31 8432.25 15687.68 −86.0% 1.14% 509.4 684.4
    int64_t 2^20 11.67 24.75 −112.1% 5.68% 179.7 381.3
    int64_t 2^24 71.43 238.11 −233.3% 2.40% 469.7 634.1
    int64_t 2^28 1055.85 3465.17 −228.2% 1.32% 508.5 697.2
    int64_t 2^31 8500.10 27713.24 −226.0% 1.46% 505.3 697.4
    __int128_t 2^20 11.68 40.05 −243.0% 4.83% 179.6 445.1
    __int128_t 2^24 78.85 441.05 −459.4% 1.93% 425.6 646.7
    __int128_t 2^28 1072.11 6552.44 −511.2% 1.81% 500.8 696.4
    __int128_t 2^31 8535.71 52215.94 −511.7% 0.34% 503.2 699.2
  4. moved this from Todo to In Progress in CCCLon Oct 27, 2026
  5. bernhardmgruber commented on Nov 3, 2026

    @bernhardmgruber
    Contributor

    a bool variable template that says if unpacking is possible

    I don't think, we will need that. We just unpack and rebase iterators, where these operations for contiguous iterators are just identity operations.

  6. moved this from In Progress to In Review in CCCLon Nov 10, 2026
  7. moved this from In Review to Done in CCCLon Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions