Skip to content

Commit

Permalink
Acquire spill lock in to/from_arrow (#13646)
Browse files Browse the repository at this point in the history
Currently, calling `to_arrow` will render a cuDF Series/DataFrame unspillable. I believe it's just an oversight that we don't call to/from_arrow in an `acquire_spill_lock` context. Neither of those methods should expose the device pointer to a cuDF object externally.

cc: @madsbk @vyasr  -- could you take a look please?

```python
In [1]: import cudf
In [2]: s = cudf.Series([1, 2, 3])
In [3]: cudf.core.buffer.spill_manager.get_global_manager()
Out[3]: <SpillManager spill_on_demand=True device_memory_limit=N/A | 0B spilled | 24B (0%) unspilled (unspillable)>
In [4]: s.to_arrow()
Out[4]:
<pyarrow.lib.Int64Array object at 0x7f31e8f7ba60>
[
  1,
  2,
  3
]
In [5]: cudf.core.buffer.spill_manager.get_global_manager()
Out[5]: <SpillManager spill_on_demand=True device_memory_limit=N/A | 0B spilled | 24B (100%) unspilled (unspillable)>
```

Authors:
  - Ashwin Srinath (https://github.com/shwina)

Approvers:
  - Vyas Ramasubramani (https://github.com/vyasr)
  - Mads R. B. Kristensen (https://github.com/madsbk)
  - Peter Andreas Entschev (https://github.com/pentschev)

URL: #13646
  • Loading branch information
shwina authored Jun 30, 2023
1 parent c872400 commit 2952f79
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/cudf/cudf/_lib/interop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ from cudf._lib.cpp.table.table_view cimport table_view
from cudf._lib.utils cimport columns_from_unique_ptr, table_view_from_columns

from cudf.api.types import is_list_dtype, is_struct_dtype
from cudf.core.buffer import acquire_spill_lock


def from_dlpack(dlpack_capsule):
Expand Down Expand Up @@ -106,6 +107,7 @@ cdef vector[column_metadata] gather_metadata(object cols_dtypes) except *:
)
return cpp_metadata


cdef _set_col_children_metadata(dtype,
column_metadata& col_meta):

Expand Down Expand Up @@ -133,6 +135,7 @@ cdef _set_col_children_metadata(dtype,
col_meta.children_meta.push_back(column_metadata())


@acquire_spill_lock()
def to_arrow(list source_columns, object column_dtypes):
"""Convert a list of columns from
cudf Frame to a PyArrow Table.
Expand All @@ -158,6 +161,7 @@ def to_arrow(list source_columns, object column_dtypes):
return pyarrow_wrap_table(cpp_arrow_table)


@acquire_spill_lock()
def from_arrow(object input_table):
"""Convert from PyArrow Table to a list of columns.
Expand Down

0 comments on commit 2952f79

Please sign in to comment.