https://docs.microsoft.com/zh-cn/windows/win32/direct3d12/gpu-tensorflow-wsl

安装最新的 Windows 预览体验开发通道生成

若要使用此预览版,你需要注册 Windows 预览体验计划完成后,请按照以下 china安装最新的内部版本。选择您的设置时,请确保您选择的是开发渠道 对于此预览版,需要版本20150或更高版本。你可以通过运行winver命令 (Windows 徽标键 + R) 运行来检查内部版本号。 实践:最后使用Windows 预览体验。猜测 可能不是必须,但是windows 家庭中文版本要最新的可能支持。

安装预览版 GPU 驱动程序

在将 TensorFlow 与 DirectML 包一起安装到 WSL 2 之前,你需要从你的 GPU 硬件供应商处安装驱动程序。这些驱动程序允许 Windows GPU 与 WSL 2 一起工作。s

AMD

从他们的网站下载并安装 AMD 的预览版驱动程序此预览版驱动程序支持以下硬件:
  • AMD Radeon RX 系列和 Radeon VII 图形。
  • AMD Radeon Pro 系列图形。
  • AMD Ryzen和 Ryzen含 Radeon Vega 图形的 PRO 处理器。
  • AMD Ryzen和 Ryzen PRO 含 Radeon Vega 图形的移动处理器。
有关兼容 AMD 产品的完整列表,请参阅 AMD 发行说明。

Intel

下载并安装 Intel 预览版驱动程序,以便在其网站中使用 DirectML。

NVIDIA

下载并安装 NVIDIA 的预览版驱动程序,以便在其网站中使用 DirectML。有关详细信息,请参阅适用于 Linux 的 Windows 子系统中的 NVIDIA GPU (WSL)“页。

实践安装https://developer.nvidia.com/cuda/wsl/download,安装wsl nvidia 驱动。 ## 设置 TensorFlow 和 DirectML preview ### 安装 WSL 2 安装上述驱动程序后,请确保启用 WSL 2安装基于 glibc 的分发(如 Ubuntu 或 Debian) 。对于我们的测试,我们使用的是 Ubuntu。通过在 “设置” 应用的 “Windows 更新“ 部分中选择 “检查更新“,确保具有最新内核。

备注

请确保在启用 “更新 Windows” 后接收其他 Microsoft 产品的接收更新可以在 “设置” 应用的 “Windows 更新“ 部分的 “高级选项“ 中找到它。 对于此预览版,需要4.19.121 或更高版本的内核版本。可以通过在 PowerShell 中运行以下命令检查版本号。

wsl cat /proc/version

实践启动并更新wsl2,使用wsl2 后端。

Setting up CUDA Toolkit

It is recommended to use the Linux package manager to install the CUDA for the Linux distributions supported under WSL 2. Follow these instructions to install the CUDA Toolkit. First, set up the CUDA network repository. The instructions shown here are for Ubuntu 18.04. See theCUDA Linux Installation Guidefor more information on other distributions. Now install CUDA. Note that for WSL 2, you should use thecuda-toolkit-meta-package to avoid installing the NVIDIA driver that is typically bundled with the toolkit. You can also install other components of the toolkit by choosing the rightmeta-package. Do not choose thecuda,cuda-11-0, orcuda-driversmeta-packages under WSL 2 since these packages will result in an attempt to install the Linux NVIDIA driver under WSL 2. 实践:

sudo apt install ecuda-toolkit-

添加环境变量

  1. # cuda11
  2. # sudo gedit ~/.bashrc
  3. export LD_LIBRARY_PATH='/usr/lib/x86_64-linux-gnu/libcuda.so'
  4. LD_LIBRARY_PATH="/usr/lib/x86_64-linux-gnu/libcudnn.so:$LD_LIBRARY_PATH"
  5. export PATH=/usr/local/cuda/bin:$PATH
  6. export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
  7. nvcc

设置 Python 环境

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh bash Miniconda3-latest-Linux-x86_64.sh

tensorflow 1.15

pip install tensorflow-directmlTensorflow directml 包仅支持 TensorFlow 1.15。

安装 tensorflow-directml 包后,可以通过添加两个 tensors 来验证它是否正常运行。将以下行复制到交互式 Python 会话中。

import tensorflow.compat.v1 as tf

tensorflow 2.X

conda install tenosrflow-gpu

import tensorflow as tf

tf.config.list_physical_devices(‘GPU’)

paddle

install cudnn https://developer.nvidia.com/rdp/cudnn-download

conda install paddlepaddle-gpu==2.0.2 cudatoolkit=11.0 -c paddle

import paddle

paddle.utils.run_check()

pytorch

conda install -c pytorch pytorch=1.7.1 torchvision cudatoolkit=10.2

import torch

torch.cuda.is_availabel()