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

clarify simd_relaxed_fma non-determinism #133844

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Dec 4, 2024

This is the safer spec in the sense that it is more likely to be satisfied by the backend -- and if people are okay with a non-deterministic result, I assume they don't care whether it's the same choice across all lanes or not?

Cc @calebzulawski @workingjubilee

@rustbot
Copy link
Collaborator

rustbot commented Dec 4, 2024

r? @scottmcm

rustbot has assigned @scottmcm.
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 Dec 4, 2024
@rustbot
Copy link
Collaborator

rustbot commented Dec 4, 2024

Some changes occurred to the platform-builtins intrinsics. Make sure the
LLVM backend as well as portable-simd gets adapted for the changes.

cc @antoyo, @GuillaumeGomez, @bjorn3, @calebzulawski, @programmerjake

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @rust-lang/wg-const-eval

@RalfJung RalfJung force-pushed the simd_relaxed_fma-nondet branch from ffaef08 to f4217f4 Compare December 4, 2024 07:39
@workingjubilee
Copy link
Member

headscratch Hmm. That would be kinda weird? I see your point, but it's a bit odd.

@RalfJung
Copy link
Member Author

RalfJung commented Dec 4, 2024 via email

@workingjubilee
Copy link
Member

Hm.

Apparently the version implemented by wasm's "Relaxed SIMD" is actually quite strict, where the nondeterministic choice is quite early: WebAssembly/relaxed-simd@c3f9359

It's still valid to lower a lax semantic to a stricter one, however, so having given it some more thought, this seems fine. LLVM indeed does not specify!

I would never expect this to happen to a "natural" vector (pow2 elements, etc.) but I could definitely see it happening to a "packed" one... say, Simd<f32, 5>? A valid interpretation would be for operations to work as if decomposed to operating on the fields of this:

#[repr(packed(4))]
struct LoweredSimd {
    fvec: Simd<f32, 4>,
    single: f32,
}

Then perhaps the code generation uses a libcall to fmaf, or just an FMA instruction, for the single f32, but then operates on the fvec using plain mul, then add. And I don't see any use in specifying which float is the odd one out.

@bors r+

@bors
Copy link
Contributor

bors commented Dec 5, 2024

📌 Commit f4217f4 has been approved by workingjubilee

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 Dec 5, 2024
fmease added a commit to fmease/rust that referenced this pull request Dec 5, 2024
…r=workingjubilee

clarify simd_relaxed_fma non-determinism

This is the safer spec in the sense that it is more likely to be satisfied by the backend -- and if people are okay with a non-deterministic result, I assume they don't care whether it's the same choice across all lanes or not?

Cc `@calebzulawski` `@workingjubilee`
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 5, 2024
Rollup of 6 pull requests

Successful merges:

 - rust-lang#127565 (Teach rustc about the Xtensa VaListImpl)
 - rust-lang#133844 (clarify simd_relaxed_fma non-determinism)
 - rust-lang#133867 (Fix "std" support status of some tier 3 targets)
 - rust-lang#133882 (Improve comments for the default backtrace printer)
 - rust-lang#133888 (Improve bootstrap job objects)
 - rust-lang#133898 (skip `setup::Hook` on non-git sources)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 5, 2024
Rollup of 6 pull requests

Successful merges:

 - rust-lang#127565 (Teach rustc about the Xtensa VaListImpl)
 - rust-lang#133844 (clarify simd_relaxed_fma non-determinism)
 - rust-lang#133867 (Fix "std" support status of some tier 3 targets)
 - rust-lang#133882 (Improve comments for the default backtrace printer)
 - rust-lang#133888 (Improve bootstrap job objects)
 - rust-lang#133898 (skip `setup::Hook` on non-git sources)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f5f8a1f into rust-lang:master Dec 5, 2024
6 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Dec 5, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 5, 2024
Rollup merge of rust-lang#133844 - RalfJung:simd_relaxed_fma-nondet, r=workingjubilee

clarify simd_relaxed_fma non-determinism

This is the safer spec in the sense that it is more likely to be satisfied by the backend -- and if people are okay with a non-deterministic result, I assume they don't care whether it's the same choice across all lanes or not?

Cc ``@calebzulawski`` ``@workingjubilee``
@RalfJung RalfJung deleted the simd_relaxed_fma-nondet branch December 5, 2024 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants