Struct nvml_wrapper::unit::Unit
source · pub struct Unit<'nvml> { /* private fields */ }
Expand description
Struct that represents a unit.
Obtain a Unit
with the various methods available to you on the Nvml
struct.
Lifetimes are used to enforce that each Unit
instance cannot be used after
the Nvml
instance it was obtained from is dropped:
use nvml_wrapper::Nvml;
let nvml = Nvml::init()?;
let unit = nvml.unit_by_index(0)?;
drop(nvml);
// This won't compile
let unit_devices = unit.devices()?;
Note that I cannot test any Unit
methods myself as I do not have access to
such hardware. Test the functionality in this module before you use it.
Implementations§
source§impl<'nvml> Unit<'nvml>
impl<'nvml> Unit<'nvml>
sourcepub unsafe fn new(unit: nvmlUnit_t, nvml: &'nvml Nvml) -> Self
pub unsafe fn new(unit: nvmlUnit_t, nvml: &'nvml Nvml) -> Self
Create a new Unit
wrapper.
You will most likely never need to call this; see the methods available to you
on the Nvml
struct to get one.
§Safety
It is your responsibility to ensure that the given nvmlUnit_t
pointer
is valid.
sourcepub unsafe fn handle(&self) -> nvmlUnit_t
pub unsafe fn handle(&self) -> nvmlUnit_t
Get the raw unit handle contained in this struct
Sometimes necessary for C interop.
§Safety
This is unsafe to prevent it from being used without care.
sourcepub fn devices(&self) -> Result<Vec<Device<'_>>, NvmlError>
pub fn devices(&self) -> Result<Vec<Device<'_>>, NvmlError>
Gets the set of GPU devices that are attached to this Unit
.
I do not have the hardware to test this call. Verify for yourself that it works before you use it. If it works, please let me know; if it doesn’t, I would love a PR. If NVML is sane this should work, but NVIDIA’s docs on this call are anything but clear.
§Errors
Uninitialized
, if the library has not been successfully initializedInvalidArg
, if the unit is invalidUnknown
, on any unexpected error
§Device Support
For S-class products.
sourcepub fn device_count(&self) -> Result<u32, NvmlError>
pub fn device_count(&self) -> Result<u32, NvmlError>
Gets the count of GPU devices that are attached to this Unit
.
I do not have the hardware to test this call. Verify for yourself that it works before you use it. If it works, please let me know; if it doesn’t, I would love a PR. If NVML is sane this should work, but NVIDIA’s docs on this call are anything but clear.
§Errors
Uninitialized
, if the library has not been successfully initializedInvalidArg
, if the unit is invalidUnknown
, on any unexpected error
§Device Support
For S-class products.
sourcepub fn fan_info(&self) -> Result<FansInfo, NvmlError>
pub fn fan_info(&self) -> Result<FansInfo, NvmlError>
Gets fan information for this Unit
(fan count and state + speed for each).
§Errors
Uninitialized
, if the library has not been successfully initializedInvalidArg
, if the unit is invalidNotSupported
, if this is not an S-class productUnexpectedVariant
, for which you can read the docs forUnknown
, on any unexpected error
§Device Support
For S-class products.
sourcepub fn led_state(&self) -> Result<LedState, NvmlError>
pub fn led_state(&self) -> Result<LedState, NvmlError>
Gets the LED state associated with this Unit
.
§Errors
Uninitialized
, if the library has not been successfully initializedInvalidArg
, if the unit is invalidNotSupported
, if this is not an S-class productUtf8Error
, if the string obtained from the C function is not valid Utf8Unknown
, on any unexpected error
§Device Support
For S-class products.
sourcepub fn psu_info(&self) -> Result<PsuInfo, NvmlError>
pub fn psu_info(&self) -> Result<PsuInfo, NvmlError>
Gets the PSU stats for this Unit
.
§Errors
Uninitialized
, if the library has not been successfully initializedInvalidArg
, if the unit is invalidNotSupported
, if this is not an S-class productUtf8Error
, if the string obtained from the C function is not valid Utf8Unknown
, on any unexpected error
§Device Support
For S-class products.
sourcepub fn temperature(
&self,
reading_type: TemperatureReading
) -> Result<u32, NvmlError>
pub fn temperature( &self, reading_type: TemperatureReading ) -> Result<u32, NvmlError>
Gets the temperature for the specified UnitTemperatureReading
, in °C.
Available readings depend on the product.
§Errors
Uninitialized
, if the library has not been successfully initializedInvalidArg
, if the unit is invalidNotSupported
, if this is not an S-class productUnknown
, on any unexpected error
§Device Support
For S-class products. Available readings depend on the product.
sourcepub fn set_led_color(&mut self, color: LedColor) -> Result<(), NvmlError>
pub fn set_led_color(&mut self, color: LedColor) -> Result<(), NvmlError>
Sets the LED color for this Unit
.
Requires root/admin permissions. This operation takes effect immediately.
Note: Current S-class products don’t provide unique LEDs for each unit. As such,
both front and back LEDs will be toggled in unison regardless of which unit is
specified with this method (aka the Unit
represented by this struct).
§Errors
Uninitialized
, if the library has not been successfully initializedInvalidArg
, if the unit is invalidNotSupported
, if this is not an S-class productNoPermission
, if the user doesn’t have permission to perform this operationUnknown
, on any unexpected error
§Device Support
For S-class products.