Skip to content

perf: RVV Max/Min (float64, float32); fix a small-n RVV sum; run RVV in CI - #66

Merged
tannevaled merged 1 commit into
mainfrom
riscv64-extrema
Oct 26, 2026
Merged

tannevaled merged 1 commit into
mainfrom
riscv64-extrema

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Three changes for riscv64.

1. RVV Max/Min, float64 and float32.

  • Accumulate: each strip is folded with vfmax.vv/vfmin.vv into a register group. The tail-undisturbed policy keeps a short last strip from touching the other lanes.
  • Count NaNs: RISC-V's fmax returns the non-NaN operand, so each strip counts its NaN lanes (vmfne.vv x, x, then vcpop.m). A non-zero count gives NaN.
  • Fold: vfredmax.vs reduces the group. fmax already orders −0 below +0.

Measured on a SpacemiT X60 with abbench (6 rounds, alternated, pinned core):

2¹⁴ 2²⁰
float64 Max −89.4% −82.8%
float32 Max −93.3% −89.8%
Sum, all dtypes (controls) ~ ~

The kernels pass the sequential-oracle test (NaN, real signed zeros and infinities at every position) and the PROT_NONE fence on the X60. A sabotaged kernel with no NaN count fails it.

2. Defect: the small-n RVV sum. Running the root suite on that real X60 failed on main: MeanAxis(1) of the int64 row [MaxInt64, MinInt64, −3] gave 0 where NumPy gives −1.

  • Cause: the strip-mined float64 sum takes even 3 elements as one vector, and its unordered reduction added MaxInt64 + (−3) first. In float64 that rounds back to MaxInt64 and cancels.
  • Fix: below 8 elements the sum is sequential, the order NumPy and the other targets' kernels (whose scalar tails take n < 8 whole) use there. The root suite now passes on the X60.

3. CI: RVV actually runs. The riscv64 qemu lane used qemu's default CPU, which has no V, so no RVV kernel had ever run in CI. That is how (2) stayed hidden. The lane now sets QEMU_CPU=rv64,v=true,vlen=256 and NDARRAY_REQUIRE_RVV. The new TestRVVWhenRequired fails if the CPU does not report V, so the lane can't pass on the scalar paths unnoticed.

SECURITY.md records the defect and the CI gap. The local coverage gate (covblocks) reports 0 uncovered blocks.

A minor release, v0.22.0.

🤖 Generated with Claude Code

…in CI

- RVV extremum kernels: vfmax.vv/vfmin.vv into a tail-undisturbed group,
  a vmfne.vv + vcpop.m NaN count (fmax drops NaN), vfredmax.vs at the
  end. SpacemiT X60 (abbench): Max float64 -89% / -83%, float32
  -93% / -90%; Sum controls flat. A sabotaged kernel (no NaN count)
  fails the sequential-oracle test.
- Defect, found by running the root suite on a real X60: MeanAxis(1)
  of int64 [MaxInt64, MinInt64, -3] was 0, NumPy -1. The strip-mined
  sum took 3 elements as one vector and its unordered reduction
  cancelled MaxInt64 + (-3). Below 8 elements the sum is sequential
  now, as on the other targets.
- CI: the riscv64 qemu lane ran without V, so no RVV kernel had ever
  run in CI. It now uses QEMU_CPU=rv64,v=true,vlen=256 and sets
  NDARRAY_REQUIRE_RVV, which TestRVVWhenRequired turns into a failure
  if the CPU lacks V.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 151c4c1 into main Oct 26, 2026
12 checks passed
@tannevaled
tannevaled deleted the riscv64-extrema branch October 26, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant