Skip to content

Commit 06427ab

Browse files
authored
Add memory resources to reduce, column, column_factories, and contiguous_split (#20135)
Contributes to #15170 Authors: - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Bradley Dice (https://github.com/bdice) URL: #20135
1 parent 166598f commit 06427ab

File tree

16 files changed

+283
-94
lines changed

16 files changed

+283
-94
lines changed

python/pylibcudf/pylibcudf/column.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ cdef class Column:
8787
cpdef gpumemoryview data(self)
8888
cpdef gpumemoryview null_mask(self)
8989
cpdef list children(self)
90-
cpdef Column copy(self, Stream stream=*)
90+
cpdef Column copy(self, Stream stream=*, DeviceMemoryResource mr=*)
9191
cpdef uint64_t device_buffer_size(self)
9292
cpdef Column with_mask(self, gpumemoryview, size_type)
9393

python/pylibcudf/pylibcudf/column.pyi

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,22 @@ class Column:
5252
def data(self) -> gpumemoryview | None: ...
5353
def null_mask(self) -> gpumemoryview | None: ...
5454
def children(self) -> list[Column]: ...
55-
def copy(self, stream: Stream | None = None) -> Column: ...
55+
def copy(
56+
self,
57+
stream: Stream | None = None,
58+
mr: DeviceMemoryResource | None = None,
59+
) -> Column: ...
5660
def device_buffer_size(self) -> int: ...
5761
def with_mask(
5862
self, mask: gpumemoryview | None, null_count: int
5963
) -> Column: ...
6064
def list_view(self) -> ListColumnView: ...
6165
@staticmethod
6266
def from_scalar(
63-
scalar: Scalar, size: int, stream: Stream | None = None
67+
scalar: Scalar,
68+
size: int,
69+
stream: Stream | None = None,
70+
mr: DeviceMemoryResource | None = None,
6471
) -> Column: ...
6572
def to_scalar(
6673
self,
@@ -69,7 +76,10 @@ class Column:
6976
) -> Scalar: ...
7077
@staticmethod
7178
def all_null_like(
72-
like: Column, size: int, stream: Stream | None = None
79+
like: Column,
80+
size: int,
81+
stream: Stream | None = None,
82+
mr: DeviceMemoryResource | None = None,
7383
) -> Column: ...
7484
@staticmethod
7585
def from_rmm_buffer(

python/pylibcudf/pylibcudf/column.pyx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,12 @@ cdef class Column:
747747
)
748748

749749
@staticmethod
750-
def from_scalar(Scalar slr, size_type size, Stream stream=None):
750+
def from_scalar(
751+
Scalar slr,
752+
size_type size,
753+
Stream stream=None,
754+
DeviceMemoryResource mr=None,
755+
):
751756
"""Create a Column from a Scalar.
752757
753758
Parameters
@@ -767,13 +772,15 @@ cdef class Column:
767772
cdef const scalar* c_scalar = slr.get()
768773
cdef unique_ptr[column] c_result
769774
stream = _get_stream(stream)
775+
mr = _get_memory_resource(mr)
770776
with nogil:
771777
c_result = make_column_from_scalar(
772778
dereference(c_scalar),
773779
size,
774-
stream.view()
780+
stream.view(),
781+
mr.get_mr()
775782
)
776-
return Column.from_libcudf(move(c_result), stream)
783+
return Column.from_libcudf(move(c_result), stream, mr)
777784

778785
cpdef Scalar to_scalar(self, Stream stream=None, DeviceMemoryResource mr=None):
779786
"""
@@ -807,7 +814,12 @@ cdef class Column:
807814
return Scalar.from_libcudf(move(result))
808815

809816
@staticmethod
810-
def all_null_like(Column like, size_type size, Stream stream=None):
817+
def all_null_like(
818+
Column like,
819+
size_type size,
820+
Stream stream=None,
821+
DeviceMemoryResource mr=None,
822+
):
811823
"""Create an all null column from a template.
812824
813825
Parameters
@@ -827,13 +839,15 @@ cdef class Column:
827839
cdef Scalar slr = Scalar.empty_like(like)
828840
cdef unique_ptr[column] c_result
829841
stream = _get_stream(stream)
842+
mr = _get_memory_resource(mr)
830843
with nogil:
831844
c_result = make_column_from_scalar(
832845
dereference(slr.get()),
833846
size,
834-
stream.view()
847+
stream.view(),
848+
mr.get_mr()
835849
)
836-
return Column.from_libcudf(move(c_result), stream)
850+
return Column.from_libcudf(move(c_result), stream, mr)
837851

838852
@staticmethod
839853
cdef Column _wrap_nested_list_column(
@@ -1250,13 +1264,14 @@ cdef class Column:
12501264
"""The children of the column."""
12511265
return self._children
12521266

1253-
cpdef Column copy(self, Stream stream=None):
1267+
cpdef Column copy(self, Stream stream=None, DeviceMemoryResource mr=None):
12541268
"""Create a copy of the column."""
12551269
cdef unique_ptr[column] c_result
12561270
stream = _get_stream(stream)
1271+
mr = _get_memory_resource(mr)
12571272
with nogil:
12581273
c_result = make_unique[column](self.view(), stream.view())
1259-
return Column.from_libcudf(move(c_result), stream)
1274+
return Column.from_libcudf(move(c_result), stream, mr)
12601275

12611276
cpdef uint64_t device_buffer_size(self):
12621277
"""

python/pylibcudf/pylibcudf/column_factories.pxd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) 2024-2025, NVIDIA CORPORATION.
22
from pylibcudf.libcudf.types cimport mask_state
3+
from rmm.pylibrmm.memory_resource cimport DeviceMemoryResource
34
from rmm.pylibrmm.stream cimport Stream
45

56
from .column cimport Column
@@ -18,39 +19,45 @@ ctypedef fused MaskArg:
1819
cpdef Column make_empty_column(
1920
MakeEmptyColumnOperand type_or_id,
2021
Stream stream=*,
22+
DeviceMemoryResource mr=*,
2123
)
2224

2325
cpdef Column make_numeric_column(
2426
DataType type_,
2527
size_type size,
2628
MaskArg mask,
2729
Stream stream = *,
30+
DeviceMemoryResource mr = *,
2831
)
2932

3033
cpdef Column make_fixed_point_column(
3134
DataType type_,
3235
size_type size,
3336
MaskArg mask,
3437
Stream stream = *,
38+
DeviceMemoryResource mr = *,
3539
)
3640

3741
cpdef Column make_timestamp_column(
3842
DataType type_,
3943
size_type size,
4044
MaskArg mask,
4145
Stream stream = *,
46+
DeviceMemoryResource mr = *,
4247
)
4348

4449
cpdef Column make_duration_column(
4550
DataType type_,
4651
size_type size,
4752
MaskArg mask,
4853
Stream stream = *,
54+
DeviceMemoryResource mr = *,
4955
)
5056

5157
cpdef Column make_fixed_width_column(
5258
DataType type_,
5359
size_type size,
5460
MaskArg mask,
5561
Stream stream = *,
62+
DeviceMemoryResource mr = *,
5663
)
Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright (c) 2024, NVIDIA CORPORATION.
2+
from rmm.pylibrmm.memory_resource import DeviceMemoryResource
23
from rmm.pylibrmm.stream import Stream
34

45
from pylibcudf.column import Column
@@ -7,19 +8,40 @@ from pylibcudf.types import DataType, MaskState, TypeId
78
def make_empty_column(
89
type_or_id: DataType | TypeId,
910
stream: Stream | None = None,
11+
mr: DeviceMemoryResource | None = None,
1012
) -> Column: ...
1113
def make_numeric_column(
12-
type_: DataType, size: int, mstate: MaskState, stream: Stream | None = None
14+
type_: DataType,
15+
size: int,
16+
mstate: MaskState,
17+
stream: Stream | None = None,
18+
mr: DeviceMemoryResource | None = None,
1319
) -> Column: ...
1420
def make_fixed_point_column(
15-
type_: DataType, size: int, mstate: MaskState, stream: Stream | None = None
21+
type_: DataType,
22+
size: int,
23+
mstate: MaskState,
24+
stream: Stream | None = None,
25+
mr: DeviceMemoryResource | None = None,
1626
) -> Column: ...
1727
def make_timestamp_column(
18-
type_: DataType, size: int, mstate: MaskState, stream: Stream | None = None
28+
type_: DataType,
29+
size: int,
30+
mstate: MaskState,
31+
stream: Stream | None = None,
32+
mr: DeviceMemoryResource | None = None,
1933
) -> Column: ...
2034
def make_duration_column(
21-
type_: DataType, size: int, mstate: MaskState, stream: Stream | None = None
35+
type_: DataType,
36+
size: int,
37+
mstate: MaskState,
38+
stream: Stream | None = None,
39+
mr: DeviceMemoryResource | None = None,
2240
) -> Column: ...
2341
def make_fixed_width_column(
24-
type_: DataType, size: int, mstate: MaskState, stream: Stream | None = None
42+
type_: DataType,
43+
size: int,
44+
mstate: MaskState,
45+
stream: Stream | None = None,
46+
mr: DeviceMemoryResource | None = None,
2547
) -> Column: ...

0 commit comments

Comments
 (0)