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

enable selecting gpu #1490

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
16 changes: 10 additions & 6 deletions desc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __getattr__(name):
config = {"device": None, "avail_mem": None, "kind": None}


def set_device(kind="cpu"):
brokenhammer marked this conversation as resolved.
Show resolved Hide resolved
def set_device(kind="cpu", gpuid=None):
"""Sets the device to use for computation.

If kind==``'gpu'``, checks available GPUs and selects the one with the most
Expand Down Expand Up @@ -127,11 +127,15 @@ def set_device(kind="cpu"):
set_device(kind="cpu")
return
devices = [dev for dev in devices if dev["index"] in gpu_ids]
for dev in devices:
mem = dev["mem_total"] - dev["mem_used"]
if mem > maxmem:
maxmem = mem
selected_gpu = dev

if (not (gpuid == None)) and (str(gpuid) in gpu_ids):
unalmis marked this conversation as resolved.
Show resolved Hide resolved
selected_gpu = [dev for dev in devices if dev["index"] == str(gpuid)][0]
YigitElma marked this conversation as resolved.
Show resolved Hide resolved
else:
for dev in devices:
mem = dev["mem_total"] - dev["mem_used"]
dpanici marked this conversation as resolved.
Show resolved Hide resolved
if mem > maxmem:
maxmem = mem
selected_gpu = dev
config["device"] = selected_gpu["type"] + " (id={})".format(
selected_gpu["index"]
)
Expand Down
Loading