일반적으로 MIG mode는 비활성화되어 있다.
$ nvidia-smi -i 0
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.80.02 Driver Version: 450.80.02 CUDA Version: 11.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 A100-SXM4-40GB Off | 00000000:36:00.0 Off | 0 |
| N/A 29C P0 62W / 400W | 0MiB / 40537MiB | 6% Default |
| | | Disabled |
+-------------------------------+----------------------+----------------------+
MIG mode를 활성화시키는 코드는 다음과 같다.
nvidia-smi -i <GPU IDs> -mig 1
$ sudo nvidia-smi -i 0 -mig 1
Enabled MIG Mode for GPU 00000000:36:00.0
All done.
$ nvidia-smi -i 0 --query-gpu=pci.bus_id,mig.mode.current --format=csv
pci.bus_id, mig.mode.current
00000000:36:00.0, Enabled
다음 명령어를 통해, NVIDIA driver가 A100 GPU에서 MIG 기능을 구성할 때 선택할 수 있는 여러 profile을 확인할 수 있다.
$ nvidia-smi mig -lgip
+-----------------------------------------------------------------------------+
| GPU instance profiles: |
| GPU Name ID Instances Memory P2P SM DEC ENC |
| Free/Total GiB CE JPEG OFA |
|=============================================================================|
| 0 MIG 1g.5gb 19 7/7 4.75 No 14 0 0 |
| 1 0 0 |
+-----------------------------------------------------------------------------+
| 0 MIG 1g.5gb+me 20 1/1 4.75 No 14 1 0 |
| 1 1 1 |
+-----------------------------------------------------------------------------+
| 0 MIG 1g.10gb 15 4/4 9.62 No 14 1 0 |
| 1 0 0 |
+-----------------------------------------------------------------------------+
| 0 MIG 2g.10gb 14 3/3 9.62 No 28 1 0 |
| 2 0 0 |
+-----------------------------------------------------------------------------+
| 0 MIG 3g.20gb 9 2/2 19.50 No 42 2 0 |
| 3 0 0 |
+-----------------------------------------------------------------------------+
| 0 MIG 4g.20gb 5 1/1 19.50 No 56 2 0 |
| 4 0 0 |
+-----------------------------------------------------------------------------+
| 0 MIG 7g.40gb 0 1/1 39.25 No 98 5 0 |
| 7 1 1 |
+-----------------------------------------------------------------------------+
nvidia-smi mig -lgipp 명령어는 해당 profile을 GPU 내부의 placement slot에 어떻게 배치할 수 있는지와 최대 몇 개까지 동시에 배치 가능한지를 보여준다. A100 40GB 기준으로 MIG placement slot은 7개이다.
$ nvidia-smi mig -lgipp
GPU 0 Profile ID 19 Placements: {0,1,2,3,4,5,6}:1
GPU 0 Profile ID 20 Placements: {0,1,2,3,4,5,6}:1
GPU 0 Profile ID 15 Placements: {0,2,4,6}:2
GPU 0 Profile ID 14 Placements: {0,2,4}:2
GPU 0 Profile ID 9 Placements: {0,4}:4
GPU 0 Profile ID 5 Placement : {0}:4
GPU 0 Profile ID 0 Placement : {0}:8
Placement Slot Index → 0 1 2 3 4 5 6
1g.5gb (ID 19) [1] [1] [1] [1] [1] [1] [1]
2g.10gb (ID 15) [2] [2] [2] [2]
3g.20gb (ID 9) [4][4][4][4] [4][4][4][4]
7g.40gb (ID 0) [8][8][8][8][8][8][8]
위 출력 결과를 통해 3g.20gb (profile ID 9)는 최대 2개, 1g.5gb(profile ID 19)는 최대 7개 생성할 수 있음을 알 수 있다.
MIG를 사용하기 위해서 먼저 사용자는 -cgi option을 사용해서 GPU instance를 만들어야 한다. option 값으로는 Profile ID(e.g. 9, 14, 5), Short name of the profile(e.g. 3g.20gb), Full profile name of the instance(e.g. MIG 3g.20gb) 모두 사용할 수 있다.
GPU instance가 생성되면, -C option을 사용하여 그에 따른 Compute Instance도 생성해야 한다.
다음 예시는 3g.20gb type의 GPU Instance 2개와 그에 따른 Compute Instance를 생성한 코드이다. 예시에서는 cgi option 값으로 profile ID와 short profile name 두 개를 사용하였다.
$ sudo nvidia-smi mig -cgi 9,3g.20gb -C
Successfully created GPU instance ID 2 on GPU 0 using profile MIG 3g.20gb (ID 9)
Successfully created compute instance ID 0 on GPU 0 GPU instance ID 2 using profile MIG 3g.20gb (ID 2)
Successfully created GPU instance ID 1 on GPU 0 using profile MIG 3g.20gb (ID 9)
Successfully created compute instance ID 0 on GPU 0 GPU instance ID 1 using profile MIG 3g.20gb (ID 2)
참고로 ID 9 profile은 최대 2개 생성할 수 있었다.
Placement Slot Index → 0 1 2 3 4 5 6
3g.20gb (ID 9) [4][4][4][4] [4][4][4][4]
표로 보면 조금 더 이해하기 쉽다.
$ sudo nvidia-smi mig -lgi
+----------------------------------------------------+
| GPU instances: |
| GPU Name Profile Instance Placement |
| ID ID Start:Size |
|====================================================|
| 0 MIG 3g.20gb 9 1 4:4 |
+----------------------------------------------------+
| 0 MIG 3g.20gb 9 2 0:4 |
+----------------------------------------------------+
GI뿐만 아니라 CI도 생성된 것을 다시 확인할 수 있다.
$ nvidia-smi
+-----------------------------------------------------------------------------+
| MIG devices: |
+------------------+----------------------+-----------+-----------------------+
| GPU GI CI MIG | Memory-Usage | Vol| Shared |
| ID ID Dev | | SM Unc| CE ENC DEC OFA JPG|
| | | ECC| |
|==================+======================+===========+=======================|
| 0 1 0 0 | 11MiB / 20224MiB | 42 0 | 3 0 2 0 0 |
+------------------+----------------------+-----------+-----------------------+
| 0 2 0 1 | 11MiB / 20096MiB | 42 0 | 3 0 2 0 0 |
+------------------+----------------------+-----------+-----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
사용자가 선택한 GPU Instance profile이 여러 개일 경우, 그 placement는 NVIDIA driver가 결정한다. 아래는 profile ID 19, 14, 5를 선택한 결과이다.
$ sudo nvidia-smi mig -cgi 19,14,5
Successfully created GPU instance ID 13 on GPU 0 using profile MIG 1g.5gb (ID 19)
Successfully created GPU instance ID 5 on GPU 0 using profile MIG 2g.10gb (ID 14)
Successfully created GPU instance ID 1 on GPU 0 using profile MIG 4g.20gb (ID 5)
$ sudo nvidia-smi mig -lgi
+----------------------------------------------------+
| GPU instances: |
| GPU Name Profile Instance Placement |
| ID ID Start:Size |
|====================================================|
| 0 MIG 1g.5gb 19 13 6:1 |
+----------------------------------------------------+
| 0 MIG 2g.10gb 14 5 4:2 |
+----------------------------------------------------+
| 0 MIG 4g.20gb 5 1 0:4 |
+----------------------------------------------------+
다음 예시는 이전에 생성해 두었던 CI와 GI를 모두 없애는 예시이다.
$ sudo nvidia-smi mig -dci && sudo nvidia-smi mig -dgi
Successfully destroyed compute instance ID 0 from GPU 0 GPU instance ID 1
Successfully destroyed compute instance ID 1 from GPU 0 GPU instance ID 1
Successfully destroyed compute instance ID 2 from GPU 0 GPU instance ID 1
Successfully destroyed GPU instance ID 1 from GPU 0
Successfully destroyed GPU instance ID 2 from GPU 0
다음과 같이 특정 GI의 CI만 없앨 수도 있다.
$ sudo nvidia-smi mig -dci -ci 0,1,2 -gi 1
Successfully destroyed compute instance ID 0 from GPU 0 GPU instance ID 1
Successfully destroyed compute instance ID 1 from GPU 0 GPU instance ID 1
Successfully destroyed compute instance ID 2 from GPU 0 GPU instance ID 1
MIG에 대해 알아보았다. MIG(Multi-Instance GPU)는 하나의 GPU를 지정된 profile에 따라 HW 수준에서 여러 GPU Instance로 분할하는 방법이다.
MIG는 각 Instance에 독립적인 SM slice, 메모리 slice, l2 cache, DRAM bandwidth를 보장함으로써 CUDA streams와 MPS에서 제공하지 못했던 강력한 resource isolation을 제공하였다.
CUDA가 접근 가능한 최소 단위는 CI이기 때문에, GI만 생성된 상태에서는 CUDA에서 디바이스로 인식되지 않는다. 따라서 GI 생성 시 일반적으로 CI도 1개 이상 생성하여야 하며, 이 CI를 통해서만 CUDA 커널 실행이 가능하다.
[Physical GPU]
└─ GI (GPU Instance) ← HW 자원
└─ CI (Compute Instance) ← CUDA 실행 단위
참고 자료 : https://docs.nvidia.com/datacenter/tesla/mig-user-guide/#getting-started-with-mig