[][src]Crate nvml_wrapper

A safe and ergonomic Rust wrapper for the NVIDIA Management Library (NVML), a C-based programmatic interface for monitoring and managing various states within NVIDIA GPUs.

let nvml = NVML::init()?;
// Get the first `Device` (GPU) in the system
let device = nvml.device_by_index(0)?;

let brand = device.brand()?; // GeForce on my system
let fan_speed = device.fan_speed(0)?; // Currently 17% on my system
let power_limit = device.enforced_power_limit()?; // 275k milliwatts on my system
let encoder_util = device.encoder_utilization()?; // Currently 0 on my system; Not encoding anything
let memory_info = device.memory_info()?; // Currently 1.63/6.37 GB used on my system

// ... and there's a whole lot more you can do. Most everything in NVML is wrapped and ready to go

NVML is intended to be a platform for building 3rd-party applications, and is also the underlying library for NVIDIA's nvidia-smi tool.


nvml-wrapper builds on top of generated bindings for NVML that make use of the libloading crate. This means the NVML library gets loaded upon calling NVML::init and can return an error if NVML isn't present, making it possible to drop NVIDIA-related features in your code at runtime on systems that don't have relevant hardware.

Successful execution of NVML::init means:

  • The NVML library was present on the system and able to be opened
  • The function symbol to initialize NVML was loaded and called successfully
  • An attempt has been made to load all other NVML function symbols

Every function you call thereafter will individually return an error if it couldn't be loaded from the NVML library during the NVML::init call.

Note that it's not advised to repeatedly call NVML::init as the constructor has to perform all the work of loading the function symbols from the library each time it gets called. Instead, call NVML::init once and store the resulting NVML instance somewhere to be accessed throughout the lifetime of your program.

NVML Support

This wrapper is being developed against and currently supports NVML version 11. Each new version of NVML is guaranteed to be backwards-compatible according to NVIDIA, so this wrapper should continue to work without issue regardless of NVML version bumps.


The Minimum Supported Rust Version is currently 1.42.0. I will not go out of my way to avoid bumping this.

Cargo Features

The serde feature can be toggled on in order to #[derive(Serialize, Deserialize)] for every NVML data structure.


pub use crate::device::Device;
pub use crate::event::EventSet;
pub use crate::nv_link::NvLink;
pub use crate::unit::Unit;



Re-exports from nvml-wrapper-sys that are necessary for use of this wrapper.




The main struct that this library revolves around.


A builder struct that provides further flexibility in how NVML is initialized.



Determines the major version of the CUDA driver given the full version.


Determines the minor version of the CUDA driver given the full version.