tests: add coverage tests for cuda core#1923
Conversation
|
Hi @mdboom , could you please help review it? Thanks! |
|
|
I spot-checked the CI failures: all infrastructure flakes. I'll update the branch so that the tests run fresh. |
|
Generated with Cursor GPT-5.4 Extra High Fast __ Nice coverage addition. One way to make the launcher fallback tests stronger would be to keep the existing Something like this would exercise the same diff --git a/cuda_core/tests/test_launcher.py b/cuda_core/tests/test_launcher.py
@@
def test_launch_scalar_argument(python_type, cpp_type, init_value):
...
+@requires_module(np, "2.1")
+def test_launch_scalar_argument_ctypes_subclass_fallback():
+ """Subclassed ctypes scalars survive the launch path and reach the kernel correctly."""
+
+ class MyInt32(ctypes.c_int32):
+ pass
+
+ dev = Device()
+ dev.set_current()
+
+ mr = LegacyPinnedMemoryResource()
+ b = mr.allocate(np.dtype(np.int32).itemsize)
+ arr = np.from_dlpack(b).view(np.int32)
+ arr[:] = 0
+
+ scalar = MyInt32(-123456)
+
+ code = r"""
+ template <typename T>
+ __global__ void write_scalar(T* arr, T val) {
+ arr[0] = val;
+ }
+ """
+
+ arch = "".join(f"{i}" for i in dev.compute_capability)
+ pro_opts = ProgramOptions(std="c++17", arch=f"sm_{arch}")
+ prog = Program(code, code_type="c++", options=pro_opts)
+ ker_name = "write_scalar<signed int>"
+ mod = prog.compile("cubin", name_expressions=(ker_name,))
+ ker = mod.get_kernel(ker_name)
+
+ # This exercises the prepare_ctypes_arg isinstance fallback through a real launch.
+ stream = dev.default_stream
+ config = LaunchConfig(grid=1, block=1)
+ launch(stream, config, ker, arr.ctypes.data, scalar)
+ stream.sync()
+
+ assert arr[0] == scalar.valueAgent hints if you want to apply the same pattern elsewhere in this PR:
|
|
Updated according to Ralf's comment. |
|
LGTM, thanks @rluo8 We're having many infrastructure flakes at the moment. I'll try reruns tomorrow (PT) to get this merged. |
* tests: add coverage tests for cuda core * tests: add launch-level coverage for ctypes/numpy subclass fallback --------- Co-authored-by: Ralf W. Grosse-Kunstleve <rwgkio@gmail.com>
Add coverage tests for cuda core about files _event.pyx, _program.pyx, _memoryview.pyx,_linker.pyx, _kernel_arg_handler.pyx.
Co-worked with cursor-agent, target is mainly for error paths.
As the test couldn't be run using the runners before commit, the data got from local run on system with A10.
_event.pyx 85.59% -> 90.68%
_program.pyx 81.48% -> 84.93%
_memoryview.pyx 60.55% -> 65.14%
_linker.pyx 63.61% -> 64.44%
_kernel_arg_handler.pyx 80.28% -> 85.45%
All the tests passed on Linux/Windows: