-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate filling operations to pylibcudf (#15225)
This PR migrates the filling operations in cuDF Python to pylibcudf. Authors: - https://github.com/brandon-b-miller - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Vyas Ramasubramani (https://github.com/vyasr) URL: #15225
- Loading branch information
1 parent
9678c90
commit 352d686
Showing
9 changed files
with
250 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -379,6 +379,7 @@ def _generate_namespaces(namespaces): | |
"type_id", | ||
# Unknown base types | ||
"int32_t", | ||
"void" | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
======== | ||
filling | ||
======== | ||
|
||
.. automodule:: cudf._lib.pylibcudf.filling | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,57 @@ | ||
# Copyright (c) 2020-2022, NVIDIA CORPORATION. | ||
# Copyright (c) 2020-2024, NVIDIA CORPORATION. | ||
|
||
from cudf.core.buffer import acquire_spill_lock | ||
|
||
from libcpp.memory cimport unique_ptr | ||
from libcpp.utility cimport move | ||
|
||
cimport cudf._lib.cpp.filling as cpp_filling | ||
from cudf._lib.column cimport Column | ||
from cudf._lib.cpp.column.column cimport column | ||
from cudf._lib.cpp.column.column_view cimport column_view, mutable_column_view | ||
from cudf._lib.cpp.scalar.scalar cimport scalar | ||
from cudf._lib.cpp.table.table cimport table | ||
from cudf._lib.cpp.table.table_view cimport table_view | ||
from cudf._lib.cpp.types cimport size_type | ||
from cudf._lib.scalar cimport DeviceScalar | ||
from cudf._lib.utils cimport columns_from_unique_ptr, table_view_from_columns | ||
from cudf._lib.utils cimport columns_from_pylibcudf_table | ||
|
||
from cudf._lib import pylibcudf | ||
from cudf._lib.scalar import as_device_scalar | ||
|
||
|
||
@acquire_spill_lock() | ||
def fill_in_place(Column destination, int begin, int end, DeviceScalar value): | ||
cdef mutable_column_view c_destination = destination.mutable_view() | ||
cdef size_type c_begin = <size_type> begin | ||
cdef size_type c_end = <size_type> end | ||
cdef const scalar* c_value = value.get_raw_ptr() | ||
|
||
cpp_filling.fill_in_place( | ||
c_destination, | ||
c_begin, | ||
c_end, | ||
c_value[0] | ||
pylibcudf.filling.fill_in_place( | ||
destination.to_pylibcudf(mode='write'), | ||
begin, | ||
end, | ||
(<DeviceScalar> as_device_scalar(value, dtype=destination.dtype)).c_value | ||
) | ||
|
||
|
||
@acquire_spill_lock() | ||
def fill(Column destination, int begin, int end, DeviceScalar value): | ||
cdef column_view c_destination = destination.view() | ||
cdef size_type c_begin = <size_type> begin | ||
cdef size_type c_end = <size_type> end | ||
cdef const scalar* c_value = value.get_raw_ptr() | ||
cdef unique_ptr[column] c_result | ||
|
||
with nogil: | ||
c_result = move(cpp_filling.fill( | ||
c_destination, | ||
c_begin, | ||
c_end, | ||
c_value[0] | ||
)) | ||
|
||
return Column.from_unique_ptr(move(c_result)) | ||
return Column.from_pylibcudf( | ||
pylibcudf.filling.fill( | ||
destination.to_pylibcudf(mode='read'), | ||
begin, | ||
end, | ||
(<DeviceScalar> as_device_scalar(value)).c_value | ||
) | ||
) | ||
|
||
|
||
@acquire_spill_lock() | ||
def repeat(list inp, object count): | ||
ctbl = pylibcudf.Table([col.to_pylibcudf(mode="read") for col in inp]) | ||
if isinstance(count, Column): | ||
return _repeat_via_column(inp, count) | ||
else: | ||
return _repeat_via_size_type(inp, count) | ||
|
||
|
||
def _repeat_via_column(list inp, Column count): | ||
cdef table_view c_inp = table_view_from_columns(inp) | ||
cdef column_view c_count = count.view() | ||
cdef unique_ptr[table] c_result | ||
|
||
with nogil: | ||
c_result = move(cpp_filling.repeat( | ||
c_inp, | ||
c_count, | ||
)) | ||
|
||
return columns_from_unique_ptr(move(c_result)) | ||
|
||
|
||
def _repeat_via_size_type(list inp, size_type count): | ||
cdef table_view c_inp = table_view_from_columns(inp) | ||
cdef unique_ptr[table] c_result | ||
|
||
with nogil: | ||
c_result = move(cpp_filling.repeat( | ||
c_inp, | ||
count = count.to_pylibcudf(mode="read") | ||
return columns_from_pylibcudf_table( | ||
pylibcudf.filling.repeat( | ||
ctbl, | ||
count | ||
)) | ||
|
||
return columns_from_unique_ptr(move(c_result)) | ||
) | ||
) | ||
|
||
|
||
@acquire_spill_lock() | ||
def sequence(int size, DeviceScalar init, DeviceScalar step): | ||
cdef size_type c_size = size | ||
cdef const scalar* c_init = init.get_raw_ptr() | ||
cdef const scalar* c_step = step.get_raw_ptr() | ||
cdef unique_ptr[column] c_result | ||
|
||
with nogil: | ||
c_result = move(cpp_filling.sequence( | ||
c_size, | ||
c_init[0], | ||
c_step[0] | ||
)) | ||
|
||
return Column.from_unique_ptr(move(c_result)) | ||
return Column.from_pylibcudf( | ||
pylibcudf.filling.sequence( | ||
size, | ||
(<DeviceScalar> as_device_scalar(init)).c_value, | ||
(<DeviceScalar> as_device_scalar(step)).c_value | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
from cudf._lib.cpp.types cimport size_type | ||
|
||
from .column cimport Column | ||
from .scalar cimport Scalar | ||
from .table cimport Table | ||
|
||
ctypedef fused ColumnOrSize: | ||
Column | ||
size_type | ||
|
||
cpdef Column fill( | ||
Column destination, | ||
size_type begin, | ||
size_type end, | ||
Scalar value, | ||
) | ||
|
||
cpdef void fill_in_place( | ||
Column destination, | ||
size_type c_begin, | ||
size_type c_end, | ||
Scalar value, | ||
) | ||
|
||
cpdef Column sequence( | ||
size_type size, | ||
Scalar init, | ||
Scalar step, | ||
) | ||
|
||
cpdef Table repeat( | ||
Table input_table, | ||
ColumnOrSize count | ||
) |
Oops, something went wrong.