在Microsoft Store商店安装Ubuntu 20.04
使用 nvidia-smi 命令查看GPU信息,查看支持的CUDA版本,这里最高支持11.7
安装cuda工具集
进入官网:CUDA Toolkit Archive | NVIDIA Developer,现在对应版本,点击
配置平台,根据平台选择,安装方式提供了三种:1、下载deb文件配置本地环境安装;2、通过网络加载deb文件安装;3、通过配置文件安装;
这里选择用本地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 命令查看安装版本信息:
安装 cuDNN
上官网下载对应版本:https://developer.nvidia.com/rdp/cudnn-archive,下压缩包
将对应的文件包解压后,将文件拷贝到对音乐目录
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 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
下载下来是一个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() |