using System; using NvAPIWrapper.Native.Exceptions; using NvAPIWrapper.Native.General; using NvAPIWrapper.Native.GPU; using NvAPIWrapper.Native.GPU.Structures; using NvAPIWrapper.Native.Helpers; using NvAPIWrapper.Native.Helpers.Structures; using NvAPIWrapper.Native.Interfaces.GPU; namespace NvAPIWrapper.Native { public static partial class GPUApi { /// /// [PRIVATE] /// Gets the cooler policy table for the passed GPU handle. /// /// The handle of the GPU to perform the operation on. /// The cooler policy to get the table for. /// The cooler index. /// Number of policy table entries retrieved. /// The cooler policy table for the GPU. // ReSharper disable once TooManyArguments public static PrivateCoolerPolicyTableV1 GetCoolerPolicyTable( PhysicalGPUHandle gpuHandle, CoolerPolicy policy, uint index, out uint count) { var instance = typeof(PrivateCoolerPolicyTableV1).Instantiate(); instance._Policy = policy; using (var policyTableReference = ValueTypeReference.FromValueType(instance)) { var status = DelegateFactory.GetDelegate()( gpuHandle, index, policyTableReference, out count ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return policyTableReference.ToValueType(typeof(PrivateCoolerPolicyTableV1)); } } /// /// [PRIVATE] /// Gets the cooler settings for the passed GPU handle. /// /// The handle of the GPU to perform the operation on. /// The cooler targets to get settings. /// The cooler settings. public static PrivateCoolerSettingsV1 GetCoolerSettings( PhysicalGPUHandle gpuHandle, CoolerTarget coolerTarget = CoolerTarget.All) { var instance = typeof(PrivateCoolerSettingsV1).Instantiate(); using (var coolerSettingsReference = ValueTypeReference.FromValueType(instance)) { var status = DelegateFactory.GetDelegate()( gpuHandle, coolerTarget, coolerSettingsReference ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return coolerSettingsReference.ToValueType(typeof(PrivateCoolerSettingsV1)); } } /// /// [PRIVATE] /// Gets the current fan speed level for the passed GPU handle. /// /// The handle of the GPU to perform the operation on. /// The current fan speed level. public static uint GetCurrentFanSpeedLevel(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory .GetDelegate()(gpuHandle, out var count); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return count; } /// /// [PRIVATE] /// Gets the current thermal level for the passed GPU handle. /// /// The handle of the GPU to perform the operation on. /// The current thermal level. public static uint GetCurrentThermalLevel(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var count); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return count; } /// /// This function returns the fan speed tachometer reading for the specified physical GPU. /// /// Physical GPU handle to get tachometer reading from /// The GPU fan speed in revolutions per minute. /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle. public static uint GetTachReading(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()( gpuHandle, out var value ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return value; } /// /// [PRIVATE] /// Gets the current thermal policies information for the passed GPU handle. /// /// The handle of the GPU to perform the operation on. /// The current thermal policies information. public static PrivateThermalPoliciesInfoV2 GetThermalPoliciesInfo(PhysicalGPUHandle gpuHandle) { var instance = typeof(PrivateThermalPoliciesInfoV2).Instantiate(); using (var policiesInfoReference = ValueTypeReference.FromValueType(instance)) { var status = DelegateFactory.GetDelegate()(gpuHandle, policiesInfoReference); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return policiesInfoReference.ToValueType( typeof(PrivateThermalPoliciesInfoV2)); } } /// /// [PRIVATE] /// Gets the thermal policies status for the passed GPU handle. /// /// The handle of the GPU to perform the operation on. /// The thermal policies status. public static PrivateThermalPoliciesStatusV2 GetThermalPoliciesStatus(PhysicalGPUHandle gpuHandle) { var instance = typeof(PrivateThermalPoliciesStatusV2).Instantiate(); using (var policiesStatusReference = ValueTypeReference.FromValueType(instance)) { var status = DelegateFactory.GetDelegate()( gpuHandle, policiesStatusReference ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return policiesStatusReference.ToValueType( typeof(PrivateThermalPoliciesStatusV2)); } } /// /// This function retrieves the thermal information of all thermal sensors or specific thermal sensor associated with /// the selected GPU. To retrieve info for all sensors, set sensorTarget to ThermalSettingsTarget.All. /// /// Handle of the physical GPU for which the memory information is to be extracted. /// Specifies the requested thermal sensor target. /// The device thermal sensors information. /// This operation is not supported. /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found. /// A delegate callback throws an exception. public static IThermalSettings GetThermalSettings( PhysicalGPUHandle physicalGPUHandle, ThermalSettingsTarget sensorTarget = ThermalSettingsTarget.All) { var getThermalSettings = DelegateFactory.GetDelegate(); foreach (var acceptType in getThermalSettings.Accepts()) { var instance = acceptType.Instantiate(); using (var gpuThermalSettings = ValueTypeReference.FromValueType(instance, acceptType)) { var status = getThermalSettings(physicalGPUHandle, sensorTarget, gpuThermalSettings); if (status == Status.IncompatibleStructureVersion) { continue; } if (status != Status.Ok) { throw new NVIDIAApiException(status); } return gpuThermalSettings.ToValueType(acceptType); } } throw new NVIDIANotSupportedException("This operation is not supported."); } /// /// [PRIVATE] /// Restores the cooler policy table to default for the passed GPU handle and cooler index. /// /// The handle of the GPU to perform the operation on. /// The cooler policy to restore to default. /// The indexes of the coolers to restore their policy tables to default. public static void RestoreCoolerPolicyTable( PhysicalGPUHandle gpuHandle, CoolerPolicy policy, uint[] indexes = null) { var status = DelegateFactory.GetDelegate()( gpuHandle, indexes, (uint) (indexes?.Length ?? 0), policy ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } } /// /// [PRIVATE] /// Restores the cooler settings to default for the passed GPU handle and cooler index. /// /// The handle of the GPU to perform the operation on. /// The indexes of the coolers to restore their settings to default. public static void RestoreCoolerSettings( PhysicalGPUHandle gpuHandle, uint[] indexes = null) { var status = DelegateFactory.GetDelegate()( gpuHandle, indexes, (uint) (indexes?.Length ?? 0) ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } } /// /// [PRIVATE] /// Sets the cooler levels for the passed GPU handle. /// /// The handle of the GPU to perform the operation on. /// The cooler index. /// The cooler level information. /// The number of entries in the cooler level information. // ReSharper disable once TooManyArguments public static void SetCoolerLevels( PhysicalGPUHandle gpuHandle, uint index, PrivateCoolerLevelsV1 coolerLevels, uint levelsCount ) { using (var coolerLevelsReference = ValueTypeReference.FromValueType(coolerLevels)) { var status = DelegateFactory.GetDelegate()( gpuHandle, index, coolerLevelsReference, levelsCount ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } } } /// /// [PRIVATE] /// Sets the cooler policy table for the passed GPU handle. /// /// The handle of the GPU to perform the operation on. /// The cooler index. /// The cooler policy table. /// The number of entries in the cooler policy table. // ReSharper disable once TooManyArguments public static void SetCoolerPolicyTable( PhysicalGPUHandle gpuHandle, uint index, PrivateCoolerPolicyTableV1 coolerPolicyTable, uint policyLevelsCount ) { var instance = typeof(PrivateCoolerPolicyTableV1).Instantiate(); using (var policyTableReference = ValueTypeReference.FromValueType(instance)) { var status = DelegateFactory.GetDelegate()( gpuHandle, index, policyTableReference, policyLevelsCount ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } } } /// /// [PRIVATE] /// Sets the thermal policies status for the passed GPU handle. /// /// The handle of the GPU to perform the operation on. /// The new thermal limiter policy to apply. public static void SetThermalPoliciesStatus( PhysicalGPUHandle gpuHandle, PrivateThermalPoliciesStatusV2 thermalPoliciesStatus) { using (var policiesStatusReference = ValueTypeReference.FromValueType(thermalPoliciesStatus)) { var status = DelegateFactory.GetDelegate()( gpuHandle, policiesStatusReference ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } } } public static PrivateFanCoolersInfoV1 GetClientFanCoolersInfo(PhysicalGPUHandle gpuHandle) { var instance = typeof(PrivateFanCoolersInfoV1).Instantiate(); using (var policiesInfoReference = ValueTypeReference.FromValueType(instance)) { var status = DelegateFactory.GetDelegate()(gpuHandle, policiesInfoReference); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return policiesInfoReference.ToValueType( typeof(PrivateFanCoolersInfoV1)); } } public static PrivateFanCoolersStatusV1 GetClientFanCoolersStatus(PhysicalGPUHandle gpuHandle) { var instance = typeof(PrivateFanCoolersStatusV1).Instantiate(); using (var policiesStatusReference = ValueTypeReference.FromValueType(instance)) { var status = DelegateFactory.GetDelegate()( gpuHandle, policiesStatusReference ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return policiesStatusReference.ToValueType( typeof(PrivateFanCoolersStatusV1)); } } public static PrivateFanCoolersControlV1 GetClientFanCoolersControl(PhysicalGPUHandle gpuHandle) { var instance = typeof(PrivateFanCoolersControlV1).Instantiate(); using (var policiesStatusReference = ValueTypeReference.FromValueType(instance)) { var status = DelegateFactory.GetDelegate()( gpuHandle, policiesStatusReference ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return policiesStatusReference.ToValueType( typeof(PrivateFanCoolersControlV1)); } } public static void SetClientFanCoolersControl(PhysicalGPUHandle gpuHandle, PrivateFanCoolersControlV1 control) { using (var coolerLevelsReference = ValueTypeReference.FromValueType(control)) { var status = DelegateFactory.GetDelegate()( gpuHandle, coolerLevelsReference ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } } } } }