Conversation
The CGEMM micro-kernel built every complex product into a temporary and
then added it to the accumulator:
tmp = vfmul(Ai, Bi); tmp = VFMACC(tmp, Br, Ar); ACC = vfadd(ACC, tmp)
Three vector instructions per accumulator and k-step. The two FMAs
write the same destination, so applying them straight to ACC yields the
same per-k-step sum for two instructions instead:
ACCr = VFMACC_RR( ACCr, Bi, Ai);
ACCr = VFMACC_RR( ACCr, Br, Ar);
ACCi = FOLD_OPA( ACCi, Br, Ai);
ACCi = FOLD_OPB( ACCi, Bi, Ar);
VFMACC_RR/VFMACC_RI already encode the +/- conjugation of the variant
being compiled, but the imaginary fold needs an op sequence that has no
existing macro, so it is spelled out per variant as FOLD_OPA/FOLD_OPB
next to them.
Two FMAs compose to a plain accumulation because vfmsac(x,u,v)=u*v-x and
vfmsac(vfmsac(a,u,v),w,y)=a+w*y-u*v, and likewise for vfmacc/vfnmsac.
The value added per k-step is therefore unchanged and the per-column
accumulation order is preserved. Only the FP rounding order differs, by
a few ULP; measured against an exact double reference the patched kernel
has the same error as the unpatched one.
A packed A element has its real and imaginary halves adjacent, so one
strided segment-2 load replaces the two separate strided loads.
Measured on a SpaceMiT X100 (2.2 GHz, single thread, ZVL256B), median of
three runs: cblas_cgemm +44.3% at 256, +45.0% at 512, +42.3% at 1024.
Tests: make tests returns 0; 125/125 utest and 1473/1473 extension tests
pass; the CBLAS L1/L2/L3 suites show no new failures.
Co-authored-by: Yuansheng <yuansheng@isrc.iscas.ac.cn>
Co-authored-by: Ning Tian <tianning24@iscas.ac.cn>
Signed-off-by: jiakai xu <xujiakai2025@iscas.ac.cn>
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.
The CGEMM micro-kernel for ZVL256B built every complex product into a temporary and then added it to the accumulator:
That is three vector instructions per accumulator and k-step. The two FMAs write the same destination, so applying them straight to ACC yields the same per-k-step sum for two instructions instead:
VFMACC_RR/VFMACC_RIalready encode the +/- conjugation of the variant being compiled, but the imaginary fold needs an op sequence that has no existing macro, so it is spelled out per variant asFOLD_OPA/FOLD_OPBnext to them.Two FMAs compose to a plain accumulation because
vfmsac(x,u,v)=u*v-xandvfmsac(vfmsac(a,u,v),w,y)=a+w*y-u*v, and likewise forvfmacc/vfnmsac. The value added per k-step is therefore unchanged and the per-column accumulation order is preserved. Only the FP rounding order differs, by a few ULP; measured against an exact double reference the patched kernel has the same error as the unpatched one.A packed A element has its real and imaginary halves adjacent, so one strided segment-2 load replaces the two separate strided loads.
Performance
Measured on a SpaceMiT X100 (2.2 GHz, single thread, ZVL256B), median of three runs:
cblas_cgemm+44.3% at 256, +45.0% at 512, +42.3% at 1024.Testing
make testsreturns 0; 125/125 utest and 1473/1473 extension tests pass; the CBLAS L1/L2/L3 suites show no new failures.