Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for __cuda_array_interface__ tests #15188

Merged
merged 4 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion python/cudf/cudf/core/single_column_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ def __cuda_array_interface__(self):
try:
return self._column.__cuda_array_interface__
except NotImplementedError:
raise AttributeError
raise AttributeError(
f"'{type(self).__name__}' object has no attribute "
"'__cuda_array_interface__'"
)

@_cudf_nvtx_annotate
def factorize(self, sort=False, use_na_sentinel=True):
Expand Down
20 changes: 13 additions & 7 deletions python/cudf/cudf/tests/test_cuda_array_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from contextlib import ExitStack as does_not_raise

import cupy
import numba.cuda
import numpy as np
import pandas as pd
import pytest
from numba import cuda

import cudf
from cudf.core.buffer.spill_manager import get_global_manager
Expand All @@ -25,7 +25,7 @@ def test_cuda_array_interface_interop_in(dtype, module):
if dtype in DATETIME_TYPES:
expectation = pytest.raises(ValueError)
elif module == "numba":
module_constructor = cuda.to_device
module_constructor = numba.cuda.to_device

with expectation:
module_data = module_constructor(np_data)
Expand Down Expand Up @@ -55,7 +55,7 @@ def to_host_function(x):
return cupy.asnumpy(x)

elif module == "numba":
module_constructor = cuda.as_cuda_array
module_constructor = numba.cuda.as_cuda_array

def to_host_function(x):
return x.copy_to_host()
Expand Down Expand Up @@ -89,7 +89,7 @@ def to_host_function(x):

elif module == "numba":
expectation = pytest.raises(NotImplementedError)
module_constructor = cuda.as_cuda_array
module_constructor = numba.cuda.as_cuda_array

def to_host_function(x):
return x.copy_to_host()
Expand Down Expand Up @@ -135,9 +135,11 @@ def test_cuda_array_interface_as_column(dtype, nulls, mask_type):

if mask_type == "bools":
if nulls == "some":
obj.__cuda_array_interface__["mask"] = cuda.to_device(mask)
obj.__cuda_array_interface__["mask"] = numba.cuda.to_device(mask)
elif nulls == "all":
obj.__cuda_array_interface__["mask"] = cuda.to_device([False] * 10)
obj.__cuda_array_interface__["mask"] = numba.cuda.to_device(
[False] * 10
)

expect = sr
got = cudf.Series(obj)
Expand Down Expand Up @@ -193,7 +195,11 @@ def test_cuda_array_interface_pytorch():

assert_eq(got, cudf.Series(buffer, dtype=np.bool_))

# TODO: This test fails with PyTorch 2. Is it still expected to be valid?
# TODO: This test fails with PyTorch 2. It appears that PyTorch
# checks that the pointer is device-accessible even when the
# size is zero. See
# https://github.com/pytorch/pytorch/issues/98133
#
# index = cudf.Index([], dtype="float64")
vyasr marked this conversation as resolved.
Show resolved Hide resolved
# tensor = torch.tensor(index)
# got = cudf.Index(tensor)
Expand Down
Loading