GpuDeviceInfo

Struct GpuDeviceInfo 

Source
pub struct GpuDeviceInfo {
    pub name: String,
    pub backend: String,
    pub total_vram_bytes: u64,
    pub available_vram_bytes: u64,
    pub used_vram_bytes: u64,
    pub driver_version: String,
    pub compute_capability: Option<String>,
    pub max_threads_per_block: u32,
    pub max_shared_memory_per_block: u64,
    pub device_id: i32,
    pub pci_bus_id: Option<String>,
}
Expand description

GPU device information

Provides detailed information about the GPU device including memory, capabilities, and backend-specific details.

§Examples

use hive_gpu::metal::MetalNativeContext;
use hive_gpu::traits::GpuContext;

let context = MetalNativeContext::new().expect("Failed to create Metal context");
let info = context.device_info().expect("Failed to get device info");

println!("Device: {}", info.name);
println!("Backend: {}", info.backend);
println!("VRAM: {} MB", info.total_vram_bytes / 1024 / 1024);
println!("Usage: {:.1}%", info.vram_usage_percent());

Fields§

§name: String

Device name (e.g., “Apple M2 Pro”, “NVIDIA RTX 4090”)

§backend: String

Backend type (e.g., “Metal”, “CUDA”, “ROCm”)

§total_vram_bytes: u64

Total VRAM in bytes

§available_vram_bytes: u64

Currently available VRAM in bytes

§used_vram_bytes: u64

Currently used VRAM in bytes (calculated as total - available)

§driver_version: String

Driver version string (e.g., “macOS 14.1”, “CUDA 12.0”, “ROCm 5.4”)

§compute_capability: Option<String>

Compute capability or architecture version

  • Metal: None
  • CUDA: e.g., “8.9” for sm_89
  • ROCm: e.g., “gfx1030”
§max_threads_per_block: u32

Maximum threads per block/workgroup

§max_shared_memory_per_block: u64

Maximum shared memory per block (in bytes)

§device_id: i32

Device ID (0-indexed)

§pci_bus_id: Option<String>

PCI bus ID (e.g., “0000:01:00.0”) None for Metal (Apple Silicon doesn’t expose PCI)

Implementations§

Source§

impl GpuDeviceInfo

Source

pub fn vram_usage_percent(&self) -> f64

Calculate VRAM usage percentage (0.0 to 100.0)

§Examples
let usage = info.vram_usage_percent();
assert!(usage >= 0.0 && usage <= 100.0);
Source

pub fn has_available_vram(&self, required_bytes: u64) -> bool

Check if there is sufficient available VRAM

§Arguments
  • required_bytes - Minimum required VRAM in bytes
§Examples
// Check if we have at least 1GB available
if info.has_available_vram(1 * 1024 * 1024 * 1024) {
    println!("Sufficient VRAM available");
}
Source

pub fn available_vram_mb(&self) -> u64

Get VRAM available in megabytes (convenience method)

§Examples
println!("Available: {} MB", info.available_vram_mb());
Source

pub fn total_vram_mb(&self) -> u64

Get total VRAM in megabytes (convenience method)

§Examples
println!("Total: {} MB", info.total_vram_mb());

Trait Implementations§

Source§

impl Clone for GpuDeviceInfo

Source§

fn clone(&self) -> GpuDeviceInfo

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GpuDeviceInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for GpuDeviceInfo

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for GpuDeviceInfo

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,