### Initialize NVML and Get Device Information Source: https://github.com/rust-nvml/nvml-wrapper/blob/main/README.md Initializes the NVML library and retrieves basic information about the first GPU in the system, such as brand, fan speed, power limit, encoder utilization, and memory usage. Ensure NVML is installed on your system. ```rust use nvml_wrapper::Nvml; let nvml = Nvml::init()?; // Get the first `Device` (GPU) in the system let device = nvml.device_by_index(0)?; let brand = device.brand()?; let fan_speed = device.fan_speed(0)?; let power_limit = device.enforced_power_limit()?; let encoder_util = device.encoder_utilization()?; let memory_info = device.memory_info()?; ``` -------------------------------- ### Acquire Device Handles Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Obtain `Device` handles using different lookup methods: by index (unstable), by UUID (stable, preferred), or by PCI bus ID (stable). These handles are tied to the `Nvml` lifetime and allow for per-GPU operations. The example also demonstrates checking if devices are on the same physical board. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; // By index (not stable across reboots) let dev0 = nvml.device_by_index(0)?; // By UUID (stable, preferred for long-running services) let uuid = dev0.uuid()?; let dev_by_uuid = nvml.device_by_uuid(&uuid)?; // By PCI bus ID (stable) let pci = dev0.pci_info()?; let dev_by_pci = nvml.device_by_pci_bus_id(&pci.bus_id)?; println!("All three handles refer to: {}", dev_by_uuid.name()?); // Check if two devices share the same physical board let same_board = nvml.are_devices_on_same_board(&dev0, &dev_by_pci)?; println!("Same board: {same_board}"); Ok(()) } ``` -------------------------------- ### Inspect NvLink Interconnect Capabilities and Counters Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Access NvLink state, version, capabilities, and utilization counters on Pascal+ GPUs. Use `device.link_wrapper_for` to get a link object and query its properties. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::enum_wrappers::nv_link::{Capability, ErrorCounter}; use nvml_wrapper::enums::nv_link::Counter; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; let device = nvml.device_by_index(0)?; // Inspect link 0 let link = device.link_wrapper_for(0); println!("NvLink 0 active: {}", link.is_active()?); println!("NvLink 0 version: {}", link.version()?); println!( "P2P supported: {}", link.has_capability(Capability::P2pSupported)? ); // Read error counters let replay_errors = link.error_counter(ErrorCounter::Replay)?; let recovery_errors = link.error_counter(ErrorCounter::Recovery)?; println!("Replay errors: {replay_errors}, Recovery errors: {recovery_errors}"); // Reset utilization counters for link 0, counter set A link.reset_utilization_counter(Counter::A)?; Ok(()) } ``` -------------------------------- ### Query GPU Utilization, P-State, and Throttle Reasons Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Get GPU core and memory utilization percentages, the current performance state (P-state), and active throttle reasons. Also retrieves encoder and decoder utilization. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; let device = nvml.device_by_index(0)?; // GPU core + memory utilization (%) let util = device.utilization_rates()?; println!("GPU util: {}%, Memory util: {}%", util.gpu, util.memory); // P-state (P0 = maximum performance, P15 = minimum) let pstate = device.performance_state()?; println!("Performance state: {:?}", pstate); // Clock throttle reasons (bitflags) let reasons = device.current_throttle_reasons()?; println!("Throttle reasons: {:?}", reasons); // Encoder and decoder utilization let enc = device.encoder_utilization()?; let dec = device.decoder_utilization()?; println!("Encoder: {}% (sample period: {} µs)", enc.utilization, enc.sampling_period); println!("Decoder: {}% (sample period: {} µs)", dec.utilization, dec.sampling_period); Ok(()) } ``` -------------------------------- ### Get PCIe Information for a Device Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Retrieves and prints various PCI bus attributes and current PCIe link status for a given GPU device. Includes information like bus ID, domain, bus, device, link generation and width, link speed, and throughput counters. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::enum_wrappers::device::PcieUtilCounter; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; let device = nvml.device_by_index(0)?; let pci = device.pci_info()?; println!("PCI bus ID: {}", pci.bus_id); println!("Domain: {:#x}, Bus: {:#x}, Device: {:#x}", pci.domain, pci.bus, pci.device); let gen = device.current_pcie_link_gen()?; let width = device.current_pcie_link_width()?; let max_gen = device.max_pcie_link_gen()?; let max_width = device.max_pcie_link_width()?; println!("PCIe link: gen {gen} x{width} (max: gen {max_gen} x{max_width})"); let link_speed = device.pcie_link_speed()?; println!("Link speed: {} MB/s per lane", u32::from(link_speed)); let tx = device.pcie_throughput(PcieUtilCounter::Send)?; let rx = device.pcie_throughput(PcieUtilCounter::Receive)?; println!("PCIe TX: {tx} KB/s, RX: {rx} KB/s"); println!("PCIe replay counter: {}", device.pcie_replay_counter()?); Ok(()) } ``` -------------------------------- ### Get GPU Thermal and Fan Information in Rust Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Reads GPU die temperature and fan speeds (percentage and RPM). Also retrieves the fan speed range and current fan control policy. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::enum_wrappers::device::TemperatureSensor; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; let device = nvml.device_by_index(0)?; // GPU die temperature let temp = device.temperature(TemperatureSensor::Gpu)?; println!("GPU temperature: {temp} °C"); // Fan speeds (percentage of max) let num_fans = device.num_fans()?; println!("Number of fans: {num_fans}"); for i in 0..num_fans { let pct = device.fan_speed(i)?; let rpm = device.fan_speed_rpm(i)?; println!(" Fan {i}: {pct}% ({rpm} RPM)"); } // Min/max allowable fan speed let (min, max) = device.min_max_fan_speed()?; println!("Fan speed range: {min}%–{max}%"); // Current fan control policy let policy = device.fan_control_policy(0)?; println!("Fan 0 control policy: {:?}", policy); Ok(()) } ``` -------------------------------- ### Initialize NVML with Flags or Custom Path Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Initialize NVML using `init_with_flags` for specific behaviors like ignoring missing GPUs or deferred attachment, or use `NvmlBuilder` to specify a custom library path. These methods offer more control over the initialization process. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::bitmasks::InitFlags; use nvml_wrapper::error::NvmlError; use std::ffi::OsStr; fn main() -> Result<(), NvmlError> { // Initialize without attaching GPUs and without failing if no GPUs present let nvml = Nvml::init_with_flags(InitFlags::NO_GPUS | InitFlags::NO_ATTACH)?; println!("Initialized (no GPUs attached)"); drop(nvml); // Builder pattern: custom library path let nvml = Nvml::builder() .lib_path(OsStr::new("/opt/nvidia/lib64/libnvidia-ml.so.1")) .flags(InitFlags::NO_GPUS) .init()?; println!("Initialized from custom path"); Ok(()) } ``` -------------------------------- ### GPU Memory Usage Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Get detailed GPU memory usage information, including total, used, and free memory in bytes, as well as BAR1 memory information. ```APIDOC ## `Device::memory_info` — GPU memory usage ### Description Returns `MemoryInfo` with `free`, `used`, and `total` bytes (v2 API, consistent with `nvidia-smi`). ### Method `memory_info()` returns a `MemoryInfo` struct containing `free`, `used`, and `total` memory in bytes. `bar1_memory_info()` provides BAR1 memory details. ### Example ```rust use nvml_wrapper::Nvml; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; let device = nvml.device_by_index(0)?; let mem = device.memory_info()?; let gb = |b: u64| b as f64 / 1_073_741_824.0; println!("Total VRAM: {:.2} GB", gb(mem.total)); println!("Used VRAM: {:.2} GB", gb(mem.used)); println!("Free VRAM: {:.2} GB", gb(mem.free)); let bar1 = device.bar1_memory_info()?; println!("BAR1 used: {:.2} MB", bar1.used as f64 / 1_048_576.0); Ok(()) } ``` ``` -------------------------------- ### Get Device Identity Information in Rust Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Retrieves basic identifying information for a GPU, such as its name, brand, architecture, UUID, and serial number. Requires initializing the NVML library. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; let device = nvml.device_by_index(0)?; println!("Name: {}", device.name()?); println!("Brand: {:?}", device.brand()?); println!("Architecture: {:?}", device.architecture()?); println!("UUID: {}", device.uuid()?); println!("NVML Index: {}", device.index()?); println!("Board ID: {:#x}", device.board_id()?); println!("Multi-GPU board: {}", device.is_multi_gpu_board()?); // CUDA compute capability (major.minor) let cc = device.cuda_compute_capability()?; println!("Compute Capability: {}.{}", cc.major, cc.minor); // Number of CUDA cores println!("CUDA cores: {}", device.num_cores()?); Ok(()) } ``` -------------------------------- ### Query and Control Multi-Instance GPU (MIG) Mode Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Shows how to query and control Multi-Instance GPU (MIG) mode on supported GPUs. This allows splitting a single GPU into isolated compute instances. Includes checking if a handle is a MIG device and iterating over active MIG devices. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; let device = nvml.device_by_index(0)?; // Query MIG mode (current and pending after reboot) let mig = device.mig_mode()?; println!("MIG current: {}, pending: {}", mig.current, mig.pending); // Is this handle itself a MIG device? println!("Is MIG device handle: {}", device.mig_is_mig_device_handle()?); if mig.current > 0 { let count = device.mig_device_count()?; println!("{count} MIG device(s) active"); for i in 0..count { let mig_dev = device.mig_device_by_index(i)?; println!(" MIG[{i}]: {}", mig_dev.name()?); // Navigate back to parent let parent = mig_dev.mig_parent_device()?; println!(" Parent: {}", parent.name()?); } } Ok(()) } ``` -------------------------------- ### Nvml::init Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Initializes the NVML library, loads the shared library, and detects the driver's field-ID numbering scheme. This is the primary entry point for using the library and should be called once per process. ```APIDOC ## Nvml::init — Initialize the NVML library ### Description The entry point for the entire library. Loads the NVML shared library, calls `nvmlInit_v2`, and detects the driver's field-ID numbering scheme. Should be called exactly once per process lifetime; store the result in a `once_cell` or similar. ### Method `Nvml::init()` ### Parameters None ### Request Example ```rust use nvml_wrapper::Nvml; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; // ... use nvml object ... nvml.shutdown()?; Ok(()) } ``` ### Response #### Success Response Returns an `Nvml` object representing the initialized library handle. #### Response Example ```rust // Successful initialization returns an Nvml object let nvml = Nvml::init()?; ``` ### Error Handling Returns `NvmlError` if initialization fails (e.g., NVML library not found, driver issues). ``` -------------------------------- ### Get GPU Clock Speeds in Rust Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Queries current, maximum, and application-specific clock frequencies for various GPU domains (Graphics, SM, Memory). Also checks auto-boost status. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::enum_wrappers::device::{Clock, ClockId}; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; let device = nvml.device_by_index(0)?; // Current clocks println!("Graphics clock: {} MHz", device.clock_info(Clock::Graphics)?); println!("Memory clock: {} MHz", device.clock_info(Clock::Memory)?); println!("SM clock: {} MHz", device.clock_info(Clock::SM)?); // Max clocks println!("Max graphics: {} MHz", device.max_clock_info(Clock::Graphics)?); // Application-locked clocks (if set) println!("App graphics clock: {} MHz", device.applications_clock(Clock::Graphics)?); // Clock with specific ID (e.g., current P-state clock) let pstate_clock = device.clock(Clock::Graphics, ClockId::Current)?; println!("P-state graphics clock: {} MHz", pstate_clock); // Auto-boost status let boost = device.auto_boosted_clocks_enabled()?; println!("Auto-boost enabled: {}, default: {}", boost.is_enabled, boost.is_enabled_default); Ok(()) } ``` -------------------------------- ### Nvml::init_with_flags / NvmlBuilder Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Initializes NVML with specific flags or a custom library path. This allows for more controlled initialization scenarios, such as when GPUs are not present or when using a non-standard library location. ```APIDOC ## Nvml::init_with_flags / NvmlBuilder — Controlled initialization ### Description Initialize NVML with `InitFlags` bitflags or a custom library path. Useful for systems without GPUs (`NO_GPUS`), deferred GPU attachment (`NO_ATTACH`), or non-standard library locations. ### Method `Nvml::init_with_flags(flags: InitFlags)` `Nvml::builder().lib_path(path).flags(flags).init()` ### Parameters - `flags` (InitFlags): Bitflags to control initialization behavior (e.g., `NO_GPUS`, `NO_ATTACH`). - `lib_path` (OsStr): Path to the NVML shared library. ### Request Example ```rust use nvml_wrapper::Nvml; use nvml_wrapper::bitmasks::InitFlags; use std::ffi::OsStr; // Initialize without attaching GPUs and without failing if no GPUs present let nvml = Nvml::init_with_flags(InitFlags::NO_GPUS | InitFlags::NO_ATTACH)?; // Builder pattern: custom library path let nvml = Nvml::builder() .lib_path(OsStr::new("/opt/nvidia/lib64/libnvidia-ml.so.1")) .flags(InitFlags::NO_GPUS) .init()?; ``` ### Response #### Success Response Returns an `Nvml` object representing the initialized library handle with the specified configurations. #### Response Example ```rust let nvml = Nvml::init_with_flags(InitFlags::NO_GPUS)?; ``` ### Error Handling Returns `NvmlError` if initialization fails with the given flags or custom path. ``` -------------------------------- ### Query and Configure GPU Power Management Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Query current power draw, power limits, and their constraints. Values are in milliwatts. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; let device = nvml.device_by_index(0)?; let usage = device.power_usage()?; println!("Current power draw: {:.1} W", usage as f64 / 1000.0); let limit = device.power_management_limit()?; println!("Power limit: {:.1} W", limit as f64 / 1000.0); let enforced = device.enforced_power_limit()?; println!("Enforced limit: {:.1} W", enforced as f64 / 1000.0); let default_limit = device.power_management_limit_default()?; println!("Default limit: {:.1} W", default_limit as f64 / 1000.0); let constraints = device.power_management_limit_constraints()?; println!( "Allowed range: {:.1}–{:.1} W", constraints.min_limit as f64 / 1000.0, constraints.max_limit as f64 / 1000.0, ); // Total energy consumed since last driver reload (mJ) let energy = device.total_energy_consumption()?; println!("Total energy: {} J", energy / 1000); Ok(()) } ``` -------------------------------- ### Collect GPU Performance Monitoring (GPM) Metrics Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Demonstrates collecting fine-grained performance metrics on Hopper+ GPUs using GPU Performance Monitoring (GPM). This involves taking two time-separated samples and computing the delta for specified metrics like SM occupancy and DRAM bandwidth utilization. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::enums::gpm::GpmMetricId; use nvml_wrapper::gpm::gpm_metrics_get; use nvml_wrapper::error::NvmlError; use std::thread; use std::time::Duration; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; let device = nvml.device_by_index(0)?; // Allocate two samples and capture them 100 ms apart let sample1 = device.gpm_sample()?; thread::sleep(Duration::from_millis(100)); let sample2 = device.gpm_sample()?; // Request SM occupancy, tensor-core utilization, and DRAM bandwidth let metric_ids = vec![ GpmMetricId::SmOccupancy, GpmMetricId::TensorCoreUtilization, GpmMetricId::DramBandwidthUtilization, ]; let results = gpm_metrics_get(&nvml, &sample1, &sample2, &metric_ids)?; for (id, result) in metric_ids.iter().zip(results.iter()) { match result { Ok(r) => println!("{id:?}: {:.2}%", r.value), Err(e) => println!("{id:?}: unsupported ({e})"), } } sample1.free()?; sample2.free()?; Ok(()) } ``` -------------------------------- ### Get GPU Memory Usage in Rust Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Retrieves GPU memory usage statistics, including total, used, and free VRAM, as well as BAR1 memory information. Uses the v2 API for consistency with nvidia-smi. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; let device = nvml.device_by_index(0)?; let mem = device.memory_info()?; let gb = |b: u64| b as f64 / 1_073_741_824.0; println!("Total VRAM: {:.2} GB", gb(mem.total)); println!("Used VRAM: {:.2} GB", gb(mem.used)); println!("Free VRAM: {:.2} GB", gb(mem.free)); // BAR1 memory (for peer-to-peer / CPU-visible mapping) let bar1 = device.bar1_memory_info()?; println!("BAR1 used: {:.2} MB", bar1.used as f64 / 1_048_576.0); Ok(()) } ``` -------------------------------- ### Initialize NVML Library Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Standard initialization of the NVML library. This function loads the NVML shared library and should be called once per process. It retrieves driver, NVML, and CUDA versions, and counts the number of available GPUs. Explicit shutdown is shown, though `Drop` also handles it. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { // Standard initialization — looks for libnvidia-ml.so.1 / nvml.dll let nvml = Nvml::init()?; let driver = nvml.sys_driver_version()?; let nvml_ver = nvml.sys_nvml_version()?; let cuda_ver = nvml.sys_cuda_driver_version()?; println!("Driver: {driver}, NVML: {nvml_ver}"); println!( "CUDA {}.{}", nvml_wrapper::cuda_driver_version_major(cuda_ver), nvml_wrapper::cuda_driver_version_minor(cuda_ver), ); let count = nvml.device_count()?; println!("{count} GPU(s) found"); // Explicit shutdown (Drop also calls shutdown, ignoring errors) nvml.shutdown()?; Ok(()) } // Expected output (example system): // Driver: 535.104.05, NVML: 12.535.104.05 // CUDA 12.2 // 1 GPU(s) found ``` -------------------------------- ### Low-level GPU Event Subscription with EventSet (Linux) Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Directly manage an `EventSet` for fine-grained control over specific event types registered per device. Use `device.register_events` and `set.wait`. ```rust #[cfg(target_os = "linux")] fn main() -> Result<(), nvml_wrapper::error::NvmlError> { use nvml_wrapper::Nvml; use nvml_wrapper::bitmasks::event::EventTypes; use nvml_wrapper::error::NvmlError; let nvml = Nvml::init()?; let device = nvml.device_by_index(0)?; let set = nvml.create_event_set()?; // Register only ECC and clock-change events let types = EventTypes::SINGLE_BIT_ECC_ERROR | EventTypes::DOUBLE_BIT_ECC_ERROR | EventTypes::CLOCK_CHANGE; let set = device.register_events(types, set)?; // Wait up to 1000 ms for an event match set.wait(1000) { Ok(event_data) => println!("Event: {:?}", event_data.event_type), Err(NvmlError::Timeout) => println!("No event within 1 second"), Err(e) => return Err(e), } Ok(()) } ``` -------------------------------- ### Initialize Nvml and check GPU memory error counter Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Initializes NVML, retrieves a device, and checks its memory error counter. Handles specific errors like DriverNotLoaded, LibraryNotFound, NotSupported, and GpuLost. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::error::NvmlError; fn check_gpu() -> Result<(), NvmlError> { let nvml = Nvml::init().map_err(|e| match e { NvmlError::DriverNotLoaded => { eprintln!("NVIDIA driver is not loaded"); e } NvmlError::LibraryNotFound => { eprintln!("libnvidia-ml not found — no NVIDIA GPU or driver installed"); e } other => other, })?; let device = nvml.device_by_index(0)?; match device.memory_error_counter( nvml_wrapper::enum_wrappers::device::MemoryError::Uncorrected, nvml_wrapper::enum_wrappers::device::EccCounter::Aggregate, nvml_wrapper::enum_wrappers::device::MemoryLocation::Device, ) { Ok(count) => println!("DBE count: {count}"), Err(NvmlError::NotSupported) => println!("ECC not supported on this device"), Err(NvmlError::GpuLost) => eprintln!("GPU fell off the bus!"), Err(e) => return Err(e), } Ok(()) } fn main() { if let Err(e) = check_gpu() { eprintln!("Error: {e}"); std::process::exit(1); } } ``` -------------------------------- ### Manually Control Fan Speed and Restore Default Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Demonstrates how to manually set fan speeds for a device and then restore them to automatic, temperature-driven control. Warning: manual fan control bypasses thermal protection; monitor temperature independently. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::enums::device::FanControlPolicy; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; let mut device = nvml.device_by_index(0)?; let num_fans = device.num_fans()?; for i in 0..num_fans { device.set_fan_speed(i, 60)?; println!("Fan {i} set to 60%"); } for i in 0..num_fans { device.set_default_fan_speed(i)?; println!("Fan {i} restored to automatic control"); } Ok(()) } ``` -------------------------------- ### Active Processes Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt List the PID and memory usage of all processes currently using the GPU. ```APIDOC ## `Device::running_compute_processes` / `running_graphics_processes` — Active processes List the PID and memory usage of all processes currently using the GPU. ### Description This section details how to list processes that are actively using the GPU, categorized into compute and graphics processes, and retrieve their memory usage. ### Methods - `running_compute_processes()`: Retrieves a list of compute processes (e.g., CUDA) running on the device, including their PIDs and used GPU memory. - `running_graphics_processes()`: Retrieves a list of graphics processes (e.g., OpenGL, DirectX) running on the device, including their PIDs and used GPU memory. - `process_utilization_stats(Option)`: Retrieves utilization statistics (SM, memory, encoder, decoder) for processes on the device (Maxwell+ GPUs). ### Example Usage (Rust) ```rust use nvml_wrapper::Nvml; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; let device = nvml.device_by_index(0)?; let compute_procs = device.running_compute_processes()?; println!("{} compute process(es):", compute_procs.len()); for p in &compute_procs { let name = nvml.sys_process_name(p.pid, 64).unwrap_or_else(|_| "".into()); println!(" PID {}: {name}, GPU mem: {:?}", p.pid, p.used_gpu_memory); } let gfx_procs = device.running_graphics_processes()?; println!("{} graphics process(es):", gfx_procs.len()); for p in &gfx_procs { println!(" PID {}: GPU mem {:?}", p.pid, p.used_gpu_memory); } let util_stats = device.process_utilization_stats(None)?; for s in &util_stats { println!(" PID {}: SM {}%, mem {}%, enc {}%, dec {}%", s.pid, s.sm_util, s.mem_util, s.enc_util, s.dec_util); } Ok(()) } ``` ``` -------------------------------- ### GPU Instance Management Source: https://github.com/rust-nvml/nvml-wrapper/blob/main/nvml-wrapper/unwrapped_functions.txt Functions for managing GPU instances, including creation, destruction, and retrieval of information. ```APIDOC ## nvmlGpuInstanceCreateComputeInstance ### Description Creates a compute instance within a GPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlGpuInstanceCreateComputeInstanceWithPlacement ### Description Creates a compute instance within a GPU instance with specified placement. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlGpuInstanceDestroy ### Description Destroys a GPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlGpuInstanceGetComputeInstanceById ### Description Retrieves a compute instance by its ID within a GPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlGpuInstanceGetComputeInstancePossiblePlacements ### Description Retrieves possible placements for compute instances within a GPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlGpuInstanceGetComputeInstanceProfileInfo ### Description Retrieves information about a compute instance profile within a GPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlGpuInstanceGetComputeInstanceProfileInfoV ### Description Retrieves information about a compute instance profile within a GPU instance (version V). ### Method N/A (Function Call) ### Endpoint N/A ## nvmlGpuInstanceGetComputeInstanceRemainingCapacity ### Description Retrieves the remaining capacity of compute instances within a GPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlGpuInstanceGetComputeInstances ### Description Retrieves all compute instances within a GPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlGpuInstanceGetInfo ### Description Retrieves information about a GPU instance. ### Method N/A (Function Call) ### Endpoint N/A ``` -------------------------------- ### Query vGPU Version and Host Mode Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Query vGPU version ranges and host mode on virtualization-capable GPUs. Use `nvml.vgpu_version` for system-wide versions and `device.virtualization_mode` for device-specific mode. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; // System-level supported and current vGPU version let (supported, current) = nvml.vgpu_version()?; println!("vGPU supported: {}-{}", supported.min, supported.max); println!("vGPU current: {}-{}", current.min, current.max); let device = nvml.device_by_index(0)?; // Active vGPU instances let active_vgpus = device.active_vgpus()?; println!("{} active vGPU(s)", active_vgpus.len()); // Host virtualization mode let virt_mode = device.virtualization_mode()?; println!("Virtualization mode: {:?}", virt_mode); Ok(()) } ``` -------------------------------- ### System and Utility Functions Source: https://github.com/rust-nvml/nvml-wrapper/blob/main/nvml-wrapper/unwrapped_functions.txt Utility functions for error handling, vGPU compatibility, and system-level information. ```APIDOC ## nvmlErrorString ### Description Retrieves the string representation of an NVML error code. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlGetVgpuCompatibility ### Description Checks vGPU compatibility. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlGetVgpuDriverCapabilities ### Description Retrieves vGPU driver capabilities. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlGetVgpuVersion ### Description Retrieves the vGPU version. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlSetVgpuVersion ### Description Sets the vGPU version. ### Method N/A (Function Call) ### Endpoint N/A ``` -------------------------------- ### VGPU Instance Functions Source: https://github.com/rust-nvml/nvml-wrapper/blob/main/nvml-wrapper/unwrapped_functions.txt Functions related to querying and managing virtual GPU instances. ```APIDOC ## VGPU Instance Functions This section lists functions for interacting with virtual GPU instances. ### Functions - `nvmlVgpuInstanceGetType` - `nvmlVgpuInstanceGetUUID` - `nvmlVgpuInstanceGetVmDriverVersion` - `nvmlVgpuInstanceGetVmID` - `nvmlVgpuInstanceSetEncoderCapacity` ``` -------------------------------- ### Compute Instance Management Source: https://github.com/rust-nvml/nvml-wrapper/blob/main/nvml-wrapper/unwrapped_functions.txt Functions for managing compute instances, including creation, destruction, and retrieval of information. ```APIDOC ## nvmlComputeInstanceDestroy ### Description Destroys a compute instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlComputeInstanceGetInfo ### Description Retrieves information about a compute instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlComputeInstanceGetInfo_v2 ### Description Retrieves extended information about a compute instance (version 2). ### Method N/A (Function Call) ### Endpoint N/A ``` -------------------------------- ### List Running Compute and Graphics Processes Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt List the PID and GPU memory usage of processes currently using the GPU, categorized into compute and graphics processes. Also shows per-process utilization stats for supported architectures. ```rust use nvml_wrapper::Nvml; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; let device = nvml.device_by_index(0)?; // CUDA / compute processes let compute_procs = device.running_compute_processes()?; println!("{} compute process(es):", compute_procs.len()); for p in &compute_procs { let name = nvml.sys_process_name(p.pid, 64).unwrap_or_else(|_| "".into()); println!(" PID {}: {name}, GPU mem: {:?}", p.pid, p.used_gpu_memory); } // OpenGL / DirectX / graphics processes let gfx_procs = device.running_graphics_processes()?; println!("{} graphics process(es):", gfx_procs.len()); for p in &gfx_procs { println!(" PID {}: GPU mem {:?}", p.pid, p.used_gpu_memory); } // Per-process utilization stats (Maxwell+) let util_stats = device.process_utilization_stats(None)?; for s in &util_stats { println!(" PID {}: SM {}%, mem {}%, enc {}%, dec {}%", s.pid, s.sm_util, s.mem_util, s.enc_util, s.dec_util); } Ok(()) } ``` -------------------------------- ### Power Management Source: https://context7.com/rust-nvml/nvml-wrapper/llms.txt Query and configure GPU power draw and TDP limits. Values are in milliwatts. ```APIDOC ## `Device::power_usage` / `enforced_power_limit` / `power_management_limit` — Power management Query and configure GPU power draw and TDP limits. Values are in milliwatts. ### Description This section covers functions for querying and setting power-related configurations for a GPU device. ### Methods - `power_usage()`: Retrieves the current power draw of the device. - `enforced_power_limit()`: Retrieves the currently enforced power limit. - `power_management_limit()`: Retrieves the configured power management limit. - `power_management_limit_default()`: Retrieves the default power management limit. - `power_management_limit_constraints()`: Retrieves the allowed range for power management limits. - `total_energy_consumption()`: Retrieves the total energy consumed since the last driver reload (in millijoules). ### Example Usage (Rust) ```rust use nvml_wrapper::Nvml; use nvml_wrapper::error::NvmlError; fn main() -> Result<(), NvmlError> { let nvml = Nvml::init()?; let device = nvml.device_by_index(0)?; let usage = device.power_usage()?; println!("Current power draw: {:.1} W", usage as f64 / 1000.0); let limit = device.power_management_limit()?; println!("Power limit: {:.1} W", limit as f64 / 1000.0); let enforced = device.enforced_power_limit()?; println!("Enforced limit: {:.1} W", enforced as f64 / 1000.0); let default_limit = device.power_management_limit_default()?; println!("Default limit: {:.1} W", default_limit as f64 / 1000.0); let constraints = device.power_management_limit_constraints()?; println!( "Allowed range: {:.1}–{:.1} W", constraints.min_limit as f64 / 1000.0, constraints.max_limit as f64 / 1000.0, ); let energy = device.total_energy_consumption()?; println!("Total energy: {} J", energy / 1000); Ok(()) } ``` ``` -------------------------------- ### System Management Source: https://github.com/rust-nvml/nvml-wrapper/blob/main/nvml-wrapper/unwrapped_functions.txt Functions for managing system-level NVML configurations and information. ```APIDOC ## nvmlSystemGetConfComputeCapabilities ### Description Retrieves compute capabilities for the system. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlSystemGetConfComputeGpusReadyState ### Description Retrieves the ready state of GPUs for compute configuration in the system. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlSystemGetConfComputeKeyRotationThresholdInfo ### Description Retrieves information about key rotation thresholds for compute configuration in the system. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlSystemGetConfComputeSettings ### Description Retrieves compute configuration settings for the system. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlSystemGetConfComputeState ### Description Retrieves the compute configuration state for the system. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlSystemGetDriverBranch ### Description Retrieves the driver branch information for the system. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlSystemGetNvlinkBwMode ### Description Retrieves the NVLink bandwidth mode for the system. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlSystemSetConfComputeGpusReadyState ### Description Sets the ready state of GPUs for compute configuration in the system. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlSystemSetConfComputeKeyRotationThresholdInfo ### Description Sets the key rotation threshold information for compute configuration in the system. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlSystemSetNvlinkBwMode ### Description Sets the NVLink bandwidth mode for the system. ### Method N/A (Function Call) ### Endpoint N/A ``` -------------------------------- ### vGPU Instance Management Source: https://github.com/rust-nvml/nvml-wrapper/blob/main/nvml-wrapper/unwrapped_functions.txt Functions for managing vGPU instances, including accounting, ECC, and frame rate limiting. ```APIDOC ## nvmlVgpuInstanceClearAccountingPids ### Description Clears accounting PIDs for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetAccountingMode ### Description Retrieves the accounting mode for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetAccountingPids ### Description Retrieves accounting PIDs for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetAccountingStats ### Description Retrieves accounting statistics for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetEccMode ### Description Retrieves the ECC mode for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetEncoderCapacity ### Description Retrieves the encoder capacity for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetEncoderSessions ### Description Retrieves encoder sessions for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetEncoderStats ### Description Retrieves encoder statistics for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetFBCSessions ### Description Retrieves FBC sessions for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetFBCStats ### Description Retrieves FBC statistics for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetFbUsage ### Description Retrieves framebuffer usage for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetFrameRateLimit ### Description Retrieves the frame rate limit for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetGpuInstanceId ### Description Retrieves the GPU instance ID for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetGpuPciId ### Description Retrieves the PCI ID of the GPU associated with a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetLicenseInfo ### Description Retrieves license information for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetLicenseInfo_v2 ### Description Retrieves license information for a vGPU instance (version 2). ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetLicenseStatus ### Description Retrieves the license status for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetMdevUUID ### Description Retrieves the MDEV UUID for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetMetadata ### Description Retrieves metadata for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetPlacementId ### Description Retrieves the placement ID for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ## nvmlVgpuInstanceGetRuntimeStateSize ### Description Retrieves the size of the runtime state for a vGPU instance. ### Method N/A (Function Call) ### Endpoint N/A ``` -------------------------------- ### Device Management Functions Source: https://github.com/rust-nvml/nvml-wrapper/blob/main/nvml-wrapper/unwrapped_functions.txt Core functions for managing and querying NVIDIA devices. ```APIDOC ## Device Management Functions This section details essential functions for device management and information retrieval. ### Functions - `nvmlDeviceGetAttributes` - `nvmlDeviceGetComputeRunningProcesses` - `nvmlDeviceGetCount` - `nvmlDeviceGetDriverModel_v2` - `nvmlDeviceGetFanSpeed` - `nvmlDeviceGetGraphicsRunningProcesses` - `nvmlDeviceGetHandleByIndex` - `nvmlDeviceGetHandleByPciBusId` - `nvmlDeviceGetMemoryInfo` - `nvmlDeviceGetNvLinkRemotePciInfo` - `nvmlDeviceGetPciInfo` - `nvmlDeviceGetPciInfo_v2` - `nvmlDeviceRemoveGpu` - `nvmlDeviceSetPowerManagementLimit_v2` ```