Repository navigation
Conversation
This comment has been minimized.
This comment has been minimized.
7b7a043 to
abd0003
Compare
This comment has been minimized.
This comment has been minimized.
abd0003 to
8ec03af
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot reroll |
|
Can approve after rebasing |
8ec03af to
ada34f5
Compare
|
Target features are being changed; ensure all ABI effects are being accounted for cc @RalfJung |
This comment has been minimized.
This comment has been minimized.
| } | ||
| } | ||
|
|
||
| pub fn additional_features_for_cpu(&self, cpu: &str) -> &'static [&'static str] { |
There was a problem hiding this comment.
Thanks for moving this logic into a more suitable place.
Please add a doc comment explaining the point of this function and what it should be used for.
It is still surprising and concerning to me that we need this at all. We have usually relied on LLVM to convert target-cpu into target-features. Why does LLVM not do this any more?
There was a problem hiding this comment.
Ideally, we could just add ptx70 to NVPTX' default features as this is the minimum required PTX version by Rust.
However, starting from LLVM 22 this would result in LLVM errors, if the SM version requires a higher PTX version and the user does not enable a compliant one explicitely.
The logic here should prevent these errors for LLVM 22, 23 and the current LLVM main branch.
For reference:
Between LLVM 22 and the current LLVM main branch, NVPTX' subtarget feature handling underwent some changes. For example, in LLVM 22 and 23, if no PTX subtarget feature is enabled explicitely, LLVM would just emit PTX using the minimum required PTX version by the SM version. However, it would not imply the corresponding PTX subtarget feature.
In the current LLVM main branch on the other hand, the corresponding PTX subtarget feature is implied by LLVM. But LLVM would still error if the highest explicitely enabled PTX subtarget feature would not be compliant to the SM version.
Additionally, in the current LLVM main branch higher PTX subtarget features imply lower ones. So
ptx91 implies ptx90 and so on.
There was a problem hiding this comment.
In the current LLVM main branch on the other hand, the corresponding PTX subtarget feature is implied by LLVM.
That sounds reasonable. So this function here that manually implements "sm_X target-cpu implies ptxY target-feature" can be removed once we require LLVM 24?
But LLVM would still error if the highest explicitely enabled PTX subtarget feature would not be compliant to the SM version.
So the PTX subtarget feature is implied but also it's not implied and we have to still enable it manually? 😵
| ("sm_20", InternalOnly { reason: "unsupported compute capability", hard_error: true }, &[]), | ||
| ("sm_21", InternalOnly { reason: "unsupported compute capability", hard_error: true }, &[]), | ||
| ("sm_30", InternalOnly { reason: "unsupported compute capability", hard_error: true }, &[]), | ||
| ("sm_32", InternalOnly { reason: "unsupported compute capability", hard_error: true }, &[]), | ||
| ("sm_35", InternalOnly { reason: "unsupported compute capability", hard_error: true }, &[]), | ||
| ("sm_37", InternalOnly { reason: "unsupported compute capability", hard_error: true }, &[]), | ||
| ("sm_50", InternalOnly { reason: "unsupported compute capability", hard_error: true }, &[]), | ||
| ("sm_52", InternalOnly { reason: "unsupported compute capability", hard_error: true }, &[]), | ||
| ("sm_53", InternalOnly { reason: "unsupported compute capability", hard_error: true }, &[]), | ||
| ("sm_60", InternalOnly { reason: "unsupported compute capability", hard_error: true }, &[]), | ||
| ("sm_61", InternalOnly { reason: "unsupported compute capability", hard_error: true }, &[]), | ||
| ("sm_62", InternalOnly { reason: "unsupported compute capability", hard_error: true }, &[]), |
There was a problem hiding this comment.
Can these be removed once we make unknown target features a hard error even on nightly? Or is there some other reason they must be listed here?
There was a problem hiding this comment.
Yes, if that is the case, these features can be removed.
There was a problem hiding this comment.
In that case please add a comment explaining that.
(Other InternalOnly features will remain because we really need to track them internally in the compiler.)
That 2nd example sounds to me like we should forbid the I don't understand the first example. |
That example is to my understanding a bug: llvm/llvm-project#202323
If a PTX file using PTX version 9.0 and later contains a |
So... some newer ptx declarations are incompatible with some older sm_ declarations? |
While setting On the ptx ISA side of the feature problem something like the flag described here would also need to be in place. I never got around to making an MCP, but I will do that next week. When disallowing them with Thanks a lot for removing my mess in codegen_ssa and thanks to Ralf for pointing it out. |
Previously, Rust did not explicitly enable a PTX version target-feature, because LLVM implied one from the selected CPU. Starting with LLVM 22, the NVPTX backend still infers the minimum required PTX version from the selected CPU when none is selected explicitly, but no longer reflects that version in the enabled subtarget features. As a result, cfg could miss the PTX version of the emitted PTX. Also, if a PTX version below the required minimum is selected explicitly, LLVM errors. We missed this because the corresponding NVPTX target-feature test was mistakenly disabled. To keep cfg evaluation consistent and avoid LLVM errors, always select an explicit PTX version: whichever is higher between - Rust's minimum required PTX version, and - the CPU's minimum required PTX version. Re-enable the NVPTX target-feature test and adapt it to Rust's minimum required PTX and sm versions. Forbid PTX and sm versions below Rust's minimum required versions by marking the corresponding target-features as `InternalOnly`. Add PTX and sm versions present in LLVM 22 or 23 but missing as Rust target-features.
ada34f5 to
74394da
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
If these things are not controlled via -Ctarget-feature then maybe they should use a different cfg. That would be a question for t-lang. But if necessary we can make them work as cfg-only, yeah.
|
|
I've rebased the PR and addressed the comments. From my perspective the PR should be mergable at this point. |
Previously, we did not explicitly enable a PTX version target-feature, because LLVM implied one from the selected CPU.
Starting with LLVM 22, the NVPTX backend still infers the minimum required PTX version from the selected CPU when none is selected explicitly, but no longer reflects that version in the enabled subtarget features. As a result, cfg could miss the PTX version of the emitted PTX. Also, if a PTX version below the required minimum is selected explicitly, LLVM errors.
We missed this because the corresponding NVPTX target-feature test was mistakenly disabled.
With this patch we always select a PTX version explicitly, whichever is higher between
The patch also re-enables the NVPTX target-feature test to catch such changes in the future.
It additionally forbids PTX and sm versions below Rust's minimum required versions by marking the corresponding target-features as
InternalOnly.Lastly it adds PTX and sm versions present in LLVM 22 or LLVM 23 but missing as Rust target-features.
This will not prevent all issues. In fact, the following combinations might still miscompile:
cc: @kjetilkjeka
r? @ZuseZ4
@rustbot label +O-NVPTX