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

NVPTX: Avoid PassMode::Direct for args in C abi #117671

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kjetilkjeka
Copy link
Contributor

Fixes #117480

I must admit that I'm confused about PassMode altogether, is there a good sum-up threads for this anywhere? I'm especially confused about how "indirect" and "byval" goes together. To me it seems like "indirect" basically means "use a indirection through a pointer", while "byval" basically means "do not use indirection through a pointer".

The return used to keep PassMode::Direct for small aggregates. It turns out that make_indirect messes up the tests and one way to fix it is to keep PassMode::Direct for all aggregates. I have mostly seen this PassMode mentioned for args. Is it also a problem for returns? When experimenting with byval as an alternative i ran into this assert

I have added tests for the same kind of types that is already tested for the "ptx-kernel" abi. The tests cannot be enabled until something like #117458 is completed and merged.

CC: @RalfJung since you seem to be the expert on this and have already helped me out tremendously

CC: @RDambrosio016 in case this influence your work on rustc_codegen_nvvm

@rustbot label +O-NVPTX

@rustbot
Copy link
Collaborator

rustbot commented Nov 7, 2023

r? @compiler-errors

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 7, 2023
@kjetilkjeka
Copy link
Contributor Author

@rustbot label +O-NVPTX

@rustbot rustbot added the O-NVPTX Target: the NVPTX LLVM backend for running rust on GPUs, https://llvm.org/docs/NVPTXUsage.html label Nov 7, 2023
@RalfJung
Copy link
Member

RalfJung commented Nov 7, 2023

I must admit that I'm confused about PassMode altogether, is there a good sum-up threads for this anywhere?

Sadly, no. The best we have are the API docs. I improved them a bit recently, but we are still lacking some proper "big-picture" docs for this. largely this is because while the system was designed with some big-picture ideas ~5 years ago, those were not written down at the time and since then it's been hotfixed and patched without regard for a coherent story. The entire system needs an overhaul. See rust-lang/compiler-team#672: the compiler team accepted the proposal to overhaul this, but we're still looking for a volunteer to do the work.

CC: @RalfJung since you seem to be the expert on this and have already helped me out tremendously

😂 I knew nothing about this until around 3 months ago, and spent way too much time on it since.^^ I still don't feel like an expert, since all I know is reverse engineered from looking at parts of rustc. There are many things about ABI I do not know. But at this point I think I know at least how rustc deals with ABI, and I know some necessary (but not sufficient) conditions for ABI adjustments to make sense.

@RalfJung
Copy link
Member

RalfJung commented Nov 7, 2023

Sadly, for this PR, I can't really tell if it makes any sense. But if it helps fix the assertions and also still generates working code for your tests, then it's at least an improvement...

@bjorn3
Copy link
Member

bjorn3 commented Nov 8, 2023

I think you will want to use PassMode::Cast for aggregate types.

@kjetilkjeka
Copy link
Contributor Author

kjetilkjeka commented Nov 8, 2023

I did experiment with casting to Uniform with Reg size equal to alignment and size equal to size. This caused miscompilation when passing types like

#[repr(C)]
pub struct SingleU8 {
    f: u8,
}

The problem was that since it was passed as a single register of size 8bit it passed it like a primitive type u8 instead of an aggregate. In ptx these primitives are padded while aggregates are not.

@bjorn3
Copy link
Member

bjorn3 commented Nov 9, 2023

In ptx these primitives are padded while aggregates are not.

😱

@compiler-errors
Copy link
Member

Sorry, too busy to review this 😰

r? compiler

@rustbot rustbot assigned cjgillot and unassigned compiler-errors Nov 16, 2023
@cjgillot
Copy link
Contributor

r? compiler

@rustbot rustbot assigned davidtwco and unassigned cjgillot Nov 19, 2023
@bors
Copy link
Contributor

bors commented Nov 19, 2023

☔ The latest upstream changes (presumably #117500) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the delay in getting to this - we don't have an expert in NVPTX on the team, so I'll take a stab at reviewing this so it isn't stuck forever. It seems reasonable to me.

Does this mean that NVPTX can be re-enabled in tests/ui/abi/compatibility.rs now? If so, could you do that in this PR? Otherwise let me know and I'll approve this.

@kjetilkjeka
Copy link
Contributor Author

When rebasing there are unfortunately regressions on some of the tests related to returning structs. I will look into re-enabling the compatibility test when I have investigated these regressions.

If there's any silver lining I guess it is that it highlights the importance of #117458 and getting the nvptx tests up and running again in CI.

@RalfJung
Copy link
Member

RalfJung commented Dec 7, 2023

Does this mean that NVPTX can be re-enabled in tests/ui/abi/compatibility.rs now? If so, could you do that in this PR? Otherwise let me know and I'll approve this.

Yeah it should be re-enabled, otherwise the claim that it fixes the issue is not accurate.

@apiraino
Copy link
Contributor

Checking status of this PR. @kjetilkjeka is this PR waiting on #117458? Switching the review flag for a rebase, thanks.

@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 Jan 25, 2024
@kjetilkjeka
Copy link
Contributor Author

Yes, this is waiting for #117458

It turned out to be more difficult than anticipated to get correct. I will of course spend the time to figure it out, but when I manage to get it right I would hate for it to break again. Therefore I would love to wait until the nvptx tests are enabled in CI so I can write tests and be confident that things will keep working.

@apiraino apiraino added the S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. label Jan 30, 2024
@Dylan-DPC Dylan-DPC removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 17, 2024
@OwenTrokeBillard
Copy link

Is this still blocked now that #117458 is merged?

@apiraino
Copy link
Contributor

@kjetilkjeka when you have a sec. can you look at this patch again? Thanks

@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-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-NVPTX Target: the NVPTX LLVM backend for running rust on GPUs, https://llvm.org/docs/NVPTXUsage.html S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nvptx abi adjustment may keep PassMode::Direct for small aggregates in conv extern "C"