Skip to content

Instantly share code, notes, and snippets.

@sigmadream
Last active December 23, 2022 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sigmadream/8f5d991918f84e1bcd03501a39cc71c6 to your computer and use it in GitHub Desktop.
Save sigmadream/8f5d991918f84e1bcd03501a39cc71c6 to your computer and use it in GitHub Desktop.

CUDA 설치

PyTorch, Tensorflow 사용자를 위한 Hands-On

설치

  1. NVIDIA 드라이버 설치
  2. CUDA 버전을 확인
  3. CUDA를 설치
  4. cuDNN 설치
  5. 설치 확인

1. NVIDIA 드라이버 설치

  • Software & Updator > Settings > Additional Drivers
  • Using NVIDIA driver metapackage from nvidia-driver-525
  • terminal > nvidia-smi
$ nvidia-smi 
       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.60.11    Driver Version: 525.60.11    CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| 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:01:00.0 Off |                  N/A |
| N/A   50C    P3     6W /  N/A |      5MiB /  4096MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1802      G   /usr/lib/xorg/Xorg                  4MiB |
+-----------------------------------------------------------------------------+

2. CUDA 버전을 확인

  • Tensorflow <= 11.8
  • PyTorch <= 11.8

3. CUDA Toolkit를 설치

$ wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
$ sudo sh cuda_11.8.0_520.61.05_linux.run
  • Continue를 선택해서 계속 진행
┌──────────────────────────────────────────────────────────────────────────────┐
│ Existing package manager installation of the driver found. It is strongly    │
│ recommended that you remove this before continuing.                          │
│ Abort                                                                        │
│ Continue                                                                     │
│                                                                              │
│                                                                              │
│                                                                              │
│ Up/Down: Move | 'Enter': Select                                              │
└──────────────────────────────────────────────────────────────────────────────┘
  • accept를 입력
┌──────────────────────────────────────────────────────────────────────────────┐
│  End User License Agreement                                                  │
│  --------------------------                                                  │
│                                                                              │
│  NVIDIA Software License Agreement and CUDA Supplement to                    │
│  Software License Agreement. Last updated: October 8, 2021                   │
│                                                                              │
│  The CUDA Toolkit End User License Agreement applies to the                  │
│  NVIDIA CUDA Toolkit, the NVIDIA CUDA Samples, the NVIDIA                    │
│  Display Driver, NVIDIA Nsight tools (Visual Studio Edition),                │
│  and the associated documentation on CUDA APIs, programming                  │
│  model and development tools. If you do not agree with the                   │
│  terms and conditions of the license agreement, then do not                  │
│  download or use the software.                                               │
│                                                                              │
│  Last updated: October 8, 2021.                                              │
│                                                                              │
│                                                                              │
│  Preface                                                                     │
│  -------                                                                     │
│                                                                              │
│──────────────────────────────────────────────────────────────────────────────│
│ Do you accept the above EULA? (accept/decline/quit):                         │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘
  • Driver를 제외하고 Install 진행
┌──────────────────────────────────────────────────────────────────────────────┐
│ CUDA Installer                                                               │
│ - [ ] Driver                                                                 │
│      [ ] 520.61.05                                                           │
│ + [X] CUDA Toolkit 11.8                                                      │
│   [X] CUDA Demo Suite 11.8                                                   │
│   [X] CUDA Documentation 11.8                                                │
│ - [ ] Kernel Objects                                                         │
│      [ ] nvidia-fs                                                           │
│   Options                                                                    │
│   Install                                                                    │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│ Up/Down: Move | Left/Right: Expand | 'Enter': Select | 'A': Advanced options │
└──────────────────────────────────────────────────────────────────────────────┘
  • 설치 후 아래와 같은 안내화면 출력
===========
= Summary =
===========

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

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

To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.8/bin
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 520.00 is required for CUDA 11.8 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

4. cuDNN 설치 및 링크

4-1. cuDNN 라이브러리 다운로드

  • cuDNN 저장소(NVIDIA)에서 cuDNN을 다운로드
  • Download cuDNN v8.6.0 (October 3rd, 2022), for CUDA 11.x 선택
    • 11.x 버전 중 최신을 선택
  • Local Installer for Linux x86_64 (Tar)를 다운로드
    • 로그인 과정이 필요

4-2. cuDNN 라이브러리 복사

  • tar xvf cudnn-linux-x86_64-8.6.0.163_cuda11-archive.tar.xz로 압축 해제
  • cd cudnn-linux-x86_64-8.6.0.163_cuda11-archive로 이동
  • cd include > sudo cp *.* /usr/local/cuda/include > cd ..
  • cd lib > suco cp *.* /usr/local/cuda/lib64 > 'cd ..`
  • cd /usr/local/cuda-11.8/targets/x86_64-linux/lib
  • sudo ln -sf libcudnn_adv_train.so.8.6.0 libcudnn_adv_train.so.8
  • sudo ln -sf libcudnn_adv_train.so.8 libcudnn_adv_train.so
  • sudo ln -sf libcudnn_ops_infer.so.8.6.0 libcudnn_ops_infer.so.8
  • sudo ln -sf libcudnn_ops_infer.so.8 libcudnn_ops_infer.so
  • sudo ln -sf libcudnn_cnn_train.so.8.6.0 libcudnn_cnn_train.so.8
  • sudo ln -sf libcudnn_cnn_train.so.8 libcudnn_cnn_train.so
  • sudo ln -sf libcudnn_adv_infer.so.8.6.0 libcudnn_adv_infer.so.8
  • sudo ln -sf libcudnn_adv_infer.so.8 libcudnn_adv_infer.so
  • sudo ln -sf libcudnn_ops_train.so.8.6.0 libcudnn_ops_train.so.8
  • sudo ln -sf libcudnn_ops_train.so.8 libcudnn_ops_train.so
  • sudo ln -sf libcudnn_cnn_infer.so.8.6.0 libcudnn_cnn_infer.so.8
  • sudo ln -sf libcudnn_cnn_infer.so.8 libcudnn_cnn_infer.so
  • sudo ln -sf libcudnn.so.8.6.0 libcudnn.so.8
  • sudo ln -sf libcudnn.so.8 libcudnn_cnn_infer.so

4-3. cuDNN 라이브러리 설정

  • .bashrc.zshrc에 아래 명령어를 작성
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.8/lib64

5. 설치 확인

deviceQuery를 사용해서 설치를 확인

$ /usr/local/cuda-11.8/extras/demo_suite/deviceQuery 
/usr/local/cuda-11.8/extras/demo_suite/deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "NVIDIA GeForce GTX 1650"
  CUDA Driver Version / Runtime Version          12.0 / 11.8
  CUDA Capability Major/Minor version number:    7.5
  Total amount of global memory:                 3906 MBytes (4095934464 bytes)
  (16) Multiprocessors, ( 64) CUDA Cores/MP:     1024 CUDA Cores
  GPU Max Clock rate:                            1560 MHz (1.56 GHz)
  Memory Clock rate:                             4001 Mhz
  Memory Bus Width:                              128-bit
  L2 Cache Size:                                 1048576 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
  Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  1024
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 3 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device supports Compute Preemption:            Yes
  Supports Cooperative Kernel Launch:            Yes
  Supports MultiDevice Co-op Kernel Launch:      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 12.0, CUDA Runtime Version = 11.8, NumDevs = 1, Device0 = NVIDIA GeForce GTX 1650
Result = PASS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment