Skip to content

Commit 2376e08

Browse files
authored
Update to Cython 3.0.0 (rapidsai#1313)
This PR contains the minimal set of changes to compile using Cython 3 without warnings. Future PRs can be made to take advantage of new or improved features. The specific changes are: - Ensuring `nogil` always comes after `except`. `except * nogil` is a compile-time error in Cython 3 - Adding `noexcept` or `except *` to any `cdef ` functions missing them. In Cython 0.29 these would default to `noexcept`, which meant that exceptions would not be properly propagated. In Cython 3.0.0, these default to `except *`, which incurs a performance penalty for reacquiring the GIL to check the exception value even for `nogil` functions. Being explicit here is important. There are a large number of outstanding warnings due to NVIDIA/cuda-python#44. cuda-python for CUDA 12 has the necessary fix, but we will need a cuda-python 11.8.* bugfix with a backport to make those warnings go away. Authors: - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Ashwin Srinath (https://github.com/shwina) - Lawrence Mitchell (https://github.com/wence-) - Ray Douglass (https://github.com/raydouglass) URL: rapidsai#1313
1 parent c4618eb commit 2376e08

File tree

12 files changed

+33
-23
lines changed

12 files changed

+33
-23
lines changed

conda/environments/all_cuda-118_arch-x86_64.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dependencies:
88
- cuda-python>=11.7.1,<12.0a0
99
- cuda-version=11.8
1010
- cudatoolkit
11-
- cython>=0.29,<0.30
11+
- cython>=3.0.0
1212
- fmt>=9.1.0,<10
1313
- gcovr>=5.0
1414
- identify>=2.5.20

conda/environments/all_cuda-120_arch-x86_64.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dependencies:
88
- cuda-nvcc
99
- cuda-python>=12.0,<13.0a0
1010
- cuda-version=12.0
11-
- cython>=0.29,<0.30
11+
- cython>=3.0.0
1212
- fmt>=9.1.0,<10
1313
- gcovr>=5.0
1414
- identify>=2.5.20

conda/recipes/rmm/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ requirements:
5858
- cuda-cudart-dev
5959
- cuda-python ==12.0.0
6060
{% endif %}
61-
- cython >=0.29,<0.30
61+
- cython >=3.0.0
6262
- librmm ={{ version }}
6363
- python
6464
- scikit-build >=0.13.1

dependencies.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ dependencies:
6262
- output_types: [conda, requirements, pyproject]
6363
packages:
6464
- &cmake_ver cmake>=3.26.4
65-
- cython>=0.29,<0.30
65+
- cython>=3.0.0
6666
- ninja
6767
- scikit-build>=0.13.1
6868
- tomli

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ build-backend = "setuptools.build_meta"
1717
requires = [
1818
"cmake>=3.26.4",
1919
"cuda-python>=11.7.1,<12.0a0",
20-
"cython>=0.29,<0.30",
20+
"cython>=3.0.0",
2121
"ninja",
2222
"scikit-build>=0.13.1",
2323
"setuptools>=61.0.0",

python/rmm/_cuda/stream.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ cdef class Stream:
2626
@staticmethod
2727
cdef Stream _from_cudaStream_t(cudaStream_t s, object owner=*)
2828

29-
cdef cuda_stream_view view(self) nogil except *
30-
cdef void c_synchronize(self) nogil except *
31-
cdef bool c_is_default(self) nogil except *
29+
cdef cuda_stream_view view(self) except * nogil
30+
cdef void c_synchronize(self) except * nogil
31+
cdef bool c_is_default(self) except * nogil
3232
cdef void _init_with_new_cuda_stream(self) except *
3333
cdef void _init_from_stream(self, Stream stream) except *

python/rmm/_cuda/stream.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ cdef class Stream:
4848
self._init_from_cupy_stream(obj)
4949

5050
@staticmethod
51-
cdef Stream _from_cudaStream_t(cudaStream_t s, object owner=None):
51+
cdef Stream _from_cudaStream_t(cudaStream_t s, object owner=None) except *:
5252
"""
5353
Construct a Stream from a cudaStream_t.
5454
"""
@@ -57,13 +57,13 @@ cdef class Stream:
5757
obj._owner = owner
5858
return obj
5959

60-
cdef cuda_stream_view view(self) nogil except *:
60+
cdef cuda_stream_view view(self) except * nogil:
6161
"""
6262
Generate a rmm::cuda_stream_view from this Stream instance
6363
"""
6464
return cuda_stream_view(<cudaStream_t><uintptr_t>(self._cuda_stream))
6565

66-
cdef void c_synchronize(self) nogil except *:
66+
cdef void c_synchronize(self) except * nogil:
6767
"""
6868
Synchronize the CUDA stream.
6969
This function *must* be called in a `with nogil` block
@@ -77,7 +77,7 @@ cdef class Stream:
7777
with nogil:
7878
self.c_synchronize()
7979

80-
cdef bool c_is_default(self) nogil except *:
80+
cdef bool c_is_default(self) except * nogil:
8181
"""
8282
Check if we are the default CUDA stream
8383
"""

python/rmm/_lib/cuda_stream.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ cdef extern from "rmm/cuda_stream.hpp" namespace "rmm" nogil:
3333
@cython.final
3434
cdef class CudaStream:
3535
cdef unique_ptr[cuda_stream] c_obj
36-
cdef cudaStream_t value(self) nogil except *
37-
cdef bool is_valid(self) nogil except *
36+
cdef cudaStream_t value(self) except * nogil
37+
cdef bool is_valid(self) except * nogil

python/rmm/_lib/cuda_stream.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ cdef class CudaStream:
2727
def __cinit__(self):
2828
self.c_obj.reset(new cuda_stream())
2929

30-
cdef cudaStream_t value(self) nogil except *:
30+
cdef cudaStream_t value(self) except * nogil:
3131
return self.c_obj.get()[0].value()
3232

33-
cdef bool is_valid(self) nogil except *:
33+
cdef bool is_valid(self) except * nogil:
3434
return self.c_obj.get()[0].is_valid()

python/rmm/_lib/device_buffer.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ cdef class DeviceBuffer:
5656

5757
@staticmethod
5858
cdef DeviceBuffer c_to_device(const unsigned char[::1] b,
59-
Stream stream=*)
59+
Stream stream=*) except *
6060
cpdef copy_to_host(self, ary=*, Stream stream=*)
6161
cpdef copy_from_host(self, ary, Stream stream=*)
6262
cpdef copy_from_device(self, cuda_ary, Stream stream=*)

0 commit comments

Comments
 (0)