Repository navigation
Conversation
The i?amax/i?amin/i?max/i?min (and complex icamax/izamax/icamin/izamin) RVV kernels track, per vector lane, the index of the first extreme value that lane has seen, and then return the index held by the lowest lane containing the overall extreme (vfirst + vslidedown). When the extreme value occurs more than once, the lowest such lane can hold a later index than another lane, so the kernels did not return the first occurrence as BLAS requires (for example isamax returned 64 instead of 21 for n = 65 with equal maxima at 21 and 64). Select the smallest recorded index among the lanes holding the extreme value instead (vmerge with UINT_MAX + vredminu).
This branch has not been deployed
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.
Summary
The RVV index kernels
iamax_rvv.c,iamin_rvv.c,imax_rvv.c,imin_rvv.c,izamax_rvv.candizamin_rvv.cdo not always return the firstoccurrence of the extreme value when that value appears more than once, which
BLAS requires. These kernels are used by RISCV64_ZVL128B and x280.
How the kernels work: each vector lane keeps the index of the first extreme
value it has seen. After the loop, they pick the lowest lane that holds the
overall extreme, using
vfirst, and return that lane's index after avslidedown. When the extreme value is duplicated, a lower lane can hold alater index. For example, with n = 65 and equal maxima at positions 21 and 64,
cblas_isamaxreturns 64.The patch instead returns the smallest index recorded by the lanes that hold
the extreme value: it sets every other lane to all-ones with
vmergeand thenreduces with
vredminu. The search loops are unchanged.Testing
Platform: SpacemiT K3 (X100, VLEN 256),
TARGET=RISCV64_ZVL128B, GCC 15.2.Targeted check of
i?amax,i?amin,i?max,i?minand oficamax/izamax/icamin/izamin, 15312 cases in total:position, or twice (a tie).
Results:
OpenBLAS tests. The default
makegoal's tests give identical resultsbefore and after the patch: utest 141/141, extension tests 1479/1479, and all
BLAS/CBLAS tests PASSED.
Performance is unchanged. ISAMAX/IDAMAX at n = 1024, 32768 and 4M all
stay within ±0.35 %.
RISCV64_ZVL256B uses the
*_vector.cindex kernels, which already return thefirst occurrence. Its ISMIN/IDMIN bug is fixed separately in #6169.