在 WSL Ubuntu 上安装 CUDA

在 WSL Ubuntu 上安装 CUDA

我按照 WSL-Ubuntu 版本 2.0 的 CUDA Toolkit 11.1 下载中的说明进行操作。

  • 我选择的安装程序类型是“runfile (local)”。
  • 我下载了wget https://developer.download.nvidia.com/compute/cuda/11.1.0/local_installers/cuda_11.1.0_455.23.05_linux.run
  • 尝试安装sudo sh cuda_11.1.0_455.23.05_linux.run

我收到以下错误:

/var/log/cuda-installer.log

[INFO]: Driver not installed.
[INFO]: Checking compiler version...
[INFO]: gcc location: /usr/bin/gcc

[INFO]: gcc version: gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2) 

[INFO]: Initializing menu
[INFO]: Setup complete
[INFO]: Initializing writeable menu
[INFO]: Components to install: 
[INFO]: Driver
[INFO]: 455.23.05
[INFO]: Executing NVIDIA-Linux-x86_64-455.23.05.run --ui=none --no-questions --accept-license --disable-nouveau --no-cc-version-check --install-libglvnd  2>&1
[INFO]: Finished with code: 256
[ERROR]: Install of driver component failed.
[ERROR]: Install of 455.23.05 failed, quitting

/var/log/nvidia-installer.log

nvidia-installer log file '/var/log/nvidia-installer.log'
creation time: Tue Oct  6 13:30:56 2020
installer version: 455.23.05

PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin

nvidia-installer command line:
    ./nvidia-installer
    --ui=none
    --no-questions
    --accept-license
    --disable-nouveau
    --no-cc-version-check
    --install-libglvnd

Using built-in stream user interface
-> Detected 8 CPUs online; setting concurrency level to 8.
-> Installing NVIDIA driver version 455.23.05.
WARNING: One or more modprobe configuration files to disable Nouveau are already present at: /usr/lib/modprobe.d/nvidia-installer-disable-nouveau.conf, /etc/modprobe.d/nvidia-installer-disable-nouveau.conf.  Please be sure you have rebooted your system since these files were written.  If you have rebooted, then Nouveau may be enabled for other reasons, such as being included in the system initial ramdisk or in your X configuration file.  Please consult the NVIDIA driver README and your Linux distribution's documentation for details on how to correctly disable the Nouveau kernel driver.
-> For some distributions, Nouveau can be disabled by adding a file in the modprobe configuration directory.  Would you like nvidia-installer to attempt to create this modprobe file for you? (Answer: Yes)
-> One or more modprobe configuration files to disable Nouveau have been written.  For some distributions, this may be sufficient to disable Nouveau; other distributions may require modification of the initial ramdisk.  Please reboot your system and attempt NVIDIA driver installation again.  Note if you later wish to reenable Nouveau, you will need to delete these files: /usr/lib/modprobe.d/nvidia-installer-disable-nouveau.conf, /etc/modprobe.d/nvidia-installer-disable-nouveau.conf
WARNING: The file '/proc/sys/kernel/modprobe' is unavailable; the X server will use `/sbin/modprobe` as the path to the `modprobe` utility.  This path differs from the one determined by `nvidia-installer`, /bin/kmod.  Please verify that `/sbin/modprobe` works correctly or mount the /proc file system and verify that '/proc/sys/kernel/modprobe' reports the correct path.
-> Performing CC sanity check with CC="/usr/bin/cc".
-> Performing CC check.
ERROR: Unable to find the kernel source tree for the currently running kernel.  Please make sure you have installed the kernel source files for your kernel and that they are properly configured; on Red Hat Linux systems, for example, be sure you have the 'kernel-source' or 'kernel-devel' RPM installed.  If you know the correct kernel source files are installed, you may specify the kernel source path with the '--kernel-source-path' command line option.
ERROR: Installation has failed.  Please see the file '/var/log/nvidia-installer.log' for details.  You may find suggestions on fixing installation problems in the README available on the Linux driver download page at www.nvidia.com.

接下来我尝试:

  • git clone https://github.com/microsoft/WSL2-Linux-Kernel
  • 使用 kernel-source-path 参数再次运行安装程序:sudo sh cuda_11.1.0_455.23.05_linux.run --kernel-source-path=/mnt/c/repos/WSL2-Linux-Kernel

/var/log/nvidia-installer.log有附加信息,但仍然失败:

-> Using the kernel source path '/mnt/c/repos/WSL2-Linux-Kernel' as specified by the '--kernel-source-path' commandline option.
ERROR: Neither the '/include/linux/version.h' nor the '/include/generated/uapi/linux/version.h' kernel header file exists.  The most likely reason for this is that the kernel source files in '/mnt/c/repos/WSL2-Linux-Kernel' have not been configured.
ERROR: Installation has failed.  Please see the file '/var/log/nvidia-installer.log' for details.  You may find suggestions on fixing installation problems in the README available on the Linux driver download page at www.nvidia.com.

wslsys

WSL Version: 2
Locale: en_US
Release Install Date: Sun Aug  2 13:00:51 PDT 2020
Branch: vb_release
Build: 19041
Full Build: 19041.1.amd64fre.vb_release.191206-1406
Display Scaling: 1
Windows Theme: light
Windows Uptime: 10d 1h 33m
WSL Uptime: 0d 0h 14m
WSL Release: Ubuntu 20.04.1 LTS
WSL Kernel: Linux 4.4.0-19041-Microsoft
Packages Count: 715

相关内容