公司动态
ubuntu26安装CUDA13.2~13.3
一、说明在前面安装成功ubuntu26.04后就要继续安装CUDA了。这样才能满足开发环境并支持进一步的开发需求。ubuntu26.04安装除了系统自行安装的相关软件和工具外没有安装其它额外的内容。从原来的24.04就发现系统已经不再自带很多开发工具了。所以在开始安装前需要进行一些准备动作。二、安装环境处理首先验证是否有C的开发环境g -v没有发现相关的编译所以先安装相关的开发环境依赖#更新系统 sudo apt update sudo apt upgrade #安装编译环境 sudo apt install build-essential sudo apt install software-properties-common #系统添加第三方软件源如 PPA,其实后面也没用更新完成后基本相关的基础依赖就配置好了。三、安装CUDAapt方式在一些资料中推荐是使用apt的方式来安装此处也可以但有两个注意首先不要使用老的方法即前面的PPA的方式另外使用新的方式下载的CUDA版本可能不是客户所需求的。比如目前可能下载的是CUDA13.1。如果想安装更高版本就需要手动进行。使用下面的方式sudo apt update sudo apt install cuda-toolkit -y说明如果找不到相关的源可搜索相关的源设置方法然后再更新安装即可。类似于sudo add-apt-repository universe -y sudo add-apt-repository multiverse -y sudo apt update上面的命令未验证请周知。由于这次采用的是错误的老的PPA方式导致安装出现问题所以改为了下面的官网下载软件进行安装的方式。2. 官网下载最新打开NVIDIA的下载官网https://developer.nvidia.com/cuda-downloads?target_osLinuxtarget_archx86_64DistributionUbuntutarget_version26.04target_typerunfile_local下载最新版本的CUDA Toolkit 13.3注意选用网页上相关的配置。官网给出了相关的下载和安装方法wget https://developer.download.nvidia.com/compute/cuda/13.3.1/local_installers/cuda_13.3.1_610.43.02_linux.run sudo sh cuda_13.3.1_610.43.02_linux.run安装首先使用nvidia-smi命令查看驱动支持的相关CUDA版本结果发现“ Driver Version: 595.71.05 CUDA Version: 13.2”即此版本驱动只持CUDA13.2。再经NVIDIA官网发现只有CUDA13.3支持ubuntu26.04。所以想到直接安装并且在安装过程中不安装驱动的方式是不可以的确实实际测试了日志报驱动版本不匹配。所以先升级驱动首先卸载原驱动sudo apt purge --autoremove -y nvidia* cuda-keyring 或 sudo apt purge nvidia-* sudo apt autoremove再安装新驱动sudo apt update sudo apt install nvidia-driver-610 -y或者直接使用CUDA安装包时安装驱动610系列安装失败。四、问题解决在出现无法安装最新版本后就要恢复老的驱动版本用来安装CUDA13.2。解决问题的方式如下先清除驱动安装指定的595和580系列驱动使用上面的命令然后安装sudo apt install nvidia-driver-595 #或者在5后按Tab键可列出当前支持的驱动 #或 sudo apt install nvidia-driver-580安装过程中处理Secure Boot在上述的安装过程中还遇到一个问题即出来一段提示意思是让处理签名来通过Secure Boot的管理并设置相关的密码。这里采用了最简单的方式直接重启到BIOSUEFI中找到Secure Boot设置为Disable。 然后重启。结果报一个问题说 dpkg 被中断您必须手工运行 ‘sudo dpkg --configure -a’ 解决此问题。 执行此命令可以完成后续的更新。但结果无效nvidia-smi命令无结果。Ubuntu自适配这时可以继续删除相关的Nvidia驱动使用上面的删除命令然后重启然后使用下面的命令ubuntu-drivers list #列出当前支持显示很多当前版本包括Server和Open版本 sudo ubuntu-drivers install #自动安装合适的版本注意不要使用旧的方法sudo ubuntu-drivers autoinstall此时再执行:nvidia-smi #仍然无效 NVIDIA-SMI has failed because it couldnt communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running使用命令lsmod | grep nvidia无结果说明内核未加载可以使用sudo modprobe nvidia #手动加载也可以直接重启或二者同时执行。即可成功。重启电脑再执行上述命令相关驱动正确安装仍然与最初自带的驱动版本一致。4. 下载并安装CUDA13.2这时再下载CUDA13.2wget https://developer.download.nvidia.com/compute/cuda/13.2.0/local_installers/cuda_13.2.0_595.45.04_linux.run sudo sh cuda_13.2.0_595.45.04_linux.run注意其驱动仍然不安装因为目前适配的驱动比其自带的驱动还要高。此时由于使用系统自带的驱动会出现下面的提示Existing package manager installation of the driver found. It is strongly recommended that you remove this before continuing.不用管他但是在安装CUDA13.2时不选择安装驱动第一项使用空格或回车键取消X即可。安装完成出现sudo sh cuda_13.2.0_595.45.04_linux.run [sudo: authenticate] 密码 Summary Driver: Not Selected Toolkit: Installed in /usr/local/cuda-13.2/ Please make sure that - PATH includes /usr/local/cuda-13.2/bin - LD_LIBRARY_PATH includes /usr/local/cuda-13.2/lib64, or, add /usr/local/cuda-13.2/lib64 to /etc/ld.so.conf and run ldconfig as root To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-13.2/bin ***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 595.00 is required for CUDA 13.2 functionality to work. To install the driver using this installer, run the following command, replacing CudaInstaller with the name of this run file: sudo CudaInstaller.run --silent --driver Logfile is /var/log/cuda-installer.log这表明CUDA安装成功但因未安装CUDA中自带的驱动所以这个安装是不完整的所以目前无法使用CUDA需要进行配置才可以。安装结果安装完成后会提示由于没有安装驱动虽然CUDA相关安装成功但无法使用。所以此时使用nvcc命令验证无法通过。可能进行相关的环境变量处理vim ~/.bashrc #尾部增加 export PATH/usr/local/cuda-13.2/bin${PATH::${PATH}} export LD_LIBRARY_PATH/usr/local/cuda-13.2/lib64${LD_LIBRARY_PATH::${LD_LIBRARY_PATH}} :wq source ~/.bashrc即可成功。五、验证直接调用命令验证是否安装成功nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2026 NVIDIA Corporation Built on Mon_Mar_02_09:52:23_PM_PST_2026 Cuda compilation tools, release 13.2, V13.2.51 Build cuda_13.2.r13.2/compiler.37434383_0为确保成功从网上找个CUDA程序代码#includestdio.h#includecuda_runtime.h__global__voidaddKernel(int*a,int*b,int*c,intn){intidxthreadIdx.xblockIdx.x*blockDim.x;if(idxn){c[idx]a[idx]b[idx];}}intmain(){intdeviceCount;cudaError_terrcudaGetDeviceCount(deviceCount);if(err!cudaSuccess){printf(cudaGetDeviceCount failed: %s\n,cudaGetErrorString(err));return1;}if(deviceCount0){printf(No CUDA-capable devices found!\n);return1;}cudaDeviceProp prop;cudaGetDeviceProperties(prop,0);printf( Device Info \n);printf(GPU Name: %s\n,prop.name);printf(Compute Capability: %d.%d\n,prop.major,prop.minor);printf(Total global memory: %.2f GB\n,prop.totalGlobalMem/(1024.0*1024.0*1024.0));printf(\n\n);intn1000;intbytesn*sizeof(int);int*h_a(int*)malloc(bytes);int*h_b(int*)malloc(bytes);int*h_c(int*)malloc(bytes);for(inti0;in;i){h_a[i]i;h_b[i]i*2;}int*d_a,*d_b,*d_c;cudaMalloc(d_a,bytes);cudaMalloc(d_b,bytes);cudaMalloc(d_c,bytes);cudaMemcpy(d_a,h_a,bytes,cudaMemcpyHostToDevice);cudaMemcpy(d_b,h_b,bytes,cudaMemcpyHostToDevice);intthreadsPerBlock256;intblocks(nthreadsPerBlock-1)/threadsPerBlock;addKernelblocks,threadsPerBlock(d_a,d_b,d_c,n);cudaMemcpy(h_c,d_c,bytes,cudaMemcpyDeviceToHost);printf( Vector Addition Test \n);printf(Checking first 10 results:\n);for(inti0;i10in;i){printf(h_a[%d] h_b[%d] %d %d %d (expected %d) %s\n,i,i,h_a[i],h_b[i],h_c[i],h_a[i]h_b[i],(h_c[i]h_a[i]h_b[i])?✓:✗);}printf(\n);cudaFree(d_a);cudaFree(d_b);cudaFree(d_c);free(h_a);free(h_b);free(h_c);errcudaGetLastError();if(err!cudaSuccess){printf(CUDA kernel error: %s\n,cudaGetErrorString(err));return1;}printf(\nCUDA installation verification PASSED!\n);return0;}编译nvcc -o test test.cu执行编译程序./test Device Info GPU Name: NVIDIA RTX PRO 4000 Blackwell Compute Capability: 12.0 Total global memory: 23.39 GB Vector Addition Test Checking first 10 results: h_a[0] h_b[0] 0 0 0 (expected 0) ✓ h_a[1] h_b[1] 1 2 3 (expected 3) ✓ h_a[2] h_b[2] 2 4 6 (expected 6) ✓ h_a[3] h_b[3] 3 6 9 (expected 9) ✓ h_a[4] h_b[4] 4 8 12 (expected 12) ✓ h_a[5] h_b[5] 5 10 15 (expected 15) ✓ h_a[6] h_b[6] 6 12 18 (expected 18) ✓ h_a[7] h_b[7] 7 14 21 (expected 21) ✓ h_a[8] h_b[8] 8 16 24 (expected 24) ✓ h_a[9] h_b[9] 9 18 27 (expected 27) ✓ CUDA installation verification PASSED!如果上述都可以实现则CUDA安装成功了。六、总结这次安装CUDA13.2遇到的问题还是比较多的。不过在AI的帮助下还是比较顺利的完成了整个环境的安装。主要的问题在于想安装最新的CUDA13.3只考虑了Ubunt26.04系统的支持而没有考虑到硬件对最新驱动的支持安装的是工业级的NVIDIA RTX PRO 4000 Blackwell架构的GPU。结果导致驱动的安装的来回折腾最终还是回到原点。建议大家在安装驱动时非必要还是要以系统最新支持的相关驱动为目标不要盲目的引入最新的硬件驱动。