Supprimer le code mort (imports inutilisés, variable _xp, conseil GPU inatteignable)
This commit is contained in:
@ -80,7 +80,6 @@ except Exception:
|
||||
# ---------------------------------------------------------------------------
|
||||
# Lazy CuPy initialization — tries each GPU until one works
|
||||
# ---------------------------------------------------------------------------
|
||||
_xp = np
|
||||
_cp = None
|
||||
_cp_ndimage = None
|
||||
_cupy_ndarray = None # type ref qui survit à disable_gpu() pour que to_cpu() récupère les tableaux orphelins
|
||||
@ -154,7 +153,7 @@ def _init_gpu():
|
||||
import CuPy directly (no subprocess test needed)
|
||||
3. Otherwise: test each GPU in a subprocess, pick the first that works
|
||||
"""
|
||||
global _xp, _cp, _cp_ndimage, _cupy_ndarray, _gpu_initialized, HAS_GPU, _best_gpu_id, _gpu_name, _gpu_mem_gb
|
||||
global _cp, _cp_ndimage, _cupy_ndarray, _gpu_initialized, HAS_GPU, _best_gpu_id, _gpu_name, _gpu_mem_gb
|
||||
if _gpu_initialized:
|
||||
return
|
||||
_gpu_initialized = True
|
||||
@ -165,7 +164,6 @@ def _init_gpu():
|
||||
candidates = _filter_candidates(_runtime_candidates())
|
||||
if not candidates:
|
||||
logger.info("Pas de GPU utilisable — mode CPU uniquement")
|
||||
_xp = np
|
||||
_cp = None
|
||||
_cp_ndimage = None
|
||||
HAS_GPU = False
|
||||
@ -191,14 +189,12 @@ def _init_gpu():
|
||||
_gpu_name = name
|
||||
_gpu_mem_gb = mem_mi // 1024
|
||||
HAS_GPU = True
|
||||
_xp = _real_cupy
|
||||
_cp = _real_cupy
|
||||
_cp_ndimage = _real_cupy_ndimage
|
||||
_cupy_ndarray = _real_cupy.ndarray
|
||||
return
|
||||
except Exception as e:
|
||||
logger.warning(f"GPU indisponible (CUDA_VISIBLE_DEVICES={cuda_visible}): {e}")
|
||||
_xp = np
|
||||
_cp = None
|
||||
_cp_ndimage = None
|
||||
HAS_GPU = False
|
||||
@ -230,7 +226,6 @@ def _init_gpu():
|
||||
|
||||
if _working_gpu is None:
|
||||
logger.info("Pas de GPU utilisable — mode CPU uniquement")
|
||||
_xp = np
|
||||
_cp = None
|
||||
_cp_ndimage = None
|
||||
HAS_GPU = False
|
||||
@ -248,7 +243,6 @@ def _init_gpu():
|
||||
_gpu_name = name
|
||||
_gpu_mem_gb = mem_mi // 1024
|
||||
HAS_GPU = True
|
||||
_xp = _real_cupy
|
||||
_cp = _real_cupy
|
||||
_cp_ndimage = _real_cupy_ndimage
|
||||
_cupy_ndarray = _real_cupy.ndarray
|
||||
@ -444,13 +438,12 @@ def disable_gpu():
|
||||
Libère le memory pool GPU avant de nuller les références (anti-fuite VRAM).
|
||||
Garde _cupy_ndarray vivant pour que to_cpu() récupère les tableaux orphelins.
|
||||
"""
|
||||
global HAS_GPU, _xp, _cp, _cp_ndimage
|
||||
global HAS_GPU, _cp, _cp_ndimage
|
||||
if not HAS_GPU:
|
||||
return
|
||||
logger.warning("GPU désactivé — passage en mode CPU pour la suite du processus")
|
||||
gpu_cleanup()
|
||||
HAS_GPU = False
|
||||
_xp = np
|
||||
_cp = None
|
||||
_cp_ndimage = None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user