Created
August 11, 2023 12:47
-
-
Save ouyen/34b08d23531491dc8007b7b204ac648d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 os | |
import pandas as pd | |
from io import StringIO | |
def query_gpu(qargs=[]): | |
''' | |
qargs: | |
query arguments | |
return: | |
a list of dict | |
Querying GPUs infos | |
查询GPU信息 | |
''' | |
qargs = ['index', 'gpu_name', 'memory.free', 'memory.total', 'power.draw', 'power.limit',"utilization.gpu"] + qargs | |
cmd = 'nvidia-smi --query-gpu={} --format=csv,noheader'.format(','.join(qargs)) | |
results = os.popen(cmd).read() | |
csv_str = ",".join(qargs)+"\n"+results | |
csv_str = csv_str.replace(" MiB", "") | |
csv_str = csv_str.replace(" W", "") | |
return pd.read_csv(StringIO(csv_str)) | |
# return csv_str | |
GPU_list=query_gpu() | |
# GPU_list["memory.free"].idxmax() | |
GPU_list | |
device = torch.device("cuda:{}".format(GPU_list["memory.free"].idxmax())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment