Journaliser les replis CPU du GPU et retirer une copie VRAM inutile
This commit is contained in:
@ -355,7 +355,10 @@ def to_gpu(arr):
|
||||
if _gpu_available():
|
||||
try:
|
||||
return _cp.asarray(arr.astype(np.float32))
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
# L'erreur d'origine (souvent OOM) ne doit pas être avalée :
|
||||
# sans elle, un repli CPU est indissociable d'un simple bug.
|
||||
logger.warning(f"Transfert GPU échoué ({e}) — repli CPU pour ce calcul")
|
||||
disable_gpu()
|
||||
return arr.astype(np.float32)
|
||||
|
||||
@ -386,7 +389,8 @@ def xp_gaussian_filter(arr, sigma):
|
||||
if _cp is not None and isinstance(arr, _cp.ndarray):
|
||||
try:
|
||||
return _cp_ndimage.gaussian_filter(arr, sigma)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
logger.warning(f"Filtre gaussien GPU échoué ({e}) — repli CPU")
|
||||
arr = to_cpu(arr)
|
||||
return ndimage.gaussian_filter(arr, sigma)
|
||||
|
||||
@ -395,7 +399,8 @@ def xp_uniform_filter(arr, size):
|
||||
if _cp is not None and isinstance(arr, _cp.ndarray):
|
||||
try:
|
||||
return _cp_ndimage.uniform_filter(arr, size)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
logger.warning(f"Filtre uniform GPU échoué ({e}) — repli CPU")
|
||||
arr = to_cpu(arr)
|
||||
return ndimage.uniform_filter(arr, size)
|
||||
|
||||
@ -404,7 +409,8 @@ def xp_minimum_filter(arr, footprint=None, size=None):
|
||||
if _cp is not None and isinstance(arr, _cp.ndarray):
|
||||
try:
|
||||
return _cp_ndimage.minimum_filter(arr, footprint=footprint, size=size)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
logger.warning(f"Filtre minimum GPU échoué ({e}) — repli CPU")
|
||||
arr = to_cpu(arr)
|
||||
return ndimage.minimum_filter(arr, footprint=footprint, size=size)
|
||||
|
||||
@ -413,7 +419,8 @@ def xp_maximum_filter(arr, footprint=None, size=None):
|
||||
if _cp is not None and isinstance(arr, _cp.ndarray):
|
||||
try:
|
||||
return _cp_ndimage.maximum_filter(arr, footprint=footprint, size=size)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
logger.warning(f"Filtre maximum GPU échoué ({e}) — repli CPU")
|
||||
arr = to_cpu(arr)
|
||||
return ndimage.maximum_filter(arr, footprint=footprint, size=size)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user