Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Cython's array to back Py_ssize_t[::1] #307

Merged
merged 1 commit into from
Oct 22, 2024

Conversation

jakirkham
Copy link
Member

In Array, Py_ssize_t[::1] objects are currently backed by CPython array's with some internal bits expressed in Cython. However these are not compatible with Python's Limited API and Stable ABI. To address that, switch to Cython's own array type. As this is baked into Cython and doesn't use anything special, it is compatible with Python's Limited API and Stable ABI.

xref: rapidsai/build-planning#42

In `Array`, `Py_ssize_t[::1]` objects are currently backed by CPython
`array`'s with some internal bits expressed in Cython. However these are
not compatible with Python's Limited API and Stable ABI. To address
that, switch to Cython's own`array` type. As this is baked into Cython
and doesn't use anything special, it is compatible with Python's Limited
API and Stable ABI.

https://cython.readthedocs.io/en/latest/src/userguide/memoryviews.html#cython-arrays
@jakirkham jakirkham requested a review from a team as a code owner October 22, 2024 06:43
@jakirkham jakirkham added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels Oct 22, 2024
Copy link
Member

@madsbk madsbk left a comment

Choose a reason for hiding this comment

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

Thanks @jakirkham

@jakirkham
Copy link
Member Author

Did a simple benchmark in this comment: rapidsai/kvikio#504 (comment)

Basically this is a bit slower, but no more than the time of 1-2 attribute accesses on an object

Copy link
Member

@pentschev pentschev left a comment

Choose a reason for hiding this comment

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

I tried to do some benchmark with UCX-Py (not UCXX, as it should have similar impact) but the variability prevents us from reaching any conclusive results regarding performance before and after this change, where sometimes results are better before and other times after, therefore I think it doesn't impose any negative impact that would be noticeable in practical use cases.

LGTM, thanks @jakirkham .

@pentschev
Copy link
Member

/merge

@rapids-bot rapids-bot bot merged commit cfe9008 into rapidsai:branch-0.41 Oct 22, 2024
65 checks passed
@jakirkham jakirkham deleted the use_cvarray_arr branch October 22, 2024 16:17
@jakirkham
Copy link
Member Author

Thanks Peter! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improves an existing functionality non-breaking Introduces a non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants