Skip to content

Commit 7e0752f

Browse files
authored
adding device::vgpu_scheduler_state/set_vgpu_scheduler_state (#111)
1 parent cffed7c commit 7e0752f

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

nvml-wrapper/src/device.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6403,7 +6403,7 @@ impl<'nvml> Device<'nvml> {
64036403
}
64046404
}
64056405

6406-
/// Obtain the n log entries (max 200) of the vGPU scheduler, to be called several time if need
6406+
/// Obtain the n log entries (max 200) of the vGPU scheduler, to be called several times if need
64076407
/// be.
64086408
pub fn vgpu_scheduler_log(&self) -> Result<VgpuSchedulerLog, NvmlError> {
64096409
let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetVgpuSchedulerLog.as_ref())?;
@@ -6417,6 +6417,29 @@ impl<'nvml> Device<'nvml> {
64176417
}
64186418
}
64196419

6420+
/// Obtain the vGPU scheduler state of the device
6421+
pub fn vgpu_scheduler_state(&self) -> Result<VgpuSchedulerGetState, NvmlError> {
6422+
let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetVgpuSchedulerState.as_ref())?;
6423+
6424+
unsafe {
6425+
let mut scheduler_state: nvmlVgpuSchedulerGetState_t = mem::zeroed();
6426+
6427+
nvml_try(sym(self.device, &mut scheduler_state))?;
6428+
6429+
Ok(VgpuSchedulerGetState::from(scheduler_state))
6430+
}
6431+
}
6432+
6433+
/// Set the vGPU scheduler state of the device
6434+
pub fn set_vgpu_scheduler_state(
6435+
&self,
6436+
scheduler_state: VgpuSchedulerSetState,
6437+
) -> Result<(), NvmlError> {
6438+
let sym = nvml_sym(self.nvml.lib.nvmlDeviceSetVgpuSchedulerState.as_ref())?;
6439+
6440+
unsafe { nvml_try(sym(self.device, &mut scheduler_state.as_c())) }
6441+
}
6442+
64206443
/// Check if the GPU is on vGPU host mode
64216444
pub fn vgpu_host_mode(&self) -> Result<HostVgpuMode, NvmlError> {
64226445
let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetHostVgpuMode.as_ref())?;

nvml-wrapper/src/struct_wrappers/device.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,70 @@ impl From<nvmlVgpuSchedulerLog_t> for VgpuSchedulerLog {
934934
}
935935
}
936936

937+
/// Vgpu scheduler state
938+
#[derive(Debug, Clone, Eq, PartialEq)]
939+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
940+
pub struct VgpuSchedulerGetState {
941+
/// Adaptative Round Robin scheduler mode
942+
pub arr_mode: u32,
943+
/// Scheduler policy
944+
pub scheduler_policy: u32,
945+
}
946+
947+
impl From<nvmlVgpuSchedulerGetState_t> for VgpuSchedulerGetState {
948+
fn from(value: nvmlVgpuSchedulerGetState_t) -> Self {
949+
Self {
950+
arr_mode: value.arrMode,
951+
scheduler_policy: value.schedulerPolicy,
952+
}
953+
}
954+
}
955+
956+
#[derive(Debug, Clone, Eq, PartialEq)]
957+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
958+
pub struct VgpuSchedulerSetParams {
959+
/// Average factor in compensating the timeslice for Adaptive Round Robin mode
960+
pub avg_factor: Option<u32>,
961+
/// Frequency for Adaptative Mode (when avg_factor is set)/timeslice in ns for each software run list as configured, or the default value otherwise
962+
pub frequency_or_timeslice: u32,
963+
}
964+
965+
impl VgpuSchedulerSetParams {
966+
pub fn as_c(&self) -> nvmlVgpuSchedulerSetParams_t {
967+
match self.avg_factor {
968+
Some(a) => nvmlVgpuSchedulerSetParams_t {
969+
vgpuSchedDataWithARR: nvmlVgpuSchedulerSetParams_t__bindgen_ty_1 {
970+
avgFactor: a,
971+
frequency: self.frequency_or_timeslice,
972+
},
973+
},
974+
_ => nvmlVgpuSchedulerSetParams_t {
975+
vgpuSchedData: nvmlVgpuSchedulerSetParams_t__bindgen_ty_2 {
976+
timeslice: self.frequency_or_timeslice,
977+
},
978+
},
979+
}
980+
}
981+
}
982+
983+
#[derive(Debug, Clone, Eq, PartialEq)]
984+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
985+
pub struct VgpuSchedulerSetState {
986+
pub scheduler_policy: u32,
987+
pub enable_arr_mode: u32,
988+
pub scheduler_params: VgpuSchedulerSetParams,
989+
}
990+
991+
impl VgpuSchedulerSetState {
992+
pub fn as_c(&self) -> nvmlVgpuSchedulerSetState_t {
993+
nvmlVgpuSchedulerSetState_t {
994+
enableARRMode: self.enable_arr_mode,
995+
schedulerPolicy: self.scheduler_policy,
996+
schedulerParams: self.scheduler_params.as_c(),
997+
}
998+
}
999+
}
1000+
9371001
#[cfg(test)]
9381002
#[allow(unused_variables, unused_imports)]
9391003
mod tests {

0 commit comments

Comments
 (0)