Skip to content

Fix #1169: correct NumPy skip conditions for DLPack host writes#2238

Open
ArsalanShakil wants to merge 1 commit into
NVIDIA:mainfrom
ArsalanShakil:fix/1169-numpy-dlpack-skip-conditions
Open

Fix #1169: correct NumPy skip conditions for DLPack host writes#2238
ArsalanShakil wants to merge 1 commit into
NVIDIA:mainfrom
ArsalanShakil:fix/1169-numpy-dlpack-skip-conditions

Conversation

@ArsalanShakil

Copy link
Copy Markdown

What

Audit and fix the NumPy version skip/guard conditions across cuda_core, per #1169.

Why

Writing into a host-accessible array obtained via np.from_dlpack(...) requires NumPy 2.2.5+: earlier versions return a read-only array (numpy GH #28632), so the write raises ValueError: assignment destination is read-only. Several tests and examples guarded these writes at NumPy 2.1.0, which only covers basic DLPack support. On NumPy 2.1.02.2.4 those tests/examples would error instead of skip — exactly the situation #1169 (and parent epic #1168) flagged.

Changes

Classification rule applied to every NumPy guard: writes into a np.from_dlpack host array → require 2.2.5; read-only DLPack usage → 2.1 is sufficient.

Bumped to 2.2.5 (with a consistent reason="need numpy 2.2.5+ (numpy GH #28632)", matching the already-correct guard in test_launcher.py):

  • Examples: memory_ops.py, graph_update.py, memory_pool_resources.py (all write to pinned/managed DLPack arrays)
  • Tests: test_launcher.py (2 sites), test_graph_builder.py (2 sites), test_graph_update.py (2), test_device_launch.py (2), test_graph_definition_mutation.py (2), test_graph_builder_conditional.py (4)

Additional cleanups:

  • examples/memory_ops.py used a plain string comparison np.__version__ < "2.1.0", which is unreliable for multi-digit versions (e.g. "2.9" > "2.10" lexicographically). Replaced with np.lib.NumpyVersion, consistent with the other examples.
  • test_graph_builder.py had a hand-rolled tuple(int(i) ...) skipif (also brittle for pre-release versions). Standardized onto the shared requires_module mark.
  • Updated affected PEP 723 dependency pins to numpy>=2.2.5.

Intentionally left at 2.1:

  • examples/strided_memory_view_constructors.py — only reads DLPack arrays.
  • test_utils.py:129 — guards an unrelated NumPy readonly-input fix (numpy#26501), not the DLPack write issue.

Testing

All edited files compile. The changes are version-guard logic only (no behavior change for supported NumPy); the GPU test suite runs in CI.

Closes #1169

Writing into a host-accessible array obtained via np.from_dlpack requires
NumPy 2.2.5+, because earlier versions return a read-only array
(numpy GH #28632). Several tests and examples guarded these writes at
NumPy 2.1.0, so on NumPy 2.1.0-2.2.4 they would error instead of skip.

Audit all NumPy version guards in cuda_core and bump the write-into-DLPack
sites to 2.2.5 with a consistent reason matching the existing correct guard
in test_launcher.py. Guards that only read DLPack arrays (e.g.
strided_memory_view_constructors.py) or skip for an unrelated NumPy fix
(test_utils.py, numpy#26501) are left at 2.1.

Also fix examples/memory_ops.py, which used a plain string comparison
(np.__version__ < "2.1.0") that is unreliable for multi-digit versions;
replace it with np.lib.NumpyVersion to match the other examples, and
standardize test_graph_builder.py off a hand-rolled tuple skipif onto
requires_module. Update affected PEP 723 dependency pins to numpy>=2.2.5.

Signed-off-by: Arsalan Shakil <shakil.arsalan@yahoo.com>
@copy-pr-bot

copy-pr-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

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 Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audit all NumPy skip conditions

1 participant