niulx commited on
Commit
1fc2c69
1 Parent(s): 70431aa

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +23 -30
main.py CHANGED
@@ -9,47 +9,40 @@ from utils import load_image, load_mask, load_mask_edit
9
  from utils_mask import process_mask_move_torch, process_mask_remove_torch, mask_union_torch, mask_substract_torch, create_outer_edge_mask_torch
10
  from utils_mask import check_mask_overlap_torch, check_cover_all_torch, visualize_mask_list, get_mask_difference_torch, save_mask_list_to_npys
11
 
12
- print("PyTorch 版本:", torch.__version__)
13
- print("CUDA 版本:", torch.version.cuda)
14
- print("CUDA 是否可用:", torch.cuda.is_available())
15
- import subprocess
16
-
17
- # 检查 nvidia-smi 命令的输出
18
- try:
19
- result = subprocess.run(['nvidia-smi'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
20
- print(result.stdout.decode())
21
- except FileNotFoundError:
22
- print("nvidia-smi 命令不可用,可能未安装 NVIDIA 驱动。")
23
-
24
- device_count = torch.cuda.device_count()
25
- print("可用的 CUDA 设备数量:", device_count)
26
- for i in range(device_count):
27
- print(f"设备 {i} 名称:", torch.cuda.get_device_name(i))
28
-
29
 
30
  import os
31
-
32
- import glob
33
  import ctypes
 
 
 
 
 
 
 
 
34
  try:
35
  ctypes.CDLL('libnvidia-ml.so')
36
  print("成功加载 libnvidia-ml.so。")
37
  except Exception as e:
38
  print("无法加载 libnvidia-ml.so,错误信息:", e)
39
 
40
- libs = glob.glob('/usr/lib*/**/libnvidia-*.so*', recursive=True)
41
- print("NVIDIA 驱动库文件:", libs)
42
- print("LD_LIBRARY_PATH:", os.environ.get('LD_LIBRARY_PATH', '未设置'))
 
 
 
 
 
 
 
 
 
43
  try:
44
- with open('/proc/driver/nvidia/version') as f:
45
- print(f.read())
46
  except Exception as e:
47
- print("无法读取驱动程序版本信息,错误信息:", e)
48
- print("PyTorch 安装路径:", torch.__file__)
49
- cuda_paths = [path for path in os.listdir('/usr/local') if path.startswith('cuda')]
50
- print("CUDA 安装路径:", cuda_paths)
51
- print("PyTorch CUDA 版本:", torch.version.cuda)
52
- print("系统 CUDA 版本:", os.environ.get('CUDA_VERSION', '未设置'))
53
 
54
 
55
  def run_main(
 
9
  from utils_mask import process_mask_move_torch, process_mask_remove_torch, mask_union_torch, mask_substract_torch, create_outer_edge_mask_torch
10
  from utils_mask import check_mask_overlap_torch, check_cover_all_torch, visualize_mask_list, get_mask_difference_torch, save_mask_list_to_npys
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  import os
 
 
14
  import ctypes
15
+ import torch
16
+
17
+ # 设置 LD_LIBRARY_PATH
18
+ nvidia_lib_path = '/usr/lib/x86_64-linux-gnu'
19
+ os.environ['LD_LIBRARY_PATH'] = nvidia_lib_path + ':' + os.environ.get('LD_LIBRARY_PATH', '')
20
+ print("LD_LIBRARY_PATH 已设置为:", os.environ['LD_LIBRARY_PATH'])
21
+
22
+ # 尝试加载 libnvidia-ml.so
23
  try:
24
  ctypes.CDLL('libnvidia-ml.so')
25
  print("成功加载 libnvidia-ml.so。")
26
  except Exception as e:
27
  print("无法加载 libnvidia-ml.so,错误信息:", e)
28
 
29
+ # 尝试加载 libcuda.so
30
+ try:
31
+ ctypes.CDLL('libcuda.so')
32
+ print("成功加载 libcuda.so。")
33
+ except Exception as e:
34
+ print("无法加载 libcuda.so,错误信息:", e)
35
+
36
+ # 检查 CUDA 是否可用
37
+ print("CUDA 是否可用:", torch.cuda.is_available())
38
+ print("可用的 CUDA 设备数量:", torch.cuda.device_count())
39
+
40
+ # 尝试在 CUDA 上创建张量
41
  try:
42
+ x = torch.tensor([1.0], device='cuda')
43
+ print("CUDA 张量创建成功:", x)
44
  except Exception as e:
45
+ print("无法在 CUDA 上创建张量,错误信息:", e)
 
 
 
 
 
46
 
47
 
48
  def run_main(