| 15 | namespace { |
| 16 | |
| 17 | void InitHostDeviceVector(size_t n, DeviceOrd device, HostDeviceVector<int> *v) { |
| 18 | // create the vector |
| 19 | v->SetDevice(device); |
| 20 | v->Resize(n); |
| 21 | |
| 22 | ASSERT_EQ(v->Size(), n); |
| 23 | ASSERT_EQ(v->Device(), device); |
| 24 | // ensure that the device have read-write access |
| 25 | ASSERT_TRUE(v->DeviceCanRead()); |
| 26 | ASSERT_TRUE(v->DeviceCanWrite()); |
| 27 | // ensure that the host has no access |
| 28 | ASSERT_FALSE(v->HostCanRead()); |
| 29 | ASSERT_FALSE(v->HostCanWrite()); |
| 30 | |
| 31 | // fill in the data on the host |
| 32 | std::vector<int>& data_h = v->HostVector(); |
| 33 | // ensure that the host has full access, while the device have none |
| 34 | ASSERT_TRUE(v->HostCanRead()); |
| 35 | ASSERT_TRUE(v->HostCanWrite()); |
| 36 | ASSERT_FALSE(v->DeviceCanRead()); |
| 37 | ASSERT_FALSE(v->DeviceCanWrite()); |
| 38 | ASSERT_EQ(data_h.size(), n); |
| 39 | std::iota(data_h.begin(), data_h.end(), 0); |
| 40 | } |
| 41 | |
| 42 | void PlusOne(HostDeviceVector<int> *v) { |
| 43 | auto device = v->Device(); |
no test coverage detected