@@ -4090,6 +4090,58 @@ impl<'nvml> Device<'nvml> {
4090
4090
unsafe { nvml_try ( sym ( self . device ) ) }
4091
4091
}
4092
4092
4093
+ /**
4094
+ Gets a vector of bitmasks with the ideal CPU affinity for this `Device` within the specified `scope`,
4095
+ the latter being NUMA node or processor socket (`NVML_AFFINITY_SCOPE_NODE` and `NVML_AFFINITY_SCOPE_SOCKET`).
4096
+
4097
+ Beyond this, the outcome and meaning are similar to `cpu_affinity`
4098
+
4099
+ # Errors
4100
+
4101
+ * `Uninitialized`, if the library has not been successfully initialized
4102
+ * `InvalidArg`, if this `Device` is invalid
4103
+ * `InsufficientSize`, if the passed-in `size` is 0 (must be > 0)
4104
+ * `NotSupported`, if this `Device` does not support this feature
4105
+ * `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible
4106
+ * `Unknown`, on any unexpected error
4107
+
4108
+ # Device Support
4109
+
4110
+ Supports Kepler or newer fully supported devices.
4111
+
4112
+ # Platform Support
4113
+
4114
+ Only supports Linux.
4115
+
4116
+ */
4117
+ #[ cfg( target_os = "linux" ) ]
4118
+ #[ doc( alias = "nvmlDeviceGetCpuAffinityWithinScope" ) ]
4119
+ pub fn cpu_affinity_within_scope (
4120
+ & self ,
4121
+ size : usize ,
4122
+ scope : nvmlAffinityScope_t ,
4123
+ ) -> Result < Vec < c_ulong > , NvmlError > {
4124
+ let sym = nvml_sym ( self . nvml . lib . nvmlDeviceGetCpuAffinityWithinScope . as_ref ( ) ) ?;
4125
+
4126
+ unsafe {
4127
+ if size == 0 {
4128
+ // Return an error containing the minimum size that can be passed.
4129
+ return Err ( NvmlError :: InsufficientSize ( Some ( 1 ) ) ) ;
4130
+ }
4131
+
4132
+ let mut affinities: Vec < c_ulong > = vec ! [ mem:: zeroed( ) ; size] ;
4133
+
4134
+ nvml_try ( sym (
4135
+ self . device ,
4136
+ size as c_uint ,
4137
+ affinities. as_mut_ptr ( ) ,
4138
+ scope,
4139
+ ) ) ?;
4140
+
4141
+ Ok ( affinities)
4142
+ }
4143
+ }
4144
+
4093
4145
/**
4094
4146
Try to set the default state of auto boosted clocks on this `Device`.
4095
4147
@@ -5550,6 +5602,13 @@ mod test {
5550
5602
test_with_device ( 3 , & nvml, |device| device. cpu_affinity ( 64 ) )
5551
5603
}
5552
5604
5605
+ #[ cfg( target_os = "linux" ) ]
5606
+ #[ test]
5607
+ fn cpu_affinity_within_scope ( ) {
5608
+ let nvml = nvml ( ) ;
5609
+ test_with_device ( 3 , & nvml, |device| device. cpu_affinity_within_scope ( 64 , 0 ) )
5610
+ }
5611
+
5553
5612
#[ test]
5554
5613
fn current_pcie_link_gen ( ) {
5555
5614
let nvml = nvml ( ) ;
0 commit comments