Skip to content

RISC-V: keep complex NRM2 byte strides signed - #6226

Open
SmaCow666 wants to merge 3 commits into
OpenMathLib:developfrom
SmaCow666:fix/rvv-complex-nrm2-signed-stride
Open

SmaCow666 wants to merge 3 commits into
OpenMathLib:developfrom
SmaCow666:fix/rvv-complex-nrm2-signed-stride

Conversation

@SmaCow666

Copy link
Copy Markdown

OpenBLAS supports negative NRM2 increments, and the public wrapper starts at the last logical element for such calls. Both RVV complex NRM2 kernels store the byte stride in unsigned int. A negative stride is consequently passed to a strided vector load as a large positive offset, so a two-element public DZNRM2/SCNRM2 call can fault.

Use BLASLONG for the byte stride in znrm2_vector.c and znrm2_rvv.c. Add C/Z Fortran and CBLAS regressions for negative unit, negative non-unit and positive non-unit increments. Keep the tests usable with NO_CBLAS and check result finiteness before approximate comparisons.

Local/QEMU validation used upstream 02f585444a0fba2505cfda77cc6684de008ea477, Clang 21.1.8, LP64D/32-bit BLAS integers, S/D/C/Z BLAS, pthreads with a two-thread limit, and QEMU 9.1.0:

  • Complete builds from the pinned upstream tree for RISCV64_ZVL128B and RISCV64_ZVL256B, with each PR applied independently.
  • Both targets: 153/153 unit tests and 1479/1479 extension tests pass, together with all enabled official Fortran BLAS and CBLAS Level-1/2/3 drivers in all four precisions.
  • VLEN=512: ZVL128B passes 153/153 unit and 1479/1479 extension tests. ZVL256B has three unit failures and 34 extension failures, exactly matching the named failures in the unmodified library at the same VLEN and thread count; all twelve added regressions and the targeted API checks pass. This configuration is not an all-passing full-library result. Primary runs use the target's minimum VLEN and request two threads; VLEN512 runs request one.
  • Four current full-library/target/VLEN cells each pass 2,484 guarded finite-value API cases, including 960 negative-increment cases. Input bytes remain unchanged.
  • Each unmodified full-library control reproduces four small-input SIGSEGV cases in isolated children; patched calls return the expected norm.
  • Ten warning-as-error precision/NO_CBLAS compilations passed. The NO_CBLAS test objects have no CBLAS references and their nine-test runners pass for both targets.
  • Library-member comparison confines changes to the affected kernels; exported symbol sets are unchanged. The patch passes git apply --check --whitespace=error-all against the pinned upstream tree.

BLAS was built with NO_LAPACK=1. A modern GCC RVV build and legacy C910V intrinsics have not been tested. No performance improvement is claimed.

Native RISC-V Linux validation (VLEN=256):

  • The same independently patched binaries pass all four target/thread cells: RISCV64_ZVL128B and RISCV64_ZVL256B, each with one and two requested threads. Each cell passes 153/153 unit tests, 1479/1479 extension tests, and all 24 enabled official S/D/C/Z Fortran BLAS and CBLAS Level-1/2/3 drivers.
  • This patch accounts for 120 native program executions; the shared unmodified-library baseline accounts for another 108. Both independently tested patches together account for 348 executions, rather than 348 per patch.
  • 9,936 guarded finite-value API calls pass, including 3,840 negative-increment calls, with unchanged input bytes. Unmodified-library controls reproduce four expected child SIGSEGV cases in each cell (16 in total). Each NO_CBLAS runner passes 9/9 tests.

Native and QEMU results are separate correctness evidence; no hardware performance measurement is claimed.

XuhuiNiu added 3 commits November 5, 2026 13:16
Use BLASLONG to preserve signed byte strides in the RVV complex norm kernels.
Add regressions to the existing unit-test framework.

Validated against pinned upstream 02f5854 with full BLAS/CBLAS suites in QEMU and on native RISC-V VLEN256 hardware.

This branch has not been deployed

No deployments
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