[WIP] Bug in count_if for AVX-512: fall back to popcount where the int ABI does not exist - #56
Open
ax3l wants to merge 1 commit into
Open
[WIP] Bug in count_if for AVX-512: fall back to popcount where the int ABI does not exist#56ax3l wants to merge 1 commit into
count_if for AVX-512: fall back to popcount where the int ABI does not exist#56ax3l wants to merge 1 commit into
Conversation
count_if accumulates one int per element:
using IV = detail::deduced_simd<int, TV::size()>;
which needs an int simd as wide in lanes as the value type's. That ABI
stops existing once TV has more lanes than simd_abi::max_fixed_size<int>
allows. simd<char> is 64 lanes on AVX-512 and max_fixed_size<int> is 32,
so deduce<int, 64> has no type and the whole function fails to
substitute:
simd_execution.h:1506: error: no type named 'type' in
'struct simd_abi::deduce<int, 64>'
It reaches anyone calling count_if over a char range on an AVX-512 host,
and it turned CI red on GCC 13 and 14 without a commit to blame, since
the testsuite builds -march=native and the runners moved to AVX-512
capable hardware.
Count the bits of each mask instead when that ABI is unavailable. The
function already does exactly this where the lane counts do not line up,
so the fallback is the existing one rather than a new way to count.
Only char is affected at AVX-512; short, int, float and double keep the
per-lane accumulator.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
count_if: fall back to popcount where the int ABI does not exist
count_if: fall back to popcount where the int ABI does not existcount_if for AVX-512: fall back to popcount where the int ABI does not exist
ax3l
added a commit
to ax3l/vir-simd
that referenced
this pull request
Aug 26, 2026
The Clang jobs were not the only ones the runner fleet moved under.
simd_abi::max_fixed_size<int> is 32, so an AVX-512 simd<char>, which has
64 lanes, has no int ABI to match it. Two of the tests walk into that:
for_each.cc count_if wants deduced_simd<int, 64>, which has no type
transform.cc widening char to int asks for simd<int, fixed_size<64>>,
whose destructor libstdc++ deletes
transform fails the same way on GCC 11, 12 and 13, so this is not one
version's bug. And because the fleet is mixed, whether a job saw any of
it came down to which machine it landed on: GCC 11 passed one run and
failed the next on an unchanged tree.
Pin these jobs the same way, so what CI covers stops depending on the
runner. The AVX-512 coverage this gives up was never dependable -- where
a runner did offer it, these tests did not compile.
Fixing the algorithms is worthwhile separately; count_if is mattkretz#56. This is
only about CI reporting something reproducible.
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.
count_ifaccumulates oneintper element:which needs an
intsimd with as many lanes as the value type's. That ABI stops existing onceTVis wider thansimd_abi::max_fixed_size<int>allows —simd<char>is 64 lanes on AVX-512 andmax_fixed_size<int>is 32, sodeduce<int, 64>has notypeand the function fails to substitute:This reaches anyone calling
count_ifover acharrange on an AVX-512 host. It also turned CI red on GCC 13 and 14 with nothing in the tree having changed: the testsuite builds-march=native, and the runner fleet moved to AVX-512 capable hardware.Counting the bits of each mask instead when that ABI is unavailable.
count_ifalready does exactly this where the lane counts do not line up, so this reuses the existing fallback rather than adding a second way to count.Testing
-march=skylake-avx512:for_each.cccompiles clean forchar,short,int,floatanddouble. Before,charfailed.if constexpr (true)) at the native ISA so it actually executes:for_eachpasses 32/32.Only
charis affected at AVX-512. Separate from #55, which pins the Clang jobs below AVX-512 for an unrelated libstdc++ bug.