cuda.core: fix _arr_is_c_contiguous discriminator for numba arrays#1998
Merged
leofang merged 1 commit intoNVIDIA:mainfrom May 1, 2026
Merged
cuda.core: fix _arr_is_c_contiguous discriminator for numba arrays#1998leofang merged 1 commit intoNVIDIA:mainfrom
leofang merged 1 commit intoNVIDIA:mainfrom
Conversation
`_arr_is_c_contiguous` checked `hasattr(arr, "flags")`, which is True
for both numpy arrays and numba `DeviceNDArray`. For numba `arr.flags`
is a plain dict, so the truthy branch falls into `arr.flags.c_contiguous`
and raises `AttributeError: 'dict' object has no attribute
'c_contiguous'`.
Discriminate on the flags object instead, mirroring the sibling
`_arr_is_writeable` helper. Unblocks six numba-cuda parametrizations:
- TestViewGPU::test_args_viewable_as_strided_memory_gpu[numba-cuda-{int8,float32}]
- TestViewGPU::test_strided_memory_view_cpu[numba-cuda-{int8,float32}]
- TestViewGPU::test_strided_memory_view_init[numba-cuda-{int8,float32}]
Made-with: Cursor
This comment has been minimized.
This comment has been minimized.
leofang
approved these changes
May 1, 2026
|
leofang
added a commit
to leofang/cuda-python
that referenced
this pull request
May 1, 2026
Per @rwgk's review: - Flip strides check to branch on view.strides (all 3 _check_view) - Add _arr_dtype helper using __cuda_array_interface__["typestr"] for torch tensors, restore dtype assertion in CAI _check_view - Merge main to pick up NVIDIA#1998 (numba flags fix) Verified locally: 76/76 tests pass across all three test classes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
leofang
added a commit
that referenced
this pull request
May 1, 2026
…1999) * Fix torch-incompatible assertions in TestViewCudaArrayInterfaceGPU The _check_view method in TestViewCudaArrayInterfaceGPU was missed during the tensor bridge refactor (#1894) and still used raw numpy attributes (in_arr.size, in_arr.strides, in_arr.flags, etc.) that don't work with torch tensors. Use the _arr_* helpers that #1894 added for torch/numpy compatibility. Caught by the nightly optional-dependency CI (#1987). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix strides assertion for torch CAI: allow explicit C-contiguous strides torch's __cuda_array_interface__ always reports strides, even for C-contiguous tensors. Use the same assertion pattern as the other _check_view methods: allow strides to equal the C-contiguous values instead of requiring None. Verified locally: 7/7 torch CAI tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Unify strides assertion pattern across all _check_view methods Use the same if/else pattern with `in (None, strides_in_counts)` in all three _check_view methods for consistency. Previously TestViewCPU and TestViewCudaArrayInterfaceGPU used a one-liner that was harder to read and behaved slightly differently. Verified locally: 66/66 tests pass across TestViewCPU, TestViewGPU, and TestViewCudaArrayInterfaceGPU (including all torch variants). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Address review: flip strides assertion, add _arr_dtype, merge main Per @rwgk's review: - Flip strides check to branch on view.strides (all 3 _check_view) - Add _arr_dtype helper using __cuda_array_interface__["typestr"] for torch tensors, restore dtype assertion in CAI _check_view - Merge main to pick up #1998 (numba flags fix) Verified locally: 76/76 tests pass across all three test classes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix the discriminator in
_arr_is_c_contiguousso the numba-cudaparametrizations of the
StridedMemoryViewGPU tests pass instead ofraising
AttributeError.Changes
_arr_is_c_contiguous(incuda_core/tests/test_utils.py) checkedhasattr(arr, "flags"), which isTruefor both numpy arrays andnumba
DeviceNDArray. For numbaarr.flagsis a plaindict, so thetruthy branch falls into
arr.flags.c_contiguousand raises:Discriminate on the flags object instead, mirroring the sibling
_arr_is_writeablehelper a few lines below:One-character placement bug; one-line patch.
Test Coverage
Unblocks the six numba-cuda parametrizations that have been failing:
TestViewGPU::test_args_viewable_as_strided_memory_gpu[numba-cuda-int8]TestViewGPU::test_args_viewable_as_strided_memory_gpu[numba-cuda-float32]TestViewGPU::test_strided_memory_view_cpu[numba-cuda-int8]TestViewGPU::test_strided_memory_view_cpu[numba-cuda-float32]TestViewGPU::test_strided_memory_view_init[numba-cuda-int8]TestViewGPU::test_strided_memory_view_init[numba-cuda-float32]Verified locally on a GPU host: the previously failing parametrizations
now pass, no other tests regress.
Pre-commit clean (
pre-commit run --all-files).