Skip to content

Commit 3b221e2

Browse files
committed
adding the MPS version of running_compute_processes for >= Volta.
1 parent 7e0752f commit 3b221e2

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

nvml-wrapper/src/device.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,48 @@ impl<'nvml> Device<'nvml> {
624624
}
625625
}
626626

627+
/**
628+
Gets information about processes with a compute context running on this `Device`.
629+
Note that processes list can differ between the accounting call and the list gathering
630+
631+
# Errors
632+
633+
* `Uninitialized`, if the library has not been successfully initialized
634+
* `InvalidArg`, if this `Device` is invalid
635+
* `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible
636+
* `Unknown`, on any unexpected error
637+
638+
# Device Support
639+
640+
Supports Volta or newer fully supported devices.
641+
*/
642+
#[doc(alias = "nvmlDeviceGetiMPSComputeRunningProcesses_v3")]
643+
pub fn mps_running_compute_processes(&self) -> Result<Vec<ProcessInfo>, NvmlError> {
644+
let sym = nvml_sym(
645+
self.nvml
646+
.lib
647+
.nvmlDeviceGetMPSComputeRunningProcesses_v3
648+
.as_ref(),
649+
)?;
650+
651+
unsafe {
652+
let mut hints: c_uint = 0;
653+
654+
nvml_try(sym(self.device, &mut hints, ptr::null_mut()))?;
655+
656+
let mut hints_shr = match hints.checked_shr(1) {
657+
Some(h) => h,
658+
None => hints,
659+
};
660+
let mut processes: Vec<nvmlProcessInfo_t> = Vec::with_capacity(hints_shr as usize);
661+
662+
nvml_try(sym(self.device, &mut hints_shr, processes.as_mut_ptr()))?;
663+
664+
processes.truncate(hints_shr as usize);
665+
Ok(processes.into_iter().map(ProcessInfo::from).collect())
666+
}
667+
}
668+
627669
/**
628670
Gets the number of processes with a compute context running on this `Device`.
629671
@@ -6633,6 +6675,12 @@ mod test {
66336675
test_with_device(3, &nvml, |device| device.running_compute_processes_v2())
66346676
}
66356677

6678+
#[test]
6679+
fn mps_running_compute_processes() {
6680+
let nvml = nvml();
6681+
test_with_device(3, &nvml, |device| device.mps_running_compute_processes())
6682+
}
6683+
66366684
#[cfg(target_os = "linux")]
66376685
#[test]
66386686
fn cpu_affinity() {

0 commit comments

Comments
 (0)