import tensorflow as tf def init_gpu(): """ Verifies Nvidia GPU presence, configures virtual memory limits, and handles dynamic memory growth to maximize processing performance. """ gpus = tf.config.list_physical_devices('GPU') if gpus: print(f"✅ Nvidia GPU Detected: {gpus}") try: for gpu in gpus: # Set memory growth so TensorFlow only allocates GPU VRAM as needed, # rather than aggressively pre-allocating 100% of it up front. tf.config.experimental.set_memory_growth(gpu, True) print("🚀 GPU Dynamic Memory Growth successfully initialized.") except RuntimeError as e: print(f"❌ Error setting GPU memory growth config: {e}") else: print("⚠️ GPU not detected by TensorFlow. Defaulting engine to host CPU execution.")