Created
December 24, 2022 02:52
-
-
Save halr9000/6d3b95b8bb28510b65023f264d619dcf to your computer and use it in GitHub Desktop.
Query NVIDIA-SMI for select properties and output them to the screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
$output = nvidia-smi.exe -q -x | |
} | |
catch { | |
<#Do this if a terminating exception happens#> | |
throw "NVIDIA System Management Interface (nvidia-smi.exe) is not found. Learn more at https://developer.nvidia.com/nvidia-system-management-interface" | |
} | |
$xml = [xml]$output | |
$log = $xml.nvidia_smi_log | |
$logObj = [PSCustomObject]@{ | |
Timestamp = $log.timestamp | |
DriverVersion = $log.driver_version | |
CudaVersion = $log.cuda_version | |
GpuCount = $log.attached_gpus | |
} | |
$logObj | Format-List | |
# Iterate over 'gpu' property in case there are multiple GPUs | |
$log.gpu | ForEach-Object { | |
$obj = [PSCustomObject]@{ | |
UUID = $_.uuid | |
Name = $_.product_name | |
Architecture = $_.product_architecture | |
GpuUtilPercent = $_.utilization.gpu_util | |
GpuMemUtilPercent = $_.utilization.memory_util | |
MemFreeMB = ($_.fb_memory_usage.free -split " ")[0] | |
MemReservedMB = ($_.fb_memory_usage.reserved -split " ")[0] | |
MemTotalMB = ($_.fb_memory_usage.total -split " ")[0] | |
MemUsedMB = ($_.fb_memory_usage.total -split " ")[0] | |
} | |
$obj | Format-List | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I make an update, it would be to skip the format-list and instead, write one custom object. And I would fix the percent values to write an integer. But making formatters is a PITA.