CUDA Green Contexts: Partition GPU SMs Inside One Process for Predictable Latency

CUDA 13.1 brings green contexts to the Runtime API. Dedicating 8 of 148 SMs to a critical kernel cut its latency from 0.140 ms to 0.007 ms while a bulk workload kept the GPU busy.

CUDA Green Contexts: Partition GPU SMs Inside One Process for Predictable Latency

GPU applications increasingly execute several independent workloads on the same device and within the same process. A latency-sensitive inference operator may run alongside a throughput-heavy background kernel. Preprocessing may overlap with model execution, or multiple stages of a pipeline may compete for GPU resources. In these situations, sharing the GPU efficiently is not just about maximizing throughput. It is also about controlling how long critical work waits before it can execute.

CUDA streams and priorities provide mechanisms for coordinating concurrent work, but they do not guarantee that urgent work will receive GPU execution resources immediately. A high-priority kernel can still wait when lower-priority work has already occupied the streaming multiprocessors (SMs). That limitation becomes important in systems where latency matters as much as total GPU utilization.

NVIDIA’s green contexts offer a more explicit way to manage this problem. Available through the CUDA Driver API since CUDA 12.4 and introduced into the Runtime API in CUDA 13.1, green contexts allow an application to create a context associated with a selected subset of GPU execution resources and submit work directly to that subset [1].

The distinction is important: instead of relying entirely on the GPU scheduler to prioritize competing work, an application can reserve part of the device for a critical workload. The remaining resources can continue executing bulk operations.

NVIDIA demonstrates the effect with a Blackwell GPU containing 148 SMs. In its test, dedicating eight SMs to a small critical kernel reduced its latency from 0.140 milliseconds to 0.007 milliseconds while a bulk workload continued running on the other 140 SMs [1:1].

That is a 20x reduction compared with the high-priority stream configuration. It illustrates a useful shift in GPU resource management: applications can move from asking the scheduler to prioritize work to explicitly assigning execution capacity to workloads that need predictable latency.

Why it matters

GPU scheduling becomes more complicated when workloads have different performance objectives.

A throughput-oriented workload generally benefits from using as much of the GPU as possible. It may consist of large kernels that keep many SMs occupied and process substantial amounts of data. Its main objective is to maximize the amount of work completed over time.

A latency-sensitive workload has a different requirement. It may involve a relatively small operation that needs to finish quickly, even while a larger workload is using the same device. Its objective is not necessarily to maximize total throughput, but to complete a particular operation within a predictable time window.

These requirements can conflict.

Consider an inference-serving process that performs a small critical operation while a background task runs a large GPU kernel. The inference operation may require only a small fraction of the GPU’s total compute capacity. However, if the background kernel has already occupied the available SMs with running thread blocks, the critical operation may not be able to begin immediately.

A similar situation can arise in distributed training, where communication-related computation needs to overlap with other GPU work, or in sensor-processing pipelines where certain operations have tighter timing requirements than background processing.

CUDA stream priorities are commonly used to express which work should receive preference. But priority is not the same as guaranteed resource availability.

When a lower-priority kernel is already executing, a higher-priority kernel cannot simply force its running thread blocks off the SMs. The critical kernel may have to wait until resources become available. This means that even a high-priority stream can experience latency caused by work that was submitted earlier.

For applications with strict latency requirements, that wait can be difficult to control.

Green contexts address the problem by allowing the application to dedicate a subset of GPU execution resources to a particular workload. If a critical kernel is submitted through a green context associated with eight SMs, it can execute on those resources without competing for the SMs assigned to a separate bulk workload.

This is useful when an application has identifiable workload classes with different priorities and resource requirements. Rather than relying exclusively on scheduling preference, it can create an execution boundary between them.

The trade-off is equally important: SMs reserved for one workload are no longer available to the other. Green contexts therefore introduce a resource-allocation decision, not a free performance improvement. The application must decide how much GPU capacity to dedicate to predictable latency and how much to leave available for overall throughput.

What green contexts are

A green context is a lightweight handle associated with a selected set of GPU execution resources [1:2]. It provides an application with a way to direct work to a defined portion of the GPU rather than always targeting the device as a whole.

The concept is built around two resource dimensions: SM partitions and workqueues.

SM partitions

Streaming multiprocessors are the GPU execution units on which thread blocks run. The number of SMs available to a kernel can influence how much parallel execution capacity it can use.

With green contexts, an application can assign a subset of SMs to a context. Work submitted through streams created from that context executes only on the resources associated with it.

For example, on a GPU with 148 SMs, an application could create one green context with eight SMs for latency-sensitive work and another with 140 SMs for bulk computation.

The application now has two execution domains within the same device. The critical workload can use its reserved SMs, while the bulk workload continues on its larger allocation.

This is different from simply giving one stream a higher priority. Priority influences scheduling decisions, whereas an SM partition changes which execution resources are available to work submitted through a context.

The distinction is especially relevant when the main source of latency is resource contention from already-running kernels. Reserving execution capacity in advance avoids depending on those kernels to finish before the critical workload can begin.

Workqueues

Green contexts also provide workqueue provisioning.

A workqueue is an underlying mechanism through which work is scheduled for execution. When independent streams share the same underlying queue, their work can experience serialization related to that shared scheduling path.

Green contexts can provision dedicated workqueues, helping independent streams avoid being serialized simply because they share the same underlying queue [1:3].

This is a separate consideration from SM partitioning. Assigning different SM subsets controls the execution resources available to workloads; workqueue provisioning helps control how their work is submitted and scheduled.

Together, these capabilities give applications more explicit control over GPU resource sharing.

Lightweight management

Traditional CUDA contexts are relatively heavyweight. Creating and destroying them can involve synchronization with unrelated GPU work and hardware context switches.

Green contexts are designed to be cheaper to manage. NVIDIA describes their creation and destruction as operations that do not synchronize unrelated GPU work in the same way as traditional CUDA context management [1:4].

This matters because the purpose is to manage resources within an application that may already have several active workloads. If creating a resource partition required the same kind of disruptive context management as switching between traditional contexts, it would undermine the flexibility the feature is intended to provide.

Green contexts therefore offer a lighter mechanism for expressing resource allocation within a process.

They should not be confused with a completely separate GPU or an independent physical device. The workloads still share the underlying GPU, but their execution is associated with different subsets of its available resources.

How it works

From implicit device state to an explicit execution context

In a traditional CUDA Runtime workflow, an application selects a device with cudaSetDevice(), creates streams and submits kernels to those streams.

The target execution context is inferred from the Runtime’s device and thread-local state. The application generally works with streams without explicitly associating each one with a separately selected subset of SMs.

Green contexts introduce an explicit execution-context handle into this workflow.

The application creates a green context using:

cudaGreenCtxCreate()

The call returns a cudaExecutionContext_t handle. Streams can then be created from that execution context using:

cudaExecutionCtxStreamCreate()

The important change is that the stream is associated with a particular execution context, rather than implicitly targeting the device-wide execution resources.

Once the stream has been created, the application continues using familiar stream-based CUDA operations. Kernel launches and other stream-ordered work can follow the same general programming model [1:5].

This keeps the integration relatively focused. Developers do not need to replace the entire CUDA execution model to take advantage of resource partitioning. They need to create the appropriate execution contexts and submit work through streams associated with them.

A device-wide execution context

Not every operation should be restricted to a subset of the GPU.

Some workloads need access to the full device, and existing code may already be designed around device-wide execution. CUDA provides a way to obtain the device-wide execution context using:

cudaDeviceGetExecutionCtx()

This allows applications to continue targeting the full device where appropriate [1:6].

The distinction supports incremental adoption. An application can introduce green contexts for selected workloads while leaving other operations associated with the device-wide context.

For example, a latency-sensitive operator could use a dedicated green context, while an existing bulk-processing pipeline continues using the full-device execution context. The application can then measure the effect of the partition and adjust its resource allocation without redesigning every part of the codebase.

The lower-level partitioning APIs are documented in the CUDA Driver API reference [2]. The Runtime API additions provide a more direct way to use green contexts from applications already written around CUDA Runtime operations.

Directing work to the intended resources

The essential workflow is straightforward:

  1. Identify the workload that needs dedicated execution capacity.
  2. Create a green context with the selected GPU resources.
  3. Create streams associated with that context.
  4. Submit the critical workload through those streams.
  5. Submit bulk work through a different context or the device-wide execution context.
  6. Measure latency and throughput to determine whether the partition is appropriate.

The application is responsible for choosing the resource allocation. Green contexts provide the mechanism, but they do not automatically determine the correct number of SMs for every workload.

That choice depends on the size and execution characteristics of the critical kernel, the throughput requirements of the background workload and the amount of contention that exists between them.

This is why the feature is best understood as an explicit resource-management capability rather than an automatic GPU optimization.

What happened

NVIDIA demonstrated green contexts using a small critical kernel running alongside a bulk workload on a Blackwell GPU with 148 SMs [1:7].

The bulk workload consisted of 20 back-to-back launches of a loop involving four million threads. While this workload kept the GPU busy, NVIDIA measured how long a small critical kernel took to complete under different scheduling configurations.

The comparison used three configurations.

| Configuration | Critical kernel latency | |—|—:| | Default context, equal priority | 3.727 ms | | Default context, high-priority critical stream | 0.140 ms | | Green context: 8 SMs for critical, 140 for bulk | 0.007 ms |

The results show the difference between prioritizing work and reserving resources for it.

Default context with equal priority

In the first configuration, both workloads used the default context with equal stream priority.

The critical kernel competed with the bulk workload for GPU execution resources. Because the bulk workload consisted of repeated launches that kept the GPU occupied, the critical kernel experienced substantial waiting time.

Its measured latency was 3.727 milliseconds [1:8].

This is the baseline result. It illustrates what can happen when workloads with different latency requirements share the same execution resources without an explicit prioritization or partitioning strategy.

High-priority stream

In the second configuration, NVIDIA assigned the critical kernel a high-priority stream while leaving both workloads in the default context.

The critical kernel’s latency fell from 3.727 milliseconds to 0.140 milliseconds [1:9].

That is approximately a 27x improvement over the equal-priority configuration.

Stream priority clearly helped. The scheduler could give preference to the critical work when it had an opportunity to schedule it.

However, the result also illustrates the limitation of priority-based scheduling. The critical kernel still had to contend with resources occupied by already-running thread blocks. A higher priority does not mean that executing blocks can be preempted immediately to make room for urgent work.

The critical kernel therefore remained exposed to the time required for those blocks to finish and release resources.

Green context with eight dedicated SMs

In the third configuration, NVIDIA created a green context with eight SMs for the critical kernel and allocated the remaining 140 SMs to the bulk workload.

The critical kernel’s latency dropped to 0.007 milliseconds, or seven microseconds [1:10].

Compared with the high-priority stream configuration, this is a further 20x reduction. Compared with the equal-priority baseline, the improvement is much larger.

<box border radius=“lg” padding={3} gap={3}> Critical kernel latency across the three configurations <box gap={1}> <row justify=“between”> <text size=“sm” color=“secondary”>Equal priority</text> 3.727 ms </row> <box background=“surface-tertiary” height=“12px” radius=“full” clip> <box background=“#8492a6” width=“100%” height=“12px” radius=“full”/> </box> </box> <box gap={1}> <row justify=“between”> <text size=“sm” color=“secondary”>High-priority stream</text> 0.140 ms </row> <box background=“surface-tertiary” height=“12px” radius=“full” clip> <box background=“#3984d6” width=“3.76%” height=“12px” radius=“full”/> </box> </box> <box gap={1}> <row justify=“between”> <text size=“sm” color=“secondary”>Green context</text> 0.007 ms </row> <box background=“surface-tertiary” height=“12px” radius=“full” clip> <box background=“#16a36a” width=“0.19%” height=“12px” radius=“full”/> </box> </box> <text color=“secondary” size=“xs”>NVIDIA’s synthetic test on a 148-SM Blackwell GPU. Bar lengths are relative to the 3.727 ms baseline. [1:11]</text> </box>

The result demonstrates the value of resource isolation. The critical kernel no longer needs to wait for the bulk workload to release the SMs it requires. Its execution is directed to a reserved subset of the GPU.

The bulk workload continues running, but it has fewer SMs available. This is the explicit trade-off behind the result: lower latency for one workload is achieved by limiting the resources available to another.

The benchmark is deliberately small and designed to demonstrate the scheduling behavior. It should not be interpreted as a universal 20x improvement for every application. Actual gains will depend on kernel characteristics, resource allocation and the competing workloads.

Nevertheless, the experiment makes the distinction between stream priority and resource partitioning clear. Priority asks the scheduler to prefer one workload. A green context gives that workload a defined portion of the GPU on which to execute.

What data and AI engineers should do

Green contexts are most relevant to teams running multiple GPU workloads in one process, especially when some operations have tighter latency requirements than others.

Several practical considerations can help determine whether the feature is worth adopting.

  • Use green contexts when predictable latency matters more than best-effort priority. If a small critical kernel repeatedly waits behind a large workload, a dedicated SM partition may provide more control than stream priorities alone. This is particularly relevant to inference serving, communication/compute overlap in distributed training and real-time processing pipelines [1:12].

  • Identify the critical workload before partitioning. Not every kernel needs dedicated resources. Start with operations whose latency has a meaningful impact on the application, then determine whether their execution is being delayed by contention from other GPU work.

  • Size the partition deliberately. NVIDIA’s example reserves eight of 148 SMs for the critical workload, but that is a demonstration rather than a recommended default. A small kernel may need only a limited allocation, while a larger one may require more. Every SM assigned to the critical context is taken away from the bulk workload.

  • Measure both latency and throughput. Improving the critical kernel’s latency does not establish that the overall application has become faster. The bulk workload may take longer because it has fewer SMs. Measure the latency-sensitive operation, background completion time and total throughput together.

  • Combine green contexts with stream priorities where useful. NVIDIA notes that advanced configurations can use both mechanisms [1:13]. Resource partitioning and scheduling priority address different aspects of execution, so they can complement each other rather than being treated as mutually exclusive choices.

  • Adopt incrementally. Green contexts are opt-in and additive. Existing code can continue targeting the full device, while selected workloads are moved to dedicated execution contexts [1:14]. This makes it possible to evaluate the feature without redesigning the entire application.

  • Review workqueue behavior as well as SM allocation. SM partitions determine where kernels can execute, while dedicated workqueues can help prevent independent streams from being serialized through a shared queue. Both dimensions may matter when several workloads operate concurrently.

  • Use realistic concurrency tests. A single critical kernel competing with a synthetic bulk workload is useful for understanding the mechanism, but production systems often have several stages and different kernel sizes. Benchmark the actual workload mix and the timing requirements that matter to the application.

For AI infrastructure teams, the most useful question is not whether green contexts make a GPU faster in general. It is whether dedicating a small amount of execution capacity to a critical operation can make the application’s latency more predictable without imposing an unacceptable throughput penalty elsewhere.

Limitations and open questions

The benchmark demonstrates a substantial latency improvement, but it is a synthetic single-GPU experiment designed to illustrate the effect of green contexts. The results should therefore be treated as evidence of the mechanism rather than a performance guarantee for production workloads.

The first limitation is the resource trade-off. In NVIDIA’s example, eight SMs are reserved for the critical kernel and 140 remain available to the bulk workload. The critical operation becomes much faster, but the background workload has less execution capacity. The post does not show the bulk workload’s own runtime in the partitioned configuration.

That missing measurement matters when evaluating the overall value of the approach. If a latency-sensitive operation is improved significantly but the bulk workload slows down enough to reduce total throughput, the application needs to determine whether the trade-off is acceptable.

Second, the appropriate partition size will vary. The eight-SM allocation is specific to the demonstration. A different kernel may need more execution capacity, while another may not benefit from dedicating as many SMs. The best allocation depends on the workload and must be measured.

Third, green contexts address resource sharing within one process. They should not be confused with a general solution for sharing GPU resources across multiple processes or containers. Multi-process GPU scheduling and isolation introduce separate considerations that are outside the scope of the demonstrated mechanism.

Fourth, the results do not establish how every workload will behave when SMs and workqueues are partitioned together. Some applications may be limited primarily by SM contention, while others may experience serialization or scheduling overhead elsewhere in the execution path.

Finally, there is a broader resource-management question: how should applications decide when to create, resize or destroy green contexts? The feature provides explicit control, but that also places responsibility on developers to understand their workload mix and allocate resources appropriately. Static partitions may be suitable for predictable workloads, while applications with changing demand may need a more deliberate management strategy.

The practical conclusion is that green contexts offer a useful new control point, not an automatic replacement for CUDA streams or priorities. Their value depends on whether the application has identifiable workloads that benefit from dedicated execution capacity and whether the remaining GPU resources can still satisfy throughput requirements.

Key takeaways

  • CUDA 13.1 brings green contexts to the Runtime API, allowing applications to partition GPU execution resources through explicit execution-context handles. [1:15]
  • Green contexts can assign subsets of SMs and provision workqueues, giving independent workloads more control over where and how their work executes. [1:16]
  • Unlike stream priorities, which cannot preempt already-running thread blocks, SM partitioning reserves execution capacity for critical work in advance. [1:17]
  • In NVIDIA’s Blackwell demonstration, dedicating eight of 148 SMs to a critical kernel reduced its latency from 0.140 milliseconds with a high-priority stream to 0.007 milliseconds. [1:18]
  • The improvement comes with a trade-off: the bulk workload has fewer SMs available, so applications must measure latency and throughput together. [1:19]
  • Green contexts are lightweight and opt-in, allowing developers to introduce resource partitioning for selected workloads while existing code continues to target the full device. [1:20]
  • The feature is designed for resource management within one process; GPU sharing across processes or containers is a separate problem.

Green contexts introduce a useful shift in how CUDA applications can manage concurrent GPU workloads. Stream priorities allow developers to express which work should receive preference, but they do not guarantee that resources will be available when a critical kernel needs them. By assigning a subset of SMs and workqueues to a dedicated execution context, applications can reserve capacity for operations where latency matters.

For AI infrastructure teams, this is especially relevant as GPU applications increasingly combine inference, preprocessing, communication and background computation on the same device. Not every workload needs the entire GPU, and not every operation can tolerate waiting behind a long-running kernel.

CUDA 13.1’s Runtime API support makes green contexts easier to introduce into existing applications. The challenge shifts from asking the scheduler to prioritize critical work to deciding how much execution capacity that work should receive. Used selectively and measured against the throughput cost, green contexts offer a more explicit path toward predictable latency on shared GPUs.

Sources


  1. NVIDIA Technical Blog, “Control How Your GPU Shares Work with Green Contexts”, 2026-10-06. https://developer.nvidia.com/blog/control-how-your-gpu-shares-work-with-green-contexts/ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎

  2. NVIDIA CUDA Driver API documentation, “Green Contexts”. https://docs.nvidia.com/cuda/cuda-driver-api/cuda_driver_api/group__CUDA__GREEN__CONTEXTS.html ↩︎

Discussion

Join the discussion: create a free account or sign in to comment.

No comments yet.

Keep reading

NVIDIA cuOpt mPDLP: Solving 100-Million-Variable Linear Programs Across Multiple GPUs
AI Engineering

NVIDIA cuOpt mPDLP: Solving 100-Million-Variable Linear Programs Across Multiple GPUs

cuOpt's new multi-GPU PDLP solver splits huge LP problems across NVLink-connected GPUs using min-cut partitioning, cutting per-GPU memory by up to 6x. Gains appear above 10 million nonzeros.

Nov 28, 2026 · 19 min read
Private AI Workflows on One NVIDIA DGX Spark: n8n, vLLM and LiteLLM With No Cloud API
AI Engineering

Private AI Workflows on One NVIDIA DGX Spark: n8n, vLLM and LiteLLM With No Cloud API

n8n served seven models from one 128GB DGX Spark behind a single OpenAI-compatible endpoint. Qwen3.6-35B-A3B ran at 120 tokens per second for one user and 359 in total for eight, but image generation cut chat speed to a third.

Nov 14, 2026 · 5 min read
TorchTPU: PyTorch Runs Natively on Google TPUs, and Hugging Face Models Come Along
AI Engineering

TorchTPU: PyTorch Runs Natively on Google TPUs, and Hugging Face Models Come Along

Google and Meta built TorchTPU, a native PyTorch backend for TPUs with eager execution and torch.compile. Hugging Face Transformers, Diffusers and Kernels now treat "tpu" as just another device.

Nov 15, 2026 · 5 min read