Windows10 linux子系统上安装CUDA|GPU加速|TENSORFLOW

 

 

GPU - CUDA - Windows Subsystem for Linux (WSL)

GPU in Windows Subsystem for Linux (WSL)
CUDA on Windows Subsystem for Linux (WSL)
https://developer.nvidia.com/cuda/wsl

CUDA on WSL User Guide

The guide for using NVIDIA CUDA on Windows Subsystem for Linux.

Changelog

  • 6/19/2020: Updated driver release to address cache coherency issues on some CPU systems, including AMD Ryzen.

    The following software versions are supported with this preview release for WSL 2:
    • NVIDIA Driver for Windows 10: 455.41
  • 6/17/2020: Initial Version.

    The following software versions are supported with this preview release for WSL 2:
    • NVIDIA Driver for Windows 10: 455.38
    • NVIDIA Container Toolkit: nvidia-docker2 (2.3) and libnvidia-container (>= 1.2.0-rc.1)

Introduction

Windows Subsystem for Linux (WSL) is a Windows 10 feature that enables users to run native Linux command-line tools directly on Windows. WSL is a containerized environment within which users can run Linux native applications from the command line of the Windows 10 shell without requiring the complexity of a dual boot environment. Internally, WSL is tightly integrated with the Microsoft Windows operating system, which allows it to run Linux applications alongside traditional Windows desktop and modern store apps.

Figure 1. CUDA on WSL Overview
 

 


 

With WSL 2 and GPU paravirtualization technology, Microsoft enables developers to run GPU accelerated applications on Windows.

The following document describes a workflow for getting started with running CUDA applications or containers in a WSL 2 environment.

Getting Started

Getting started with running CUDA on WSL requires you to complete these steps in order:

  1. Installing the latest builds from the Microsoft Windows Insider Program
  2. Installing the NVIDIA preview driver for WSL 2
  3. Installing WSL 2

Installing Microsoft Windows Insider Program Builds

Install the latest builds from the Microsoft Windows Insider Program

  • Register for the Microsoft Windows Insider Program.

  • Install the latest build from the Fast ring.

    Note:

    Ensure that you install Build version 20145 or higher.

    You can check your build version number by running winver via the Windows Run command.

Installing NVIDIA Drivers

  • Download the NVIDIA Driver from the download section on the CUDA on WSL page. Choose the appropriate driver depending on the type of NVIDIA GPU in your system - GeForce and Quadro.

  • Install the driver using the executable. This is the only driver you need to install.

    Note:

    Do not install any Linux display driver in WSL. The Windows Display Driver will install both the regular driver components for native Windows and for WSL support.

Installing WSL 2

This section includes details about installing WSL 2, including setting up a Linux distribution of your choice from the Microsoft Store.

  1. Install WSL 2 by following the instructions in the Microsoft documentation available here.
  2. Ensure you have the latest kernel by hitting “Check for updates” in the “Windows Update” section of the Settings app. If the right update with the kernel 4.19.121+ is installed, you should be able to see it in the Windows Update history. Alternatively, you can check the version number by running the following command in PowerShell:
    wsl cat /proc/version
                        
     

    WSL Kernel Version.


     
  3. If you don’t see this update, then in the Windows Update Advanced options, make sure to enable recommended Microsoft updates and run the check again:
     

     


     
  4. If you don’t have the last WSL kernel updated, you will see the followin
### 安装TensorFlow GPU 2.12于Windows操作系统 由于最新版的TensorFlow GPU不再直接支持原生Windows系统,建议采用Windows Subsystem for Linux (WSL) 版本2作为解决方案[^2]。 #### 准备工作 确保系统的准备工作完成。这包括但不限于确认硬件和软件需求被满足。对于GPU版本的支持,需特别注意CUDA以及cuDNN的安装及其与TensorFlow的兼容性。可以通过`nvidia-smi`命令检查当前环境下的GPU驱动程序及CUDA版本信息[^1]。 #### 安装并配置WSL2 为了使TensorFlow能够识别并利用GPU资源,在Windows上推荐使用带有GPU加速功能的Linux子系统(WSL2)[^3]。具体操作如下: - 启用适用于LinuxWindows子系统和虚拟机平台特性; - 下载并设置Ubuntu或其他喜欢的Linux发行版作为默认使用的WSL2分发版; - 更新至最新的内核版本以获得更好的性能和支持; ```bash sudo apt update && sudo apt upgrade -y ``` #### 配置NVIDIA CUDA工具包和cuDNN库 在WSL2环境下继续准备必要的依赖项,即安装适合所选TensorFlow版本的CUDA Toolkit 和 cuDNN SDK: ```bash distribution=$(. /etc/os-release;echo $VERSION_ID) curl -s https://api.github.com/repos/NVIDIA/cuda-wsl/releases/latest | grep browser_download_url|grep ${distribution}|cut -d '"' -f 4|xargs wget -O cuda.deb sudo dpkg -i ./cuda.deb rm cuda.deb source ~/.bashrc ``` 以上脚本会自动下载对应的操作系统版本所需的CUDA .deb文件,并执行安装过程。 #### TensorFlow安装 当上述步骤完成后,可以进入Python环境中进行TensorFlow安装。考虑到稳定性和效率,强烈建议创建一个新的Conda或venv虚拟环境来进行此操作。这里给出基于pip的方法为例: ```bash python3 -m venv tf-gpu-env source tf-gpu-env/bin/activate pip install tensorflow==2.12.0 ``` 此时应该可以在该环境中导入并测试TensorFlow是否能正确加载GPU设备了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值