Linux/nvidia:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
 
(未显示同一用户的20个中间版本)
第2行: 第2行:
查看计算机的显卡。
查看计算机的显卡。
{{Shc_out|<syntaxhighlight lang="bash">
{{Shc_out|<syntaxhighlight lang="bash">
lspci | grep -i vga</syntaxhighlight>|<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)
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)
01:00.0 VGA compatible controller: NVIDIA Corporation TU106 [GeForce RTX 2060] (rev a1)
</syntaxhighlight>|$|/home/kangkk}}
</syntaxhighlight>|$|/home/kangkk}}


== ubuntu-drivers ==
检查已经安装的 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 系统推荐的驱动。
输入 <code>ubuntu-drivers</code> 命令进行查看 ubuntu 系统推荐的驱动。
{{Shc_out|<syntaxhighlight lang="bash">
{{Shc_out|<syntaxhighlight lang="bash">
第61行: 第75行:
[[文件:安装cuda步骤示意图.png|500px|无框|无|安装cuda步骤示意图]]
[[文件:安装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 的版本。
查询 CUDA 的版本。
{{Shc_out|<syntaxhighlight lang="bash">
{{Shc_out|<syntaxhighlight lang="bash">
第147行: 第173行:
安装完成之后,使用 <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>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 的环境变量
确定存在之后,在 <code>.bashrc</code> 文件中加入 nvcc 的环境变量
{{Hc|~/bashrc|<pre>
{{Hc|~/.bashrc|<pre>
export PATH=/usr/local/cuda-11.5/bin:$PATH
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-15.5/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
</pre>}}
</pre>}}
<div class="pageBoxGreen">对应的环境变量。
# LIBRARY_PATH: 程序编译期间(开发阶段,如 gcc 编译)。
# LD_LIBRARY_PATH: 程序加载运行期间。</div>


{{shc|<syntaxhighlight lang="bash">
{{shc|<syntaxhighlight lang="bash">
第157行: 第187行:


=== nvidia-cuda-toolkit ===
=== nvidia-cuda-toolkit ===
多种安装方式,最简单的如下,但是版本滞后。
多种安装方式,最简单的如下,但是版本滞后,不建议。
{{shc|<syntaxhighlight lang="bash">
{{shc|<syntaxhighlight lang="bash">
sudo apt install nvidia-cuda-toolkit -y</syntaxhighlight>|$|/home/kangkk}}
sudo apt install nvidia-cuda-toolkit -y</syntaxhighlight>|$|/home/kangkk}}
第167行: 第197行:
{{Shc_out|<syntaxhighlight lang="bash">
{{Shc_out|<syntaxhighlight lang="bash">
nvcc -V</syntaxhighlight>|<syntaxhighlight lang="bash">nvcc: NVIDIA (R) Cuda compiler driver
nvcc -V</syntaxhighlight>|<syntaxhighlight lang="bash">nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
nvcc: NVIDIA (R) Cuda compiler driver
Built on Sun_Jul_28_19:07:16_PDT_2019
Copyright (c) 2005-2021 NVIDIA Corporation
Cuda compilation tools, release 10.1, V10.1.243
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}}
</syntaxhighlight>|$|/home/kangkk}}
=== other ===
==== pycuda ====
{{shc|<syntaxhighlight lang="bash">
pip3 install pycuda</syntaxhighlight>|$|/home/kangkk}}


== cuDNN ==
== cuDNN ==
第177行: 第213行:
=== 插入式安装 ===
=== 插入式安装 ===
只需要解压后,将 CUDNN 文件复制到 CUDA 的对应文件夹。
只需要解压后,将 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">
cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
</syntaxhighlight>|<syntaxhighlight lang="bash">
#define CUDNN_MAJOR 8
#define CUDNN_MINOR 3
#define CUDNN_PATCHLEVEL 0
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
#endif /* CUDNN_VERSION_H */
</syntaxhighlight>|$|/home/kangkk}}
== 推理引擎 ==
{| class="wikitable"
|-
| [[/TensorRT|TensorRT]]
|}
== 模型引擎 ==
[[/ONNX|ONNX]]
== python ==
使用 python 检查安装的 cuda、cudnn 版本
{{Shc_out|<syntaxhighlight lang="bash">
python3</syntaxhighlight>|<syntaxhighlight lang="bash">
Python 3.8.8 (default, Apr 13 2021, 19:58:26)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> print(tensorflow.__version__)
2.7.0
>>> import tensorflow.python.platform.build_info as build
>>> print(build.build_info)
OrderedDict([('cpu_compiler', '/dt7/usr/bin/gcc'), ('cuda_compute_capabilities', ['sm_35', 'sm_50', 'sm_60', 'sm_70', 'sm_75', 'compute_80']), ('cuda_version', '11.2'), ('cudnn_version', '8'), ('is_cuda_build', True), ('is_rocm_build', False), ('is_tensorrt_build', True)])
</syntaxhighlight>|$|/home/kangkk}}


== other ==
== other ==
=== cuda 与 nvcc 版本不一致问题 ===
=== 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>。
刚接触 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>。