Fix #1169: correct NumPy skip conditions for DLPack host writes#2238
Open
ArsalanShakil wants to merge 1 commit into
Open
Fix #1169: correct NumPy skip conditions for DLPack host writes#2238ArsalanShakil wants to merge 1 commit into
ArsalanShakil wants to merge 1 commit into
Conversation
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>
Contributor
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.
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 raisesValueError: assignment destination is read-only. Several tests and examples guarded these writes at NumPy2.1.0, which only covers basic DLPack support. On NumPy2.1.0–2.2.4those 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_dlpackhost array → require 2.2.5; read-only DLPack usage → 2.1 is sufficient.Bumped to
2.2.5(with a consistentreason="need numpy 2.2.5+ (numpy GH #28632)", matching the already-correct guard intest_launcher.py):memory_ops.py,graph_update.py,memory_pool_resources.py(all write to pinned/managed DLPack arrays)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.pyused a plain string comparisonnp.__version__ < "2.1.0", which is unreliable for multi-digit versions (e.g."2.9" > "2.10"lexicographically). Replaced withnp.lib.NumpyVersion, consistent with the other examples.test_graph_builder.pyhad a hand-rolledtuple(int(i) ...)skipif (also brittle for pre-release versions). Standardized onto the sharedrequires_modulemark.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