Skip to content
Merged
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
4 changes: 4 additions & 0 deletions cuda_core/cuda/core/_context.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ cdef class Context:
return None
return as_py(self._h_context)

@property
def _handle(self):
return self.handle

def __eq__(self, other):
if not isinstance(other, Context):
return NotImplemented
Expand Down
6 changes: 4 additions & 2 deletions cuda_core/cuda/core/_cpp/resource_handles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,8 @@ LibraryHandle create_library_handle_from_file(const char* path) {
new LibraryBox{library},
[](const LibraryBox* b) {
GILReleaseGuard gil;
p_cuLibraryUnload(b->resource);
// TODO: re-enable once LibraryBox tracks its owning context
// p_cuLibraryUnload(b->resource);
Comment on lines -753 to +754
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for posterity: This restores the old behavior since cuda.core 0.1.0 (this was changed when module/library was cythonized).

delete b;
}
);
Expand All @@ -768,7 +769,8 @@ LibraryHandle create_library_handle_from_data(const void* data) {
new LibraryBox{library},
[](const LibraryBox* b) {
GILReleaseGuard gil;
p_cuLibraryUnload(b->resource);
// TODO: re-enable once LibraryBox tracks its owning context
// p_cuLibraryUnload(b->resource);
delete b;
}
);
Expand Down
8 changes: 4 additions & 4 deletions cuda_core/cuda/core/_event.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ cdef class IPCEventDescriptor:
def __init__(self, *arg, **kwargs):
raise RuntimeError("IPCEventDescriptor objects cannot be instantiated directly. Please use Event APIs.")

@classmethod
def _init(cls, reserved: bytes, busy_waited: cython.bint):
cdef IPCEventDescriptor self = IPCEventDescriptor.__new__(cls)
@staticmethod
def _init(reserved: bytes, busy_waited: cython.bint):
cdef IPCEventDescriptor self = IPCEventDescriptor.__new__(IPCEventDescriptor)
self._reserved = reserved
self._busy_waited = busy_waited
return self
Expand All @@ -307,7 +307,7 @@ cdef class IPCEventDescriptor:
return self._reserved == rhs._reserved

def __reduce__(self):
return self._init, (self._reserved, self._busy_waited)
return IPCEventDescriptor._init, (self._reserved, self._busy_waited)


def _reduce_event(event):
Expand Down
6 changes: 5 additions & 1 deletion cuda_core/cuda/core/_memory/_buffer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,13 @@ cdef class Buffer:
self._mem_attrs_inited = False
return self

@staticmethod
def _reduce_helper(mr, ipc_descriptor):
return Buffer.from_ipc_descriptor(mr, ipc_descriptor)

def __reduce__(self):
# Must not serialize the parent's stream!
return Buffer.from_ipc_descriptor, (self.memory_resource, self.get_ipc_descriptor())
return Buffer._reduce_helper, (self.memory_resource, self.get_ipc_descriptor())

@staticmethod
def from_handle(
Expand Down
8 changes: 4 additions & 4 deletions cuda_core/cuda/core/_memory/_ipc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ cdef class IPCBufferDescriptor:
def __init__(self, *arg, **kwargs):
raise RuntimeError("IPCBufferDescriptor objects cannot be instantiated directly. Please use MemoryResource APIs.")

@classmethod
def _init(cls, reserved: bytes, size: int):
cdef IPCBufferDescriptor self = IPCBufferDescriptor.__new__(cls)
@staticmethod
def _init(reserved: bytes, size: int):
cdef IPCBufferDescriptor self = IPCBufferDescriptor.__new__(IPCBufferDescriptor)
self._payload = reserved
self._size = size
return self

def __reduce__(self):
return self._init, (self._payload, self._size)
return IPCBufferDescriptor._init, (self._payload, self._size)

@property
def size(self):
Expand Down
11 changes: 7 additions & 4 deletions cuda_core/cuda/core/_module.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ cdef class Kernel:
"""
return as_py(self._h_kernel)

@property
def _handle(self):
return self.handle

@staticmethod
def from_handle(handle, mod: ObjectCode = None) -> Kernel:
"""Creates a new :obj:`Kernel` object from a foreign kernel handle.
Expand Down Expand Up @@ -657,10 +661,9 @@ cdef class ObjectCode:

return self

@classmethod
def _reduce_helper(cls, module, code_type, name, symbol_mapping):
# just for forwarding kwargs
return cls._init(module, code_type, name=name if name else "", symbol_mapping=symbol_mapping)
@staticmethod
def _reduce_helper(module, code_type, name, symbol_mapping):
return ObjectCode._init(module, code_type, name=name if name else "", symbol_mapping=symbol_mapping)

def __reduce__(self):
return ObjectCode._reduce_helper, (self._module, self._code_type, self._name, self._sym_map)
Expand Down
4 changes: 4 additions & 0 deletions cuda_core/docs/nv-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "latest",
"url": "https://nvidia.github.io/cuda-python/cuda-core/latest/"
},
{
"version": "0.6.0",
"url": "https://nvidia.github.io/cuda-python/cuda-core/0.6.0/"
},
{
"version": "0.5.1",
"url": "https://nvidia.github.io/cuda-python/cuda-core/0.5.1/"
Expand Down
8 changes: 7 additions & 1 deletion cuda_core/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
except ImportError:
torch = None
import cuda.core
import ml_dtypes

try:
import ml_dtypes
except ImportError:
ml_dtypes = None
import numpy as np
import pytest
from cuda.core import Device
Expand Down Expand Up @@ -545,6 +549,7 @@ def test_from_array_interface_unsupported_strides(init_cuda):
param((slice(None, None, 2), slice(1, None, 2)), id="strided"),
],
)
@pytest.mark.skipif(ml_dtypes is None, reason="ml_dtypes is not installed")
@pytest.mark.skipif(cp is None, reason="CuPy is not installed")
@pytest.mark.skipif(cp is not None and _get_cupy_version_major() < 14, reason="CuPy version is less than 14.0.0")
def test_ml_dtypes_bfloat16_dlpack(init_cuda, slices):
Expand Down Expand Up @@ -575,6 +580,7 @@ def test_ml_dtypes_bfloat16_dlpack(init_cuda, slices):
param((slice(None, None, 2), slice(1, None, 2)), id="strided"),
],
)
@pytest.mark.skipif(ml_dtypes is None, reason="ml_dtypes is not installed")
@pytest.mark.skipif(torch is None, reason="PyTorch is not installed")
def test_ml_dtypes_bfloat16_torch_dlpack(init_cuda, slices):
a = torch.tensor([1, 2, 3, 4, 5, 6], dtype=torch.bfloat16, device="cuda").reshape(2, 3)[slices]
Expand Down
Loading