You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: Harden reductions, casts, and bindings against degenerate inputs
Several SIMD kernels and Python-binding paths mishandled degenerate shapes and
strides, ranging from a hang to out-of-bounds reads and writes. The reduce
kernels (skylake/icelake/haswell/sierra/alder/neonbfdot) hit an infinite loop,
SIGFPE, or stack overflow when handed stride_bytes == 0; their `!aligned`
serial fallbacks now also catch `stride_elements == 0`. The sub-byte cast
oracle in cast/serial.h hard-coded its pack/unpack loops to four bytes
regardless of count, reading and writing past the buffer on any odd i4/u4/e2m1
length -- every site now bounds the loop by nk_size_divide_round_up_(count, 2)
and guards the odd tail. Rank-0 and empty reductions no longer touch a
non-existent element: C++ moments()/minmax() indexed stride_bytes(SIZE_MAX) on
a 0-D view, the Python rank-0 path fabricated a zero stride, and empty minmax
primed its accumulators from element [0].
The Python bindings gained the missing input validation. Dense-metric `out=`
buffers are checked for rank and capacity before writing (an undersized out
overflowed the heap); parse_tensor now requires exact inner-axis contiguity,
rejecting the negative/zero strides (e.g. x[::-1]) that the old signed
`> itemsize` check let walk off the buffer; and DLPack import rejects negative
extents and a NULL data pointer. The Rust symmetric matrix verbs reject
non-contiguous-row (transposed) views, matching the packed and parallel paths.
The test suites were deduplicated and extended over the same edges. The Python
*_float/*_integer reduction and arithmetic pairs collapse into parametrized
tests (removing dead precise_*/baseline_sum helpers and a stale DLPack helper),
and new cases cover empty/0-D tensors, NaN/Inf preservation on dense casts, and
block-scaled round-trip / idempotence / byte-identity across all seven formats,
plus the degenerate inputs above. Net test lines shrink while coverage grows.
Comments were stripped of decorative banner separators and ephemeral numbered
"Phase"/"Step"/"Option" labels, whose ordering is implied by code order. Also
sets the rustfmt line width to 120 and bumps the Rust MSRV to 1.73 for
usize::div_ceil.
0 commit comments