Skip to content

Commit 94f8239

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

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

nvml-wrapper/src/device.rs

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

627+
fn mps_running_compute_processes_count(&self) -> Result<c_uint, NvmlError> {
628+
let sym = nvml_sym(
629+
self.nvml
630+
.lib
631+
.nvmlDeviceGetMPSComputeRunningProcesses_v3
632+
.as_ref(),
633+
)?;
634+
635+
unsafe {
636+
let mut len: c_uint = 0;
637+
638+
match sym(self.device, &mut len, ptr::null_mut()) {
639+
nvmlReturn_enum_NVML_ERROR_INSUFFICIENT_SIZE => Ok(len),
640+
another_attempt => nvml_try(another_attempt).map(|_| 0),
641+
}
642+
}
643+
}
644+
645+
/**
646+
Gets information about processes with a compute context running on this `Device`.
647+
Note that processes list can differ between the accounting call and the list gathering
648+
649+
# Errors
650+
651+
* `Uninitialized`, if the library has not been successfully initialized
652+
* `InvalidArg`, if this `Device` is invalid
653+
* `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible
654+
* `Unknown`, on any unexpected error
655+
656+
# Device Support
657+
658+
Supports Volta or newer fully supported devices.
659+
*/
660+
#[doc(alias = "nvmlDeviceGetMPSComputeRunningProcesses_v3")]
661+
pub fn mps_running_compute_processes(&self) -> Result<Vec<ProcessInfo>, NvmlError> {
662+
let sym = nvml_sym(
663+
self.nvml
664+
.lib
665+
.nvmlDeviceGetMPSComputeRunningProcesses_v3
666+
.as_ref(),
667+
)?;
668+
669+
unsafe {
670+
let mut len: c_uint = match self.mps_running_compute_processes_count()? {
671+
0 => return Ok(vec![]),
672+
value => value,
673+
};
674+
675+
let mut processes: Vec<nvmlProcessInfo_t> = Vec::with_capacity(len as usize);
676+
677+
nvml_try(sym(self.device, &mut len, processes.as_mut_ptr()))?;
678+
679+
processes.set_len(len as usize);
680+
Ok(processes.into_iter().map(ProcessInfo::from).collect())
681+
}
682+
}
683+
627684
/**
628685
Gets the number of processes with a compute context running on this `Device`.
629686
@@ -6633,6 +6690,12 @@ mod test {
66336690
test_with_device(3, &nvml, |device| device.running_compute_processes_v2())
66346691
}
66356692

6693+
#[test]
6694+
fn mps_running_compute_processes() {
6695+
let nvml = nvml();
6696+
test_with_device(3, &nvml, |device| device.mps_running_compute_processes())
6697+
}
6698+
66366699
#[cfg(target_os = "linux")]
66376700
#[test]
66386701
fn cpu_affinity() {

0 commit comments

Comments
 (0)