protected override void OnStop() { _cancel.Cancel(); _counterThread.Join(); _cancel.Dispose(); Nvml.nvmlShutdown(); }
public void UpdateCounters() { var err = Nvml.nvmlDeviceGetUtilizationRates(_device, out _utilization); _utilization = (err == Nvml.nvmlReturn.NVML_SUCCESS) ? _utilization : default(Nvml.NvmlUtilization); err = Nvml.nvmlDeviceGetMemoryInfo(_device, out _memory); _memory = (err == Nvml.nvmlReturn.NVML_SUCCESS) ? _memory : default(Nvml.NvmlMemory); err = Nvml.nvmlDeviceGetFanSpeed(_device, out _fanSpeed); _fanSpeed = (err == Nvml.nvmlReturn.NVML_SUCCESS) ? _fanSpeed : 0; err = Nvml.nvmlDeviceGetPowerUsage(_device, out _power); _power = (err == Nvml.nvmlReturn.NVML_SUCCESS) ? _power : 0; err = Nvml.nvmlDeviceGetTemperature(_device, Nvml.nvmlTemperatureSensors.NVML_TEMPERATURE_GPU, out _temperature); _temperature = (err == Nvml.nvmlReturn.NVML_SUCCESS) ? _temperature : 0; err = Nvml.nvmlDeviceGetClockInfo(_device, Nvml.nvmlClockType.NVML_CLOCK_SM, out _smClock); _smClock = (err == Nvml.nvmlReturn.NVML_SUCCESS) ? _smClock : 0; }
public static IEnumerable <GpuDevice> EnumDevices() { var err = Nvml.nvmlInit_v2(); if (err != Nvml.nvmlReturn.NVML_SUCCESS) { yield break; } int cdev; err = Nvml.nvmlDeviceGetCount(out cdev); if (err != Nvml.nvmlReturn.NVML_SUCCESS) { yield break; } for (int i = 0; i < cdev; i++) { yield return(new GpuDevice(i)); } }
public GpuDevice(int deviceId) { DeviceId = deviceId; var err = Nvml.nvmlInit_v2(); if (err == Nvml.nvmlReturn.NVML_SUCCESS) { err = Nvml.nvmlDeviceGetHandleByIndex((uint)deviceId, out _device); if (err == Nvml.nvmlReturn.NVML_SUCCESS) { var name = new StringBuilder(MaxNameLen); var uuid = new StringBuilder(MaxUuidLen); if (Nvml.nvmlDeviceGetName(_device, name, (uint)name.Capacity) == Nvml.nvmlReturn.NVML_SUCCESS && Nvml.nvmlDeviceGetPciInfo(_device, out _pci) == Nvml.nvmlReturn.NVML_SUCCESS && Nvml.nvmlDeviceGetUUID(_device, uuid, (uint)uuid.Capacity) == Nvml.nvmlReturn.NVML_SUCCESS) { Name = name.ToString(); Uuid = uuid.ToString(); return; } } } Name = "<FailedToInitialize>"; }