Spatial Partitioning of GPUs using Nvidia MIG - Rafay Product Documentation

Spatial Partitioning of GPUs using Nvidia MIG

In the prior blogs, we discussed why GPUs are managed differently in Kubernetes, how the GPU Operator helps streamline management and various strategies to share GPUs on Kubernetes. In 2020, Nvidia introduced Multi-Instance GPU (MIG) that takes GPU sharing to a different level.

In this blog, we will start by reviewing some common industry use cases where MIG is used and then dive deeper into how MIG is configured and used.


Common Use Cases

Let's look at some common use cases and applications for GPU Sharing using Nvidia MIG.

1. GPU Cloud

GPU Cloud providers can use MIG to provide GPU resources to multiple customers simultaneously. Instead of allocating an entire GPU to a single user, they can partition GPUs and offer this to their users that only require a slice of the full GPU. This reduces costs for users running smaller-scale workloads and maximizes the provider’s GPU utilization.

2. Inference for Multiple Applications

Inference workloads generally do not require the full power of a GPU. With MIG, multiple models or applications can be run concurrently on the same GPU. For example,

3. Multi-Tenancy for Enterprises

A large research lab can use MIG in a multi-tenant Kubernetes environment, where multiple data scientists are running various machine learning workloads. Each scientist’s pod in the Kubernetes cluster can be assigned a different MIG instance, ensuring fair and isolated access to GPU resources without needing to allocate an entire GPU to each workload.

4. Healthcare

Many hospitals or research institutions run ML models for medical image analysis (e.g. detect tumors from MRI scans, analyze CT images for abnormalities). MIG enables running different models for multiple patients on the same GPU simultaneously, speeding up the diagnosis. Each model can be provided a dedicated portion of the GPU, providing faster results.


Concepts

MIG enables a single physical GPU to be split into multiple independent instances. Each instance operates with its own memory, cache and compute cores, effectively allowing different workloads to run concurrently on separate GPU partitions. With MIG, GPUs such as NVIDIA A100 etc, can be securely partitioned up to seven separate GPU instances.

A MIG device consists of the 3-tuple (Top level GPU + A GPU Instance created inside that GPU + A Compute Instance created inside that GPU Instance).

This gives us a MIG device naming convention ("[GPU Instance slice count]g.[total memory]gb") that refers to a MIG device. For example, 3g.20gb


Partitioning Strategy

Three strategies are supported with MIG allowing for flexible use of the GPUs.

None

Use this strategy when MIG mode is not enabled on your GPU. This is the default mode and no changes are required to existing pod manifests.

<br> 1<br> 2<br> 3<br> 4<br> 5<br> 6<br> 7<br> 8<br> 9<br>10<br>11<br>12<br>13<br> <br>apiVersion: v1<br>kind: Pod<br>metadata:<br> name: gpu-pod<br>spec:<br> restartPolicy: Never<br> containers:<br> - name: gpu-container<br> image: "nvidia/cuda:11.0-base"<br> command: ["nvidia-smi"]<br> resources:<br> limits:<br> nvidia.com/gpu: 1 # Requesting 1 GPU<br>

Single

With this strategy, a node exposes a single type of MIG device across all its GPUs. The logic behind this strategy is to avoid the fragmentation of jobs across different nodes. Pods will need to use the nodeSelector to specify the exact model of GPU or MIG device that is required. In single mode, the GPU is partitioned, and users should specify the MIG profile being used.

<br> 1<br> 2<br> 3<br> 4<br> 5<br> 6<br> 7<br> 8<br> 9<br>10<br>11<br>12<br>13<br>14<br>15<br> <br>apiVersion: v1<br>kind: Pod<br>metadata:<br> name: gpu-pod<br>spec:<br> restartPolicy: Never<br> containers:<br> - name: gpu-container<br> image: "nvidia/cuda:11.0-base"<br> command: ["nvidia-smi"]<br> resources:<br> limits:<br> nvidia.com/gpu: 1<br> nodeSelector: # This ensures the pod gets scheduled on nodes with the correct MIG profile<br> nvidia.com/gpu.product: "A100-SXM4-40GB"<br>

Mixed

With the mixed strategy, a node can expose different MIG device types and GPUs. Applications need to request a specific MIG device by specifying both the number of compute instances and the total amount of memory provided by the device type (e.g. 2g.10GB). To request a MIG device from the mixed strategy, users must change their YAML specs to request the corresponding resource type.

<br> 1<br> 2<br> 3<br> 4<br> 5<br> 6<br> 7<br> 8<br> 9<br>10<br>11<br>12<br>13<br>14<br>15<br> <br>apiVersion: v1<br>kind: Pod<br>metadata:<br> name: gpu-pod<br>spec:<br> restartPolicy: Never<br> containers:<br> - name: gpu-container<br> image: "nvidia/cuda:11.0-base"<br> command: ["nvidia-smi"]<br> resources:<br> limits:<br> nvidia.com/mig-3g.20gb: 1 # Requesting 1 MIG instance with the 3g.20gb profile<br> nodeSelector: # This ensures the pod gets scheduled on nodes with the correct MIG profile<br> nvidia.com/gpu.product: "A100-SXM4-40GB"<br>

MIG Profiles

MIG offers predefined profiles that specify how much of the GPU’s resources (e.g., compute units, memory) are allocated to each instance. MIG does not allow GPU instances to be created with an arbitrary number of GPU slices. On a given GPU, you can create multiple GPU instances from a mix and match of the supported profiles. Some profiles may allocate more GPU cores or memory, while others might create smaller, more numerous instances. MIG Profiles follow a naming convention (M:xg:ygb) where

Shown below is a table of available MIG profiles for a Nvidia A100 TensorCore GPU

MIG Profile Description Instances
1g.5gb 1 compute instance with 5GB memory 7
2g.10gb 2 compute instances, each with 10GB memory 3
3g.20gb 3 compute instances, each with 20GB memory 2
4g.20gb 4 compute instances, each with 20GB memory 1
7g.40gb Full GPU with all compute and memory (40GB) 1

Considerations

Listed below are considerations that users need to factor in when using MIG. These are valid at the time of writing this blog and may change as Nvidia updates MIG's capabilities.

  1. Available only on specific GPU models like A30, A100 (PCIE/SXM4), H100 (PCIE/SXM5/GH200), and H200 (SXM5)
  2. Designed primarily for computing tasks (i.e. no graphical applications)
  3. Best suited for servers with GPUs of the same model.
  4. Requires the latest version of the GPU drivers.
  5. Reconfiguration requires unloading all computing tasks from memory and stopping applications.
  6. GPU to GPU P2P (i.e. PCIe or NVLink) is not supported
  7. Best suited for Linux

Summary

NVIDIA MIG (Multi-Instance GPU) allows partitioning a single GPU into multiple isolated instances, enabling better resource utilization by running different workloads concurrently on a single GPU. This improves efficiency by tailoring GPU resources to the specific needs of diverse applications, such as training, inference, and development. Shown below is a table that maps common MIG device types to types of workload.

MIG Device Type Workload Type
7g.40gb Heavy Deep Learning Training Jobs
3g.20gb Small/Medium Training Jobs
1g.10gb Inference workloads (low-latency models), Development Jupyter notebooks

In the next blog, we will discuss how organizations can provide their users (data scientists and ML engineers) self-service access to GPU-enabled workspaces from a shared pool of GPU resources.