Repository navigation
Rewrite iterators to not depend on Numba - #7441
Conversation
| @@ -0,0 +1,229 @@ | |||
| # Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. | |||
There was a problem hiding this comment.
Copyrights, everywhere.
This comment has been minimized.
This comment has been minimized.
|
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. |
51902a1 to
c4e756b
Compare
There was a problem hiding this comment.
Let's run compile benchmarks to make sure the dedup isn't hurting compile time too much.
There was a problem hiding this comment.
Done (see PR description).
| return hashlib.sha256(kind_str.encode()).hexdigest()[:16] | ||
|
|
||
|
|
||
| def compose_iterator_states( |
There was a problem hiding this comment.
Can we push this down to C++ or Cython?
There was a problem hiding this comment.
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.") |
There was a problem hiding this comment.
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.
🥳 CI Workflow Results🟩 Finished in 1h 11m: Pass: 100%/64 | Total: 19h 10m | Max: 44m 55s | Hits: 100%/1264See results here. |
| """ | ||
| 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. | ||
| """ |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
* 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]>
* 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]>
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 theadvanceanddereferencemethods 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.pyisto_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:
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):
bench_unary_transform_iterator:
bench_select_iterator:
➡️ Pointer Benchmarks - Neutral Performance
bench_binary_transform_pointer:
📦 Struct Benchmarks - Neutral with Slight Regression
bench_reduce_struct:
bench_upper_bound (handles structs well):
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