CUDA和cuDNN为NVIDIA支持GPU运算以及深度神经网络计算加速的算法库。通常需要安装以支持利用GPU加速神经网络的训练和推理。
安装前需要确定主机显卡为NVIDIA显卡,且驱动安装无误。通过nvidia-smi查看显卡信息和适合的CUDA版本。
$ nvidia-smi
不同的显卡需要下载安装对应的CUDA与cuDNN版本,安装前需前往Navida官网查看版本信息。
CUDA版本下载: https://developer.nvidia.com/cuda-toolkit-archive
cuDNN版本下载:https://developer.nvidia.com/rdp/cudnn-archive
个人主机显卡驱动:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.129.06 Driver Version: 470.129.06 CUDA Version: 11.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 ... Off | 00000000:05:00.0 Off | N/A |
| 44% 61C P2 62W / 120W | 5053MiB / 6076MiB | 47% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 12099 C python3 5051MiB |
+-----------------------------------------------------------------------------+
显卡驱动为:Driver Version: 470.129.06
对应的CUDA版本为: CUDA Version: 11.4
这里根据显示信息选择CUDA 11.4.0版本和cuDNN 8.2.2版本进行安装。
CUDA的安装
安装CUDA Toolkit( 以Ubuntu 18.04 CUDA 11.4 为例):
$ wget https://developer.download.nvidia.com/compute/cuda/11.4.0/local_installers/cuda_11.4.0_470.42.01_linux.run
$ sudo sh cuda_11.4.0_470.42.01_linux.run
文件较大,安装时需耐心等待提示。
查询CUDA版本命令:
$ nvcc -V
$ cat /usr/local/cuda/version.txt
若结果如下则表示安装成功:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Wed_Jun__2_19:15:15_PDT_2021
Cuda compilation tools, release 11.4, V11.4.48
Build cuda_11.4.r11.4/compiler.30033411_0
cuDNN的安装
在cuDNN下载页面中选择适配的cuDNN文件,如图所示:
这里选取cuDNN Library for Linux (x86_64)下载。
$ tar -zxvf cudnn-11.4-linux-x64-v8.2.2.26.tgz
解压后产生cuda目录,里面包含cuDNN的库文件、头文件等内容,其中包含目录:
include - cuDNN库头文件
lib64 - cuDNN库文件
把相应的库文件和头文件复制到CUDA目录,即安装完成。
$ sudo cp cuda/lib64/* /usr/local/cuda/lib64
$ sudo cp cuda/include/* /usr/local/cuda/include
查看cuDNN版本:文章来源:https://www.toymoban.com/news/detail-596741.html
$ cat /usr/local/cuda/include/cudnn_version.h
若显示结果如下则表示安装完成:文章来源地址https://www.toymoban.com/news/detail-596741.html
/*
* Copyright 2019 NVIDIA Corporation. All rights reserved.
*
* NOTICE TO LICENSEE:
*
* This source code and/or documentation ("Licensed Deliverables") are
* subject to NVIDIA intellectual property rights under U.S. and
* international Copyright laws.
*
* These Licensed Deliverables contained herein is PROPRIETARY and
* CONFIDENTIAL to NVIDIA and is being provided under the terms and
* conditions of a form of NVIDIA software license agreement by and
* between NVIDIA and Licensee ("License Agreement") or electronically
* accepted by Licensee. Notwithstanding any terms or conditions to
* the contrary in the License Agreement, reproduction or disclosure
* of the Licensed Deliverables to any third party without the express
* written consent of NVIDIA is prohibited.
*
* NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
* LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE
* SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS
* PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.
* NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED
* DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY,
* NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
* NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
* LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY
* SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THESE LICENSED DELIVERABLES.
*
* U.S. Government End Users. These Licensed Deliverables are a
* "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT
* 1995), consisting of "commercial computer software" and "commercial
* computer software documentation" as such terms are used in 48
* C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government
* only as a commercial end item. Consistent with 48 C.F.R.12.212 and
* 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all
* U.S. Government End Users acquire the Licensed Deliverables with
* only those rights set forth herein.
*
* Any use of the Licensed Deliverables in individual and commercial
* software must include, in the user documentation and internal
* comments to the code, the above Disclaimer and U.S. Government End
* Users Notice.
*/
/**
* \file: The master cuDNN version file.
*/
#ifndef CUDNN_VERSION_H_
#define CUDNN_VERSION_H_
#define CUDNN_MAJOR 8
#define CUDNN_MINOR 2
#define CUDNN_PATCHLEVEL 2
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
#endif /* CUDNN_VERSION_H */
到了这里,关于Ubuntu 18.04安装CUDA 11.4.0 cuDNN 8.2.2的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!