Last active
March 27, 2023 17:09
-
-
Save ShawonAshraf/ca52d0f6ad31454370c2af4fdfb70803 to your computer and use it in GitHub Desktop.
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
import pynvml | |
pynvml.nvmlInit() | |
device_count = pynvml.nvmlDeviceGetCount() | |
for i in range(device_count): | |
try: | |
handle = pynvml.nvmlDeviceGetHandleByIndex(i) | |
util = pynvml.nvmlDeviceGetUtilizationRates(handle) | |
print("========================================") | |
print(f"GPU Index: {i}") | |
print(f"Name: {pynvml.nvmlDeviceGetName(handle)} || Utilization: {util.gpu}%") | |
info = pynvml.nvmlDeviceGetMemoryInfo(handle) | |
print(f"Memory Usage (free/total): {info.free / 1024 / 1024}/{info.total / 1024 / 1024}") | |
print("========================================\n") | |
except Exception: | |
print("GPU ", i, " can't be accessed") | |
pynvml.nvmlShutdown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment