@@ -1493,6 +1493,65 @@ impl<'nvml> Device<'nvml> {
14931493 }
14941494 }
14951495
1496+ /**
1497+ Sets the intended operating speed of the specified fan as a percentage of the
1498+ maximum fan speed (100%).
1499+
1500+ You can determine valid fan indices using [`Self::num_fans()`].
1501+
1502+ WARNING: This function changes the fan control policy to manual. It means that YOU have to
1503+ monitor the temperature and adjust the fan speed accordingly. If you set the fan speed too
1504+ low you can burn your GPU! Use [`Self::set_default_fan_speed()`] to restore default control
1505+ policy.
1506+
1507+ # Errors
1508+
1509+ * `Uninitialized`, if the library has not been successfully initialized
1510+ * `InvalidArg`, if this `Device` is invalid or `fan_idx` is invalid
1511+ * `NotSupported`, if this `Device` does not have a fan or is newer than Maxwell
1512+ * `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible
1513+ * `Unknown`, on any unexpected error
1514+
1515+ # Device Support
1516+
1517+ Supports all cuda-capable discrete products with fans that are Maxwell or Newer.
1518+ */
1519+ // Checked against local
1520+ // Tested (no-run)
1521+ #[ doc( alias = "nvmlDeviceSetFanSpeed_v2" ) ]
1522+ pub fn set_fan_speed ( & self , fan_idx : u32 , speed : u32 ) -> Result < ( ) , NvmlError > {
1523+ let sym = nvml_sym ( self . nvml . lib . nvmlDeviceSetFanSpeed_v2 . as_ref ( ) ) ?;
1524+
1525+ unsafe { nvml_try ( sym ( self . device , fan_idx, speed) ) }
1526+ }
1527+
1528+ /**
1529+ Sets the speed of the fan control policy to default.
1530+ Used to restore default control policy after calling [`Self::set_fan_speed()`].
1531+
1532+ You can determine valid fan indices using [`Self::num_fans()`].
1533+
1534+ # Errors
1535+
1536+ * `Uninitialized`, if the library has not been successfully initialized
1537+ * `InvalidArg`, if this `Device` is invalid or `fan_idx` is invalid
1538+ * `NotSupported`, if this `Device` does not have a fan or is newer than Maxwell
1539+ * `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible
1540+ * `Unknown`, on any unexpected error
1541+
1542+ # Device Support
1543+
1544+ Supports cuda-capable discrete products with fans.
1545+ */
1546+ // Checked against local
1547+ // Tested (no-run)
1548+ #[ doc( alias = "nvmlDeviceSetDefaultFanSpeed_v2" ) ]
1549+ pub fn set_default_fan_speed ( & self , fan_idx : u32 ) -> Result < ( ) , NvmlError > {
1550+ let sym = nvml_sym ( self . nvml . lib . nvmlDeviceSetDefaultFanSpeed_v2 . as_ref ( ) ) ?;
1551+
1552+ unsafe { nvml_try ( sym ( self . device , fan_idx) ) }
1553+ }
1554+
14961555 /**
14971556 Gets the current GPU operation mode and the pending one (that it will switch to
14981557 after a reboot).
@@ -5998,6 +6057,28 @@ mod test {
59986057 } )
59996058 }
60006059
6060+ // This modifies device state, so we don't want to actually run the test
6061+ #[ allow( dead_code) ]
6062+ fn set_fan_speed ( ) {
6063+ let nvml = nvml ( ) ;
6064+ let mut device = device ( & nvml) ;
6065+
6066+ device
6067+ . set_fan_speed ( 0 , 50 )
6068+ . expect ( "set fan with index 0 to speed of 50%" )
6069+ }
6070+
6071+ // This modifies device state, so we don't want to actually run the test
6072+ #[ allow( dead_code) ]
6073+ fn set_default_fan_speed ( ) {
6074+ let nvml = nvml ( ) ;
6075+ let mut device = device ( & nvml) ;
6076+
6077+ device
6078+ . set_default_fan_speed ( 0 )
6079+ . expect ( "set fan with index 0 to default control policy" )
6080+ }
6081+
60016082 // This modifies device state, so we don't want to actually run the test
60026083 #[ allow( dead_code) ]
60036084 fn set_accounting ( ) {
0 commit comments