Skip to content

x86_64/arm64: fix complex Level-1 threaded worker ABI and dummy_alpha - #6272

Open
M-Colley wants to merge 1 commit into
OpenMathLib:developfrom
M-Colley:fix/complex-l1-thread-abi
Open

M-Colley wants to merge 1 commit into
OpenMathLib:developfrom
M-Colley:fix/complex-l1-thread-abi

Conversation

@M-Colley

Copy link
Copy Markdown
Contributor

Summary

In legacy_exec (blas_server.c, blas_server_win32.c, and blas_server_omp.c), every BLAS_COMPLEX Level-1 job reads both ((FLOAT *)args->alpha)[0] and ((FLOAT *)args->alpha)[1] and invokes the worker function with two FLOAT scalar arguments (dummy2r, dummy2i) prior to the vector pointers. Several x86_64 and arm64 complex Level-1 threaded kernels violate this contract. Specifically, kernel/x86_64/{casum,zasum,csum,zsum}.c (active on SkylakeX, Cooperlake, SapphireRapids, Zen4, and Zen5) and ten kernel/arm64/*_thunderx2t99.c files declare a single FLOAT dummy2 parameter in their worker callbacks. Under the Windows x64 and ARM64EC calling conventions, the missing fifth argument shifts all subsequent stack arguments by 8 bytes, so result receives ldb (0 / NULL) and dereferences NULL whenever n > 10000 runs on multiple threads. Additionally, kernel/x86_64/zdot.c and six kernel/arm64/*_thunderx2t99.c kernels declare FLOAT dummy_alpha as a single scalar, which causes legacy_exec to read alpha[1] past the variable on the caller stack during every multithreaded call.

Changes

  • Update worker callback signatures to accept FLOAT dummy2r, FLOAT dummy2i in kernel/x86_64/{casum,zasum,csum,zsum}.c and kernel/arm64/{casum,zasum,csum,zsum,zdot,izamax}_thunderx2t99.c, matching commit b2053239f in kernel/x86_64/zdot.c.
  • Guard FLOAT dummy2 (!defined(COMPLEX)) vs FLOAT dummy2r, FLOAT dummy2i (defined(COMPLEX)) in dual-compiled kernel/arm64/{copy_thunderx2t99,dznrm2_thunderx2t99,dznrm2_thunderx2t99_fast,scnrm2_thunderx2t99}.c.
  • Declare and zero-initialize FLOAT dummy_alpha[2] = {ZERO, ZERO} across kernel/x86_64/{casum,zasum,csum,zsum,zdot}.c and all ten kernel/arm64/*_thunderx2t99.c files, and align int (*function)(void) prototypes with blas_l1_thread.c.
  • Add multithreaded (N = 20005) complex Level-1 regression tests for cdotu, zdotu, scasum, dzasum, scnrm2, dznrm2, icamax, izamax, ccopy, zcopy, scsum, and dzsum in utest.

Verification

  • Reproduced the crash locally on Windows x86_64 (MinGW-w64 GCC 14.3.0, -DMS_ABI -DSMP_SERVER): calling dzasum, scasum, dzsum, and scsum from kernel/x86_64/{zasum,casum,zsum,csum}.c with n = 20005 on 2 threads crashed with STATUS_ACCESS_VIOLATION (0xC0000005) prior to this patch and returned exact sums (40010.0, exit code 0) with this patch.
  • Built and ran openblas_utest (163/163 passed) and openblas_utest_ext (1547/1547 passed) with zero compiler warnings.

In legacy_exec, complex Level-1 jobs read two FLOAT elements from
args->alpha and invoke the worker callback with both real and imaginary
alpha arguments. Several x86_64 and arm64 complex Level-1 thread
wrappers violate this calling convention in two ways.

First, x86_64 casum, zasum, csum, and zsum plus ten arm64 thunderx2t99
Level-1 kernels declare a single FLOAT dummy2 parameter in their worker
callbacks. Under the Windows x64 and ARM64EC ABIs, the missing fifth
parameter shifts all stack arguments by 8 bytes, causing result to read
ldb (NULL) and crash with an access violation whenever n > 10000 on
multiple threads. In dual real/complex arm64 kernels (copy, dznrm2,
dznrm2_fast, and scnrm2), guard the two-scalar signature under COMPLEX.

Second, x86_64 zdot and six arm64 thunderx2t99 kernels pass a scalar
dummy_alpha to blas_level1_thread_with_return_value or
blas_level1_thread, causing an out-of-bounds stack read of alpha[1] in
legacy_exec. Zero-initialize dummy_alpha[2] across all affected files
and add multithreaded complex Level-1 regression tests in utest.
@M-Colley
M-Colley force-pushed the fix/complex-l1-thread-abi branch from 90984d4 to 425c5ea Compare November 21, 2026 22:38

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