NVML
NVML, the NVIDIA Management Library, reports the state of the GPUs in the system: their clocks, power draw, temperature, memory use and the processes using them. It ships with the driver and doesn't need a CUDA context, so it can also see GPUs that CUDA.jl doesn't use. CUDA.versioninfo() uses it when it is available.
The module offers NVML at two levels:
- The functions documented below query a device or the system, and return Julia values, in bytes, MHz, watts, joules and degrees Celsius, and fractions for utilization. They are not exported, apart from
has_nvml, so call them asNVML.memory_info(dev). - The generated bindings in
libnvml.jlfollow NVIDIA's C API, and change with the driver headers. AnNVML.Deviceconverts to thenvmlDevice_tthey take.
Check has_nvml before using NVML: CUDA.jl doesn't use it on Tegra devices, and on some systems the library is missing or fails to initialize. Not every query is supported by every device, and some need administrator rights: a failing query throws an NVMLError, whose code tells these cases apart.
NVML numbers devices differently from CUDA, so look up the NVML device for a CuDevice by its UUID:
dev = device()nvml_dev = NVML.Device(uuid(dev); mig = uuid(dev) != parent_uuid(dev))NVML.memory_info(nvml_dev)Public
NVML.NVML — Module
Julia wrappers for NVML, the NVIDIA Management Library, which queries the state of the GPUs in the system (clocks, power, temperature, memory, processes) without creating a CUDA context. See has_nvml and NVML.Device.
NVML.Device — Type
NVML.Device(index::Integer) -> NVML.Device
NVML.Device(uuid::Base.UUID; mig=false) -> NVML.Device
NVML.Device(serial::String) -> NVML.DeviceA GPU as seen by NVML, looked up by its NVML index (starting at 0), its UUID, or its board serial number. Wraps nvmlDeviceGetHandleByIndex, nvmlDeviceGetHandleByUUID and nvmlDeviceGetHandleBySerial.
NVML numbers the GPUs in its own order, which ignores CUDA_VISIBLE_DEVICES and can differ from CUDA's, so an NVML index need not match the ordinal of a CuDevice. To get the NVML device for a CuDevice, look it up by UUID instead; for a MIG compute instance, set mig = true:
dev = device()mig = uuid(dev) != parent_uuid(dev)nvml_dev = NVML.Device(uuid(dev); mig)NVML.Device(parent_uuid(dev)) gives the physical GPU a MIG instance belongs to.
NVML.NVMLError — Type
NVMLErrorThe exception the functions in this module throw when an NVML call fails. Its code field is the nvmlReturn_t code, e.g. ERROR_NOT_SUPPORTED when the device doesn't support a query, or ERROR_NO_PERMISSION when it needs administrator rights.
CUDACore.name — Method
NVML.name(dev::NVML.Device) -> StringThe product name of the device, e.g. "NVIDIA GeForce RTX 5080", or of the MIG compute instance. Wraps nvmlDeviceGetName.
This is a method of CUDACore.name, so name(dev) works without the NVML. prefix.
CUDACore.uuid — Method
NVML.uuid(dev::NVML.Device) -> Base.UUIDThe UUID of the device, or of the MIG compute instance. It matches uuid(::CuDevice) for the corresponding CUDA device. Wraps nvmlDeviceGetUUID.
This is a method of CUDACore.uuid, so uuid(dev) works without the NVML. prefix.
NVML.applications_clock — Method
NVML.applications_clock(dev::NVML.Device) -> NamedTupleThe applications clocks the device is configured to run kernels at, in MHz, as a named tuple with entries for the graphics, sm, memory and video clocks. Clocks that the device doesn't report are left out. Wraps nvmlDeviceGetApplicationsClock.
NVML.brand — Method
NVML.brand(dev::NVML.Device) -> nvmlBrandType_tThe brand of the device, e.g. NVML_BRAND_GEFORCE. Wraps nvmlDeviceGetBrand.
NVML.clock_event_reasons — Method
NVML.clock_event_reasons(dev::NVML.Device) -> NamedTupleWhy the clocks of the device are currently reduced, as a named tuple of Bools with entries for the reasons the device supports:
idle: nothing is running on the GPU;application_setting: the applications clocks limit the clocks;sw_power_cap: the driver keeps the power draw below the power limit;hw_slow: hardware slowdown, because of temperature, power or an external signal;sync_boost: the GPU is part of a sync boost group;sw_thermal: the driver keeps the temperature below its limit;hw_thermal: hardware slowdown because of temperature;hw_power_brake: hardware slowdown because of an external power brake signal;display_setting: the display clock settings limit the clocks.
Wraps nvmlDeviceGetCurrentClocksEventReasons and nvmlDeviceGetSupportedClocksEventReasons, or their predecessors nvmlDeviceGet*ClocksThrottleReasons on drivers older than R535.
NVML.clock_info — Method
NVML.clock_info(dev::NVML.Device) -> NamedTupleThe current clocks of the device, in MHz, as a named tuple with entries for the graphics, sm, memory and video clocks. Clocks that the device doesn't report are left out. Wraps nvmlDeviceGetClockInfo.
NVML.compute_capability — Method
NVML.compute_capability(dev::NVML.Device) -> VersionNumberThe compute capability of the device, e.g. v"12.0", as capability(::CuDevice) returns it. Wraps nvmlDeviceGetCudaComputeCapability.
NVML.compute_mode — Method
NVML.compute_mode(dev::NVML.Device) -> nvmlComputeMode_tThe compute mode of the device, which determines whether several processes can use it at the same time, e.g. NVML_COMPUTEMODE_DEFAULT or NVML_COMPUTEMODE_EXCLUSIVE_PROCESS. Wraps nvmlDeviceGetComputeMode.
NVML.compute_processes — Method
NVML.compute_processes(dev::NVML.Device)
-> Dict{Int,@NamedTuple{used_gpu_memory::Union{Int,Missing}}}The processes that have a compute context on the device, by process ID, with the GPU memory in bytes each one uses. The memory use is missing when NVML can't report it, e.g. on Windows with the WDDM driver model. Processes in other containers may be left out. Wraps nvmlDeviceGetComputeRunningProcesses.
NVML.cuda_driver_version — Method
NVML.cuda_driver_version() -> VersionNumberThe latest version of CUDA that the system's CUDA driver library supports, e.g. v"12.6.0". Wraps nvmlSystemGetCudaDriverVersion_v2, which asks the libcuda library that NVML finds. This usually equals CUDACore.driver_version(), but differs when CUDA.jl loaded another driver library, such as a forward-compatible one.
NVML.default_applications_clock — Method
NVML.default_applications_clock(dev::NVML.Device) -> NamedTupleThe default applications clocks of the device: the clocks it runs kernels at unless configured otherwise, in MHz, as a named tuple with entries for the graphics, sm, memory and video clocks. Clocks that the device doesn't report are left out. Wraps nvmlDeviceGetDefaultApplicationsClock.
NVML.devices — Method
NVML.devices() -> NVML.DeviceIteratorAn iterator over all GPUs that NVML knows of, as NVML.Devices in NVML's order. Unlike CUDACore.devices(), it includes GPUs hidden by CUDA_VISIBLE_DEVICES. It is not exported, so that it doesn't clash with devices().
NVML.driver_version — Method
NVML.driver_version() -> VersionNumberThe version of the installed NVIDIA driver, e.g. v"560.35.3" for driver 560.35.03. Wraps nvmlSystemGetDriverVersion. Unlike CUDACore.driver_version(), this is not the CUDA version the driver supports: use NVML.cuda_driver_version for that.
NVML.energy_consumption — Method
NVML.energy_consumption(dev::NVML.Device) -> Float64The energy the device has consumed since the driver was last loaded, in joules. Take the difference of two calls to measure the energy used in between. Wraps nvmlDeviceGetTotalEnergyConsumption, which needs a Volta or newer GPU.
NVML.has_nvml — Method
has_nvml() -> BoolWhether NVML, the NVIDIA Management Library that ships with the driver, can be used. It can't when the library is missing or fails to initialize, and CUDA.jl doesn't use it on Tegra devices, where it can't look up the NVML device of a CuDevice. Check this before calling any other function in this module.
NVML.index — Method
NVML.index(dev::NVML.Device) -> IntThe NVML index of the device, as passed to NVML.Device(index). For a MIG compute instance, it is the index of the instance within its GPU instead. Wraps nvmlDeviceGetIndex.
NVML.max_clock_info — Method
NVML.max_clock_info(dev::NVML.Device) -> NamedTupleThe maximum clocks of the device, in MHz, as a named tuple with entries for the graphics, sm, memory and video clocks. Clocks that the device doesn't report are left out. Wraps nvmlDeviceGetMaxClockInfo.
NVML.memory_info — Method
NVML.memory_info(dev::NVML.Device) -> @NamedTuple{total::Int, free::Int, used::Int}The total, free and used memory of the device, in bytes, counting the memory of all processes. For a MIG compute instance, these are the numbers of the instance; for a GPU in MIG mode, querying the GPU as a whole needs administrator rights. Wraps nvmlDeviceGetMemoryInfo.
NVML.power_usage — Method
NVML.power_usage(dev::NVML.Device) -> Float64The power draw of the device, in watts. On Ampere (except GA100) and newer GPUs, this is the average over the last second, on older ones the instantaneous power draw. Wraps nvmlDeviceGetPowerUsage.
NVML.serial — Method
NVML.serial(dev::NVML.Device) -> StringThe serial number printed on the board. Wraps nvmlDeviceGetSerial, which only supports data-center and workstation GPUs: others throw an NVMLError with code ERROR_NOT_SUPPORTED.
NVML.supported_graphics_clocks — Method
NVML.supported_graphics_clocks(dev::NVML.Device, [memory_clock]) -> Vector{Int}The graphics clocks, in MHz, that the applications clocks of the device can be set to together with the memory clock memory_clock (in MHz), or with any of the supported_memory_clocks if it is omitted. Wraps nvmlDeviceGetSupportedGraphicsClocks.
NVML.supported_memory_clocks — Method
NVML.supported_memory_clocks(dev::NVML.Device) -> Vector{Int}The memory clocks, in MHz, that the applications clocks of the device can be set to. Wraps nvmlDeviceGetSupportedMemoryClocks.
NVML.temperature — Function
NVML.temperature(dev::NVML.Device, sensor=NVML_TEMPERATURE_GPU) -> IntThe temperature of the device, in degrees Celsius, as measured by sensor, an nvmlTemperatureSensors_t. Wraps nvmlDeviceGetTemperature.
NVML.utilization_rates — Method
NVML.utilization_rates(dev::NVML.Device) -> @NamedTuple{compute::Float64, memory::Float64}How busy the device was over the driver's last sample period (between 1/6 s and 1 s), as fractions between 0 and 1: compute is the fraction of time a kernel was running, and memory the fraction of time device memory was being read or written. Wraps nvmlDeviceGetUtilizationRates, which doesn't support GPUs in MIG mode.
NVML.version — Method
NVML.version() -> VersionNumberReturn the version of the NVML API. The major version is the CUDA major version the driver supports, while the driver part of the version string (e.g. 560.35.03 in 12.560.35.03) is stored in the build suffix: v"12.0.0+560.35.3". Minor versions are not reported, so compare against NVML.driver_version() or NVML.cuda_driver_version() to check for features added in a minor release. Wraps nvmlSystemGetNVMLVersion.