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

Enable f16 tests on platforms that were missing conversion symbols #129385

Merged
merged 1 commit into from
Sep 28, 2024

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Aug 22, 2024

The only requirement for f16 support, aside from LLVM not crashing and no ABI issues, is that symbols to convert to and from f32 are available. Since the update to compiler-builtins in #125016, we now provide these on all platforms.

This also enables f16 math since there are no further requirements.

Still excluded are platforms for which LLVM emits infinitely-recursing code.

try-job: arm-android
try-job: test-various
try-job: x86_64-fuchsia

@rustbot
Copy link
Collaborator

rustbot commented Aug 22, 2024

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 22, 2024
@tgross35
Copy link
Contributor Author

This will conflict with #128349 and #129384 but we can start some tests.

@martn3 could you check that mips is working now since you disabled it in #127235?

@tgross35
Copy link
Contributor Author

@bors try

@tgross35
Copy link
Contributor Author

This affects a ton of targets, I can almost guarantee at least one failure when we go to merge.

@bors rollup=never

@tgross35 tgross35 changed the title Enable f16 on platforms that were missing conversion symbols Enable f16 tests on platforms that were missing conversion symbols Aug 22, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 22, 2024
…r=<try>

Enable `f16` tests on platforms that were missing conversion symbols

The only requirement for `f16` support, aside from LLVM not crashing and no ABI issues, is that symbols to convert to and from `f32` are available. Since the update to compiler-builtins in rust-lang#125016, we now provide these on all platforms.

This also enables `f16` math since there are no further requirements.

try-job: dist-powerpc64-linux
try-job: dist-powerpc64le-linux
try-job: dist-riscv64-linux
try-job: dist-aarch64-msvc
@bors
Copy link
Contributor

bors commented Aug 22, 2024

⌛ Trying commit b557938 with merge 2e1289c...

@tgross35
Copy link
Contributor Author

tgross35 commented Aug 22, 2024

I need to disable wasm since it is no longer caught by the default case this should match, https://github.com/rust-lang/compiler-builtins/blob/d96d3a7ca0e63fe990e2dc200f4c275591fa63f0/configure.rs#L62-L77. Will wait for this set of tests to complete.

@beetrees mind checking my logic here?

@tgross35 tgross35 added the F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` label Aug 22, 2024
@bors
Copy link
Contributor

bors commented Aug 22, 2024

☀️ Try build successful - checks-actions
Build commit: 2e1289c (2e1289c32280fb4263ce79eccf48781e05959eab)

@beetrees
Copy link
Contributor

While the symbols are now available on most targets, f16 tests will fail on any target affected by llvm/llvm-project#97981 (that is, when target arch matches "csky" | "hexagon" | "loongarch64" | "mips" | "mips64" | "mips32r6" | "mips64r6" | "powerpc" | "powerpc64" | "sparc" | "sparc64" | "wasm32" | "wasm64"). Specifically, the LLVM issue will cause infinite recursion in compiler-builtins implementation of the __extendhfsf2 and __truncsfhf2 builtins (like rust-lang/compiler-builtins#651).

@tgross35
Copy link
Contributor Author

Ah that's right, I was just going off of the comments and forgot there is more to the story. I'll have to update jobs.yaml so these actually get verified in CI too.

At least we should be able to enable Windows and MacOS.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 22, 2024
@martn3
Copy link

martn3 commented Aug 22, 2024

@tgross35 Thanks for the ping! I did some quick testing and things seems to work as they should after I cherry-picked your commit. Maybe you should also remove the FIXMEs I added?

Click here to see a diff of what I mean
From 34ef3b44cd49a5a9081c522d9373f0f95a1803c8 Mon Sep 17 00:00:00 2001
From: Martin Nordholts <martn@axis.com>
Date: Thu, 22 Aug 2024 12:03:04 +0200
Subject: [PATCH] core: Enable f16 doctests for all linux archs

---
 library/core/src/num/f16.rs | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/library/core/src/num/f16.rs b/library/core/src/num/f16.rs
index 41bd34a2702..64484d432a7 100644
--- a/library/core/src/num/f16.rs
+++ b/library/core/src/num/f16.rs
@@ -630,8 +630,7 @@ pub fn next_down(self) -> Self {
     ///
     /// ```
     /// #![feature(f16)]
-    /// # // FIXME(f16_f128): extendhfsf2, truncsfhf2, __gnu_h2f_ieee, __gnu_f2h_ieee missing for many platforms
-    /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] {
+    /// # #[cfg(all(target_os = "linux"))] {
     ///
     /// let x = 2.0_f16;
     /// let abs_difference = (x.recip() - (1.0 / x)).abs();
@@ -650,8 +649,7 @@ pub fn recip(self) -> Self {
     ///
     /// ```
     /// #![feature(f16)]
-    /// # // FIXME(f16_f128): extendhfsf2, truncsfhf2, __gnu_h2f_ieee, __gnu_f2h_ieee missing for many platforms
-    /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] {
+    /// # #[cfg(all(target_os = "linux"))] {
     ///
     /// let angle = std::f16::consts::PI;
     ///
@@ -672,8 +670,7 @@ pub fn to_degrees(self) -> Self {
     ///
     /// ```
     /// #![feature(f16)]
-    /// # // FIXME(f16_f128): extendhfsf2, truncsfhf2, __gnu_h2f_ieee, __gnu_f2h_ieee missing for many platforms
-    /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] {
+    /// # #[cfg(all(target_os = "linux"))] {
     ///
     /// let angle = 180.0f16;
     ///
@@ -1175,8 +1172,7 @@ pub const fn from_bits(v: u16) -> Self {
     ///
     /// ```
     /// #![feature(f16)]
-    /// # // FIXME(f16_f128): extendhfsf2, truncsfhf2, __gnu_h2f_ieee, __gnu_f2h_ieee missing for many platforms
-    /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] {
+    /// # #[cfg(all(target_os = "linux"))] {
     ///
     /// struct GoodBoy {
     ///     name: &'static str,
-- 
2.39.2

@tgross35
Copy link
Contributor Author

@martn3 thanks for checking. Do you mean things build correctly, or tests actually pass? Based on @beetrees comment I have to expect that some things will fail, hence I'm going to back the MIPS changes (and others) out of this PR.

Good point, the FIXMEs are fixed. I'm going to leave the gates x86-only for now until we know they pass on all platforms, I just don't want to list every arch or duplicate this config in core/build.rs (the doctests running at all is just to show they aren't broken, the integration tests do the thorough checks)

@martn3
Copy link

martn3 commented Aug 22, 2024

@tgross35 f16 tests both build and pass for me. I run

TEST_DEVICE_ADDR=192.168.0.173:12345 CARGOFLAGS_NOT_BOOTSTRAP=-Zdoctest-xcompile ./x.py test --set rust.verbose-tests=true --target mipsel-unknown-linux-gnu library/core library/std -- --test f16

and get

click to expand
test f16::tests::test_abs ... ok
test f16::tests::test_acosh ... ok
test f16::tests::test_asinh ... ok
test f16::tests::test_atanh ... ok
test f16::tests::test_ceil ... ok
test f16::tests::test_classify ... ok
test f16::tests::test_exp ... ok
test f16::tests::test_exp2 ... ok
test f16::tests::test_float_bits_conv ... ok
test f16::tests::test_floor ... ok
test f16::tests::test_fract ... ok
test f16::tests::test_gamma ... ok
test f16::tests::test_infinity ... ok
test f16::tests::test_is_finite ... ok
test f16::tests::test_is_infinite ... ok
test f16::tests::test_is_nan ... ok
test f16::tests::test_is_normal ... ok
test f16::tests::test_is_sign_negative ... ok
test f16::tests::test_is_sign_positive ... ok
test f16::tests::test_ln ... ok
test f16::tests::test_ln_gamma ... ok
test f16::tests::test_log ... ok
test f16::tests::test_log10 ... ok
test f16::tests::test_log2 ... ok
test f16::tests::test_max_nan ... ok
test f16::tests::test_maximum ... ok
test f16::tests::test_min_nan ... ok
test f16::tests::test_minimum ... ok
test f16::tests::test_mul_add ... ok
test f16::tests::test_nan ... ok
test f16::tests::test_neg_infinity ... ok
test f16::tests::test_one ... ok
test f16::tests::test_next_up ... ok
test f16::tests::test_neg_zero ... ok
test f16::tests::test_powi ... ok
test f16::tests::test_next_down ... ok
test f16::tests::test_num_f16 ... ok
test f16::tests::test_powf ... ok
test f16::tests::test_round_ties_even ... ok
test f16::tests::test_sqrt_domain ... ok
test f16::tests::test_zero ... ok
test f16::tests::test_to_degrees ... ok
test f16::tests::test_real_consts ... ok
test f16::tests::test_trunc ... ok
test f16::tests::test_round ... ok
test f16::tests::test_to_radians ... ok
test f16::tests::test_recip ... ok
test f16::tests::test_total_cmp ... ok
test f16::tests::test_clamp_min_is_nan ... ok
test f16::tests::test_clamp_max_is_nan ... ok
test f16::tests::test_clamp_min_greater_than_max ... ok
test core/src/num/f16.rs - f16::f16::is_sign_negative (line 499) ... ok
test core/src/num/f16.rs - f16::f16::is_finite (line 320) ... ok
test core/src/num/f16.rs - f16::f16::classify (line 410) ... ok
test core/src/num/f16.rs - f16::f16::from_be_bytes (line 1069) ... ok
test core/src/num/f16.rs - f16::f16::from_ne_bytes (line 1122) ... ok
test core/src/num/f16.rs - f16::f16::is_infinite (line 294) ... ok
test core/src/num/f16.rs - f16::f16::from_bits (line 956) ... ok
test core/src/char/methods.rs - char::methods::char::encode_utf16 (line 696) ... ok
test core/src/char/methods.rs - char::methods::char::len_utf16 (line 632) ... ok
test core/src/num/f16.rs - f16::f16::from_le_bytes (line 1092) ... ok
test core/src/num/f16.rs - f16::f16::clamp (line 1254) ... ok
test core/src/num/f16.rs - f16::f16::is_normal (line 378) ... ok
test core/src/num/f16.rs - f16::f16::is_subnormal (line 348) ... ok
test core/src/char/methods.rs - char::methods::char::decode_utf16 (line 126) ... ok
test core/src/num/f16.rs - f16::f16::min (line 722) ... ok
test core/src/num/f16.rs - f16::f16::midpoint (line 827) ... ok
test core/src/num/f16.rs - f16::f16::is_sign_positive (line 473) ... ok
test core/src/char/methods.rs - char::methods::char::decode_utf16 (line 104) ... ok
test core/src/num/f16.rs - f16::f16::next_up (line 534) ... ok
test core/src/num/f16.rs - f16::f16::recip (line 631) ... ok
test core/src/num/f16.rs - f16::f16::to_be_bytes (line 982) ... ok
test core/src/num/f16.rs - f16::f16::to_bits (line 908) ... ok
test core/src/num/f16.rs - f16::f16::to_degrees (line 650) ... ok
test core/src/num/f16.rs - f16::f16::to_int_unchecked (line 865) ... ok
test core/src/num/f16.rs - f16::f16::to_le_bytes (line 1007) ... ok
test core/src/num/f16.rs - f16::f16::to_ne_bytes (line 1038) ... ok
test core/src/num/f16.rs - f16::f16::to_radians (line 671) ... ok
test core/src/num/f16.rs - f16::f16::total_cmp (line 1173) ... ok
test core/src/num/f16.rs - f16::f16::maximum (line 744) ... ok
test core/src/num/f16.rs - f16::f16::next_down (line 588) ... ok
test core/src/char/methods.rs - char::methods::char::encode_utf16 (line 706) ... ok
test core/src/num/f16.rs - f16::f16::max (line 698) ... ok
test core/src/num/f16.rs - f16::f16::minimum (line 784) ... ok
test core/src/num/f16.rs - f16::f16::is_nan (line 262) ... ok
test core/src/ops/arith.rs - ops::arith::f16 (line 630) ... ok
test core/src/str/mod.rs - str::str::encode_utf16 (line 1084) ... ok
test core/src/num/mod.rs - num::u16::is_utf16_surrogate (line 1112) ... ok
test std/src/f16.rs - f16::f16::acos (line 868) ... ok
test std/src/f16.rs - f16::f16::asin (line 833) ... ok
test std/src/f16.rs - f16::f16::cbrt (line 677) ... ok
test std/src/f16.rs - f16::f16::copysign (line 258) ... ok
test std/src/f16.rs - f16::f16::acosh (line 1219) ... ok
test std/src/f16.rs - f16::f16::atanh (line 1253) ... ok
test std/src/f16.rs - f16::f16::cos (line 770) ... ok
test std/src/f16.rs - f16::f16::abs (line 197) ... ok
test std/src/f16.rs - f16::f16::atan (line 902) ... ok
test std/src/f16.rs - f16::f16::cosh (line 1120) ... ok
test std/src/f16.rs - f16::f16::atan2 (line 940) ... ok
test std/src/f16.rs - f16::f16::ln (line 552) ... ok
test std/src/f16.rs - f16::f16::ln_1p (line 1051) ... ok
test std/src/f16.rs - f16::f16::floor (line 26) ... ok
test std/src/f16.rs - f16::f16::ln_gamma (line 1320) ... ok
test std/src/f16.rs - f16::f16::hypot (line 712) ... ok
test std/src/f16.rs - f16::f16::gamma (line 1286) ... ok
test std/src/f16.rs - f16::f16::asinh (line 1187) ... ok
test std/src/f16.rs - f16::f16::div_euclid (line 339) ... ok
test std/src/f16.rs - f16::f16::log (line 587) ... ok
test std/src/f16.rs - f16::f16::log10 (line 645) ... ok
test std/src/f16.rs - f16::f16::log2 (line 616) ... ok
test std/src/f16.rs - f16::f16::mul_add (line 296) ... ok
test std/src/f16.rs - f16::f16::powf (line 432) ... ok
test std/src/f16.rs - f16::f16::rem_euclid (line 381) ... ok
test std/src/f16.rs - f16::f16::round (line 80) ... ok
test std/src/f16.rs - f16::f16::round_ties_even (line 112) ... ok
test std/src/f16.rs - f16::f16::signum (line 227) ... ok
test std/src/f16.rs - f16::f16::fract (line 170) ... ok
test std/src/f16.rs - f16::f16::ceil (line 53) ... ok
test std/src/f16.rs - f16::f16::exp2 (line 523) ... ok
test std/src/f16.rs - f16::f16::sin (line 742) ... ok
test std/src/f16.rs - f16::f16::sin_cos (line 982) ... ok
test std/src/f16.rs - f16::f16::sinh (line 1085) ... ok
test std/src/f16.rs - f16::f16::sqrt (line 462) ... ok
test std/src/f16.rs - f16::f16::tan (line 801) ... ok
test std/src/f16.rs - f16::f16::tanh (line 1155) ... ok
test std/src/f16.rs - f16::f16::trunc (line 142) ... ok
test std/src/f16.rs - f16::f16::exp (line 492) ... ok
test std/src/f16.rs - f16::f16::exp_m1 (line 1017) ... ok

@beetrees
Copy link
Contributor

beetrees commented Aug 22, 2024

Huh. When cross-testing via QEMU with x test library/std --target mipsel-unknown-linux-gnu, I get:

thread 'f16::tests::test_acosh' has overflowed its stack
fatal runtime error: stack overflow

Not sure why we're getting different results. @martn3 What's your config.toml? I'm getting this error when using the defaults from profile = "library".

@martn3
Copy link

martn3 commented Aug 23, 2024

@beetrees My linker and MIPS system are not vanilla Debian, and I use special compiler and link flags, for example -Ctarget-feature=+mips32r2 -Ctarget-feature=+soft-float, which I think can explain our different results.

My config.toml is just

[target.mipsel-unknown-linux-gnu]
linker = "..."

@beetrees
Copy link
Contributor

That would explain it: llvm/llvm-project#97981 only occurs on hard-float MIPS (soft-float MIPS is only affected by llvm/llvm-project#97975).

@alex-semenyuk
Copy link
Member

alex-semenyuk commented Sep 23, 2024

@tgross35
From wg-triage. Is it something that need clarification here or you can proceed with this?

The only requirement for `f16` support, aside from LLVM not crashing and
no ABI issues, is that symbols to convert to and from `f32` are
available. Since the update to compiler-builtins in [1], we now provide
these on all platforms.

This also enables `f16` math since there are no further requirements.

Still excluded are platforms for which LLVM emits infinitely-recursing
code.

[1]: rust-lang#125016
@tgross35
Copy link
Contributor Author

I updated this PR to reflect @beetrees comment in #129385 (comment). The only net change here is that f16 tests should be enabled on OSs that are not Linux or MacOS, but still excluding x86 Windows because of the MinGW bug. We don't have an aarch64 Windows CI job so I just enabled a few jobs that should hopefully cover the tests somewhere.

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 27, 2024
…r=<try>

Enable `f16` tests on platforms that were missing conversion symbols

The only requirement for `f16` support, aside from LLVM not crashing and no ABI issues, is that symbols to convert to and from `f32` are available. Since the update to compiler-builtins in rust-lang#125016, we now provide these on all platforms.

This also enables `f16` math since there are no further requirements.

try-job: arm-android
try-job: test-various
try-job: x86_64-fuchsia
@bors
Copy link
Contributor

bors commented Sep 27, 2024

⌛ Trying commit 404c5d2 with merge 5d4a2b6...

@bors
Copy link
Contributor

bors commented Sep 28, 2024

☀️ Try build successful - checks-actions
Build commit: 5d4a2b6 (5d4a2b6b8e1db005ed98a5c525f0dca1eb377fe1)

@tgross35
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 28, 2024
@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Sep 28, 2024

📌 Commit 404c5d2 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 28, 2024
@bors
Copy link
Contributor

bors commented Sep 28, 2024

⌛ Testing commit 404c5d2 with merge ed04567...

@bors
Copy link
Contributor

bors commented Sep 28, 2024

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing ed04567 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 28, 2024
@bors bors merged commit ed04567 into rust-lang:master Sep 28, 2024
7 checks passed
@rustbot rustbot added this to the 1.83.0 milestone Sep 28, 2024
@tgross35 tgross35 deleted the more-platforms-enable-f16 branch September 28, 2024 23:14
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ed04567): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 2.2%, secondary 2.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.2% [2.2%, 2.2%] 1
Regressions ❌
(secondary)
2.0% [1.6%, 2.5%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.2% [2.2%, 2.2%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 769.092s -> 767.6s (-0.19%)
Artifact size: 341.40 MiB -> 341.36 MiB (-0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants