MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / getBackingDevices

Function getBackingDevices

cpp/0_Introduction/vectorAddMMAP/vectorAddMMAP.cpp:79–113  ·  view source on GitHub ↗

collect all of the devices whose memory can be mapped from cuDevice.

Source from the content-addressed store, hash-verified

77
78// collect all of the devices whose memory can be mapped from cuDevice.
79vector<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
116int main(int argc, char **argv)

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected