niulx commited on
Commit
46d6254
1 Parent(s): 9a3725e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -28
main.py CHANGED
@@ -29,40 +29,27 @@ for i in range(device_count):
29
 
30
  import os
31
 
32
- nvidia_devices = [dev for dev in os.listdir('/dev') if dev.startswith('nvidia')]
33
- print("NVIDIA 设备文件:", nvidia_devices)
34
- for dev in nvidia_devices:
35
- path = os.path.join('/dev', dev)
36
- print(f"设备 {path} 的权限:", oct(os.stat(path).st_mode))
37
- import ctypes
38
-
39
- try:
40
- ctypes.CDLL('libcuda.so')
41
- print("CUDA 库已加载。")
42
- except Exception as e:
43
- print("无法加载 CUDA 库,错误信息:", e)
44
-
45
- import os
46
-
47
- cuda_visible_devices = os.environ.get('CUDA_VISIBLE_DEVICES', '未设置')
48
- print("CUDA_VISIBLE_DEVICES:", cuda_visible_devices)
49
-
50
  try:
51
- torch.cuda.init()
52
- x = torch.tensor([1.0], device='cuda')
53
- print("CUDA 张量创建成功:", x)
54
  except Exception as e:
55
- print("无法在 CUDA 上创建张量,错误信息:", e)
56
 
57
- import subprocess
58
 
59
- # 查看 GPU 信息
 
 
60
  try:
61
- result = subprocess.run(['lspci'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
62
- gpu_info = [line for line in result.stdout.decode().split('\n') if 'NVIDIA' in line]
63
- print("GPU 信息:", gpu_info)
64
  except Exception as e:
65
- print("无法获取 GPU 信息,错误信息:", e)
 
 
 
 
 
66
 
67
 
68
  def run_main(
 
29
 
30
  import os
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  try:
33
+ ctypes.CDLL('libnvidia-ml.so')
34
+ print("成功加载 libnvidia-ml.so。")
 
35
  except Exception as e:
36
+ print("无法加载 libnvidia-ml.so,错误信息:", e)
37
 
38
+ import glob
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(