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

Export kernel descriptor for amdgpu kernels #135909

Merged
merged 1 commit into from
Feb 16, 2025
Merged

Conversation

Flakebi
Copy link
Contributor

@Flakebi Flakebi commented Jan 23, 2025

The host runtime (HIP or HSA) expects a kernel descriptor object for each kernel in the ELF file. The amdgpu LLVM backend generates the object. It is created as a symbol with the name of the kernel plus a .kd suffix.

Add it to the exported symbols in the linker script, so that it can be found.

For reference, the symbol is created here in LLVM: https://github.com/llvm/llvm-project/blob/d5457e4c1619e5dbeefd49841e284cbc24d35cb4/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp#L966
I wrote a test for this as well, I’ll add that once the target is merged and working.
With this, all PRs to get working code for amdgpu are open (this + the target + the two patches adding addrspacecasts for alloca and global variables).

Tracking issue: #135024

r? @workingjubilee

@rustbot
Copy link
Collaborator

rustbot commented Jan 23, 2025

Could not assign reviewer from: workingjubilee.
User(s) workingjubilee are either the PR author, already assigned, or on vacation. Please use r? to specify someone else to assign.

@rustbot
Copy link
Collaborator

rustbot commented Jan 23, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
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-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 23, 2025
@Flakebi Flakebi mentioned this pull request Jan 23, 2025
21 tasks
@workingjubilee
Copy link
Member

workingjubilee commented Jan 24, 2025

I wonder if we should require pub or no_mangle or export_name or something.

I'm not sold on that tho'.

Well, in any case, can you add a comment about that? (or implement it, either one)

@workingjubilee
Copy link
Member

workingjubilee commented Jan 28, 2025

@rustbot label +S-waiting-on-author -S-waiting-on-review

@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 28, 2025
@Flakebi
Copy link
Contributor Author

Flakebi commented Jan 31, 2025

I wonder if we should require pub or no_mangle or export_name or something.

Requiring no_mangle or export_name for gpu-kernel functions sounds reasonable. (All ptx-kernel tests I found use no_mangle as well.) I added a TODO to the amdgpu tracking issue.
For some reason, pub alone does not export the function for me in the final ELF.

Independent of that, this PR needs a test once the target is merged.

@workingjubilee
Copy link
Member

cool.

@workingjubilee workingjubilee added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 5, 2025
@workingjubilee
Copy link
Member

blocked on #134740

@workingjubilee workingjubilee 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: Blocked on something else such as an RFC or other implementation work. labels Feb 10, 2025
@workingjubilee
Copy link
Member

Congratulations! It landed! Your reward is more toil. Alas, the futility of humankind. :^)

@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Feb 10, 2025
@Flakebi
Copy link
Contributor Author

Flakebi commented Feb 10, 2025

Hehe 😄 I added the test that I mentioned in the PR description (and forgot about before). Diff

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2025

This PR modifies tests/run-make/. If this PR is trying to port a Makefile
run-make test to use rmake.rs, please update the
run-make port tracking issue
so we can track our progress. You can either modify the tracking issue
directly, or you can comment on the tracking issue and link this PR.

cc @jieyouxu

@Flakebi
Copy link
Contributor Author

Flakebi commented Feb 10, 2025

Added a needs-rust-lld to the test. Diff

@jieyouxu jieyouxu self-assigned this Feb 10, 2025
Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

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

this is fine modulo a thing

@workingjubilee
Copy link
Member

And jieyouxu being happy ofc

@Flakebi
Copy link
Contributor Author

Flakebi commented Feb 10, 2025

Thanks for the quick review, I fixed both comments (diff)

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Tiny test nit, test LGTM otherwise

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

One test nit re. a bit more context then r=me on the test. You can also flip this PR to mark as ready-for-view via @rustbot ready.

The host runtime (HIP or HSA) expects a kernel descriptor object for
each kernel in the ELF file. The amdgpu LLVM backend generates the
object. It is created as a symbol with the name of the kernel plus a
`.kd` suffix.

Add it to the exported symbols in the linker script, so that it can be
found.
@Flakebi
Copy link
Contributor Author

Flakebi commented Feb 12, 2025

Expanded the comment in the test with the commit description. Diff

@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 Feb 12, 2025
@jieyouxu
Copy link
Member

@workingjubilee to double-check, are you happy w/ the current iteration of changes?

@workingjubilee
Copy link
Member

Yes.

@bors r=jieyouxu,workingjubilee

@bors
Copy link
Collaborator

bors commented Feb 15, 2025

📌 Commit 99ec64c has been approved by jieyouxu,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 Feb 15, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 16, 2025
Rollup of 5 pull requests

Successful merges:

 - rust-lang#135797 (Import initial generated 1.85 relnotes)
 - rust-lang#135909 (Export kernel descriptor for amdgpu kernels)
 - rust-lang#136545 (nvptx64: update default alignment to match LLVM 21)
 - rust-lang#137092 (abi_unsupported_vector_types: say which type is the problem)
 - rust-lang#137097 (Ignore Self in bounds check for associated types with Self:Sized)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 20004d4 into rust-lang:master Feb 16, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Feb 16, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 16, 2025
Rollup merge of rust-lang#135909 - Flakebi:amdgpu-kd, r=jieyouxu,workingjubilee

Export kernel descriptor for amdgpu kernels

The host runtime (HIP or HSA) expects a kernel descriptor object for each kernel in the ELF file. The amdgpu LLVM backend generates the object. It is created as a symbol with the name of the kernel plus a `.kd` suffix.

Add it to the exported symbols in the linker script, so that it can be found.

For reference, the symbol is created here in LLVM: https://github.com/llvm/llvm-project/blob/d5457e4c1619e5dbeefd49841e284cbc24d35cb4/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp#L966
I wrote [a test](Flakebi@6a9115b) for this as well, I’ll add that once the target is merged and working.
With this, all PRs to get working code for amdgpu are open (this + the target + the two patches adding addrspacecasts for alloca and global variables).

Tracking issue: rust-lang#135024

r? `@workingjubilee`
@Flakebi Flakebi deleted the amdgpu-kd branch February 16, 2025 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

7 participants