You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Some unit tests fail with SSE disabled (i.e. scalar path only) #2414
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<RunConfiguration>
<!--Used in conjunction with ActiveIssueAttribute to skip tests with known issues-->
<TestCaseFilter>category!=failing</TestCaseFilter>
<EnvironmentVariables>
<DOTNET_EnableSSE>0</DOTNET_EnableSSE>
</EnvironmentVariables>
</RunConfiguration>
</RunSettings>
Tests started to fail -- even when going back in the history of main-branch (so no recent commit caused these failures).
To me it looks like there are latent bugs in the scalar code-pathes. Can anyone confirm?
It looks like CI runs the tests on the agents "as is", so with AVX (except MacOS?) and SSE enabled. When the PR is labeled for ARM then an extra runner for ARM is started.
Thus bugs in the scalar code-paths may not be covered by CI, as the path via AVX/SSE is taken usually.
Some bugs get revealed by running on ARM (e.g. #2409 (comment)) but CI should cover the scalar paths on non-ARM too.
has environment variable DOTNET_EnableSSE=0 set
so that JIT treats Sse.IsSupported = false (and all "inherited" intrinsics like SSE2, ..., AVX, AVX2), thus only the scalar code-paths are executed.
I guess that's not covered, as it's a scalar-path and method ClampedAddSubtractHalf (which calls this method) has a pure SSE2-implemation.
Here is the coverage report For LosslessUtils. ClampedAddSubtractHalf is reported as covered, but the Clip255 which is called by ClampedAddSubtractHalf is only reported as covered partially. I think that's the problem.
I will improve the test, so it will be fully covered.
We should be running any decoder/encoder tests using FeatureTestRunner with which we can disable Avx/Sse etc.
There is a test RunPredictor13Test which uses the FeatureTestRunner to run with and without intrinsics. For context: Predictor13() calls ClampedAddSubtractHalf().
There are some paths not covered, for example BundleColorMap() and SubtractGreenFromBlueAndRedScalar()
That's a bit strange. When the private method AddSubtractComponentHalf is covered, and that method had the bug, then it should have shown up. Or is the test -- ran via FeatureTestRunner -- only executing some inputs?
I'm new to the test infrastructure here, so I have to ask?
Besides that I wonder why so many tests (10+) fail when SSE is disabled.
The issue is in Clip255, this method is called by AddSubtractComponentHalf
and is not fully covered. Only the path a < 256 == true is covered, not the case a < 256 == false
This hides the error. This means we need two test cases for RunPredictor13Test one for a < 256 == true and one for a < 256 == false.
The when you revert back your commit b694956 to have the issue, it will show up as a failed test.
FeatureTestRunner allows us to run tests with disabled intrinsics features.
For example:
FeatureTestRunner is a nice solution. Thanks for the explanaition 👍🏻
Is the cost of running of a whole CI-leg with SSE disabled too high?
Or can this be run only on a scheduled basis?
So all code-paths w/o vectorization are touched, and no one has to think about adding a test-case with the FeatureTestRunner.
To cover all the intrinsic paths on 4 OS (linux is counted 2x now we have ARM) for 2X target frameworks the build matrix explodes to something like 28 images now.
FeatureTestRunner was my workaround to keep numbers low and also so we could get a detailed code coverage report from a single entry in the build matrix.
I don't think there's a way to keep our coverage report intact while splitting out the features into separate matrix entries.
I would suggest we ensure that all decoder/encoder methods use FeatureTestRunner for Avx, Sse, AdvancedSimd, and scalar runs. It's a chore but absolutely necessary.
This should be avoided, for sure.
I'd do only +1, so run a additional ubuntu-latest with DOTNET_EnableSSE=0 set. So that scalar pathes are touched at least once (for sure).
If there's a test missing for running via FeatureTestRunner code will be covered too.
I'm not that familiar with GH-Actions (I'm using Azure Pipelines mostly) but I think that should be possible w/o exploding the matrix.
FeatureTestRunner is good and should be kept, as tests can be run on other operating systems too quite easily.
(BTW: your implementation of that is really nice).
I can confirm this. I see 133 failing tests going scalar-only on my machine. For example, this is the output when decoding testorig12.jpg:
I recommend fixing these one-by-one, adding the missing test cases for each individual bug in the process.
While FeatureTestRunner is good tool, using it systematically in every single integration test would be very expensive. I think adding one test leg to cover the scalar case on one OS, as #2414 (comment) suggests, would be valuable.
With #2427 merged, 15 test remain failing on the current main branch now.
Two failing tests are webp encoding tests. I think there is an issue that the AVX version of Vp8Residual.GetResidualCost() does not match the scalar version. I am trying to figure out what's wrong there.
P.S. I whish there would be an option not to close linked issues when PR are merged. I could not find any.
Wild guess: maybe tiered compilation (rejitter?) doesn't respect ISA environmental variables on net6? Didn't check on net7.
I've set this env variable DOTNET_TieredCompilation=0 and got following results:
Last failing test is related to image diff threshold, not sure whether it's related to the codegen.
Now I'm completely lost, we can't simply set this variable and go on - there's a probability it can be broken by some R2R situation? Sorry to bother you @tannergooding but I'm not sure we can solve this on our own :)
We are trying to test all ImageSharp tests for scalar path so I've set <DOTNET_EnableSSE>0</DOTNET_EnableSSE> in .runsettings for emulating cpu without sse support at all.
We got some flaky tests which end up throwing System.PlatformNotSupportedException : Operation is not supported on this platform.. If these tests are executed among other tests - everything breaks due to this call: Sse2.LoadScalarVector128(UInt64* address) from mscorlib, you can check exact stacktrace from the message above mine.
But if these flacky tests are launched in isolation - they successfully pass. I immediately thought about tiered jitting and decided to turn it off with <DOTNET_TieredCompilation>0</DOTNET_TieredCompilation> in .runsettings file, file looked like this:
Activity
gfoidl commentedon Mar 25, 2023
It looks like CI runs the tests on the agents "as is", so with AVX (except MacOS?) and SSE enabled. When the PR is labeled for ARM then an extra runner for ARM is started.
Thus bugs in the scalar code-paths may not be covered by CI, as the path via AVX/SSE is taken usually.
Some bugs get revealed by running on ARM (e.g. #2409 (comment)) but CI should cover the scalar paths on non-ARM too.
My suggestion is to add a new entry in the
ImageSharp/.github/workflows/build-and-test.yml
Lines 16 to 19 in 302a23f
ubuntu-latestDOTNET_EnableSSE=0setso that JIT treats
Sse.IsSupported = false(and all "inherited" intrinsics like SSE2, ..., AVX, AVX2), thus only the scalar code-paths are executed.gfoidl commentedon Mar 25, 2023
@brianpopow in #2413 (comment) you wrote about coverage.
Please check if there's coverage for
ImageSharp/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs
Line 1459 in ca21b6d
I guess that's not covered, as it's a scalar-path and method
ClampedAddSubtractHalf(which calls this method) has a pure SSE2-implemation.JimBobSquarePants commentedon Mar 25, 2023
We should be running any decoder/encoder tests using
FeatureTestRunnerwith which we can disable Avx/Sse etc.brianpopow commentedon Mar 25, 2023
Here is the coverage report For LosslessUtils.
ClampedAddSubtractHalfis reported as covered, but theClip255which is called byClampedAddSubtractHalfis only reported as covered partially. I think that's the problem.I will improve the test, so it will be fully covered.
There is a test
RunPredictor13Testwhich uses theFeatureTestRunnerto run with and without intrinsics. For context:Predictor13()callsClampedAddSubtractHalf().There are some paths not covered, for example
BundleColorMap()andSubtractGreenFromBlueAndRedScalar()gfoidl commentedon Mar 25, 2023
That's a bit strange. When the private method
AddSubtractComponentHalfis covered, and that method had the bug, then it should have shown up. Or is the test -- ran viaFeatureTestRunner-- only executing some inputs?I'm new to the test infrastructure here, so I have to ask?
Besides that I wonder why so many tests (10+) fail when SSE is disabled.
brianpopow commentedon Mar 26, 2023
The issue is in
Clip255, this method is called byAddSubtractComponentHalfand is not fully covered. Only the path
a < 256 == trueis covered, not the casea < 256 == falseThis hides the error. This means we need two test cases for
RunPredictor13Testone fora < 256 == trueand one fora < 256 == false.The when you revert back your commit b694956 to have the issue, it will show up as a failed test.
FeatureTestRunnerallows us to run tests with disabled intrinsics features.For example:
This will run
RunTestwith hardware intrinsics once and once without AVX2 (assuming the host cpu has AVX2).I had no chance yet to look into those failing tests, but we need to fix them all.
gfoidl commentedon Mar 26, 2023
FeatureTestRunneris a nice solution. Thanks for the explanaition 👍🏻Is the cost of running of a whole CI-leg with SSE disabled too high?
Or can this be run only on a scheduled basis?
So all code-paths w/o vectorization are touched, and no one has to think about adding a test-case with the FeatureTestRunner.
JimBobSquarePants commentedon Mar 26, 2023
To cover all the intrinsic paths on 4 OS (linux is counted 2x now we have ARM) for 2X target frameworks the build matrix explodes to something like 28 images now.
FeatureTestRunnerwas my workaround to keep numbers low and also so we could get a detailed code coverage report from a single entry in the build matrix.I don't think there's a way to keep our coverage report intact while splitting out the features into separate matrix entries.
I would suggest we ensure that all decoder/encoder methods use
FeatureTestRunnerfor Avx, Sse, AdvancedSimd, and scalar runs. It's a chore but absolutely necessary.gfoidl commentedon Mar 26, 2023
This should be avoided, for sure.
I'd do only +1, so run a additional
ubuntu-latestwithDOTNET_EnableSSE=0set. So that scalar pathes are touched at least once (for sure).If there's a test missing for running via
FeatureTestRunnercode will be covered too.I'm not that familiar with GH-Actions (I'm using Azure Pipelines mostly) but I think that should be possible w/o exploding the matrix.
FeatureTestRunneris good and should be kept, as tests can be run on other operating systems too quite easily.(BTW: your implementation of that is really nice).
antonfirsov commentedon Mar 27, 2023
I can confirm this. I see 133 failing tests going scalar-only on my machine. For example, this is the output when decoding
testorig12.jpg:I recommend fixing these one-by-one, adding the missing test cases for each individual bug in the process.
While
FeatureTestRunneris good tool, using it systematically in every single integration test would be very expensive. I think adding one test leg to cover the scalar case on one OS, as #2414 (comment) suggests, would be valuable.stefannikolei commentedon Mar 27, 2023
After merging #2416 many errors will be solved. Probably the image you have posted will render correct.
6 remaining items
brianpopow commentedon Apr 2, 2023
@br3aker thanks for looking into this issue!
brianpopow commentedon Apr 5, 2023
With #2427 merged, 15 test remain failing on the current main branch now.
Two failing tests are webp encoding tests. I think there is an issue that the AVX version of
Vp8Residual.GetResidualCost()does not match the scalar version. I am trying to figure out what's wrong there.P.S. I whish there would be an option not to close linked issues when PR are merged. I could not find any.
JimBobSquarePants commentedon Apr 5, 2023
The only way to avoid closing is not to use the closing keywords when linking to issues.
brianpopow commentedon Apr 23, 2023
I cant figure out what's going wrong with those png encoder tests. As mentioned above those failing tests seem to be related to decoding text chunks.
Here is an example stack trace from
PngEncoderTests.Chunks.cs:The weird thing is, when I execute a single failing test, the test runs fine and is green.
br3aker commentedon Apr 23, 2023
Wild guess: maybe tiered compilation (rejitter?) doesn't respect ISA environmental variables on net6? Didn't check on net7.
I've set this env variable

DOTNET_TieredCompilation=0and got following results:Last failing test is related to image diff threshold, not sure whether it's related to the codegen.
Now I'm completely lost, we can't simply set this variable and go on - there's a probability it can be broken by some R2R situation? Sorry to bother you @tannergooding but I'm not sure we can solve this on our own :)
tannergooding commentedon Apr 24, 2023
Could I get a few more details on exactly what's being set and what OS/architecture you're running on?
br3aker commentedon Apr 24, 2023
Win11/x86, no emulation
We are trying to test all ImageSharp tests for scalar path so I've set
<DOTNET_EnableSSE>0</DOTNET_EnableSSE>in.runsettingsfor emulating cpu without sse support at all.We got some flaky tests which end up throwing
System.PlatformNotSupportedException : Operation is not supported on this platform.. If these tests are executed among other tests - everything breaks due to this call:Sse2.LoadScalarVector128(UInt64* address)frommscorlib, you can check exact stacktrace from the message above mine.But if these flacky tests are launched in isolation - they successfully pass. I immediately thought about tiered jitting and decided to turn it off with
<DOTNET_TieredCompilation>0</DOTNET_TieredCompilation>in.runsettingsfile, file looked like this:With this settings flaky tests do not fail, i.e. no more
System.PlatformNotSupportedExceptionfrom SSE calls.tannergooding commentedon Apr 24, 2023
This sounds like a bad interaction between
EnableSSE=0andReadyToRun. Does settingDOTNET_ReadyToRun=0fix it?br3aker commentedon Apr 24, 2023
Yep, setting
DOTNET_ReadyToRun=0fixed tests. Should we open an issue or it's intended/workaround exists?tannergooding commentedon Apr 24, 2023
Please open an issue. I'm pretty sure I know what the issue is, but would be good to get it tracked explicitly as impacting the broader community
br3aker commentedon Apr 24, 2023
Got it, will do tomorrow, thank you for the help!
JimBobSquarePants commentedon Nov 9, 2023
I think we can go ahead and close this now that the upstream issue is fixed in .NET 7+