All Products
Search
Document Center

Create a GPU-accelerated elastic container instance

Last Updated: May 19, 2022

This topic describes how to create and use a GPU-accelerated elastic container instance.

Background information

GPU-accelerated elastic container instances feature built-in graphics cards and NVIDIA CUDA drivers. Therefore, when you use a GPU-accelerated elastic container instance, you only need to use a basic image with a runtime such as the CUDA Toolkit. You do not need to care about the installation of the driver.

Note

The GPU driver version supported by GPU-accelerated elastic container instances is NVIDIA 460.73.01. The CUDA Toolkit version supported by GPU-accelerated elastic container instances is 11.2.

You can specify an instance type of the following GPU-accelerated Elastic Compute Service (ECS) instance families to create GPU-accelerated elastic container instances:

  • gn7i, a GPU-accelerated compute-optimized instance family that uses NVIDIA A10 GPUs. This instance family includes a variety of instance types, such as ecs.gn7i-c8g1.2xlarge.

  • gn7, a GPU-accelerated compute-optimized instance family that uses NVIDIA A100 GPUs. This instance family includes a variety of instance types, such as ecs.gn7-c12g1.3xlarge.

  • gn6v, a GPU-accelerated compute-optimized instance family that uses NVIDIA V100 GPUs. This instance family includes a variety of instance types, such as ecs.gn6v-c8g1.2xlarge.

  • gn6e, a GPU-accelerated compute-optimized instance family that uses NVIDIA V100 GPUs. This instance family includes a variety of instance types, such as ecs.gn6e-c12g1.3xlarge.

  • gn6i, a GPU-accelerated compute-optimized instance family that uses NVIDIA T4 GPUs. This instance family includes a variety of instance types, such as ecs.gn6i-c4g1.xlarge.

  • gn5i, GPU-accelerated compute-optimized instance family that uses NVIDIA P4 GPUs. This instance family includes a variety of instance types, such as ecs.gn5i-c2g1.large.

  • gn5, GPU-accelerated compute-optimized instance family that uses NVIDIA P100 GPUs. This instance family includes a variety of instance types, such as ecs.gn5-c4g1.xlarge.

    Note

    The gn5 instance family is equipped with local disks. You can mount local disks to elastic container instances. For more information, see Create an elastic container instance that has local disks attached.

For more information, see:

Use Kubernetes to specify an ECS instance type

You can add annotations to metadata in the pod configuration file to specify a GPU-accelerated ECS instance type. After you specify a GPU-accelerated ECS instance type, you must add the nvidia.com/gpu field to the containers.resources section to declare GPU resources.

Notice

The nvidia.com/gpu field indicates the number of GPUs to be allocated to a container. You must specify this field when you create a GPU-accelerated elastic container instance. If you do not specify this field, an error is returned when the pod is started.

Sample code:

apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
  name: nginx-gpu-demo-1
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
      annotations:
        k8s.aliyun.com/eci-use-specs: ecs.gn5i-c4g1.xlarge  #Specify a GPU-accelerated ECS instance type.
    spec:
      containers:
      - name: nginx
        image: registry-vpc.cn-beijing.aliyuncs.com/eci_open/nginx:1.15.10 # replace it with your exactly <image_name:tags>
        resources:
            limits:
              nvidia.com/gpu: '1'    # Specify the number of GPUs that are required by the container. This field is required. If you do not specify this field, an error is returned when the pod is started. 
        ports:
        - containerPort: 80

Call an API operation to specify an ECS instance type

When you call the CreateContainerGroup API operation to create an elastic container instance, you can use the InstanceType parameter to specify a GPU-accelerated ECS instance type, and use the Container.N.Gpu and InitContainer.N.Gpu parameters to specify the number of GPUs to be allocated to a container. The following table describes the parameters. For more information, see CreateContainerGroup.

Parameter

Type

Example

Description

InstanceType

String

ecs.gn6v-c8g1.2xlarge

The GPU-accelerated ECS instance types. The following GPU-accelerated ECS instance families are supported: gn6v, gn6i, gn5i, gn5, gn7, and gn7i. You can specify up to five ECS instance types at a time. Separate multiple instance types with commas (,). Example: ecs.gn6v-c8g1.2xlarge,ecs.gn6i-c4g1.xlarge.

Container.N.Gpu

Integer

1

The number of GPUs to be allocated to container N.

InitContainer.N.Gpu

Integer

1

The number of GPUs allocated to init container N.

Notice

When you create a GPU-accelerated elastic container instance, you must specify both the InstanceType and Container.N.Gpu parameters. You must make sure that the total number of GPUs to be allocated to all the containers does not exceed the number of GPUs provided by each specified GPU-accelerated ECS instance type.

You can call the UpdateContainerGroup API operation to change the number of GPUs allocated to containers in an existing GPU-accelerated elastic container instance. For more information, see UpdateContainerGroup.