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

is_x86_feature_detected!("avx512f") fails to build on beta and nightly #68905

Closed
oconnor663 opened this issue Feb 6, 2020 · 38 comments · Fixed by #70151
Closed

is_x86_feature_detected!("avx512f") fails to build on beta and nightly #68905

oconnor663 opened this issue Feb 6, 2020 · 38 comments · Fixed by #70151
Assignees
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@oconnor663
Copy link
Contributor

oconnor663 commented Feb 6, 2020

The following program builds and runs on stable but fails to build on nightly:

fn main() {
    dbg!(is_x86_feature_detected!("avx512f"));
}

Here's the build error on rustc 1.43.0-nightly (58b834344 2020-02-05):

error[E0658]: use of unstable library feature 'stdsimd'
 --> src/main.rs:2:10
  |
2 |     dbg!(is_x86_feature_detected!("avx512f"));
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: for more information, see https://github.com/rust-lang/rust/issues/27731
  = help: add `#![feature(stdsimd)]` to the crate attributes to enable
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

But note that if I replace "avx512f" with "avx2", the error goes away.

@Mark-Simulacrum
Copy link
Member

cc @gnzlbg

@oconnor663
Copy link
Contributor Author

Here's the output of cargo-bisect-rustc:

searched nightlies: from nightly-2020-01-02 to nightly-2020-02-10
regressed nightly: nightly-2020-02-06
searched commits: from c9290dc to 58b8343
regressed commit: eda1a7a

That points to #68755, which is a large merge of stdarch. When I bisect stdarch, I find the error was introduced in rust-lang/stdarch@cb6fa68, possibly intentionally. Is it the case that AVX-512 feature detection was never intended to be stabilized? Or maybe it got caught up in a larger group of unstable features? Prior to this regression, it did in fact work :)

oconnor663 added a commit to BLAKE3-team/BLAKE3 that referenced this issue Feb 10, 2020
…bled

rust-lang/rust#68905 is currently causing
nightly builds to fail, unless `--no-default-features` is used. This
change means that the default build will succeed, and the failure will
only happen when the "c_avx512" is enabled. The `b3sum` crate will still
fail to build on nightly, because it enables that feature, but most
callers should start succeeding on nightly.
oconnor663 added a commit to BLAKE3-team/BLAKE3 that referenced this issue Feb 10, 2020
…bled

rust-lang/rust#68905 is currently causing
nightly builds to fail, unless `--no-default-features` is used. This
change means that the default build will succeed, and the failure will
only happen when the "c_avx512" is enabled. The `b3sum` crate will still
fail to build on nightly, because it enables that feature, but most
callers should start succeeding on nightly.
oconnor663 added a commit to BLAKE3-team/BLAKE3 that referenced this issue Feb 10, 2020
Changes since 0.1.4:
- Remove all AVX-512 code from builds with the default feature set. This
  works around rust-lang/rust#68905 and fixes
  the nightly build as long as the "c_avx512" feature is not activated.

This release is a backport of a single commit, e43a7d6. The master
branch contains backwards-incompatible changes (fc219f4), and the next
release of master will be version 0.2.0.

Note that the `b3sum` crate activates the "c_avx512" feature by default,
and it will continue to fail to build on nightly until the upstream bug
is fixed.
@oconnor663
Copy link
Contributor Author

oconnor663 commented Feb 12, 2020

A quick search through https://github.com/search?q=is_x86_feature_detected%21%28%22avx512f%22%29&type=Code turns up at least one other crate besides BLAKE3 that fails to build on nightly for this reason:

git clone https://github.com/PoC-Consortium/scavenger
cd scavenger
cargo check --features=simd           # succeeds
cargo +nightly check --features=simd  # fails

@oconnor663
Copy link
Contributor Author

@Mark-Simulacrum, this might be a hi-pri regression. (Though of course I'm biased cause it affects my crate.) If @gnzlbg isn't available to evaluate it, could we pull in someone else?

@Mark-Simulacrum
Copy link
Member

cc @rust-lang/libs

To be honest I'm not even entirely sure where this macro is implemented...

@Amanieu
Copy link
Member

Amanieu commented Feb 14, 2020

Caused by rust-lang/stdarch#739, which started enforcing stability on individual features.

@oconnor663
Copy link
Contributor Author

oconnor663 commented Feb 14, 2020

It looks like a crater run was done in September, but the blake3 and b3sum crates were published in January. The blake3 crate relies on std to detect AVX-512 support, but the actual AVX-512 implementation code is in C or assembly. Also the scavenger crate I mentioned above hides its use of AVX-512 detection behind its simd feature, so I don't think crater would've caught it.

@Mark-Simulacrum
Copy link
Member

Seems like there was no discussion done of whether this would break folks (or at least I can't find it). Clearly this is "permitted" under a strict interpretation of our stability rules, though is not documented on the macro at all; the docs list avx512f with no warning that it is unstable. That at least sounds like a bug.

I guess someone (libs team?) needs to make a call on whether this is a bug, and whether we should fix it.

@Amanieu
Copy link
Member

Amanieu commented Feb 17, 2020

Considering that this broke two crates on stable, I think we should just go ahead and stabilize the avx512 features. I don't think there is any particular reason for holding back on them.

@pnkfelix
Copy link
Member

(nominating to try to ensure T-libs resolves this in some manner before this hits stable.)

@sfackler
Copy link
Member

Even if we don't want to stabilize the intrinsics themselves for whatever reason, it seems fine to allow detection of avx512 support via the macro.

@Mark-Simulacrum
Copy link
Member

Could someone on T-libs fcp a stabilization for the following x86 features, which have been destabilized in nightly:

  • mmx
  • sse4a
  • avx512f
  • avx512cd
  • avx512er
  • avx512pf
  • avx512bw
  • avx512dq
  • avx512vl
  • avx512ifma
  • avx512vbmi
  • avx512vpopcntdq
  • tbm

https://doc.rust-lang.org/nightly/std/macro.is_x86_feature_detected.html#supported-arguments

Once we get the ball rolling on that, I can work on trying to fix whatever the root cause of this destabilization is.

@Mark-Simulacrum
Copy link
Member

(Or, if we don't want to stabilize all of them, and want to say "oh well breaking change", then that would be helpful too).

@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Feb 20, 2020
@Amanieu
Copy link
Member

Amanieu commented Feb 20, 2020

Also see #60109: there was an approved FCP to stabilize adx, tbm and sse4a but it got closed because the PR author was inactive.

@Amanieu
Copy link
Member

Amanieu commented Feb 25, 2020

According to rust-lang/stdarch#310, it seems that a lot of AVX512 intrinsics are missing from std::arch. As such I don't think it really makes sense to stabilize the AVX512 feature.

I think the best approach would be to stabilize avx512 only for is_x86_feature_detected, since it was already (accidentally) stable and code is relying on it.

Any thoughts @rust-lang/libs @gnzlbg? I will write up a PR for stdarch if there are no objections.

@BurntSushi
Copy link
Member

It seems to me that stabilizing avx512 just as a parameter to is_x86_feature_detected should be fine? As in, I don't think there's any hazard of us never stabilizing it.

I'd be more skeptical of blanket stabilizing a bunch of parameters to is_x86_feature_detected though. For example, we might want to never stabilize anything to do with mmx.

it seems that a lot of AVX512 intrinsics are missing from std::arch. As such I don't think it really makes sense to stabilize the AVX512 feature.

Definitely agree here.

@pnkfelix
Copy link
Member

pnkfelix commented Mar 4, 2020

triage: After spending a while explaining this bug to @spastorino , I figured I should take the plunge and mark this as P-high.

(I'm not 100% sure if it is a release blocker per se, but my interpretation of the comments above is that we would prefer to either land a fix for this before beta is cut or, failing that, prioritize a backport to the beta branch, so that the bug itself never hits stable.)

@pnkfelix pnkfelix added the P-high High priority label Mar 4, 2020
@Amanieu
Copy link
Member

Amanieu commented Mar 5, 2020

OK, let's try to make some progress on this. I'd like to propose stabilizing the following features for feature detection only:

  • mmx
  • sse4a
  • tbm
  • avx512f
  • avx512cd
  • avx512er
  • avx512pf
  • avx512bw
  • avx512dq
  • avx512vl

The SSE4a and TBM features were already scheduled to be stabilized in #60109, but the PR got abandoned. Only a subset of the AVX512 features are listed here because there is some uncertainty with the newer ones as to whether they should contain an underscore: avx512vbmi vs avx512_vbmi. Finally MMX, while not supported by LLVM, is a well known feature name.

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Mar 5, 2020

Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Mar 5, 2020
@oconnor663
Copy link
Contributor Author

rust-lang/stdarch#842 is now up to speed with @Amanieu's proposal above.

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Mar 12, 2020
@rfcbot
Copy link

rfcbot commented Mar 12, 2020

🔔 This is now entering its final comment period, as per the review above. 🔔

@oconnor663
Copy link
Contributor Author

As of the 1.42 release today, cargo +beta install b3sum is failing. This fix will need to be backported.

@oconnor663 oconnor663 changed the title is_x86_feature_detected!("avx512f") fails to build on nightly is_x86_feature_detected!("avx512f") fails to build on beta and nightly Mar 16, 2020
@spastorino
Copy link
Member

@rustbot assign @Amanieu

@rustbot rustbot assigned Amanieu and unassigned Amanieu Mar 19, 2020
Amanieu pushed a commit to rust-lang/stdarch that referenced this issue Mar 19, 2020
…#842)

* re-stabilize the AVX-512 features that were stabilized in Rust 1.27.0

#739 added per-feature
stabilization of runtime CPU feature detection. In so doing, it
de-stabilized some detection features that had been stable since Rust
1.27.0, breaking some published crates (on nightly). This commit
re-stabilizes the subset of AVX-512 detection features that were
included in 1.27.0 (that is, the pre-Ice-Lake subset). Other instruction
sets (MMX in particular) remain de-stabilized, pending a decision about
whether should ever stabilize them.

See rust-lang/rust#68905.

* add a comment explaining feature detection stability

* adjust stabilizations to match most recent proposal

rust-lang/rust#68905 (comment)
@Amanieu
Copy link
Member

Amanieu commented Mar 19, 2020

PR to update the submodule is here: #70151

It will need to be backported to beta.

@bors bors closed this as completed in 744bcc6 Mar 21, 2020
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Mar 22, 2020
oconnor663 added a commit to oconnor663/blake3-py that referenced this issue Mar 23, 2020
rust-lang/rust#68905 is fixed as of
rustc 1.44.0-nightly (38114ff16 2020-03-21).

Closes #3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.