finish host_device_vector.cu
This commit is contained in:
parent
14cc438a64
commit
d27f9dfdce
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* Copyright 2017 XGBoost contributors
|
||||
*/
|
||||
#ifndef XGBOOST_USE_CUDA
|
||||
#if !defined(XGBOOST_USE_CUDA) && !defined(XGBOOST_USE_HIP)
|
||||
|
||||
// dummy implementation of HostDeviceVector in case CUDA is not used
|
||||
|
||||
@ -197,4 +197,4 @@ template class HostDeviceVector<std::size_t>;
|
||||
|
||||
} // namespace xgboost
|
||||
|
||||
#endif // XGBOOST_USE_CUDA
|
||||
#endif // XGBOOST_USE_CUDA && !defined(XGBOOST_USE_HIP)
|
||||
|
||||
@ -12,7 +12,12 @@
|
||||
#include "xgboost/data.h"
|
||||
#include "xgboost/host_device_vector.h"
|
||||
#include "xgboost/tree_model.h"
|
||||
|
||||
#if defined(XGBOOST_USE_CUDA)
|
||||
#include "device_helpers.cuh"
|
||||
#elif defined(XGBOOST_USE_HIP)
|
||||
#include "device_helpers.hip.h"
|
||||
#endif
|
||||
|
||||
namespace xgboost {
|
||||
|
||||
@ -140,10 +145,18 @@ class HostDeviceVectorImpl {
|
||||
auto ptr = other->ConstDevicePointer();
|
||||
SetDevice();
|
||||
CHECK_EQ(this->DeviceIdx(), other->DeviceIdx());
|
||||
|
||||
#if defined(XGBOOST_USE_CUDA)
|
||||
dh::safe_cuda(cudaMemcpyAsync(this->DevicePointer() + ori_size,
|
||||
ptr,
|
||||
other->Size() * sizeof(T),
|
||||
cudaMemcpyDeviceToDevice));
|
||||
#elif defined(XGBOOST_USE_HIP)
|
||||
dh::safe_cuda(hipMemcpyAsync(this->DevicePointer() + ori_size,
|
||||
ptr,
|
||||
other->Size() * sizeof(T),
|
||||
hipMemcpyDeviceToDevice));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,10 +209,18 @@ class HostDeviceVectorImpl {
|
||||
gpu_access_ = access;
|
||||
if (data_h_.size() != data_d_->size()) { data_h_.resize(data_d_->size()); }
|
||||
SetDevice();
|
||||
|
||||
#if defined(XGBOOST_USE_CUDA)
|
||||
dh::safe_cuda(cudaMemcpy(data_h_.data(),
|
||||
data_d_->data().get(),
|
||||
data_d_->size() * sizeof(T),
|
||||
cudaMemcpyDeviceToHost));
|
||||
#elif defined(XGBOOST_USE_HIP)
|
||||
dh::safe_cuda(hipMemcpy(data_h_.data(),
|
||||
data_d_->data().get(),
|
||||
data_d_->size() * sizeof(T),
|
||||
hipMemcpyDeviceToHost));
|
||||
#endif
|
||||
}
|
||||
|
||||
void LazySyncDevice(GPUAccess access) {
|
||||
@ -212,10 +233,18 @@ class HostDeviceVectorImpl {
|
||||
// data is on the host
|
||||
LazyResizeDevice(data_h_.size());
|
||||
SetDevice();
|
||||
|
||||
#if defined(XGBOOST_USE_CUDA)
|
||||
dh::safe_cuda(cudaMemcpyAsync(data_d_->data().get(),
|
||||
data_h_.data(),
|
||||
data_d_->size() * sizeof(T),
|
||||
cudaMemcpyHostToDevice));
|
||||
#elif defined(XGBOOST_USE_HIP)
|
||||
dh::safe_cuda(hipMemcpyAsync(data_d_->data().get(),
|
||||
data_h_.data(),
|
||||
data_d_->size() * sizeof(T),
|
||||
hipMemcpyHostToDevice));
|
||||
#endif
|
||||
gpu_access_ = access;
|
||||
}
|
||||
|
||||
@ -240,8 +269,14 @@ class HostDeviceVectorImpl {
|
||||
LazyResizeDevice(Size());
|
||||
gpu_access_ = GPUAccess::kWrite;
|
||||
SetDevice();
|
||||
|
||||
#if defined(XGBOOST_USE_CUDA)
|
||||
dh::safe_cuda(cudaMemcpyAsync(data_d_->data().get(), other->data_d_->data().get(),
|
||||
data_d_->size() * sizeof(T), cudaMemcpyDefault));
|
||||
#elif defined(XGBOOST_USE_HIP)
|
||||
dh::safe_cuda(hipMemcpyAsync(data_d_->data().get(), other->data_d_->data().get(),
|
||||
data_d_->size() * sizeof(T), hipMemcpyDefault));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,8 +284,14 @@ class HostDeviceVectorImpl {
|
||||
LazyResizeDevice(Size());
|
||||
gpu_access_ = GPUAccess::kWrite;
|
||||
SetDevice();
|
||||
|
||||
#if defined(XGBOOST_USE_CUDA)
|
||||
dh::safe_cuda(cudaMemcpyAsync(data_d_->data().get(), begin,
|
||||
data_d_->size() * sizeof(T), cudaMemcpyDefault));
|
||||
#elif defined(XGBOOST_USE_HIP)
|
||||
dh::safe_cuda(hipMemcpyAsync(data_d_->data().get(), begin,
|
||||
data_d_->size() * sizeof(T), hipMemcpyDefault));
|
||||
#endif
|
||||
}
|
||||
|
||||
void LazyResizeDevice(size_t new_size) {
|
||||
@ -262,7 +303,11 @@ class HostDeviceVectorImpl {
|
||||
void SetDevice() {
|
||||
CHECK_GE(device_, 0);
|
||||
if (cudaSetDeviceHandler == nullptr) {
|
||||
#if defined(XGBOOST_USE_CUDA)
|
||||
dh::safe_cuda(cudaSetDevice(device_));
|
||||
#elif defined(XGBOOST_USE_HIP)
|
||||
dh::safe_cuda(hipSetDevice(device_));
|
||||
#endif
|
||||
} else {
|
||||
(*cudaSetDeviceHandler)(device_);
|
||||
}
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
|
||||
#if defined(XGBOOST_USE_HIP)
|
||||
#include "host_device_vector.cu"
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user