Lazy initialization of device vector. (#5173)

* Lazy initialization of device vector.

* Fix #5162.

* Disable copy constructor of HostDeviceVector.  Prevents implicit copying.

* Fix CPU build.

* Bring back move assignment operator.
This commit is contained in:
Jiaming Yuan
2020-01-07 11:23:05 +08:00
committed by GitHub
parent 77cfbff5a7
commit ee287808fb
7 changed files with 114 additions and 64 deletions

View File

@@ -59,8 +59,25 @@ class MetaInfo {
* can be used to specify initial prediction to boost from.
*/
HostDeviceVector<bst_float> base_margin_;
/*! \brief default constructor */
MetaInfo() = default;
MetaInfo& operator=(MetaInfo const& that) {
this->num_row_ = that.num_row_;
this->num_col_ = that.num_col_;
this->num_nonzero_ = that.num_nonzero_;
this->labels_.Resize(that.labels_.Size());
this->labels_.Copy(that.labels_);
this->group_ptr_ = that.group_ptr_;
this->weights_.Resize(that.weights_.Size());
this->weights_.Copy(that.weights_);
this->base_margin_.Resize(that.base_margin_.Size());
this->base_margin_.Copy(that.base_margin_);
return *this;
}
/*!
* \brief Get weight of each instances.
* \param i Instance index.
@@ -246,10 +263,10 @@ class SparsePage {
/**
* \brief Pushes external data batch onto this page
*
* \tparam AdapterBatchT
* \param batch
* \param missing
* \param nthread
* \tparam AdapterBatchT
* \param batch
* \param missing
* \param nthread
*
* \return The maximum number of columns encountered in this input batch. Useful when pushing many adapter batches to work out the total number of columns.
*/

View File

@@ -88,8 +88,13 @@ class HostDeviceVector {
HostDeviceVector(std::initializer_list<T> init, int device = -1);
explicit HostDeviceVector(const std::vector<T>& init, int device = -1);
~HostDeviceVector();
HostDeviceVector(const HostDeviceVector<T>&);
HostDeviceVector<T>& operator=(const HostDeviceVector<T>&);
HostDeviceVector(const HostDeviceVector<T>&) = delete;
HostDeviceVector(HostDeviceVector<T>&&);
HostDeviceVector<T>& operator=(const HostDeviceVector<T>&) = delete;
HostDeviceVector<T>& operator=(HostDeviceVector<T>&&);
size_t Size() const;
int DeviceIdx() const;
common::Span<T> DeviceSpan();
@@ -116,6 +121,7 @@ class HostDeviceVector {
bool HostCanWrite() const;
bool DeviceCanRead() const;
bool DeviceCanWrite() const;
GPUAccess DeviceAccess() const;
void SetDevice(int device) const;