diff --git a/nvml-wrapper/src/device.rs b/nvml-wrapper/src/device.rs index 2173e40..c70b3ed 100644 --- a/nvml-wrapper/src/device.rs +++ b/nvml-wrapper/src/device.rs @@ -2681,6 +2681,37 @@ impl<'nvml> Device<'nvml> { } } + /** + Get Gpu instance profile info for a give profile. + # Errors + + * `Uninitialized`, if the library has not been successfully initialized + * `InvalidArg`, if this `Device` is invalid + * `NotSupported`, if this `Device` does not support this feature + * `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible + * `Unknown`, on any unexpected error + + # Platform Support + + Only supports Linux. + + # Device Support + + Supports Ampere and newer fully supported devices. + */ + #[cfg(target_os = "linux")] + #[doc(alias = "nvmlDeviceGetGpuInstanceProfileInfo")] + pub fn profile_info(&self, profile: u32) -> Result { + let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetGpuInstanceProfileInfo.as_ref())?; + + unsafe { + let mut info: nvmlGpuInstanceProfileInfo_t = mem::zeroed(); + nvml_try(sym(self.device, profile, &mut info))?; + + Ok(info.into()) + } + } + /** Get GPU instance placements. A placement is a given location of a GPU in a device. @@ -6900,6 +6931,13 @@ mod test { test_with_device(3, &nvml, |device| device.possible_placements(0)) } + #[cfg(target_os = "linux")] + #[test] + fn profile_info() { + let nvml = nvml(); + test_with_device(3, &nvml, |device| device.profile_info(0)) + } + #[test] fn mig_mode() { let nvml = nvml(); diff --git a/nvml-wrapper/src/struct_wrappers/device.rs b/nvml-wrapper/src/struct_wrappers/device.rs index 5a69886..9a4bd11 100644 --- a/nvml-wrapper/src/struct_wrappers/device.rs +++ b/nvml-wrapper/src/struct_wrappers/device.rs @@ -757,6 +757,41 @@ impl TryFrom for ClockOffset { } } +/// Profile info. +#[derive(Debug, Clone, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct ProfileInfo { + pub copy_engine_count: u32, + pub decoder_count: u32, + pub encoder_count: u32, + pub id: u32, + pub instance_count: u32, + pub is_p2p_supported: bool, + pub jpeg_count: u32, + pub memory_size_mb: u64, + pub multiprocessor_count: u32, + pub ofa_count: u32, + pub slice_count: u32, +} + +impl From for ProfileInfo { + fn from(struct_: nvmlGpuInstanceProfileInfo_t) -> Self { + Self { + copy_engine_count: struct_.copyEngineCount, + decoder_count: struct_.decoderCount, + encoder_count: struct_.encoderCount, + id: struct_.id, + instance_count: struct_.instanceCount, + is_p2p_supported: struct_.isP2pSupported > 0, + jpeg_count: struct_.jpegCount, + memory_size_mb: struct_.memorySizeMB, + multiprocessor_count: struct_.multiprocessorCount, + ofa_count: struct_.ofaCount, + slice_count: struct_.sliceCount, + } + } +} + /// MIG profile placements #[derive(Debug, Clone, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] diff --git a/nvml-wrapper/src/test_utils.rs b/nvml-wrapper/src/test_utils.rs index 2307f4d..528651b 100644 --- a/nvml-wrapper/src/test_utils.rs +++ b/nvml-wrapper/src/test_utils.rs @@ -112,6 +112,7 @@ impl ShouldPrint for ClockOffset {} impl ShouldPrint for MigMode {} impl ShouldPrint for Vec {} impl ShouldPrint for (VgpuVersion, VgpuVersion) {} +impl ShouldPrint for ProfileInfo {} #[cfg(target_os = "windows")] impl ShouldPrint for DriverModelState {}