英文:
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: "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
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 "import torch; print(torch.cuda.is_available())"
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 "/home/iaciber2/test_pytorch.py", line 2, in <module>
print( torch.cuda.current_device()) # The ID of the current GPU.
^^^^^^^^^^^^^^^^^^^^^^^^^^^
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
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论