GPU共享調度
更新時間 2025-06-11 11:37:18
最近更新時間: 2025-06-11 11:37:18
分享文章
本文介紹GPU共享調度,實現GPU的共享和隔離能力。
前提條件
已創建Kubernetes集群,安裝好智算套件,并且集群包含NVIDIA GPU節點。
使用限制
共享GPU調度目前支持僅申請顯存和同時申請顯存和算力兩種任務,這兩種任務不能同時存在于一個節點上,即一個節點只運行僅申請顯存的任務,或者只運行同時申請顯存和算力的任務。
為工作負載申請算力和顯存時,有如下限制:
每一張GPU提供的算力按100計量,代表這張卡的100%算力,例如申請50代表使用GPU卡的50%算力。
顯存的計算單位為MiB,比如申請1000,則代表工作負載需要1000MiB的顯存資源。
共享GPU調度標簽說明
用戶可根據實際使用場景,選擇 【僅申請顯存】和 【同時申請顯存和算力】其中一種的調度能力,給節點打上標簽,啟用共享調度的能力。
| 標簽 | 標簽值 | 說明 |
|---|---|---|
| ack.node.gpu.schedule | egpu | 僅顯存隔離,不限制算力 |
| core_mem | 顯存隔離和算力限制 |
場景一:僅顯存隔離,不限制算力
步驟1:節點配置共享GPU調度標簽。
kubectl label no <node_name> ccse.node.gpu.schedule=egpu步驟2:提交任務,任務YAML如下:
apiVersion: apps/v1
kind: Deployment
metadata:
name: gpu-share-test
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: gpu-share-test
template:
metadata:
labels:
app: gpu-share-test
spec:
containers:
- name: gpu-share-test
image: registry-vpc-crs-hangzhou7.cnsp-internal.daliqc.cn/library/nvidia-samples:vectoradd-cuda11.6.0-ubi8
command:
- sleep
- 1h
resources:
limits:
daliqc.cn/gpu-memory: '2000' # 單位為MiB,此處代表申請 2000MiB 顯存步驟3:驗證顯存隔離能力。
遠程登錄到剛剛創建的pod。
kubectl exec -it <pod_name> -- bash執行nvidia-smi查看顯存大小,預期輸出如下:
[root@gpu-share-test-77db5c96cd-ghl9b /]# nvidia-smi
Mon Nov 25 08:10:08 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.54.14 Driver Version: 550.54.14 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 A10 On | 00000000:00:06.0 Off | 0 |
| 0% 33C P8 21W / 150W | 0MiB / 2000MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
場景二:顯存隔離和算力限制
步驟1:節點配置共享GPU調度標簽
kubectl label no <node_name> ccse.node.gpu.schedule=core_mem步驟2:提交任務,任務YAML如下:
apiVersion: apps/v1
kind: Deployment
metadata:
name: gpu-share-test
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: gpu-share-test
template:
metadata:
labels:
app: gpu-share-test
spec:
containers:
- name: gpu-share-test
image: deep-learning-examples:v3
command:
- sleep
- 1h
resources:
limits:
daliqc.cn/gpu-core.percentage: "10" # 每一張GPU提供的算力按100計量,10代表一張一張卡10%的算力
daliqc.cn/gpu-memory: '2000' # 單位為MiB,此處代表申請 2000MiB 顯存步驟3:驗證顯存隔離能力。
遠程登錄到剛剛創建的pod。
kubectl exec -it <pod_name> -- bash執行nvidia-smi查看顯存大小,預期輸出如下:
[root@gpu-share-test-77db5c96cd-ghl9b /]# nvidia-smi
Mon Nov 25 08:10:08 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.54.14 Driver Version: 550.54.14 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 A10 On | 00000000:00:06.0 Off | 0 |
| 0% 33C P8 21W / 150W | 0MiB / 2000MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| No running processes found |
+-----------------------------------------------------------------------------------------+步驟4:執行GPU任務.
執行以下命令,運行GPU任務。
time python ./main.py --arch=resnet50 --evaluate --epochs=1 --pretrained -b=5 /imagenet執行任務后,查看執行時間。
DLL 2024-12-08 14:26:52.588591 - Summary: train.data_time : None s train.compute_time : None s val.data_time : 0.00411 s val.compute_latency_at100 : 1.87428 s val.compute_latency_at
99 : 0.07948 s val.compute_latency_at95 : 0.07825 s
Experiment ended
real 0m49.596s
user 0m52.247s
sys 0m3.520s步驟5:調整算力資源,查看任務執行時間。
將上面工作負載中的daliqc.cn/gpu-core.percentage增大至50。
resources:
limits:
daliqc.cn/gpu-core.percentage: "50" # 每一張GPU提供的算力按100計量,50代表一張一張卡50%的算力
daliqc.cn/gpu-memory: '2000'執行GPU任務,查看命令輸出內容,可以見到耗時減少。
data_time : 0.00086 s val.compute_latency_at100 : 0.60483 s val.compute_latency_at
99 : 0.02637 s val.compute_latency_at95 : 0.02540 s
Experiment ended
real 0m12.447s
user 0m12.778s
sys 0m3.486s