Pytorch未检测到GPU(RTX 4000)。

huangapple go评论71阅读模式
英文:

Pytorch not detecting GPU (RTX 4000

问题

我使用Linux Mint 21.1,并且从https://developer.nvidia.com/cuda-downloads下载并安装了cuda_12.2.1_535.86.10_linux.run。

在安装cuda后,我尝试运行/usr/local/cuda/extras/demo_suite/deviceQuery并得到以下结果:

/usr/local/cuda/extras/demo_suite/deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "NVIDIA RTX A4000"
  CUDA Driver Version / Runtime Version          12.2 / 12.2
  CUDA Capability Major/Minor version number:    8.6
  Total amount of global memory:                 16101 MBytes (16882663424 bytes)
  (48) Multiprocessors, (128) CUDA Cores/MP:     6144 CUDA Cores
  GPU Max Clock rate:                            1560 MHz (1.56 GHz)
  Memory Clock rate:                             7001 Mhz
  Memory Bus Width:                              256-bit
  L2 Cache Size:                                 4194304 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
  Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  1536
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device supports Compute Preemption:            Yes
  Supports Cooperative Kernel Launch:            Yes
  Supports MultiDevice Co-op Kernel Launch:      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 12.2, CUDA Runtime Version = 12.2, NumDevs = 1, Device0 = NVIDIA RTX A4000
Result = PASS

所以,我理解cuda安装(驱动程序等)是正常的!

在此之后,我安装了Anaconda3-2023.07-1-Linux-x86_64。但在安装后,我尝试安装pytorch:

$ conda install pytorch torchvision cudatoolkit -c pytorch

但在安装pytorch后,当我尝试获取可用的GPU时出现问题:

$ python3 -c "import torch; print(torch.cuda.is_available())"
False

现在我不知所措,因为cuda安装似乎没有问题。

经过一些思考,我尝试运行以下代码:

import torch
print(torch.cuda.current_device())     # 当前GPU的ID。
print(torch.cuda.get_device_name(0))  # 指定GPU的名称,其中id是整数。
print(torch.cuda.device(0))           # 指定GPU的内存地址,其中id是整数。
print(torch.cuda.device_count())

我得到了以下错误:

Traceback (most recent call last):
  File "/home/iaciber2/test_pytorch.py", line 2, in <module>
    print( torch.cuda.current_device())     # 当前GPU的ID。
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/iaciber2/anaconda3/envs/dl_pytorch/lib/python3.11/site-packages/torch/cuda/__init__.py", line 674, in current_device
    _lazy_init()
  File "/home/iaciber2/anaconda3/envs/dl_pytorch/lib/python3.11/site-packages/torch/cuda/__init__.py", line 239, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

有什么想法?

英文:

I am using Linux Mint 21.1 and I've download and installed cuda_12.2.1_535.86.10_linux.run from https://developer.nvidia.com/cuda-downloads.

After cuda installation, I tried to run /usr/local/cuda/extras/demo_suite/deviceQuery and got the following:

/usr/local/cuda/extras/demo_suite/deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: &quot;NVIDIA RTX A4000&quot;
  CUDA Driver Version / Runtime Version          12.2 / 12.2
  CUDA Capability Major/Minor version number:    8.6
  Total amount of global memory:                 16101 MBytes (16882663424 bytes)
  (48) Multiprocessors, (128) CUDA Cores/MP:     6144 CUDA Cores
  GPU Max Clock rate:                            1560 MHz (1.56 GHz)
  Memory Clock rate:                             7001 Mhz
  Memory Bus Width:                              256-bit
  L2 Cache Size:                                 4194304 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
  Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  1536
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device supports Compute Preemption:            Yes
  Supports Cooperative Kernel Launch:            Yes
  Supports MultiDevice Co-op Kernel Launch:      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
  Compute Mode:
     &lt; Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) &gt;

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 12.2, CUDA Runtime Version = 12.2, NumDevs = 1, Device0 = NVIDIA RTX A4000
Result = PASS

So, I understand the cuda installation (drivers, etc) is ok!

After this, I've installed Anaconda3-2023.07-1-Linux-x86_64. But after installantion, I tried to install pytorch:

$ conda install pytorch torchvision cudatoolkit -c pytorch

but after pytorch installation I am having problems when trying to get the available gpus:

$ python3 -c &quot;import torch; print(torch.cuda.is_available())&quot;
False

Now I get nowhere, since cuda installation seems alrigh.

After some thinking. I tried to run the following code:

import torch
print( torch.cuda.current_device())     # The ID of the current GPU.
print(torch.cuda.get_device_name(0))  # The name of the specified GPU, where id is an integer.
print(torch.cuda.device(0))           # The memory address of the specified GPU, where id is an integer.
print(torch.cuda.device_count())

and I got

Traceback (most recent call last):
  File &quot;/home/iaciber2/test_pytorch.py&quot;, line 2, in &lt;module&gt;
    print( torch.cuda.current_device())     # The ID of the current GPU.
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File &quot;/home/iaciber2/anaconda3/envs/dl_pytorch/lib/python3.11/site-packages/torch/cuda/__init__.py&quot;, line 674, in current_device
    _lazy_init()
  File &quot;/home/iaciber2/anaconda3/envs/dl_pytorch/lib/python3.11/site-packages/torch/cuda/__init__.py&quot;, line 239, in _lazy_init
    raise AssertionError(&quot;Torch not compiled with CUDA enabled&quot;)
AssertionError: Torch not compiled with CUDA enabled

Any ideas ?

答案1

得分: 1

after all, I found out that a cpu version of pytorch have been installed.

Using:
import torch

print(torch.version.cuda)

I got "None", so the installed pytorch did not support GPU.

So, to force an GPU support installation:

$ conda install  pytorch=2.0.1=py3.11_cuda11.8_cudnn8.7.0_0 torchvision torchaudio pytorch-cuda=11.8 cudatoolkit -c pytorch -c nvidia

Thats all

英文:

after all, I found out that a cpu version of pytorch have been installed.

Using:
import torch

print(torch.version.cuda)

I got "None", so the installed pytorch did not support GPU.

So, to force an gpu support installation :

$ conda install  pytorch=2.0.1=py3.11_cuda11.8_cudnn8.7.0_0 torchvision torchaudio pytorch-cuda=11.8 cudatoolkit -c pytorch -c nvidia

Thats all

huangapple
  • 本文由 发表于 2023年8月4日 02:08:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76830638.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定