nvidia smi tool call
This commit is contained in:
28
nvidia_smi.py
Normal file
28
nvidia_smi.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
|
def get_gpu_stats():
|
||||||
|
command = [
|
||||||
|
"nvidia-smi",
|
||||||
|
"--query-gpu=index,name,memory.used,memory.free,power.draw,temperature.gpu",
|
||||||
|
"--format=csv,noheader,nounits"
|
||||||
|
]
|
||||||
|
result = subprocess.run(command, stdout=subprocess.PIPE, text=True)
|
||||||
|
stats = result.stdout.strip().split(", ")
|
||||||
|
return {
|
||||||
|
"index": int(stats[0]),
|
||||||
|
"name": str(stats[1]),
|
||||||
|
"memory_used": float(stats[2]), # in MB
|
||||||
|
"memory_free": float(stats[3]), # in MB
|
||||||
|
"power_draw": float(stats[4]), # in watts
|
||||||
|
"temperature": float(stats[5]) # in Celsius
|
||||||
|
}
|
||||||
|
|
||||||
|
def main():
|
||||||
|
while True:
|
||||||
|
stats = get_gpu_stats()
|
||||||
|
print(f"Power: {stats['power_draw']} W, Memory: {stats['memory_used']} MB, Temp: {stats['temperature']}°C")
|
||||||
|
time.sleep(1) # Update every second
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Reference in New Issue
Block a user