Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions nvml-wrapper/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2681,6 +2681,37 @@
}
}

/**
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<ProfileInfo, NvmlError> {
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.

Expand Down Expand Up @@ -6339,14 +6370,14 @@
NVIDIA does not provide any information as to how to obtain a valid NvLink
value, so you're on your own there.
*/
pub fn link_wrapper_for(&self, link: u32) -> NvLink {

Check warning on line 6373 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Clippy

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6373 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (macos-latest, stable)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6373 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (macos-latest, stable)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6373 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, stable)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6373 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, stable)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6373 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (windows-latest, stable)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6373 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (windows-latest, stable)

hiding a lifetime that's elided elsewhere is confusing
NvLink { device: self, link }
}

// vGPU

/// Obtain a list of vGPU type (profiles) supported by the device, if any.
pub fn vgpu_supported_types(&self) -> Result<Vec<VgpuType>, NvmlError> {

Check warning on line 6380 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Clippy

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6380 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (macos-latest, stable)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6380 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (macos-latest, stable)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6380 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, stable)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6380 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, stable)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6380 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (windows-latest, stable)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6380 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (windows-latest, stable)

hiding a lifetime that's elided elsewhere is confusing
let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetSupportedVgpus.as_ref())?;
let mut ids = vec![];

Expand All @@ -6366,7 +6397,7 @@
}

/// Obtain a list of vGPU type (profiles) creatable on the device, if any.
pub fn vgpu_creatable_types(&self) -> Result<Vec<VgpuType>, NvmlError> {

Check warning on line 6400 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Clippy

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6400 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (macos-latest, stable)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6400 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (macos-latest, stable)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6400 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, stable)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6400 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, stable)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6400 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (windows-latest, stable)

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 6400 in nvml-wrapper/src/device.rs

View workflow job for this annotation

GitHub Actions / Check (windows-latest, stable)

hiding a lifetime that's elided elsewhere is confusing
let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetCreatableVgpus.as_ref())?;
let mut ids = vec![];

Expand Down Expand Up @@ -6900,6 +6931,13 @@
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();
Expand Down
35 changes: 35 additions & 0 deletions nvml-wrapper/src/struct_wrappers/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,41 @@ impl TryFrom<nvmlClockOffset_v1_t> 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<nvmlGpuInstanceProfileInfo_t> 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))]
Expand Down
1 change: 1 addition & 0 deletions nvml-wrapper/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ impl ShouldPrint for ClockOffset {}
impl ShouldPrint for MigMode {}
impl ShouldPrint for Vec<GpuInstancePlacement> {}
impl ShouldPrint for (VgpuVersion, VgpuVersion) {}
impl ShouldPrint for ProfileInfo {}

#[cfg(target_os = "windows")]
impl ShouldPrint for DriverModelState {}
Expand Down
Loading