From 0f46d6effcad98c756bccd5a747fdb6ff5ac2505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20R=C3=B8d?= Date: Sun, 24 Mar 2024 20:43:44 -0700 Subject: [PATCH 1/3] Update to nvmlDeviceGetMemoryInfo_v2 --- nvml-wrapper/src/device.rs | 13 +++++++++---- nvml-wrapper/src/struct_wrappers/device.rs | 11 +++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/nvml-wrapper/src/device.rs b/nvml-wrapper/src/device.rs index 2e46a24..1a1e114 100644 --- a/nvml-wrapper/src/device.rs +++ b/nvml-wrapper/src/device.rs @@ -1959,13 +1959,17 @@ impl<'nvml> Device<'nvml> { // Tested #[doc(alias = "nvmlDeviceGetMemoryInfo")] pub fn memory_info(&self) -> Result { - 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::() | (2_usize << 24_usize)) as u32; nvml_try(sym(self.device, &mut info))?; - Ok(info.into()) + let result = info.into(); + + Ok(result) } } @@ -5316,6 +5320,7 @@ mod test { } #[test] + #[ignore = "my machine doesn't support this call"] fn fan_speed() { let nvml = nvml(); test_with_device(3, &nvml, |device| device.fan_speed(0)) @@ -5428,7 +5433,7 @@ mod test { #[test] fn memory_info() { let nvml = nvml(); - test_with_device(3, &nvml, |device| device.memory_info()) + test_with_device(3, &nvml, |device| device.memory_info()); } #[cfg(target_os = "linux")] diff --git a/nvml-wrapper/src/struct_wrappers/device.rs b/nvml-wrapper/src/struct_wrappers/device.rs index 213d16b..772a7b4 100644 --- a/nvml-wrapper/src/struct_wrappers/device.rs +++ b/nvml-wrapper/src/struct_wrappers/device.rs @@ -290,6 +290,9 @@ impl From for EccErrorCounts { pub struct MemoryInfo { /// Unallocated FB memory. pub free: u64, + + pub reserved: u64, + /// Total installed FB memory. pub total: u64, /// Allocated FB memory. @@ -297,14 +300,18 @@ pub struct MemoryInfo { /// Note that the driver/GPU always sets aside a small amount of memory for /// bookkeeping. pub used: u64, + + pub version: u32 } -impl From for MemoryInfo { - fn from(struct_: nvmlMemory_t) -> Self { +impl From 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 } } } From c794e89ad964f679dffd44eb09bc8f7c5122958d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20R=C3=B8d?= Date: Sun, 24 Mar 2024 21:00:37 -0700 Subject: [PATCH 2/3] Documentation, clean up --- nvml-wrapper/src/device.rs | 6 ++---- nvml-wrapper/src/struct_wrappers/device.rs | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nvml-wrapper/src/device.rs b/nvml-wrapper/src/device.rs index 1a1e114..30b4a7c 100644 --- a/nvml-wrapper/src/device.rs +++ b/nvml-wrapper/src/device.rs @@ -1963,13 +1963,12 @@ impl<'nvml> Device<'nvml> { unsafe { 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::() | (2_usize << 24_usize)) as u32; nvml_try(sym(self.device, &mut info))?; - let result = info.into(); - - Ok(result) + Ok(info.into()) } } @@ -5320,7 +5319,6 @@ mod test { } #[test] - #[ignore = "my machine doesn't support this call"] fn fan_speed() { let nvml = nvml(); test_with_device(3, &nvml, |device| device.fan_speed(0)) diff --git a/nvml-wrapper/src/struct_wrappers/device.rs b/nvml-wrapper/src/struct_wrappers/device.rs index 772a7b4..ab820d6 100644 --- a/nvml-wrapper/src/struct_wrappers/device.rs +++ b/nvml-wrapper/src/struct_wrappers/device.rs @@ -291,6 +291,7 @@ pub struct MemoryInfo { /// Unallocated FB memory. pub free: u64, + /// Reserved FB memory. pub reserved: u64, /// Total installed FB memory. @@ -301,6 +302,7 @@ pub struct MemoryInfo { /// bookkeeping. pub used: u64, + /// Struct version, must be set according to API specification before calling the API. pub version: u32 } From 235b27d0bd77756a9ef98f8e678886c7b91cbba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20R=C3=B8d?= Date: Sun, 24 Mar 2024 21:02:13 -0700 Subject: [PATCH 3/3] Formatting --- nvml-wrapper/src/device.rs | 2 +- nvml-wrapper/src/struct_wrappers/device.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nvml-wrapper/src/device.rs b/nvml-wrapper/src/device.rs index 30b4a7c..19745b9 100644 --- a/nvml-wrapper/src/device.rs +++ b/nvml-wrapper/src/device.rs @@ -5431,7 +5431,7 @@ mod test { #[test] fn memory_info() { let nvml = nvml(); - test_with_device(3, &nvml, |device| device.memory_info()); + test_with_device(3, &nvml, |device| device.memory_info()) } #[cfg(target_os = "linux")] diff --git a/nvml-wrapper/src/struct_wrappers/device.rs b/nvml-wrapper/src/struct_wrappers/device.rs index ab820d6..3e6cc45 100644 --- a/nvml-wrapper/src/struct_wrappers/device.rs +++ b/nvml-wrapper/src/struct_wrappers/device.rs @@ -303,7 +303,7 @@ pub struct MemoryInfo { pub used: u64, /// Struct version, must be set according to API specification before calling the API. - pub version: u32 + pub version: u32, } impl From for MemoryInfo { @@ -313,7 +313,7 @@ impl From for MemoryInfo { reserved: struct_.reserved, total: struct_.total, used: struct_.used, - version: struct_.version + version: struct_.version, } } }