Alessio Grancini commited on
Commit
512f124
Β·
verified Β·
1 Parent(s): f796a73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -23
app.py CHANGED
@@ -13,32 +13,29 @@ from point_cloud_generator import display_pcd
13
 
14
 
15
 
 
16
  import subprocess
 
 
 
 
17
 
18
- # Check if CUDA is available
19
- def check_gpu():
20
- try:
21
- # Run nvidia-smi to check for GPU
22
- gpu_check = subprocess.run(["nvidia-smi"], capture_output=True, text=True)
23
- if "NVIDIA-SMI" in gpu_check.stdout:
24
- print("βœ… GPU is available!")
25
- return True
26
- else:
27
- print("❌ No GPU detected!")
28
- return False
29
- except FileNotFoundError:
30
- print("❌ No nvidia-smi found! GPU likely unavailable.")
31
- return False
32
-
33
- # Set device based on GPU availability
34
- if check_gpu() and torch.cuda.is_available():
35
- print(f"βœ… CUDA available: {torch.cuda.get_device_name(0)}")
36
- device = torch.device("cuda")
37
- torch.cuda.empty_cache()
38
  else:
39
- print("❌ No CUDA available. Falling back to CPU.")
40
- os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
41
- device = torch.device("cpu")
 
 
 
 
 
 
 
 
 
42
 
43
 
44
 
 
13
 
14
 
15
 
16
+ import torch
17
  import subprocess
18
+ import os
19
+
20
+ # Check if CUDA is available in PyTorch
21
+ print(f"πŸš€ PyTorch CUDA Available: {torch.cuda.is_available()}")
22
 
23
+ # Check available CUDA devices
24
+ if torch.cuda.is_available():
25
+ print(f"βœ… GPU detected: {torch.cuda.get_device_name(0)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  else:
27
+ print("❌ No GPU detected by PyTorch!")
28
+
29
+ # Check `nvidia-smi` output (if NVIDIA GPU is assigned)
30
+ try:
31
+ gpu_check = subprocess.run(["nvidia-smi"], capture_output=True, text=True)
32
+ print(f"πŸ–₯️ nvidia-smi output:\n{gpu_check.stdout}")
33
+ except FileNotFoundError:
34
+ print("❌ nvidia-smi not found! GPU might not be assigned.")
35
+
36
+ # Check if Hugging Face assigned a GPU
37
+ hf_gpu_env = os.getenv("CUDA_VISIBLE_DEVICES")
38
+ print(f"πŸ” Hugging Face CUDA_VISIBLE_DEVICES: {hf_gpu_env}")
39
 
40
 
41