Skip to content

Rewrite iterators to not depend on Numba - #7441

Merged
shwina merged 17 commits into
NVIDIA:mainfrom
shwina:byoc-iterator
Feb 9, 2026
Merged

shwina merged 17 commits into
NVIDIA:mainfrom
shwina:byoc-iterator

Conversation

@shwina

@shwina shwina commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

Closes #7353

This PR is the next major step towards dropping Numba as a required dependency of cuda.compute. Previously, all iterators were implemented in pure Python, with numba being used to JIT compile the definitions of the advance and dereference methods of all iterators. This PR reimplements all methods in C++, and uses NVRTC to JIT compile those into LTOIR. This does not affect the API/usage in any way.

The end effect of this PR is that numba is only ever imported in _jit.py (and the associated _odr_helpers.py). The only function exported by _jit.py is to_jit_op_adapter. This makes the library importable without numba, and also makes it trivial to raise if numba is not available in the future.

The important changes are:

  • Some tooling to generate and JIT compile C++ with NVRTC (d16f6a8)
  • Reimplementation of all iterator methods in C++ (eb9b0f2)

Performance impact

The performance impact is neutral to slightly positive, with most benchmarks within noise. Attached here is a comparison of the pytest benchmarks between this branch ("byoc") and main:

comparison.txt

And an AI-generated summary::

Representative Benchmark Results

🚀 Iterator Benchmarks - Clear Improvements

bench_binary_transform_iterator (time in μs, lower is better):

Size      main                  byoc      Speedup
------------------------------------------------------
10K       18.13                 15.57     1.16x (16% faster)
100K      18.49                 15.22     1.21x (21% faster)
1M        19.79                 16.30     1.21x (21% faster)

bench_unary_transform_iterator:

Size      main                  byoc      Speedup
------------------------------------------------------
10K       15.51                 13.62     1.14x (14% faster)
100K      15.38                 13.67     1.13x (13% faster)
1M        16.52                 14.82     1.11x (11% faster)

bench_select_iterator:

Size      main                  byoc      Speedup
------------------------------------------------------
10K       30.92                 29.17     1.06x (6% faster)
100K      32.05                 29.68     1.08x (8% faster)
1M        34.19                 32.09     1.07x (7% faster)

➡️ Pointer Benchmarks - Neutral Performance

bench_binary_transform_pointer:

Size      main                  byoc      Speedup
------------------------------------------------------
10K       14.04                 13.50     1.04x (neutral)
100K      13.81                 13.71     1.01x (neutral)
1M        17.20                 17.23     1.00x (neutral)

📦 Struct Benchmarks - Neutral with Slight Regression

bench_reduce_struct:

Size      main                  byoc      Speedup
------------------------------------------------------
10K       40.67                 41.08     0.99x (1% slower)
100K      40.58                 41.24     0.98x (2% slower)
1M        41.61                 42.95     0.97x (3% slower)

bench_upper_bound (handles structs well):

Size      main                  byoc      Speedup
------------------------------------------------------
10K       23.96                 23.23     1.03x (neutral)
100K      30.42                 27.87     1.09x (9% faster)
1M        123.35                114.74    1.08x (8% faster)

Key Takeaways

✅ Iterator operations: Consistent 6-21% speedups across the board
✅ Pointer operations: Performance maintained (within 1-4% variation)
✅ Struct operations: Mostly neutral, one 3% regression in reduce_struct
✅ Scaling: Benefits increase with problem size for search operations

Checklist

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

@shwina
shwina requested review from a team as code owners January 30, 2026 16:28
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jan 30, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jan 30, 2026
Comment thread c/parallel/include/cccl/c/types.h Resolved
@@ -0,0 +1,229 @@
# Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.

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.

Copyrights, everywhere.

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.

yeah switch to 2026

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.

✅

@github-actions

This comment has been minimized.

@shwina
shwina marked this pull request as draft January 30, 2026 21:09
@copy-pr-bot

copy-pr-bot Bot commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cccl-authenticator-app cccl-authenticator-app Bot moved this from In Review to In Progress in CCCL Jan 30, 2026
@shwina
shwina force-pushed the byoc-iterator branch 5 times, most recently from 51902a1 to c4e756b Compare February 5, 2026 16:46
Comment thread c/parallel/src/nvrtc/command_list.h Resolved

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.

Let's run compile benchmarks to make sure the dedup isn't hurting compile time too much.

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.

Done (see PR description).

return hashlib.sha256(kind_str.encode()).hexdigest()[:16]


def compose_iterator_states(

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.

Can we push this down to C++ or Cython?

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.

I left this as is for now. As we talked about earlier, this is host logic so we definitely can't JIT compile this with NVRTC. It's totally possible to push this down to Cython and ship as part of a pre-built extension, but we can revisit that idea if it ever becomes a problem. Currently the benchmarks show no compile time regressions.

@shwina
shwina marked this pull request as ready for review February 8, 2026 15:59
@cccl-authenticator-app cccl-authenticator-app Bot moved this from In Progress to In Review in CCCL Feb 8, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

np.testing.assert_equal(d_output.get(), expected)


@pytest.mark.no_verify_sass(reason="LDL/STL instructions emitted for this test.")

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.

Note, this test is newly found to fail the LDL/STL check for CUDA 13.1 on H100.

I suspect this is due to https://github.com/NVIDIA/cccl/pull/7441/changes#diff-26033a79ec965190c915b3fe616dd6cba8eac2a7d556fb51f0f09d80e46ff35dR102, but we should follow up with an investigation.

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.

@github-actions

github-actions Bot commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 1h 11m: Pass: 100%/64 | Total: 19h 10m | Max: 44m 55s | Hits: 100%/1264

See results here.

Comment on lines +18 to +24
"""
Iterator that accesses values through an index mapping.

At position i, yields values[indices[i]]. The indices iterator is advanced
normally, and the values iterator is accessed via random access using the
index value.
"""

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.

Suggestion: for consistency with other iterator docstrings, add a link to https://nvidia.github.io/cccl/thrust/api/classthrust_1_1permutation__iterator.html and include example code (if we have it)

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.

I'll tack this on in the third PR in this series to save another CI cycle.

"""Get the compute capability string for the current device."""
from cuda.core import Device

device = Device()

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.

was a typo, I meant a machine with multiple devices. I think they would all have the same compute capability so it probably wouldn't matter here

@shwina
shwina merged commit 17d84ba into NVIDIA:main Feb 9, 2026
85 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Feb 9, 2026
fbusato pushed a commit to fbusato/cccl that referenced this pull request Feb 19, 2026
* Add support for passing extra LTOIRs (with deduplication)

* Plumb extra LTOIRS to Python

* Delete old iterators

* Some infrastructure updates

* Add C++ JIT compilation infrastructure

* Add IteratorBase type

* Update all iterators to use C++ codegen + compilation

* Update iterator factories

* Update all algorithms

* Copyright

* Fix iterator method declarations to be all void* types

* Lint

* Unnecessary comment

* Address review comments

* Copyright updates

* Pre-commit fix

* Mark test no_verify_sass

---------

Co-authored-by: Ashwin Srinath <[email protected]>
fbusato pushed a commit to fbusato/cccl that referenced this pull request Feb 26, 2026
* Add support for passing extra LTOIRs (with deduplication)

* Plumb extra LTOIRS to Python

* Delete old iterators

* Some infrastructure updates

* Add C++ JIT compilation infrastructure

* Add IteratorBase type

* Update all iterators to use C++ codegen + compilation

* Update iterator factories

* Update all algorithms

* Copyright

* Fix iterator method declarations to be all void* types

* Lint

* Unnecessary comment

* Address review comments

* Copyright updates

* Pre-commit fix

* Mark test no_verify_sass

---------

Co-authored-by: Ashwin Srinath <[email protected]>
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.

Rewrite iterators to not use numba-cuda

2 participants