HyperAI
Back to Headlines

CUDA 12 on WSL 2: Full NVIDIA GPU Acceleration Without Reboots in 30 Minutes

7 days ago

Zero-Reboot GPU Power: CUDA 12 on WSL 2 in 30 Minutes Tired of constantly rebooting between Windows and Ubuntu to switch between tasks like editing slides and compiling CUDA kernels? With the latest updates to Windows 11, the days of this tedious back-and-forth are over. Thanks to GPU paravirtualization and NVIDIA's unified Game-Ready/Studio driver, Windows Subsystem for Linux (WSL) 2 can now directly access your NVIDIA RTX GPU, providing full acceleration without the need for a dual-boot setup or additional drivers within the virtual machine. In this guide, we will walk you through setting up Ubuntu 22.04 on WSL 2 and installing CUDA 12.4 to harness the power of your GPU seamlessly from within Windows. By following these steps, you'll be able to leverage the full capabilities of your NVIDIA GPU for both Windows and Linux workloads without missing a beat. Step 1: Install Windows 11 and WSL 2 First, ensure that your system is running the latest version of Windows 11. This is crucial because WSL 2 and its GPU support rely on specific features available only in Windows 11. To check your current version, go to Settings > System > About > Windows Specifications. Next, install WSL 2 by opening PowerShell as an administrator and running the following command: wsl --install -d Ubuntu This command will download and set up Ubuntu 22.04, which is fully compatible with the latest CUDA releases. Step 2: Enable GPU Support in WSL 2 To enable GPU support, you need to install the CUDA WSL driver. NVIDIA has made this process straightforward with their unified Game-Ready/Studio driver. Open PowerShell and run: wsl --update Then, open the NVIDIA Control Panel and ensure that the WSL option is enabled. You can do this by navigating to "Manage GPU" and checking the box to enable WSL 2. Step 3: Install Ubuntu 22.04 and Configure It Once WSL 2 is installed, you will need to set up your Ubuntu environment. Open the Windows Terminal and launch Ubuntu: Ubuntu When prompted, create a new user and set a password. This step is important as it will be your primary account for all future operations within Ubuntu. After logging in, update the package list and install essential tools: sudo apt update && sudo apt upgrade -y sudo apt install -y build-essential Step 4: Install CUDA 12.4 CUDA 12.4 can be installed via the official NVIDIA repository. First, add the CUDA repository to your system: wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600 wget https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda-repo-wsl-ubuntu-12-4-local_12.4.0-1_amd64.deb sudo dpkg -i cuda-repo-wsl-ubuntu-12-4-local_12.4.0-1_amd64.deb sudo cp /var/cuda-repo-wsl-ubuntu-12-4-local/cuda-*-keyring.gpg /usr/share/keyrings/ sudo apt update Finally, install CUDA 12.4: sudo apt-get -y install cuda Step 5: Verify the Installation To ensure that CUDA 12.4 is correctly installed and functional, you can run a simple test. First, install the NVIDIA CUDA Toolkit: sudo apt-get -y install nvidia-cuda-toolkit Then, verify the installation by running: nvidia-smi If everything is set up correctly, you should see information about your NVIDIA GPU. Additionally, you can compile and run a sample CUDA program to further confirm the functionality: cd /usr/local/cuda-12.4/samples/1_Utilities/deviceQuery sudo make ./deviceQuery If the deviceQuery program runs successfully and displays detailed information about your GPU, you're all set! Conclusion By following these steps, you can now enjoy the full power of your NVIDIA RTX GPU within Ubuntu on WSL 2, all without the need for constant reboots. This setup is ideal for developers and researchers who require seamless access to both Windows and Linux environments. Whether you're working on machine learning models, graphics rendering, or any other GPU-intensive tasks, you can switch between operating systems effortlessly and maintain productivity. For more detailed instructions and troubleshooting tips, refer to the official documentation from NVIDIA and Microsoft: [NVIDIA Developer] [Microsoft Learn] Happy coding!

Related Links