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

[Breaking] Rename Quantile DMatrix C API. #7082

Merged
merged 1 commit into from Jul 8, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions include/xgboost/c_api.h
Expand Up @@ -234,8 +234,8 @@ XGB_DLL int XGDMatrixCreateFromDT(void** data,
* - XGProxyDMatrixCreate
* - XGDMatrixCallbackNext
* - DataIterResetCallback
* - XGDeviceQuantileDMatrixSetDataCudaArrayInterface
* - XGDeviceQuantileDMatrixSetDataCudaColumnar
* - XGProxyDMatrixSetDataCudaArrayInterface
* - XGProxyDMatrixSetDataCudaColumnar
* - ... (data setters)
*/

Expand Down Expand Up @@ -371,9 +371,10 @@ XGB_DLL int XGDeviceQuantileDMatrixCreateFromCallback(
*
* \return 0 when success, -1 when failure happens
*/
XGB_DLL int XGDeviceQuantileDMatrixSetDataCudaArrayInterface(
DMatrixHandle handle,
const char* c_interface_str);
XGB_DLL int
XGProxyDMatrixSetDataCudaArrayInterface(DMatrixHandle handle,
const char *c_interface_str);

/*!
* \brief Set data on a DMatrix proxy.
*
Expand All @@ -383,9 +384,9 @@ XGB_DLL int XGDeviceQuantileDMatrixSetDataCudaArrayInterface(
*
* \return 0 when success, -1 when failure happens
*/
XGB_DLL int XGDeviceQuantileDMatrixSetDataCudaColumnar(
DMatrixHandle handle,
const char* c_interface_str);
XGB_DLL int XGProxyDMatrixSetDataCudaColumnar(DMatrixHandle handle,
const char *c_interface_str);

/*
* ==========================- End data callback APIs ==========================
*/
Expand Down Expand Up @@ -563,7 +564,7 @@ XGB_DLL int XGDMatrixGetStrFeatureInfo(DMatrixHandle handle, const char *field,
* \return 0 when success, -1 when failure happens
*/
XGB_DLL int XGDMatrixSetDenseInfo(DMatrixHandle handle, const char *field,
void *data, bst_ulong size, int type);
void const *data, bst_ulong size, int type);

/*!
* \brief (deprecated) Use XGDMatrixSetUIntInfo instead. Set group of the training matrix
Expand Down
15 changes: 8 additions & 7 deletions python-package/xgboost/core.py
Expand Up @@ -322,6 +322,7 @@ def __init__(self):
self._handle = _ProxyDMatrix()
self.exception = None
self.enable_categorical = False
self._allow_host = False

@property
def proxy(self):
Expand Down Expand Up @@ -349,12 +350,12 @@ def data_handle(
feature_types=None,
**kwargs
):
from .data import dispatch_device_quantile_dmatrix_set_data
from .data import _device_quantile_transform
data, feature_names, feature_types = _device_quantile_transform(
from .data import dispatch_proxy_set_data
from .data import _proxy_transform
data, feature_names, feature_types = _proxy_transform(
data, feature_names, feature_types, self.enable_categorical,
)
dispatch_device_quantile_dmatrix_set_data(self.proxy, data)
dispatch_proxy_set_data(self.proxy, data, self._allow_host)
self.proxy.set_info(
feature_names=feature_names,
feature_types=feature_types,
Expand Down Expand Up @@ -1009,18 +1010,18 @@ def _set_data_from_cuda_interface(self, data):
interface = data.__cuda_array_interface__
interface_str = bytes(json.dumps(interface, indent=2), 'utf-8')
_check_call(
_LIB.XGDeviceQuantileDMatrixSetDataCudaArrayInterface(
_LIB.XGProxyDMatrixSetDataCudaArrayInterface(
self.handle,
interface_str
)
)

def _set_data_from_cuda_columnar(self, data):
'''Set data from CUDA columnar format.1'''
'''Set data from CUDA columnar format.'''
from .data import _cudf_array_interfaces
_, interfaces_str = _cudf_array_interfaces(data)
_check_call(
_LIB.XGDeviceQuantileDMatrixSetDataCudaColumnar(
_LIB.XGProxyDMatrixSetDataCudaColumnar(
self.handle,
interfaces_str
)
Expand Down
8 changes: 5 additions & 3 deletions python-package/xgboost/data.py
Expand Up @@ -775,7 +775,7 @@ def reset(self):
self.it = 0


def _device_quantile_transform(data, feature_names, feature_types, enable_categorical):
def _proxy_transform(data, feature_names, feature_types, enable_categorical):
if _is_cudf_df(data) or _is_cudf_ser(data):
return _transform_cudf_df(
data, feature_names, feature_types, enable_categorical
Expand All @@ -788,8 +788,8 @@ def _device_quantile_transform(data, feature_names, feature_types, enable_catego
raise TypeError("Value type is not supported for data iterator:" + str(type(data)))


def dispatch_device_quantile_dmatrix_set_data(proxy: _ProxyDMatrix, data: Any) -> None:
'''Dispatch for DeviceQuantileDMatrix.'''
def dispatch_proxy_set_data(proxy: _ProxyDMatrix, data: Any, allow_host: bool) -> None:
"""Dispatch for DeviceQuantileDMatrix."""
if _is_cudf_df(data):
proxy._set_data_from_cuda_columnar(data) # pylint: disable=W0212
return
Expand All @@ -803,5 +803,7 @@ def dispatch_device_quantile_dmatrix_set_data(proxy: _ProxyDMatrix, data: Any) -
data = _transform_dlpack(data)
proxy._set_data_from_cuda_interface(data) # pylint: disable=W0212
return
# Part of https://github.com/dmlc/xgboost/pull/7070
assert allow_host is False, "host data is not yet supported."
raise TypeError('Value type is not supported for data iterator:' +
str(type(data)))
11 changes: 5 additions & 6 deletions src/c_api/c_api.cc
Expand Up @@ -197,8 +197,8 @@ XGB_DLL int XGProxyDMatrixCreate(DMatrixHandle* out) {
}

XGB_DLL int
XGDeviceQuantileDMatrixSetDataCudaArrayInterface(DMatrixHandle handle,
char const *c_interface_str) {
XGProxyDMatrixSetDataCudaArrayInterface(DMatrixHandle handle,
char const *c_interface_str) {
API_BEGIN();
CHECK_HANDLE();
auto p_m = static_cast<std::shared_ptr<xgboost::DMatrix> *>(handle);
Expand All @@ -209,9 +209,8 @@ XGDeviceQuantileDMatrixSetDataCudaArrayInterface(DMatrixHandle handle,
API_END();
}

XGB_DLL int
XGDeviceQuantileDMatrixSetDataCudaColumnar(DMatrixHandle handle,
char const *c_interface_str) {
XGB_DLL int XGProxyDMatrixSetDataCudaColumnar(DMatrixHandle handle,
char const *c_interface_str) {
API_BEGIN();
CHECK_HANDLE();
auto p_m = static_cast<std::shared_ptr<xgboost::DMatrix> *>(handle);
Expand Down Expand Up @@ -433,7 +432,7 @@ XGB_DLL int XGDMatrixGetStrFeatureInfo(DMatrixHandle handle, const char *field,
}

XGB_DLL int XGDMatrixSetDenseInfo(DMatrixHandle handle, const char *field,
void *data, xgboost::bst_ulong size,
void const *data, xgboost::bst_ulong size,
int type) {
API_BEGIN();
CHECK_HANDLE();
Expand Down
2 changes: 1 addition & 1 deletion tests/cpp/helpers.cu
Expand Up @@ -23,7 +23,7 @@ int CudaArrayIterForTest::Next() {
if (iter_ == n_batches_) {
return 0;
}
XGDeviceQuantileDMatrixSetDataCudaArrayInterface(proxy_, batches_[iter_].c_str());
XGProxyDMatrixSetDataCudaArrayInterface(proxy_, batches_[iter_].c_str());
iter_++;
return 1;
}
Expand Down