-
Notifications
You must be signed in to change notification settings - Fork 51
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
Merged
Merged
vgpu apis #130
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| use std::{ffi::CStr, 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, | ||
|
FreeMasen marked this conversation as resolved.
|
||
| } | ||
|
|
||
| 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]| unsafe { | ||
| CStr::from_ptr(c_str.as_ptr()) | ||
| .to_str() | ||
| .map(|v| v.to_string()) | ||
| }; | ||
|
|
||
| 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, | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.