Skip to content

ManagedMemoryResource() without options fails when the default pool does not support managed allocations #1617

@Andy-Jost

Description

@Andy-Jost

ManagedMemoryResource() (no options) attempts to retrieve the current memory pool via cuMemGetMemPool with CU_MEM_ALLOCATION_TYPE_MANAGED. On platforms where the default pool does not support managed allocations, this fails with a cryptic error:

CUDAError: CUDA_ERROR_NOT_SUPPORTED: This error indicates that the attempted operation is not supported
on the current system or device.

Meanwhile, ManagedMemoryResource(options=ManagedMemoryResourceOptions(preferred_location=0)) works on the same platform because it creates a new managed pool via cuMemPoolCreate.

Improve the error message so users understand what went wrong, and investigate whether the API should handle this case more gracefully (e.g., by falling back to pool creation).

Reproducer:

from cuda.core import Device, ManagedMemoryResource, ManagedMemoryResourceOptions

device = Device(0)
device.set_current()

# Fails with CUDA_ERROR_NOT_SUPPORTED
mr = ManagedMemoryResource()

# Workaround: succeeds
mr = ManagedMemoryResource(options=ManagedMemoryResourceOptions(preferred_location=0))

Test results:

On WSL2 x86_64 (concurrent_managed_access=False, memory_pools_supported=True):

ManagedMemoryResource() ...
  failed: CUDA_ERROR_NOT_SUPPORTED: This error indicates that the attempted
  operation is not supported on the current system or device.

ManagedMemoryResource(options=ManagedMemoryResourceOptions(preferred_location=0)) ...
  succeeded (device_id=0)

On Linux x86_64 (concurrent_managed_access=True, memory_pools_supported=True):

ManagedMemoryResource() ...
  succeeded (device_id=-1)

ManagedMemoryResource(options=ManagedMemoryResourceOptions(preferred_location=0)) ...
  succeeded (device_id=0)

Metadata

Metadata

Assignees

Labels

P1Medium priority - Should dobugSomething isn't workingcuda.coreEverything related to the cuda.core module

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions