Skip to content

Instantly share code, notes, and snippets.

@peatmonster
Last active November 3, 2023 15:42
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peatmonster/d86306009b7adfae717c10e1724dac81 to your computer and use it in GitHub Desktop.
Save peatmonster/d86306009b7adfae717c10e1724dac81 to your computer and use it in GitHub Desktop.

WSL 2 with CUDA

Set up Windows Subsystem for Linux (version 2) with CUDA support + TensorFlow.

Before you start

  • You must be on Windows 10 21H2 or above.

    Note: On my system 21H2 could not be updated to. I ended up with a bricked install as Windows tried to install Windows 11 on my unsupported CPU. I recommend just installing Windows 10 21H2 directly from an ISO.

  • You don't have to be on OS build 20140 or above as some sources state. My build: 19044.1469
  • Install the latest "game ready driver" for your card.

    Note: You don't need a special driver despite the Nvidia documentation, I got mine here: https://www.nvidia.com/Download/index.aspx

  • The apt-cache search <PACKAGE> command is your friend. Use it to see what CUDA versions are available.

Steps to install

  1. Open CMD as administrator and run:

    wsl --install -d ubuntu
    
  2. In the Ubuntu WSL, update the system:

    sudo apt update
    sudo apt upgrade
    
  3. Install Git:

    sudo apt install git
    
  4. Figure out what version of CUDA & cuDNN you need, I recommend looking at this page: https://www.tensorflow.org/install/source#gpu

  5. Find the desired version of CUDA on this page: https://developer.nvidia.com/cuda-toolkit-archive

  6. Enter the following information and follow the instructions, but do not run the apt-get install cuda command!

    image

  7. Install the specific version of CUDA, for example:

    sudo apt install cuda-toolkit-11-8 cuda-11-8
    
  8. Install cuDNN for CUDA 11.x and Ubuntu 22.04:

    1. Download the TAR file from: https://developer.nvidia.com/rdp/cudnn-archive
    2. Decompress the file, for example:
      tar xf cudnn-linux-x86_64-8.9.5.30_cuda11-archive.tar.xz
      
    3. Copy the library files into the right place:
      cd cudnn-linux-x86_64-8.9.5.30_cuda11-archive/
      
      sudo cp include/cudnn.h /usr/local/cuda-11/include/
      sudo cp lib/libcudnn* /usr/local/cuda-11/lib64/
      sudo chmod a+r /usr/local/cuda-11/include/cudnn.h /usr/local/cuda-11/lib64/libcudnn*
      
  9. Edit ~/.bashrc and add the following:

    # CUDA environment variables
    export PATH=/usr/local/cuda-11/bin${PATH:+:${PATH}}
    export LD_LIBRARY_PATH=/usr/local/cuda-11/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    
  10. Restart your terminal or run source ~/.bashrc

  11. Verify CUDA installation (optional)

    git clone https://github.com/NVIDIA/cuda-samples.git
    cd cuda-samples/Samples/5_Domain_Specific/BlackScholes/
    make
    ./BlackScholes
    
  12. Install Python and Tensorflow (optional)

    sudo apt install python3-dev python3-pip
    pip3 install tensorflow
    
  13. Try not to think about https://en.wikipedia.org/wiki/Embrace,_extend,_and_extinguish (optional)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment