-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
[SPARK-28433][SQL][TEST] Remove hardware-dependent 0.0/0.0
and NaN comparison assertions
#25186
[SPARK-28433][SQL][TEST] Remove hardware-dependent 0.0/0.0
and NaN comparison assertions
#25186
Conversation
Interesting! Could you post some refs? From my understanding, aarch64 FP ISA should fully support IEEE 754, then why there's a difference between x86_64 & aarch64? |
@yeshengm Hi, I post the discuss topic in JIRA issue, paste it again here:) https://users.scala-lang.org/t/the-value-of-floattorawintbits-0-0f-0-0f-is-different-on-x86-64-and-aarch64-platforms/4845 |
I think this change is narrowly fine. I'm actually not sure why we test the result of this JDK method directly; it's not a Spark method. @cloud-fan I think you added this? I'm wondering if there are other usages of floatToRawIntBits, and I see only one other in QueryTest. There it's just comparing floats as bits to distinguish 0 and -0, and the varying representation of NaN probably doesn't matter. But by the same token, I think that code in QueryTest should use floatToIntBits to canonicalize NaN? maybe even have a better test to exercise NaN. So: I think my suggestion is to delete these assertions instead. |
sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
Show resolved
Hide resolved
assert(doubleToRawLongBits(0.0/0.0) != doubleToRawLongBits(Double.NaN)) | ||
if (System.getProperty("os.arch").contains("aarch64")) { | ||
// 0.0/0.0 and NaN are same value on aarch64. | ||
assert(floatToRawIntBits(0.0f/0.0f) == floatToRawIntBits(Float.NaN)) |
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.
We can change it to any value that is NaN but has a different binary representation than Float.NaN
.
Test build #4824 has finished for PR 25186 at commit
|
So maybe delete these assertion is a good choose? The binary representation depends on hardware and seems these assertion is not related with spark function. |
Since I have no aarch64 machine, I am curious about the following statement.
Did you actually see unexpected results due to this assertion? |
(Yes, this assertion fails on ARM, per the thread on dev@) |
// 0.0/0.0 and NaN are different values. | ||
assert(floatToRawIntBits(0.0f/0.0f) != floatToRawIntBits(Float.NaN)) | ||
assert(doubleToRawLongBits(0.0/0.0) != doubleToRawLongBits(Double.NaN)) | ||
if (System.getProperty("os.arch").contains("aarch64")) { |
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.
Just a question; the existing tests call System.setProperty("os.arch", "xxx")
, so this affects this check? e.g.,
https://github.com/apache/spark/blob/master/core/src/test/scala/org/apache/spark/util/SizeEstimatorSuite.scala#L195
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.
No, we ran the tests without modification of spark code on arm64, and the test failed, and also I took the tests on arm64, see:
on x86_64
root@donotdel-openlab-allinone-l00242678:/home/ubuntu# uname -a
Linux donotdel-openlab-allinone-l00242678 4.4.0-154-generic #181-Ubuntu SMP Tue Jun 25 05:29:03 UTC
2019 x86_64 x86_64 x86_64 GNU/Linux
scala> import java.lang.Float.floatToRawIntBits
import java.lang.Float.floatToRawIntBits
scala> floatToRawIntBits(0.0f/0.0f)
res0: Int = -4194304
scala> floatToRawIntBits(Float.NaN)
res1: Int = 2143289344
#on aarch64
[root@arm-huangtianhua spark]# uname -a
Linux arm-huangtianhua 4.14.0-49.el7a.aarch64 #1 SMP Tue Apr 10 17:22:26 UTC 2018 aarch64 aarch64 aarch64 GNU/Linux
scala> import java.lang.Float.floatToRawIntBits
import java.lang.Float.floatToRawIntBits
scala> floatToRawIntBits(0.0f/0.0f)
res1: Int = 2143289344
scala> floatToRawIntBits(Float.NaN)
res2: Int = 2143289344
agree with @srowen that we can just remove this assertion if it depends on hardware |
OK, thanks all, and I will remove this assertion. |
We ran unit tests of spark on aarch64 server, then found the values of floatToRawIntBits(0.0f / 0.0f) and floatToRawIntBits(Float.NaN) on aarch64 are same, after discuss with jdk-dev and scala community, we believe the value should depend on the architecture. This removes the incorrect assertions to make sure the tests fit all architectures.
a0e6edd
to
cd5cf0c
Compare
ok to test |
0.0/0.0
and NaN comparison assertions
Test build #107908 has finished for PR 25186 at commit
|
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.
+1, LGTM.
I tested this PR on EC2 a1.4xlarge
with OpenJDK, too.
Merged to master.
Thank you for your first contribution, @huangtianhua . |
…comparison assertions ## What changes were proposed in this pull request? This PR removes a few hardware-dependent assertions which can cause a failure in `aarch64`. **x86_64** ``` rootdonotdel-openlab-allinone-l00242678:/home/ubuntu# uname -a Linux donotdel-openlab-allinone-l00242678 4.4.0-154-generic apache#181-Ubuntu SMP Tue Jun 25 05:29:03 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux scala> import java.lang.Float.floatToRawIntBits import java.lang.Float.floatToRawIntBits scala> floatToRawIntBits(0.0f/0.0f) res0: Int = -4194304 scala> floatToRawIntBits(Float.NaN) res1: Int = 2143289344 ``` **aarch64** ``` [rootarm-huangtianhua spark]# uname -a Linux arm-huangtianhua 4.14.0-49.el7a.aarch64 #1 SMP Tue Apr 10 17:22:26 UTC 2018 aarch64 aarch64 aarch64 GNU/Linux scala> import java.lang.Float.floatToRawIntBits import java.lang.Float.floatToRawIntBits scala> floatToRawIntBits(0.0f/0.0f) res1: Int = 2143289344 scala> floatToRawIntBits(Float.NaN) res2: Int = 2143289344 ``` ## How was this patch tested? Pass the Jenkins (This removes the test coverage). Closes apache#25186 from huangtianhua/special-test-case-for-aarch64. Authored-by: huangtianhua <huangtianhua@huawei.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
What changes were proposed in this pull request?
This PR removes a few hardware-dependent assertions which can cause a failure in
aarch64
.x86_64
aarch64
How was this patch tested?
Pass the Jenkins (This removes the test coverage).