Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
86 changes: 43 additions & 43 deletions cuda_bindings/pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cuda_core/cuda/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
finally:
del bindings, importlib, subdir, cuda_major, cuda_minor

from cuda.core import system, utils
from cuda.core import managed_memory, system, utils
from cuda.core._device import Device
from cuda.core._event import Event, EventOptions
from cuda.core._graph import (
Expand Down
9 changes: 9 additions & 0 deletions cuda_core/cuda/core/_memory/_buffer.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from libc.stdint cimport uintptr_t

from cuda.bindings cimport cydriver
from cuda.core._resource_handles cimport DevicePtrHandle
from cuda.core._stream cimport Stream

Expand All @@ -12,6 +13,7 @@ cdef struct _MemAttrs:
int device_id
bint is_device_accessible
bint is_host_accessible
bint is_managed


cdef class Buffer:
Expand All @@ -37,3 +39,10 @@ cdef Buffer Buffer_from_deviceptr_handle(
MemoryResource mr,
object ipc_descriptor = *
)

# Memory attribute query helpers (used by _managed_memory_ops)
cdef void _init_mem_attrs(Buffer self)
cdef int _query_memory_attrs(
_MemAttrs& out,
cydriver.CUdeviceptr ptr,
) except -1 nogil
8 changes: 6 additions & 2 deletions cuda_core/cuda/core/_memory/_buffer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ A type union of :obj:`~driver.CUdeviceptr`, `int` and `None` for hinting
:attr:`Buffer.handle`.
"""


cdef class Buffer:
"""Represent a handle to allocated memory.

Expand Down Expand Up @@ -420,14 +421,14 @@ cdef class Buffer:

# Memory Attribute Query Helpers
# ------------------------------
cdef inline void _init_mem_attrs(Buffer self):
cdef void _init_mem_attrs(Buffer self):
"""Initialize memory attributes by querying the pointer."""
if not self._mem_attrs_inited:
_query_memory_attrs(self._mem_attrs, as_cu(self._h_ptr))
self._mem_attrs_inited = True


cdef inline int _query_memory_attrs(
cdef int _query_memory_attrs(
_MemAttrs& out,
cydriver.CUdeviceptr ptr
) except -1 nogil:
Expand Down Expand Up @@ -459,6 +460,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 +469,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 != 0
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: 6 additions & 0 deletions cuda_core/cuda/core/_memory/_managed_memory_ops.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0

# Managed-memory operation helpers (advise, prefetch, discard_prefetch).
# The public API is exposed via def functions; no cdef declarations needed.
Loading
Loading