Skip to content

Commit b927e5e

Browse files
authored
adding the MPS version of running_compute_processes for >= Volta. (#112)
1 parent a7323db commit b927e5e

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
@@ -651,6 +651,63 @@ impl<'nvml> Device<'nvml> {
651651
}
652652
}
653653

654+
fn mps_running_compute_processes_count(&self) -> Result<c_uint, NvmlError> {
655+
let sym = nvml_sym(
656+
self.nvml
657+
.lib
658+
.nvmlDeviceGetMPSComputeRunningProcesses_v3
659+
.as_ref(),
660+
)?;
661+
662+
unsafe {
663+
let mut len: c_uint = 0;
664+
665+
match sym(self.device, &mut len, ptr::null_mut()) {
666+
nvmlReturn_enum_NVML_ERROR_INSUFFICIENT_SIZE => Ok(len),
667+
another_attempt => nvml_try(another_attempt).map(|_| 0),
668+
}
669+
}
670+
}
671+
672+
/**
673+
Gets information about processes with a compute context running on this `Device`.
674+
Note that processes list can differ between the accounting call and the list gathering
675+
676+
# Errors
677+
678+
* `Uninitialized`, if the library has not been successfully initialized
679+
* `InvalidArg`, if this `Device` is invalid
680+
* `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible
681+
* `Unknown`, on any unexpected error
682+
683+
# Device Support
684+
685+
Supports Volta or newer fully supported devices.
686+
*/
687+
#[doc(alias = "nvmlDeviceGetMPSComputeRunningProcesses_v3")]
688+
pub fn mps_running_compute_processes(&self) -> Result<Vec<ProcessInfo>, NvmlError> {
689+
let sym = nvml_sym(
690+
self.nvml
691+
.lib
692+
.nvmlDeviceGetMPSComputeRunningProcesses_v3
693+
.as_ref(),
694+
)?;
695+
696+
unsafe {
697+
let mut len: c_uint = match self.mps_running_compute_processes_count()? {
698+
0 => return Ok(vec![]),
699+
value => value,
700+
};
701+
702+
let mut processes: Vec<nvmlProcessInfo_t> = Vec::with_capacity(len as usize);
703+
704+
nvml_try(sym(self.device, &mut len, processes.as_mut_ptr()))?;
705+
706+
processes.set_len(len as usize);
707+
Ok(processes.into_iter().map(ProcessInfo::from).collect())
708+
}
709+
}
710+
654711
/**
655712
Gets the number of processes with a compute context running on this `Device`.
656713
@@ -6697,6 +6754,12 @@ mod test {
66976754
test_with_device(3, &nvml, |device| device.running_compute_processes_v2())
66986755
}
66996756

6757+
#[test]
6758+
fn mps_running_compute_processes() {
6759+
let nvml = nvml();
6760+
test_with_device(3, &nvml, |device| device.mps_running_compute_processes())
6761+
}
6762+
67006763
#[cfg(target_os = "linux")]
67016764
#[test]
67026765
fn cpu_affinity() {

0 commit comments

Comments
 (0)