Legacy resources#

2026-10-23

1 min read time

Applies to Linux and Windows

Legacy memory resources provide synchronous allocation interfaces backed by the HIP runtime’s legacy allocation APIs. They are primarily intended for compatibility with platforms that do not support the newer memory pool-based resources. Prefer the modern memory resources where available.

In libhipcxx, the pinned and managed memory pools are not available, so these resources are the way to allocate pinned (page-locked) host memory and managed (unified) memory through the memory resource interface.

For the full memory resource model and property system, see Memory Resources (Extended API).

cuda::mr::legacy_pinned_memory_resource#

Provides pinned (page-locked) host allocations using hipHostMalloc and hipHostFree. This resource is synchronous-only and is intended as a compatibility fallback. See Pinned host memory.

#include <cuda/memory_resource>

void use_legacy_pinned() {
  cuda::mr::legacy_pinned_memory_resource resource{};
  void* ptr = resource.allocate_sync(1024, 64);
  // Use memory...
  resource.deallocate_sync(ptr, 1024, 64);
}

cuda::mr::legacy_managed_memory_resource#

Provides managed (unified) allocations using hipMallocManaged and hipFree. This resource is synchronous-only and accepts the HIP attachment flags (hipMemAttachGlobal / hipMemAttachHost). See Managed memory.

#include <cuda/memory_resource>

void use_legacy_managed() {
  cuda::mr::legacy_managed_memory_resource resource{hipMemAttachGlobal};
  void* ptr = resource.allocate_sync(1024, 64);
  // Use memory...
  resource.deallocate_sync(ptr, 1024, 64);
}