public NvidiaGpuModel(int adapterIndex, NvPhysicalGpuHandle handle, NvDisplayHandle displayHandle) { AdapterIndex = adapterIndex; _handle = handle; _displayHandle = displayHandle; NVAPI.NvAPI_GPU_GetFullName(handle, out _gpuName); }
public NVidiaGPU() { //NvAPI.Initialize(); //var err = NvAPI.GetErrorMessage(Status.FILE_NOT_FOUND); if (available = NVAPI.IsAvailable) { handles = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS * 4]; NvAPI.Initialize(); var dh = NvAPI.GetAssociatedNvidiaDisplayHandle(@"\\.\DISPLAY1"); int count; var r = NVAPI.NvAPI_EnumPhysicalGPUs(handles, out count); if (r != NvStatus.OK) { NvDisplayHandle dhnd = new NvDisplayHandle(); for (int i = 0; i < NVAPI.MAX_PHYSICAL_GPUS * 2; i++) { var h = NvAPI.EnumNvidiaUnAttachedDisplayHandle(i); if (h != IntPtr.Zero) { Console.WriteLine("Found dev at #{0} ({1:X8})", i, dhnd); } // r = NVAPI.NvAPI_EnumNvidiaDisplayHandle(i, ref dhnd); //if (r != NvStatus.OK) //{ // continue; //} //else //{ // Console.WriteLine("Found dev at #{0} ({1:X8})", i, dhnd); //} } } } }
public NvidiaGPU(int adapterIndex, NvPhysicalGpuHandle handle, NvDisplayHandle? displayHandle, ISettings settings) : base(GetName(handle), new Identifier("nvidiagpu", adapterIndex.ToString(CultureInfo.InvariantCulture)), settings) { this.adapterIndex = adapterIndex; this.handle = handle; this.displayHandle = displayHandle; NvGPUThermalSettings thermalSettings = GetThermalSettings(); temperatures = new Sensor[thermalSettings.Count]; for (int i = 0; i < temperatures.Length; i++) { NvSensor sensor = thermalSettings.Sensor[i]; string name; switch (sensor.Target) { case NvThermalTarget.BOARD: name = "GPU Board"; break; case NvThermalTarget.GPU: name = "GPU Core"; break; case NvThermalTarget.MEMORY: name = "GPU Memory"; break; case NvThermalTarget.POWER_SUPPLY: name = "GPU Power Supply"; break; case NvThermalTarget.UNKNOWN: name = "GPU Unknown"; break; default: name = "GPU"; break; } temperatures[i] = new Sensor(name, i, SensorType.Temperature, this, new ParameterDescription[0], settings); ActivateSensor(temperatures[i]); } int value; if (NVAPI.NvAPI_GPU_GetTachReading != null && NVAPI.NvAPI_GPU_GetTachReading(handle, out value) == NvStatus.OK) { if (value >= 0) { fan = new Sensor("GPU", 0, SensorType.Fan, this, settings); ActivateSensor(fan); } } clocks = new Sensor[3]; clocks[0] = new Sensor("GPU Core", 0, SensorType.Clock, this, settings); clocks[1] = new Sensor("GPU Memory", 1, SensorType.Clock, this, settings); clocks[2] = new Sensor("GPU Shader", 2, SensorType.Clock, this, settings); for (int i = 0; i < clocks.Length; i++) ActivateSensor(clocks[i]); loads = new Sensor[3]; loads[0] = new Sensor("GPU Core", 0, SensorType.Load, this, settings); loads[1] = new Sensor("GPU Memory Controller", 1, SensorType.Load, this, settings); loads[2] = new Sensor("GPU Video Engine", 2, SensorType.Load, this, settings); memoryLoad = new Sensor("GPU Memory", 3, SensorType.Load, this, settings); memoryFree = new Sensor("GPU Memory Free", 1, SensorType.SmallData, this, settings); memoryUsed = new Sensor("GPU Memory Used", 2, SensorType.SmallData, this, settings); memoryAvail = new Sensor("GPU Memory Total", 3, SensorType.SmallData, this, settings); control = new Sensor("GPU Fan", 0, SensorType.Control, this, settings); NvGPUCoolerSettings coolerSettings = GetCoolerSettings(); if (coolerSettings.Count > 0) { fanControl = new Control(control, settings, coolerSettings.Cooler[0].DefaultMin, coolerSettings.Cooler[0].DefaultMax); fanControl.ControlModeChanged += ControlModeChanged; fanControl.SoftwareControlValueChanged += SoftwareControlValueChanged; ControlModeChanged(fanControl); control.Control = fanControl; } Update(); }
public GpuSensor() { if (!NVAPI.IsAvailable) { throw new Exception("Unable to obtain primary GPU; NVAPI is not available"); } NvPhysicalGpuHandle[] handles = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS]; int numGpus; if (NVAPI.NvAPI_EnumPhysicalGPUs == null) { throw new Exception("Unable to obtain primary GPU; NvAPI_EnumPhysicalGPUs not available"); } else { NvStatus status = NVAPI.NvAPI_EnumPhysicalGPUs(handles, out numGpus); if (status != NvStatus.OK) { throw new Exception("Unable to obtain primary GPU"); } } if (numGpus < 1) { throw new Exception("Unable to obtain primary GPU"); } gpuHandle = handles[0]; IDictionary <NvPhysicalGpuHandle, NvDisplayHandle> displayHandles = new Dictionary <NvPhysicalGpuHandle, NvDisplayHandle>(); if (NVAPI.NvAPI_EnumNvidiaDisplayHandle != null && NVAPI.NvAPI_GetPhysicalGPUsFromDisplay != null) { int i = 0; NvStatus status = NvStatus.OK; while (status == NvStatus.OK) { NvDisplayHandle displayHandle = new NvDisplayHandle(); status = NVAPI.NvAPI_EnumNvidiaDisplayHandle(i, ref displayHandle); i++; if (status == NvStatus.OK) { NvPhysicalGpuHandle[] handlesFromDisplay = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS]; if (NVAPI.NvAPI_GetPhysicalGPUsFromDisplay(displayHandle, handlesFromDisplay, out uint countFromDisplay) == NvStatus.OK) { for (int j = 0; j < countFromDisplay; j++) { if (!displayHandles.ContainsKey(handlesFromDisplay[j])) { displayHandles.Add(handlesFromDisplay[j], displayHandle); } } } } } } displayHandles.TryGetValue(handles[0], out displayHandle); }
public NvidiaGroup(ISettings settings) { if (!NVAPI.IsAvailable) return; report.AppendLine("NVAPI"); report.AppendLine(); string version; if (NVAPI.NvAPI_GetInterfaceVersionString(out version) == NvStatus.OK) { report.Append("Version: "); report.AppendLine(version); } NvPhysicalGpuHandle[] handles = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS]; int count; if (NVAPI.NvAPI_EnumPhysicalGPUs == null) { report.AppendLine("Error: NvAPI_EnumPhysicalGPUs not available"); report.AppendLine(); return; } else { NvStatus status = NVAPI.NvAPI_EnumPhysicalGPUs(handles, out count); if (status != NvStatus.OK) { report.AppendLine("Status: " + status); report.AppendLine(); return; } } IDictionary<NvPhysicalGpuHandle, NvDisplayHandle> displayHandles = new Dictionary<NvPhysicalGpuHandle, NvDisplayHandle>(); if (NVAPI.NvAPI_EnumNvidiaDisplayHandle != null && NVAPI.NvAPI_GetPhysicalGPUsFromDisplay != null) { NvStatus status = NvStatus.OK; int i = 0; while (status == NvStatus.OK) { NvDisplayHandle displayHandle = new NvDisplayHandle(); status = NVAPI.NvAPI_EnumNvidiaDisplayHandle(i, ref displayHandle); i++; if (status == NvStatus.OK) { NvPhysicalGpuHandle[] handlesFromDisplay = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS]; uint countFromDisplay; if (NVAPI.NvAPI_GetPhysicalGPUsFromDisplay(displayHandle, handlesFromDisplay, out countFromDisplay) == NvStatus.OK) { for (int j = 0; j < countFromDisplay; j++) { if (!displayHandles.ContainsKey(handlesFromDisplay[j])) displayHandles.Add(handlesFromDisplay[j], displayHandle); } } } } } report.Append("Number of GPUs: "); report.AppendLine(count.ToString(CultureInfo.InvariantCulture)); for (int i = 0; i < count; i++) { NvDisplayHandle displayHandle; displayHandles.TryGetValue(handles[i], out displayHandle); hardware.Add(new NvidiaGPU(i, handles[i], displayHandle, settings)); } report.AppendLine(); }
public Nvidia() { bool available = NVAPI.IsAvailable; NvPhysicalGpuHandle[] handles = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS]; int count; if (NVAPI.NvAPI_EnumPhysicalGPUs == null) { //Console.WriteLine("Error: NvAPI_EnumPhysicalGPUs not available"); return; } else { NvStatus status = NVAPI.NvAPI_EnumPhysicalGPUs(handles, out count); if (status != NvStatus.OK) { //Console.WriteLine("Error: NvAPI_EnumPhysicalGPUs not available"); //Console.WriteLine("Status: " + status); return; } } IDictionary <NvPhysicalGpuHandle, NvDisplayHandle> displayHandles = new Dictionary <NvPhysicalGpuHandle, NvDisplayHandle>(); NvDisplayHandle displayHandle; if (NVAPI.NvAPI_EnumNvidiaDisplayHandle != null && NVAPI.NvAPI_GetPhysicalGPUsFromDisplay != null) { NvStatus status = NvStatus.OK; int i = 0; while (status == NvStatus.OK) { displayHandle = new NvDisplayHandle(); status = NVAPI.NvAPI_EnumNvidiaDisplayHandle(i, ref displayHandle); i++; if (status == NvStatus.OK) { NvPhysicalGpuHandle[] handlesFromDisplay = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS]; uint countFromDisplay; if (NVAPI.NvAPI_GetPhysicalGPUsFromDisplay(displayHandle, handlesFromDisplay, out countFromDisplay) == NvStatus.OK) { for (int j = 0; j < countFromDisplay; j++) { if (!displayHandles.ContainsKey(handlesFromDisplay[j])) { displayHandles.Add(handlesFromDisplay[j], displayHandle); } } } } } } if (count > 1) { Console.WriteLine("only suppoert 1 GUP"); } displayHandles.TryGetValue(handles[0], out displayHandle); this._handle = handles[0]; this._displayHandle = displayHandle; this.Name = GetName(this._handle); }