Skip to content

Conversation

@Monishver11
Copy link

Description

Makes _legacy_default() and _per_thread_default() class methods public by removing the leading underscore, providing users with a clean API for accessing default streams.

Changes

  • Renamed _legacy_default()legacy_default()
  • Renamed _per_thread_default()per_thread_default()
  • Added comprehensive docstrings explaining stream synchronization behavior
  • Updated internal callers to use new public methods
  • Updated existing tests to use public API
  • Added new tests: test_stream_legacy_default_public_api() and test_stream_per_thread_default_public_api()

Motivation

Previously, users had to use the undocumented workaround Stream.from_handle(0) to access the legacy default stream. This PR provides official, documented class methods for accessing both default stream types.

Testing

  • All existing tests pass with updated method names (33/33 tests passing)
  • New tests verify public API functionality
  • Subclassing behavior preserved and tested
(cuda-python-dev) [mc10322@cuda5 cuda_core]$ pytest tests/test_stream.py -v
============================================== test session starts ==============================================
platform linux -- Python 3.10.19, pytest-9.0.2, pluggy-1.6.0 -- /scratch/mc10322/miniconda3/envs/cuda-python-dev/bin/python3.10
cachedir: .pytest_cache
rootdir: /scratch/mc10322/cuda-python/cuda_core
configfile: pytest.ini
collected 33 items

tests/test_stream.py::test_stream_init_disabled PASSED                                                    [  3%]
tests/test_stream.py::test_stream_init_with_options PASSED                                                [  6%]
tests/test_stream.py::test_stream_handle PASSED                                                           [  9%]
tests/test_stream.py::test_stream_is_nonblocking PASSED                                                   [ 12%]
tests/test_stream.py::test_stream_priority PASSED                                                         [ 15%]
tests/test_stream.py::test_stream_sync PASSED                                                             [ 18%]
tests/test_stream.py::test_stream_record PASSED                                                           [ 21%]
tests/test_stream.py::test_stream_wait_event PASSED                                                       [ 24%]
tests/test_stream.py::test_stream_wait_invalid_event PASSED                                               [ 27%]
tests/test_stream.py::test_stream_device PASSED                                                           [ 30%]
tests/test_stream.py::test_stream_context PASSED                                                          [ 33%]
tests/test_stream.py::test_stream_from_foreign_stream PASSED                                              [ 36%]
tests/test_stream.py::test_stream_from_handle PASSED                                                      [ 39%]
tests/test_stream.py::test_legacy_default_stream PASSED                                                   [ 42%]
tests/test_stream.py::test_per_thread_default_stream PASSED                                               [ 45%]
tests/test_stream.py::test_stream_subclassing PASSED                                                      [ 48%]
tests/test_stream.py::test_stream_legacy_default_subclassing PASSED                                       [ 51%]
tests/test_stream.py::test_stream_per_thread_default_subclassing PASSED                                   [ 54%]
tests/test_stream.py::test_stream_legacy_default_public_api PASSED                                        [ 57%]
tests/test_stream.py::test_stream_per_thread_default_public_api PASSED                                    [ 60%]
tests/test_stream.py::test_stream_equality_same_handle PASSED                                             [ 63%]
tests/test_stream.py::test_stream_inequality_different_handles PASSED                                     [ 66%]
tests/test_stream.py::test_stream_equality_reflexive PASSED                                               [ 69%]
tests/test_stream.py::test_stream_equality_symmetric PASSED                                               [ 72%]
tests/test_stream.py::test_stream_type_safety PASSED                                                      [ 75%]
tests/test_stream.py::test_stream_not_equal_operator PASSED                                               [ 78%]
tests/test_stream.py::test_stream_hash_consistency PASSED                                                 [ 81%]
tests/test_stream.py::test_stream_hash_equality_same_handle PASSED                                        [ 84%]
tests/test_stream.py::test_stream_hash_inequality_different_handles PASSED                                [ 87%]
tests/test_stream.py::test_stream_dict_key PASSED                                                         [ 90%]
tests/test_stream.py::test_stream_set_membership PASSED                                                   [ 93%]
tests/test_stream.py::test_builtin_stream_hash PASSED                                                     [ 96%]
tests/test_stream.py::test_default_stream_consistency PASSED                                              [100%]

============================================== 33 passed in 0.37s ===============================================

Note

Pre-commit's mypy-pathfinder check fails on load_dl_linux.py, but this is a pre-existing issue in cuda_pathfinder unrelated to these cuda_core changes.

Fixes #1445

…A#1445

Signed-off-by: Monishver Chandrasekaran <monishver@Monishvers-MacBook-Air.local>
…A#1445

Signed-off-by: Monishver Chandrasekaran <monishverchandrasekaran@gmail.com>
@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Jan 14, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEA]: Add public class methods for retrieving the legacy default stream as well as the per-thread default stream

1 participant