-
Notifications
You must be signed in to change notification settings - Fork 233
Add Python bindings to cuda_stream_pool #2110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rapids-bot
merged 16 commits into
rapidsai:main
from
nirandaperera:cuda-stream-pool-python-bindings
Nov 4, 2025
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cd29a87
adding stream pool python bindings
nirandaperera eb2c3cd
adding tests
nirandaperera 30d38d7
Merge branch 'main' of github.com:rapidsai/rmm into cuda-stream-pool-…
nirandaperera f196957
Merge remote-tracking branch 'upstream/main' into cuda-stream-pool-py…
bdice c15b39c
Sort CMake sources
bdice 5308dd3
Merge remote-tracking branch 'upstream/main' into cuda-stream-pool-py…
bdice b9f6ccf
removing exception
nirandaperera 7e1f944
addressing PR comments
nirandaperera 8234fe0
minor changer
nirandaperera 2c70d9d
moving CudaStreamFlags
nirandaperera 14d4468
removing by_id method
nirandaperera d5429bd
Apply suggestion from @bdice
nirandaperera cdbdfbe
adding doc strings
nirandaperera 9bc15f8
Merge branch 'main' of github.com:rapidsai/rmm into cuda-stream-pool-…
nirandaperera 66b7b0a
Fix copyrights on new files
bdice 2c10356
Fix docstrings
bdice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2021-2024, NVIDIA CORPORATION. | ||
| # SPDX-FileCopyrightText: Copyright (c) 2021-2025, NVIDIA CORPORATION. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from rmm.librmm.cuda_stream_view cimport cuda_stream_view | ||
|
|
||
| from rmm.librmm.cuda_stream cimport cuda_stream_flags | ||
|
|
||
| cdef extern from "rmm/cuda_stream_pool.hpp" namespace "rmm" nogil: | ||
| cdef cppclass cuda_stream_pool: | ||
| cuda_stream_pool(size_t pool_size) | ||
| cuda_stream_pool(size_t pool_size, cuda_stream_flags flags) | ||
| cuda_stream_view get_stream() | ||
| cuda_stream_view get_stream(size_t stream_id) except + | ||
| size_t get_pool_size() |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| cimport cython | ||
| from libc.stddef cimport size_t | ||
| from libcpp.memory cimport unique_ptr | ||
|
|
||
| from rmm.librmm.cuda_stream_pool cimport cuda_stream_pool | ||
|
|
||
|
|
||
| @cython.final | ||
| cdef class CudaStreamPool: | ||
| cdef unique_ptr[cuda_stream_pool] c_obj |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| cimport cython | ||
| from libc.stddef cimport size_t | ||
| from cython.operator cimport dereference as deref | ||
|
|
||
| from rmm.librmm.cuda_stream cimport cuda_stream_flags | ||
| from rmm.librmm.cuda_stream_pool cimport cuda_stream_pool | ||
|
|
||
| from rmm.pylibrmm.stream cimport Stream | ||
|
|
||
| from typing import Optional | ||
|
|
||
|
|
||
| @cython.final | ||
| cdef class CudaStreamPool: | ||
| """ | ||
| A pool of CUDA streams for efficient stream management. | ||
|
|
||
| Provides thread-safe access to a collection of CUDA stream objects. | ||
| Successive calls may return views of identical streams. | ||
| """ | ||
|
|
||
| def __cinit__(self, size_t pool_size = 16, | ||
| cuda_stream_flags flags = cuda_stream_flags.sync_default): | ||
| with nogil: | ||
| self.c_obj.reset(new cuda_stream_pool(pool_size, flags)) | ||
|
|
||
| def __dealloc__(self): | ||
| with nogil: | ||
| self.c_obj.reset() | ||
|
|
||
| def get_stream(self, stream_id: Optional[int] = None) -> Stream: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method and |
||
| """ | ||
| Get a Stream from the pool (optionally by ID). | ||
|
|
||
| Parameters | ||
| ---------- | ||
| stream_id : Optional[int], optional | ||
| The ID of the stream to get. If None, the next stream from the pool is | ||
| returned. | ||
|
|
||
| Returns | ||
| ------- | ||
| Stream | ||
| A non-owning Stream object from the pool | ||
| """ | ||
| cdef size_t c_stream_id | ||
| if stream_id is None: | ||
| return Stream._from_cudaStream_t( | ||
| deref(self.c_obj).get_stream().value(), owner=self) | ||
| else: | ||
| c_stream_id = <size_t>stream_id | ||
| return Stream._from_cudaStream_t( | ||
| deref(self.c_obj).get_stream(c_stream_id).value(), owner=self) | ||
|
|
||
| def get_pool_size(self) -> int: | ||
| """ | ||
| Get the pool size. | ||
|
|
||
| Returns | ||
| ------- | ||
| int | ||
| The number of streams in the pool | ||
| """ | ||
| return deref(self.c_obj).get_pool_size() | ||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A size_t cannot be negative so the non negative stipulation is unnecessary