Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gpu_load_smi: add gpu_load_smi, read GPU data from NVIDIA-SMI #533

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions gpu_load_smi/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2024 Syed Isam Hashmi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

33 changes: 33 additions & 0 deletions gpu_load_smi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# gpu_load_smi

Displays information about the current state of a specific NVIDIA GPU using the `nvidia-smi` utility.

Although it will likely be zero, you should still confirm the GPU index.
The GPU index can be fetched by using the `nvidia-smi dmon` command.
`$ nvidia-smi dmon`
```
# gpu pwr gtemp mtemp sm mem enc dec jpg ofa mclk pclk
# Idx W C C % % % % % % MHz MHz
0 3 51 - 0 0 0 0 0 0 405 210
```
The GPU index is the first column in the output. as depicted by the headers.
Identify which GPU index you want and use that as the `GPU_IDX` parameter.


![](gpu_load_smi.png)

# Dependencies
- nvidia-utils (contains the `nvidia-smi` binary)
- bash


```
[gpu_load_smi]
command=$SCRIPT_DIR/gpu-load
label=GPU
interval=5
GPU_IDX=0 // [YOUR_GPU_INDEX]
```

If you found this useful, I'd love to hear about it.
Feel free to email me: is@mhashmi.com
42 changes: 42 additions & 0 deletions gpu_load_smi/gpu_load_smi
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

# Author: Syed Isam Hashmi
# 2024-07-30

gpuIdx="${GPU_IDX}"

while read -r line; do
firstChar="${line:0:1}"

# First couple lines and occasional lines of
# the NVIDIA-SMI output are headers that start with '#'
#
# In addition, ignore lines that arent related to this GPU device.
if [ "$firstChar" == "#" ] || [ "$firstChar" != "$gpuIdx" ];
then
continue;
else
# I commented out unused variables
#
# Uncomment and use these lines as you wish.
line=($line)
# gpuId=${line[0]}
# pwrW=${line[1]}
gTemp=${line[2]}
# mTemp=${line[3]}
sm=${line[4]}
mem=${line[5]}
# enc=${line[6]}
# dec=${line[7]}
# jpg=${line[8]}
# ofa=${line[9]}
# mclk=${line[10]}
# pclk=${line[11]}

# Customize to your heart's content
echo "$gTemp°C SM%: $sm% MEM: $mem%"
exit
fi
done < <(nvidia-smi dmon -d 1)
wait

Binary file added gpu_load_smi/gpu_load_smi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions gpu_load_smi/i3blocks.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[gpu_load_smi]
label=GPU
interval=5
GPU_IDX=0