Get a specific GPU device Args: idx: index of device Returns: NvidiaDevice: single GPU device
(self, idx)
| 183 | return [self.device(i) for i in range(self.num_devices())] |
| 184 | |
| 185 | def device(self, idx): |
| 186 | """Get a specific GPU device |
| 187 | |
| 188 | Args: |
| 189 | idx: index of device |
| 190 | |
| 191 | Returns: |
| 192 | NvidiaDevice: single GPU device |
| 193 | """ |
| 194 | num_dev = self.num_devices() |
| 195 | assert idx < num_dev, "Cannot obtain device {}: NVML only found {} devices.".format(idx, num_dev) |
| 196 | |
| 197 | class GpuDevice(Structure): |
| 198 | pass |
| 199 | |
| 200 | c_nvmlDevice_t = POINTER(GpuDevice) |
| 201 | |
| 202 | c_index = c_uint(idx) |
| 203 | device = c_nvmlDevice_t() |
| 204 | _check_return(_NVML.get_function( |
| 205 | "nvmlDeviceGetHandleByIndex_v2")(c_index, byref(device))) |
| 206 | return NvidiaDevice(device) |
| 207 | |
| 208 | |
| 209 | if __name__ == '__main__': |
no test coverage detected