Repository navigation
Conversation
Add bli_sgemm_rviv_2vx12 (MR = 2*v at LMUL 2, NR = 12) and select it for sgemm when VLEN is 256 (v == 8). Twelve LMUL-2 accumulators hold the tile, A is double-buffered, and each k-step issues 12 vfmacc.vf per vector load of A (the 4vx4 kernel issues 4). MC = 320 (rounded to MR) and KC = 512. The selection is limited to VLEN 256, where the kernel was measured: at VLEN >= 1024 an MR = 2*v by NR = 12 tile would exceed the default BLIS_STACK_BUF_MAX_SIZE. All other datatypes and VLENs keep 4vx4. The assembly uses only caller-saved registers and RV32/RV64 common instructions, so it also assembles for rv32iv.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a
2vx12sgemm micro-kernel torv64ivand uses it when VLEN is 256.The kernel.
bli_sgemm_rviv_2vx12(assembly plus C wrapper) has MR = 2·v, one LMUL-2 vector group of A, and NR = 12.vfmacc.vf. Each loaded A element feeds 12FMAs, against 4 in 4vx4.
rv32iv, which shares the rviv kernel set.Context.
bli_cntx_init_rv64ivselects the kernel for sgemm when v == 8 (VLEN 256), with MC = 320 and KC = 512(NC stays 3072). Every other datatype and every other VLEN keeps the existing 4vx4 kernels and block sizes.
Why VLEN 256 only. That is the VLEN where we measured it. At VLEN ≥ 1024, an MR = 2·v by NR = 12 tile gives
mr·nr·sizeof(dcomplex)above the defaultBLIS_STACK_BUF_MAX_SIZE(8192), andbli_gksaborts; #963 discusses thesame limit for the sifive configurations.
Measurements
The board is a SpacemiT K3: X100 cores, VLEN 256, 2.2 GHz.
Builds. All three are clang 21.1.8 builds, configured with
./configure --enable-cblas -t pthreads CC=clang rv64iv.Harness. Row-major
cblas_sgemmon square n ∈ {2048, 3072, 4096}, with 2 warm-ups and 10 timed reps per size, in 4processes per configuration with the order alternating. Before timing, 256 sampled entries are checked against an
fp64 reference. The figure reported is the geometric mean over the three sizes of the per-size medians, in GFLOP/s.
BLIS_NUM_THREADS=8, default ways)Per size, against master:
The final commit (VLEN-256-only selection) was re-run against master at 8 threads: 134.65 against 50.50 GFLOP/s
(+167 %).
Testing
make checkblis-fastandmake checkblaspass on the K3 for the final commit built with clang 21.1.8. They alsopass for the first version of the patch (selected for VLEN ≥ 256, so the same code on this board) built with
clang 21.1.8 and with gcc 15.2.0.
benchmark size.
rv64gcvandrv32gcvwith LLVM.Relation to #955
#955 (draft) adds a 2vx8 sgemm and an 8x8 dgemm for VLEN ≥ 256, and it edits the same block of
bli_cntx_init_rv64iv.c. If #955 lands first I can rebase on it, or the 2vx12 sgemm could be folded into it. On thesame board, 2vx12 was 10.7 % (1 thread) and 39 % (8 threads) faster than 2vx8; see the table.
Disclosure: an AI coding agent (Anthropic Claude) prepared this patch, its validation runs and this description on
behalf of the account owner. All numbers above come from archived runs on the board.