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>

source

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.

source

pub fn nvml(&self) -> &'nvml Nvml

Access the NVML reference this struct wraps

source

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.

source

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 initialized
  • InvalidArg, if the unit is invalid
  • Unknown, on any unexpected error
§Device Support

For S-class products.

source

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 initialized
  • InvalidArg, if the unit is invalid
  • Unknown, on any unexpected error
§Device Support

For S-class products.

source

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 initialized
  • InvalidArg, if the unit is invalid
  • NotSupported, if this is not an S-class product
  • UnexpectedVariant, for which you can read the docs for
  • Unknown, on any unexpected error
§Device Support

For S-class products.

source

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 initialized
  • InvalidArg, if the unit is invalid
  • NotSupported, if this is not an S-class product
  • Utf8Error, if the string obtained from the C function is not valid Utf8
  • Unknown, on any unexpected error
§Device Support

For S-class products.

source

pub fn psu_info(&self) -> Result<PsuInfo, NvmlError>

Gets the PSU stats for this Unit.

§Errors
  • Uninitialized, if the library has not been successfully initialized
  • InvalidArg, if the unit is invalid
  • NotSupported, if this is not an S-class product
  • Utf8Error, if the string obtained from the C function is not valid Utf8
  • Unknown, on any unexpected error
§Device Support

For S-class products.

source

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 initialized
  • InvalidArg, if the unit is invalid
  • NotSupported, if this is not an S-class product
  • Unknown, on any unexpected error
§Device Support

For S-class products. Available readings depend on the product.

source

pub fn info(&self) -> Result<UnitInfo, NvmlError>

Gets the static information associated with this Unit.

§Errors
  • Uninitialized, if the library has not been successfully initialized
  • InvalidArg, if the unit is invalid
  • Utf8Error, if the string obtained from the C function is not valid Utf8
§Device Support

For S-class products.

source

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 initialized
  • InvalidArg, if the unit is invalid
  • NotSupported, if this is not an S-class product
  • NoPermission, if the user doesn’t have permission to perform this operation
  • Unknown, on any unexpected error
§Device Support

For S-class products.

Trait Implementations§

source§

impl<'nvml> Debug for Unit<'nvml>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'nvml> Send for Unit<'nvml>

source§

impl<'nvml> Sync for Unit<'nvml>

Auto Trait Implementations§

§

impl<'nvml> !RefUnwindSafe for Unit<'nvml>

§

impl<'nvml> Unpin for Unit<'nvml>

§

impl<'nvml> !UnwindSafe for Unit<'nvml>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.