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

Update for thrust 1.17 and fixes to accommodate for cuDF Buffer refactor #4871

Merged
merged 8 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/cmake/thirdparty/get_gputreeshap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ function(find_and_configure_gputreeshap)

endfunction()

find_and_configure_gputreeshap(PINNED_TAG c78fe621e429117cbca45e7b23eb5c3b6280fa3a)
find_and_configure_gputreeshap(PINNED_TAG 78e3548cda5e7c263d125e8c10e733ebf2c4ebbd)
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ __global__ void excess_sample_with_replacement_kernel(
// compute the adjacent differences according to the functor
// TODO: Replace deprecated 'FlagHeads' with 'SubtractLeft' when it is available
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO: Replace deprecated 'FlagHeads' with 'SubtractLeft' when it is available

We can remove this comment now.

BlockAdjacentDifferenceT(temp_storage.diff)
.FlagHeads(mask, items, mask, CustomDifference<IdxT>());
.SubtractLeft(items, mask, CustomDifference<IdxT>(), mask[0]);

__syncthreads();

Expand Down
105 changes: 80 additions & 25 deletions python/cuml/common/array.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020-2021, NVIDIA CORPORATION.
# Copyright (c) 2020-2022, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -18,10 +18,11 @@
import numpy as np
import operator
import nvtx
import rmm

# Temporarily disabled due to CUDA 11.0 issue
# https://github.com/rapidsai/cuml/issues/4332
# from rmm import DeviceBuffer
from rmm import DeviceBuffer
from cudf import DataFrame
from cudf import Series
from cudf.core.buffer import Buffer
Expand All @@ -31,6 +32,7 @@
from cuml.common.memory_utils import _strides_to_order
from cuml.common.memory_utils import class_with_cupy_rmm
from numba import cuda
from typing import Tuple


@class_with_cupy_rmm(ignore_pattern=["serialize"])
Expand Down Expand Up @@ -137,26 +139,45 @@ def __init__(self,

ary_interface = False

# Base class (Buffer) constructor call
size, shape = _get_size_from_shape(shape, dtype)

if not memview_construction and not detailed_construction:
# Convert to cupy array and manually specify the ptr, size and
# owner. This is to avoid the restriction on Buffer that requires
# all data be u8
cupy_data = cp.asarray(data)
flattened_data = cupy_data.data.ptr

# Size for Buffer is not the same as for cupy. Use nbytes
size = cupy_data.nbytes
owner = cupy_data if cupy_data.flags.owndata else data
else:
flattened_data = data
data = cupy_data

self._index = index
super().__init__(data=flattened_data,
owner=owner,
size=size)

if hasattr(data, "__array_interface__"):
ary_interface = data.__array_interface__
elif hasattr(data, "__cuda_array_interface__"):
ary_interface = data.__cuda_array_interface__

# We no longer call the super init due to the refactor
if isinstance(data, int):
wphicks marked this conversation as resolved.
Show resolved Hide resolved
if size is None:
raise ValueError(
"size must be specified when `data` is an integer"
)
if size < 0:
raise ValueError("size cannot be negative")
self._ptr = data
self._size = size
self._owner = owner

elif isinstance(data, DeviceBuffer) or isinstance(data, Buffer):
self._ptr = data.ptr
self._size = data.size
self._owner = data

elif ary_interface:
ptr = ary_interface["data"][0] or 0
self._ptr = ptr
self._size = size
self._owner = data

# Post processing of meta data
if detailed_construction:
Expand All @@ -165,16 +186,7 @@ def __init__(self,
self.order = order
self.strides = _order_to_strides(order, shape, dtype)

elif hasattr(data, "__array_interface__"):
ary_interface = data.__array_interface__

elif hasattr(data, "__cuda_array_interface__"):
ary_interface = data.__cuda_array_interface__

else:
raise TypeError("Unrecognized data type: %s" % str(type(data)))

if ary_interface:
elif ary_interface:
self.shape = ary_interface['shape']
self.dtype = np.dtype(ary_interface['typestr'])
if ary_interface.get('strides', None) is None:
Expand All @@ -185,6 +197,9 @@ def __init__(self,
self.strides = ary_interface['strides']
self.order = _strides_to_order(self.strides, self.dtype)

else:
raise TypeError("Unrecognized data type: %s" % str(type(data)))

# We use the index as a property to allow for validation/processing
# in the future if needed
@property
Expand Down Expand Up @@ -311,18 +326,58 @@ def to_output(self, output_type='cupy', output_dtype=None):

return self

@nvtx.annotate(message="common.CumlArray.host_serialize", category="utils",
domain="cuml_python")
def host_serialize(self):
"""Serialize data and metadata associated with host memory.
Returns
-------
header : dict
The metadata required to reconstruct the object.
frames : list
The Buffers or memoryviews that the object should contain.
:meta private:
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def host_serialize(self):
"""Serialize data and metadata associated with host memory.
Returns
-------
header : dict
The metadata required to reconstruct the object.
frames : list
The Buffers or memoryviews that the object should contain.
:meta private:
"""
def host_serialize(self):
"""
Serialize data and metadata associated with host memory.
Returns
-------
header : dict
The metadata required to reconstruct the object.
frames : list
The Buffers or memoryviews that the object should contain.
:meta private:
"""

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to fix the current error in CI:


Warning, treated as error:
/workspace/python/cuml/common/array.py:docstring of cuml.common.array.CumlArray.host_serialize:6:Unexpected indentation.
make: *** [Makefile:20: html] Error 2

header, frames = self.device_serialize()
header["writeable"] = len(frames) * (None,)
frames = [
f.to_host_array().data if c else memoryview(f)
for c, f in zip(header["is-cuda"], frames)
]
return header, frames

@nvtx.annotate(message="common.CumlArray.serialize", category="utils",
domain="cuml_python")
def serialize(self):
def serialize(self) -> Tuple[dict, list]:
header, frames = super().serialize()
header["constructor-kwargs"] = {
"dtype": self.dtype.str,
"shape": self.shape,
"order": self.order,
}
frames = [Buffer(f) for f in frames]
frames = [CumlArray(f) for f in frames]
return header, frames

@nvtx.annotate(message="common.CumlArray.copy", category="utils",
domain="cuml_python")
def copy(self) -> Buffer:
"""
Create a new Buffer containing a copy of the data contained
in this Buffer.
"""
from rmm._lib.device_buffer import copy_device_to_ptr

out = Buffer.empty(size=self.size)
copy_device_to_ptr(self.ptr, out.ptr, self.size)
return out

@nvtx.annotate(message="common.CumlArray.to_host_array", category="utils",
domain="cuml_python")
def to_host_array(self):
data = np.empty((self.size,), "u1")
rmm._lib.device_buffer.copy_ptr_to_host(self.ptr, data)
return data

@classmethod
@nvtx.annotate(message="common.CumlArray.empty", category="utils",
domain="cuml_python")
Expand Down Expand Up @@ -420,7 +475,7 @@ def ones(cls,
def _check_low_level_type(data):
if isinstance(data, CumlArray):
return False
elif not (
if not (
hasattr(data, "__array_interface__")
or hasattr(data, "__cuda_array_interface__")
# Temporarily disabled due to CUDA 11.0 issue
Expand Down