Skip to content

Commit

Permalink
Update to Cython 3.0.0 (#13777)
Browse files Browse the repository at this point in the history
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
- Removing any extern cdef functions that uses C++ rvalues. These were never supported by Cython, but prior to 3.0 they were silently ignored whereas now Cython throws warnings during compilation
- Relative imports are no longer off by one level in pxd files and must be adjusted accordingly (see cython/cython#3442)

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.

There are also warnings coming from pyarrow due to apache/arrow#34564. pyarrow 12 contains the necessary fixes, so this issues should be resolved once #13728 is merged.

Authors:
  - Vyas Ramasubramani (https://github.com/vyasr)
  - GALI PREM SAGAR (https://github.com/galipremsagar)

Approvers:
  - Ray Douglass (https://github.com/raydouglass)
  - Bradley Dice (https://github.com/bdice)
  - Benjamin Zaitlen (https://github.com/quasiben)
  - GALI PREM SAGAR (https://github.com/galipremsagar)
  - https://github.com/jakirkham

URL: #13777
  • Loading branch information
vyasr authored Aug 4, 2023
1 parent 8370cbe commit a8ef4d4
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 35 deletions.
2 changes: 1 addition & 1 deletion ci/test_wheel_dask_cudf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RAPIDS_PY_WHEEL_NAME="cudf_${RAPIDS_PY_CUDA_SUFFIX}" rapids-download-wheels-from
python -m pip install --no-deps ./local-cudf-dep/cudf*.whl

# Always install latest dask for testing
python -m pip install git+https://github.com/dask/[email protected] git+https://github.com/dask/[email protected] git+https://github.com/rapidsai/dask-cuda.git@branch-23.08
python -m pip install git+https://github.com/dask/[email protected] git+https://github.com/dask/[email protected] git+https://github.com/rapidsai/dask-cuda.git@branch-23.10

# echo to expand wildcard before adding `[extra]` requires for pip
python -m pip install $(echo ./dist/dask_cudf*.whl)[test]
Expand Down
2 changes: 1 addition & 1 deletion conda/environments/all_cuda-118_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies:
- cudatoolkit
- cupy>=12.0.0
- cxx-compiler
- cython>=0.29,<0.30
- cython>=3.0.0
- dask-core==2023.7.1
- dask-cuda==23.10.*
- dask==2023.7.1
Expand Down
2 changes: 1 addition & 1 deletion conda/environments/all_cuda-120_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies:
- cuda-version=12.0
- cupy>=12.0.0
- cxx-compiler
- cython>=0.29,<0.30
- cython>=3.0.0
- dask-core==2023.7.1
- dask-cuda==23.10.*
- dask==2023.7.1
Expand Down
2 changes: 1 addition & 1 deletion conda/recipes/cudf/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ requirements:
host:
- protobuf ==4.21.*
- python
- cython >=0.29,<0.30
- cython >=3.0.0
- scikit-build >=0.13.1
- setuptools
- dlpack >=0.5,<0.6.0a0
Expand Down
2 changes: 1 addition & 1 deletion conda/recipes/cudf_kafka/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ requirements:
- sysroot_{{ target_platform }} {{ sysroot_version }}
host:
- python
- cython >=0.29,<0.30
- cython >=3.0.0
- cuda-version ={{ cuda_version }}
- cudf ={{ version }}
- libcudf_kafka ={{ version }}
Expand Down
2 changes: 1 addition & 1 deletion dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ dependencies:
common:
- output_types: [conda, requirements, pyproject]
packages:
- cython>=0.29,<0.30
- cython>=3.0.0
# Hard pin the patch version used during the build. This must be kept
# in sync with the version pinned in get_arrow.cmake.
- pyarrow==12.0.1.*
Expand Down
8 changes: 1 addition & 7 deletions python/cudf/cudf/_lib/cpp/column/column.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020, NVIDIA CORPORATION.
# Copyright (c) 2020-2023, NVIDIA CORPORATION.

from libcpp cimport bool
from libcpp.memory cimport unique_ptr
Expand All @@ -20,12 +20,6 @@ cdef extern from "cudf/column/column.hpp" namespace "cudf" nogil:
column() except +
column(const column& other) except +

column(
data_type dtype,
size_type size,
device_buffer&& data
) except +

column(column_view view) except +

size_type size() except +
Expand Down
3 changes: 1 addition & 2 deletions python/cudf/cudf/_lib/cpp/column/column_view.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020, NVIDIA CORPORATION.
# Copyright (c) 2020-2023, NVIDIA CORPORATION.

from libcpp cimport bool
from libcpp.vector cimport vector
Expand All @@ -12,7 +12,6 @@ cdef extern from "cudf/column/column_view.hpp" namespace "cudf" nogil:
column_view(const column_view& other) except +

column_view& operator=(const column_view&) except +
column_view& operator=(column_view&&) except +

column_view(
data_type type,
Expand Down
3 changes: 1 addition & 2 deletions python/cudf/cudf/_lib/cpp/table/table.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2022, NVIDIA CORPORATION.
# Copyright (c) 2020-2023, NVIDIA CORPORATION.

from libcpp.memory cimport unique_ptr
from libcpp.vector cimport vector
Expand All @@ -11,7 +11,6 @@ from cudf._lib.cpp.types cimport size_type
cdef extern from "cudf/table/table.hpp" namespace "cudf" nogil:
cdef cppclass table:
table(const table&) except +
table(vector[unique_ptr[column]]&& columns) except +
table(table_view) except +
size_type num_columns() except +
size_type num_rows() except +
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/_lib/csv.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def write_csv(
)


cdef data_type _get_cudf_data_type_from_dtype(object dtype) except +:
cdef data_type _get_cudf_data_type_from_dtype(object dtype) except *:
# TODO: Remove this work-around Dictionary types
# in libcudf are fully mapped to categorical columns:
# https://github.com/rapidsai/cudf/issues/3960
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/_lib/io/datasource.pxd
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Copyright (c) 2020, NVIDIA CORPORATION.
# Copyright (c) 2020-2023, NVIDIA CORPORATION.

from libcpp.memory cimport shared_ptr

from cudf._lib.cpp.io.types cimport arrow_io_source, datasource


cdef class Datasource:
cdef datasource* get_datasource(self) nogil except *
cdef datasource* get_datasource(self) except * nogil

cdef class NativeFileDatasource(Datasource):
cdef shared_ptr[arrow_io_source] c_datasource
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/_lib/io/datasource.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020, NVIDIA CORPORATION.
# Copyright (c) 2020-2023, NVIDIA CORPORATION.

from libcpp.memory cimport shared_ptr
from pyarrow.includes.libarrow cimport CRandomAccessFile
Expand All @@ -8,7 +8,7 @@ from cudf._lib.cpp.io.types cimport arrow_io_source, datasource


cdef class Datasource:
cdef datasource* get_datasource(self) nogil except *:
cdef datasource* get_datasource(self) except * nogil:
with gil:
raise NotImplementedError("get_datasource() should not "
+ "be directly invoked here")
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/_lib/json.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def write_json(
)


cdef schema_element _get_cudf_schema_element_from_dtype(object dtype) except +:
cdef schema_element _get_cudf_schema_element_from_dtype(object dtype) except *:
cdef schema_element s_element
cdef data_type lib_type
if cudf.api.types.is_categorical_dtype(dtype):
Expand All @@ -236,7 +236,7 @@ cdef schema_element _get_cudf_schema_element_from_dtype(object dtype) except +:
return s_element


cdef data_type _get_cudf_data_type_from_dtype(object dtype) except +:
cdef data_type _get_cudf_data_type_from_dtype(object dtype) except *:
if cudf.api.types.is_categorical_dtype(dtype):
raise NotImplementedError(
"CategoricalDtype as dtype is not yet "
Expand Down
14 changes: 5 additions & 9 deletions python/cudf/cudf/_lib/pylibcudf/__init__.pxd
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# Copyright (c) 2023, NVIDIA CORPORATION.

# TODO: Verify consistent usage of relative/absolute imports in pylibcudf.
# Relative Cython imports always look one level too high. This is a known bug
# https://github.com/cython/cython/issues/3442
# that is fixed in Cython 3
# https://github.com/cython/cython/pull/4552
from .pylibcudf cimport copying
from .pylibcudf.column cimport Column
from .pylibcudf.gpumemoryview cimport gpumemoryview
from .pylibcudf.table cimport Table
from .pylibcudf.types cimport DataType, TypeId
from . cimport copying
from .column cimport Column
from .gpumemoryview cimport gpumemoryview
from .table cimport Table
from .types cimport DataType, TypeId

__all__ = [
"Column",
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
build-backend = "setuptools.build_meta"
requires = [
"cmake>=3.26.4",
"cython>=0.29,<0.30",
"cython>=3.0.0",
"ninja",
"numpy>=1.21",
"protoc-wheel",
Expand Down
2 changes: 1 addition & 1 deletion python/cudf_kafka/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[build-system]

requires = [
"cython>=0.29,<0.30",
"cython>=3.0.0",
"numpy>=1.21",
"pyarrow==12.0.1.*",
"setuptools",
Expand Down

0 comments on commit a8ef4d4

Please sign in to comment.