From e5860a4999c98a13757c6301ebbab65612e3af2c Mon Sep 17 00:00:00 2001 From: layerdiffusion <19834515+lllyasviel@users.noreply.github.com> Date: Fri, 2 Aug 2024 03:32:52 -0700 Subject: [PATCH] move stream file --- ldm_patched/modules/ops.py | 2 +- modules_forge/stream.py | 67 -------------------------------------- 2 files changed, 1 insertion(+), 68 deletions(-) delete mode 100644 modules_forge/stream.py diff --git a/ldm_patched/modules/ops.py b/ldm_patched/modules/ops.py index 286f83a5..4c3c4f84 100644 --- a/ldm_patched/modules/ops.py +++ b/ldm_patched/modules/ops.py @@ -6,7 +6,7 @@ import torch import ldm_patched.modules.model_management import contextlib -from modules_forge import stream +from backend import stream # https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/14855/files diff --git a/modules_forge/stream.py b/modules_forge/stream.py deleted file mode 100644 index 93ddadeb..00000000 --- a/modules_forge/stream.py +++ /dev/null @@ -1,67 +0,0 @@ -# https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/14855 - -import torch - -from ldm_patched.modules import args_parser -from ldm_patched.modules import model_management - - -def stream_context(): - if torch.cuda.is_available(): - return torch.cuda.stream - - if model_management.is_intel_xpu(): - return torch.xpu.stream - - return None - - -def get_current_stream(): - try: - if torch.cuda.is_available(): - device = torch.device(torch.cuda.current_device()) - stream = torch.cuda.current_stream(device) - with torch.cuda.stream(stream): - torch.zeros((1, 1)).to(device, torch.float32) - stream.synchronize() - return stream - if model_management.is_intel_xpu(): - device = torch.device("xpu") - stream = torch.xpu.current_stream(device) - with torch.xpu.stream(stream): - torch.zeros((1, 1)).to(device, torch.float32) - stream.synchronize() - return stream - except: - return None - - -def get_new_stream(): - try: - if torch.cuda.is_available(): - device = torch.device(torch.cuda.current_device()) - stream = torch.cuda.Stream(device) - with torch.cuda.stream(stream): - torch.zeros((1, 1)).to(device, torch.float32) - stream.synchronize() - return stream - if model_management.is_intel_xpu(): - device = torch.device("xpu") - stream = torch.xpu.Stream(device) - with torch.xpu.stream(stream): - torch.zeros((1, 1)).to(device, torch.float32) - stream.synchronize() - return stream - except: - return None - - -current_stream = None -mover_stream = None -using_stream = False - -if args_parser.args.cuda_stream: - current_stream = get_current_stream() - mover_stream = get_new_stream() - using_stream = current_stream is not None and mover_stream is not None -