runtime icon indicating copy to clipboard operation
runtime copied to clipboard

ExplicitConversion_FromSingle failing due to NaN != NaN

Open stephentoub opened this issue 1 year ago • 2 comments

Build Information

Build: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=705150 Build error leg or test failing: System.Tests.HalfTests.ExplicitConversion_FromSingle Pull request: https://github.com/dotnet/runtime/pull/103306

Error Message

Fill the error message using step by step known issues guidance.

{
  "ErrorMessage": "ExplicitConversion_FromSingle",
  "ErrorPattern": "",
  "BuildRetry": false,
  "ExcludeConsoleLog": false
}

Known issue validation

Build: :mag_right: https://dev.azure.com/dnceng-public/public/_build/results?buildId=705150 Error message validated: [ExplicitConversion_FromSingle] Result validation: :white_check_mark: Known issue matched with the provided build. Validation performed at: 6/12/2024 3:13:29 PM UTC

[14:40:21] info: [FAIL] System.Tests.HalfTests.ExplicitConversion_FromSingle(f: NaN, expected: NaN)
[14:40:21] info: Assert.Equal() Failure: Values differ
[14:40:21] info: Expected:   NaN
[14:40:21] info: Actual:     NaN
[14:40:21] info:    at System.AssertExtensions.Equal(Half expected, Half actual)
[14:40:21] info:    at System.Tests.HalfTests.ExplicitConversion_FromSingle(Single f, Half expected)
[14:40:21] info:    at System.Object.InvokeStub_HalfTests.ExplicitConversion_FromSingle(Object , Span`1 )
[14:40:21] info:    at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
[14:40:21] info: [FAIL] System.Tests.HalfTests.ExplicitConversion_FromSingle(f: NaN, expected: NaN)
[14:40:21] info: Assert.Equal() Failure: Values differ
[14:40:21] info: Expected:   NaN
[14:40:21] info: Actual:     NaN
[14:40:21] info:    at System.AssertExtensions.Equal(Half expected, Half actual)
[14:40:21] info:    at System.Tests.HalfTests.ExplicitConversion_FromSingle(Single f, Half expected)
[14:40:21] info:    at System.Object.InvokeStub_HalfTests.ExplicitConversion_FromSingle(Object , Span`1 )
[14:40:21] info:    at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

Report

Build Definition Test Pull Request
724838 dotnet/runtime WasmTestOnChrome-MT-System.Runtime.Tests.WorkItemExecution dotnet/runtime#104103
724459 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103915
724329 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103555
724335 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103915
724039 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103632
723841 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#104104
723792 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103915
723682 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103915
722132 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103915
720981 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#104026
720979 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#104025
720772 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103915
720649 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103915
719408 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#101531
719296 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103915
719184 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103915
718997 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103915
718856 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103740
718831 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103916
717912 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103714
717514 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103873
717491 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution
717204 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103861
716316 dotnet/runtime WasmTestOnFirefox-MT-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103841
715604 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103697
715199 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103793
714603 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103372
714025 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103757
713768 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103681
713175 dotnet/runtime System.Tests.HalfTests.ExplicitConversion_FromSingle dotnet/runtime#103351
713038 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103706
712828 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103574
711372 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103621
710890 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103588
710707 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103255
709151 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103527
706610 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103412
706286 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103395
705911 dotnet/runtime WasmTestOnV8-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103381
705150 dotnet/runtime WasmTestOnChrome-ST-System.Runtime.Tests.WorkItemExecution dotnet/runtime#103306

Summary

24-Hour Hit Count 7-Day Hit Count 1-Month Count
2 23 40

stephentoub avatar Jun 12 '24 15:06 stephentoub

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries See info in area-owners.md if you want to be subscribed.

Tagging subscribers to this area: @dotnet/area-system-numerics See info in area-owners.md if you want to be subscribed.

This issue is matching to tests jobs which log test names. Need to further constrain the match.

ericstj avatar Jul 30 '24 16:07 ericstj

Just hit this in #106040 for WasmTestOnChrome-ST-System.Runtime.Tests config: net9.0-browser-Release-wasm-Mono_Release-WasmTestOnChrome

[18:27:21] info: [STRT] System.Tests.HalfTests.ExplicitConversion_FromSingle(f: NaN, expected: NaN)
[18:27:21] info: [FAIL] System.Tests.HalfTests.ExplicitConversion_FromSingle(f: NaN, expected: NaN)
[18:27:21] info: Assert.Equal() Failure: Values differ
[18:27:21] info: Expected:   NaN
[18:27:21] info: Actual:     NaN
[18:27:21] info:    at System.AssertExtensions.Equal(Half expected, Half actual)
[18:27:21] info:    at System.Tests.HalfTests.ExplicitConversion_FromSingle(Single f, Half expected)
[18:27:21] info:    at System.Object.InvokeStub_HalfTests.ExplicitConversion_FromSingle(Object , Span`1 )
[18:27:21] info:    at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
[18:27:21] info: [STRT] System.Tests.HalfTests.ExplicitConversion_FromSingle(f: NaN, expected: NaN)
[18:27:21] info: [FAIL] System.Tests.HalfTests.ExplicitConversion_FromSingle(f: NaN, expected: NaN)
[18:27:21] info: Assert.Equal() Failure: Values differ
[18:27:21] info: Expected:   NaN
[18:27:21] info: Actual:     NaN
[18:27:21] info:    at System.AssertExtensions.Equal(Half expected, Half actual)
[18:27:21] info:    at System.Tests.HalfTests.ExplicitConversion_FromSingle(Single f, Half expected)
[18:27:21] info:    at System.Object.InvokeStub_HalfTests.ExplicitConversion_FromSingle(Object , Span`1 )
[18:27:21] info:    at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

Not sure why it didn't match in build analysis

mdh1418 avatar Aug 07 '24 21:08 mdh1418

The test here should likely be filtered out on WASM for the time being, with a tracking issue against it.

WASM isn't technically doing anything wrong here, normalizing NaN is fully allowed by the IEEE 754 spec. However, it is undesirable and not recommended for most cases and should typically be avoided if possible.

WASM also has instructions that should guarantee the underlying bits are preserved, so it should be possible for it to be preserved and match the behavior of other targets (both for RyuJIT and Mono).

tannergooding avatar Aug 07 '24 21:08 tannergooding

Hm the weird thing here is that this seems to be an intermittent failure. I've checked and we definitely have passing runs of the test on the exact same config.

akoeplinger avatar Aug 08 '24 18:08 akoeplinger

Is there perhaps a difference in the WASM version or configuration options for the failing platform as compared to others?

Maybe some machine specific issue that's only triggering in some scenarios?

tannergooding avatar Aug 08 '24 18:08 tannergooding

the tests are running in containers on the same helix queue so even the VM/machine should be the same...

Passing run: https://helixre107v0xdcypoyl9e7f.blob.core.windows.net/dotnet-runtime-refs-pull-106013-merge-6f4bade3cf974edcb8/WasmTestOnChrome-ST-System.Runtime.Tests/1/console.3fb2056a.log?helixlogtype=result

Failing run: https://helixre107v0xdcypoyl9e7f.blob.core.windows.net/dotnet-runtime-refs-pull-106040-merge-0b77eabb49f848cab5/WasmTestOnChrome-ST-System.Runtime.Tests/1/console.5edeb661.log?helixlogtype=result

The only difference is the order of the tests, but I'm having a hard time imagining how that could be relevant

akoeplinger avatar Aug 08 '24 18:08 akoeplinger

~~hm one interesting thing is that the failing run reports two tests that failed i.e. five total, but the passing run only ran four NaN tests...~~ that seems just a log quirk, the testResult.xml only contains four NaN tests and two of them failing.

akoeplinger avatar Aug 08 '24 19:08 akoeplinger

According to Kusto test data this started happening on or before 2024-06-06. I also found that it's happening on Windows-based containers too so it's not related to the underlying OS.

Given it's only happening intermittently and doesn't appear to be a blocker for 9.0 I'm moving it to 10.0

akoeplinger avatar Aug 09 '24 16:08 akoeplinger

Couple of things could be responsible which might be explained by the test order:

  1. jiterp might be kicking in
  2. browser JIT might be kicking in

But I'd like to push back against hte idea that bitwise comparison of two NaNs is a good idea. there are many NaN bitpatterns; all are semantically indistinguishable. Reasonable code should not depend on the bit pattern staying identical after computation

lambdageek avatar Aug 23 '24 22:08 lambdageek

But I'd like to push back against hte idea that bitwise comparison of two NaNs is a good idea. there are many NaN bitpatterns; all are semantically indistinguishable. Reasonable code should not depend on the bit pattern staying identical after computation

This is a core thing frequently depended upon for SIMD, NaN boxing, etc. It also follows the IEEE 754 "recommended" guidelines, even if it's not strictly required by the IEEE 754 spec.

The WASM 1.0 and 2.0 specs similarly:

  • distinguish canonical NaN from arithmetic NaN (a nan with payload n)
  • provide explicit APIs for getting the bits of any NaN
    • fbits(+/-nan(n)) is defined as fsign(+/-) * 1^expon(n) * ibits(sinif(n))
    • which is to say, its doing BitConverter.SingleToInt32Bits or BitConverter.DoubleToInt64Bits or vice-versa
  • recommend that operators propagate NaN payloads (matching the IEEE 754 recommendation)
  • provides explicit support for specifying the payload of a NaN

However, the WASM specs do notably explicitly allow non-determinism for fneg, fabs, and fcopysign; explicitly specifying that the sign and payload of the result are non-deterministic

So while a given implementation is technically allowed to do "other things" (such as always canonicalizing NaN), its highly irregular to do so and that's why we have tests that validate such conversions are preserving bits and propagating payloads as expected. -- It's also notably cheaper to propagate and to preserve NaN as is then it is to canonicalize (particularly for things like fbits), so there's really no reason for a browser to deviate here

tannergooding avatar Aug 23 '24 23:08 tannergooding

@tannergooding @lambdageek what are the next steps here ?

pavelsavara avatar Sep 24 '24 09:09 pavelsavara

Should the milestone be 10? This is hitting 9.0 PRs too. Example:

  • 9.0 PR: https://github.com/dotnet/runtime/pull/108326
  • Job: https://dev.azure.com/dnceng-public/public/_build/results?buildId=839877&view=logs&j=d4e38924-13a0-58bd-9074-6a4810543e7c&t=7a581d54-fbdb-5b9d-4377-cc346f489112&l=104
  • Log: https://helixre107v0xd1eu3ibi6ka.blob.core.windows.net/dotnet-runtime-refs-pull-108326-merge-06a2d595e69e44cd8b/WasmTestOnV8-ST-System.Runtime.Tests/1/console.46ef387c.log?helixlogtype=result

carlossanlop avatar Oct 11 '24 18:10 carlossanlop