Skip to content

adding device::active_vgpus() #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
41 changes: 41 additions & 0 deletions nvml-wrapper/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@

* `UnexpectedVariant`, for which you can read the docs for
* `IncorrectBits`, if bits are found in a session's info flags that don't
match the flags in this wrapper

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

View workflow job for this annotation

GitHub Actions / Clippy

doc list item overindented
* `Uninitialized`, if the library has not been successfully initialized
* `NotSupported`, if this `Device` does not support this feature
* `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible
Expand Down Expand Up @@ -3242,7 +3242,7 @@

* `Uninitialized`, if the library has not been successfully initialized
* `IncorrectBits`, if NVML returns any bits that do not correspond to flags in
`ThrottleReasons`

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

View workflow job for this annotation

GitHub Actions / Clippy

doc list item without indentation
* `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible
* `Unknown`, on any unexpected error

Expand Down Expand Up @@ -4289,7 +4289,7 @@
* `Uninitialized`, if the library has not been successfully initialized
* `InvalidArg`, if the `Device` is invalid
* `NotSupported`, if this `Device` does not support this feature or accounting mode
is disabled

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

View workflow job for this annotation

GitHub Actions / Clippy

doc list item without indentation
* `Unknown`, on any unexpected error

# Device Support
Expand Down Expand Up @@ -4351,7 +4351,7 @@
* `Uninitialized`, if the library has not been successfully initialized
* `InvalidArg`, if the `Device` is invalid
* `NotSupported`, if this `Device` does not support this feature or accounting
mode is disabled

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

View workflow job for this annotation

GitHub Actions / Clippy

doc list item without indentation
* `Unknown`, on any unexpected error
*/
// Checked against local
Expand Down Expand Up @@ -4408,9 +4408,9 @@
Note:
* Accounting mode needs to be on. See `.is_accounting_enabled()`.
* Only compute and graphics applications stats can be queried. Monitoring
applications can't be queried since they don't contribute to GPU utilization.

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

View workflow job for this annotation

GitHub Actions / Clippy

doc list item without indentation
* If a PID collision occurs, the stats of the latest process (the one that
terminated last) will be reported.

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

View workflow job for this annotation

GitHub Actions / Clippy

doc list item without indentation

# Errors

Expand All @@ -4418,7 +4418,7 @@
* `InvalidArg`, if the `Device` is invalid
* `NotFound`, if the process stats were not found
* `NotSupported`, if this `Device` does not support this feature or accounting
mode is disabled

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

View workflow job for this annotation

GitHub Actions / Clippy

doc list item without indentation
* `Unknown`, on any unexpected error

# Device Support
Expand Down Expand Up @@ -4452,8 +4452,8 @@

Note:
* This setting is not persistent and will default to disabled after the driver
unloads. Enable persistence mode to be sure the setting doesn't switch off

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

View workflow job for this annotation

GitHub Actions / Clippy

doc list item without indentation
to disabled.

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

View workflow job for this annotation

GitHub Actions / Clippy

doc list item without indentation
* Enabling accounting mode has no negative impact on GPU performance.
* Disabling accounting clears accounting information for all PIDs

Expand Down Expand Up @@ -4526,7 +4526,7 @@
* `Uninitialized`, if the library has not been successfully initialized
* `InvalidArg`, if the `Device` is invalid or `api_type` is invalid (shouldn't occur?)
* `NotSupported`, if this `Device` does not support changing API restrictions or
this `Device` does not support the feature that API restrictions are being set for

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

View workflow job for this annotation

GitHub Actions / Clippy

doc list item without indentation
(e.g. enabling/disabling auto boosted clocks is not supported by this `Device`).
* `NoPermission`, if the user doesn't have permission to perform this operation
* `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible
Expand Down Expand Up @@ -5314,6 +5314,40 @@
}
}

/**
Gets the active vGPU instances for `Device`

A list as Vec of vGPU handles is returned to be used with nvmlVgpuInstance* calls.

# Errors

* `Uninitialized`, if the library has not been successfully initialized
* `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible
* `Unknown`, on any unexpected error
* `NotSupported`, if the platform does not support this feature

# Platform Support

Only supports Linux.
*/
// Checked against local
// Tested
#[cfg(target_os = "linux")]
#[doc(alias = "nvmlDeviceGetActiveVgpus")]
pub fn active_vgpus(&self) -> Result<Vec<nvmlVgpuInstance_t>, NvmlError> {
let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetActiveVgpus.as_ref())?;

unsafe {
let mut count: u32 = mem::zeroed();

nvml_try(sym(self.device, std::ptr::null_mut(), &mut count))?;
let mut arr: Vec<nvmlVgpuInstance_t> = vec![0; count as usize];
nvml_try(sym(self.device, arr.as_mut_ptr(), &mut count))?;

Ok(arr)
}
}

/**
Removes this `Device` from the view of both NVML and the NVIDIA kernel driver.

Expand Down Expand Up @@ -6514,6 +6548,13 @@
test_with_device(3, &nvml, |device| device.is_drain_enabled(None))
}

#[cfg(target_os = "linux")]
#[test]
fn active_vgpus() {
let nvml = nvml();
test_with_device(3, &nvml, |device| device.active_vgpus())
}

#[cfg(target_os = "linux")]
#[test]
fn device_attributes() {
Expand Down
Loading