Skip to content

Support explicit CUDA managed-memory allocation #1523

Closed

Description

@shi-eric

Description

Add a first-class way for users to explicitly allocate CUDA managed-memory arrays in Warp without changing the default CUDA allocation behavior.

The feature should:

  • Provide an opt-in allocator path for CUDA managed memory through Warp's existing allocator configuration mechanisms.
  • Preserve the CUDA device/context associated with each allocation so arrays still have normal Warp CUDA device metadata.
  • Record allocation provenance so Warp can distinguish managed-memory arrays from default CUDA, CUDA memory-pool, CPU, custom, and externally wrapped allocations.
  • Update access queries and checked launch validation so managed arrays are validated through CUDA managed-memory capabilities instead of peer-access or CUDA memory-pool access state.
  • Reject unsupported CUDA IPC export for managed-memory arrays with a clear error.
  • Allow managed arrays allocated before CUDA graph capture to be used by captured kernels.
  • Reject managed allocation during CUDA graph capture with a clear error. The initial implementation uses cudaMallocManaged() outside capture on all supported CUDA toolkit builds, including CUDA 13.x builds.

Deferred follow-up

Graph-capturable managed allocation through CUDA 13 managed memory pools is intentionally out of scope for this issue and branch. Track it separately if/when needed, since it requires additional design around managed memory pool creation, graph-capture allocation lifetime, free ordering, and CUDA 12.x compatibility.

Context

Warp currently supports default CUDA allocation and CUDA memory-pool allocation, but it does not provide a first-class opt-in path for CUDA managed-memory arrays. Users working on systems with HMM, ATS, concurrent managed access, or limited managed-memory support need a clear way to request Unified Memory while preserving Warp's normal device metadata and diagnostics.

This feature would let users choose managed memory explicitly while keeping standard CUDA arrays unchanged. It would also let Warp make allocation-aware access decisions: CUDA devices that support managed memory can accept managed arrays without relying on peer-access or memory-pool-access state, CPU access can be gated on the owning CUDA device's managed host-access capabilities, and unknown/custom allocations can remain conservative.

CUDA toolkit compatibility is important. Warp's PyPI build currently uses CUDA 12.9, where CUDA managed memory pools are not available through the runtime enum needed for pool creation. This issue therefore scopes initial support to cudaMallocManaged() outside CUDA graph capture on all supported builds, with clear capture-time rejection. CUDA 13+ managed memory pools can be evaluated separately for graph-capturable managed allocation.

Activity

  1. self-assigned this
    on Jun 4, 2026
  2. added this to the 1.15.0 milestone on Jun 4, 2026
  3. added a commit that references this issue on Jun 25, 2026
  4. shi-eric commented on Jun 26, 2026

    @shi-eric
    ContributorAuthor

    This is addressed by e6a8ed4.

    The change adds an explicit CUDA managed-memory allocator path while preserving default CUDA allocation behavior. Managed arrays keep normal Warp CUDA device metadata, report CUDA_MANAGED through array.memory_kind, and are handled by wp.can_access() and checked launch validation using CUDA managed-memory capabilities. Unsupported CUDA IPC export for managed arrays now raises a clear error. Preallocated managed arrays can be used in CUDA graph captures; allocation during capture is rejected through the cudaMallocManaged() path with CUDA's native diagnostic.

    Public API behavior:

    Python scope:

    • wp.CudaManagedAllocator() is a new allocator that works with the existing allocator APIs.
    • wp.MemoryKind and array.memory_kind expose host, pinned host, CUDA device, CUDA mempool, CUDA managed, and unknown memory kinds.
    • CUDA devices now expose managed-memory capability flags used by access checks.
    • wp.can_access() and checked launch validation use memory kind instead of allocator identity where Warp can classify the allocation.
    • array.ipc_handle() rejects managed-memory arrays, array views, and externally wrapped CUDA pointers with explicit errors.

    Kernel scope:

    • No new kernel builtin API was added. Existing CPU and CUDA kernel launches can use managed arrays when wp.can_access() or checked validation says the target device can access the allocation.

    Test coverage:

    • New tests in warp/tests/test_allocator.py cover MemoryKind values, CPU array memory kinds, managed allocator protocol behavior, managed allocation on the selected CUDA device, deallocation context handling, and managed allocator failure reporting.
    • New tests in warp/tests/cuda/test_unified_memory.py cover CUDA memory-kind queries, wrapped managed pointer classification, managed wp.can_access() behavior, managed IPC rejection, checked CPU launches with managed arrays, preallocated managed arrays in CUDA graph capture, and memory-kind diagnostics for unknown or unowned allocations.
    • Existing unified-memory tests were updated to assert memory-kind-specific checked-launch errors and capability reporting.

    This issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

feature requestRequest for something to be added

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions