Here are the examples of the csharp api System.Collections.Generic.List.Add(nvmlDevice) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
19
View Source File : NvmlHelper.cs
License : GNU Lesser General Public License v3.0
Project Creator : ntminer
License : GNU Lesser General Public License v3.0
Project Creator : ntminer
public List<NvGpu> GetGpus() {
List<NvGpu> results = new List<NvGpu>();
try {
if (NvmlInit()) {
_nvmlDevices.Clear();
uint deviceCount = 0;
var r = NvmlNativeMethods.nvmlDeviceGetCount(ref deviceCount);
CheckResult(r, () => $"{nameof(NvmlNativeMethods.nvmlDeviceGetCount)} {r.ToString()}");
for (int i = 0; i < deviceCount; i++) {
NvGpu gpu = new NvGpu {
GpuIndex = i
};
nvmlDevice nvmlDevice = new nvmlDevice();
r = NvmlNativeMethods.nvmlDeviceGetHandleByIndex((uint)i, ref nvmlDevice);
_nvmlDevices.Add(nvmlDevice);
CheckResult(r, () => $"{nameof(NvmlNativeMethods.nvmlDeviceGetHandleByIndex)}({((uint)i).ToString()}) {r.ToString()}");
r = NvmlNativeMethods.nvmlDeviceGetName(nvmlDevice, out string name);
CheckResult(r, () => $"{nameof(NvmlNativeMethods.nvmlDeviceGetName)} {r.ToString()}");
nvmlMemory memory = new nvmlMemory();
r = NvmlNativeMethods.nvmlDeviceGetMemoryInfo(nvmlDevice, ref memory);
CheckResult(r, () => $"{nameof(NvmlNativeMethods.nvmlDeviceGetMemoryInfo)} {r.ToString()}");
// short gpu name
if (!string.IsNullOrEmpty(name)) {
name = name.Replace("GeForce GTX ", string.Empty);
name = name.Replace("GeForce ", string.Empty);
}
nvmlPciInfo pci = new nvmlPciInfo();
r = NvmlNativeMethods.nvmlDeviceGetPciInfo(nvmlDevice, ref pci);
CheckResult(r, () => $"{nameof(NvmlNativeMethods.nvmlDeviceGetPciInfo)} {r.ToString()}");
gpu.Name = name;
gpu.BusId = (int)pci.bus;
gpu.TotalMemory = memory.total;
results.Add(gpu);
}
}
}
catch {
}
return results;
}