Skip to content

Instantly share code, notes, and snippets.

@halr9000
Created December 24, 2022 02:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halr9000/6d3b95b8bb28510b65023f264d619dcf to your computer and use it in GitHub Desktop.
Save halr9000/6d3b95b8bb28510b65023f264d619dcf to your computer and use it in GitHub Desktop.
Query NVIDIA-SMI for select properties and output them to the screen
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
}
@halr9000
Copy link
Author

halr9000 commented Dec 24, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment