Skip to content

Commit 6c47dcc

Browse files
authored
Update nvmlDeviceGetMemoryInfo to version 2 to be consistent with nvidia-smi (#58)
Update API call used in Device::memory_info to use nvmlDeviceGetMemoryInfo_v2. Fixes #57.
1 parent be1dfba commit 6c47dcc

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

nvml-wrapper/src/device.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,10 +2128,13 @@ impl<'nvml> Device<'nvml> {
21282128
// Tested
21292129
#[doc(alias = "nvmlDeviceGetMemoryInfo")]
21302130
pub fn memory_info(&self) -> Result<MemoryInfo, NvmlError> {
2131-
let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetMemoryInfo.as_ref())?;
2131+
let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetMemoryInfo_v2.as_ref())?;
21322132

21332133
unsafe {
2134-
let mut info: nvmlMemory_t = mem::zeroed();
2134+
let mut info: nvmlMemory_v2_t = mem::zeroed();
2135+
2136+
// Implements NVML_STRUCT_VERSION(Memory, 2), as detailed in nvml.h (https://github.com/NVIDIA/nvidia-settings/issues/78)
2137+
info.version = (std::mem::size_of::<nvmlMemory_v2_t>() | (2_usize << 24_usize)) as u32;
21352138
nvml_try(sym(self.device, &mut info))?;
21362139

21372140
Ok(info.into())

nvml-wrapper/src/struct_wrappers/device.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,21 +290,30 @@ impl From<nvmlEccErrorCounts_t> for EccErrorCounts {
290290
pub struct MemoryInfo {
291291
/// Unallocated FB memory.
292292
pub free: u64,
293+
294+
/// Reserved FB memory.
295+
pub reserved: u64,
296+
293297
/// Total installed FB memory.
294298
pub total: u64,
295299
/// Allocated FB memory.
296300
///
297301
/// Note that the driver/GPU always sets aside a small amount of memory for
298302
/// bookkeeping.
299303
pub used: u64,
304+
305+
/// Struct version, must be set according to API specification before calling the API.
306+
pub version: u32,
300307
}
301308

302-
impl From<nvmlMemory_t> for MemoryInfo {
303-
fn from(struct_: nvmlMemory_t) -> Self {
309+
impl From<nvmlMemory_v2_t> for MemoryInfo {
310+
fn from(struct_: nvmlMemory_v2_t) -> Self {
304311
Self {
305312
free: struct_.free,
313+
reserved: struct_.reserved,
306314
total: struct_.total,
307315
used: struct_.used,
316+
version: struct_.version,
308317
}
309318
}
310319
}

0 commit comments

Comments
 (0)