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

@@ -60,6 +60,7 @@ void PlusOne(HostDeviceVector<int> *v) {
SetDevice(device);
thrust::transform(dh::tcbegin(*v), dh::tcend(*v), dh::tbegin(*v),
[=]__device__(unsigned int a){ return a + 1; });
ASSERT_TRUE(v->DeviceCanWrite());
}
void CheckDevice(HostDeviceVector<int>* v,
@@ -125,7 +126,8 @@ TEST(HostDeviceVector, Copy) {
// a separate scope to ensure that v1 is gone before further checks
HostDeviceVector<int> v1;
InitHostDeviceVector(n, device, &v1);
v = v1;
v.Resize(v1.Size());
v.Copy(v1);
}
CheckDevice(&v, n, 0, GPUAccess::kRead);
PlusOne(&v);