我按照这个说明配置了 Cuda,但在这一步我尝试写下这些行
To configure the CUDA environment for all users (and applications) on your system create the file (use sudo and a text editor of your choice)
/etc/profile.d/cuda.sh
with the following content,
export PATH=$PATH:/usr/local/cuda/bin
export CUDADIR=/usr/local/cuda
但得到了"/etc/profile.d/cuda.sh" is a directory
我尝试运行 Cuda 示例,结果
Error: target directory missing
Usage: cuda-install-samples-11.1.sh <target directory>
Will append NVIDIA_CUDA-11.1_Samples to <target directory>
我尝试在 bashrc 中写入以下内容
export CUDA_HOME=/usr/local/cuda
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64
PATH=${CUDA_HOME}/bin:${PATH}
export PATH
编辑
我尝试使用此命令运行示例来测试 cuda
./cuda-install-samples-11.1.sh
但得到了
Error: target directory missing
Usage: cuda-install-samples-11.1.sh <target directory>
Will append NVIDIA_CUDA-11.1_Samples to <target directory>
编辑2
我尝试运行这个命令
./cuda-install-samples-11.1.sh /home/user/NVIDIA_CUDA-11.1_Samples
但得到了
bash: ./cuda-install-samples-11.1.sh: No such file or directory
答案1
该目录/etc/profile.d/cuda.sh
应该是一个文件,因此首先删除该目录但删除目录时要格外小心:
sudo rm -Rf /etc/profile.d/cuda.sh
将以下内容添加到您的(每个用户)底部~/.profile
或将其添加到名为(全局)的文件中/etc/profile.d/cuda.sh
,然后重新启动系统:
# set PATH for cuda 11.1 installation
if [ -d "/usr/local/cuda-11.1/bin/" ]; then
export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
fi
然后,cuda-install-samples-11.1.sh <target directory>
当您使用.run
文件或.deb
文件安装时的命令默认为,~/NVIDIA_CUDA-11.1_Samples
因此运行该命令如下:
./cuda-install-samples-11.1.sh ~/NVIDIA_CUDA-11.1_Samples
或者在运行上述命令之前,请通过运行以下命令确保它是可执行的:
chmod +x cuda-install-samples-11.1.sh