查看“︁Linux/nvidia”︁的源代码
来自康健生活
←
Linux/nvidia
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 引言 == 查看计算机的显卡。 {{Shc_out|<syntaxhighlight lang="bash"> lspci | grep -i vga # or lspci | egrep 'VGA|3D'</syntaxhighlight>|<syntaxhighlight lang="bash"> 00:02.0 VGA compatible controller: Intel Corporation UHD Graphics (rev 05) 01:00.0 VGA compatible controller: NVIDIA Corporation TU106 [GeForce RTX 2060] (rev a1) </syntaxhighlight>|$|/home/kangkk}} 检查已经安装的 nvidia 驱动。 {{Shc_out|<syntaxhighlight lang="bash"> nvidia-detector</syntaxhighlight>|<syntaxhighlight lang="bash"> nvidia-driver-495 </syntaxhighlight>|$|/home/kangkk}} == 卸载 == 卸载所有已安装的 nvidia 驱动以及 cuda 相关文件。 {{shc|<syntaxhighlight lang="bash"> sudo apt remove --purge nvidia* sudo apt remove --purge cuda* sudo rm -rf cuda*</syntaxhighlight>|$|/home/kangkk}} == 安装 == 输入 <code>ubuntu-drivers</code> 命令进行查看 ubuntu 系统推荐的驱动。 {{Shc_out|<syntaxhighlight lang="bash"> ubuntu-drivers devices</syntaxhighlight>|<syntaxhighlight lang="bash">== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 == modalias : pci:v000010DEd00001F15sv00001043sd00001C6Fbc03sc00i00 vendor : NVIDIA Corporation driver : nvidia-driver-455 - third-party non-free driver : nvidia-driver-465 - third-party non-free driver : nvidia-driver-495 - third-party non-free recommended driver : nvidia-driver-470 - third-party non-free driver : nvidia-driver-450-server - distro non-free driver : nvidia-driver-460 - third-party non-free driver : nvidia-driver-460-server - distro non-free driver : nvidia-driver-450 - third-party non-free driver : nvidia-driver-470-server - distro non-free driver : xserver-xorg-video-nouveau - distro free builtin </syntaxhighlight>|$|/home/kangkk}} 进行驱动安装。 {{shc|<syntaxhighlight lang="bash"> sudo apt install nvidia-driver-495</syntaxhighlight>|$|/home/kangkk}} == nvidia-smi == 输入 nvidia-smi 命令查看支持的 cuda 版本。 {{Shc_out|<syntaxhighlight lang="bash"> nvidia-smi</syntaxhighlight>|<syntaxhighlight lang="bash">Sun Nov 7 17:33:37 2021 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 495.29.05 Driver Version: 495.29.05 CUDA Version: 11.5 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |===============================+======================+======================| | 0 NVIDIA GeForce ... On | 00000000:01:00.0 Off | N/A | | N/A 35C P8 5W / N/A | 362MiB / 5934MiB | 7% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | 0 N/A N/A 1195 G /usr/lib/xorg/Xorg 45MiB | | 0 N/A N/A 1710 G /usr/lib/xorg/Xorg 112MiB | | 0 N/A N/A 1886 G /usr/bin/gnome-shell 74MiB | | 0 N/A N/A 2962 G ...AAAAAAAAA= --shared-files 119MiB | +-----------------------------------------------------------------------------+ </syntaxhighlight>|$|/home/kangkk}} == CUDA == [https://developer.nvidia.com/cuda-toolkit-archive 官网]下载,按照步骤安装即可。 [[文件:安装cuda步骤示意图.png|500px|无框|无|安装cuda步骤示意图]] === 检查 === 验证 GPU 是否支持 CUDA。 {{Shc_out|<syntaxhighlight lang="bash"> lspci | grep -i nvidia </syntaxhighlight>|<syntaxhighlight lang="bash"> 01:00.0 VGA compatible controller: NVIDIA Corporation TU106 [GeForce RTX 2060] (rev a1) 01:00.1 Audio device: NVIDIA Corporation TU106 High Definition Audio Controller (rev a1) 01:00.2 USB controller: NVIDIA Corporation TU106 USB 3.1 Host Controller (rev a1) 01:00.3 Serial bus controller [0c80]: NVIDIA Corporation TU106 USB Type-C UCSI Controller (rev a1) </syntaxhighlight>|$|/home/kangkk}} 检查显卡是否在 [https://developer.nvidia.com/cuda-gpus cuda-gpus] 列表中。 查询 CUDA 的版本。 {{Shc_out|<syntaxhighlight lang="bash"> cat /usr/local/cuda/version.json</syntaxhighlight>|<syntaxhighlight lang="bash"> { "cuda" : { "name" : "CUDA SDK", "version" : "11.5.1" }, "cuda_cudart" : { "name" : "CUDA Runtime (cudart)", "version" : "11.5.117" }, ... </syntaxhighlight>|$|/home/kangkk}} 测试 CUDA。 {{Shc_out|<syntaxhighlight lang="bash"> cd /usr/local/cuda/samples/1_Utilities/deviceQuery sudo make</syntaxhighlight>|<syntaxhighlight lang="bash"> /usr/local/cuda-11.5/bin/nvcc -ccbin g++ -I../../common/inc -m64 --threads 0 --std=c++11 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_80,code=sm_80 -gencode arch=compute_86,code=sm_86 -gencode arch=compute_86,code=compute_86 -o deviceQuery.o -c deviceQuery.cpp nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning). /usr/local/cuda-11.5/bin/nvcc -ccbin g++ -m64 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_80,code=sm_80 -gencode arch=compute_86,code=sm_86 -gencode arch=compute_86,code=compute_86 -o deviceQuery deviceQuery.o nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning). mkdir -p ../../bin/x86_64/linux/release cp deviceQuery ../../bin/x86_64/linux/release </syntaxhighlight>|$|/home/kangkk}} 编译完成之后,执行生成的 <code>deviceQuery</code> 程序。 {{Shc_out|<syntaxhighlight lang="bash"> sudo /usr/local/cuda/samples/1_Utilities/deviceQuery/deviceQuery</syntaxhighlight>|<syntaxhighlight lang="bash"> /usr/local/cuda/samples/1_Utilities/deviceQuery/deviceQuery Starting... CUDA Device Query (Runtime API) version (CUDART static linking) Detected 1 CUDA Capable device(s) Device 0: "NVIDIA GeForce RTX 2060" CUDA Driver Version / Runtime Version 11.5 / 11.5 CUDA Capability Major/Minor version number: 7.5 Total amount of global memory: 5935 MBytes (6222839808 bytes) (030) Multiprocessors, (064) CUDA Cores/MP: 1920 CUDA Cores GPU Max Clock rate: 1560 MHz (1.56 GHz) Memory Clock rate: 5501 Mhz Memory Bus Width: 192-bit L2 Cache Size: 3145728 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.5, CUDA Runtime Version = 11.5, NumDevs = 1 Result = PASS </syntaxhighlight>|$|/home/kangkk}} === run === 下载并进行安装。 {{shc|<syntaxhighlight lang="bash"> sudo sh cuda_*_linux.run</syntaxhighlight>|$|/home/kangkk}} 安装完成之后,使用 <code>nvcc</code> 命令,提示 <code>sudo apt-get install nvidia-cuda-toolkit</code>,这个时候不确定是否安装成功,需要到 <code>/usr/local/cuda</code> 文件夹下面检查 cuda 目录下的 <code>bin</code> 文件夹中是否存在 <code>nvcc</code>。 确定存在之后,在 <code>.bashrc</code> 文件中加入 nvcc 的环境变量 {{Hc|~/.bashrc|<pre> export PATH=/usr/local/cuda/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH </pre>}} <div class="pageBoxGreen"> # LIBRARY_PATH: 程序编译期间(开发阶段,如 gcc 编译)。 # LD_LIBRARY_PATH: 程序加载运行期间。</div> {{shc|<syntaxhighlight lang="bash"> source ~/.bashrc</syntaxhighlight>|$|/home/kangkk}} === nvidia-cuda-toolkit === 多种安装方式,最简单的如下,但是版本滞后,不建议。 {{shc|<syntaxhighlight lang="bash"> sudo apt install nvidia-cuda-toolkit -y</syntaxhighlight>|$|/home/kangkk}} === nvcc === NVIDIA (R) Cuda compiler driver(CUDA-C 和 CUDA-C++ 编译器)。 验证版本信息。 {{Shc_out|<syntaxhighlight lang="bash"> nvcc -V</syntaxhighlight>|<syntaxhighlight lang="bash">nvcc: NVIDIA (R) Cuda compiler driver nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2021 NVIDIA Corporation Built on Thu_Nov_18_09:45:30_PST_2021 Cuda compilation tools, release 11.5, V11.5.119 Build cuda_11.5.r11.5/compiler.30672275_0 </syntaxhighlight>|$|/home/kangkk}} == cuDNN == [https://developer.nvidia.com/rdp/cudnn-archive CUDNN] 是基于 CUDA 的深度学习 GPU 加速库(扩展计算库),是深度神经网络的必备库。 === 插入式安装 === 只需要解压后,将 CUDNN 文件复制到 CUDA 的对应文件夹。 {{shc|<syntaxhighlight lang="bash"> sudo cp cuda/include/cudnn*.h /usr/local/cuda/include sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn* </syntaxhighlight>|$|/home/kangkk}} 验证安装是否成功。 {{Shc_out|<syntaxhighlight lang="bash"> Insert comment here </syntaxhighlight>|<syntaxhighlight lang="bash"> </syntaxhighlight>|$|/home/kangkk}} == other == === cuda 与 nvcc 版本不一致问题 === 刚接触 cuda 的时候,我使用 <code>sudo apt install nvidia-driver-495</code> 安装 nvidia 驱动,同时又使用 <code>sudo apt install nvidia-cuda-toolkit -y</code> 安装 nvcc,导致版本 cuda 与 nvcc 版本不一致,cuda 版本是 <code>11.5</code>,而 nvcc 版本是 <code>9.5</code>。
此页面嵌入的页面:
模板:Hc
(
查看源代码
)
模板:Hc/style.css
(
查看源代码
)
模板:Shc
(
查看源代码
)
模板:Shc/style.css
(
查看源代码
)
模板:Shc out
(
查看源代码
)
模板:Shc out/style.css
(
查看源代码
)
返回
Linux/nvidia
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。