-
Notifications
You must be signed in to change notification settings - Fork 50
vgpu apis #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
vgpu apis #130
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| use crate::error::NvmlError; | ||
| use ffi::bindings::*; | ||
| #[cfg(feature = "serde")] | ||
| use serde_derive::{Deserialize, Serialize}; | ||
| use wrapcenum_derive::EnumWrapper; | ||
|
|
||
| #[derive(Debug, Clone, Eq, PartialEq, Hash)] | ||
| pub enum VmId { | ||
|
swlynch99 marked this conversation as resolved.
|
||
| Domain(String), | ||
| Uuid(String), | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] | ||
| #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
| #[repr(u32)] | ||
| pub enum VgpuLicenseState { | ||
|
swlynch99 marked this conversation as resolved.
|
||
| Unknown = NVML_GRID_LICENSE_STATE_UNKNOWN, | ||
| Uninitialized = NVML_GRID_LICENSE_STATE_UNINITIALIZED, | ||
| UnlicensedUnrestricted = NVML_GRID_LICENSE_STATE_UNLICENSED_UNRESTRICTED, | ||
| UnlicensedRestricted = NVML_GRID_LICENSE_STATE_UNLICENSED_RESTRICTED, | ||
| Unlicensed = NVML_GRID_LICENSE_STATE_UNLICENSED, | ||
| Licensed = NVML_GRID_LICENSE_STATE_LICENSED, | ||
| } | ||
|
|
||
| impl From<u32> for VgpuLicenseState { | ||
|
swlynch99 marked this conversation as resolved.
|
||
| fn from(value: u32) -> Self { | ||
| match value { | ||
| NVML_GRID_LICENSE_STATE_UNINITIALIZED => Self::Uninitialized, | ||
| NVML_GRID_LICENSE_STATE_UNLICENSED_UNRESTRICTED => Self::UnlicensedUnrestricted, | ||
| NVML_GRID_LICENSE_STATE_UNLICENSED_RESTRICTED => Self::UnlicensedRestricted, | ||
| NVML_GRID_LICENSE_STATE_UNLICENSED => Self::Unlicensed, | ||
| NVML_GRID_LICENSE_STATE_LICENSED => Self::Licensed, | ||
| _ => Self::Unknown, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| //nvmlVgpuGuestInfoState_enum | ||
| #[derive(EnumWrapper, Debug, Clone, Copy, Eq, PartialEq, Hash)] | ||
| #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
| #[wrap(c_enum = "nvmlVgpuGuestInfoState_enum")] | ||
| pub enum VgpuGuestInfoState { | ||
| #[wrap(c_variant = "NVML_VGPU_INSTANCE_GUEST_INFO_STATE_UNINITIALIZED")] | ||
| Uninitialized, | ||
| #[wrap(c_variant = "NVML_VGPU_INSTANCE_GUEST_INFO_STATE_INITIALIZED")] | ||
| Initialized, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| use std::os::raw::c_char; | ||
|
|
||
| use ffi::bindings::*; | ||
|
|
||
| use crate::{ | ||
| enum_wrappers::vgpu::{VgpuGuestInfoState, VgpuLicenseState}, | ||
| error::NvmlError, | ||
| }; | ||
|
|
||
| #[derive(Debug, Copy, Clone)] | ||
| pub struct VgpuLicenseInfo { | ||
| pub is_licensed: bool, | ||
| pub expiry: VgpuLicenseExpiry, | ||
| pub state: VgpuLicenseState, | ||
| } | ||
|
|
||
| impl From<nvmlVgpuLicenseInfo_t> for VgpuLicenseInfo { | ||
| fn from(value: nvmlVgpuLicenseInfo_t) -> Self { | ||
| Self { | ||
| is_licensed: value.isLicensed != 0, | ||
| expiry: VgpuLicenseExpiry::from(value.licenseExpiry), | ||
| state: VgpuLicenseState::from(value.currentState), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Copy, Clone)] | ||
| pub struct VgpuLicenseExpiry { | ||
| pub year: u16, | ||
| pub month: u8, | ||
| pub day: u8, | ||
| pub hour: u8, | ||
| pub min: u8, | ||
| pub sec: u8, | ||
| pub status: u8, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find any documentation about why are expected values here and left the type effectively unchanged. Let me know if there is something I missed and I can add another enum to capture the status. |
||
| } | ||
|
|
||
| impl From<nvmlVgpuLicenseExpiry_t> for VgpuLicenseExpiry { | ||
| fn from(value: nvmlVgpuLicenseExpiry_t) -> Self { | ||
| Self { | ||
| year: u16::try_from(value.year).unwrap_or(u16::MAX), | ||
| month: u8::try_from(value.month).unwrap_or(u8::MAX), | ||
| day: u8::try_from(value.day).unwrap_or(u8::MAX), | ||
| hour: u8::try_from(value.hour).unwrap_or(u8::MAX), | ||
| min: u8::try_from(value.min).unwrap_or(u8::MAX), | ||
| sec: u8::try_from(value.sec).unwrap_or(u8::MAX), | ||
|
swlynch99 marked this conversation as resolved.
|
||
| status: value.status, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct VgpuMetadata { | ||
| pub version: u32, | ||
| pub revision: u32, | ||
| pub guest_info_state: VgpuGuestInfoState, | ||
| pub guest_driver_version: String, | ||
| pub host_driver_version: String, | ||
| pub vgpu_virtualization_caps: u32, | ||
| pub guest_vgpu_version: u32, | ||
| } | ||
|
|
||
| impl TryFrom<nvmlVgpuMetadata_t> for VgpuMetadata { | ||
| type Error = NvmlError; | ||
| fn try_from(value: nvmlVgpuMetadata_t) -> Result<Self, Self::Error> { | ||
| let convert_c_str = |c_str: &[c_char]| { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is a bit odd, I wanted to avoid using any |
||
| let mut ret = String::with_capacity(c_str.len()); | ||
| for &byte in c_str { | ||
| if byte == 0 { | ||
| break; | ||
| } | ||
| let us = u8::try_from(byte).map_err(|_| NvmlError::Unknown)?; | ||
| ret.push(us as char); | ||
| } | ||
|
|
||
| Ok::<String, NvmlError>(ret) | ||
| }; | ||
|
|
||
| Ok(Self { | ||
| version: value.version, | ||
| revision: value.revision, | ||
| guest_driver_version: convert_c_str(&value.guestDriverVersion)?, | ||
| host_driver_version: convert_c_str(&value.hostDriverVersion)?, | ||
| vgpu_virtualization_caps: value.vgpuVirtualizationCaps, | ||
| guest_vgpu_version: value.guestVgpuVersion, | ||
| guest_info_state: value.guestInfoState.try_into()?, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Copy, Clone)] | ||
| pub struct VgpuPlacementId { | ||
| pub version: u32, | ||
| pub id: u32, | ||
| } | ||
|
|
||
| impl From<nvmlVgpuPlacementId_t> for VgpuPlacementId { | ||
| fn from(value: nvmlVgpuPlacementId_t) -> Self { | ||
| Self { | ||
| version: value.version, | ||
| id: value.placementId, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Copy, Clone)] | ||
| pub struct VgpuRuntimeState { | ||
| pub version: u32, | ||
| pub size: u64, | ||
| } | ||
|
|
||
| impl From<nvmlVgpuRuntimeState_t> for VgpuRuntimeState { | ||
| fn from(value: nvmlVgpuRuntimeState_t) -> Self { | ||
| Self { | ||
| version: value.version, | ||
| size: value.size, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Copy)] | ||
| pub struct Bar1Info { | ||
| pub version: u32, | ||
| pub size: u64, | ||
| } | ||
|
|
||
| impl From<nvmlVgpuTypeBar1Info_v1_t> for Bar1Info { | ||
| fn from(value: nvmlVgpuTypeBar1Info_v1_t) -> Self { | ||
| Self { | ||
| version: value.version, | ||
| size: value.bar1Size, | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.