Skip to content
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

Closed

Conversation

huangtianhua
Copy link
Contributor

@huangtianhua huangtianhua commented Jul 18, 2019

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

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

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 

How was this patch tested?

Pass the Jenkins (This removes the test coverage).

@huangtianhua huangtianhua changed the title Special scala test case for aarch64 [SPARK-28433] Special scala test case for aarch64 Jul 18, 2019
@huangtianhua huangtianhua changed the title [SPARK-28433] Special scala test case for aarch64 [SPARK-28433][SQL]Special scala test case for aarch64 Jul 18, 2019
@yeshengm
Copy link
Contributor

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?

@huangtianhua
Copy link
Contributor Author

@srowen
Copy link
Member

srowen commented Jul 18, 2019

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.

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))
Copy link
Contributor

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.

@SparkQA
Copy link

SparkQA commented Jul 18, 2019

Test build #4824 has finished for PR 25186 at commit a0e6edd.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@huangtianhua
Copy link
Contributor Author

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.

@kiszk
Copy link
Member

kiszk commented Jul 19, 2019

Since I have no aarch64 machine, I am curious about the following statement.

seems these assertion is not related with spark function.

Did you actually see unexpected results due to this assertion?

@srowen
Copy link
Member

srowen commented Jul 19, 2019

(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")) {
Copy link
Member

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

Copy link
Contributor Author

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

@cloud-fan
Copy link
Contributor

agree with @srowen that we can just remove this assertion if it depends on hardware

@huangtianhua
Copy link
Contributor Author

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.
@huangtianhua huangtianhua force-pushed the special-test-case-for-aarch64 branch from a0e6edd to cd5cf0c Compare July 19, 2019 06:35
@cloud-fan
Copy link
Contributor

ok to test

@dongjoon-hyun dongjoon-hyun changed the title [SPARK-28433][SQL]Special scala test case for aarch64 [SPARK-28433][SQL][TEST] Remove hardware-dependent 0.0/0.0 and NaN comparison assertions Jul 19, 2019
@SparkQA
Copy link

SparkQA commented Jul 19, 2019

Test build #107908 has finished for PR 25186 at commit cd5cf0c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a 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.

@dongjoon-hyun
Copy link
Member

Thank you for your first contribution, @huangtianhua .
You are added to the Apache Spark contributor group and the following issue is assigned to you.

yiheng pushed a commit to yiheng/spark that referenced this pull request Jul 24, 2019
…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>
@huangtianhua huangtianhua deleted the special-test-case-for-aarch64 branch September 11, 2019 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants