From 7ba6cdeeb35319288c1afc10bbcd8d56872eef49 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Mon, 10 Nov 2025 22:08:06 -0600 Subject: [PATCH 1/2] Improve Python docs --- python/rmm/rmm/pylibrmm/device_buffer.pyx | 23 ++++++++----- .../memory_resource/_memory_resource.pyx | 33 +++++++++---------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/python/rmm/rmm/pylibrmm/device_buffer.pyx b/python/rmm/rmm/pylibrmm/device_buffer.pyx index e2535269b..e45667533 100644 --- a/python/rmm/rmm/pylibrmm/device_buffer.pyx +++ b/python/rmm/rmm/pylibrmm/device_buffer.pyx @@ -173,11 +173,12 @@ cdef class DeviceBuffer: strm.view()) def copy(self): - """Returns a copy of DeviceBuffer. + """Returns a copy of this :class:`DeviceBuffer`. Returns ------- - A deep copy of existing ``DeviceBuffer`` + DeviceBuffer + A deep copy of this :class:`DeviceBuffer` Examples -------- @@ -232,8 +233,10 @@ cdef class DeviceBuffer: Parameters ---------- - ary : ``bytes``-like buffer to write into - stream : CUDA stream to use for copying, default the default stream + ary : + :class:`bytes`-like buffer to write into + stream : optional + CUDA stream to use for copying, defaults to the default stream Examples -------- @@ -270,8 +273,10 @@ cdef class DeviceBuffer: Parameters ---------- - ary : ``bytes``-like buffer to copy from - stream : CUDA stream to use for copying, default the default stream + ary : + :class:`bytes`-like buffer to copy from + stream : optional + CUDA stream to use for copying, defaults to the default stream Examples -------- @@ -301,8 +306,10 @@ cdef class DeviceBuffer: Parameters ---------- - cuda_ary : object to copy from that has ``__cuda_array_interface__`` - stream : CUDA stream to use for copying, default the default stream + cuda_ary : + Object to copy from that has ``__cuda_array_interface__`` + stream : optional + CUDA stream to use for copying, defaults to the default stream Examples -------- diff --git a/python/rmm/rmm/pylibrmm/memory_resource/_memory_resource.pyx b/python/rmm/rmm/pylibrmm/memory_resource/_memory_resource.pyx index e950c140c..8c265e166 100644 --- a/python/rmm/rmm/pylibrmm/memory_resource/_memory_resource.pyx +++ b/python/rmm/rmm/pylibrmm/memory_resource/_memory_resource.pyx @@ -81,7 +81,7 @@ cdef class DeviceMemoryResource: ---- On integrated memory systems, attempting to allocate more memory than available can cause the process to be killed by the operating system - instead of raising a catchable ``MemoryError``. + instead of raising a catchable :class`MemoryError`. Raises ------ @@ -950,8 +950,8 @@ cdef class TrackingResourceAdaptor(UpstreamResourceAdaptor): def log_outstanding_allocations(self): """ - Logs the output of `get_outstanding_allocations_str` to the current - RMM log file if enabled. + Logs the output of :meth:`get_outstanding_allocations_str` to the + current RMM log file if enabled. """ (( @@ -1215,26 +1215,25 @@ cpdef _flush_logs(): def enable_logging(log_file_name=None): """ - Enable logging of run-time events for all devices. + Enable logging of runtime events for all devices. Parameters ---------- - log_file_name: str, optional + log_file_name: str, optional Name of the log file. If not specified, the environment variable - RMM_LOG_FILE is used. A ValueError is thrown if neither is available. - A separate log file is produced for each device, - and the suffix `".dev{id}"` is automatically added to the log file - name. + RMM_LOG_FILE is used. A :class:`ValueError` is thrown if neither is + available. A separate log file is produced for each device, and the + suffix ``".dev{id}"`` is automatically added to the log file name. Notes ----- - Note that if you use the environment variable CUDA_VISIBLE_DEVICES + Note that if you use the environment variable ``CUDA_VISIBLE_DEVICES`` with logging enabled, the suffix may not be what you expect. For - example, if you set CUDA_VISIBLE_DEVICES=1, the log file produced - will still have suffix `0`. Similarly, if you set - CUDA_VISIBLE_DEVICES=1,0 and use devices 0 and 1, the log file - with suffix `0` will correspond to the GPU with device ID `1`. - Use `rmm.get_log_filenames()` to get the log file names + example, if you set ``CUDA_VISIBLE_DEVICES=1``, the log file produced + will still have suffix ``0``. Similarly, if you set + ``CUDA_VISIBLE_DEVICES=1,0`` and use devices 0 and 1, the log file + with suffix ``0`` will correspond to the GPU with device ID ``1``. + Use :func:`rmm.get_log_filenames` to get the log file names corresponding to each device. """ global _per_device_mrs @@ -1253,7 +1252,7 @@ def enable_logging(log_file_name=None): def disable_logging(): """ Disable logging if it was enabled previously using - `rmm.initialize()` or `rmm.enable_logging()`. + :func:`rmm.reinitialize()` or :func:`rmm.enable_logging()`. """ global _per_device_mrs for i, each_mr in _per_device_mrs.items(): @@ -1263,7 +1262,7 @@ def disable_logging(): def get_log_filenames(): """ - Returns the log filename (or `None` if not writing logs) + Returns the log filename (or ``None`` if not writing logs) for each device in use. Examples From 1589571e65e8c6e80c52b254320601203da290c6 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 11 Nov 2025 08:43:36 -0600 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Matthew Murray <41342305+Matt711@users.noreply.github.com> --- .../rmm/rmm/pylibrmm/memory_resource/_memory_resource.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/rmm/rmm/pylibrmm/memory_resource/_memory_resource.pyx b/python/rmm/rmm/pylibrmm/memory_resource/_memory_resource.pyx index 8c265e166..a8d86a77f 100644 --- a/python/rmm/rmm/pylibrmm/memory_resource/_memory_resource.pyx +++ b/python/rmm/rmm/pylibrmm/memory_resource/_memory_resource.pyx @@ -81,7 +81,7 @@ cdef class DeviceMemoryResource: ---- On integrated memory systems, attempting to allocate more memory than available can cause the process to be killed by the operating system - instead of raising a catchable :class`MemoryError`. + instead of raising a catchable :class:`MemoryError`. Raises ------ @@ -1219,9 +1219,9 @@ def enable_logging(log_file_name=None): Parameters ---------- - log_file_name: str, optional + log_file_name : str, optional Name of the log file. If not specified, the environment variable - RMM_LOG_FILE is used. A :class:`ValueError` is thrown if neither is + ``RMM_LOG_FILE`` is used. A :class:`ValueError` is thrown if neither is available. A separate log file is produced for each device, and the suffix ``".dev{id}"`` is automatically added to the log file name.