### Get Active GPU and Basic Info Source: https://docs.rs/gfxinfo/0.1.2/gfxinfo/fn.active_gpu.html This example demonstrates how to get the active GPU and print its vendor, model, family, and device ID. It expects a GPU to be available and will panic if none is found. ```rust pub fn main() { let gpu = gfxinfo::active_gpu().expect("No GPU found"); println!("Vendor: {}", gpu.vendor()); println!("Model: {}", gpu.model()); println!("Family: {}", gpu.family()); println!("Device ID: 0x{:X}", gpu.device_id()); } ``` -------------------------------- ### Get Active GPU and VRAM/Load/Temperature Info Source: https://docs.rs/gfxinfo/0.1.2/gfxinfo/fn.active_gpu.html This example shows how to obtain the active GPU and display its VRAM usage, load percentage, and temperature. It assumes the existence of a `byte_to_mb` function for VRAM conversion and that temperature is in milliseconds. ```rust pub fn main() { let gpu = gfxinfo::active_gpu().expect("No GPU found"); let info = gpu.info(); println!( "VRAM usage: {} / {}", byte_to_mb(info.used_vram()), byte_to_mb(info.total_vram()) ); println!("Load: {}%", info.load_pct()); println!("Temperature: {} C", info.temperature() / 1000); } ``` -------------------------------- ### Get GPU Family Source: https://docs.rs/gfxinfo/0.1.2/gfxinfo/trait.Gpu.html Retrieves the family or architecture of the GPU, for example, 'Vega' or 'Navi'. ```rust fn family(&self) -> &str; ``` -------------------------------- ### Get GPU Model Source: https://docs.rs/gfxinfo/0.1.2/gfxinfo/trait.Gpu.html Retrieves the specific model name of the GPU. ```rust fn model(&self) -> &str; ``` -------------------------------- ### Get GPU Vendor Source: https://docs.rs/gfxinfo/0.1.2/gfxinfo/trait.Gpu.html Retrieves the vendor name of the GPU, such as 'AMD' or 'Nvidia'. ```rust fn vendor(&self) -> &str; ``` -------------------------------- ### Get GPU Info Source: https://docs.rs/gfxinfo/0.1.2/gfxinfo/trait.Gpu.html Returns a boxed trait object containing detailed GPU information. The specific type implementing GpuInfo is determined by the concrete implementation. ```rust fn info(&self) -> Box; ``` -------------------------------- ### Get Active GPU Information Source: https://docs.rs/gfxinfo/0.1.2/gfxinfo/index.html Retrieves information about the active GPU, including vendor, model, family, and device ID. Requires the `gpu_info` feature to access VRAM and load details. If numbers return 0, they are likely unsupported or unavailable. ```rust use gfxinfo::active_gpu; let gpu = active_gpu(); println!("GPU vendor: {}", gpu.vendor()); println!("GPU model: {}", gpu.model()); println!("GPU family: {}", gpu.family()); println!("GPU device ID: {}", gpu.device_id()); // And with `gpu_info` feature enabled let info = gpu.info(); println!("Total VRAM: {} bytes", info.total_vram()); println!("Used VRAM: {} bytes", info.used_vram()); println!("Load: {}%", info.load_pct()); println!("Temperature: {} C", info.temperature() / 1000); ``` -------------------------------- ### active_gpu Source: https://docs.rs/gfxinfo Attempts to get the currently active GPU, using vendor-specific methods. This function is the primary entry point for querying GPU information. ```APIDOC ## active_gpu ### Description Attempts to get the currently active GPU, using vendor-specific methods. ### Function Signature `pub fn active_gpu() -> Gpu` ### Returns A `Gpu` struct containing information about the active GPU. ### Example ```rust use gfxinfo::active_gpu; let gpu = active_gpu(); println!("GPU vendor: {}", gpu.vendor()); println!("GPU model: {}", gpu.model()); println!("GPU family: {}", gpu.family()); println!("GPU device ID: {}", gpu.device_id()); // If the 'gpu_info' feature is enabled: let info = gpu.info(); println!("Total VRAM: {} bytes", info.total_vram()); println!("Used VRAM: {} bytes", info.used_vram()); println!("Load: {}%", info.load_pct()); println!("Temperature: {} C", info.temperature() / 1000); ``` ``` -------------------------------- ### Get GPU Device ID Source: https://docs.rs/gfxinfo/0.1.2/gfxinfo/trait.Gpu.html Retrieves the unique device ID of the GPU as a 32-bit unsigned integer. ```rust fn device_id(&self) -> &u32; ``` -------------------------------- ### active_gpu Source: https://docs.rs/gfxinfo/0.1.2/gfxinfo/index.html Attempts to get the currently active GPU, using vendor-specific methods. This function returns a GPU object that can be used to query various GPU properties. ```APIDOC ## active_gpu ### Description Attempts to get the currently active GPU, using vendor-specific methods. ### Function Signature `pub fn active_gpu() -> Gpu` ### Returns A `Gpu` object representing the active GPU. This object provides methods to query GPU vendor, model, family, and device ID. If the `gpu_info` feature is enabled, it also provides access to VRAM information and GPU load/temperature. ### Example ```rust use gfxinfo::active_gpu; let gpu = active_gpu(); println!("GPU vendor: {}", gpu.vendor()); println!("GPU model: {}", gpu.model()); println!("GPU family: {}", gpu.family()); println!("GPU device ID: {}", gpu.device_id()); // With `gpu_info` feature enabled: let info = gpu.info(); println!("Total VRAM: {} bytes", info.total_vram()); println!("Used VRAM: {} bytes", info.used_vram()); println!("Load: {}%", info.load_pct()); println!("Temperature: {} C", info.temperature() / 1000); ``` ``` -------------------------------- ### active_gpu Function Source: https://docs.rs/gfxinfo/0.1.2/gfxinfo/fn.active_gpu.html Attempts to get the currently active GPU, using vendor-specific methods. This function returns a boxed trait object representing the GPU, or an error if no GPU is found. ```APIDOC ## active_gpu ### Description Attempts to get the currently active GPU, using vendor-specific methods. ### Signature ```rust pub fn active_gpu() -> Result, Box> ``` ### Returns - `Ok(Box)`: A boxed trait object representing the active GPU if found. - `Err(Box)`: An error if no GPU is found or an issue occurs. ### Example ```rust let gpu = gfxinfo::active_gpu().expect("No GPU found"); println!("Vendor: {}", gpu.vendor()); println!("Model: {}", gpu.model()); println!("Family: {}", gpu.family()); println!("Device ID: 0x{:X}", gpu.device_id()); ``` ### Example with VRAM and Load ```rust let gpu = gfxinfo::active_gpu().expect("No GPU found"); let info = gpu.info(); println!("VRAM usage: {} / {}", byte_to_mb(info.used_vram()), byte_to_mb(info.total_vram())); println!("Load: {}%", info.load_pct()); println!("Temperature: {} C", info.temperature() / 1000); ``` ``` -------------------------------- ### GpuInfo Trait Methods Source: https://docs.rs/gfxinfo/0.1.2/gfxinfo/trait.GpuInfo.html This snippet details the methods available on the GpuInfo trait for querying GPU information. If any numbers return 0, they are likely unsupported or otherwise not available. ```APIDOC ## Trait GpuInfo Trait for providing GPU information. If any numbers return 0, they are likely unsupported or otherwise not available. ### Required Methods #### fn total_vram(&self) -> u64 Get the total amount of VRAM in bytes. #### fn used_vram(&self) -> u64 Get the amount of used VRAM in bytes. #### fn load_pct(&self) -> u32 Get the load percentage. #### fn temperature(&self) -> u32 Get the GPU temperature in degrees celsius. ``` -------------------------------- ### Gpu Trait Methods Source: https://docs.rs/gfxinfo/0.1.2/gfxinfo/trait.Gpu.html This section details the methods available on the Gpu trait for querying GPU properties. ```APIDOC ## Trait Gpu ### Summary ```rust pub trait Gpu: Debug { // Required methods fn vendor(&self) -> &str; fn model(&self) -> &str; fn family(&self) -> &str; fn device_id(&self) -> &u32; fn info(&self) -> Box; } ``` ## Required Methods ### fn vendor(&self) -> &str Get the GPU vendor (ie. AMD, Nvidia). ### fn model(&self) -> &str ### fn family(&self) -> &str Get the GPU family (ie. Vega, Navi). ### fn device_id(&self) -> &u32 Get the GPU device ID. ### fn info(&self) -> Box ``` -------------------------------- ### GpuInfo Trait Definition Source: https://docs.rs/gfxinfo/0.1.2/gfxinfo/trait.GpuInfo.html Defines the GpuInfo trait with methods for retrieving GPU information. If any numbers return 0, they are likely unsupported or otherwise not available. ```rust pub trait GpuInfo { // Required methods fn total_vram(&self) -> u64; fn used_vram(&self) -> u64; fn load_pct(&self) -> u32; fn temperature(&self) -> u32; } ``` -------------------------------- ### Gpu Trait Definition Source: https://docs.rs/gfxinfo/0.1.2/gfxinfo/trait.Gpu.html Defines the Gpu trait with methods to retrieve GPU vendor, model, family, device ID, and general info. Implementors must provide concrete logic for these methods. ```rust pub trait Gpu: Debug { // Required methods fn vendor(&self) -> &str; fn model(&self) -> &str; fn family(&self) -> &str; fn device_id(&self) -> &u32; fn info(&self) -> Box; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.