Commit Graph

2826 Commits

Author SHA1 Message Date
Martin Kroeker c3db185d6c
Merge pull request #5879 from amritahs-ibm/BGEMM_PPC
BGEMM Kernel implementation for Power PC Architecture
2026-07-31 00:04:15 +02:00
Martin Kroeker b080247a21
Revert "Mark temporaries as volatile to avoid SIGBUS in multithreaded builds with gcc15+ on 32bit FreeBSD/x86" 2026-07-26 22:51:58 +02:00
Amrita H S 8d439717c5 power/sbgemm_kernel_power10.c: reformat to 4-space indentation
Pure cosmetic cleanup; no functional changes.

Convert all tab-indented code to 4-space indent, align macro
continuation backslashes, switch brace placement to consistent K&R
style, reformat multi-line vector initialisers, and remove trailing
whitespace on SAVE4x2_ACC1_SCALAR.

Signed-off-by: Amrita H S <amritahs@linux.vnet.ibm.com>
2026-07-23 02:14:01 -05:00
Amrita H S 0d6d459161 power/bgemm: add BFloat16-in, BFloat16-out GEMM kernel for POWER10
Add BGEMM (BF16 input → BF16 output) for POWER10 by reusing the
existing SBGEMM kernel infrastructure. A -DBGEMM compile flag switches
only the store path; the xvbf16ger2pp MMA instruction and BF16 packing
routines are shared with SBGEMM unchanged.

Changes
-------
kernel/power/KERNEL.POWER10
  - Register BGEMM kernel and copy-routine targets, reusing the
    sbgemm_ncopy/tcopy sources (packing layout is identical).

kernel/power/sbgemm_kernel_power10.c
  - Under BGEMM: force v4sf_t to float so accumulators stay in
    float32; add STORE4_BF16/STORE2_BF16 macros (read BF16 C, widen,
    apply alpha*acc, convert back via xvcvspbf16, store); add
    f32_to_bf16_scalar() for m&1/n&1 tails; add BGEMM variants of
    all SAVE_ACC macros covering the full m/n tile hierarchy.

param.h
  - Add BGEMM_DEFAULT_UNROLL_M=16, UNROLL_N=8, P/Q/R blocking
    parameters for POWER10, matching the 16x8 kernel tile.

Unit test (utest/test_extensions/test_bgemm.c)
  - Uses SBGEMM as a trusted reference. 21 test cases cover all four
    transpose combinations, all m/n remainder paths, odd-k, alpha=0,
    beta=0/1, and the m>=32 fast path. Tolerance 0.01 to account for
    the one extra BF16 rounding on the BGEMM store.

Performance (POWER10, single-threaded, Transa=N Transb=N)
----------------------------------------------------------
Step=1 (sizes 1–200):
  - Sizes 1–80:   baseline 0.1–128 MFlops (scalar fallback);
                  patch 0.1–39,656 MFlops (up to ~350x faster at M=80).
  - Sizes 81–200: patch 3x–24x faster (avg ~10x) with 16×8 MMA tile
                  engaged.

Step=8 (sizes 8–1024):
  - Baseline peaks at ~2,950 MFlops (avg ~1,746 MFlops).
  - Patch sustains 75,000–1,009,866 MFlops for sizes 384–960,
    exceeding 1 TFlops at large sizes.
  - Median speedup ~99x; average speedup ~140x across all sizes.

Signed-off-by: Amrita H S <amritahs@linux.vnet.ibm.com>
2026-07-23 02:13:31 -05:00
Martin Kroeker 63ad298a67
Merge branch 'develop' into attrib-hidden 2026-07-21 20:00:16 +02:00
moluopro 2f21ad9282 CMake: Use effective core for fallback kernels
Keep the logical target for dynamic dispatch names while selecting kernel sources and capabilities from the core chosen by getarch after ISA restrictions.
2026-07-19 20:48:10 +08:00
Martin Kroeker bf7f06d9ac
Mark temporaries as volatile to avoid SIGBUS in multithreading with gcc15+ on 32bit FreeBSD/x86 2026-07-16 18:42:23 +02:00
Martin Kroeker 739b2f084c
Mark temporaries as volatile to avoid SIGBUS in multithreading with gcc15+ on 32bit FreeBSD/x86 2026-07-16 18:40:45 +02:00
Martin Kroeker 9ce1d6ff2a
Mark temporaties as volatile to avoid SIGBUS in multithreading with gcc15+ on 32bit FreeBSD/x86 2026-07-16 18:39:06 +02:00
Martin Kroeker 3e48730742
Add transpose support for C in GEADD (fixes #4646) (#5913)
* Add transpose support for C in GEADD (fixes #4646)

Extends GEADD to support independent transposition of both A and C,
matching the behavior of cuBLAS's geam and Apple's Accelerate geadd.
Previously only A could be transposed.

- Add transc parameter across cblas.h, common_interface.h,
  common_level3.h, common_param.h
- Add transc handling to interface/geadd.c and interface/zgeadd.c
- Extend kernel/generic/geadd.c and kernel/generic/zgeadd.c with
  stride logic for transposed C
- Add transpose test coverage (hand-verified 2x2 cases and randomized
  large-matrix tests) for sgeadd, dgeadd, cgeadd, zgeadd

* Add self to CONTRIBUTORS.md
2026-07-15 18:34:43 +02:00
Martin Kroeker dc3aa2cbd9
Fix non-SVE ARM64 potentially using non-zeroed register in SDOT/DDOT accumulation (#5918)
* Zero d0 register as it may not be identical with OUT, amend clobber list

* Add sdot/ddot reproducer from issue 5917 as ARM64-specific utest
2026-07-15 17:30:11 +02:00
aadityansha06 2c6bf39e4e Add transpose support for C in GEADD (fixes #4646)
Extends GEADD to support independent transposition of both A and C,
matching the behavior of cuBLAS's geam and Apple's Accelerate geadd.
Previously only A could be transposed.

- Add transc parameter across cblas.h, common_interface.h,
  common_level3.h, common_param.h
- Add transc handling to interface/geadd.c and interface/zgeadd.c
- Extend kernel/generic/geadd.c and kernel/generic/zgeadd.c with
  stride logic for transposed C
- Add transpose test coverage (hand-verified 2x2 cases and randomized
  large-matrix tests) for sgeadd, dgeadd, cgeadd, zgeadd
2026-07-15 17:12:31 +05:30
Martin Kroeker 873f005957
Merge pull request #5903 from hmeiland/u74-gemm-4x4-kernel
Add SiFive U74 target with a scalar 4×4 register-tiled GEMM kernel
2026-07-14 07:27:12 +02:00
Hugo Meiland 5d7868f487 U74 target: move the U74-specific gemm kernel to kernel/riscv64
Per review, the U74-specific DGEMM micro-kernel does not belong under
kernel/generic (reserved for portable, architecture-neutral C kernels).
Move both the hybrid dispatcher and its readable assembly source into
kernel/riscv64, next to KERNEL.U74:

- git mv kernel/generic/gemmkernel_4x4_u74.c -> kernel/riscv64/
- git mv kernel/generic/kern_u74.S          -> kernel/riscv64/
- KERNEL.U74: DGEMMKERNEL ../generic/gemmkernel_4x4_u74.c
                       -> ../riscv64/gemmkernel_4x4_u74.c
- gemmkernel_4x4_u74.c: #include "conversion_macros.h"
                     -> #include "../generic/conversion_macros.h"
  (that header stays under kernel/generic; same form kernel/wasm
   already uses for it)

No functional change. The portable gemmkernel_4x4.c (SGEMMKERNEL) is
untouched and stays in kernel/generic. DGEMMKERNEL still resolves through
$(KERNELDIR), so both the Makefile ($(KERNELDIR)/$(DGEMMKERNEL)) and CMake
(GenerateNamedObjects "${KERNELDIR}/${DGEMMKERNEL}") builds pick the kernel
up from its new location.
2026-07-13 16:37:03 +02:00
Martin Kroeker 992a536238
Merge pull request #5902 from wxpppp/develop
LoongArch64: avoid SGEMM LA464 ncopy fallthrough from N2 to N1
2026-07-12 01:11:37 +02:00
hmeiland cfdaa69b9f U74 asm kernel: note full-memory HPL result in header
Full-memory HPL N=27456 (asm hybrid + Q=256) measured at 5.99 GFLOPS
(residual PASSED, ~50% of the 12 GF peak, +10.7% over the tuned C kernel,
1.81x the stock 2x2) - the best clean figure. Doc-only header update.
2026-07-10 05:44:15 +02:00
hmeiland 4999e881a5 U74 target: hand-scheduled scalar asm DGEMM micro-kernel
Adds a hand-written RV64GC scalar 4x4 DGEMM micro-kernel (kern_u74.S) and
wires it as the U74 DGEMMKERNEL via a hybrid dispatcher
(gemmkernel_4x4_u74.c): the fast path (bm,bn multiples of 4, even bk,
non-TRMM) runs the asm; all other shapes, odd bk, and the TRMM builds fall
back to the portable C 4x4 kernel.

The asm uses a 4x4 register tile (16 accumulators), full operand double-
buffering (P/Q ping-pong) with one-iteration lookahead, and load-before-FMA
issue ordering matched to the U74's dual-issue in-order front end.  Probes
show this reaches the FP-pipe peak (~16.5 cycles / 16 fmadd.d = 2.9 GF on
L1-resident data); the streaming plateau is memory-latency-bound, not the
schedule.

Measured on a VisionFive 2 (single-core, KC=256): micro-kernel 1.88 vs 1.54
GF (+22%), full blocked DGEMM 1.77 vs 1.48 GF (+20%); the advantage holds
under 4-core contention (+17%).  End-to-end HPL N=10000 (4 cores, Q=256):
5.17 vs 4.97 GF (+4.0%), residual PASSED.  Correctness validated against the
full BLAS Level-3 test suite (DGEMM 17,496 computational calls, 0 failures).
kern_u74.S is the readable source; the .c embeds it via top-level __asm__ so
it builds as a single OpenBLAS kernel object with no build-system changes.
2026-07-10 03:31:45 +02:00
wangweijie 2707282e8c LoongArch64: avoid SGEMM LA464 ncopy fallthrough from N2 to N1 2026-07-09 20:53:05 +08:00
hmeiland a3620c264a Add U74 target with a 4x4 register-tiled GEMM kernel
The SiFive U74 (RV64GC; e.g. StarFive JH7110 / VisionFive 2) is a scalar,
in-order core with no RVV, so today it falls back to RISCV64_GENERIC whose
S/D GEMM uses the generic 2x2 C micro-kernel.

Per the U74 Core Complex Manual (Table 169) fmadd.d has a 7-cycle latency
at repeat rate 1 (fully pipelined). A 2x2 tile exposes only 4 independent
accumulator chains -- fewer than the FMA latency -- so the FP pipe stalls
on the accumulator dependency, and the 1:1 load:FMA ratio saturates the
single load/store pipe ("only one outstanding line fill", manual 8.2).

This adds a portable 4x4 GEMM micro-kernel and a dedicated U74 target:

- kernel/generic/gemmkernel_4x4.c: 16-accumulator 4x4 register tile. 16
  independent chains exceed the 7-cycle latency, and the load:FMA ratio
  drops to 1:2. 16 acc + 4 A + 4 B fit RV64G's 32 FP registers without
  spilling. Full 4/2/1 edge handling in both M and N.

- U74 target wiring: getarch.c (FORCE_U74, 32 KiB/64 B L1D, 2 MiB L2),
  param.h (S/D UNROLL 4/4; complex stays 2/2), kernel/riscv64/KERNEL.U74
  (S/D GEMM -> gemmkernel_4x4 + gemm_[nt]copy_4; S/D TRMM -> existing
  trmmkernel_4x4), Makefile.prebuild + Makefile.riscv64 (-mtune=sifive-u74),
  TargetList.txt, cpuid_riscv64.c.

The 4x4 kernel was verified numerically against a naive reference GEMM,
driven through the real gemm_tcopy_4 / gemm_ncopy_4 packing routines,
across 27,436 M/N/K x alpha combinations covering every 4/2/1 tail case:
worst absolute error 0.

Build with: make TARGET=U74
2026-07-09 14:00:16 +02:00
moluopro 06d553d0b1 arm64: normalize SME direct source line endings 2026-07-09 13:44:29 +08:00
moluopro 6fdc8db640 arm64: tighten SME STRMM direct variants 2026-07-09 13:43:51 +08:00
moluopro 95cae64181 arm64: harden SME SGEMM direct heuristic 2026-07-09 13:42:48 +08:00
moluopro a33e238b35 cmake: define ARM64 SME direct kernel variants 2026-07-09 13:41:10 +08:00
moluopro 0e163c9db2 kernel/riscv64: enable RVV TRSM for ZVL256B 2026-07-08 19:42:26 +08:00
moluopro a8b8136114 kernel/riscv64: enable RVV TRSM for ZVL128B 2026-07-08 19:42:17 +08:00
moluopro 0723136260 kernel/riscv64: add RVV RT TRSM kernel 2026-07-08 19:42:09 +08:00
moluopro e4e3ad2430 kernel/riscv64: add RVV RN TRSM kernel 2026-07-08 19:41:58 +08:00
moluopro 945f4352d3 kernel/riscv64: add RVV LT TRSM kernel 2026-07-08 19:41:49 +08:00
moluopro 5282a38239 kernel/riscv64: add RVV LN TRSM kernel 2026-07-08 19:41:42 +08:00
moluopro 09fd1da6fa kernel/riscv64: enable RVV ROTM for ZVL256B
Use the RVV ROTM kernel for single and double precision ROTM on the RISCV64_ZVL256B target.
2026-07-07 15:20:26 +08:00
moluopro a11b444d67 kernel/riscv64: enable RVV ROTM for ZVL128B
Use the RVV ROTM kernel for single and double precision ROTM on the RISCV64_ZVL128B target.
2026-07-07 15:20:26 +08:00
moluopro 395f8b347f fix(riscv64): keep signed strides in RVV ROTM
The general-stride ROTM path already computes kx/ky with the BLAS negative-increment starting offset. Converting negative increments to positive strides and moving dx/dy again double-adjusted the address and could access the wrong elements. Keep the signed byte strides for RVV strided loads and stores.
2026-07-07 15:20:17 +08:00
moluopro f82cf88caa fix(riscv64): handle zero-stride ROTM in RVV kernel
ROTM has loop-carried dependencies when incx or incy is zero because the same element is updated repeatedly across iterations. The RVV strided load/store path would compute lanes from the same old value and write them back in parallel, producing results that do not match BLAS ROTM semantics. Use a scalar path for zero-stride cases.
2026-07-07 15:20:06 +08:00
Martin Kroeker de54968e16
Merge pull request #5890 from martin-frbg/fixup5843
Apply the NEON S/DOMATCOPY kernels from PR 5843 to all arm64 targets
2026-07-07 00:47:11 +02:00
Martin Kroeker a5d477f195
fix omatcopy filenames 2026-07-06 12:28:02 +02:00
Martin Kroeker 36365a602e
Make the OMATCOPY kernels from 5843 universally available 2026-07-06 11:49:27 +02:00
moluopro 130102e661 Clean up SSYR2K SME direct warnings
Mark read-only transpose inputs const and limit sve_cntw and ldb definitions to the variants that use them.
2026-07-06 16:00:21 +08:00
moluopro 3781e2c15d Clean up SSYRK SME direct warnings
Mark the read-only B input const and limit sve_cntw and ldb definitions to the variants that use them.
2026-07-06 15:59:53 +08:00
moluopro edd8ab196d Clean up SSYMM SME preprocessing warnings
Use const source pointers in the symmetric preprocessing helpers and compile only the LU or LL helper needed by each object variant.
2026-07-06 15:59:25 +08:00
moluopro 8cde36c9b8 Use integer round-up in ARM64 SME direct kernels
The padded SME dimensions are integer quantities, so compute them with integer arithmetic and drop the now-unused math.h include.
2026-07-06 15:33:29 +08:00
moluopro d49cd021dd Handle zero alpha/beta in SSYR2K SME direct kernel
Avoid loading C when beta is zero, and skip A/B preprocessing for alpha == 0 or K == 0 by reusing the triangular direct kernel with k = 0.
2026-07-06 15:30:42 +08:00
moluopro 9925b29db5 Handle zero alpha/beta in SSYRK SME direct kernel
Avoid loading C when beta is zero, and skip A preprocessing for alpha == 0 or K == 0 by reusing the triangular direct kernel with k = 0.
2026-07-06 15:30:37 +08:00
moluopro 35a841fd49 Handle zero alpha in SSYMM SME direct kernel
When alpha is zero, avoid preprocessing the symmetric matrix and reuse the SGEMM alpha/beta direct kernel with k = 0 for the beta-only update.
2026-07-06 15:30:27 +08:00
moluopro ab27636deb Handle zero alpha/beta in SGEMM SME direct kernel
Avoid loading C when beta is zero; ZA has already been initialized to zero.

For alpha == 0 or K == 0, skip A preprocessing and reuse the direct kernel with k = 0 to perform only the beta update.
2026-07-06 15:30:22 +08:00
Martin Kroeker e70a7a735f
Merge pull request #5868 from Vasudeva-bit/macTuneZEN4
Optimize Zen 4 GEMM macro block sizes (P, Q, R)
2026-07-05 00:01:20 +02:00
Vasudeva-bit 58846317d9 fix C89 scoping, dynamic R for memory issues, robust zen4/5 check 2026-07-04 11:30:34 +05:30
Julien Schueller 43f0a90e1b Fix ZA tile slice indices in ssyrk SME direct kernel
The kernel_2x2 function uses 4 ZA tiles (0-3) each with svl slices.
Tiles 0/1 handle rows 0..svl-1 with slice indices 0..svl-1.
Tiles 2/3 handle rows svl..2*svl-1, so their slice indices
must start at 0, i.e. (i - svl) instead of i.

Fix all three tile 2/3 access sites:
- C load into ZA (svwrite_hor_za32_f32_m)
- C writeback for UPPER (svst1_hor_za32)
- C writeback for LOWER (svst1_hor_za32)

Fixes #5873
2026-07-02 09:29:32 +02:00
Vasudeva-bit 753604cfe2 Optimize Zen 4 GEMM macro block sizes (P, Q, R) 2026-06-25 19:06:26 +05:30
zhir 46aa158dcc AArch64: NEON omatcopy CT/RT kernels 2026-06-20 22:54:04 +03:00
Martin Kroeker ef20ea1644
Merge pull request #5828 from amritahs-ibm/fix_dcbt_constraints
Fix incorrect inline assembly constraints in dcbt prefetch instructions
2026-06-15 11:22:10 +02:00