Using GPU Virtualization
This section describes how to use the GPU virtualization capability to isolate the computing power from the GPU memory and efficiently use GPU device resources.
Prerequisites
- You have prepared GPU virtualization resources.
- If you want to create a cluster using commands, use kubectl to access the cluster. For details, see Connecting to a Cluster Using kubectl.
Notes and Constraints
- A single GPU can be virtualized into a maximum of 20 xGPU devices.
- xGPUs cannot be used in init containers.
- GPU virtualization supports two isolation modes: GPU memory isolation and isolation between GPU memory and computing power. A single GPU can schedule only workloads in the same isolation mode.
- Autoscaler cannot be used to automatically scale in or out GPU nodes.
- xGPU isolation does not allow you to request for GPU memory by calling CUDA API cudaMallocManaged(), which is also known as using UVM. For more information, see NVIDIA official documents. Use other methods to request for GPU memory, for example, by calling cudaMalloc().
- When a containerized application is initializing, the real-time compute monitored by the nvidia-smi may exceed the upper limit of the available compute of the container.
Creating a GPU Virtualization Application
Using the CCE Console
- Log in to the CCE console.
- Click the cluster name to go to the cluster console, choose Workloads in the navigation pane, and click the Create Workload in the upper right corner.
- Set basic information about the workload.
Choose Container Settings > Basic Info and configure the GPU quota.
- Video memory: The unit is MiB. The value must be a positive integer that is a multiple of 128. If the value exceeds the memory of a single GPU, scheduling cannot be performed.
- Computing power: The unit is %. The value must be a multiple of 5 and cannot exceed 100.
- If the GPU memory is set to the capacity upper limit of a single GPU or the computing power is set to 100%, the entire GPU will be used.
- When GPU virtualization is used, the workload scheduler defaults to Volcano and cannot be changed.
Figure 1 Configuring the xGPU quota
This section describes how to use GPU virtualization. For details about other parameters, see Workloads.
After completing the setting, click Create.
- After a workload is created, you can try to verify the isolation capability of GPU virtualization.
- Log in to the pod and check the total GPU memory allocated to the pod.
kubectl exec -it gpu-app -- nvidia-smi
Expected output:
Wed Apr 12 07:54:59 2023 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 470.141.03 Driver Version: 470.141.03 CUDA Version: 11.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 Tesla V100-SXM2... Off | 00000000:21:01.0 Off | 0 | | N/A 27C P0 37W / 300W | 4912MiB / 5120MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| +-----------------------------------------------------------------------------+
The expected output indicates that the total GPU memory allocated to the pod is 5120 MiB, and 4912 MiB is used.
- Run the following command on the node to check the isolation status of the GPU memory:
nvidia-smi
Expected output:
Wed Apr 12 09:31:10 2023 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 470.141.03 Driver Version: 470.141.03 CUDA Version: 11.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 Tesla V100-SXM2... Off | 00000000:21:01.0 Off | 0 | | N/A 27C P0 37W / 300W | 4957MiB / 16160MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | 0 N/A N/A 760445 C python 4835MiB | +-----------------------------------------------------------------------------+
The expected output indicates that the total GPU memory on the node is 16160 MiB, and the example pod uses 4957 MiB.
- Log in to the pod and check the total GPU memory allocated to the pod.
Using kubectl
- Use kubectl to access the cluster.
- Create an application that uses GPU virtualization.
The GPU memory isolation and isolation between GPU memory and computing power are supported. The computing power cannot be isolated only. volcano.sh and gpu-core.percentage cannot be set separately.
Create a gpu-app.yaml file with the following content.
- Isolate GPU memory only:
apiVersion: apps/v1 kind: Deployment metadata: name: gpu-app labels: app: gpu-app spec: replicas: 1 selector: matchLabels: app: gpu-app template: metadata: labels: app: gpu-app spec: containers: - name: container-1 image: <your_image_address> # Replace it with your image address. resources: limits: volcano.sh/gpu-mem.128Mi: 40 # GPU memory allocated to the pod. The value is a multiple of 128 MiB (40 x 128 = 5120 MiB). imagePullSecrets: - name: default-secret schedulerName: volcano
- Isolate the GPU memory from computing power:
apiVersion: apps/v1 kind: Deployment metadata: name: gpu-app labels: app: gpu-app spec: replicas: 1 selector: matchLabels: app: gpu-app template: metadata: labels: app: gpu-app spec: containers: - name: container-1 image: <your_image_address> # Replace it with your image address. resources: limits: volcano.sh/gpu-mem.128Mi: 40 # GPU memory allocated to the pod. The value is a multiple of 128 MiB (40 x 128 = 5120 MiB). volcano.sh/gpu-core.percentage: 25 # Computing power allocated to the pod imagePullSecrets: - name: default-secret schedulerName: volcano
Table 1 Key parameters Parameter
Mandatory
Description
volcano.sh/gpu-mem.128Mi
No
The value is a positive integer that is a multiple of 128 in the unit of MiB. If the value exceeds the memory of a single GPU, scheduling cannot be performed.
volcano.sh/gpu-core.percentage
No
The unit of the computing power is %. The value must be a multiple of 5 and cannot exceed 100.
- If the GPU memory is set to the capacity upper limit of a single GPU or the computing power is set to 100%, the entire GPU will be used.
- When GPU virtualization is used, the workload scheduler defaults to Volcano and cannot be changed.
- Isolate GPU memory only:
- Run the following command to create an application:
kubectl apply -f gpu-app.yaml
- Verify the isolation capability of GPU virtualization.
- Log in to the pod and check the total GPU memory allocated to the pod.
kubectl exec -it gpu-app -- nvidia-smi
Expected output:
Wed Apr 12 07:54:59 2023 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 470.141.03 Driver Version: 470.141.03 CUDA Version: 11.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 Tesla V100-SXM2... Off | 00000000:21:01.0 Off | 0 | | N/A 27C P0 37W / 300W | 4912MiB / 5120MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| +-----------------------------------------------------------------------------+
The expected output indicates that the total GPU memory allocated to the pod is 5120 MiB, and 4912 MiB is used.
- Run the following command on the node to check the isolation status of the GPU memory:
nvidia-smi
Expected output:
Wed Apr 12 09:31:10 2023 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 470.141.03 Driver Version: 470.141.03 CUDA Version: 11.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 Tesla V100-SXM2... Off | 00000000:21:01.0 Off | 0 | | N/A 27C P0 37W / 300W | 4957MiB / 16160MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | 0 N/A N/A 760445 C python 4835MiB | +-----------------------------------------------------------------------------+
The expected output indicates that the total GPU memory on the node is 16160 MiB, and the example pod uses 4957 MiB.
- Log in to the pod and check the total GPU memory allocated to the pod.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot