Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cuda_core/cuda/core/_memory/_buffer.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cdef struct _MemAttrs:
int device_id
bint is_device_accessible
bint is_host_accessible
bint is_managed


cdef class Buffer:
Expand Down
9 changes: 9 additions & 0 deletions cuda_core/cuda/core/_memory/_buffer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ cdef class Buffer:
_init_mem_attrs(self)
return self._mem_attrs.is_host_accessible

@property
def is_managed(self) -> bool:
"""Return True if this buffer is CUDA managed (unified) memory, otherwise False."""
_init_mem_attrs(self)
return self._mem_attrs.is_managed

@property
def is_mapped(self) -> bool:
"""Return True if this buffer is mapped into the process via IPC."""
Expand Down Expand Up @@ -459,6 +465,7 @@ cdef inline int _query_memory_attrs(
out.is_host_accessible = True
out.is_device_accessible = False
out.device_id = -1
out.is_managed = False
elif (
is_managed
or memory_type == cydriver.CUmemorytype.CU_MEMORYTYPE_HOST
Expand All @@ -467,10 +474,12 @@ cdef inline int _query_memory_attrs(
out.is_host_accessible = True
out.is_device_accessible = True
out.device_id = device_id
out.is_managed = is_managed
elif memory_type == cydriver.CUmemorytype.CU_MEMORYTYPE_DEVICE:
out.is_host_accessible = False
out.is_device_accessible = True
out.device_id = device_id
out.is_managed = False
else:
with cython.gil:
raise ValueError(f"Unsupported memory type: {memory_type}")
Expand Down
6 changes: 4 additions & 2 deletions cuda_core/cuda/core/_memoryview.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,10 @@ cdef inline int _smv_get_dl_device(
device_type = _kDLCUDA
device_id = buf.device_id
elif d and h:
# We do not currently differentiate pinned vs managed here.
device_type = _kDLCUDAHost
if buf.is_managed:
device_type = _kDLCUDAManaged
else:
device_type = _kDLCUDAHost
device_id = 0
elif (not d) and h:
device_type = _kDLCPU
Expand Down
Loading