diff --git a/nvml-wrapper/src/device.rs b/nvml-wrapper/src/device.rs index 591c640..6bfd183 100644 --- a/nvml-wrapper/src/device.rs +++ b/nvml-wrapper/src/device.rs @@ -5314,6 +5314,44 @@ impl<'nvml> Device<'nvml> { } } + /** + Get the list of performance modes for `Device` + + Originally, NVML returns as a list in a form of a single string separated by comma. + + # Errors + + * `Uninitialized`, if the library has not been successfully initialized + * `NotSupported`, if the platform does not support this feature or some of the + requested event types. + * `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible + * `Unknown`, on any unexpected error. **If this error is returned, the `set` you + + # Platform Support + + Only supports Linux. + */ + // Checked against local + // Tested + #[cfg(target_os = "linux")] + #[doc(alias = "nvmlDeviceGetPerformanceModes")] + pub fn performance_modes(&self) -> Result<(Vec, u32), NvmlError> { + let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetPerformanceModes.as_ref())?; + + unsafe { + let mut pmodes: nvmlDevicePerfModes_t = mem::zeroed(); + + nvml_try(sym(self.device, &mut pmodes))?; + + let modes_str = CStr::from_ptr(pmodes.str_.as_ptr()); + let modes = modes_str.to_str()?; + Ok(( + modes.split(';').map(str::to_string).collect(), + pmodes.version, + )) + } + } + /** Removes this `Device` from the view of both NVML and the NVIDIA kernel driver. @@ -6514,6 +6552,13 @@ mod test { test_with_device(3, &nvml, |device| device.is_drain_enabled(None)) } + #[cfg(target_os = "linux")] + #[test] + fn performance_modes() { + let nvml = nvml(); + test_with_device(3, &nvml, |device| device.performance_modes()) + } + #[cfg(target_os = "linux")] #[test] fn device_attributes() { diff --git a/nvml-wrapper/src/test_utils.rs b/nvml-wrapper/src/test_utils.rs index 72f1b8d..7f93ea6 100644 --- a/nvml-wrapper/src/test_utils.rs +++ b/nvml-wrapper/src/test_utils.rs @@ -105,6 +105,7 @@ impl ShouldPrint for PowerSource {} impl ShouldPrint for DeviceArchitecture {} impl ShouldPrint for PcieLinkMaxSpeed {} impl ShouldPrint for DeviceAttributes {} +impl ShouldPrint for (Vec, u32) {} #[cfg(target_os = "windows")] impl ShouldPrint for DriverModelState {}