Skip to content

Commit f907e46

Browse files
Fix #1169: correct NumPy skip conditions for DLPack host writes (#2238)
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>
1 parent 60d431f commit f907e46

9 files changed

Lines changed: 32 additions & 25 deletions

cuda_core/examples/graph_update.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# ################################################################################
1111

1212
# /// script
13-
# dependencies = ["cuda_bindings", "cuda_core", "nvidia-cuda-nvrtc", "numpy>=2.1"]
13+
# dependencies = ["cuda_bindings", "cuda_core", "nvidia-cuda-nvrtc", "numpy>=2.2.5"]
1414
# ///
1515

1616
import sys
@@ -44,8 +44,11 @@ def build_increment_graph(device, kernel, target_ptr):
4444

4545

4646
def main():
47-
if np.lib.NumpyVersion(np.__version__) < "2.1.0":
48-
print("This example requires NumPy 2.1.0 or later", file=sys.stderr)
47+
# Writing into the pinned host array imported via DLPack requires NumPy
48+
# 2.2.5+ (np.from_dlpack returns a read-only array on earlier versions;
49+
# see numpy GH #28632).
50+
if np.lib.NumpyVersion(np.__version__) < "2.2.5":
51+
print("This example requires NumPy 2.2.5 or later", file=sys.stderr)
4952
sys.exit(1)
5053

5154
device = Device()

cuda_core/examples/memory_ops.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
# ################################################################################
66
#
77
# This example demonstrates memory resources for allocation and management,
8-
# copying data between device and pinned memory, and DLPack interop. Requires
9-
# NumPy 2.1.0+.
8+
# copying data between device and pinned memory, and DLPack interop. Writing
9+
# into the pinned host array imported via DLPack requires NumPy 2.2.5+ (arrays
10+
# from np.from_dlpack are read-only on earlier versions; see numpy GH #28632).
1011
#
1112
# ################################################################################
1213

1314
# /// script
14-
# dependencies = ["cuda_bindings", "cuda_core", "nvidia-cuda-nvrtc", "cupy-cuda13x"]
15+
# dependencies = ["cuda_bindings", "cuda_core", "nvidia-cuda-nvrtc", "cupy-cuda13x", "numpy>=2.2.5"]
1516
# ///
1617

1718
import sys
@@ -47,8 +48,8 @@
4748

4849

4950
def main():
50-
if np.__version__ < "2.1.0":
51-
print("This example requires NumPy 2.1.0 or later", file=sys.stderr)
51+
if np.lib.NumpyVersion(np.__version__) < "2.2.5":
52+
print("This example requires NumPy 2.2.5 or later", file=sys.stderr)
5253
sys.exit(1)
5354

5455
dev = Device()

cuda_core/examples/memory_pool_resources.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# ################################################################################
1212

1313
# /// script
14-
# dependencies = ["cuda_bindings", "cuda_core", "nvidia-cuda-nvrtc", "numpy>=2.1"]
14+
# dependencies = ["cuda_bindings", "cuda_core", "nvidia-cuda-nvrtc", "numpy>=2.2.5"]
1515
# ///
1616

1717
import sys
@@ -43,8 +43,11 @@
4343

4444

4545
def main():
46-
if np.lib.NumpyVersion(np.__version__) < "2.1.0":
47-
print("This example requires NumPy 2.1.0 or later", file=sys.stderr)
46+
# Writing into the managed/pinned host arrays imported via DLPack requires
47+
# NumPy 2.2.5+ (np.from_dlpack returns a read-only array on earlier
48+
# versions; see numpy GH #28632).
49+
if np.lib.NumpyVersion(np.__version__) < "2.2.5":
50+
print("This example requires NumPy 2.2.5 or later", file=sys.stderr)
4851
sys.exit(1)
4952

5053
device = Device()

cuda_core/tests/graph/test_device_launch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _compile_device_launcher_kernel():
7676
Device().compute_capability.major < 9,
7777
reason="Device-side graph launch requires Hopper (sm_90+) architecture",
7878
)
79-
@requires_module(np, "2.1")
79+
@requires_module(np, "2.2.5", reason="need numpy 2.2.5+ (numpy GH #28632)")
8080
def test_device_launch_basic(init_cuda):
8181
"""Test basic device-side graph launch functionality.
8282
@@ -128,7 +128,7 @@ def test_device_launch_basic(init_cuda):
128128
Device().compute_capability.major < 9,
129129
reason="Device-side graph launch requires Hopper (sm_90+) architecture",
130130
)
131-
@requires_module(np, "2.1")
131+
@requires_module(np, "2.2.5", reason="need numpy 2.2.5+ (numpy GH #28632)")
132132
def test_device_launch_multiple(init_cuda):
133133
"""Test that device-side graph launch can be executed multiple times.
134134

cuda_core/tests/graph/test_graph_builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_graph_is_join_required(init_cuda):
121121
gb.end_building().complete()
122122

123123

124-
@requires_module(np, "2.1")
124+
@requires_module(np, "2.2.5", reason="need numpy 2.2.5+ (numpy GH #28632)")
125125
def test_graph_repeat_capture(init_cuda):
126126
mod = compile_common_kernels()
127127
add_one = mod.get_kernel("add_one")
@@ -341,7 +341,7 @@ def read_byte(data):
341341
assert result[0] == 0xAB
342342

343343

344-
@pytest.mark.skipif(tuple(int(i) for i in np.__version__.split(".")[:2]) < (2, 1), reason="need numpy 2.1.0+")
344+
@requires_module(np, "2.2.5", reason="need numpy 2.2.5+ (numpy GH #28632)")
345345
def test_graph_child_graph(init_cuda):
346346
mod = compile_common_kernels()
347347
add_one = mod.get_kernel("add_one")

cuda_core/tests/graph/test_graph_builder_conditional.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@pytest.mark.parametrize(
1818
"condition_value", [True, False, ctypes.c_bool(True), ctypes.c_bool(False), np.bool_(True), np.bool_(False), 1, 0]
1919
)
20-
@requires_module(np, "2.1")
20+
@requires_module(np, "2.2.5", reason="need numpy 2.2.5+ (numpy GH #28632)")
2121
def test_graph_conditional_if(init_cuda, condition_value):
2222
mod = compile_conditional_kernels(type(condition_value))
2323
add_one = mod.get_kernel("add_one")
@@ -81,7 +81,7 @@ def test_graph_conditional_if(init_cuda, condition_value):
8181
@pytest.mark.parametrize(
8282
"condition_value", [True, False, ctypes.c_bool(True), ctypes.c_bool(False), np.bool_(True), np.bool_(False), 1, 0]
8383
)
84-
@requires_module(np, "2.1")
84+
@requires_module(np, "2.2.5", reason="need numpy 2.2.5+ (numpy GH #28632)")
8585
def test_graph_conditional_if_else(init_cuda, condition_value):
8686
mod = compile_conditional_kernels(type(condition_value))
8787
add_one = mod.get_kernel("add_one")
@@ -153,7 +153,7 @@ def test_graph_conditional_if_else(init_cuda, condition_value):
153153

154154

155155
@pytest.mark.parametrize("condition_value", [0, 1, 2, 3])
156-
@requires_module(np, "2.1")
156+
@requires_module(np, "2.2.5", reason="need numpy 2.2.5+ (numpy GH #28632)")
157157
def test_graph_conditional_switch(init_cuda, condition_value):
158158
mod = compile_conditional_kernels(type(condition_value))
159159
add_one = mod.get_kernel("add_one")
@@ -244,7 +244,7 @@ def test_graph_conditional_switch(init_cuda, condition_value):
244244

245245

246246
@pytest.mark.parametrize("condition_value", [True, False, 1, 0])
247-
@requires_module(np, "2.1")
247+
@requires_module(np, "2.2.5", reason="need numpy 2.2.5+ (numpy GH #28632)")
248248
def test_graph_conditional_while(init_cuda, condition_value):
249249
mod = compile_conditional_kernels(type(condition_value))
250250
add_one = mod.get_kernel("add_one")

cuda_core/tests/graph/test_graph_definition_mutation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def close(self):
139139
self._buf.close()
140140

141141

142-
@requires_module(np, "2.1")
142+
@requires_module(np, "2.2.5", reason="need numpy 2.2.5+ (numpy GH #28632)")
143143
class TestMutateYRig:
144144
"""Tests that mutate the Y-shaped graph built by YRig."""
145145

@@ -335,7 +335,7 @@ def test_self_edge(init_cuda):
335335
node.succ.add(node)
336336

337337

338-
@requires_module(np, "2.1")
338+
@requires_module(np, "2.2.5", reason="need numpy 2.2.5+ (numpy GH #28632)")
339339
def test_convert_linear_to_fan_in(init_cuda):
340340
"""Chain four computations sequentially, then rewire so all pairs run in
341341
parallel feeding into a reduce node.

cuda_core/tests/graph/test_graph_update.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
@pytest.mark.parametrize("builder", ["GraphBuilder", "GraphDefinition"])
17-
@requires_module(np, "2.1")
17+
@requires_module(np, "2.2.5", reason="need numpy 2.2.5+ (numpy GH #28632)")
1818
def test_graph_update_kernel_args(init_cuda, builder):
1919
"""Update redirects a kernel to write to a different pointer."""
2020
mod = compile_common_kernels()
@@ -60,7 +60,7 @@ def build(ptr):
6060
b.close()
6161

6262

63-
@requires_module(np, "2.1")
63+
@requires_module(np, "2.2.5", reason="need numpy 2.2.5+ (numpy GH #28632)")
6464
def test_graph_update_conditional(init_cuda):
6565
"""Update swaps conditional switch graphs with matching topology."""
6666
mod = compile_conditional_kernels(int)

cuda_core/tests/test_launcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def test_launch_invalid_values(init_cuda):
320320

321321

322322
@pytest.mark.parametrize("python_type, cpp_type, init_value", PARAMS)
323-
@requires_module(np, "2.1")
323+
@requires_module(np, "2.2.5", reason="need numpy 2.2.5+ (numpy GH #28632)")
324324
def test_launch_scalar_argument(python_type, cpp_type, init_value):
325325
dev = Device()
326326
dev.set_current()
@@ -536,7 +536,7 @@ class MyBool(ctypes.c_bool):
536536
assert holder.ptr != 0
537537

538538

539-
@requires_module(np, "2.1")
539+
@requires_module(np, "2.2.5", reason="need numpy 2.2.5+ (numpy GH #28632)")
540540
@pytest.mark.parametrize(
541541
("scalar_kind", "np_dtype", "cpp_type", "raw_value"),
542542
[

0 commit comments

Comments
 (0)