WIP: Add `cuda.core.utils.make_aligned_dtype` by leofang · Pull Request #1636 · NVIDIA/cuda-python · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 183 additions & 0 deletions cuda_core/cuda/core/_utils/dtype_utils.pyx
5 changes: 4 additions & 1 deletion cuda_core/cuda/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0

from cuda.core._memoryview import (
StridedMemoryView, # noqa: F401
args_viewable_as_strided_memory, # noqa: F401
)
from cuda.core._utils.dtype_utils import (
make_aligned_dtype, # noqa: F401
)
1 change: 1 addition & 0 deletions cuda_core/docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Utility functions
:toctree: generated/

args_viewable_as_strided_memory
make_aligned_dtype

:template: autosummary/cyclass.rst

Expand Down
7 changes: 7 additions & 0 deletions cuda_core/docs/source/release/0.6.0-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ New features

This replaces the previous undocumented workaround of using ``Stream.from_handle(0)`` to access the legacy default stream.

- Added :func:`~cuda.core.utils.make_aligned_dtype` utility for creating
structured NumPy dtypes with GPU-compatible alignment. Field offsets and
the total ``itemsize`` are recomputed so that each field is naturally aligned
and the structure size is a multiple of the largest member alignment. An
explicit ``alignment`` can be requested and is stored in the dtype's metadata
under the key ``"__cuda_alignment__"``. (Resolves :issue:`734`.)

Fixes and enhancements
-----------------------

Expand Down
125 changes: 124 additions & 1 deletion cuda_core/tests/test_utils.py