Specify GPU model and driver version for ACS GPU pods
Set a GPU model and NVIDIA driver version in your Alibaba Cloud Container Compute Service (ACS) pod spec to override cluster defaults.
Prerequisites
Ensure the following:
-
An ACK cluster with ACS enabled
-
kubectl configured to connect to your cluster
-
A supported GPU model (submit a ticket to check availability)
GPU models
ACS supports multiple GPU models. You can use them with capacity reservations or request them on demand when you create a pod. The way you request GPU resources depends on the compute class:
-
High-performance network GPU (GPU-HPN): You can only request node reservations. After you purchase a reservation, you must associate it with your cluster. Each reservation runs as an independent virtual node in the cluster. For more information, see GPU-HPN Capacity Reservation.
-
GPU instance: You can use GPU resources on demand or configure capacity reservations. After you create a pod, ACS automatically deducts the GPU resources from your capacity reservation.
Specify a GPU model
For a high-performance network GPU (GPU-HPN), you can only request node reservations. Each reservation exists as an independent virtual node in the cluster, and the label of the virtual node specifies the GPU model. You can use node affinity scheduling to request a specific GPU model. For more information, see Schedule pods to GPU-HPN virtual nodes with attribute labels.
For a GPU instance, set the alibabacloud.com/gpu-model-series label in both the labels and nodeSelector fields of the pod to request a specific GPU model.
| Compute class | Protocol field | Example |
|---|---|---|
| High-performance network GPU (GPU-HPN) | spec.nodeSelector |
|
| GPU instance | metadata.labels[alibabacloud.com/gpu-model-series] |
|
Driver versions
Override the cluster-wide default NVIDIA driver for individual pods.
How to choose a driver version
GPU workloads typically rely on Compute Unified Device Architecture (CUDA), NVIDIA's parallel computing platform and programming model. Use the CUDA base images provided by NVIDIA to install the CUDA Toolkit in your container image. These base images already include the CUDA Toolkit. You can build your application image on top of the base image that matches the CUDA Toolkit version required by your application, and select different CUDA base images for different CUDA Toolkit versions.
The CUDA stack includes two APIs:
-
Driver API (in the NVIDIA driver package): provides low-level GPU control.
-
Runtime API (in the CUDA Toolkit package): wraps the Driver API with automatic initialization. Check the CUDA Toolkit Release Notes for compatibility requirements.
The CUDA runtime API version used by your application must match the version of the CUDA base image used to build its container image. For example, if your container image is built from the CUDA base image nvidia/cuda:12.2.0-base-ubuntu20.04, your application uses CUDA runtime API version 12.2.0.
Supported driver versions
When you specify a driver version for a pod, make sure that the version is included in the list of driver versions supported by ACS. For more information, see Supported GPU driver versions.
Pod label compared with cluster default
Two ways to configure driver versions:
| Method | Scope | When to use |
|---|---|---|
Pod label (alibabacloud.com/gpu-driver-version) |
Single pod or workload | A workload needs a non-default driver version |
| acs-profile selector | GPU pods that match a selector | Set different driver versions for specific types of GPU pods |
To change the default driver version for specific types of GPU pods, use acs-profile to inject pod configurations.
Default GPU driver version for pods
ACS lets you configure specific attributes for pods based on rules. If the default driver version does not meet your requirements, add the following configuration to the kube-system/acs-profile ConfigMap to assign different GPU driver versions to specific types of GPU pods.
The following configuration sets the driver version to 1.5.0 for all GPU-HPN pods in the cluster.
apiVersion: v1
kind: ConfigMap
metadata:
name: acs-profile
namespace: kube-system
data:
# Keep other system configurations unchanged.
selectors: |
[
{
"name": "gpu-hpn-driver",
"objectSelector": {
"matchLabels": {
"alibabacloud.com/compute-class": "gpu-hpn"
}
},
"effect": {
"labels": {
"alibabacloud.com/gpu-driver-version": "1.5.0"
}
}
}
]
Specify a driver version
Set the alibabacloud.com/gpu-driver-version label in the pod metadata.
| Compute class | Label | Example value |
|---|---|---|
| GPU instance | alibabacloud.com/gpu-driver-version |
535.161.08 |
| High-performance network GPU (GPU-HPN) | 535.161.08 |
Example for a GPU instance with both labels:
metadata:
labels:
# Set the compute class to gpu.
alibabacloud.com/compute-class: "gpu"
# Set the GPU model. Replace example-model with the actual GPU model, such as T4.
alibabacloud.com/gpu-model-series: "example-model"
# Set the driver version to 535.161.08.
alibabacloud.com/gpu-driver-version: "535.161.08"
Example for a GPU-HPN pod:
metadata:
labels:
# Set the compute class to gpu-hpn.
alibabacloud.com/compute-class: "gpu-hpn"
# Set the driver version to 535.161.08.
alibabacloud.com/gpu-driver-version: "535.161.08"
Deploy a GPU pod with a specific model and driver version
Create a Deployment with a specific GPU model and driver version, then verify the configuration.
-
Create a file named
acs-pod-with-model-and-driver.yaml:apiVersion: apps/v1 kind: Deployment metadata: name: acs-pod-with-model-and-driver namespace: default labels: app: acs-pod-with-model-and-driver spec: replicas: 1 selector: matchLabels: app: acs-pod-with-model-and-driver template: metadata: name: acs-pod-with-model-and-driver labels: app: acs-pod-with-model-and-driver # Specify ACS compute power. alibabacloud.com/acs: "true" # Set the compute class to gpu. alibabacloud.com/compute-class: "gpu" # example-model indicates the GPU model. Replace it with the actual GPU model, such as T4. alibabacloud.com/gpu-model-series: "<example-model>" # Set the driver version to 535.161.08. alibabacloud.com/gpu-driver-version: "535.161.08" spec: containers: - image: registry.cn-beijing.aliyuncs.com/acs/tensorflow-mnist-sample:v1.5 name: tensorflow-mnist command: - sleep - infinity resources: requests: cpu: 1 memory: 1Gi nvidia.com/gpu: 1 limits: cpu: 1 memory: 1Gi nvidia.com/gpu: 1 -
Apply the Deployment:
kubectl apply -f acs-pod-with-model-and-driver.yaml -
Verify the pod is running:
kubectl get podExpected output:
NAME READY STATUS RESTARTS AGE acs-pod-with-model-and-driver-7b89cbf4cf-2w66p 1/1 Running 0 6m26s -
Verify the pod's GPU configuration:
NoteThe sample container image includes
/usr/bin/nvidia-smi.ImportantActual output varies. Values shown are representative.
kubectl exec -it acs-pod-with-model-and-driver-7b89cbf4cf-2w66p -- /usr/bin/nvidia-smiExpected output:
+---------------------------------------------------------------------------------------+ | NVIDIA-SMI xxx.xxx.xx Driver Version: 535.161.08 CUDA Version: xx.x | |-----------------------------------------+----------------------+----------------------+ ... |=========================================+======================+======================| | x NVIDIA example-model xx | xxxxxxxx:xx:xx.x xxx | x | | xxx xxx xx xxx / xxxx | xxxx / xxx| x% xxxxxxxx| | | | xxx | +-----------------------------------------+----------------------+----------------------+The output shows GPU model
example-modelwith driver version535.161.08, which matches the labels in the pod spec.