Skip to content

Commit 8690c9f

Browse files
authored
Require passing memory resources to from_libcudf methods (#20171)
Resolves #14229 Authors: - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Matthew Roeschke (https://github.com/mroeschke) URL: #20171
1 parent d520ba2 commit 8690c9f

File tree

9 files changed

+26
-24
lines changed

9 files changed

+26
-24
lines changed

python/cudf/cudf/_lib/strings_udf.pyx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ from pylibcudf.libcudf.strings_udf cimport (
1717
from rmm.librmm.device_buffer cimport device_buffer
1818
from rmm.pylibrmm.device_buffer cimport DeviceBuffer
1919
from rmm.pylibrmm.stream import DEFAULT_STREAM
20+
from rmm.mr import get_current_device_resource
2021

2122
import numpy as np
2223

@@ -38,7 +39,11 @@ def column_from_managed_udf_string_array(DeviceBuffer d_buffer):
3839
with nogil:
3940
c_result = move(cpp_column_from_managed_udf_string_array(data, size))
4041

41-
return plc_Column.from_libcudf(move(c_result), DEFAULT_STREAM)
42+
return plc_Column.from_libcudf(
43+
move(c_result),
44+
DEFAULT_STREAM,
45+
get_current_device_resource(),
46+
)
4247

4348

4449
def get_character_flags_table_ptr():

python/pylibcudf/pylibcudf/column.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ cdef class Column:
6060
cdef Column from_libcudf(
6161
unique_ptr[column] libcudf_col,
6262
Stream stream,
63-
DeviceMemoryResource mr=*
63+
DeviceMemoryResource mr
6464
)
6565

6666
@staticmethod

python/pylibcudf/pylibcudf/column.pyx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ cdef class Column:
604604
cdef Column from_libcudf(
605605
unique_ptr[column] libcudf_col,
606606
Stream stream,
607-
DeviceMemoryResource mr=None
607+
DeviceMemoryResource mr
608608
):
609609
"""Create a Column from a libcudf column.
610610
@@ -619,8 +619,6 @@ cdef class Column:
619619

620620
cdef column_contents contents = libcudf_col.get().release()
621621

622-
stream = _get_stream(stream)
623-
mr = _get_memory_resource(mr)
624622
# Note that when converting to cudf Column objects we'll need to pull
625623
# out the base object.
626624
cdef gpumemoryview data = gpumemoryview(

python/pylibcudf/pylibcudf/contiguous_split.pxd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@ cpdef PackedColumns pack(Table input)
5050
cpdef Table unpack(PackedColumns input, DeviceMemoryResource mr=*)
5151

5252
cpdef Table unpack_from_memoryviews(
53-
memoryview metadata, gpumemoryview gpu_data, DeviceMemoryResource mr=*
53+
memoryview metadata,
54+
gpumemoryview gpu_data,
5455
)

python/pylibcudf/pylibcudf/contiguous_split.pyx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ cpdef Table unpack(PackedColumns input, DeviceMemoryResource mr=None):
374374

375375

376376
cpdef Table unpack_from_memoryviews(
377-
memoryview metadata, gpumemoryview gpu_data, DeviceMemoryResource mr=None
377+
memoryview metadata,
378+
gpumemoryview gpu_data,
378379
):
379380
"""Deserialize the result of `pack`.
380381
@@ -388,19 +389,22 @@ cpdef Table unpack_from_memoryviews(
388389
The packed metadata to unpack.
389390
gpu_data : gpumemoryview
390391
The packed gpu_data to unpack.
391-
mr : DeviceMemoryResource, optional
392-
Device memory resource used to allocate the returned table's device memory.
393392
394393
Returns
395394
-------
396395
Table
397396
Copy of the packed columns.
398397
"""
399-
mr = _get_memory_resource(mr)
400398
if metadata.nbytes == 0:
401399
if gpu_data.__cuda_array_interface__["data"][0] != 0:
402400
raise ValueError("Expected an empty gpu_data from unpacking an empty table")
403-
return Table.from_libcudf(make_unique[table](table_view()), stream=None, mr=mr)
401+
# For an empty table we just attach the default stream and mr since neither will
402+
# be used for any operations.
403+
return Table.from_libcudf(
404+
make_unique[table](table_view()),
405+
_get_stream(),
406+
_get_memory_resource(),
407+
)
404408

405409
# Extract the raw data pointers
406410
cdef const uint8_t[::1] _metadata = metadata

python/pylibcudf/pylibcudf/io/types.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ cdef class TableWithMetadata:
8585

8686
@staticmethod
8787
cdef TableWithMetadata from_libcudf(
88-
table_with_metadata& tbl, Stream stream=*, DeviceMemoryResource mr=*
88+
table_with_metadata& tbl, Stream stream, DeviceMemoryResource mr
8989
)
9090

9191
cdef class SourceInfo:

python/pylibcudf/pylibcudf/io/types.pyx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ from pylibcudf.libcudf.io.types cimport (
2929
from pylibcudf.libcudf.types cimport size_type
3030
from pylibcudf.libcudf.utilities.span cimport host_span, device_span
3131

32-
from pylibcudf.utils cimport _get_stream, _get_memory_resource
3332
from rmm.pylibrmm.device_buffer cimport DeviceBuffer
3433
from rmm.pylibrmm.stream cimport Stream
3534
from rmm.pylibrmm.memory_resource cimport DeviceMemoryResource
@@ -395,13 +394,11 @@ cdef class TableWithMetadata:
395394
@staticmethod
396395
cdef TableWithMetadata from_libcudf(
397396
table_with_metadata& tbl_with_meta,
398-
Stream stream = None,
399-
DeviceMemoryResource mr = None
397+
Stream stream,
398+
DeviceMemoryResource mr
400399
):
401400
"""Create a Python TableWithMetadata from a libcudf table_with_metadata"""
402401
cdef TableWithMetadata out = TableWithMetadata.__new__(TableWithMetadata)
403-
stream = _get_stream(stream)
404-
mr = _get_memory_resource(mr)
405402
out.tbl = Table.from_libcudf(move(tbl_with_meta.tbl), stream, mr)
406403
out.metadata = tbl_with_meta.metadata
407404
return out

python/pylibcudf/pylibcudf/table.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ cdef class Table:
1919
@staticmethod
2020
cdef Table from_libcudf(
2121
unique_ptr[table] libcudf_tbl,
22-
Stream stream=*,
23-
DeviceMemoryResource mr=*
22+
Stream stream,
23+
DeviceMemoryResource mr
2424
)
2525

2626
@staticmethod

python/pylibcudf/pylibcudf/table.pyx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ from pylibcudf.libcudf.table.table cimport table
3333

3434
from .column cimport Column
3535
from .types cimport DataType
36-
from .utils cimport _get_stream, _get_memory_resource
3736
from pylibcudf._interop_helpers cimport (
3837
_release_schema,
3938
_release_array,
@@ -202,8 +201,8 @@ cdef class Table:
202201
@staticmethod
203202
cdef Table from_libcudf(
204203
unique_ptr[table] libcudf_tbl,
205-
Stream stream=None,
206-
DeviceMemoryResource mr=None
204+
Stream stream,
205+
DeviceMemoryResource mr
207206
):
208207
"""Create a Table from a libcudf table.
209208
@@ -214,8 +213,6 @@ cdef class Table:
214213
cdef vector[unique_ptr[column]] c_columns = dereference(libcudf_tbl).release()
215214

216215
cdef vector[unique_ptr[column]].size_type i
217-
stream = _get_stream(stream)
218-
mr = _get_memory_resource(mr)
219216
return Table([
220217
Column.from_libcudf(move(c_columns[i]), stream, mr)
221218
for i in range(c_columns.size())

0 commit comments

Comments
 (0)