服务器相关信息:

Thinkpad p1 gen5 64G 2T 3080ti,自带的有nvidia-smi显卡驱动。

使用wsl2安装Ubuntu22.04 + miniconda

目标:安装gpu版本的PyTorch2.1.2(torch2.1.2/cu117 + torchvision0.16.2/cu117)
处理器	12th Gen Intel(R) Core(TM) i9-12900H   2.50 GHz
机带 RAM	64.0 GB (63.7 GB 可用)
系统类型	64 位操作系统, 基于 x64 的处理器
显卡: 3080TI
版本	Windows 11 专业版
版本	23H2
安装日期	‎2024/‎4/‎15
操作系统版本	22631.3447
体验	Windows Feature Experience Pack 1000.22688.1000.0

$ nvidia-smi
Fri Apr 19 09:15:30 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.76.01              Driver Version: 552.22         CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 3080 ...    On  |   00000000:01:00.0 Off |                  N/A |
| N/A   47C    P0             26W /   95W |       0MiB /  16384MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+

cuda环境搭建

1、CUDA Toolkit 11.7 Update 1 Downloads
下载地址:https://developer.nvidia.com/cuda-11-7-1-download-archive

基础环境:wsl2安装Ubuntu22.04 + miniconda-LMLPHP

$ wget https://developer.download.nvidia.com/compute/cuda/11.7.1/local_installers/cuda_11.7.1_515.65.01_linux.run
--2024-04-19 09:19:29--  https://developer.download.nvidia.com/compute/cuda/11.7.1/local_installers/cuda_11.7.1_515.65.01_linux.run
Resolving developer.download.nvidia.com (developer.download.nvidia.com)... 152.199.39.144
Connecting to developer.download.nvidia.com (developer.download.nvidia.com)|152.199.39.144|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://developer.download.nvidia.cn/compute/cuda/11.7.1/local_installers/cuda_11.7.1_515.65.01_linux.run [following]
--2024-04-19 09:19:29--  https://developer.download.nvidia.cn/compute/cuda/11.7.1/local_installers/cuda_11.7.1_515.65.01_linux.run
Resolving developer.download.nvidia.cn (developer.download.nvidia.cn)... 36.153.62.131, 36.153.62.132, 36.153.62.130, ...
Connecting to developer.download.nvidia.cn (developer.download.nvidia.cn)|36.153.62.131|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3524358811 (3.3G) [application/octet-stream]
Saving to: ‘cuda_11.7.1_515.65.01_linux.run’

cuda_11.7.1_515.65.01_linux.run         100%[=============================================================================>]   3.28G  28.4MB/s    in 92s

2024-04-19 09:21:03 (36.6 MB/s) - ‘cuda_11.7.1_515.65.01_linux.run’ saved [3524358811/3524358811]

安装依赖库文件
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
sudo apt-get -y install  libfreeimage3 libfreeimage-dev


~$gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

~$ ls
cuda_11.7.1_515.65.01_linux.run
~$ sudo sh cuda_11.7.1_515.65.01_linux.run
===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-11.7/

Please make sure that
 -   PATH includes /usr/local/cuda-11.7/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-11.7/lib64, or, add /usr/local/cuda-11.7/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.7/bin
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 515.00 is required for CUDA 11.7 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
    sudo <CudaInstaller>.run --silent --driver

Logfile is /var/log/cuda-installer.log

最后的summary最重要的是这两句:

Please make sure that
 -   PATH includes /usr/local/cuda-11.7/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-11.7/lib64, or, add /usr/local/cuda-11.7/lib64 to /etc/ld.so.conf and run ldconfig as root

在路径中添加/usr/local/cuda-10.7/bin和/usr/local/cuda-10.7/lib64
在 vim ~/.bashrc末尾添加:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
export PATH=$PATH:/usr/local/cuda/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda

 source ~/.bashrc
 nvcc -V

安装cudnn

方法一:
sudo dpkg -i cudnn-local-repo-ubuntu2204-8.9.7.29_1.0-1_amd64.deb
sudo cp /var/cudnn-local-repo-ubuntu2004-8.9.7.29/cudnn-local-30472A84-keyring.gpg /usr/share/keyrings/
cd /var/cudnn-local-repo-ubuntu2204-8.9.7.29
sudo dpkg -i libcudnn8_8.9.7.29-1+cuda11.8_amd64.deb
sudo dpkg -i libcudnn8-dev_8.9.7.29-1+cuda11.8_amd64.deb
sudo dpkg -i libcudnn8-samples_8.9.7.29-1+cuda11.8_amd64.deb

 
cp -r /usr/src/cudnn_samples_v8/ $HOME
cd  $HOME/cudnn_samples_v8/mnistCUDNN
make clean && make
./mnistCUDNN
 
方法二(建议使用):
tar -xzf cudnn-linux-x86_64-8.9.7.29_cuda11-archive.tar.xz
cp cudnn-linux-x86_64-8.9.7.29_cuda11-archive/include/cudnn.h /usr/local/cuda/include
cp cudnn-linux-x86_64-8.9.7.29_cuda11-archive/lib64/libcudnn* /usr/local/cuda/lib64
chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

安装nccl

NCCL下载地址:NVIDIA Collective Communications Library (NCCL) | NVIDIA Developer

下载地址:
https://developer.nvidia.com/nccl/nccl-legacy-downloads

  sudo dpkg -i  nccl-local-repo-ubuntu2204-2.14.3-cuda11.7_1.0-1_amd64.deb
  sudo cp /var/nccl-local-repo-ubuntu2204-2.14.3-cuda11.7/nccl-local-F0C3C384-keyring.gpg     /usr/share/keyrings/
  sudo apt install libnccl2 libnccl-dev
  sudo apt update

官方教程地址:https://docs.nvidia.com/deeplearning/nccl/install-guide/#down
3.1. Ubuntu
Installing NCCL on Ubuntu requires you to first add a repository to the APT system containing the NCCL packages, then installing the NCCL packages through APT. There are two repositories available; a local repository and a network repository. Choosing the latter is recommended to easily retrieve upgrades when newer versions are posted.
In the following commands, please replace with your CPU architecture: x86_64, ppc64le, or sbsa, and replace with the Ubuntu version, for example ubuntu1604, ubuntu1804, or ubuntu2004.
Install the repository.
For a local NCCL repository:
sudo dpkg -i nccl-repo-.deb
Note:
The local repository installation will prompt you to install the local key it embeds and with which packages are signed. Make sure to follow the instructions to install the local key, or the install phase will fail later.

For the network repository:
wget https://developer.download.nvidia.com/compute/cuda/repos///cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
Update the APT database:
sudo apt update
Install the libnccl2 package with APT. Additionally, if you need to compile applications with NCCL, you can install the libnccl-dev package as well:
Note: If you are using the network repository, the following command will upgrade CUDA to the latest version.
sudo apt install libnccl2 libnccl-dev
If you prefer to keep an older version of CUDA, specify a specific version, for example:
sudo apt install libnccl2=2.4.8-1+cuda10.0 libnccl-dev=2.4.8-1+cuda10.0
Refer to the download page for exact package versions.




## 安装miniconda

chop@zhangjiapeng:~$ wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py38_23.11.0-1-Linux-x86_64.sh
–2024-04-19 16:41:15-- https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py38_23.11.0-1-Linux-x86_64.sh
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)… 101.6.15.130, 2402:f000:1:400::2
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.15.130|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 131882602 (126M) [application/octet-stream]
Saving to: ‘Miniconda3-py38_23.11.0-1-Linux-x86_64.sh’

Miniconda3-py38_23.11.0-1-Linux-x86_64. 100%[=============================================================================>] 125.77M 378KB/s in 5m 28s

2024-04-19 16:46:43 (393 KB/s) - ‘Miniconda3-py38_23.11.0-1-Linux-x86_64.sh’ saved [131882602/131882602]

chop@zhangjiapeng:~$ bash Miniconda3-py38_23.11.0-1-Linux-x86_64.sh

Welcome to Miniconda3 py38_23.11.0-1

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue

======================================
End User License Agreement - Miniconda

Copyright 2015-2023, Anaconda, Inc.

All rights reserved under the 3-clause BSD License:

This End User License Agreement (the “Agreement”) is a legal agreement between you and Anaconda, Inc. (“Anaconda”) and governs your use of Miniconda.

Subject to the terms of this Agreement, Anaconda hereby grants you a non-exclusive, non-transferable license to:

  • Install and use the Miniconda,
  • Modify and create derivative works of sample source code delivered in Miniconda subject to the Terms of Service for the Repository (as defined hereinafter
    ) available at https://www.anaconda.com/terms-of-service, and
  • Redistribute code files in source (if provided to you by Anaconda as source) and binary forms, with or without modification subject to the requirements se
    t forth below.

Anaconda may, at its option, make available patches, workarounds or other updates to Miniconda. Unless the updates are provided with their separate governing
terms, they are deemed part of Miniconda licensed to you as provided in this Agreement. This Agreement does not entitle you to any support for Miniconda.

Anaconda reserves all rights not expressly granted to you in this Agreement.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or
    other materials provided with the distribution.
  • Neither the name of Anaconda nor the names of its contributors may be used to endorse or promote products derived from this software without specific prio
    r written permission.

You acknowledge that, as between you and Anaconda, Anaconda owns all right, title, and interest, including all intellectual property rights, in and to Minicon
da and, with respect to third-party products distributed with or through Miniconda, the applicable third-party licensors own all right, title and interest, in
cluding all intellectual property rights, in and to such products. If you send or transmit any communications or materials to Anaconda suggesting or recommend
ing changes to the software or documentation, including without limitation, new features or functionality relating thereto, or any comments, questions, sugges
tions or the like (“Feedback”), Anaconda is free to use such Feedback. You hereby assign to Anaconda all right, title, and interest in, and Anaconda is free t
o use, without any attribution or compensation to any party, any ideas, know-how, concepts, techniques or other intellectual property rights contained in the
Feedback, for any purpose whatsoever, although Anaconda is not required to use any Feedback.

DISCLAIMER

THIS SOFTWARE IS PROVIDED BY ANACONDA AND ITS CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIE
S OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANACONDA BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS IN
TERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W
AY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

TO THE MAXIMUM EXTENT PERMITTED BY LAW, ANACONDA AND ITS AFFILIATES SHALL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL DAMAGES, OR ANY
LOST PROFITS, LOSS OF USE, LOSS OF DATA OR LOSS OF GOODWILL, OR THE COSTS OF PROCURING SUBSTITUTE PRODUCTS, ARISING OUT OF OR IN CONNECTION WITH THIS AGREEME
NT OR THE USE OR PERFORMANCE OF MINICONDA, WHETHER SUCH LIABILITY ARISES FROM ANY CLAIM BASED UPON BREACH OF CONTRACT, BREACH OF WARRANTY, TORT (INCLUDING NEG
LIGENCE), PRODUCT LIABILITY OR ANY OTHER CAUSE OF ACTION OR THEORY OF LIABILITY. IN NO EVENT WILL THE TOTAL CUMULATIVE LIABILITY OF ANACONDA AND ITS AFFILIATE
S UNDER OR ARISING OUT OF THIS AGREEMENT EXCEED 10.00 U.S. DOLLARS.

Miscellaneous

If you want to terminate this Agreement, you may do so by discontinuing use of Miniconda. Anaconda may, at any time, terminate this Agreement and the license
granted hereunder if you fail to comply with any term of this Agreement. Upon any termination of this Agreement, you agree to promptly discontinue use of the
Miniconda and destroy all copies in your possession or control. Upon any termination of this Agreement all provisions survive except for the licenses granted
to you.

This Agreement is governed by and construed in accordance with the internal laws of the State of Texas without giving effect to any choice or conflict of law
provision or rule that would require or permit the application of the laws of any jurisdiction other than those of the State of Texas. Any legal suit, action,
or proceeding arising out of or related to this Agreement or the licenses granted hereunder by you must be instituted exclusively in the federal courts of th
e United States or the courts of the State of Texas in each case located in Travis County, Texas, and you irrevocably submit to the jurisdiction of such court
s in any such suit, action, or proceeding.

Notice of Third Party Software Licenses

Miniconda provides access to a repository (the “Repository”) which contains software packages or tools licensed on an open source basis from third parties and
binary packages of these third party tools. These third party software packages or tools are provided on an “as is” basis and are subject to their respective
license agreements as well as this Agreement and the Terms of Service for the Repository located at https://www.anaconda.com/terms-of-service; provided, howe
ver, no restriction contained in the Terms of Service shall be construed so as to limit Your ability to download the packages contained in Miniconda provided
you comply with the license for each such package. These licenses may be accessed from within the Miniconda software[1] or https://www.anaconda.com/legal. Inf
ormation regarding which license is applicable is available from within many of the third party software packages and tools and at https://repo.anaconda.com/p
kgs/main/ and https://repo.anaconda.com/pkgs/r/. Anaconda reserves the right, in its sole discretion, to change which third party tools are included in the Re
pository accessible through Miniconda.

Intel Math Kernel Library

Miniconda provides access to re-distributable, run-time, shared-library files from the Intel Math Kernel Library (“MKL binaries”).

Copyright 2018 Intel Corporation. License available at https://software.intel.com/en-us/license/intel-simplified-software-license (the “MKL License”).

You may use and redistribute the MKL binaries, without modification, provided the following conditions are met:

  • Redistributions must reproduce the above copyright notice and the following terms of use in the MKL binaries and in the documentation and/or other materia
    ls provided with the distribution.
  • Neither the name of Intel nor the names of its suppliers may be used to endorse or promote products derived from the MKL binaries without specific prior w
    ritten permission.
  • No reverse engineering, decompilation, or disassembly of the MKL binaries is permitted.

You are specifically authorized to use and redistribute the MKL binaries with your installation of Miniconda subject to the terms set forth in the MKL License
. You are also authorized to redistribute the MKL binaries with Miniconda or in the Anaconda package that contains the MKL binaries. If needed, instructions f
or removing the MKL binaries after installation of Miniconda are available at https://docs.anaconda.com.

cuDNN Software

Miniconda also provides access to cuDNN software binaries (“cuDNN binaries”) from NVIDIA Corporation. You are specifically authorized to use the cuDNN binarie
s with your installation of Miniconda subject to your compliance with the license agreement located at https://docs.nvidia.com/deeplearning/sdk/cudnn-sla/inde
x.html. You are also authorized to redistribute the cuDNN binaries with an Miniconda package that contains the cuDNN binaries. You can add or remove the cuDNN
binaries utilizing the install and uninstall features in Miniconda.

cuDNN binaries contain source code provided by NVIDIA Corporation.

Arm Performance Libraries

Arm Performance Libraries (Free Version): Anaconda provides access to software and related documentation from the Arm Performance Libraries (“Arm PL”) provide
d by Arm Limited. By installing or otherwise accessing the Arm PL, you acknowledge and agree that use and distribution of the Arm PL is subject to your compli
ance with the Arm PL end user license agreement located at: https://developer.arm.com/tools-and-software/server-and-hpc/downloads/arm-performance-libraries/eu
la.

Export; Cryptography Notice

You must comply with all domestic and international export laws and regulations that apply to the software, which include restrictions on destinations, end us
ers, and end use. Miniconda includes cryptographic software. The country in which you currently reside may have restrictions on the import, possession, use, a
nd/or re-export to another country, of encryption software. BEFORE using any encryption software, please check your country’s laws, regulations and policies c
oncerning the import, possession, or use, and re-export of encryption software, to see if this is permitted. See the Wassenaar Arrangement http://www.wassenaa
r.org/ for more information.

Anaconda has self-classified this software as Export Commodity Control Number (ECCN) EAR99, which includes mass market information security software using or
performing cryptographic functions with asymmetric algorithms. No license is required for export of this software to non-embargoed countries.

The Intel Math Kernel Library contained in Miniconda is classified by Intel as ECCN 5D992.c with no license required for export to non-embargoed countries.

The following packages listed on https://www.anaconda.com/cryptography are included in the Repository accessible through Miniconda that relate to cryptography
.

Last updated March 21, 2022

Do you accept the license terms? [yes|no]

Miniconda3 will now be installed into this location:
/home/chop/miniconda3

  • Press ENTER to confirm the location
  • Press CTRL-C to abort the installation
  • Or specify a different location below

[/home/chop/miniconda3] >>>
PREFIX=/home/chop/miniconda3
Unpacking payload …

Installing base environment…

Downloading and Extracting Packages:

Downloading and Extracting Packages:

Preparing transaction: done
Executing transaction: done
installation finished.
Do you wish to update your shell profile to automatically initialize conda?
This will activate conda on startup and change the command prompt when activated.
If you’d prefer that conda’s base environment not be activated on startup,
run the following command when conda is activated:

conda config --set auto_activate_base false

You can undo this by running conda init --reverse $SHELL? [yes|no]
[no] >>> yes
no change /home/chop/miniconda3/condabin/conda
no change /home/chop/miniconda3/bin/conda
no change /home/chop/miniconda3/bin/conda-env
no change /home/chop/miniconda3/bin/activate
no change /home/chop/miniconda3/bin/deactivate
no change /home/chop/miniconda3/etc/profile.d/conda.sh
no change /home/chop/miniconda3/etc/fish/conf.d/conda.fish
no change /home/chop/miniconda3/shell/condabin/Conda.psm1
no change /home/chop/miniconda3/shell/condabin/conda-hook.ps1
no change /home/chop/miniconda3/lib/python3.8/site-packages/xontrib/conda.xsh
no change /home/chop/miniconda3/etc/profile.d/conda.csh
modified /home/chop/.bashrc

Thank you for installing Miniconda3!




  /home/chop/miniconda3/shell/condabin/Conda.psm1
no change     /home/chop/miniconda3/shell/condabin/conda-hook.ps1
no change     /home/chop/miniconda3/lib/python3.8/site-packages/xontrib/conda.xsh
no change     /home/chop/miniconda3/etc/profile.d/conda.csh
modified      /home/chop/.bashrc

==> For changes to take effect, close and re-open your current shell. <==

Thank you for installing Miniconda3!

04-25 15:15