-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang][CodeGen][SPIRV] Translate amdgpu_flat_work_group_size into max_work_group_size.
#116820
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
Merged
AlexVlx
merged 6 commits into
llvm:main
from
AlexVlx:handle_flat_work_group_size_amdgcnspirv
Jan 7, 2025
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c5efdd2
Translate `amdgpu_flat_work_group_size` into `reqd_work_group_size`.
AlexVlx 4349def
Adapt test.
AlexVlx 2dd4456
Merge branch 'main' of https://github.com/llvm/llvm-project into hand…
AlexVlx 958d1cd
Switch to using `max_workgroup_size` which models expected semantics …
AlexVlx 27d5c6e
Merge branch 'main' of https://github.com/llvm/llvm-project into hand…
AlexVlx 59d057f
Merge branch 'main' of https://github.com/llvm/llvm-project into hand…
AlexVlx 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,8 @@ class SPIRVTargetCodeGenInfo : public CommonSPIRTargetCodeGenInfo { | |
| void setCUDAKernelCallingConvention(const FunctionType *&FT) const override; | ||
| LangAS getGlobalVarAddressSpace(CodeGenModule &CGM, | ||
| const VarDecl *D) const override; | ||
| void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, | ||
| CodeGen::CodeGenModule &M) const override; | ||
| llvm::SyncScope::ID getLLVMSyncScopeID(const LangOptions &LangOpts, | ||
| SyncScope Scope, | ||
| llvm::AtomicOrdering Ordering, | ||
|
|
@@ -245,6 +247,38 @@ SPIRVTargetCodeGenInfo::getGlobalVarAddressSpace(CodeGenModule &CGM, | |
| return DefaultGlobalAS; | ||
| } | ||
|
|
||
| void SPIRVTargetCodeGenInfo::setTargetAttributes( | ||
| const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const { | ||
| if (!M.getLangOpts().HIP || | ||
| M.getTarget().getTriple().getVendor() != llvm::Triple::AMD) | ||
| return; | ||
| if (GV->isDeclaration()) | ||
| return; | ||
|
|
||
| auto F = dyn_cast<llvm::Function>(GV); | ||
| if (!F) | ||
| return; | ||
|
Comment on lines
+258
to
+260
Contributor
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. Can this fail if the FunctionDecl below fails? |
||
|
|
||
| auto FD = dyn_cast_or_null<FunctionDecl>(D); | ||
| if (!FD) | ||
| return; | ||
| if (!FD->hasAttr<CUDAGlobalAttr>()) | ||
| return; | ||
|
|
||
| unsigned N = M.getLangOpts().GPUMaxThreadsPerBlock; | ||
| if (auto FlatWGS = FD->getAttr<AMDGPUFlatWorkGroupSizeAttr>()) | ||
| N = FlatWGS->getMax()->EvaluateKnownConstInt(M.getContext()).getExtValue(); | ||
|
|
||
| auto Int32Ty = llvm::IntegerType::getInt32Ty(M.getLLVMContext()); | ||
| llvm::Metadata *AttrMDArgs[] = { | ||
| llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, N)), | ||
| llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 1)), | ||
| llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 1))}; | ||
|
|
||
| F->setMetadata("reqd_work_group_size", | ||
| llvm::MDNode::get(M.getLLVMContext(), AttrMDArgs)); | ||
| } | ||
|
|
||
| llvm::SyncScope::ID | ||
| SPIRVTargetCodeGenInfo::getLLVMSyncScopeID(const LangOptions &, SyncScope Scope, | ||
| llvm::AtomicOrdering, | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the vendor check. The language check is also suspect, this is interpretation of a target attribute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not super suspect in context as at the moment this is only for AMDGCN flavoured SPIR-V, which we only support in HIP, and the mapping from flat to dim X only makes sense there.