Toc
  1. what is WSL
  2. installation
  3. GPU compute support
    1. install Insider Preview Builds
    2. install preview GPU driver
    3. develop
    4. sample
  4. Running Graphical Applications
  5. troubleshooting
    1. installation
    2. GPU support
    3. Windows 10 Insider Preview Builds
    4. Python environment
Toc
0 results found
MINGG
Windows Subsystem for Linux
2021/06/28 PC

what is WSL

WSL is a Microsoft official solution for GNU/Linux environment running on windows, instead of either virtual machine or double system, for more information referring to What is Windows Subsystem for Linux | Microsoft Docs.

GNU/Linux environment is a application on windows via WSL, and you can manage this environment by terminal. Now there are several GUI tool having supported it, while Microsoft team is now trying to develop GPU compute on WSL.

installation

for installation refer to Install WSL on Windows 10 | Microsoft Docs, WSL | Ubuntu, WSL - Ubuntu Wiki

Notice: The Windows Subsystem for Linux only runs on your system drive(usually this is your C: drive).

GPU compute support

Support for GPU compute, the #1 most requested WSL feature, is now ONLY available for preview via the Windows Insider program, referring to GPU accelerated ML training in WSL | Microsoft Docs, GPU accelerated ML training inside the Windows Subsystem for Linux - Windows Developer Blog.

To make it, refer to NVIDIA CUDA preview in WSL 2 | Microsoft Docs, Latest CUDA/CUDA on Windows Subsystem for Linux topics - NVIDIA Developer Forums,

install Insider Preview Builds

download and install the Windows 10 Insider Preview Builds(actually Windows 11 Insider Preview-6/29/2021).

preview win

installingwin11

win11des

win11os

install preview GPU driver

refer to preview GPU driver | Microsoft Docs.

develop

develop based on the above preview GPU driver

  1. if use NVIDIA GPU, the preview GPU driver actually includes the CUDA on WSL 2, refer to CUDA on Windows Subsystem for Linux (WSL) - Public Preview | NVIDIA Developer,

    so you can use directly CUDA C++, consulting the CUDA C++ Programming Guide, located in /usr/local/cuda-10.1/doc, or referring to CUDA 高性能并行计算入门_cyhbrilliant的博客-CSDN博客_cuda并行计算, and its performance is really good(Ubuntu > WSL > Windows);

    -7c741225dfd3191d

    besides, you can start using your existing Linux workflows through NVIDIA Docker, refer to CUDA on WSL Documentation (nvidia.com);

    Wrong try: go on installing cuDNN based on CUDA, you may need to use mirrors source, refer to 使用conda安装python包_cathar的专栏-CSDN博客_conda安装python包 or pip 使用国内镜像源 | 菜鸟教程 (runoob.com), actually there is error around CUDA lib64 and hence almost frameworks (like TensorFlow2, MindSpore) cannot access to NVIDIA GPU, but PyTorch.

    7d69554556d47e45

  2. Besides, use TensorFlow with DirectML. AMD, Intel and NVIDIA preview GPU drivers all include DirectX WSL driver supporting DX12 APIs, so TensorFlow with a DirectML backend can access to those GPUs,refer to Install the Tensorflow with DirectML package | Microsoft Docs. There is a sample in the following section.

Notice: many operations on WSL need root, so if you meet something wrong, try to type sudo ahead, and it is also really useful and important to look up the output information; maybe you need some knowledge of Ubuntu

sample

bash:

cd ~
ls
mkdir mycode
cd mycode
touch tf_test.py
ls
vim tf_test.py

python, refer to docs/site/en/r1/tutorials at master · tensorflow/docs · GitHub:

import tensorflow as tf

mnist = tf.keras.datasets.mnist

(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(512, activation=tf.nn.relu),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation=tf.nn.softmax)
])

model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)

bash:

<Esc>
:wq<Enter>

conda info --envs
conda activate directml
ls
python3 tf_test.py

output:

appl

You can see it working well, though there are several warnings, which are almost due to versions, refer to How can I address these warning messages on my first directml attempt? · Issue #117 · microsoft/DirectML · GitHub, 成功解决Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2_张齐贤的博客-CSDN博客.

For more samples, refer to DirectML/TensorFlow at master · microsoft/DirectML · GitHub.

Running Graphical Applications

refer to Running Graphical Applications - Ubuntu Wiki,

troubleshooting

installation

refer to troubleshooting installation of WSL on Windows 10 | Microsoft Docs,

GPU support

Windows 10 Insider Preview Builds

install the Windows 10 Insider Preview Builds, but stop here

preparation35

attention_bug

solution:

before building this preview, update Windows as well as kernel to the latest general version

updatanormal

done21h1

Python environment

when you try to use TensorFlow with DirectML, following official steps and setting up Python environment, you may meet errors using either sudo conda or conda.

solution:

  1. First, check the bashrc program on WSL:
vim ~/.bashrc

make sure there is export PATH of miniconda3, like

bashrc

and then execute it:

source ~/.bashrc
  1. Root. you need to give root to write in the direction of miniconda3, refer to conda创建环境报错:NotWritableError: The current user does not have write permissions to a required path._HaotianYan的博客-CSDN博客:
cd ~
sudo chown -R {username} anaconda3

*username: user name of your Ubuntu; besides, ~ means /home/{username}.

打赏
支付宝
微信
本文作者:MINGG
版权声明:本文首发于MINGG的博客,转载请注明出处!