安装CUDA和cuDNN到指定目录

您所在的位置:网站首页 cuda默认安装位置 安装CUDA和cuDNN到指定目录

安装CUDA和cuDNN到指定目录

2023-08-13 05:21| 来源: 网络整理| 查看: 265

先到官网下载对应版本的cuda和cudnn,我下载的是cuda_10.0.130_410.48_linux.run和cudnn-10.0-linux-x64-v7.6.5.32.tgz(科学上网下载速度可能会快一点)

运行以下命令查看帮助

sh cuda_10.0.130_410.48_linux.run --help

得到命令提示,其中有几个option比较有用

Options: --silent Performs an installation with no further user-input and minimal command-line output based on the options provided below. Silent installations are useful for scripting the installation of CUDA. Using this option implies acceptance of the EULA. The following flags can be used to customize the actions taken during installation. At least one of --driver, --uninstall, --toolkit, and --samples must be passed if running with non-root permissions. --toolkit Install the CUDA Toolkit. --toolkitpath= Install the CUDA Toolkit to the directory. If this flag is not provided, the default path of /usr/local/cuda-10.0 is used.

由于此时安装我只需要安装cuda toolkit,因此可以使用--toolkit并用--toolkitpath来指定安装位置,同时需要使用--silent才能够正常安装。

运行以下命令安装(替换成安装位置的绝对路径)

sh cuda_10.0.130_410.48_linux.run --toolkitpath= --toolkit -silent

安装cudnn,按照这个博客第6步解压下载的压缩包,复制粘贴到cuda对应的目录,并赋予权限即可。

配置环境变量(参考博客)

由于我只需要在某一个项目内使用这个版本的cuda,因此我可以在虚拟环境内配置环境变量,在base环境中使用默认的cuda。

首先创建虚拟环境(cuda_test为虚拟环境名)

conda create -n cuda_test python=3.6

在anaconda的目录新建启动该虚拟环境时需要运行的脚本

mkdir -p envs/cuda_test/etc/conda/activate.d vim envs/cuda_test/etc/conda/activate.d/activate.sh chmod +x envs/cuda_test/etc/conda/activate.d/activate.sh

在打开activate.sh脚本时输入以下内容,使得该虚拟环境启动时,自动切换为cuda10.0

ORIGINAL_CUDA_HOME=$CUDA_HOME ORIGINAL_LD_LIBRARY_PATH=$LD_LIBRARY_PATH ORIGINAL_PATH=$PATH export CUDA_HOME= export LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH export PATH=$CUDA_HOME/bin:$PATH

在anaconda的目录新建退出该虚拟环境时需要运行的脚本

mkdir -p envs/cuda_test/etc/conda/deactivate.d vim envs/cuda_test/etc/conda/deactivate.d/deactivate.sh chmod +x envs/cuda_test/etc/conda/deactivate.d/deactivate.sh

在打开deactivate.sh脚本时输入以下内容

export CUDA_HOME=$ORIGINAL_CUDA_HOME export LD_LIBRARY_PATH=$ORIGINAL_LD_LIBRARY_PATH export PATH=$ORIGINAL_PATH unset ORIGINAL_CUDA_HOME unset ORIGINAL_LD_LIBRARY_PATH unset ORIGINAL_PATH

测试cuda是否成功安装

在base环境下运行

nvcc -V

得到原来cuda的版本信息

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

进入虚拟环境之后

conda activate cuda_test nvcc -V

得到新安装的cuda版本信息

nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2018 NVIDIA Corporation Built on Sat_Aug_25_21:08:01_CDT_2018 Cuda compilation tools, release 10.0, V10.0.130

至此完成安装



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3