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

Creating a GPU-accelerated Application

Updated on 2025-01-24 GMT+08:00

This section describes how to use GPU virtualization to isolate the compute and GPU memory and efficiently use GPU resources.

Prerequisites

Constraints

  • The init container does not support GPU virtualization.
  • For a single GPU:
    • Up to 20 virtual GPUs can be created.
    • Up to 20 pods that use the isolation capability can be scheduled.
    • Only workloads in the same isolation mode can be scheduled. (GPU virtualization supports two isolation modes: GPU memory isolation and isolation of GPU memory and compute.)
  • For different containers of the same workload:
    • You can configure one GPU model and cannot configure two or more GPU models concurrently.
    • You can configure the same GPU usage mode and cannot configure virtualization and non-virtualization modes concurrently.
  • After a GPU is virtualized, the GPU cannot be used by workloads that use shared GPU resources.

Creating a GPU-accelerated Application on the Console

  1. Log in to the UCS console.
  2. Click the on-premises cluster name to access the cluster console. In the navigation pane, choose Workloads. In the upper right corner, click Create from Image.
  3. Configure the workload parameters. In Basic Info under Container Settings, select GPU for Heterogeneous Resource and select a resource use method.

    • Whole GPU: The default Kubernetes scheduling mode schedules the pods to nodes that meet GPU resource requirements.
    • Sharing mode: Multiple pods preempt the same GPU. This improves the utilization of idle GPU resources when the workload resource usage fluctuates sharply.
    • Virtual GPU: In-house GPU virtualization technology dynamically allocates the GPU memory and compute to improve GPU utilization.
    NOTE:

    Resource Use Method

    • Whole GPU: A GPU is dedicated for one pod. The value ranges from 1 to 10, depending on the number of GPUs on the node.
    • Sharing mode: A GPU is shared by multiple pods. Configure the percentage of GPU usage for each individual pod. It is not possible to allocate resources across multiple GPUs. For example, value 50% indicates that all the requested GPU resources come from the same GPU.

    Virtual GPU

    • GPU memory: GPU virtualization configuration. The value must be an integer multiple of 128 MiB. The minimum value allowed is 128 MiB. If the total GPU memory configured exceeds that of a single GPU, GPU scheduling will not be performed.
    • GPU compute (%): GPU virtualization configuration. The value must be a multiple of 5 and cannot exceed 100. This parameter is optional. If it is left blank, the GPU memory is isolated and the compute is shared.

  4. Configure other parameters and click Create.

Creating a GPU-accelerated Application Using kubectl

  1. Use kubectl to access the cluster.
  2. Creating a GPU-accelerated application.

    Create a gpu-app.yaml file.

    • Static GPU allocation
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: gpu-app
        namespace: default
        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:
                  nvidia.com/gpu: 200m        # Request for 0.2 GPUs. Value 1 indicates that the GPU resources will be dedicated, and a value less than 1 indicates that the GPU resources will be shared.
           schedulerName: volcano            # To use GPU virtualization, you must use the Volcano scheduler.
            imagePullSecrets:
              - name: default-secret
      NOTE:

      There are two isolation modes: GPU memory isolation and isolation of both GPU memory and compute. volcano.sh/gpu-core.percentage cannot be set separately for GPU compute isolation.

    • Isolate the GPU memory only:
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: gpu-app
        namespace: default
        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: 5  # GPU memory allocated to the pod, in the unit of 128 MiB
            schedulerName: volcano         # To use GPU virtualization, you must use the Volcano scheduler.
            imagePullSecrets:
              - name: default-secret
    • Isolate both the GPU memory and compute:
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: gpu-app
        namespace: default
        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: 5     # GPU memory allocated to the pod, in the unit of 128 MiB
                  volcano.sh/gpu-core.percentage: 25    # Compute allocated to the pod
            schedulerName: volcano                 # To use GPU virtualization, you must use the Volcano scheduler.
            imagePullSecrets:
              - name: default-secret
    Table 1 Key parameters

    Parameter

    Mandatory

    Description

    nvidia.com/gpu

    No

    nvidia.com/gpu specifies the number of GPUs to be requested. The value can be smaller than 1. For example, nvidia.com/gpu: 0.5 indicates that multiple pods share a GPU. In this case, all the requested GPU resources come from the same GPU.

    After nvidia.com/gpu is specified, workloads will not be scheduled to nodes without GPUs. If the node is GPU-starved, Kubernetes events similar to the following will be reported:

    • 0/2 nodes are available: 2 Insufficient nvidia.com/gpu.
    • 0/4 nodes are available: 1 InsufficientResourceOnSingleGPU, 3 Insufficient nvidia.com/gpu.

    volcano.sh/gpu-mem.128Mi

    No

    The GPU memory, which must be a positive integer multiple of 128 MiB. For example, if the value is set to 5, the GPU memory will be 640 MiB (128 MiB × 5). If the total GPU memory configured exceeds that of a single GPU, GPU scheduling will not be performed.

    volcano.sh/gpu-core.percentage

    No

    The value must be a multiple of 5 and cannot exceed 100.

    Only compute isolation is not supported. volcano.sh/gpu-core.percentage cannot be configured separately.

  3. Run the following command to create an application:

    kubectl apply -f gpu-app.yaml

Verifying GPU Virtualization Isolation

After an application is created, you can verify its GPU virtualization isolation.
  • Log in to the target container and check its GPU memory.
    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 |   4792MiB /  5000MiB |      0%      Default |
    |                               |                      |                  N/A |
    +-------------------------------+----------------------+----------------------+
    +-----------------------------------------------------------------------------+
    | Processes:                                                                  |
    |  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
    |        ID   ID                                                   Usage      |
    |=============================================================================|
    +-----------------------------------------------------------------------------+

    5,000 MiB of GPU memory is allocated to the container, and 4,792 MiB is used.

  • Run the following command on the node to check the isolation of the GPU memory:
    export PATH=$PATH:/usr/local/nvidia/bin;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 |   4837MiB / 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 4837 MiB is used by the example pod.

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