Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Using GPU Virtualization

Updated on 2024-12-04 GMT+08:00

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

Constraints

  • A single GPU can be virtualized into a maximum of 20 xGPU devices.
  • After GPU virtualization is used, init containers are not supported.
  • 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

  1. Log in to the CCE console.
  2. 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.
  3. 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.
    NOTE:
    • 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.

    This section describes how to use GPU virtualization. For details about other parameters, see Workloads.

    After completing the setting, click Create.

  4. After a workload is created, you can try to verify the isolation capability of GPU virtualization.

    1. Log in to the container 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.

    2. 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.

Using kubectl

  1. Use kubectl to connect to the cluster.
  2. Create an application that uses GPU virtualization.

    NOTE:

    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.

    NOTE:
    • 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.

  3. Run the following command to create an application:

    kubectl apply -f gpu-app.yaml

  4. Verify the isolation capability of GPU virtualization.

    1. Log in to the container 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.

    2. 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.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback