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)
|
||||
|
||||
|
||||
@ -460,7 +460,8 @@ def generate_hillshade(dem_file, basename, vis_dir, resolution, shared=None):
|
||||
if shared:
|
||||
transform = shared.transform
|
||||
crs = shared.crs
|
||||
dem = to_gpu(shared.dem_np)
|
||||
# Pas de copie GPU du DEM brut ici : seuls gradient/pente/aspect
|
||||
# servent (déjà partagés) — ~100 Mo de VRAM économisés par dalle
|
||||
dy = to_gpu(shared.dy) if _gpu_mod.HAS_GPU else shared.dy
|
||||
dx = to_gpu(shared.dx) if _gpu_mod.HAS_GPU else shared.dx
|
||||
slope = to_gpu(shared.slope_rad) if _gpu_mod.HAS_GPU else shared.slope_rad
|
||||
|
||||
Reference in New Issue
Block a user