我对我的系统上安装的 CUDA 版本以及我的软件是否有效使用有疑问。 我在网上做了一些研究,但找不到解决我的疑问的方法。 对我的理解有一点帮助并且与我下面要问的问题最相关的问题是这个。
问题描述:
我使用 virtualenvironmentwrapper 创建了一个虚拟环境,然后在其中安装了 pytorch。
过了一段时间,我意识到我的系统上没有安装 CUDA。
您可以通过执行以下操作找到它:
nvcc –V
如果没有返回任何内容,则意味着您没有安装 CUDA(据我了解)。
因此,我按照此处
的说明进行操作我用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/
这正常吗?
感谢您的帮助。
PyTorch 不使用系统的 CUDA 库。当您使用 pip 或 conda 使用预编译的二进制文件安装 PyTorch 时,它会附带在您的环境中本地安装的指定版本的 CUDA 库的副本。事实上,您甚至不需要在系统上安装 CUDA 即可使用支持 CUDA 的 PyTorch。
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
),您需要在系统上单独安装驱动程序。
当我安装lib,Detectron2时,它会检查cuda的版本(torch.version.cuda和安装的cuda for real(nvcc --version)一致吗?),如果torch.version.cuda没有意义,为什么它检查版本是否一致?遗憾的是,我无法召集所有人到会议室讨论这个问题。