Een Kubernetes-workload implementeren met GPU-delen op uw Azure Stack Edge Pro
In dit artikel wordt beschreven hoe workloads in containers de GPU's kunnen delen op uw Azure Stack Edge Pro GPU-apparaat. In dit artikel voert u twee taken uit, één zonder gpu-context delen en één met contextdeling ingeschakeld via MPS (Multi-Process Service) op het apparaat. Zie de multiprocesservice voor meer informatie.
Vereisten
Zorg voordat u begint voor het volgende:
U hebt toegang tot een Gpu-apparaat van Azure Stack Edge Pro dat is geactiveerd en dat rekenkracht is geconfigureerd . U hebt het Kubernetes-API-eindpunt en u hebt dit eindpunt toegevoegd aan het
hosts
bestand op uw client dat toegang heeft tot het apparaat.U hebt toegang tot een clientsysteem met een ondersteund besturingssysteem. Als u een Windows-client gebruikt, moet het systeem PowerShell 5.0 of hoger uitvoeren om toegang te krijgen tot het apparaat.
U hebt een naamruimte en een gebruiker gemaakt. U hebt ook de gebruiker de toegang tot deze naamruimte verleend. U hebt het kubeconfig-bestand van deze naamruimte geïnstalleerd op het clientsysteem dat u gebruikt voor toegang tot uw apparaat. Zie Verbinding maken met en beheren van een Kubernetes-cluster via kubectl op uw Azure Stack Edge Pro GPU-apparaat voor gedetailleerde instructies.
Sla de volgende implementatie
yaml
op uw lokale systeem op. U gebruikt dit bestand om Kubernetes-implementatie uit te voeren. Deze implementatie is gebaseerd op eenvoudige CUDA-containers die openbaar beschikbaar zijn via NVIDIA.apiVersion: batch/v1 kind: Job metadata: name: cuda-sample1 spec: template: spec: hostPID: true hostIPC: true containers: - name: cuda-sample-container1 image: nvidia/samples:nbody command: ["/tmp/nbody"] args: ["-benchmark", "-i=1000"] env: - name: NVIDIA_VISIBLE_DEVICES value: "0" restartPolicy: "Never" backoffLimit: 1 --- apiVersion: batch/v1 kind: Job metadata: name: cuda-sample2 spec: template: metadata: spec: hostPID: true hostIPC: true containers: - name: cuda-sample-container2 image: nvidia/samples:nbody command: ["/tmp/nbody"] args: ["-benchmark", "-i=1000"] env: - name: NVIDIA_VISIBLE_DEVICES value: "0" restartPolicy: "Never" backoffLimit: 1
GPU-stuurprogramma, CUDA-versie controleren
De eerste stap is om te controleren of op uw apparaat het vereiste GPU-stuurprogramma en de CUDA-versies worden uitgevoerd.
Maak verbinding met de PowerShell-interface van uw apparaat.
Voer de volgende opdracht uit:
Get-HcsGpuNvidiaSmi
Noteer in de NVIDIA smi-uitvoer de GPU-versie en de CUDA-versie op uw apparaat. Als u Azure Stack Edge 2102-software uitvoert, komt deze versie overeen met de volgende stuurprogrammaversies:
- GPU-stuurprogrammaversie: 460.32.03
- CUDA-versie: 11.2
Hier volgt een voorbeeld van uitvoer:
[10.100.10.10]: PS>Get-HcsGpuNvidiaSmi K8S-1HXQG13CL-1HXQG13: Wed Mar 3 12:24:27 2021 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.2 | |-------------------------------+----------------------+----------------------+ | 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 Tesla T4 On | 00002C74:00:00.0 Off | 0 | | N/A 34C P8 9W / 70W | 0MiB / 15109MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | No running processes found | +-----------------------------------------------------------------------------+ [10.100.10.10]: PS>
Houd deze sessie open, omdat u deze gebruikt om de NVIDIA smi-uitvoer in het hele artikel weer te geven.
Taak zonder context delen
U voert de eerste taak uit om een toepassing op uw apparaat te implementeren in de naamruimte mynamesp1
. Deze toepassingsimplementatie geeft ook aan dat het delen van GPU-contexten niet standaard is ingeschakeld.
Vermeld alle pods die worden uitgevoerd in de naamruimte. Voer de volgende opdracht uit:
kubectl get pods -n <Name of the namespace>
Hier volgt een voorbeeld van uitvoer:
PS C:\WINDOWS\system32> kubectl get pods -n mynamesp1 No resources found.
Start een implementatietaak op uw apparaat met behulp van de eerder opgegeven deployment.yaml. Voer de volgende opdracht uit:
kubectl apply -f <Path to the deployment .yaml> -n <Name of the namespace>
Met deze taak maakt u twee containers en voert u een n-bodysimulatie uit op beide containers. Het aantal simulatie-iteraties wordt opgegeven in de
.yaml
.Hier volgt een voorbeeld van uitvoer:
PS C:\WINDOWS\system32> kubectl apply -f -n mynamesp1 C:\gpu-sharing\k8-gpusharing.yaml job.batch/cuda-sample1 created job.batch/cuda-sample2 created PS C:\WINDOWS\system32>
Voer de volgende opdracht uit om de pods weer te geven die in de implementatie zijn gestart:
kubectl get pods -n <Name of the namespace>
Hier volgt een voorbeeld van uitvoer:
PS C:\WINDOWS\system32> kubectl get pods -n mynamesp1 NAME READY STATUS RESTARTS AGE cuda-sample1-27srm 1/1 Running 0 28s cuda-sample2-db9vx 1/1 Running 0 27s PS C:\WINDOWS\system32>
Er zijn twee pods
cuda-sample1-cf979886d-xcwsq
encuda-sample2-68b4899948-vcv68
worden uitgevoerd op uw apparaat.Haal de details van de pods op. Voer de volgende opdracht uit:
kubectl -n <Name of the namespace> describe <Name of the job>
Hier volgt een voorbeeld van uitvoer:
PS C:\WINDOWS\system32> kubectl -n mynamesp1 describe job.batch/cuda-sample1; kubectl -n mynamesp1 describe job.batch/cuda-sample2 Name: cuda-sample1 Namespace: mynamesp1 Selector: controller-uid=22783f76-6af1-490d-b6eb-67dd4cda0e1f Labels: controller-uid=22783f76-6af1-490d-b6eb-67dd4cda0e1f job-name=cuda-sample1 Annotations: kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"batch/v1","kind":"Job","metadata":{"annotations":{},"name":"cuda-sample1","namespace":"mynamesp1"},"spec":{"backoffLimit":1... Parallelism: 1 Completions: 1 Start Time: Wed, 03 Mar 2021 12:25:34 -0800 Pods Statuses: 1 Running / 0 Succeeded / 0 Failed Pod Template: Labels: controller-uid=22783f76-6af1-490d-b6eb-67dd4cda0e1f job-name=cuda-sample1 Containers: cuda-sample-container1: Image: nvidia/samples:nbody Port: <none> Host Port: <none> Command: /tmp/nbody Args: -benchmark -i=10000 Environment: NVIDIA_VISIBLE_DEVICES: 0 Mounts: <none> Volumes: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal SuccessfulCreate 60s job-controller Created pod: cuda-sample1-27srm Name: cuda-sample2 Namespace: mynamesp1 Selector: controller-uid=e68c8d5a-718e-4880-b53f-26458dc24381 Labels: controller-uid=e68c8d5a-718e-4880-b53f-26458dc24381 job-name=cuda-sample2 Annotations: kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"batch/v1","kind":"Job","metadata":{"annotations":{},"name":"cuda-sample2","namespace":"mynamesp1"},"spec":{"backoffLimit":1... Parallelism: 1 Completions: 1 Start Time: Wed, 03 Mar 2021 12:25:35 -0800 Pods Statuses: 1 Running / 0 Succeeded / 0 Failed Pod Template: Labels: controller-uid=e68c8d5a-718e-4880-b53f-26458dc24381 job-name=cuda-sample2 Containers: cuda-sample-container2: Image: nvidia/samples:nbody Port: <none> Host Port: <none> Command: /tmp/nbody Args: -benchmark -i=10000 Environment: NVIDIA_VISIBLE_DEVICES: 0 Mounts: <none> Volumes: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal SuccessfulCreate 60s job-controller Created pod: cuda-sample2-db9vx PS C:\WINDOWS\system32>
De uitvoer geeft aan dat beide pods zijn gemaakt door de taak.
Hoewel beide containers de n-bodysimulatie uitvoeren, bekijkt u het GPU-gebruik van de NVIDIA smi-uitvoer. Ga naar de PowerShell-interface van het apparaat en voer deze uit
Get-HcsGpuNvidiaSmi
.Hier volgt een voorbeeld van uitvoer wanneer beide containers de n-body simulatie uitvoeren:
[10.100.10.10]: PS>Get-HcsGpuNvidiaSmi K8S-1HXQG13CL-1HXQG13: Wed Mar 3 12:26:41 2021 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.2 | |-------------------------------+----------------------+----------------------+ | 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 Tesla T4 On | 00002C74:00:00.0 Off | 0 | | N/A 64C P0 69W / 70W | 221MiB / 15109MiB | 100% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | 0 N/A N/A 197976 C /tmp/nbody 109MiB | | 0 N/A N/A 198051 C /tmp/nbody 109MiB | +-----------------------------------------------------------------------------+ [10.100.10.10]: PS>
Zoals u kunt zien, worden er twee containers (Type = C) uitgevoerd met n-bodysimulatie op GPU 0.
Bewaak de n-bodysimulatie. Voer de
get pod
opdrachten uit. Hier volgt een voorbeeld van uitvoer wanneer de simulatie wordt uitgevoerd.PS C:\WINDOWS\system32> kubectl get pods -n mynamesp1 NAME READY STATUS RESTARTS AGE cuda-sample1-27srm 1/1 Running 0 70s cuda-sample2-db9vx 1/1 Running 0 69s PS C:\WINDOWS\system32>
Wanneer de simulatie is voltooid, geeft de uitvoer dat aan. Hier volgt een voorbeeld van uitvoer:
PS C:\WINDOWS\system32> kubectl get pods -n mynamesp1 NAME READY STATUS RESTARTS AGE cuda-sample1-27srm 0/1 Completed 0 2m54s cuda-sample2-db9vx 0/1 Completed 0 2m53s PS C:\WINDOWS\system32>
Nadat de simulatie is voltooid, kunt u de logboeken en de totale tijd voor de voltooiing van de simulatie bekijken. Voer de volgende opdracht uit:
kubectl logs -n <Name of the namespace> <pod name>
Hier volgt een voorbeeld van uitvoer:
PS C:\WINDOWS\system32> kubectl logs -n mynamesp1 cuda-sample1-27srm Run "nbody -benchmark [-numbodies=<numBodies>]" to measure performance. ===========// CUT //===================// CUT //===================== > Windowed mode > Simulation data stored in video memory > Single precision floating point simulation > 1 Devices used for simulation GPU Device 0: "Turing" with compute capability 7.5 > Compute 7.5 CUDA device: [Tesla T4] 40960 bodies, total time for 10000 iterations: 170398.766 ms = 98.459 billion interactions per second = 1969.171 single-precision GFLOP/s at 20 flops per interaction PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32> kubectl logs -n mynamesp1 cuda-sample2-db9vx Run "nbody -benchmark [-numbodies=<numBodies>]" to measure performance. ===========// CUT //===================// CUT //===================== > Windowed mode > Simulation data stored in video memory > Single precision floating point simulation > 1 Devices used for simulation GPU Device 0: "Turing" with compute capability 7.5 > Compute 7.5 CUDA device: [Tesla T4] 40960 bodies, total time for 10000 iterations: 170368.859 ms = 98.476 billion interactions per second = 1969.517 single-precision GFLOP/s at 20 flops per interaction PS C:\WINDOWS\system32>
Er mogen op dit moment geen processen worden uitgevoerd op de GPU. U kunt dit controleren door het GPU-gebruik te bekijken met behulp van de NVIDIA smi-uitvoer.
[10.100.10.10]: PS>Get-HcsGpuNvidiaSmi K8S-1HXQG13CL-1HXQG13: Wed Mar 3 12:32:52 2021 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.2 | |-------------------------------+----------------------+----------------------+ | 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 Tesla T4 On | 00002C74:00:00.0 Off | 0 | | N/A 38C P8 9W / 70W | 0MiB / 15109MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | No running processes found | +-----------------------------------------------------------------------------+ [10.100.10.10]: PS>
Taak met context delen
U voert de tweede taak uit om de n-bodysimulatie op twee CUDA-containers te implementeren wanneer GPU-context delen is ingeschakeld, hoewel de MPS. Eerst schakelt u MPS in op het apparaat.
Maak verbinding met de PowerShell-interface van uw apparaat.
Als u MPS op uw apparaat wilt inschakelen, voert u de
Start-HcsGpuMPS
opdracht uit.[10.100.10.10]: PS>Start-HcsGpuMPS K8S-1HXQG13CL-1HXQG13: Set compute mode to EXCLUSIVE_PROCESS for GPU 00002C74:00:00.0. All done. Created nvidia-mps.service [10.100.10.10]: PS>
Voer de taak uit met dezelfde implementatie
yaml
die u eerder hebt gebruikt. Mogelijk moet u de bestaande implementatie verwijderen. Zie Implementatie verwijderen.Hier volgt een voorbeeld van uitvoer:
PS C:\WINDOWS\system32> kubectl -n mynamesp1 delete -f C:\gpu-sharing\k8-gpusharing.yaml job.batch "cuda-sample1" deleted job.batch "cuda-sample2" deleted PS C:\WINDOWS\system32> kubectl get pods -n mynamesp1 No resources found. PS C:\WINDOWS\system32> kubectl -n mynamesp1 apply -f C:\gpu-sharing\k8-gpusharing.yaml job.batch/cuda-sample1 created job.batch/cuda-sample2 created PS C:\WINDOWS\system32> kubectl get pods -n mynamesp1 NAME READY STATUS RESTARTS AGE cuda-sample1-vcznt 1/1 Running 0 21s cuda-sample2-zkx4w 1/1 Running 0 21s PS C:\WINDOWS\system32> kubectl -n mynamesp1 describe job.batch/cuda-sample1; kubectl -n mynamesp1 describe job.batch/cuda-sample2 Name: cuda-sample1 Namespace: mynamesp1 Selector: controller-uid=ed06bdf0-a282-4b35-a2a0-c0d36303a35e Labels: controller-uid=ed06bdf0-a282-4b35-a2a0-c0d36303a35e job-name=cuda-sample1 Annotations: kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"batch/v1","kind":"Job","metadata":{"annotations":{},"name":"cuda-sample1","namespace":"mynamesp1"},"spec":{"backoffLimit":1... Parallelism: 1 Completions: 1 Start Time: Wed, 03 Mar 2021 21:51:51 -0800 Pods Statuses: 1 Running / 0 Succeeded / 0 Failed Pod Template: Labels: controller-uid=ed06bdf0-a282-4b35-a2a0-c0d36303a35e job-name=cuda-sample1 Containers: cuda-sample-container1: Image: nvidia/samples:nbody Port: <none> Host Port: <none> Command: /tmp/nbody Args: -benchmark -i=10000 Environment: NVIDIA_VISIBLE_DEVICES: 0 Mounts: <none> Volumes: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal SuccessfulCreate 46s job-controller Created pod: cuda-sample1-vcznt Name: cuda-sample2 Namespace: mynamesp1 Selector: controller-uid=6282b8fa-e76d-4f45-aa85-653ee0212b29 Labels: controller-uid=6282b8fa-e76d-4f45-aa85-653ee0212b29 job-name=cuda-sample2 Annotations: kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"batch/v1","kind":"Job","metadata":{"annotations":{},"name":"cuda-sample2","namespace":"mynamesp1"},"spec":{"backoffLimit":1... Parallelism: 1 Completions: 1 Start Time: Wed, 03 Mar 2021 21:51:51 -0800 Pods Statuses: 1 Running / 0 Succeeded / 0 Failed Pod Template: Labels: controller-uid=6282b8fa-e76d-4f45-aa85-653ee0212b29 job-name=cuda-sample2 Containers: cuda-sample-container2: Image: nvidia/samples:nbody Port: <none> Host Port: <none> Command: /tmp/nbody Args: -benchmark -i=10000 Environment: NVIDIA_VISIBLE_DEVICES: 0 Mounts: <none> Volumes: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal SuccessfulCreate 47s job-controller Created pod: cuda-sample2-zkx4w PS C:\WINDOWS\system32>
Terwijl de simulatie wordt uitgevoerd, kunt u de NVIDIA smi-uitvoer bekijken. De uitvoer toont processen die overeenkomen met de cuda-containers (M + C-type) met n-bodysimulatie en de MPS-service (C-type) die worden uitgevoerd. Al deze processen delen GPU 0.
PS>Get-HcsGpuNvidiaSmi K8S-1HXQG13CL-1HXQG13: Mon Mar 3 21:54:50 2021 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.2 | |-------------------------------+----------------------+----------------------+ | 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 Tesla T4 On | 0000E00B:00:00.0 Off | 0 | | N/A 45C P0 68W / 70W | 242MiB / 15109MiB | 100% E. Process | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | 0 N/A N/A 144377 M+C /tmp/nbody 107MiB | | 0 N/A N/A 144379 M+C /tmp/nbody 107MiB | | 0 N/A N/A 144443 C nvidia-cuda-mps-server 25MiB | +-----------------------------------------------------------------------------+
Nadat de simulatie is voltooid, kunt u de logboeken en de totale tijd voor de voltooiing van de simulatie bekijken. Voer de volgende opdracht uit:
PS C:\WINDOWS\system32> kubectl get pods -n mynamesp1 NAME READY STATUS RESTARTS AGE cuda-sample1-vcznt 0/1 Completed 0 5m44s cuda-sample2-zkx4w 0/1 Completed 0 5m44s PS C:\WINDOWS\system32> kubectl logs -n mynamesp1 cuda-sample1-vcznt Run "nbody -benchmark [-numbodies=<numBodies>]" to measure performance. ===========// CUT //===================// CUT //===================== > Windowed mode > Simulation data stored in video memory > Single precision floating point simulation > 1 Devices used for simulation GPU Device 0: "Turing" with compute capability 7.5 > Compute 7.5 CUDA device: [Tesla T4] 40960 bodies, total time for 10000 iterations: 154979.453 ms = 108.254 billion interactions per second = 2165.089 single-precision GFLOP/s at 20 flops per interaction PS C:\WINDOWS\system32> kubectl logs -n mynamesp1 cuda-sample2-zkx4w Run "nbody -benchmark [-numbodies=<numBodies>]" to measure performance. ===========// CUT //===================// CUT //===================== > Windowed mode > Simulation data stored in video memory > Single precision floating point simulation > 1 Devices used for simulation GPU Device 0: "Turing" with compute capability 7.5 > Compute 7.5 CUDA device: [Tesla T4] 40960 bodies, total time for 10000 iterations: 154986.734 ms = 108.249 billion interactions per second = 2164.987 single-precision GFLOP/s at 20 flops per interaction PS C:\WINDOWS\system32>
Nadat de simulatie is voltooid, kunt u de NVIDIA smi-uitvoer opnieuw bekijken. Alleen het nvidia-cuda-mps-serverproces voor de MPS-service wordt weergegeven als actief.
PS>Get-HcsGpuNvidiaSmi K8S-1HXQG13CL-1HXQG13: Mon Mar 3 21:59:55 2021 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.2 | |-------------------------------+----------------------+----------------------+ | 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 Tesla T4 On | 0000E00B:00:00.0 Off | 0 | | N/A 37C P8 9W / 70W | 28MiB / 15109MiB | 0% E. Process | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | 0 N/A N/A 144443 C nvidia-cuda-mps-server 25MiB | +-----------------------------------------------------------------------------+
Implementatie verwijderen
Mogelijk moet u implementaties verwijderen bij uitvoering met MPS ingeschakeld en met MPS uitschakelen op uw apparaat.
Voer de volgende opdracht uit om de implementatie op uw apparaat te verwijderen:
kubectl delete -f <Path to the deployment .yaml> -n <Name of the namespace>
Hier volgt een voorbeeld van uitvoer:
PS C:\WINDOWS\system32> kubectl delete -f 'C:\gpu-sharing\k8-gpusharing.yaml' -n mynamesp1
deployment.apps "cuda-sample1" deleted
deployment.apps "cuda-sample2" deleted
PS C:\WINDOWS\system32>