mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2025-12-12 15:35:00 +08:00
mm: guard against double pin and unpin explicitly (#10672)
As commented, if you let cuda be the one to detect double pin/unpinning it actually creates an asyc GPU error.
This commit is contained in:
parent
eb1c42f649
commit
cf97b033ee
@ -1103,6 +1103,12 @@ def pin_memory(tensor):
|
|||||||
if not is_device_cpu(tensor.device):
|
if not is_device_cpu(tensor.device):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if tensor.is_pinned():
|
||||||
|
#NOTE: Cuda does detect when a tensor is already pinned and would
|
||||||
|
#error below, but there are proven cases where this also queues an error
|
||||||
|
#on the GPU async. So dont trust the CUDA API and guard here
|
||||||
|
return False
|
||||||
|
|
||||||
size = tensor.numel() * tensor.element_size()
|
size = tensor.numel() * tensor.element_size()
|
||||||
if (TOTAL_PINNED_MEMORY + size) > MAX_PINNED_MEMORY:
|
if (TOTAL_PINNED_MEMORY + size) > MAX_PINNED_MEMORY:
|
||||||
return False
|
return False
|
||||||
@ -1123,6 +1129,12 @@ def unpin_memory(tensor):
|
|||||||
if not is_device_cpu(tensor.device):
|
if not is_device_cpu(tensor.device):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if not tensor.is_pinned():
|
||||||
|
#NOTE: Cuda does detect when a tensor is already pinned and would
|
||||||
|
#error below, but there are proven cases where this also queues an error
|
||||||
|
#on the GPU async. So dont trust the CUDA API and guard here
|
||||||
|
return False
|
||||||
|
|
||||||
ptr = tensor.data_ptr()
|
ptr = tensor.data_ptr()
|
||||||
if torch.cuda.cudart().cudaHostUnregister(ptr) == 0:
|
if torch.cuda.cudart().cudaHostUnregister(ptr) == 0:
|
||||||
TOTAL_PINNED_MEMORY -= PINNED_MEMORY.pop(ptr)
|
TOTAL_PINNED_MEMORY -= PINNED_MEMORY.pop(ptr)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user