Skip to content

Conversation

@cpcloud
Copy link
Contributor

@cpcloud cpcloud commented Jan 6, 2026

Summary

Add the StridedMemoryView.from_array_interface() class method to support
creating memory views from objects implementing the NumPy Array Interface
protocol (__array_interface__).

Changes

New API (cuda_core/cuda/core/_memoryview.pyx:156-163)

  • Added StridedMemoryView.from_array_interface(obj) classmethod for creating
    memory views from array interface objects
  • Implemented view_as_array_interface() helper function that:
    • Validates array interface version (requires v3+)
    • Rejects masked arrays per existing behavior in CAI APIs
    • Extracts pointer, shape, dtype, strides, and readonly flag from __array_interface__ dict
    • Marks buffers as not device-accessible

Test Coverage (cuda_core/tests/test_utils.py:464-515)

  • 25+ parameterized test cases covering:
    • Multiple dtypes (int8-64, uint8-64, float32/64, complex64/128)
    • Various array shapes (scalar, 1D, 2D, 3D, empty)
    • Memory layouts (C-contiguous, Fortran-contiguous, strided)
    • Structured dtypes
  • Validates: size, dtype, shape, pointer address, device accessibility, readonly flag, strides

Note: This PR builds on #1425 (structured dtype support). Only review the latest commit dd893ce - previous commits are from the base PR.

@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Jan 6, 2026

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cpcloud cpcloud force-pushed the add-from-array-interface branch from dd893ce to b140ed6 Compare January 6, 2026 13:13
@cpcloud
Copy link
Contributor Author

cpcloud commented Jan 6, 2026

/ok to test

@github-actions

This comment has been minimized.

@cpcloud cpcloud force-pushed the add-from-array-interface branch from b140ed6 to 9d88940 Compare January 6, 2026 13:24
@cpcloud
Copy link
Contributor Author

cpcloud commented Jan 6, 2026

/ok to test

@cpcloud
Copy link
Contributor Author

cpcloud commented Jan 6, 2026

/ok to test

1 similar comment
@cpcloud
Copy link
Contributor Author

cpcloud commented Jan 6, 2026

/ok to test

@cpcloud cpcloud force-pushed the add-from-array-interface branch from b7f7313 to a87b279 Compare January 6, 2026 16:17
@cpcloud
Copy link
Contributor Author

cpcloud commented Jan 6, 2026

/ok to test

@cpcloud cpcloud enabled auto-merge (squash) January 6, 2026 16:18
@cpcloud cpcloud merged commit 9b301ba into NVIDIA:main Jan 6, 2026
80 checks passed
@github-actions
Copy link

github-actions bot commented Jan 6, 2026

Doc Preview CI
Preview removed because the pull request was closed or merged.

@cpcloud cpcloud deleted the add-from-array-interface branch January 6, 2026 17:51
@leofang
Copy link
Member

leofang commented Jan 6, 2026

Ideally we want to always use from_dlpack to cover NumPy arrays. @cpcloud is there a reason that we need to accept array interfaces?

@cpcloud
Copy link
Contributor Author

cpcloud commented Jan 6, 2026

Yes, structured arrays, strings, bytes, and whatever other things DLPack doesn't support.

@leofang
Copy link
Member

leofang commented Jan 6, 2026

Ah right, thx for reminder...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants