collect all of the devices whose memory can be mapped from cuDevice.
| 77 | |
| 78 | // collect all of the devices whose memory can be mapped from cuDevice. |
| 79 | vector<CUdevice> getBackingDevices(CUdevice cuDevice) |
| 80 | { |
| 81 | int num_devices; |
| 82 | |
| 83 | checkCudaErrors(cuDeviceGetCount(&num_devices)); |
| 84 | |
| 85 | vector<CUdevice> backingDevices; |
| 86 | backingDevices.push_back(cuDevice); |
| 87 | for (int dev = 0; dev < num_devices; dev++) { |
| 88 | int capable = 0; |
| 89 | int attributeVal = 0; |
| 90 | |
| 91 | // The mapping device is already in the backingDevices vector |
| 92 | if (dev == cuDevice) { |
| 93 | continue; |
| 94 | } |
| 95 | |
| 96 | // Only peer capable devices can map each others memory |
| 97 | checkCudaErrors(cuDeviceCanAccessPeer(&capable, cuDevice, dev)); |
| 98 | if (!capable) { |
| 99 | continue; |
| 100 | } |
| 101 | |
| 102 | // The device needs to support virtual address management for the required |
| 103 | // apis to work |
| 104 | checkCudaErrors( |
| 105 | cuDeviceGetAttribute(&attributeVal, CU_DEVICE_ATTRIBUTE_VIRTUAL_ADDRESS_MANAGEMENT_SUPPORTED, cuDevice)); |
| 106 | if (attributeVal == 0) { |
| 107 | continue; |
| 108 | } |
| 109 | |
| 110 | backingDevices.push_back(dev); |
| 111 | } |
| 112 | return backingDevices; |
| 113 | } |
| 114 | |
| 115 | // Host code |
| 116 | int main(int argc, char **argv) |