Skip to content

Fix torch-incompatible assertions in TestViewCudaArrayInterfaceGPU#1999

Merged
leofang merged 6 commits intoNVIDIA:mainfrom
leofang:fix-test-utils-arr-size
May 1, 2026
Merged

Fix torch-incompatible assertions in TestViewCudaArrayInterfaceGPU#1999
leofang merged 6 commits intoNVIDIA:mainfrom
leofang:fix-test-utils-arr-size

Conversation

@leofang
Copy link
Copy Markdown
Member

@leofang leofang commented Apr 30, 2026

The _check_view method in TestViewCudaArrayInterfaceGPU was missed during the tensor bridge refactor (#1894) and still used raw numpy attributes that don't work with torch.Tensor:

  • in_arr.size — torch's .size is a method (returns shape), not a property (returns element count)
  • in_arr.strides / in_arr.dtype.itemsize — torch tensors don't have numpy-style .strides
  • in_arr.flags["C_CONTIGUOUS"] — torch tensors don't have .flags
  • gpu_array_ptr(in_arr) — didn't handle torch tensors
  • in_arr.dtype — torch dtype != numpy dtype

Changes

  • Replace raw array accesses with _arr_* helpers (_arr_ptr, _arr_size, _arr_strides_in_counts, _arr_is_c_contiguous)
  • Add _arr_dtype helper: uses __cuda_array_interface__["typestr"] for torch tensors to get a numpy-compatible dtype
  • Flip strides assertion to branch on view.strides is None (per review) — clearer semantics, consistent across all three _check_view methods
  • Restore dtype assertion using _arr_dtype

Testing

Verified locally: 76/76 tests pass across TestViewCPU, TestViewGPU, and TestViewCudaArrayInterfaceGPU (including all torch and cupy variants).

Caught by the nightly optional-dependency CI (#1987).

-- Leo's bot

The _check_view method in TestViewCudaArrayInterfaceGPU was missed
during the tensor bridge refactor (NVIDIA#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 NVIDIA#1894
added for torch/numpy compatibility.

Caught by the nightly optional-dependency CI (NVIDIA#1987).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@copy-pr-bot
Copy link
Copy Markdown
Contributor

copy-pr-bot Bot commented Apr 30, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Apr 30, 2026
@leofang leofang self-assigned this May 1, 2026
@leofang leofang added bug Something isn't working P0 High priority - Must do! test Improvements or additions to tests labels May 1, 2026
@leofang leofang added this to the cuda.core v1.0.0 milestone May 1, 2026
@leofang
Copy link
Copy Markdown
Member Author

leofang commented May 1, 2026

/ok to test 24fc3aa

@github-actions

This comment has been minimized.

leofang and others added 3 commits May 1, 2026 02:28
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>
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>
@leofang
Copy link
Copy Markdown
Member Author

leofang commented May 1, 2026

/ok to test dacfec9

@leofang leofang marked this pull request as ready for review May 1, 2026 03:12
@leofang leofang requested review from Andy-Jost and rwgk May 1, 2026 15:33
Comment thread cuda_core/tests/test_utils.py Outdated
Comment thread cuda_core/tests/test_utils.py Outdated
Comment thread cuda_core/tests/test_utils.py
Comment thread cuda_core/tests/test_utils.py
leofang and others added 2 commits May 1, 2026 19:38
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
Copy link
Copy Markdown
Member Author

leofang commented May 1, 2026

/ok to test 6b017b7

@leofang leofang enabled auto-merge (squash) May 1, 2026 19:46
@leofang leofang merged commit ad9bc92 into NVIDIA:main May 1, 2026
95 checks passed
@leofang leofang deleted the fix-test-utils-arr-size branch May 1, 2026 20:36
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Doc Preview CI
Preview removed because the pull request was closed or merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module P0 High priority - Must do! test Improvements or additions to tests

3 participants