-
Notifications
You must be signed in to change notification settings - Fork 513
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
rapids-bot
merged 8 commits into
rapidsai:branch-22.10
from
dantegd:fix-deprecated-thrust-117
Aug 25, 2022
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ee8cf58
FIX Updat deprecated thrust call
dantegd 92e385f
FIX pin gputreeshap temporarily
dantegd 4ca8e42
FIX clang-format
dantegd 001930c
FIX cumlarray changes to accomodate for cudf buffer refactor
dantegd 901e603
FIX copyright year
dantegd 0fd68ea
FIX Use Gputreeshap from main repo again
dantegd 407aa96
FIX remove host_serialize docstring
dantegd 69b01ea
FIX remove host_serialize docstring
dantegd File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,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. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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"]) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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: | ||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to fix the current error in CI:
|
||||||||||||||||||||||||||||||||||||||||||||||||
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") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this comment now.