Pytorch未检测到GPU(RTX 4000)。

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

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并得到以下结果:

  1. /usr/local/cuda/extras/demo_suite/deviceQuery Starting...
  2. CUDA Device Query (Runtime API) version (CUDART static linking)
  3. Detected 1 CUDA Capable device(s)
  4. Device 0: "NVIDIA RTX A4000"
  5. CUDA Driver Version / Runtime Version 12.2 / 12.2
  6. CUDA Capability Major/Minor version number: 8.6
  7. Total amount of global memory: 16101 MBytes (16882663424 bytes)
  8. (48) Multiprocessors, (128) CUDA Cores/MP: 6144 CUDA Cores
  9. GPU Max Clock rate: 1560 MHz (1.56 GHz)
  10. Memory Clock rate: 7001 Mhz
  11. Memory Bus Width: 256-bit
  12. L2 Cache Size: 4194304 bytes
  13. Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
  14. Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
  15. Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
  16. Total amount of constant memory: 65536 bytes
  17. Total amount of shared memory per block: 49152 bytes
  18. Total number of registers available per block: 65536
  19. Warp size: 32
  20. Maximum number of threads per multiprocessor: 1536
  21. Maximum number of threads per block: 1024
  22. Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  23. Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
  24. Maximum memory pitch: 2147483647 bytes
  25. Texture alignment: 512 bytes
  26. Concurrent copy and kernel execution: Yes with 2 copy engine(s)
  27. Run time limit on kernels: Yes
  28. Integrated GPU sharing Host Memory: No
  29. Support host page-locked memory mapping: Yes
  30. Alignment requirement for Surfaces: Yes
  31. Device has ECC support: Disabled
  32. Device supports Unified Addressing (UVA): Yes
  33. Device supports Compute Preemption: Yes
  34. Supports Cooperative Kernel Launch: Yes
  35. Supports MultiDevice Co-op Kernel Launch: Yes
  36. Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0
  37. Compute Mode:
  38. < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
  39. deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 12.2, CUDA Runtime Version = 12.2, NumDevs = 1, Device0 = NVIDIA RTX A4000
  40. Result = PASS

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

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

  1. $ conda install pytorch torchvision cudatoolkit -c pytorch

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

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

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

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

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

我得到了以下错误:

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

  1. /usr/local/cuda/extras/demo_suite/deviceQuery Starting...
  2. CUDA Device Query (Runtime API) version (CUDART static linking)
  3. Detected 1 CUDA Capable device(s)
  4. Device 0: &quot;NVIDIA RTX A4000&quot;
  5. CUDA Driver Version / Runtime Version 12.2 / 12.2
  6. CUDA Capability Major/Minor version number: 8.6
  7. Total amount of global memory: 16101 MBytes (16882663424 bytes)
  8. (48) Multiprocessors, (128) CUDA Cores/MP: 6144 CUDA Cores
  9. GPU Max Clock rate: 1560 MHz (1.56 GHz)
  10. Memory Clock rate: 7001 Mhz
  11. Memory Bus Width: 256-bit
  12. L2 Cache Size: 4194304 bytes
  13. Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
  14. Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
  15. Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
  16. Total amount of constant memory: 65536 bytes
  17. Total amount of shared memory per block: 49152 bytes
  18. Total number of registers available per block: 65536
  19. Warp size: 32
  20. Maximum number of threads per multiprocessor: 1536
  21. Maximum number of threads per block: 1024
  22. Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  23. Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
  24. Maximum memory pitch: 2147483647 bytes
  25. Texture alignment: 512 bytes
  26. Concurrent copy and kernel execution: Yes with 2 copy engine(s)
  27. Run time limit on kernels: Yes
  28. Integrated GPU sharing Host Memory: No
  29. Support host page-locked memory mapping: Yes
  30. Alignment requirement for Surfaces: Yes
  31. Device has ECC support: Disabled
  32. Device supports Unified Addressing (UVA): Yes
  33. Device supports Compute Preemption: Yes
  34. Supports Cooperative Kernel Launch: Yes
  35. Supports MultiDevice Co-op Kernel Launch: Yes
  36. Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0
  37. Compute Mode:
  38. &lt; Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) &gt;
  39. deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 12.2, CUDA Runtime Version = 12.2, NumDevs = 1, Device0 = NVIDIA RTX A4000
  40. 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:

  1. $ conda install pytorch torchvision cudatoolkit -c pytorch

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

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

Now I get nowhere, since cuda installation seems alrigh.

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

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

and I got

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

  1. $ 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 :

  1. $ 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:

确定