Skip to content

cuda.core: fix _arr_is_c_contiguous discriminator for numba arrays - #1998

Merged
leofang merged 1 commit into
NVIDIA:mainfrom
Andy-Jost:fix-arr-is-c-contiguous-numba
May 1, 2026
Merged

cuda.core: fix _arr_is_c_contiguous discriminator for numba arrays#1998
leofang merged 1 commit into
NVIDIA:mainfrom
Andy-Jost:fix-arr-is-c-contiguous-numba

Conversation

@Andy-Jost

@Andy-JostAndy-Jost commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix the discriminator in _arr_is_c_contiguous so the numba-cuda
parametrizations of the StridedMemoryView GPU tests pass instead of
raising AttributeError.

Changes

_arr_is_c_contiguous (in cuda_core/tests/test_utils.py) 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 a few lines below:

returnarr.flags.c_contiguousifhasattr(arr.flags, "c_contiguous") elsearr.flags["C_CONTIGUOUS"]

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).

`_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
@Andy-JostAndy-Jost added this to the cuda.core v1.0.0 milestone Apr 30, 2026
@Andy-JostAndy-Jost added bug Something isn't working cuda.core Everything related to the cuda.core module labels Apr 30, 2026
@Andy-JostAndy-Jost self-assigned this Apr 30, 2026
@Andy-Jost
Andy-Jost requested a review from leofangApril 30, 2026 20:02
@github-actions

This comment has been minimized.

@leofangleofang added P1 Medium priority - Should do test Improvements or additions to tests labels May 1, 2026
@leofang
leofang merged commit 0f85061 into NVIDIA:mainMay 1, 2026
175 of 197 checks passed
@github-actions

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

@Andy-Jost
Andy-Jost deleted the fix-arr-is-c-contiguous-numba branch May 1, 2026 17:18
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>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't workingcuda.coreEverything related to the cuda.core moduleP1Medium priority - Should dotestImprovements or additions to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@Andy-Jost@leofang