Repository navigation
Host incrementable iterator approach 2 - #4697
Merged
oleksandr-pavlyk merged 26 commits intoMay 20, 2025
Merged
oleksandr-pavlyk merged 26 commits into
oleksandr-pavlyk merged 26 commits into
Conversation
Contributor
🟨 CI finished in 15m 26s: Pass: 80%/5 | Total: 40m 25s | Avg: 8m 05s | Max: 15m 19s | Hits: 96%/326
|
| Project | |
|---|---|
| CCCL Infrastructure | |
| libcu++ | |
| CUB | |
| Thrust | |
| CUDA Experimental | |
| stdpar | |
| +/- | python |
| +/- | CCCL C Parallel Library |
| Catch2Helper |
Modifications in project or dependencies?
| Project | |
|---|---|
| CCCL Infrastructure | |
| libcu++ | |
| CUB | |
| Thrust | |
| CUDA Experimental | |
| stdpar | |
| +/- | python |
| +/- | CCCL C Parallel Library |
| Catch2Helper |
🏃 Runner counts (total jobs: 5)
| # | Runner |
|---|---|
| 4 | linux-amd64-gpu-rtx2080-latest-1 |
| 1 | linux-amd64-cpu16 |
The test cooks input sequence in the form of F(i+1) - F(i) for
0 <= i < num_segments * segment_size.
Fixed-size segmented reduction is expected to to be
[ F(segment_size * (k + 1)) - F(segment_size * k) for
k in range(num_segments) ]
All operations (addition (+), inversion (-)) are assumed to take
place in a ring.
In this test the ring is a cycling ring of integers modulo 7.
F(i) = g(i) * g(i+1) % 7, where g: i -> (i % 5 + i % 3).
Note that `my_add` computes addition modulo 7 too.
Choice of moduli 3, 5, 7 is arbitrary and may be changed. The test
is expected to pass so long as they are changed consistently throughout
the test.
This example computes segmented reduce of input constant iterator of int8(1) values. The offsets iterators are crafted to that segment lengths are 1, 2, ..., (p - 2), (p - 1), 1, 2, ..., (p - 2), (p - 1), 1, ... The expected sums would equal these lengths. The example is run for (2**15 + 2**3) * 2**16 number of segments which is INT_MAX and about 2**19 elements. 1. Input iterator changed to have type int16 2. Initial value changed to have type int16 3. Changed range of change of segments from [1, p] to [m0, m0 + p) and set m0, p as they are set in native test. Specifically, m0, p = 265, 163 This means segment sizes vary from 265 elements to 428 elements, which is an improvement over previous situation where it was varying from 1 to 113 elements (and most threads in a 256-string block were unused).
… null This ensures meaningful prescriptive cerr output.
…state and advance cvalue. We rely on cvalue being a ctype for which __add__ is defined
For IteratorBase it is defined as None For concrete iterators, it is defined as input_iterators, except for transform iterator, where host_advance does not involve numba-cuda compiled object.
… offset iterators This is done during build step irrespective of the input size, but it should perhaps be done as needed the first time num_segments > INT_MAX is encountered. TBD
The host_advance function is now generated and set during segmented_reduce build step.
Validation is now performed by constructing an iterator yielding expected result. The allocating fixed size uint8 buffer and running binary transform to compare actual to expected and write result of comparison to the validation buffer. We then use `cp.all(validation.view(cp.bool_))` to validate this chunk, and move to the next.
oleksandr-pavlyk
force-pushed
the
host-incrementable-iterator-approach-2
branch
from
May 14, 2025 20:54
1ea66c9 to
aa62806
Compare
Contributor
🟨 CI finished in 17m 11s: Pass: 80%/5 | Total: 46m 04s | Avg: 9m 12s | Max: 16m 29s | Hits: 90%/326
|
| Project | |
|---|---|
| CCCL Infrastructure | |
| libcu++ | |
| CUB | |
| Thrust | |
| CUDA Experimental | |
| stdpar | |
| +/- | python |
| +/- | CCCL C Parallel Library |
| Catch2Helper |
Modifications in project or dependencies?
| Project | |
|---|---|
| CCCL Infrastructure | |
| libcu++ | |
| CUB | |
| Thrust | |
| CUDA Experimental | |
| stdpar | |
| +/- | python |
| +/- | CCCL C Parallel Library |
| Catch2Helper |
🏃 Runner counts (total jobs: 5)
| # | Runner |
|---|---|
| 4 | linux-amd64-gpu-rtx2080-latest-1 |
| 1 | linux-amd64-cpu16 |
gevtushenko
approved these changes
May 15, 2025
rwgk
approved these changes
May 16, 2025
rwgk
left a comment
Contributor
There was a problem hiding this comment.
LGTM — High-level review only. There are many details that would take me a significant amount of time to understand fully. I read through all diffs, nothing stood out to me, this PR looks great.
Contributor
🟨 CI finished in 2h 07m: Pass: 98%/187 | Total: 3d 13h | Avg: 27m 31s | Max: 1h 31m | Hits: 69%/283143
|
| Project | |
|---|---|
| +/- | CCCL Infrastructure |
| libcu++ | |
| CUB | |
| Thrust | |
| CUDA Experimental | |
| stdpar | |
| +/- | python |
| +/- | CCCL C Parallel Library |
| Catch2Helper |
Modifications in project or dependencies?
| Project | |
|---|---|
| +/- | CCCL Infrastructure |
| +/- | libcu++ |
| +/- | CUB |
| +/- | Thrust |
| +/- | CUDA Experimental |
| +/- | stdpar |
| +/- | python |
| +/- | CCCL C Parallel Library |
| +/- | Catch2Helper |
🏃 Runner counts (total jobs: 187)
| # | Runner |
|---|---|
| 129 | linux-amd64-cpu16 |
| 15 | windows-amd64-cpu16 |
| 12 | linux-arm64-cpu16 |
| 12 | linux-amd64-gpu-rtxa6000-latest-1 |
| 11 | linux-amd64-gpu-rtx2080-latest-1 |
| 5 | linux-amd64-gpu-h100-latest-1 |
| 3 | linux-amd64-gpu-rtx4090-latest-1 |
bernhardmgruber
approved these changes
May 20, 2025
oleksandr-pavlyk
enabled auto-merge (squash)
May 20, 2025 15:06
Contributor
🟩 CI finished in 5h 40m: Pass: 100%/187 | Total: 1d 09h | Avg: 10m 39s | Max: 59m 45s | Hits: 96%/283143
|
| Project | |
|---|---|
| +/- | CCCL Infrastructure |
| libcu++ | |
| CUB | |
| Thrust | |
| CUDA Experimental | |
| stdpar | |
| +/- | python |
| +/- | CCCL C Parallel Library |
| Catch2Helper |
Modifications in project or dependencies?
| Project | |
|---|---|
| +/- | CCCL Infrastructure |
| +/- | libcu++ |
| +/- | CUB |
| +/- | Thrust |
| +/- | CUDA Experimental |
| +/- | stdpar |
| +/- | python |
| +/- | CCCL C Parallel Library |
| +/- | Catch2Helper |
🏃 Runner counts (total jobs: 187)
| # | Runner |
|---|---|
| 129 | linux-amd64-cpu16 |
| 15 | windows-amd64-cpu16 |
| 12 | linux-arm64-cpu16 |
| 12 | linux-amd64-gpu-rtxa6000-latest-1 |
| 11 | linux-amd64-gpu-rtx2080-latest-1 |
| 5 | linux-amd64-gpu-h100-latest-1 |
| 3 | linux-amd64-gpu-rtx4090-latest-1 |
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
closes gh-4148
This PR implements approach 2 from gh-4148, where user-provided host-increment function is used, when necessary, to increment iterator from host for algorithms that support large input sizes via streaming approach.
c/parallelThis PR extends
cccl_iterator_twith a function pointervoid (*)(void *, cccl_increment_t), where the latter is a union of signed and unsigned 64-bit integers:Furthermore,
indirect_iterator_tclass is introduced in"indirect_args.h"which implements__host__ void operator+=(U offset), for integral 64-bit increment typeU.The operator throws if the function pointer is null.
indirect_iterator_tcan be constructed fromcccl_iterator_tinstance only. Instances of typeindirect_iterator_tare intended to be used in calls to CUB device-wide algorithms for iterators that may need to be incremented on the host, e.g.,DeviceSegmentedReducealgorithm.This PR uses
indirect_iterator_tinDeviceSegmentedReduceto supportuint64_t num_segmentswhose value exceeds INT_MAX. It is used for thed_output,start_offsets_inandend_offsets_inarguments.A test is added to
c/parallel/test/test_segmented_reduce.cppto exercise a non-trivial largenum_segmentscall. All inputs are provided as iterators to save device memory. Validation is performed usingdevice_reducecall over and iterator that compares segmented reduce result to expected value and reducing using logical_and.pythonBindings is modified so that
_bindings.Iteratorconstructor acquireshost_advance_fn=Nonekeyword argument as well ashost_advance_fnproperty with setter/getter.The host advance function can only be set for iterators of kind
ITERATORand has no effect for iterators of kindPOINTER. Support values forhost_advance_fnareNoneint: a function pointer reinterpreted asuintptr_tctypes.c_void_p: a function pointer cast tovoid *ctypes.CFuncPtr: ctypes object representing C callable (produced by numba)"void (void *, cccl_increment_t)"whosevoid *payload is understood as a function pointerSupport for the latter type aims to support Python capsules produced by Cython CAPI. For example, see https://gist.github.com/oleksandr-pavlyk/75d5b78c5a006a34e5d97578267c8616
Two tests are added to verify correctness for
num_segments > INT_MAX.Create transform iterator over counting iterator and transformation
k -> F(k+1) - F(k) % 7for some functionF. Set up start and end offsets for offsets of fixed size. Perform segmented reduce usingdef _add(a, b): return (a + b) % 7. Validate result against expectedF(end_offset[k] + 1) - F(start_offset[k])) % 7for segmentk.For input which is constant iterator of value 1, and offset iterator crafted to point to start of offsets of length
min + (k % p)for segmentk, computesegmened_reduceusing ordinary plus. Expected reduced values aremin + (k % p)for segmentk.Checklist