Skip to content

Instantly share code, notes, and snippets.

@0xnurl
Created January 18, 2023 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xnurl/0698cd9d4b8a15f4ccafb77eb0430062 to your computer and use it in GitHub Desktop.
Save 0xnurl/0698cd9d4b8a15f4ccafb77eb0430062 to your computer and use it in GitHub Desktop.
def get_free_gpu():
max_free = 0
max_idx = 0
rows = (
subprocess.check_output(
["nvidia-smi", "--format=csv", "--query-gpu=memory.free"]
)
.decode("utf-8")
.split("\n")
)
for i, row in enumerate(rows[1:-1]):
mb = float(row.rstrip(" [MiB]"))
if mb > max_free:
max_idx = i
max_free = mb
return max_idx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment