Skip to content
Merged
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
7 changes: 5 additions & 2 deletions nvml-wrapper/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1959,10 +1959,13 @@ impl<'nvml> Device<'nvml> {
// Tested
#[doc(alias = "nvmlDeviceGetMemoryInfo")]
pub fn memory_info(&self) -> Result<MemoryInfo, NvmlError> {
let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetMemoryInfo.as_ref())?;
let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetMemoryInfo_v2.as_ref())?;

unsafe {
let mut info: nvmlMemory_t = mem::zeroed();
let mut info: nvmlMemory_v2_t = mem::zeroed();

// Implements NVML_STRUCT_VERSION(Memory, 2), as detailed in nvml.h (https://github.com/NVIDIA/nvidia-settings/issues/78)
info.version = (std::mem::size_of::<nvmlMemory_v2_t>() | (2_usize << 24_usize)) as u32;
nvml_try(sym(self.device, &mut info))?;

Ok(info.into())
Expand Down
13 changes: 11 additions & 2 deletions nvml-wrapper/src/struct_wrappers/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,30 @@ impl From<nvmlEccErrorCounts_t> for EccErrorCounts {
pub struct MemoryInfo {
/// Unallocated FB memory.
pub free: u64,

/// Reserved FB memory.
pub reserved: u64,

/// Total installed FB memory.
pub total: u64,
/// Allocated FB memory.
///
/// Note that the driver/GPU always sets aside a small amount of memory for
/// bookkeeping.
pub used: u64,

/// Struct version, must be set according to API specification before calling the API.
pub version: u32,
}

impl From<nvmlMemory_t> for MemoryInfo {
fn from(struct_: nvmlMemory_t) -> Self {
impl From<nvmlMemory_v2_t> for MemoryInfo {
fn from(struct_: nvmlMemory_v2_t) -> Self {
Self {
free: struct_.free,
reserved: struct_.reserved,
total: struct_.total,
used: struct_.used,
version: struct_.version,
}
}
}
Expand Down