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>
impl<'nvml> GpmSample<'nvml>
Sourcepub unsafe fn from_handle(nvml: &'nvml Nvml, sample: nvmlGpmSample_t) -> Self
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
nvmlGpmSampleAllocvia the same loaded NVML library asnvmland must not already have been freed. - Nothing else may free the handle afterward — neither another
GpmSamplewrapping the same handle nor a manualnvmlGpmSampleFreecall — as that would result in a double-free. UseSelf::into_handleto release ownership from an existingGpmSamplebefore reconstructing it with this function.
Sourcepub fn free(self) -> Result<(), NvmlError>
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 initializedUnknown, on any unexpected error
Sourcepub unsafe fn handle(&self) -> nvmlGpmSample_t
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.
Sourcepub fn into_handle(self) -> nvmlGpmSample_t
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.
Trait Implementations§
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.
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.