Skip to content

Commit 598e07e

Browse files
Merge branch 'rust-nvml:main' into main
2 parents 7552dac + 572095f commit 598e07e

File tree

9 files changed

+5493
-1198
lines changed

9 files changed

+5493
-1198
lines changed

nvml-wrapper-sys/nvml.h

Lines changed: 2839 additions & 716 deletions
Large diffs are not rendered by default.

nvml-wrapper-sys/src/bindings.rs

Lines changed: 1997 additions & 421 deletions
Large diffs are not rendered by default.

nvml-wrapper/src/device.rs

Lines changed: 462 additions & 17 deletions
Large diffs are not rendered by default.

nvml-wrapper/src/enums/device.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,34 @@ impl TryFrom<c_uint> for PcieLinkMaxSpeed {
350350
}
351351
}
352352
}
353+
354+
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
355+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
356+
#[repr(u32)]
357+
pub enum FanControlPolicy {
358+
TemperatureContinousSw = NVML_FAN_POLICY_TEMPERATURE_CONTINOUS_SW,
359+
Manual = NVML_FAN_POLICY_MANUAL,
360+
}
361+
362+
/// Returned by [`crate::Device::get_fan_control_policy()`].
363+
///
364+
/// Policy used for fan control.
365+
// TODO: technically this is an "enum wrapper" but the type on the C side isn't
366+
// an enum
367+
impl FanControlPolicy {
368+
pub fn as_c(&self) -> nvmlFanControlPolicy_t {
369+
*self as u32
370+
}
371+
}
372+
373+
impl TryFrom<nvmlFanControlPolicy_t> for FanControlPolicy {
374+
type Error = NvmlError;
375+
376+
fn try_from(value: nvmlFanControlPolicy_t) -> Result<Self, Self::Error> {
377+
match value {
378+
NVML_FAN_POLICY_TEMPERATURE_CONTINOUS_SW => Ok(Self::TemperatureContinousSw),
379+
NVML_FAN_POLICY_MANUAL => Ok(Self::TemperatureContinousSw),
380+
_ => Err(NvmlError::UnexpectedVariant(value)),
381+
}
382+
}
383+
}

nvml-wrapper/src/event.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ mod test {
172172
})
173173
}
174174

175-
#[cfg(feature = "test-local")]
176175
#[test]
177176
fn wait() {
178177
use crate::error::NvmlError;

nvml-wrapper/src/struct_wrappers/device.rs

Lines changed: 73 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
}
@@ -656,6 +665,68 @@ impl TryFrom<nvmlFBCSessionInfo_t> for FbcSessionInfo {
656665
}
657666
}
658667

668+
/// Hardware level attributes from a GPU device
669+
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
670+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
671+
pub struct DeviceAttributes {
672+
/// Streaming MultiProcessor Count
673+
pub multiprocessor_count: u32,
674+
/// Shared Copy Engine Count
675+
pub shared_copy_engine_count: u32,
676+
/// Shared Decoder Count
677+
pub shared_decoder_count: u32,
678+
/// Shared Encoder Count
679+
pub shared_encoder_count: u32,
680+
/// Shared JPEG Count
681+
pub shared_jpeg_count: u32,
682+
/// Shared OFA Count
683+
pub shared_ofa_count: u32,
684+
/// GPU instance slice Count
685+
pub gpu_instance_slice_count: u32,
686+
/// Compute Instance slice count
687+
pub compute_instance_slice_count: u32,
688+
/// Device memory size in MB
689+
pub memory_size_mb: u64,
690+
}
691+
692+
impl From<nvmlDeviceAttributes_t> for DeviceAttributes {
693+
fn from(struct_: nvmlDeviceAttributes_t) -> Self {
694+
Self {
695+
multiprocessor_count: struct_.multiprocessorCount,
696+
shared_copy_engine_count: struct_.sharedCopyEngineCount,
697+
shared_decoder_count: struct_.sharedDecoderCount,
698+
shared_encoder_count: struct_.sharedEncoderCount,
699+
shared_jpeg_count: struct_.sharedJpegCount,
700+
shared_ofa_count: struct_.sharedOfaCount,
701+
gpu_instance_slice_count: struct_.gpuInstanceSliceCount,
702+
compute_instance_slice_count: struct_.computeInstanceSliceCount,
703+
memory_size_mb: struct_.memorySizeMB,
704+
}
705+
}
706+
}
707+
708+
/// Fan speed info
709+
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
710+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
711+
pub struct FanSpeedInfo {
712+
/// The API version number
713+
pub version: u32,
714+
/// The fan index
715+
pub fan: u32,
716+
/// OUT: the fan speed in RPM.
717+
pub speed: u32,
718+
}
719+
720+
impl From<nvmlFanSpeedInfo_t> for FanSpeedInfo {
721+
fn from(struct_: nvmlFanSpeedInfo_t) -> Self {
722+
Self {
723+
version: struct_.version,
724+
fan: struct_.fan,
725+
speed: struct_.speed,
726+
}
727+
}
728+
}
729+
659730
#[cfg(test)]
660731
#[allow(unused_variables, unused_imports)]
661732
mod tests {

nvml-wrapper/src/structs/device.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,40 @@ use crate::enum_wrappers::device::OperationMode;
44
#[cfg(feature = "serde")]
55
use serde_derive::{Deserialize, Serialize};
66

7+
/// Returned from `Device.confidential_compute_gpu_attestation_report_bytes()`
8+
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
9+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10+
pub struct ConfidentialComputeGpuAttestationReport {
11+
/// The size of the attestation report.
12+
pub attestation_report_size: u32,
13+
/// The attestation report, of size
14+
/// `ffi::bindings::NVML_CC_GPU_ATTESTATION_REPORT_SIZE` == 8192 bytes.
15+
pub attestation_report: Vec<u8>,
16+
/// Whether the CEC attestation report is present.
17+
pub is_cec_attestation_report_present: bool,
18+
/// The size of the CEC attestation report.
19+
pub cec_attestation_report_size: u32,
20+
/// The CEC attestation report, of size
21+
/// `ffi::bindings::NVML_CC_GPU_CEC_ATTESTATION_REPORT_SIZE` == 4096 bytes.
22+
pub cec_attestation_report: Vec<u8>,
23+
}
24+
25+
/// Returned from `Device.confidential_compute_gpu_certificate()`
26+
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
27+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
28+
pub struct ConfidentialComputeGpuCertificate {
29+
/// The size of the certificate chain.
30+
pub cert_chain_size: u32,
31+
/// The size of the attestation certificate chain.
32+
pub attestation_cert_chain_size: u32,
33+
/// The certificate chain, of size
34+
/// `ffi::bindings::NVML_GPU_CERT_CHAIN_SIZE` == 4096 bytes.
35+
pub cert_chain: Vec<u8>,
36+
/// The attestation certificate chain, of size
37+
/// `ffi::bindings::NVML_GPU_ATTESTATION_CERT_CHAIN_SIZE` == 5120 bytes.
38+
pub attestation_cert_chain: Vec<u8>,
39+
}
40+
741
/// Returned from `Device.auto_boosted_clocks_enabled()`
842
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
943
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

nvml-wrapper/src/test_utils.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl ShouldPrint for BusType {}
104104
impl ShouldPrint for PowerSource {}
105105
impl ShouldPrint for DeviceArchitecture {}
106106
impl ShouldPrint for PcieLinkMaxSpeed {}
107+
impl ShouldPrint for DeviceAttributes {}
107108

108109
#[cfg(target_os = "windows")]
109110
impl ShouldPrint for DriverModelState {}
@@ -126,9 +127,9 @@ where
126127
T: Fn() -> Result<R, NvmlError>,
127128
R: ShouldPrint,
128129
{
129-
single(|| test());
130+
single(&test);
130131

131-
multi(reps, || test());
132+
multi(reps, test);
132133
}
133134

134135
pub fn test_with_device<T, R>(reps: usize, nvml: &Nvml, test: T)

0 commit comments

Comments
 (0)