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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ repos:
pass_filenames: false
require_serial: true
additional_dependencies:
- Cython==3.2.9
- Cython==3.3.2


default_language_version:
Expand Down
624 changes: 239 additions & 385 deletions cuda_bindings_12/pixi.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions cuda_bindings_12/pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cuda-python-test-helpers = { path = "../cuda_python_test_helpers", editable = tr
[feature.docs.dependencies]
cuda-bindings = "12.9.*"
python = "3.12.*"
cython = ">=3.2.5,<3.3"
cython = ">=3.3.1,<3.4"
enum_tools = "*"
furo = "*"
make = "*"
Expand All @@ -44,7 +44,7 @@ sphinx-copybutton = "*"
sphinx-toolbox = "*"

[feature.cython-tests.dependencies]
cython = ">=3.2.5,<3.3" # for tests that exercise APIs from cython
cython = ">=3.3.1,<3.4" # for tests that exercise APIs from cython
setuptools = "*" # for distutils
gxx = "*" # to compile the generated code
# These are necessary because running the Cython tests requires compiling
Expand Down Expand Up @@ -111,7 +111,7 @@ python = "*"
cuda-version = "12.*"
setuptools = ">=80"
setuptools-scm = ">=8,!=10.1"
cython = ">=3.2.5,<3.3"
cython = ">=3.3.1,<3.4"
cuda-pathfinder = { path = "../cuda_pathfinder" }
cuda-cudart-static = "*"
cuda-nvrtc-dev = "*"
Expand Down
6 changes: 3 additions & 3 deletions cuda_bindings_12/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
requires = [
"setuptools>=80.0.0",
"setuptools-scm[simple]>=8,!=10.1",
"cython>=3.2.5,<3.3",
"cython>=3.3.1,<3.4",
]
build-backend = "build_hooks"
backend-path = ["."]
Expand Down Expand Up @@ -52,11 +52,11 @@ all = [
build = [
"setuptools>=80.0.0",
"setuptools-scm[simple]>=8,!=10.1",
"cython>=3.2.5,<3.3",
"cython>=3.3.1,<3.4",
]
test = [
"cuda-pathfinder>=1.5",
"cython>=3.2.5,<3.3",
"cython>=3.3.1,<3.4",
"setuptools>=80.0.0",
"numpy>=1.21.1",
"pytest==9.1.0",
Expand Down
1,039 changes: 463 additions & 576 deletions cuda_bindings_13/pixi.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions cuda_bindings_13/pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cuda-python-test-helpers = { path = "../cuda_python_test_helpers", editable = tr
# Document the checkout's API, including modules absent from published packages.
cuda-bindings = { path = "." }
python = "3.12.*"
cython = ">=3.2.5,<3.3"
cython = ">=3.3.1,<3.4"
enum_tools = "*"
make = "*"
myst-nb = "*"
Expand All @@ -47,7 +47,7 @@ sphinx-copybutton = "*"
sphinx-toolbox = "*"

[feature.cython-tests.dependencies]
cython = ">=3.2.5,<3.3" # for tests that exercise APIs from cython
cython = ">=3.3.1,<3.4" # for tests that exercise APIs from cython
setuptools = "*" # for distutils
gxx = "*" # to compile the generated code
# These are necessary because running the Cython tests requires compiling
Expand Down Expand Up @@ -124,7 +124,7 @@ python = "*"
cuda-version = "*"
setuptools = ">=80"
setuptools-scm = ">=8"
cython = ">=3.2.5,<3.3"
cython = ">=3.3.1,<3.4"
cuda-pathfinder = { path = "../cuda_pathfinder" }
cuda-cudart-static = "*"
cuda-nvrtc-dev = "*"
Expand Down
6 changes: 3 additions & 3 deletions cuda_bindings_13/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
requires = [
"setuptools>=80.0.0",
"setuptools_scm[simple]>=8,!=10.1",
"cython>=3.2.5,<3.3",
"cython>=3.3.1,<3.4",
"cuda-pathfinder>=1.5",
]
build-backend = "build_hooks"
Expand Down Expand Up @@ -47,11 +47,11 @@ all = [
build = [
"setuptools>=80.0.0",
"setuptools_scm[simple]>=8,!=10.1",
"cython>=3.2.5,<3.3",
"cython>=3.3.1,<3.4",
]
test = [
"cuda-pathfinder>=1.5",
"cython>=3.2.5,<3.3",
"cython>=3.3.1,<3.4",
"setuptools>=80.0.0",
"numpy>=1.21.1",
"pytest==9.1.0",
Expand Down
4 changes: 2 additions & 2 deletions cuda_core/cuda/core/_device_resources.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SMResourceOptions:
preferred_coscheduled_sm_count: int | SequenceABC[int] | None = None
backfill: bool | SequenceABC[bool] = False

@dataclass
@dataclass(init=False)
class WorkqueueResourceOptions:
"""Customizable :obj:`WorkqueueResource.configure` options.

Expand All @@ -60,7 +60,7 @@ class WorkqueueResourceOptions:
sharing_scope: WorkqueueSharingScopeType | str | None = None
concurrency_limit: int | None = None

def __post_init__(self): ...
def __init__(self, sharing_scope: WorkqueueSharingScopeType | str | None=None, concurrency_limit: int | None=None): ...

class SMResource:
"""Represent an SM (streaming multiprocessor) resource partition.
Expand Down
16 changes: 11 additions & 5 deletions cuda_core/cuda/core/_device_resources.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ cdef class SMResourceOptions:
backfill: bool | SequenceABC[bool] = False


@dataclass
@dataclass(init=False)
cdef class WorkqueueResourceOptions:
"""Customizable :obj:`WorkqueueResource.configure` options.

Expand All @@ -131,13 +131,19 @@ cdef class WorkqueueResourceOptions:
sharing_scope: WorkqueueSharingScopeType | str | None = None
concurrency_limit: int | None = None

def __post_init__(self):
def __init__(
self,
sharing_scope: WorkqueueSharingScopeType | str | None = None,
concurrency_limit: int | None = None,
):
from cuda.core.typing import WorkqueueSharingScopeType
check_str_enum(self.sharing_scope, WorkqueueSharingScopeType, allow_none=True)
if self.concurrency_limit is not None and self.concurrency_limit < 1:
check_str_enum(sharing_scope, WorkqueueSharingScopeType, allow_none=True)
if concurrency_limit is not None and concurrency_limit < 1:
raise ValueError(
f"concurrency_limit must be >= 1, got {self.concurrency_limit}"
f"concurrency_limit must be >= 1, got {concurrency_limit}"
)
self.sharing_scope = sharing_scope
self.concurrency_limit = concurrency_limit


cdef inline int _validate_split_field_length(
Expand Down
14 changes: 9 additions & 5 deletions cuda_core/cuda/core/_memory/_buffer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ cdef class Buffer:
return _ipc.Buffer_from_ipc_descriptor(cls, mr, ipc_descriptor, stream)

@property
@cython.critical_section
def ipc_descriptor(self) -> IPCBufferDescriptor:
"""Descriptor for sharing this buffer with other processes.

Expand All @@ -448,11 +447,16 @@ cdef class Buffer:
"""
Buffer_check_open(self)
cdef object ipc_data
if self._ipc_data is None:
with cython.critical_section(self):
ipc_data = self._ipc_data
if ipc_data is None:
ipc_data = IPCDataForBuffer(_ipc.Buffer_get_ipc_descriptor(self), False)
if self._ipc_data is None:
self._ipc_data = ipc_data
return self._ipc_data.ipc_descriptor
with cython.critical_section(self):
if self._ipc_data is None:
self._ipc_data = ipc_data
else:
ipc_data = self._ipc_data
return ipc_data.ipc_descriptor

def close(self, stream: Stream | GraphBuilder | None = None) -> None:
"""Deallocate this buffer asynchronously on the given stream.
Expand Down
55 changes: 35 additions & 20 deletions cuda_core/cuda/core/_memoryview.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,25 @@ cdef inline bint _torch_version_check():

cdef object _get_torch_tensor_type():
global _torch_tensor_type
cdef object tensor_type
with cython.critical_section(_torch_type_cache):
if _torch_tensor_type is None:
torch = sys.modules.get("torch")
tensor_type = getattr(torch, "Tensor", None)
if tensor_type is None:
# Torch may be imported after an earlier protocol-only call.
return None
_torch_tensor_type = tensor_type
if not _torch_version_check():
tensor_type = _torch_tensor_type
if tensor_type is None:
torch = sys.modules.get("torch")
tensor_type = getattr(torch, "Tensor", None)
if tensor_type is None:
# Torch may be imported after an earlier protocol-only call.
return None
return _torch_tensor_type
# The critical section only protects the check-and-set of the
# cached global; the Python-level lookups above run outside it.
with cython.critical_section(_torch_type_cache):
if _torch_tensor_type is None:
_torch_tensor_type = tensor_type
else:
tensor_type = _torch_tensor_type
if not _torch_version_check():
return None
return tensor_type


cdef inline bint _is_torch_tensor(object obj):
Expand Down Expand Up @@ -585,7 +593,6 @@ cdef class StridedMemoryView:
self._layout = layout
return self._layout

@cython.critical_section
cdef inline object get_buffer(self):
"""
Returns Buffer instance with the underlying data.
Expand All @@ -594,7 +601,9 @@ cdef class StridedMemoryView:
Otherwise, it will create a new instance with owner set to the exporting object.
"""
cdef object buffer
if self._buffer is None:
with cython.critical_section(self):
buffer = self._buffer
if buffer is None:
if isinstance(self.exporting_obj, Buffer):
buffer = self.exporting_obj
elif self.dl_tensor != NULL:
Expand All @@ -604,15 +613,18 @@ cdef class StridedMemoryView:
return Buffer.from_handle(self.ptr, 0, owner=self)
else:
buffer = Buffer.from_handle(self.ptr, 0, owner=self.exporting_obj)
if self._buffer is None:
self._buffer = buffer
return self._buffer
with cython.critical_section(self):
if self._buffer is None:
self._buffer = buffer
else:
buffer = self._buffer
return buffer

@cython.critical_section
cdef inline object get_dtype(self):
cdef object dtype
if self._dtype is None:
dtype = None
with cython.critical_section(self):
dtype = self._dtype
if dtype is None:
if self.dl_tensor != NULL:
dtype = dtype_dlpack_to_numpy(&self.dl_tensor.dtype)
elif isinstance(self.metadata, int):
Expand All @@ -621,9 +633,12 @@ cdef class StridedMemoryView:
self.metadata)
elif self.metadata is not None:
dtype = _typestr2dtype(self.metadata["typestr"])
if self._dtype is None:
self._dtype = dtype
return self._dtype
with cython.critical_section(self):
if self._dtype is None:
self._dtype = dtype
else:
dtype = self._dtype
return dtype


cdef void _smv_pycapsule_deleter(object capsule) noexcept:
Expand Down
Loading
Loading