在Microsoft Store商店安装Ubuntu 20.04
![](https://i-blog.csdnimg.cn/direct/089b60286cf74d72ab2ca63aac41f0af.png)
使用 nvidia-smi 命令查看GPU信息,查看支持的CUDA版本,这里最高支持11.7
![](https://i-blog.csdnimg.cn/direct/1cea4f107d0f42e496b5d376ec08d7b7.png)
安装cuda工具集
进入官网:CUDA Toolkit Archive | NVIDIA Developer,现在对应版本,点击
![](https://i-blog.csdnimg.cn/direct/eae3e0f2ab564236822108ed6cf3263e.png)
配置平台,根据平台选择,安装方式提供了三种:1、下载deb文件配置本地环境安装;2、通过网络加载deb文件安装;3、通过配置文件安装;
![](https://i-blog.csdnimg.cn/direct/393706f8bdfc4a178e289bd86fe078d4.png)
这里选择用本地deb方式,安装官方提供的命令安装:
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pinsudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600wget https://developer.download.nvidia.com/compute/cuda/11.7.0/local_installers/cuda-repo-ubuntu2004-11-7-local_11.7.0-515.43.04-1_amd64.debsudo dpkg -i cuda-repo-ubuntu2004-11-7-local_11.7.0-515.43.04-1_amd64.debsudo cp /var/cuda-repo-ubuntu2004-11-7-local/cuda-*-keyring.gpg /usr/share/keyrings/sudo apt-get updatesudo apt-get -y install cuda |
添加环境变量:
vim ~/.bashrc
在末尾添加以下内容:
|---------------------------------------------------------------------------------------------------------------|
| export PATH=PATH:/usr/local/cuda-11.7/bin export LD_LIBRARY_PATH=LD_LIBRARY_PATH:/usr/local/cuda-11.7/lib64 |
source ~/.bashrc
使用 nvcc -V 命令查看安装版本信息:
![](https://i-blog.csdnimg.cn/direct/ee1cb4c2f4ea46819466c2cc6719fdcc.png)
安装 cuDNN
上官网下载对应版本:https://developer.nvidia.com/rdp/cudnn-archive,下压缩包
![](https://i-blog.csdnimg.cn/direct/bc4429c582dd4f6f8a2fa39162b02299.png)
将对应的文件包解压后,将文件拷贝到对音乐目录
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| tar -xvf cudnn-linux-x86_64-8.9.7.29_cuda11-archive.tar.xz cd cudnn-linux-x86_64-8.9.7.29_cuda11-archive sudo cp lib/* /usr/local/cuda-11.7/lib64/ sudo cp include/* /usr/local/cuda-11.7/include/ sudo chmod a+r /usr/local/cuda-11.7/lib64/* sudo chmod a+r /usr/local/cuda-11.7/include/* |
至此gpu NN开发环境就构建好了
安装tensorflow环境
安装Anaconda
官网下载安装文件 Download Now | Anaconda
![](https://i-blog.csdnimg.cn/direct/4e96c1938e7a426887b337801bcae8a3.png)
下载下来是一个Anaconda3-2024.06-1-Linux-x86_64.sh文件,执行脚本文件进行安装:
|------------------------------------------|
| bash Anaconda3-2024.06-1-Linux-x86_64.sh |
根据提示选择安装路径,推荐使用sudo安装到/usr/local/anaconda3,添加环境变量:
|-------------------------------------------------------|
| cd /usr/local/anaconda3/bin && conda init && cd - |
设置默认不启动base环境
|---------------------------------------------|
| conda config --set auto_activate_base false |
|-------------------------------------------------------------------------------------------------------------------------------|
| # 构建环境 conda create --name py_3.7.5_tf_gpu_env python=3.7.5 anaconda tensorflow-gpu # 运行环境 conda activate py_3.7.5_tf_gpu_env |
测试环境:
|----------------------------------------------------|
| import tensorflow as tf tf.test.is_gpu_available() |
![](https://i-blog.csdnimg.cn/direct/74f10dc5b1d94047bb7da68c808ff243.png)