当前位置: 首页 > news >正文

ubantu安装CUDA

想要通过llama.cpp的方式跑deepseek R1模型。在按照https://huggingface.co/unsloth/DeepSeek-R1-GGUF教程去配环境时报错了。具体如下:

(base) oem@core:~/Desktop/deepseek_llama.cpp$ sudo cmake llama.cpp -B llama.cpp/build     -DBUILD_SHARED_LIBS=OFF -DGGML_CUDA=ON -DLLAMA_CURL=ON
-- Warning: ccache not found - consider installing it for faster compilation or disable this warning with GGML_CCACHE=OFF
-- CMAKE_SYSTEM_PROCESSOR: x86_64
-- Including CPU backend
-- x86 detected
-- Adding CPU backend variant ggml-cpu: -march=native 
-- Found CUDAToolkit: /usr/local/cuda/targets/x86_64-linux/include (found version "12.9.41")
-- CUDA Toolkit found
-- Using CUDA architectures: native
CMake Error at ggml/src/ggml-cuda/CMakeLists.txt:25 (enable_language):The CMAKE_CUDA_COMPILER:/usr/bin/nvccis not a full path to an existing compiler tool.Tell CMake where to find the compiler by setting either the environmentvariable "CUDACXX" or the CMake cache entry CMAKE_CUDA_COMPILER to the fullpath to the compiler, or to the compiler name if it is in the PATH.-- Configuring incomplete, errors occurred!

具体是说,CUDA编译的路径是 /usr/bin/nvcc。但是这个目录不存在。
首先查看nvcc的目录,运行下面命令:

which nvcc

如果有输出,则跳过第1步,如果没有输出,则跳到第3步。

第1步

输入which nvcc后,假设有输出,例如输出/usr/local/cuda/bin/nvcc
,则把命令改成:

sudo cmake llama.cpp -B llama.cpp/build     -DBUILD_SHARED_LIBS=OFF     -DGGML_CUDA=ON     -DLLAMA_CURL=ON     -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc

输入此命令后,如果报错下面内容,说明deepseek-llama.cpp 项目 要求 至少支持 CUDA 17(也就是C++17 for CUDA)。而你的版本太老了。此时跳到第2步。

-- Warning: ccache not found - consider installing it for faster compilation or disable this warning with GGML_CCACHE=OFF
-- CMAKE_SYSTEM_PROCESSOR: x86_64
-- Including CPU backend
-- x86 detected
-- Adding CPU backend variant ggml-cpu: -march=native 
-- CUDA Toolkit found
-- Using CUDA architectures: native
-- The CUDA compiler identification is NVIDIA 10.1.243 with host compiler GNU 8.4.0
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: /usr/bin/nvcc - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- CUDA host compiler is GNU 8.4.0
-- Including CUDA backend
-- Configuring done (3.8s)
CMake Error in ggml/src/ggml-cuda/CMakeLists.txt:Target "ggml-cuda" requires the language dialect "CUDA17" (with compilerextensions).  But the current compiler "NVIDIA" does not support this, orCMake does not know the flags to enable it.-- Generating done (0.2s)
CMake Generate step failed.  Build files cannot be regenerated correctly.

第2步

当前CUDA版本太老了,那就把它卸载了重新装。按照下面命令卸载cuda及其驱动:

#退出图形界面
sudo systemctl isolate multi-user.target
#卸载旧驱动
sudo apt-get --purge remove '*cuda*' '*nvidia*'
sudo apt-get autoremove
#检查驱动是否卸载干净
lsmod | grep nvidia
#若上述命令打印出东西,如打印出nvidia_drm,则执行:
sudo rmmod nvidia_drm #运行sudo rmmod XXX命令,直到lsmod | grep nvidia打印不出内容

第3步

现在系统没有驱动也没有cuda了,可以安装高版本的cuda了。
去NVIDIA官网,按照官网的配置教程来:https://developer.nvidia.com/cuda-12-2-0-download-archive
我的系统是linux,X86_64,Ubantu,我选择的是deb(local)形式。得到下面命令:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda-repo-ubuntu2004-12-9-local_12.9.0-575.51.03-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2004-12-9-local_12.9.0-575.51.03-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2004-12-9-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda

注意第3条命令,最好用cuda-repo-ubuntu2004-12-9-local_12.9.0-575.51.03-1_amd64.deb而不用cuda-repo-ubuntu2004-12-2-local_12.2.0-535.54.03-1_amd64.deb。因为驱动如果是535版本的和5.15.x的内核版本不兼容。
运行上述命令后,使用sudo reboot重启一下。
输入nvidia-smi,可以得到以下内容,圈出来的内容是驱动的版本:

在这里插入图片描述然后再输入以下内容,把nvcc的路径添加到环境变量中:

which nvcc
nvcc --version
export PATH=/usr/local/cuda/bin:$PATH  #注意:这里的路径是which nvcc打印的内容去掉nvcc后的路径
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH  #注意:这里的路径是which nvcc打印的内容去掉nvcc后的路径再加上lib64的路径
source ~/.bashrc

做完这些后,再去执行sudo cmake llama.cpp -B llama.cpp/build -DBUILD_SHARED_LIBS=OFF -DGGML_CUDA=ON -DLLAMA_CURL=ON -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc命令,应该能成功了。

相关文章:

  • 园区网的发展
  • tinyrenderer笔记(法线映射)
  • 龙虎榜——20250506
  • AI教你学VUE——Deepseek版
  • Matlab/Simulink的一些功能用法笔记(4)
  • 区块链交易所开发:开启数字交易新时代
  • 【JEECG】BasicTable内嵌Table表格错位
  • MySQL 触发器(Trigger)讲解
  • LeetCode 790 多米诺和托米诺平铺 题解
  • Latex排版问题:图片单独占据一页
  • 【网络原理】IP协议
  • vmware虚拟机克隆
  • 聊天助手提示词调优案例
  • 代码随想录算法训练营第九天 |【字符串】151.翻转字符串里的单词、卡码网55.右旋转字符串、28.实现strStr、459.重复的子字符串
  • 星纪魅族新品发布会定档5月13日,Note 16系列战神归来
  • 第七章,VLAN技术
  • 驱动开发系列57 - Linux Graphics QXL显卡驱动代码分析(四)显示区域更新
  • C#中从本地(两个路径文件夹)中实时拿图显示到窗口中并接收(两个tcp发送的信号)转为字符串显示在窗体中实现检测可视化
  • 【C语言】推箱子小游戏
  • C++ 构造函数
  • 习近平离京赴莫斯科对俄罗斯进行国事访问并出席纪念苏联伟大卫国战争胜利80周年庆典
  • 探索人类的心灵这件事,永远也不会过时
  • 五一假期上海边检查验出入境人员超61万人次,同比增长23%
  • 美CIA发布视频“招募中国官员窃取机密”,外交部:赤裸裸的政治挑衅
  • 被炒热的“高潮针”:超适应症使用,安全性和有效性存疑
  • 科技赋能文化体验,“五一”假期“海昏侯”人气创新高