Skip to content

Add StridedMemoryView DLPack export and C exchange API support#1630

Open
cpcloud wants to merge 7 commits intoNVIDIA:mainfrom
cpcloud:issue-1438-stridedmemoryview-dlpack
Open

Add StridedMemoryView DLPack export and C exchange API support#1630
cpcloud wants to merge 7 commits intoNVIDIA:mainfrom
cpcloud:issue-1438-stridedmemoryview-dlpack

Conversation

@cpcloud
Copy link
Contributor

@cpcloud cpcloud commented Feb 17, 2026

Summary

  • Add DLPack export coverage for StridedMemoryView in cuda_core/tests/test_utils.py, including NumPy/CuPy roundtrip checks, dtype-required failure behavior, and C exchange API capsule exposure.
  • Implement StridedMemoryView producer support in cuda_core/cuda/core/_memoryview.pyx via __dlpack__ and __dlpack_device__, plus managed-tensor lifecycle helpers and C exchange API function-table exposure.
  • Sync vendored cuda_core/cuda/core/_include/dlpack.h to DLPack v1.3 and align compatibility behavior discussed in review:
    • negotiate via max_version and emit legacy vs versioned capsules accordingly,
    • carry explicit DLPack version metadata for versioned tensors,
    • provide explicit strides for ndim > 0 (required by DLPack v1.2+) while remaining broadly compatible with consumers,
    • expose both __dlpack_c_exchange_api__ and __c_dlpack_exchange_api__ as aliases on the type.
  • Add cuda-nvrtc-dev to cuda_core host dependencies (cuda_core/pixi.toml, cuda_core/pixi.lock) so nvrtc.h is consistently available in pixi build/test environments.

Closes #1438.

Test plan

  • pixi run --frozen -e cu13 --manifest-path cuda_core test tests/test_utils.py -k dlpack -q (16 passed, 10 skipped)
  • nix run nixpkgs#gcc -- -fsyntax-only cuda_core/cuda/core/_include/dlpack.h
  • Full cuda_core test suite

cpcloud and others added 5 commits February 17, 2026 14:06
Add coverage for StridedMemoryView DLPack producer behavior and the C exchange API capsule so the implementation can be landed in follow-up commits.

Co-authored-by: Cursor <cursoragent@cursor.com>
Align cuda-core's bundled DLPack header with upstream v1.3 so protocol constants and C API declarations match current spec.

Co-authored-by: Cursor <cursoragent@cursor.com>
Add __dlpack__ and __dlpack_device__ support to StridedMemoryView, including owned DLManagedTensor capsule creation and lifecycle handling for shape, strides, dtype, and device metadata.

Co-authored-by: Cursor <cursoragent@cursor.com>
Expose the C exchange API capsules for StridedMemoryView and align exported tensor metadata with current DLPack semantics and shared type declarations.

Co-authored-by: Cursor <cursoragent@cursor.com>
Ensure nvrtc headers are present when building cuda-core in the test environment so pixi test runs do not fail on missing nvrtc.h.

Co-authored-by: Cursor <cursoragent@cursor.com>
@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Feb 17, 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.

Normalize test_utils import order after pre-commit autofixes so local and CI hook runs stay clean.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cpcloud
Copy link
Contributor Author

cpcloud commented Feb 17, 2026

/ok to test

Clarify why setup_dl_tensor_layout always sets a non-NULL stride pointer for non-scalar exports under DLPack v1.2+ semantics.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cpcloud
Copy link
Contributor Author

cpcloud commented Feb 17, 2026

/ok to test

@github-actions
Copy link

kDLCUDA = _kDLCUDA
kDLCUDAHost = _kDLCUDAHost
kDLCUDAManaged = _kDLCUDAManaged
kDLTrn = _kDLTrn
Copy link
Member

Choose a reason for hiding this comment

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

This is not an NVIDIA product, we should not expose it:

Suggested change
kDLTrn = _kDLTrn

setuptools-scm = ">=8"
cython = ">=3.2,<3.3"
cuda-cudart-dev = "*"
cuda-nvrtc-dev = "*"
Copy link
Member

Choose a reason for hiding this comment

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

👍

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.

[FEA]: Support exporting StridedMemoryView objects via DLPack

2 participants