Prefer to read without ads? Become a member — from $10/month — and support the work. Already a member? Log in to read ad-free on this device.

7.7 Green Contexts

A CUDA context (Section 3.3) traditionally owns the entire GPU: any kernel launched in it may occupy every multiprocessor on the device. Green contexts, added to the driver API in CUDA 12.4, allow an application to carve the GPU’s multiprocessors into partitions and create lightweight contexts that own only a share of them. The application queries the device’s SM resource with cuDeviceGetDevResource(), splits it with cuDevSmResourceSplitByCount(), generates a descriptor with cuDevResourceGenerateDesc(), and creates the green context with cuGreenCtxCreate(); streams created in the green context with cuGreenCtxStreamCreate() then launch work onto that partition’s multiprocessors only.

The motivating use case is spatial partitioning within a single process: reserving a set of multiprocessors for latency-critical work so that bulk throughput work in the rest of the GPU cannot crowd it out. Green contexts share the process’s address space and are much lighter-weight and more dynamic than the hardware partitioning of MIG or the process-level sharing of MPS – but the isolation is correspondingly softer, covering compute resources only, with memory bandwidth and the L2 cache still shared.