Skip to content

Commit 3be0a43

Browse files
authored
adding device::performance_modes() (#88)
Adds device::performance_modes()
1 parent add8fc2 commit 3be0a43

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

nvml-wrapper/src/device.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5793,6 +5793,44 @@ impl<'nvml> Device<'nvml> {
57935793
}
57945794
}
57955795

5796+
/**
5797+
Get the list of performance modes for `Device`
5798+
5799+
Originally, NVML returns as a list in a form of a single string separated by comma.
5800+
5801+
# Errors
5802+
5803+
* `Uninitialized`, if the library has not been successfully initialized
5804+
* `NotSupported`, if the platform does not support this feature or some of the
5805+
requested event types.
5806+
* `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible
5807+
* `Unknown`, on any unexpected error. **If this error is returned, the `set` you
5808+
5809+
# Platform Support
5810+
5811+
Only supports Linux.
5812+
*/
5813+
// Checked against local
5814+
// Tested
5815+
#[cfg(target_os = "linux")]
5816+
#[doc(alias = "nvmlDeviceGetPerformanceModes")]
5817+
pub fn performance_modes(&self) -> Result<(Vec<String>, u32), NvmlError> {
5818+
let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetPerformanceModes.as_ref())?;
5819+
5820+
unsafe {
5821+
let mut pmodes: nvmlDevicePerfModes_t = mem::zeroed();
5822+
5823+
nvml_try(sym(self.device, &mut pmodes))?;
5824+
5825+
let modes_str = CStr::from_ptr(pmodes.str_.as_ptr());
5826+
let modes = modes_str.to_str()?;
5827+
Ok((
5828+
modes.split(';').map(str::to_string).collect(),
5829+
pmodes.version,
5830+
))
5831+
}
5832+
}
5833+
57965834
/**
57975835
Gets the active vGPU instances for `Device`
57985836
@@ -7112,6 +7150,13 @@ mod test {
71127150
test_with_device(3, &nvml, |device| device.is_drain_enabled(None))
71137151
}
71147152

7153+
#[cfg(target_os = "linux")]
7154+
#[test]
7155+
fn performance_modes() {
7156+
let nvml = nvml();
7157+
test_with_device(3, &nvml, |device| device.performance_modes())
7158+
}
7159+
71157160
#[cfg(target_os = "linux")]
71167161
#[test]
71177162
fn active_vgpus() {

nvml-wrapper/src/test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ impl ShouldPrint for PowerSource {}
106106
impl ShouldPrint for DeviceArchitecture {}
107107
impl ShouldPrint for PcieLinkMaxSpeed {}
108108
impl ShouldPrint for DeviceAttributes {}
109+
impl ShouldPrint for (Vec<String>, u32) {}
109110
impl ShouldPrint for GpuVirtualizationMode {}
110111
impl ShouldPrint for ClockOffset {}
111112
impl ShouldPrint for MigMode {}

0 commit comments

Comments
 (0)