Skip to content

Make transform iterator utility in c parallel test suite - #4645

Merged
oleksandr-pavlyk merged 4 commits into
NVIDIA:mainfrom
oleksandr-pavlyk:make-transform-iterator-utility-in-c-paralle-test-suite
May 9, 2025
Merged

oleksandr-pavlyk merged 4 commits into
NVIDIA:mainfrom
oleksandr-pavlyk:make-transform-iterator-utility-in-c-paralle-test-suite

Conversation

@oleksandr-pavlyk

@oleksandr-pavlyk oleksandr-pavlyk commented May 6, 2025 •

Copy link
Copy Markdown
Contributor

Description

closes #4643
closes #4644

This PR build on top of #4609 and should only be merged after #4609 is merged. UPD: The PR has been rebased since #4609 has been merged.

Summary of changes:

  1. Utilities such as make_operator and make_iterator now support arguments of type std::string_view and const char * (thanks @ericniebler for helping me streamline my clunky implementation)
  2. Introduce utilities to obtain source strings defining iterator state, iterator's advance function and iterator's dereference function.
  3. Modified make_counting_iterator and others to use code-definition generation utilities,
  4. Modified iterator_t to add member std::string state_name, and modified make_iterator utility to accept state_name argument in addition to state_def_src.
  5. Introduce simple struct name_source_t to bind entity name and its code definition
  6. Introduce make_stateful_transform_iterator and make_stateless_transform_iterator which take name/source pairs for base iterator state, base iterator advance function, base iterator dereference function, as well as for transform operator state, transform operator implementation function.
  7. Modified "test_segmented_reduce.cpp" to use new iterator utilities.
  8. Add a test to "test_segmented_reduce.cpp" that uses make_stateful_transformed_iterator that is ready to test implementation of host-streaming approach to support num_segments that exceed INT_MAX value.

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@oleksandr-pavlyk
oleksandr-pavlyk requested a review from a team as a code owner May 6, 2025 14:57
@oleksandr-pavlyk
oleksandr-pavlyk requested a review from wmaxey May 6, 2025 14:57
@github-project-automation github-project-automation Bot moved this to Todo in CCCL May 6, 2025
@oleksandr-pavlyk oleksandr-pavlyk self-assigned this May 6, 2025
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL May 6, 2025
@github-actions

github-actions Bot commented May 6, 2025

Copy link
Copy Markdown
Contributor
🟩 CI finished in 1h 57m: Pass: 100%/5 | Total: 44m 17s | Avg: 8m 51s | Max: 21m 33s | Hits: 98%/326
  • 🟩 python: Pass: 100%/3 | Total: 31m 00s | Avg: 10m 20s | Max: 21m 33s

    🟩 cpu
      🟩 amd64              Pass: 100%/3   | Total: 31m 00s | Avg: 10m 20s | Max: 21m 33s
    🟩 ctk
      🟩 12.8               Pass: 100%/3   | Total: 31m 00s | Avg: 10m 20s | Max: 21m 33s
    🟩 cudacxx
      🟩 nvcc12.8           Pass: 100%/3   | Total: 31m 00s | Avg: 10m 20s | Max: 21m 33s
    🟩 cudacxx_family
      🟩 nvcc               Pass: 100%/3   | Total: 31m 00s | Avg: 10m 20s | Max: 21m 33s
    🟩 cxx
      🟩 GCC13              Pass: 100%/3   | Total: 31m 00s | Avg: 10m 20s | Max: 21m 33s
    🟩 cxx_family
      🟩 GCC                Pass: 100%/3   | Total: 31m 00s | Avg: 10m 20s | Max: 21m 33s
    🟩 gpu
      🟩 rtx2080            Pass: 100%/3   | Total: 31m 00s | Avg: 10m 20s | Max: 21m 33s
    🟩 jobs
      🟩 cuda.cccl          Pass: 100%/1   | Total:  2m 43s | Avg:  2m 43s | Max:  2m 43s
      🟩 cuda.cooperative   Pass: 100%/1   | Total: 21m 33s | Avg: 21m 33s | Max: 21m 33s
      🟩 cuda.parallel      Pass: 100%/1   | Total:  6m 44s | Avg:  6m 44s | Max:  6m 44s
    
  • 🟩 cccl_c_parallel: Pass: 100%/2 | Total: 13m 17s | Avg: 6m 38s | Max: 10m 52s | Hits: 98%/326

    🟩 cpu
      🟩 amd64              Pass: 100%/2   | Total: 13m 17s | Avg:  6m 38s | Max: 10m 52s | Hits:  98%/326   
    🟩 ctk
      🟩 12.8               Pass: 100%/2   | Total: 13m 17s | Avg:  6m 38s | Max: 10m 52s | Hits:  98%/326   
    🟩 cudacxx
      🟩 nvcc12.8           Pass: 100%/2   | Total: 13m 17s | Avg:  6m 38s | Max: 10m 52s | Hits:  98%/326   
    🟩 cudacxx_family
      🟩 nvcc               Pass: 100%/2   | Total: 13m 17s | Avg:  6m 38s | Max: 10m 52s | Hits:  98%/326   
    🟩 cxx
      🟩 GCC13              Pass: 100%/2   | Total: 13m 17s | Avg:  6m 38s | Max: 10m 52s | Hits:  98%/326   
    🟩 cxx_family
      🟩 GCC                Pass: 100%/2   | Total: 13m 17s | Avg:  6m 38s | Max: 10m 52s | Hits:  98%/326   
    🟩 gpu
      🟩 rtx2080            Pass: 100%/2   | Total: 13m 17s | Avg:  6m 38s | Max: 10m 52s | Hits:  98%/326   
    🟩 jobs
      🟩 Build              Pass: 100%/1   | Total:  2m 25s | Avg:  2m 25s | Max:  2m 25s | Hits:  98%/163   
      🟩 Test               Pass: 100%/1   | Total: 10m 52s | Avg: 10m 52s | Max: 10m 52s | Hits:  98%/163   
    

👃 Inspect Changes

Modifications in project?

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

@oleksandr-pavlyk

oleksandr-pavlyk commented May 6, 2025 •

Copy link
Copy Markdown
Contributor Author

Only the last two commits are unique to these PR. Other commits are from #4609

`iterator_t` stored names of advance/dereference functions
in operator_t struct members, but did not store the name of
the iterator state. This made it difficult to create another
instance of the same iterator on GPU without running into
multiple definition issues.

Used this in test_segmented_reduce.cpp, where we can now say
to reuse state and methods defined for `start_offsets_it`.

```
  auto end_offsets_it = make_iterator<IndexT, HostTransformStateT>(
     {start_offsets_it.state_name, empty_src},
     {start_offsets_it.advance.name, empty_src},
     {start_offsets_it.dereference.name, empty_src});
```

Also:

 1. Introduce `name_source_t` struct that stores
    name of an entity and its source code definition.
 2. Introduce `make_stateful_transformed_iterator` and
    `make_stateless_transformed_iterator` utilities.

    These take name_source_t arguments describing
    state of base iterator, base iterator advance/deref
    function definitions, and state of transformation functor
    and it operation definition.

3. Introduce utilities to get definition sources for
   common iterators and used those in make_constant_iterator,
   and other iterator makers.

   Such utilities are useful for building transform iterators
   from canonical iterators.

4. Applied solution to support std::string_view in operation_t,
   stateful_operation_t constructors and various make_iterator
   functions.

   The solution was suggested to me by @ericniebler and @miscco
1. The test is based on Python test test_large_num_segments3
from test_segmented_reduce.py

The test performs segments reduce of constant iterator with value
of 1, with offsets being a transformed iterator over a counting iterator,
where transformation computes offsets of the beginning of the next
segment, assuming that segment lengths form a sequence

 [ min, min+1, ..., max-1, max, min, min + 1, ... ]

For segments ID `k`, the segment length is `min + (k % (max + 1 - min))`.

Only the result array much be allocated, resulting in substantial
memory savings, given than n_segments > INT_MAX.

Since expected result is known in closed form, test validation is
performed using call to cccl_device_reduce, where input is a transformed
iterator over counting iterator, with transformation function returning
1 is result array element agrees with expected value, and 0 otherwise.

Comparsion combining binary operation is implemented as follows
 (
   ((actual[i1] == expected(i1) ? int32_t(1) : int32_t(0)) *
   ((actual[i2] == expected(i2) ? int32_t(1) : int32_t(0))
 )

== N.B.:

In this test both transformed iterators use stateful operations.
The state for computation of offsets requires min and p = max + 1 - min.
The state for checking the outptu requires min, p, and result array pointer.

Right now the test is deployed for n_segments smaller than INT_MAX,
but it is ready to be enabled when support for incrementing
indirect terators on the host is added.
@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the make-transform-iterator-utility-in-c-paralle-test-suite branch from 5b1f3be to d8564a4 Compare May 7, 2025 12:47
@github-actions

github-actions Bot commented May 7, 2025

Copy link
Copy Markdown
Contributor
🟩 CI finished in 17m 06s: Pass: 100%/5 | Total: 43m 22s | Avg: 8m 40s | Max: 16m 49s | Hits: 98%/326
  • 🟩 python: Pass: 100%/3 | Total: 29m 44s | Avg: 9m 54s | Max: 16m 49s

    🟩 cpu
      🟩 amd64              Pass: 100%/3   | Total: 29m 44s | Avg:  9m 54s | Max: 16m 49s
    🟩 ctk
      🟩 12.8               Pass: 100%/3   | Total: 29m 44s | Avg:  9m 54s | Max: 16m 49s
    🟩 cudacxx
      🟩 nvcc12.8           Pass: 100%/3   | Total: 29m 44s | Avg:  9m 54s | Max: 16m 49s
    🟩 cudacxx_family
      🟩 nvcc               Pass: 100%/3   | Total: 29m 44s | Avg:  9m 54s | Max: 16m 49s
    🟩 cxx
      🟩 GCC13              Pass: 100%/3   | Total: 29m 44s | Avg:  9m 54s | Max: 16m 49s
    🟩 cxx_family
      🟩 GCC                Pass: 100%/3   | Total: 29m 44s | Avg:  9m 54s | Max: 16m 49s
    🟩 gpu
      🟩 rtx2080            Pass: 100%/3   | Total: 29m 44s | Avg:  9m 54s | Max: 16m 49s
    🟩 jobs
      🟩 cuda.cccl          Pass: 100%/1   | Total:  6m 22s | Avg:  6m 22s | Max:  6m 22s
      🟩 cuda.cooperative   Pass: 100%/1   | Total: 16m 49s | Avg: 16m 49s | Max: 16m 49s
      🟩 cuda.parallel      Pass: 100%/1   | Total:  6m 33s | Avg:  6m 33s | Max:  6m 33s
    
  • 🟩 cccl_c_parallel: Pass: 100%/2 | Total: 13m 38s | Avg: 6m 49s | Max: 11m 12s | Hits: 98%/326

    🟩 cpu
      🟩 amd64              Pass: 100%/2   | Total: 13m 38s | Avg:  6m 49s | Max: 11m 12s | Hits:  98%/326   
    🟩 ctk
      🟩 12.8               Pass: 100%/2   | Total: 13m 38s | Avg:  6m 49s | Max: 11m 12s | Hits:  98%/326   
    🟩 cudacxx
      🟩 nvcc12.8           Pass: 100%/2   | Total: 13m 38s | Avg:  6m 49s | Max: 11m 12s | Hits:  98%/326   
    🟩 cudacxx_family
      🟩 nvcc               Pass: 100%/2   | Total: 13m 38s | Avg:  6m 49s | Max: 11m 12s | Hits:  98%/326   
    🟩 cxx
      🟩 GCC13              Pass: 100%/2   | Total: 13m 38s | Avg:  6m 49s | Max: 11m 12s | Hits:  98%/326   
    🟩 cxx_family
      🟩 GCC                Pass: 100%/2   | Total: 13m 38s | Avg:  6m 49s | Max: 11m 12s | Hits:  98%/326   
    🟩 gpu
      🟩 rtx2080            Pass: 100%/2   | Total: 13m 38s | Avg:  6m 49s | Max: 11m 12s | Hits:  98%/326   
    🟩 jobs
      🟩 Build              Pass: 100%/1   | Total:  2m 26s | Avg:  2m 26s | Max:  2m 26s | Hits:  98%/163   
      🟩 Test               Pass: 100%/1   | Total: 11m 12s | Avg: 11m 12s | Max: 11m 12s | Hits:  98%/163   
    

👃 Inspect Changes

Modifications in project?

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

@oleksandr-pavlyk oleksandr-pavlyk changed the title Make transform iterator utility in c paralle test suite Make transform iterator utility in c parallel test suite May 8, 2025
@github-actions

github-actions Bot commented May 8, 2025

Copy link
Copy Markdown
Contributor
🟩 CI finished in 17m 18s: Pass: 100%/5 | Total: 40m 00s | Avg: 8m 00s | Max: 17m 17s | Hits: 98%/326
  • 🟩 python: Pass: 100%/3 | Total: 26m 51s | Avg: 8m 57s | Max: 17m 17s

    🟩 cpu
      🟩 amd64              Pass: 100%/3   | Total: 26m 51s | Avg:  8m 57s | Max: 17m 17s
    🟩 ctk
      🟩 12.8               Pass: 100%/3   | Total: 26m 51s | Avg:  8m 57s | Max: 17m 17s
    🟩 cudacxx
      🟩 nvcc12.8           Pass: 100%/3   | Total: 26m 51s | Avg:  8m 57s | Max: 17m 17s
    🟩 cudacxx_family
      🟩 nvcc               Pass: 100%/3   | Total: 26m 51s | Avg:  8m 57s | Max: 17m 17s
    🟩 cxx
      🟩 GCC13              Pass: 100%/3   | Total: 26m 51s | Avg:  8m 57s | Max: 17m 17s
    🟩 cxx_family
      🟩 GCC                Pass: 100%/3   | Total: 26m 51s | Avg:  8m 57s | Max: 17m 17s
    🟩 gpu
      🟩 rtx2080            Pass: 100%/3   | Total: 26m 51s | Avg:  8m 57s | Max: 17m 17s
    🟩 jobs
      🟩 cuda.cccl          Pass: 100%/1   | Total:  2m 56s | Avg:  2m 56s | Max:  2m 56s
      🟩 cuda.cooperative   Pass: 100%/1   | Total: 17m 17s | Avg: 17m 17s | Max: 17m 17s
      🟩 cuda.parallel      Pass: 100%/1   | Total:  6m 38s | Avg:  6m 38s | Max:  6m 38s
    
  • 🟩 cccl_c_parallel: Pass: 100%/2 | Total: 13m 09s | Avg: 6m 34s | Max: 10m 58s | Hits: 98%/326

    🟩 cpu
      🟩 amd64              Pass: 100%/2   | Total: 13m 09s | Avg:  6m 34s | Max: 10m 58s | Hits:  98%/326   
    🟩 ctk
      🟩 12.8               Pass: 100%/2   | Total: 13m 09s | Avg:  6m 34s | Max: 10m 58s | Hits:  98%/326   
    🟩 cudacxx
      🟩 nvcc12.8           Pass: 100%/2   | Total: 13m 09s | Avg:  6m 34s | Max: 10m 58s | Hits:  98%/326   
    🟩 cudacxx_family
      🟩 nvcc               Pass: 100%/2   | Total: 13m 09s | Avg:  6m 34s | Max: 10m 58s | Hits:  98%/326   
    🟩 cxx
      🟩 GCC13              Pass: 100%/2   | Total: 13m 09s | Avg:  6m 34s | Max: 10m 58s | Hits:  98%/326   
    🟩 cxx_family
      🟩 GCC                Pass: 100%/2   | Total: 13m 09s | Avg:  6m 34s | Max: 10m 58s | Hits:  98%/326   
    🟩 gpu
      🟩 rtx2080            Pass: 100%/2   | Total: 13m 09s | Avg:  6m 34s | Max: 10m 58s | Hits:  98%/326   
    🟩 jobs
      🟩 Build              Pass: 100%/1   | Total:  2m 11s | Avg:  2m 11s | Max:  2m 11s | Hits:  98%/163   
      🟩 Test               Pass: 100%/1   | Total: 10m 58s | Avg: 10m 58s | Max: 10m 58s | Hits:  98%/163   
    

👃 Inspect Changes

Modifications in project?

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

@shwina shwina 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.

It looks good. As discussed offline, a potential API improvement could be simply holding the sources in the iterator itself, and hiding source from the test author behind make_iterator. However this comes with challenges and other potential benefits which will be described in a subsequent issue. No need to block this PR on that work as this is already an improvement.

Separated lines to promote readability.
@github-actions

github-actions Bot commented May 8, 2025

Copy link
Copy Markdown
Contributor
🟩 CI finished in 17m 48s: Pass: 100%/5 | Total: 40m 05s | Avg: 8m 01s | Max: 17m 08s | Hits: 98%/326
  • 🟩 python: Pass: 100%/3 | Total: 26m 39s | Avg: 8m 53s | Max: 17m 08s

    🟩 cpu
      🟩 amd64              Pass: 100%/3   | Total: 26m 39s | Avg:  8m 53s | Max: 17m 08s
    🟩 ctk
      🟩 12.8               Pass: 100%/3   | Total: 26m 39s | Avg:  8m 53s | Max: 17m 08s
    🟩 cudacxx
      🟩 nvcc12.8           Pass: 100%/3   | Total: 26m 39s | Avg:  8m 53s | Max: 17m 08s
    🟩 cudacxx_family
      🟩 nvcc               Pass: 100%/3   | Total: 26m 39s | Avg:  8m 53s | Max: 17m 08s
    🟩 cxx
      🟩 GCC13              Pass: 100%/3   | Total: 26m 39s | Avg:  8m 53s | Max: 17m 08s
    🟩 cxx_family
      🟩 GCC                Pass: 100%/3   | Total: 26m 39s | Avg:  8m 53s | Max: 17m 08s
    🟩 gpu
      🟩 rtx2080            Pass: 100%/3   | Total: 26m 39s | Avg:  8m 53s | Max: 17m 08s
    🟩 jobs
      🟩 cuda.cccl          Pass: 100%/1   | Total:  2m 50s | Avg:  2m 50s | Max:  2m 50s
      🟩 cuda.cooperative   Pass: 100%/1   | Total: 17m 08s | Avg: 17m 08s | Max: 17m 08s
      🟩 cuda.parallel      Pass: 100%/1   | Total:  6m 41s | Avg:  6m 41s | Max:  6m 41s
    
  • 🟩 cccl_c_parallel: Pass: 100%/2 | Total: 13m 26s | Avg: 6m 43s | Max: 11m 11s | Hits: 98%/326

    🟩 cpu
      🟩 amd64              Pass: 100%/2   | Total: 13m 26s | Avg:  6m 43s | Max: 11m 11s | Hits:  98%/326   
    🟩 ctk
      🟩 12.8               Pass: 100%/2   | Total: 13m 26s | Avg:  6m 43s | Max: 11m 11s | Hits:  98%/326   
    🟩 cudacxx
      🟩 nvcc12.8           Pass: 100%/2   | Total: 13m 26s | Avg:  6m 43s | Max: 11m 11s | Hits:  98%/326   
    🟩 cudacxx_family
      🟩 nvcc               Pass: 100%/2   | Total: 13m 26s | Avg:  6m 43s | Max: 11m 11s | Hits:  98%/326   
    🟩 cxx
      🟩 GCC13              Pass: 100%/2   | Total: 13m 26s | Avg:  6m 43s | Max: 11m 11s | Hits:  98%/326   
    🟩 cxx_family
      🟩 GCC                Pass: 100%/2   | Total: 13m 26s | Avg:  6m 43s | Max: 11m 11s | Hits:  98%/326   
    🟩 gpu
      🟩 rtx2080            Pass: 100%/2   | Total: 13m 26s | Avg:  6m 43s | Max: 11m 11s | Hits:  98%/326   
    🟩 jobs
      🟩 Build              Pass: 100%/1   | Total:  2m 15s | Avg:  2m 15s | Max:  2m 15s | Hits:  98%/163   
      🟩 Test               Pass: 100%/1   | Total: 11m 11s | Avg: 11m 11s | Max: 11m 11s | Hits:  98%/163   
    

👃 Inspect Changes

Modifications in project?

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

@oleksandr-pavlyk
oleksandr-pavlyk merged commit 592352a into NVIDIA:main May 9, 2025
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL May 9, 2025
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

2 participants