Skip to content

Conversation

@cpcloud
Copy link
Contributor

@cpcloud cpcloud commented Jan 5, 2026

Improve Support for Structured Dtype Arrays in StridedMemoryView

Summary

Extends StridedMemoryView to handle NumPy structured dtypes (e.g., dtype([("field1", float64), ("field2", int64)])) instead of only built-in numeric types.

Changes

cuda/core/_memoryview.pyx (30 lines, +20 -10)

  • Converted _typestr2dtype from static dict to function with lazy caching
  • Converted _typestr2itemsize from static dict to function with lazy caching
  • Falls back to numpy.dtype(typestr) for non-builtin types (e.g., structured dtypes)
  • Renamed globals: _typestr2dtype_TYPESTR_TO_DTYPE, _typestr2itemsize_TYPESTR_TO_ITEMSIZE
  • Removed TODO comment about built-in-only limitation (now resolved)

tests/test_utils.py (+17 lines)

  • Added test_struct_array() validating structured dtype handling
  • Tests array with dtype=[("array1", np.float64), ("array2", np.int64)]
  • Verifies size, shape, and dtype preservation (note: full dtype info lost due to typestr encoding)

Key Behavior

Structured dtypes now work but are represented as void types (e.g., V16) due to inherent lossiness in typestr encoding (dtype([("a", "int")]).str == "V8").

@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Jan 5, 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
Copy link
Contributor Author

cpcloud commented Jan 5, 2026

/ok to test

@cpcloud cpcloud requested a review from leofang January 5, 2026 20:20
@github-actions

This comment has been minimized.

Copy link
Contributor

@mdboom mdboom left a comment

Choose a reason for hiding this comment

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

LGTM, other than improving the test a bit.

Leaning on Numpy for the conversion, as this now does, feels more future-proof as well.

@cpcloud cpcloud force-pushed the improve-support-for-struct-dtypes branch from 3236804 to 9d37149 Compare January 6, 2026 12:28
@cpcloud
Copy link
Contributor Author

cpcloud commented Jan 6, 2026

/ok to test

@cpcloud cpcloud enabled auto-merge (squash) January 6, 2026 12:28
@cpcloud cpcloud merged commit 36742dd 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.

@github-actions
Copy link

Backport failed for release/cuda-core-v0.5.1, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin release/cuda-core-v0.5.1
git worktree add -d .worktree/backport-1425-to-release/cuda-core-v0.5.1 origin/release/cuda-core-v0.5.1
cd .worktree/backport-1425-to-release/cuda-core-v0.5.1
git switch --create backport-1425-to-release/cuda-core-v0.5.1
git cherry-pick -x 36742ddc5b91ed388f55d5ec7ade8d245835fb35

github-actions bot pushed a commit that referenced this pull request Jan 13, 2026
…1425)

* test: add test for structured dtype properties

* feat: improve support for structured dtype arrays held by `StridedMemoryView`

* chore: simplify using an lru cache instead of manual caching

(cherry picked from commit 36742dd)
@github-actions
Copy link

Successfully created backport PR for release/cuda-core-v0.5.1:

cpcloud added a commit that referenced this pull request Jan 13, 2026
…1425) (#1472)

Co-authored-by: Phillip Cloud <417981+cpcloud@users.noreply.github.com>
@leofang leofang added this to the cuda.core beta 12 milestone Jan 14, 2026
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