-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wip: trying to debug windows CI failures #128
Conversation
f00499a
to
bbbf3f2
Compare
@lemire, It does appear to reproduce with c only, building this file with msvc cl: see the "msvc c roaring" step of this job (which is set to continue on error for that step). It's built with https://github.com/Dr-Emann/croaring-rs/blob/debug_win_ci/.github/workflows/rust.yml#L53-L60, based on the flags/environment rust is compiling the c code with
(where -1073741795 is 0xC000001D (STATUS_ILLEGAL_INSTRUCTION)). croaring_hardware_support() = 0x1 doesn't appear to indicate AVX512 is the problem. The issues began (with I believe no meaningful changes in CRoaring/croaring-rs, this PR is right off master, with no changes to CRoaring/croaring-rs) sometime between 3 months ago and 2 weeks ago I have no idea why we don't see any issues in CRoaring itself |
7ccc4f0
to
2f067a3
Compare
@lemire Here's the assembly of (the first part of) the function crashing
Call stack:
Source code line according to debug info (may be wrong?): inline static uint64_t avx2_harley_seal_popcount256(const __m256i *data,
const uint64_t size) {
__m256i total = _mm256_setzero_si256();
__m256i ones = _mm256_setzero_si256();
__m256i twos = _mm256_setzero_si256();
__m256i fours = _mm256_setzero_si256();
__m256i eights = _mm256_setzero_si256();
__m256i sixteens = _mm256_setzero_si256();
__m256i twosA, twosB, foursA, foursB, eightsA, eightsB;
const uint64_t limit = size - size % 16;
uint64_t i = 0; // <- This line is shown as where the crash occurs
for (; i < limit; i += 16) {
CSA(&twosA, &ones, ones, _mm256_lddqu_si256(data + i),
_mm256_lddqu_si256(data + i + 1));
CSA(&twosB, &ones, ones, _mm256_lddqu_si256(data + i + 2),
_mm256_lddqu_si256(data + i + 3)); |
This feels awfully relevant: https://developercommunity.visualstudio.com/t/Invalid-AVX512-instructions-generated-wh/10521872
|
Also relevant, looks like if MSVC figures out we're going to avx512 in the function, it can use it anywhere. I don't see anywhere we could use any avx512 intrinsics in the avx2 code path though, from a somewhat close look:
EDIT: |
I think we can disable AVX-512 code paths entirely (under Windows). |
2f067a3
to
2cd3458
Compare
Looks like disabling AVX512 isn't enough, we have to disable AVX entirely 🫤 |
It is certainly possible to have hardware lacking AVX instruction support. But we should handle this scenario. You may have seen that CRoaring now effectively runs your small tests from the amalgamated files in CI, and it appears to work. |
@Dr-Emann Can you review CI tests You can see that it is running the amalgamation tests which involve precisely the function you suggested. It is building it using the default Visual Studio 2022 provided by GitHub. What are we missing? |
f8a774f
to
59745f6
Compare
But it is not going to be super useful because my laptop does support AVX instructions. :-/ |
vpxord is AVX512F + AVX512VL. |
My best guess is that this code confuses Visual Studio into using AVX-512 throughout: int bitset_container_compute_cardinality(const bitset_container_t *bitset) {
int support = croaring_hardware_support();
#if CROARING_COMPILER_SUPPORTS_AVX512
if( support & ROARING_SUPPORTS_AVX512 ) {
return (int) avx512_vpopcount(
(const __m512i *)bitset->words,
BITSET_CONTAINER_SIZE_IN_WORDS / (WORDS_IN_AVX512_REG));
} else
#endif // CROARING_COMPILER_SUPPORTS_AVX512
if( support & ROARING_SUPPORTS_AVX2 ) {
return (int) avx2_harley_seal_popcount256(
(const __m256i *)bitset->words,
BITSET_CONTAINER_SIZE_IN_WORDS / (WORDS_IN_AVX2_REG));
} else {
return _scalar_bitset_container_compute_cardinality(bitset);
}
} What confuses me is that you are say that disabling AVX-512 did not help. |
@Dr-Emann Please review... RoaringBitmap/CRoaring#579 If it makes sense to you, we shall try this approach. If it solves the issue, then we are lucky. |
I'm fairly sure that when I tried with I think there were two "bugs" I posted. The first was acknowledged as a bug by microsoft, and it seemed to be that the compiler would insert avx512 instructions when only AVX2 was enabled (or maybe that the AVX2 intrinsics were producing avx512 instructions?), and was marked as The second was closed as not a bug, where the compiler figured out that the codepath was going to use avx512 intrinsics in the same codepath, so optimized assuming it could use avx512. I think we're hitting the first issue, not the second. |
@Dr-Emann If you take my PR, the one where I move the AVX-512, and you use that in your rust binding, does it help? |
a5fe9f9
to
2770b7b
Compare
2770b7b
to
9ca8eb7
Compare
Nope, it still ends up with avx512 instructions with that branch (even with |
@Dr-Emann Hmmmm.... I don't know what else to do. |
I really think it's just an MSVC bug that'll hopefully be fixed in 14.39. I think our only real options are:
|
Disabling AVX seems extreme. I would happily disable AVX-512 under Windows if it were needed, but I feel uneasy about disabling AVX since almost all Windows machines that we care about have AVX2. |
I really don't see any way around it for the versions of MSVC that has this bug, the alternative is miscompilation which will cause a crash. Here's a godbolt link including only And if you change back to MSVC 19.37 (still don't understand the versioning, why is it 14 some places and 19 elsewhere? EDIT: see https://devblogs.microsoft.com/oldnewthing/20221219-00/?p=107601, 14.38 is the toolchain version 19.38 is the compiler version (and is related to the _MSC_VER)), there's no vpxord instruction. |
Seeing same issue, glad to see there's a thread here about this because I've been tearing my hair out over this for a couple of weeks now: |
I think that @Dr-Emann has demonstrated that it is a compiler bug. |
@yeastplume For now, I recommend you just avoid the offending compiler version. If I were Microsoft, I would just patch it and make sure that the bug goes away. I don't think we will do anything. |
Yes, makes sense and thanks for your work tracking this down. Slightly tangential, I guess, but does anyone have a quick pointer as to how to force github actions to use a particular compiler version? |
The current windows-latest runner should only have two versions installed, a very old one, and the very latest one, see the specs... https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md I don't think it is possible to install another version of Visual Studio on the GitHub hosted runners. So we have to wait for Microsoft to fix this. |
@Dr-Emann Waiting for a fix from Microsoft did not help. They released 17.9 and it is the version we have in the GitHub runners, but the issue remains for us. We need to change our code to try and fix this issue. |
No description provided.