GPU Virtualization in Practice: Sharing and Scheduling Compute Resources

    This article explains how GPU virtualization turns coarse, whole-card allocation into fine-grained, shareable compute supply. It compares three mainstream approaches—hardware-based multi-instance partitioning, a virtualization layer (vGPU), and stream-based multi-process sharing—along with their selection trade-offs, then covers the resource profiling metrics needed before rollout, practical scheduling strategies and admission checks, isolation and stability costs, observability and capacity governance, and a phased implementation roadmap.

    1. Why Compute Virtualization Is Needed

    In the early build-out of AI compute centers and AI platforms, accelerators were typically assigned to workloads as a whole card with exclusive ownership. This approach is simple to implement and provides thorough isolation, but it quickly exposed three structural problems.

    The first is resource fragmentation. Training and inference workloads differ enormously in memory requirements. Once an inference service that needs only a few gigabytes of GPU memory occupies an entire card, the remaining memory cannot be used by other tasks, leaving a gap that is allocated on paper but unused in practice.

    The second is unbalanced utilization. Workloads generally have peaks and troughs, and average utilization is often several times lower than peak utilization. Provisioning for the peak leaves large amounts of compute idle under normal conditions; provisioning for the average leads to throttling at peak times.

    The third is cost pass-through. Accelerators are expensive and have long supply lead times, so low utilization translates directly into a higher cost per unit of compute and reduces the platform’s capacity to take on more workloads.

    The essence of virtualization is to insert a layer of resource abstraction between the hardware and the workloads, converting coarse “one card, one task” allocation into fine-grained supply that can be partitioned, shared, capped, and reclaimed.

    2. A Technical Comparison of Three Mainstream Virtualization Paths

    2.1 Hardware-Level Multi-Instance Partitioning

    The hardware performs physical isolation across dimensions such as memory, compute units, and caches, splitting the card into multiple instances that do not interfere with each other. The advantages are strong isolation and low performance jitter, which suit online services sensitive to latency and stability. The constraints are that partition sizes are usually preset tiers, so granularity is not flexible enough, and not all models support it.

    2.2 Virtualization Middleware Layer (vGPU)

    By introducing an interception and forwarding layer between the driver and the container runtime, memory and compute quotas are enforced logically. It offers fairly flexible custom sizing and integrates easily with container orchestration systems. The cost is a certain amount of forwarding overhead and clear compatibility requirements for kernel and driver versions.

    2.3 Stream-Based Multi-Process Sharing

    Multiple processes are allowed to share the same context, and sharing is achieved together with memory limits and compute quota controls. It typically delivers the highest resource utilization, but the weakest isolation: an abnormal single process is more likely to affect its neighbors on the same card.

    Selection guidance: prioritize isolation for online inference, prioritize throughput and utilization for offline training and batch processing, and for mixed scenarios assign different approaches by workload tier rather than applying one mode across the entire platform.

    3. Resource Profiling Before Implementation: Turning “Gut Feel” into Data

    Whether a virtualization approach can be implemented depends on a quantified understanding of the workload. At least four categories of metrics need to be collected:

    • GPU memory usage: distinguish average from peak, and pay attention to how long the peak lasts;
    • Compute utilization: note that brief spikes with a low average are the norm;
    • Request volume and latency distribution: define P95/P99 rather than looking only at the average;
    • Start and release frequency: frequent scaling amplifies scheduling overhead.

    A sample collection logic is shown below (pseudocode):

    1. # Collect a resource profile for each workload over a time window
    2. profile = {
    3. "gpu_mem_avg": sample_mean(mem_usage, window="1h"),
    4. "gpu_mem_peak": sample_max(mem_usage, window="1h"),
    5. "gpu_util_avg": sample_mean(util, window="1h"),
    6. "gpu_util_peak": sample_max(util, window="1h"),
    7. "qps_p95": percentile(requests, 0.95),
    8. "latency_p99": percentile(latency, 0.99),
    9. }
    10. # Decision basis: the peak sets the upper bound, the average sets normal packing density

    The key principle is that the average is used to calculate packing density and the peak is used to set a safe upper bound, with the gap between the two covered by elastic capacity.

    4. Scheduling Strategy Design

    The core problem a scheduler must solve is not “is there an idle card,” but “which card and which quota range is the most reasonable place for this task.” Deployable strategy combinations include:

    1. Packing first: fill existing instances first to reduce fragmentation, suited to cost-sensitive scenarios;
    2. Balancing first: spread the load to reduce same-card interference, suited to latency-sensitive scenarios;
    3. Quota-constrained scheduling: perform admission checks on both memory and compute dimensions, rejecting the request if either dimension exceeds the limit;
    4. Priority and preemption: online tasks rank above offline tasks, allowing lower-priority tasks to be displaced;
    5. Topology awareness: in single-node multi-card and multi-node multi-card scenarios, prioritize the shortest communication path.

    A simplified expression of the admission check:

    1. if req.mem <= card.free_mem and req.compute_quota <= card.free_compute:
    2. admit(req)
    3. else:
    4. queue_or_reject(req)

    It is important to emphasize that GPU memory is a non-compressible resource while compute is a compressible one. Admission decisions must therefore treat memory as a hard constraint and compute as a soft constraint; otherwise runtime failures will occur where “there is enough compute but memory overflows.”

    5. Isolation and Stability: The Hidden Cost of Virtualization

    Sharing brings utilization, and also interference. Engineering practice needs to handle three types of noise: latency jitter caused by compute contention, throughput degradation caused by memory bandwidth contention, and an entire card becoming unavailable because of an abnormal process.

    The corresponding measures include reserving an independent quota range for online workloads, setting memory limits to prevent overruns, performing fast eviction and self-healing of abnormal processes, and bringing same-card neighbor relationships into monitoring and alerting dimensions. Without these supporting measures, virtualization easily degrades from “improving utilization” into “manufacturing random failures.”

    6. Observability and Capacity Governance

    After virtualization, the original whole-card view no longer works, and an intra-card observability system must be established: report memory and compute usage per instance, correlate resource profiles per workload, and analyze fragmentation rate and oversubscription ratio trends. For capacity governance, the recommendation is to use the oversubscription ratio as the core lever—do not oversubscribe memory, oversubscribe compute moderately, and adjust the oversubscription factor in reverse based on measured queueing time and P99 latency.

    7. Implementation Roadmap

    1. Pilot on a non-core inference scenario to validate compatibility and overhead;
    2. Build resource profiling collection and dashboards to form baseline data;
    3. Roll out quotas and admission first, then sharing and oversubscription, releasing risk step by step;
    4. Integrate scheduling strategies and the priority system into a unified orchestration platform to enable automation;
    5. Use three metrics—fragmentation rate, average utilization, and P99 latency—for closed-loop evaluation and iteration.

    8. Conclusion

    The value of compute virtualization lies not in “how finely you can partition,” but in driving scheduling decisions with measurable resource profiles and finding a balance between isolation and utilization that matches workload characteristics. In related practice at Baidu AI Cloud, the common approach is likewise to first make resource abstraction and the quota system solid, then gradually introduce sharing and elasticity, so that high-value compute is genuinely used to its fullest and used well.