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

kal*_*ger -1 python linux cuda virtual-environment pytorch

我对我的系统上安装的 CUDA 版本以及是否被我的软件有效使用有疑问。\n我在网上做了一些研究,但找不到解决我的疑问的方法。\n这个问题对我的理解有所帮助,并且是与我下面要问的问题最相关的是这个

\n

问题描述:

\n

我使用 virtualenvironmentwrapper 创建了一个虚拟环境,然后在其中安装了 pytorch。

\n

一段时间后,我意识到我的系统上没有安装 CUDA。

\n

您可以通过执行以下操作找到它:
\nnvcc \xe2\x80\x93V

\n

如果没有返回任何内容,则意味着您没有安装 CUDA(据我了解)。

\n

因此,我按照这里的说明进行操作

\n

我用这个官方链接安装了CUDA。

\n

然后,我nvidia-development-kit简单地安装了

\n

sudo apt install nvidia-cuda-toolkit

\n

现在,如果在我的虚拟环境中我这样做:

\n

nvcc -V

\n

我得到:

\n
nvcc: NVIDIA (R) Cuda compiler driver\nCopyright (c) 2005-2019 NVIDIA Corporation\nBuilt on Sun_Jul_28_19:07:16_PDT_2019\nCuda compilation tools, release 10.1, V10.1.243\n
Run Code Online (Sandbox Code Playgroud)\n

但是,如果(总是在虚拟环境中)我这样做:

\n

python -c "import torch; print(torch.version.cuda)"

\n

我得到:

\n

10.2

\n

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

\n

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

\n
./deviceQuery \n./deviceQuery Starting...\n\n CUDA Device Query (Runtime API) version (CUDART static linking)\n\nDetected 1 CUDA Capable device(s)\n\nDevice 0: "NVIDIA GeForce RTX 2080 Super with Max-Q Design"\n  CUDA Driver Version / Runtime Version          11.4 / 11.4\n  CUDA Capability Major/Minor version number:    7.5\n  Total amount of global memory:                 7974 MBytes (8361279488 bytes)\n  (048) Multiprocessors, (064) CUDA Cores/MP:    3072 CUDA Cores\n  GPU Max Clock rate:                            1080 MHz (1.08 GHz)\n  Memory Clock rate:                             5501 Mhz\n  Memory Bus Width:                              256-bit\n  L2 Cache Size:                                 4194304 bytes\n  Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)\n  Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers\n  Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers\n  Total amount of constant memory:               65536 bytes\n  Total amount of shared memory per block:       49152 bytes\n  Total shared memory per multiprocessor:        65536 bytes\n  Total number of registers available per block: 65536\n  Warp size:                                     32\n  Maximum number of threads per multiprocessor:  1024\n  Maximum number of threads per block:           1024\n  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)\n  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)\n  Maximum memory pitch:                          2147483647 bytes\n  Texture alignment:                             512 bytes\n  Concurrent copy and kernel execution:          Yes with 3 copy engine(s)\n  Run time limit on kernels:                     Yes\n  Integrated GPU sharing Host Memory:            No\n  Support host page-locked memory mapping:       Yes\n  Alignment requirement for Surfaces:            Yes\n  Device has ECC support:                        Disabled\n  Device supports Unified Addressing (UVA):      Yes\n  Device supports Managed Memory:                Yes\n  Device supports Compute Preemption:            Yes\n  Supports Cooperative Kernel Launch:            Yes\n  Supports MultiDevice Co-op Kernel Launch:      Yes\n  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0\n  Compute Mode:\n     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >\n\ndeviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.4, CUDA Runtime Version = 11.4, NumDevs = 1\nResult = PASS\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n

另一个信息如下。如果我检查我的/usr/local文件夹,我会看到三个与 CUDA 相关的文件夹。

\n

如果我做:

\n

cd /usr/local && ll | grep -i CUDA

\n

我得到:

\n
lrwxrwxrwx  1 root root   22 Oct  7 11:33 cuda -> /etc/alternatives/cuda/\nlrwxrwxrwx  1 root root   25 Oct  7 11:33 cuda-11 -> /etc/alternatives/cuda-11/\ndrwxr-xr-x 16 root root 4096 Oct  7 11:33 cuda-11.4/\n
Run Code Online (Sandbox Code Playgroud)\n

这正常吗?

\n

感谢您的帮助。

\n

jod*_*dag 5

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