Skip to content

Commit

Permalink
Merge pull request vladmandic#1255 from vincenavarro/dualxpu
Browse files Browse the repository at this point in the history
Add --device-id support for XPU
  • Loading branch information
Disty0 authored Jun 1, 2023
2 parents 02c9640 + c30eb90 commit e10d929
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions modules/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def extract_device_id(args, name): # pylint: disable=redefined-outer-name

def get_cuda_device_string():
if shared.cmd_opts.use_ipex:
if shared.cmd_opts.device_id is not None:
return f"xpu:{shared.cmd_opts.device_id}"
return "xpu"
else:
if shared.cmd_opts.device_id is not None:
Expand All @@ -33,7 +35,7 @@ def get_cuda_device_string():

def get_optimal_device_name():
if shared.cmd_opts.use_ipex:
return "xpu"
return get_cuda_device_string()
elif cuda_ok and not shared.cmd_opts.use_directml:
return get_cuda_device_string()
if has_mps():
Expand Down Expand Up @@ -66,7 +68,7 @@ def torch_gc(force=False):
collected = gc.collect()
if shared.cmd_opts.use_ipex:
try:
with torch.xpu.device("xpu"):
with torch.xpu.device(get_cuda_device_string()):
torch.xpu.empty_cache()
except:
pass
Expand Down Expand Up @@ -143,7 +145,10 @@ def set_cuda_params():

args = cmd_args.parser.parse_args()
if args.use_ipex:
cpu = torch.device("xpu") #Use XPU instead of CPU. %20 Perf improvement on weak CPUs.
if args.device_id is not None:
cpu = torch.device(f"xpu:{args.device_id}") #Use XPU instead of CPU. %20 Perf improvement on weak CPUs.
else:
cpu = torch.device("xpu")
else:
cpu = torch.device("cpu")
device = device_interrogate = device_gfpgan = device_esrgan = device_codeformer = None
Expand Down

0 comments on commit e10d929

Please sign in to comment.