Spaces:
Running
Running
File size: 1,333 Bytes
f8f5549 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import os
import tensorflow as tf
# --- THE WORKAROUND ---
# Define the full path to the CUDA bin directory
cuda_bin_path = r"E:\Nvidia\CUDA\v11.2\bin"
# Add this path to the OS environment's DLL search path
# This MUST be done BEFORE importing tensorflow
try:
os.add_dll_directory(cuda_bin_path)
print(f"Successfully added {cuda_bin_path} to DLL search path.")
except AttributeError:
# This function was added in Python 3.8. For older versions, you might need
# to add the path to the system PATH environment variable manually.
print("os.add_dll_directory not available. Ensure CUDA bin is in the system PATH.")
# --- END WORKAROUND ---
print(f"TensorFlow Version: {tf.__version__}")
print("-" * 30)
# Check for GPU devices
gpu_devices = tf.config.list_physical_devices('GPU')
print(f"Num GPUs Available: {len(gpu_devices)}")
print("-" * 30)
if gpu_devices:
print("GPU Device Details:")
for gpu in gpu_devices:
tf.config.experimental.set_memory_growth(gpu, True)
print(f"- {gpu.name}, Type: {gpu.device_type}")
print("\nSUCCESS: TensorFlow is configured to use the GPU!")
else:
print("\nFAILURE: TensorFlow did not detect a GPU.")
import tensorflow as tf
from tensorflow.python.client import device_lib
print("Verbose device list:")
print(device_lib.list_local_devices()) |