-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Add intrinsic for launch-sized workgroup memory on GPUs #146181
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -298,10 +298,12 @@ extern "C" LLVMValueRef LLVMRustGetOrInsertFunction(LLVMModuleRef M, | |
| .getCallee()); | ||
| } | ||
|
|
||
| extern "C" LLVMValueRef LLVMRustGetOrInsertGlobal(LLVMModuleRef M, | ||
| const char *Name, | ||
| size_t NameLen, | ||
| LLVMTypeRef Ty) { | ||
| // Get the global variable with the given name if it exists or create a new | ||
| // external global. | ||
| extern "C" LLVMValueRef | ||
| LLVMRustGetOrInsertGlobalInAddrspace(LLVMModuleRef M, const char *Name, | ||
|
Comment on lines
+303
to
+304
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this function will always create a specifically-extern global, can we document that here? The name is whatever, to me.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I added a comment for that (it already did that before my change, I only added the addrspace argument) |
||
| size_t NameLen, LLVMTypeRef Ty, | ||
| unsigned int AddressSpace) { | ||
| Module *Mod = unwrap(M); | ||
| auto NameRef = StringRef(Name, NameLen); | ||
|
|
||
|
|
@@ -312,10 +314,24 @@ extern "C" LLVMValueRef LLVMRustGetOrInsertGlobal(LLVMModuleRef M, | |
| GlobalVariable *GV = Mod->getGlobalVariable(NameRef, true); | ||
| if (!GV) | ||
| GV = new GlobalVariable(*Mod, unwrap(Ty), false, | ||
| GlobalValue::ExternalLinkage, nullptr, NameRef); | ||
| GlobalValue::ExternalLinkage, nullptr, NameRef, | ||
| nullptr, GlobalValue::NotThreadLocal, AddressSpace); | ||
| return wrap(GV); | ||
| } | ||
|
|
||
| // Get the global variable with the given name if it exists or create a new | ||
| // external global. | ||
| extern "C" LLVMValueRef LLVMRustGetOrInsertGlobal(LLVMModuleRef M, | ||
| const char *Name, | ||
| size_t NameLen, | ||
| LLVMTypeRef Ty) { | ||
| Module *Mod = unwrap(M); | ||
| unsigned int AddressSpace = | ||
| Mod->getDataLayout().getDefaultGlobalsAddressSpace(); | ||
| return LLVMRustGetOrInsertGlobalInAddrspace(M, Name, NameLen, Ty, | ||
| AddressSpace); | ||
| } | ||
|
|
||
| // Must match the layout of `rustc_codegen_llvm::llvm::ffi::AttributeKind`. | ||
| enum class LLVMRustAttributeKind { | ||
| AlwaysInline = 0, | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At first I kind of wanted there to be another test that does the cross-crate version of this. Then I remembered what was discussed elsewhere: that the targets in question are pure LLVM bitcode that gets mashed together anyways, so I am not sure it would actually benefit us, and it would probably involve a ton of tedium with run-make, having considered it in more detail. So, meh. Basically only leaving this note here to remind myself that if this turns out to go awry in the future, I can update in the direction of following this kind of instinct more often. :^) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Checks that the GPU intrinsic to get launch-sized workgroup memory works | ||
| // and correctly aligns the `external addrspace(...) global`s over multiple calls. | ||
|
|
||
| //@ revisions: amdgpu nvptx | ||
| //@ compile-flags: --crate-type=rlib -Copt-level=1 | ||
| // | ||
| //@ [amdgpu] compile-flags: --target amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 | ||
| //@ [amdgpu] needs-llvm-components: amdgpu | ||
| //@ [nvptx] compile-flags: --target nvptx64-nvidia-cuda | ||
| //@ [nvptx] needs-llvm-components: nvptx | ||
| //@ add-minicore | ||
| #![feature(intrinsics, no_core, rustc_attrs)] | ||
| #![no_core] | ||
|
|
||
| extern crate minicore; | ||
|
|
||
| #[rustc_intrinsic] | ||
| #[rustc_nounwind] | ||
| fn gpu_launch_sized_workgroup_mem<T>() -> *mut T; | ||
|
|
||
| // amdgpu-DAG: @[[SMALL:[^ ]+]] = external addrspace(3) global [0 x i8], align 4 | ||
| // amdgpu-DAG: @[[BIG:[^ ]+]] = external addrspace(3) global [0 x i8], align 8 | ||
| // amdgpu: ret { ptr, ptr } { ptr addrspacecast (ptr addrspace(3) @[[SMALL]] to ptr), ptr addrspacecast (ptr addrspace(3) @[[BIG]] to ptr) } | ||
|
|
||
| // nvptx: @[[BIG:[^ ]+]] = external addrspace(3) global [0 x i8], align 8 | ||
| // nvptx: ret { ptr, ptr } { ptr addrspacecast (ptr addrspace(3) @[[BIG]] to ptr), ptr addrspacecast (ptr addrspace(3) @[[BIG]] to ptr) } | ||
| #[unsafe(no_mangle)] | ||
| pub fn fun() -> (*mut i32, *mut f64) { | ||
| let small = gpu_launch_sized_workgroup_mem::<i32>(); | ||
| let big = gpu_launch_sized_workgroup_mem::<f64>(); // Increase alignment to 8 | ||
| (small, big) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.