linux 为什么torch.version.cuda和deviceQuery报告不同的版本?

yzuktlbb  于 5个月前  发布在  Linux
关注(0)|答案(2)|浏览(86)

我有一个关于CUDA版本安装在我的系统上,并被有效地使用我的软件的疑问.我做了一些研究,但无法找到一个解决我的疑问.这有助于我在我的理解有点问题,是最相关的是什么,我会问下面是this one.
问题描述:
我用virtualtumentwrapper创建了一个虚拟环境,然后在里面安装了pytorch。
一段时间后,我意识到我没有在我的系统上安装CUDA。
你可以通过做以下事情来找到答案:
第一个月
如果没有返回任何内容,则意味着您没有安装CUDA(据我所知)。
因此,我按照说明here
我用this官方链接安装了CUDA。
然后,我安装了nvidia-development-kit
sudo apt install nvidia-cuda-toolkit
现在,如果在我的虚拟环境中我这样做:
nvcc -V
我得到:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

字符串
然而,如果(总是在虚拟环境中)我这样做:
python -c "import torch; print(torch.version.cuda)"
我得到:
10.2

这是我不明白的第一件事。我在虚拟环境中使用的是哪个版本的CUDA?

然后,如果我运行示例deviceQuery(从cuda-samples文件夹-可以通过此链接安装示例),我会得到:

./deviceQuery 
./deviceQuery Starting...

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

Detected 1 CUDA Capable device(s)

Device 0: "NVIDIA GeForce RTX 2080 Super with Max-Q Design"
  CUDA Driver Version / Runtime Version          11.4 / 11.4
  CUDA Capability Major/Minor version number:    7.5
  Total amount of global memory:                 7974 MBytes (8361279488 bytes)
  (048) Multiprocessors, (064) CUDA Cores/MP:    3072 CUDA Cores
  GPU Max Clock rate:                            1080 MHz (1.08 GHz)
  Memory Clock rate:                             5501 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 shared memory per multiprocessor:        65536 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  1024
  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 3 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 Managed Memory:                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 = 11.4, CUDA Runtime Version = 11.4, NumDevs = 1
Result = PASS

为什么现在提到CUDA版本11.4?是不是因为我用的是NVIDIA_CUDA-11.4_Samples

另一个信息如下。如果我检查我的/usr/local文件夹,我会看到三个与CUDA相关的文件夹。
如果我这样做:
cd /usr/local && ll | grep -i CUDA
我得到:

lrwxrwxrwx  1 root root   22 Oct  7 11:33 cuda -> /etc/alternatives/cuda/
lrwxrwxrwx  1 root root   25 Oct  7 11:33 cuda-11 -> /etc/alternatives/cuda-11/
drwxr-xr-x 16 root root 4096 Oct  7 11:33 cuda-11.4/


这正常吗
谢谢你的帮忙。

f87krz0w

f87krz0w1#

PyTorch不使用系统的CUDA库。当您使用pip或conda使用预编译的二进制文件安装PyTorch时,它会附带一个本地安装在您的环境中的指定版本的CUDA库的副本。事实上,您甚至不需要在系统上安装CUDA就可以使用支持CUDA的PyTorch。

svdrlsy4

svdrlsy42#

torch.version.cuda只是定义为一个字符串。它不会查询任何东西。它不会告诉你安装了哪个版本的CUDA。它只会告诉你安装的PyTorch适用于那个(10.2)版本的CUDA。但你实际上在系统上运行的CUDA版本是11.4
如果你安装了PyTorch,比如说,

conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c nvidia

字符串
那么你也应该在Anaconda目录中有必要的库(cudatoolkit),它可能与你的系统级库不同。
但是,请注意,这些取决于NVIDIA显示驱动程序:


的数据
安装cudatoolkit不会安装驱动程序(nvidia.ko),您需要在系统上单独安装驱动程序。

相关问题