Skip to content

Commit 0a43c30

Browse files
authored
feat: add set fan control policy function (#91)
Add set_fan_control_policy function, and fix FanControlPolicy try_from from #77
1 parent 30ed0fa commit 0a43c30

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

nvml-wrapper/src/device.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,35 @@ impl<'nvml> Device<'nvml> {
19001900
}
19011901
}
19021902

1903+
/**
1904+
Sets fan control policy.
1905+
1906+
You can determine valid fan indices using [`Self::num_fans()`].
1907+
1908+
# Errors
1909+
1910+
* `Uninitialized`, if the library has not been successfully initialized
1911+
* `InvalidArg`, if this `Device` is invalid or `fan_idx` is invalid
1912+
* `NotSupported`, if this `Device` does not have a fan
1913+
* `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible
1914+
* `UnexpectedVariant`, for which you can read the docs for
1915+
* `Unknown`, on any unexpected error
1916+
1917+
# Device Support
1918+
1919+
Supports Maxwell or newer fully supported discrete devices with fans.
1920+
*/
1921+
#[doc(alias = "nvmlDeviceSetFanControlPolicy")]
1922+
pub fn set_fan_control_policy(
1923+
&mut self,
1924+
fan_idx: u32,
1925+
policy: FanControlPolicy,
1926+
) -> Result<(), NvmlError> {
1927+
let sym = nvml_sym(self.nvml.lib.nvmlDeviceSetFanControlPolicy.as_ref())?;
1928+
1929+
unsafe { nvml_try(sym(self.device, fan_idx, policy.as_c())) }
1930+
}
1931+
19031932
/**
19041933
Sets the speed of a specified fan.
19051934

nvml-wrapper/src/enums/device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl TryFrom<nvmlFanControlPolicy_t> for FanControlPolicy {
376376
fn try_from(value: nvmlFanControlPolicy_t) -> Result<Self, Self::Error> {
377377
match value {
378378
NVML_FAN_POLICY_TEMPERATURE_CONTINOUS_SW => Ok(Self::TemperatureContinousSw),
379-
NVML_FAN_POLICY_MANUAL => Ok(Self::TemperatureContinousSw),
379+
NVML_FAN_POLICY_MANUAL => Ok(Self::Manual),
380380
_ => Err(NvmlError::UnexpectedVariant(value)),
381381
}
382382
}

nvml-wrapper/unwrapped_functions.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ nvmlDevicePowerSmoothingSetState
9090
nvmlDevicePowerSmoothingUpdatePresetProfileParam
9191
nvmlDeviceSetConfComputeUnprotectedMemSize
9292
nvmlDeviceSetDramEncryptionMode
93-
nvmlDeviceSetFanControlPolicy
9493
nvmlDeviceSetMigMode
9594
nvmlDeviceSetNvlinkBwMode
9695
nvmlDeviceSetNvLinkDeviceLowPowerThreshold

0 commit comments

Comments
 (0)