Skip to content
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

Memory Profiling #15866

Merged
merged 21 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions docs/cudf/source/user_guide/memory-profiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

# Memory Profiling


Peak memory usage is a common concern in GPU programming since the available GPU memory is typically less than available CPU memory. To easily identify memory hotspots, cudf provides a memory profiler.
Peak memory usage is a common concern in GPU programming since the available GPU memory is typically less than available CPU memory. To easily identify memory hotspots, cudf provides a memory profiler. In comes with an overhead so avoid using it in performance-sensitive code.
madsbk marked this conversation as resolved.
Show resolved Hide resolved

## Enabling memory profiling

1. Use `cudf.set_option`:
First, we need to enable memory profiling in [RMM](https://docs.rapids.ai/api/rmm/stable/guide/). One way to do this is by calling {py:func}`rmm.statistics.enable_statistics()`. This will add a statistics resource adaptor to the current RMM memory resource, which enables cudf to access memory profiling information. See the RMM documentation for more details.

Second, we need to enable memory profiling in cudf by using either of the following:
madsbk marked this conversation as resolved.
Show resolved Hide resolved

1. Use {py:func}`cudf.set_option`:

```python
>>> import cudf
Expand All @@ -21,13 +24,15 @@ launch of the Python interpreter:
CUDF_MEMORY_PROFILING="1" python -c "import cudf"
```

## Get profiling result
To get the result of the profiling, use {py:func}`cudf.utils.performance_tracking.print_memory_report`.

To get the result of the profiling, use {py:func}`cudf.utils.performance_tracking.print_memory_report`. In the following, we enable profiling, do some work, and then print the profiling results:
In the following example, we enable profiling, do some work, and then print the profiling results:

```python
>>> import cudf
>>> from cudf.utils.performance_tracking import print_memory_report
>>> from rmm.statistics import enable_statistics
>>> enable_statistics()
>>> cudf.set_option("memory_profiling", True)
>>> cudf.DataFrame({"a": [1, 2, 3]}) # Some work
a
Expand All @@ -51,4 +56,4 @@ ncalls memory_peak memory_total filename:lineno(function)
6 0 0 cudf/core/index.py:424(RangeIndex.__len__)
```

It is also possible to access the raw profiling data through {py:func}`cudf.utils.performance_tracking.get_memory_records`.
It is also possible to access the raw profiling data by calling: {py:func}`cudf.utils.performance_tracking.get_memory_records`.
3 changes: 2 additions & 1 deletion python/cudf/cudf/utils/performance_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def _performance_tracking(func, domain="cudf_python"):
def wrapper(*args, **kwargs):
with contextlib.ExitStack() as stack:
if get_option("memory_profiling"):
rmm.statistics.enable_statistics()
# NB: the user still needs to call `rmm.statistics.enable_statistics()`
# to enable memory profiling.
stack.enter_context(
rmm.statistics.profiler(
name=rmm.statistics._get_descriptive_name_of_object(
Expand Down
Loading