-
-
Notifications
You must be signed in to change notification settings - Fork 29
Mr/guard simd tests #416
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
base: main
Are you sure you want to change the base?
Mr/guard simd tests #416
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 3 files with indirect coverage changes 🚀 New features to boost your workflow:
|
zlib-rs/src/adler32/neon.rs
Outdated
| } | ||
|
|
||
| #[cfg(test)] | ||
| #[cfg(all(test, feature = "std"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The aarch64 targets enable neon, so #[cfg(target_feature = "neon")] seems like it would be sufficient if you add #[cfg(target_feature = "neon")] return true; to is_enabled_neon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that should also work, yes. I can rebase this later using that approach if you want!
zlib-rs/src/adler32/avx2.rs
Outdated
|
|
||
| #[cfg(test)] | ||
| #[cfg(target_feature = "avx2")] | ||
| #[cfg(feature = "std")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alternative would be to add #[cfg(all(target_feature = "bmi1", target_feature = "bmi2")], right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that would be more complete, but running the test with cargo test --no-default-features --features c-allocator (as an example) would still fail, because the runtime CPU feature detection will always return false if the std feature is not enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't. If avx2, bmi1 and bmi2 are enabled at compile time then is_enabled_avx2_and_bmi2 will unconditionally return true even when the std feature` is disabled.
zlib-rs/zlib-rs/src/cpu_features.rs
Lines 33 to 38 in bbf2574
| #[cfg(all( | |
| target_feature = "avx2", | |
| target_feature = "bmi1", | |
| target_feature = "bmi2" | |
| ))] | |
| return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right, I looked at the wrong runtime checker (the one for avx512, not avx2_..).
|
I'll try to expand a bit:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we replicate this issue with cross-compilation? neon cannot actually be disabled for the aarch64 targets I think. I'm also not having any luck reproducing this for x86_64.
I'm a bit worried that we will at some point forget to include the std feature somewhere and miss test coverage that we thought we would have.
|
cross compilation doesn't help here, you need to execute the tests to see the failures. I verified the issue on an arm64 porterbox for the neon part. the avx part requires a target that has avx compiled in, or removing the the same test invocation with the |
|
Hmm then I think statically gating on the target features like bjorn suggested is the best approach. Yes we do lose some test coverage, but the functions at hand receive plenty of coverage via our dedicated tests. I don't think testing on a wider variety of hardware has much value. I don't think targets without these features are likely to be used for development, and in any case our CI would catch any issues. (well I guess we should check github CI runners have bmi1/bmi2? I'd expect them to have it, but we should make sure) |
ff41479 to
8df0b44
Compare
|
reworked the two commits:
|
8df0b44 to
f5442a5
Compare
|
Hmm we are actually losing coverage right now. One way to fix that is to build with in the CI script, like here zlib-rs/.github/workflows/checks.yaml Lines 35 to 37 in bbf2574
we'd then run without these tests, but with dynamic feature detection, for our x86 windows and macos builds. That should be sufficient I think. |
|
do you want to add that yourself? I know very little about your CI setup, so you are probably in a better position to decide which target features to set for which of the test runs.. alternatively, I had another patch on top like this: that would re-enable the avx2 tests with runtime detection (and potential for failure if the |
the runtime checker returns true if those target features are enabled, so guard the tests which assert on the runtime check being true accordingly. Signed-off-by: Fabian Grünbichler <[email protected]>
f5442a5 to
5b8e3fb
Compare
|
I merged the changes to neon in a separate PR and rebased here. That leaves the issue where tests of simd implementations fail when the required features are not available at runtime. I'm wondering though: why is that a problem? Does it cause issues with the debian processes? From my perspective I'd really like the default settings to test as widely as possible on the most common targets. |
|
it's not an issue per se, if that is the behaviour you want upstream than that's obviously okay. we'll patch around it downstream, because we don't want tests failing depending on which test environment they run in (e.g., between a developer's build environment and the official CI, or between different runners of the official CI). unfortunately cargo test doesn't have the option (AFAIK?) for a test case to say at runtime "please treat me as skipped, I couldn't run", else that would be the best solution here I think. |
the
neonandavx512adler32 tests currently require thestdfeature being enabled to work, since the CPU feature detection is based on it.note that there is a slight inconsistency between the two test modules:
the former means that if the target is compiled without neon support, the tests would still fail. the latter means that the tests don't run on targets that don't have avx enabled, but could support it at runtime if the CPU does (e.g., Debian's amd64 doesn't have AVX enabled automatically, but most modern CPUs support it)..
ideally, the runtime detection would just cause those tests to be skipped, instead of making them fail..