Skip to main content

GpmSample

Struct GpmSample 

Source
pub struct GpmSample<'nvml> { /* private fields */ }
Expand description

Handle to a GPM (GPU Performance Monitoring) sample.

GPM enables collecting fine-grained GPU performance metrics (SM occupancy, tensor utilization, PCIe/NVLink bandwidth, etc.) on Hopper+ GPUs. Metrics are computed by taking two time-separated samples and comparing them via gpm_metrics_get.

Operations on a sample are not thread-safe. It does not, therefore, implement Sync.

You can obtain a GpmSample via crate::Device::gpm_sample() or crate::Device::gpm_mig_sample().

Lifetimes are used to enforce that each GpmSample instance cannot be used after the Nvml instance it was obtained from is dropped.

Implementations§

Source§

impl<'nvml> GpmSample<'nvml>

Source

pub unsafe fn from_handle(nvml: &'nvml Nvml, sample: nvmlGpmSample_t) -> Self

Wrap a raw sample handle.

The returned GpmSample takes ownership of the handle and will free it on drop.

§Safety
  • The handle must have been allocated by nvmlGpmSampleAlloc via the same loaded NVML library as nvml and must not already have been freed.
  • Nothing else may free the handle afterward — neither another GpmSample wrapping the same handle nor a manual nvmlGpmSampleFree call — as that would result in a double-free. Use Self::into_handle to release ownership from an existing GpmSample before reconstructing it with this function.
Source

pub fn free(self) -> Result<(), NvmlError>

Use this to free the sample if you care about handling potential errors (the Drop implementation ignores errors!).

§Errors
  • Uninitialized, if the library has not been successfully initialized
  • Unknown, on any unexpected error
Source

pub unsafe fn handle(&self) -> nvmlGpmSample_t

Get the raw sample handle.

The handle is borrowed: this GpmSample still owns the sample and will free it on drop.

§Safety

This is unsafe to prevent it from being used without care. In particular, you must avoid creating a new GpmSample from this handle (e.g. via Self::from_handle) and allowing both this GpmSample and the newly created one to drop (which would result in a double-free). To transfer ownership of the sample out of the wrapper, use Self::into_handle instead.

Source

pub fn into_handle(self) -> nvmlGpmSample_t

Consume this GpmSample and return the raw sample handle without freeing it.

The caller takes ownership of the handle and is responsible for freeing it, either by calling nvmlGpmSampleFree manually or by reconstructing a GpmSample with Self::from_handle and letting that free it.

Source

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

Get a reference to the Nvml instance this sample was created from.

Trait Implementations§

Source§

impl<'nvml> Debug for GpmSample<'nvml>

Source§

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

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

impl<'nvml> Drop for GpmSample<'nvml>

This Drop implementation ignores errors! Use the .free() method on the GpmSample struct if you care about handling them.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'nvml> Send for GpmSample<'nvml>

Auto Trait Implementations§

§

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

§

impl<'nvml> !Sync for GpmSample<'nvml>

§

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

§

impl<'nvml> Freeze for GpmSample<'nvml>

§

impl<'nvml> Unpin for GpmSample<'nvml>

§

impl<'nvml> UnsafeUnpin for GpmSample<'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>,

Source§

type Error = !

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>,

Source§

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.