[DO-NOT-MERGE] Prototype: driver memsets for ndarray.fill #43
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.52) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #43"
general
weight: 0.35
seberg
Prototype, parked here until CuPy can rely on
cuda-bindings(PR 10464 in cupy/cupy is a step toward that). The first two commits are PR 10474 in cupy/cupy by its author, which fixesfill(-0.0)losing the sign by sending such values tofill_kernel; the two commits on top are the prototype.What it does
ndarray.fillissues onecuMemsetD8Async/cuMemsetD16Async/cuMemsetD32Asynccall when the array is C-contiguous and the bytes of the value repeat every 1, 2 or 4 bytes. That covers every 1-, 2- and 4-byte dtype, any zero, and values such as int64-1or complex641+1j. Bytes are compared, so-0.0stays distinct from+0.0and remains a memset for float16 and float32. CUDA has no 64-bit memset, so other float64 / complex128 values still go throughfill_kernel.PyArray_Pack(second commit). Plain Python and NumPy scalars and 0-d NumPy arrays are converted straight into a stack buffer instead of going throughnumpy.asarray(value, dtype=...).Numbers
Host time per call in µs (launch only, no sync) on an RTX A6000 with CUDA 13.4 and NumPy 2.5, median of 4 interleaved rounds:
| | main | PR 10474 | + driver memsets | +
PyArray_Pack||---|---:|---:|---:|---:|
| float32
fill(1.0), 1000 elements | 6.20 | 6.80 | 2.74 | 2.24 || float32
fill(-0.0), 1000 elements | 2.95 (sign lost) | 6.82 | 2.74 | 2.23 || bool
fill(True), 1000 elements | 8.08 | 6.78 | 2.73 | 2.23 || complex64
fill(1+1j), 1000 elements | 6.20 | 7.05 | 3.52 | 2.95 || float64
fill(0.0), 0-d | 2.94 | 3.51 | 2.68 | 2.23 ||
cupy.ones(1000, float32)| 9.20 | 10.07 | 4.92 | 4.47 ||
cupy.array(np.float32(1))| 10.59 | 12.64 | 6.19 | 6.24 || float64
fill(1.0), 1000 elements (kernel) | 6.18 | 7.02 | 5.97 | 5.26 || float64
fill(-0.0), 1000 elements (kernel) | 3.71 (sign lost) | 6.82 | 5.96 | 5.29 ||
cupy.ones(1000)| 9.20 | 10.52 | 8.87 | 7.98 |Launch plus sync for large arrays: float16 with 64M elements goes from 357 to 195 µs and float32 with 1M elements from 15.4 to 9.0 µs; float32 with 64M elements is unchanged (386 vs 383 µs).
For reference, on the same machine one
cuMemsetD32Asynccall costs about 1.9 µs, onecuLaunchKernelcall about 2.6 µs and oneElementwiseKernelcall about 5.1 µs. Fills that become a memset are therefore within about 0.3 µs of the floor. The float64 / complex128 values that stay on the kernel could get to roughly 3 µs with a dedicatedcuLaunchKernelpath; that is an estimate and is not part of this branch.Open items
core.pyxcimportscuda.bindings.cydriverunconditionally, so the branch builds only withcuda-bindingsinstalled and not for ROCm. HIP needs its ownhipMemsetD8/D16/D32Asyncpath, or the current code as a fallback.cydriver.pxdneeds acuda.hat least as new as thecuda-bindingsrelease: 13.5.0 does not compile against CUDA 13.4 headers (CUDA_FABRIC_COPY_BATCH_OP_stis undefined), 13.4.4 does.PyArray_Pack, an out-of-range NumPy scalar (for examplenp.int64(231 - 1)into an int8 array) raisesOverflowError, asnumpy.ndarray.filldoes. Today it wraps silently.fillthat takes a 0-d CuPy array as the value is unchanged: it still callscudaMemsetAsyncwithout that check, which on main fails with an invalid-value error for a zero fill of an array on another device until peer access is on.core_tests/test_ndarray_copy_and_view.py,creation_tests/test_basic.pyandcreation_tests/test_from_data.pypass.cupy.fullgoes throughcopytorather thanfill, so it does not benefit.<details><summary>Benchmark script</summary>
</details>
<details><summary>Correctness script</summary>
</details>
-- Leo's bot