Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
samples: Only return samples that are actually valid.
The number of samples returned can be smaller than the number initially
returned by `samples_count`. Account for this by only returning as
many as are actually returned according to the second call to
`nvmlDeviceGetSamples` .
  • Loading branch information
umanwizard committed Oct 17, 2024
commit 746bf8032b9924475e914b309dc833d72ec3029f
6 changes: 4 additions & 2 deletions nvml-wrapper/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2606,24 +2606,26 @@ impl<'nvml> Device<'nvml> {

unsafe {
let mut val_type: nvmlValueType_t = mem::zeroed();
let mut count = match self.samples_count(&sample_type, timestamp)? {
let count = match self.samples_count(&sample_type, timestamp)? {
0 => return Ok(vec![]),
value => value,
};
let mut samples: Vec<nvmlSample_t> = vec![mem::zeroed(); count as usize];
let mut new_count = count;

nvml_try(sym(
self.device,
sample_type.as_c(),
timestamp,
&mut val_type,
&mut count,
&mut new_count,
samples.as_mut_ptr(),
))?;

let val_type_rust = SampleValueType::try_from(val_type)?;
Ok(samples
.into_iter()
.take(new_count as usize)
.map(|s| Sample::from_tag_and_struct(&val_type_rust, s))
.collect())
}
Expand Down