From b8e972b70f3ac261a3c3e52e700af8ef417b8c1d Mon Sep 17 00:00:00 2001 From: JYX Date: Sat, 26 Nov 2022 09:06:10 +0800 Subject: [PATCH] Fix running_compute_processes count handling (#36) * Fix running_compute_processes count handling Consistent with running_graphics_processes --- CHANGELOG.md | 7 +++++++ nvml-wrapper/src/device.rs | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6817e1c..423def8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,13 @@ This file describes the changes / additions / fixes between wrapper releases, tr * `Brand` * Added new variants ([#35](https://github.com/Cldfire/nvml-wrapper/pull/35) - @nemosupremo) +### Fixed + +* `Device` + * `running_compute_processes()` + * Fixed count handling ([#36](https://github.com/Cldfire/nvml-wrapper/pull/36) - @jjyyxx) + * This bug would have caused five blank process information structs to be returned in addition to actual process information if there were any running compute processes. + ### Internal * SPDX expressions in `Cargo.toml` files have been updated to avoid using the now-deprecated slash syntax ([#32](https://github.com/Cldfire/nvml-wrapper/pull/32) - @KisaragiEffective) diff --git a/nvml-wrapper/src/device.rs b/nvml-wrapper/src/device.rs index 71c4e25..9fe9958 100644 --- a/nvml-wrapper/src/device.rs +++ b/nvml-wrapper/src/device.rs @@ -565,7 +565,7 @@ impl<'nvml> Device<'nvml> { unsafe { let mut count: c_uint = match self.running_compute_processes_count()? { 0 => return Ok(vec![]), - value => value + 5, + value => value, }; // Add a bit of headroom in case more processes are launched in // between the above call to get the expected count and the time we @@ -575,6 +575,7 @@ impl<'nvml> Device<'nvml> { nvml_try(sym(self.device, &mut count, processes.as_mut_ptr()))?; + processes.truncate(count as usize); Ok(processes.into_iter().map(ProcessInfo::from).collect()) } }