-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Add amdgpu_dispatch_ptr intrinsic #150607
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
Open
Flakebi
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
Flakebi:dispatch-ptr-intrinsic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+61
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -454,6 +454,7 @@ symbols! { | |
| alu32, | ||
| always, | ||
| amdgpu, | ||
| amdgpu_dispatch_ptr, | ||
| analysis, | ||
| and, | ||
| and_then, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //! Intrinsics for GPU targets. | ||
| //! | ||
| //! Intrinsics in this module are intended for use on GPU targets. | ||
| //! They can be target specific but in general GPU targets are similar. | ||
| #![unstable(feature = "gpu_intrinsics", issue = "none")] | ||
|
|
||
| /// Returns a pointer to the HSA kernel dispatch packet. | ||
| /// | ||
| /// A `gpu-kernel` on amdgpu is always launched through a kernel dispatch packet. | ||
| /// The dispatch packet contains the workgroup size, launch size and other data. | ||
| /// The content is defined by the [HSA Platform System Architecture Specification], | ||
| /// which is implemented e.g. in AMD's [hsa.h]. | ||
| /// The intrinsic returns a unit pointer so that rustc does not need to know the packet struct. | ||
| /// The pointer is valid for the whole lifetime of the program. | ||
| /// | ||
| /// [HSA Platform System Architecture Specification]: https://hsafoundation.com/wp-content/uploads/2021/02/HSA-SysArch-1.2.pdf | ||
| /// [hsa.h]: https://github.com/ROCm/rocm-systems/blob/rocm-7.1.0/projects/rocr-runtime/runtime/hsa-runtime/inc/hsa.h#L2959 | ||
| #[rustc_nounwind] | ||
| #[rustc_intrinsic] | ||
| #[cfg(target_arch = "amdgpu")] | ||
| #[must_use = "returns a pointer that does nothing unless used"] | ||
| pub fn amdgpu_dispatch_ptr() -> *const (); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,7 @@ use crate::{mem, ptr}; | |
|
|
||
| mod bounds; | ||
| pub mod fallback; | ||
| pub mod gpu; | ||
| pub mod mir; | ||
| pub mod simd; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Tests the amdgpu_dispatch_ptr intrinsic. | ||
|
|
||
| //@ compile-flags: --crate-type=rlib --target amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 | ||
| //@ needs-llvm-components: amdgpu | ||
| //@ add-minicore | ||
| #![feature(intrinsics, no_core, rustc_attrs)] | ||
| #![no_core] | ||
|
|
||
| extern crate minicore; | ||
|
|
||
| pub struct DispatchPacket { | ||
| pub header: u16, | ||
| pub setup: u16, | ||
| pub workgroup_size_x: u16, // and more | ||
| } | ||
|
|
||
| #[rustc_intrinsic] | ||
| #[rustc_nounwind] | ||
| fn amdgpu_dispatch_ptr() -> *const (); | ||
|
|
||
Flakebi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // CHECK-LABEL: @get_dispatch_data | ||
| // CHECK: %[[ORIG_PTR:[^ ]+]] = {{(tail )?}}call ptr addrspace(4) @llvm.amdgcn.dispatch.ptr() | ||
| // CHECK-NEXT: %[[PTR:[^ ]+]] = addrspacecast ptr addrspace(4) %[[ORIG_PTR]] to ptr | ||
| #[unsafe(no_mangle)] | ||
| pub fn get_dispatch_data() -> &'static DispatchPacket { | ||
| unsafe { &*(amdgpu_dispatch_ptr() as *const _) } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.