WSL2 / NVIDIA GPU Driver for DirectML and Tensor Flow | by Cristian Saavedra Desmoineaux | Towards Data Science

In September 2020, NVIDIA announced native CUDA features on Windows Subsystem for Linux (WSL2) in the last version of the preview driver, which motivated me to write this post.
I will explain how to install NVIDIA Driver on WSL2 (Microsoft Subsystem Linux) and test TensorFlow's parallel execution.
Some of the main changes are:
Improving the experience in the performance of CUDA users
TensorFlow with DirectML API support for DirectX 12 based GPU acceleration
Support for PTX JIT will enable us to run parallel execution (PTX) code.
Until Microsoft Windows build 20145 is not available to the general public, to use GPU on WSL version 2, you will need to do the following:
Activate the Microsoft Insider ProgramCheck your Windows Subsystem for Linux (WSL) version.Sign In or Create an account in NVIDIA DeveloperDownload and Install the NVIDIA DriverTest GPU usage by WSL2
Activate the Microsoft Insider Program
Check your Windows Subsystem for Linux (WSL) version.
Sign In or Create an account in NVIDIA Developer
Download and Install the NVIDIA Driver
Test GPU usage by WSL2
Previous to activate the Microsoft Insider program, we will check if the required build is available. To do that, first, go to Check for Updates and verify that you have the last updates.
The next step is to go to About your PC and verify the OS build in the Windows Specifications.
If you are in a build greater than 20145, then you can skip the next section.
Register at https://insider.windows.com/en-us/getting-started and follow the steps. After the restart, you will get a new setting option, Windows Insider Program Setting.
After many updates, you can use the GPU by the WSL if you have the OS builds 20145 or higher. If you don’t have the minimum build, change to Dev Channel or Fast Ring in the Windows Insider Program settings and rerun Windows Update.
You need the 2nd version of the Windows Subsystem for Linux. To check if you are using the WSL 2, run the following command in a prompt
wsl --list -v
If you have version 1, you can update it with the next link. If you don’t have the WSL installed, I recommend you to read my previous post.
The next step is to update your WSL distribution. To do that, open a prompt with and execute:
sudo apt-get update && sudo apt-get upgrade
The NVIDIA Developer page has some not regular way to Sign In or Create an account, begin to go https://developer.nvidia.com and on Account at the upper-right corner, and select the email sign in or for creating a new account. Then enter your current email and password or click on Create account and follow the steps.
To download the last version of the NVIDIA Driver, go to https://developer.nvidia.com/cuda/wsl/download and choose between GEFORCE or QUADRO depending on your current hardware.
I am going to use GeForce and express installation of the version 460.20_gameready_win10-dch_64bit_international.exe
After install, go to GEFORCE Experience and select the settings, Enable experimental features, and press the Restart button.
Previous to begin, I recommend checking the NVIDIA WSL Documentation. For the next steps and install Miniconda. If you don’t have it, you will find it helpful in my previous post.
You will need at least the Linux kernel version 4.19.121. To know your Linux version, run cmd or Command Prompt and execute the following command:
wsl cat /proc/version
You will see something similar to this:
Linux version 4.19.128-microsoft-standard
Next, update Miniconda, Create a new environment called DirectML using python 3.6, and Install Tensor Flow / Direct ML.
conda update condaconda update --allconda create --name directml python=3.6conda activate directmlpip install tensorflow-directml
Then open an interactive Python and execute the following:
import tensorflow.compat.v1 as tf tf.enable_eager_execution(tf.ConfigProto(log_device_placement=True)) print(tf.add([1.0, 2.0], [3.0, 4.0]))
You will get your current Hardware.
To double-check, I ran the last statement many times, waiting different times between each executing to try if affect the GPU usage trend:
news.developer.nvidia.com
developer.nvidia.com
developer.nvidia.com
github.com
devblogs.microsoft.com
devblogs.microsoft.com
To finish, I am grateful to my brother Michael Saavedra who push me to continue writing about these topics.