Skip to content

Commit

Permalink
Use pylibcudf only in pure Python mode
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasr committed Aug 17, 2023
1 parent 984a67a commit c0816e9
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 24 deletions.
3 changes: 1 addition & 2 deletions python/cudf/cudf/_lib/column.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ from libcpp.memory cimport unique_ptr

from rmm._lib.device_buffer cimport device_buffer

from cudf._lib cimport pylibcudf
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.types cimport size_type
Expand All @@ -30,7 +29,7 @@ cdef class Column:
cdef column_view _view(self, size_type null_count) except *
cdef column_view view(self) except *
cdef mutable_column_view mutable_view(self) except *
cpdef pylibcudf.Column to_pylibcudf(self, mode: Literal["read", "write"])
cpdef to_pylibcudf(self, mode: Literal["read", "write"])

@staticmethod
cdef Column from_unique_ptr(
Expand Down
13 changes: 5 additions & 8 deletions python/cudf/cudf/_lib/column.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import rmm
import cudf
import cudf._lib as libcudf
from cudf._lib import pylibcudf

from cudf._lib cimport pylibcudf

from cudf.api.types import is_categorical_dtype, is_datetime64tz_dtype
from cudf.core.buffer import (
Buffer,
Expand Down Expand Up @@ -447,7 +444,7 @@ cdef class Column:
# underlying buffers as exposed before this function can itself be exposed
# publicly. User requests to convert to pylibcudf must assume that the
# data may be modified afterwards.
cpdef pylibcudf.Column to_pylibcudf(self, mode: Literal["read", "write"]):
cpdef to_pylibcudf(self, mode: Literal["read", "write"]):
"""Convert this Column to a pylibcudf.Column.
This function will generate a pylibcudf Column pointing to the same
Expand Down Expand Up @@ -477,9 +474,9 @@ cdef class Column:
else:
col = self

cdef pylibcudf.DataType dtype = dtype_to_pylibcudf_type(col.dtype)
dtype = dtype_to_pylibcudf_type(col.dtype)

cdef pylibcudf.gpumemoryview data = None
data = None
if col.base_data is not None:
cai = cuda_array_interface_wrapper(
ptr=col.base_data.get_ptr(mode=mode),
Expand All @@ -488,7 +485,7 @@ cdef class Column:
)
data = pylibcudf.gpumemoryview(cai)

cdef pylibcudf.gpumemoryview mask = None
mask = None
if self.nullable:
# TODO: Are we intentionally use self's mask instead of col's?
# Where is the mask stored for categoricals?
Expand Down Expand Up @@ -587,7 +584,7 @@ cdef class Column:
# TODO: Actually support exposed data pointers.
@staticmethod
def from_pylibcudf(
pylibcudf.Column col, bint data_ptr_exposed=False
col, bint data_ptr_exposed=False
):
"""Create a Column from a pylibcudf.Column.
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/_lib/copying.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ from libcpp.vector cimport vector
from rmm._lib.device_buffer cimport DeviceBuffer

import cudf
from cudf._lib import pylibcudf
from cudf.core.buffer import Buffer, acquire_spill_lock, as_buffer

from cudf._lib cimport pylibcudf
from cudf._lib.column cimport Column

from cudf._lib.scalar import as_device_scalar
Expand Down Expand Up @@ -174,7 +174,7 @@ def gather(
Column gather_map,
bool nullify=False
):
cdef pylibcudf.Table tbl = pylibcudf.copying.gather(
tbl = pylibcudf.copying.gather(
pylibcudf.Table([col.to_pylibcudf(mode="read") for col in columns]),
gather_map.to_pylibcudf(mode="read"),
pylibcudf.copying.OutOfBoundsPolicy.NULLIFY if nullify
Expand Down
3 changes: 1 addition & 2 deletions python/cudf/cudf/_lib/types.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ from libc.stdint cimport int32_t
from libcpp cimport bool

cimport cudf._lib.cpp.types as libcudf_types
from cudf._lib cimport pylibcudf
from cudf._lib.cpp.column.column_view cimport column_view
from cudf._lib.cpp.lists.lists_column_view cimport lists_column_view

Expand All @@ -18,5 +17,5 @@ ctypedef bool underlying_type_t_null_policy
cdef dtype_from_column_view(column_view cv)

cdef libcudf_types.data_type dtype_to_data_type(dtype) except *
cpdef pylibcudf.DataType dtype_to_pylibcudf_type(dtype)
cpdef dtype_to_pylibcudf_type(dtype)
cdef bool is_decimal_type_id(libcudf_types.type_id tid) except *
9 changes: 4 additions & 5 deletions python/cudf/cudf/_lib/types.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ from cudf._lib.types cimport (

import cudf
from cudf._lib import pylibcudf
from cudf._lib cimport pylibcudf

size_type_dtype = np.dtype("int32")

Expand Down Expand Up @@ -257,7 +256,7 @@ cdef libcudf_types.data_type dtype_to_data_type(dtype) except *:
else:
return libcudf_types.data_type(tid)

cpdef pylibcudf.DataType dtype_to_pylibcudf_type(dtype):
cpdef dtype_to_pylibcudf_type(dtype):
if cudf.api.types.is_list_dtype(dtype):
return pylibcudf.DataType(pylibcudf.TypeId.LIST)
elif cudf.api.types.is_struct_dtype(dtype):
Expand All @@ -282,7 +281,7 @@ cdef bool is_decimal_type_id(libcudf_types.type_id tid) except *:
)


def dtype_from_pylibcudf_lists_column(pylibcudf.Column col):
def dtype_from_pylibcudf_lists_column(col):
child = col.list_view().child()
tid = child.type().id()

Expand All @@ -296,15 +295,15 @@ def dtype_from_pylibcudf_lists_column(pylibcudf.Column col):
)


def dtype_from_pylibcudf_structs_column(pylibcudf.Column col):
def dtype_from_pylibcudf_structs_column(col):
fields = {
str(i): dtype_from_pylibcudf_column(col.child(i))
for i in range(col.num_children())
}
return cudf.StructDtype(fields)


def dtype_from_pylibcudf_column(pylibcudf.Column col):
def dtype_from_pylibcudf_column(col):
type_ = col.type()
tid = type_.id()

Expand Down
3 changes: 1 addition & 2 deletions python/cudf/cudf/_lib/utils.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ from libcpp.memory cimport unique_ptr
from libcpp.string cimport string
from libcpp.vector cimport vector

from cudf._lib cimport pylibcudf
from cudf._lib.cpp.column.column cimport column_view
from cudf._lib.cpp.table.table cimport table, table_view

Expand All @@ -19,4 +18,4 @@ cdef table_view table_view_from_columns(columns) except *
cdef table_view table_view_from_table(tbl, ignore_index=*) except*
cdef columns_from_unique_ptr(unique_ptr[table] c_tbl)
cdef columns_from_table_view(table_view tv, object owners)
cdef columns_from_pylibcudf_table(pylibcudf.Table table)
cdef columns_from_pylibcudf_table(tbl)
4 changes: 1 addition & 3 deletions python/cudf/cudf/_lib/utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ from libcpp.string cimport string
from libcpp.utility cimport move
from libcpp.vector cimport vector

from cudf._lib cimport pylibcudf
from cudf._lib.column cimport Column
from cudf._lib.cpp.column.column cimport column, column_view
from cudf._lib.cpp.table.table cimport table
Expand Down Expand Up @@ -247,7 +246,7 @@ cdef columns_from_unique_ptr(
return columns


cdef columns_from_pylibcudf_table(pylibcudf.Table tbl):
cdef columns_from_pylibcudf_table(tbl):
"""Convert a pylibcudf table into list of columns.
Parameters
Expand All @@ -260,7 +259,6 @@ cdef columns_from_pylibcudf_table(pylibcudf.Table tbl):
list[Column]
A list of columns.
"""
cdef pylibcudf.Column plc
return [Column.from_pylibcudf(plc) for plc in tbl.columns()]


Expand Down

0 comments on commit c0816e9

Please sign in to comment.