-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
AMDGPU: Propagate amdgpu-max-num-workgroups attribute #113018
Open
arsenm
wants to merge
4
commits into
users/arsenm/amdgpu-default-val-amdgpu-max-num-workgroups
Choose a base branch
from
users/arsenm/amdgpu-attributor-propagate-amdgpu-max-num-workgroups
base: users/arsenm/amdgpu-default-val-amdgpu-max-num-workgroups
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.
+392
−2
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
|
@@ -179,6 +179,11 @@ class AMDGPUInformationCache : public InformationCache { | |
return {ST.getMinFlatWorkGroupSize(), ST.getMaxFlatWorkGroupSize()}; | ||
} | ||
|
||
SmallVector<unsigned> getMaxNumWorkGroups(const Function &F) { | ||
const GCNSubtarget &ST = TM.getSubtarget<GCNSubtarget>(F); | ||
return ST.getMaxNumWorkGroups(F); | ||
} | ||
|
||
/// Get code object version. | ||
unsigned getCodeObjectVersion() const { | ||
return CodeObjectVersion; | ||
|
@@ -821,6 +826,152 @@ AAAMDFlatWorkGroupSize::createForPosition(const IRPosition &IRP, | |
"AAAMDFlatWorkGroupSize is only valid for function position"); | ||
} | ||
|
||
struct TupleDecIntegerRangeState : public AbstractState { | ||
DecIntegerState<uint32_t> X, Y, Z; | ||
|
||
bool isValidState() const override { | ||
return X.isValidState() && Y.isValidState() && Z.isValidState(); | ||
} | ||
|
||
bool isAtFixpoint() const override { | ||
return X.isAtFixpoint() && Y.isAtFixpoint() && Z.isAtFixpoint(); | ||
} | ||
|
||
ChangeStatus indicateOptimisticFixpoint() override { | ||
return X.indicateOptimisticFixpoint() | Y.indicateOptimisticFixpoint() | | ||
Z.indicateOptimisticFixpoint(); | ||
} | ||
|
||
ChangeStatus indicatePessimisticFixpoint() override { | ||
return X.indicatePessimisticFixpoint() | Y.indicatePessimisticFixpoint() | | ||
Z.indicatePessimisticFixpoint(); | ||
} | ||
|
||
TupleDecIntegerRangeState operator^=(const TupleDecIntegerRangeState &Other) { | ||
X ^= Other.X; | ||
Y ^= Other.Y; | ||
Z ^= Other.Z; | ||
return *this; | ||
} | ||
|
||
bool operator==(const TupleDecIntegerRangeState &Other) const { | ||
return X == Other.X && Y == Other.Y && Z == Other.Z; | ||
} | ||
|
||
TupleDecIntegerRangeState &getAssumed() { return *this; } | ||
const TupleDecIntegerRangeState &getAssumed() const { return *this; } | ||
}; | ||
|
||
using AAAMDMaxNumWorkgroupsState = | ||
StateWrapper<TupleDecIntegerRangeState, AbstractAttribute, uint32_t>; | ||
|
||
/// Propagate amdgpu-max-num-workgroups attribute. | ||
struct AAAMDMaxNumWorkgroups | ||
: public StateWrapper<TupleDecIntegerRangeState, AbstractAttribute> { | ||
using Base = StateWrapper<TupleDecIntegerRangeState, AbstractAttribute>; | ||
|
||
AAAMDMaxNumWorkgroups(const IRPosition &IRP, Attributor &A) : Base(IRP) {} | ||
|
||
void initialize(Attributor &A) override { | ||
Function *F = getAssociatedFunction(); | ||
auto &InfoCache = static_cast<AMDGPUInformationCache &>(A.getInfoCache()); | ||
|
||
SmallVector<unsigned> MaxNumWorkgroups = InfoCache.getMaxNumWorkGroups(*F); | ||
|
||
// FIXME: What is the interpretation of 0? | ||
for (unsigned &Entry : MaxNumWorkgroups) { | ||
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. Do we even allow it? 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. There's no verifier check, and the default value returned is 0,0,0 if the attribute isn't present. So something is off |
||
if (Entry == 0) | ||
Entry = std::numeric_limits<uint32_t>::max(); | ||
} | ||
|
||
X.takeKnownMinimum(MaxNumWorkgroups[0]); | ||
Y.takeKnownMinimum(MaxNumWorkgroups[1]); | ||
Z.takeKnownMinimum(MaxNumWorkgroups[2]); | ||
|
||
if (AMDGPU::isEntryFunctionCC(F->getCallingConv())) | ||
indicatePessimisticFixpoint(); | ||
} | ||
|
||
ChangeStatus updateImpl(Attributor &A) override { | ||
ChangeStatus Change = ChangeStatus::UNCHANGED; | ||
|
||
auto CheckCallSite = [&](AbstractCallSite CS) { | ||
Function *Caller = CS.getInstruction()->getFunction(); | ||
LLVM_DEBUG(dbgs() << "[AAAMDMaxNumWorkgroups] Call " << Caller->getName() | ||
<< "->" << getAssociatedFunction()->getName() << '\n'); | ||
|
||
const auto *CallerInfo = A.getAAFor<AAAMDMaxNumWorkgroups>( | ||
*this, IRPosition::function(*Caller), DepClassTy::REQUIRED); | ||
if (!CallerInfo || !CallerInfo->isValidState()) | ||
return false; | ||
|
||
Change |= | ||
clampStateAndIndicateChange(this->getState(), CallerInfo->getState()); | ||
return true; | ||
}; | ||
|
||
bool AllCallSitesKnown = true; | ||
if (!A.checkForAllCallSites(CheckCallSite, *this, | ||
/*RequireAllCallSites=*/true, | ||
AllCallSitesKnown)) | ||
return indicatePessimisticFixpoint(); | ||
|
||
return Change; | ||
} | ||
|
||
/// Create an abstract attribute view for the position \p IRP. | ||
static AAAMDMaxNumWorkgroups &createForPosition(const IRPosition &IRP, | ||
Attributor &A); | ||
|
||
ChangeStatus manifest(Attributor &A) override { | ||
Function *F = getAssociatedFunction(); | ||
// TODO: Skip adding if worst case? | ||
LLVMContext &Ctx = F->getContext(); | ||
SmallString<32> Buffer; | ||
raw_svector_ostream OS(Buffer); | ||
OS << X.getAssumed() << ',' << Y.getAssumed() << ',' << Z.getAssumed(); | ||
|
||
// TODO: Should annotate loads of the group size for this to do anything | ||
// useful. | ||
return A.manifestAttrs( | ||
getIRPosition(), | ||
{Attribute::get(Ctx, "amdgpu-max-num-workgroups", OS.str())}, | ||
/* ForceReplace= */ true); | ||
} | ||
|
||
const std::string getName() const override { return "AAAMDMaxNumWorkgroups"; } | ||
|
||
const std::string getAsStr(Attributor *) const override { | ||
std::string Buffer = "AAAMDMaxNumWorkgroupsState["; | ||
raw_string_ostream OS(Buffer); | ||
OS << X.getAssumed() << ',' << Y.getAssumed() << ',' << Z.getAssumed() | ||
<< ']'; | ||
return OS.str(); | ||
} | ||
|
||
const char *getIdAddr() const override { return &ID; } | ||
|
||
/// This function should return true if the type of the \p AA is | ||
/// AAAMDMaxNumWorkgroups | ||
static bool classof(const AbstractAttribute *AA) { | ||
return (AA->getIdAddr() == &ID); | ||
} | ||
|
||
void trackStatistics() const override {} | ||
|
||
/// Unique ID (due to the unique address) | ||
static const char ID; | ||
}; | ||
|
||
const char AAAMDMaxNumWorkgroups::ID = 0; | ||
|
||
AAAMDMaxNumWorkgroups & | ||
AAAMDMaxNumWorkgroups::createForPosition(const IRPosition &IRP, Attributor &A) { | ||
if (IRP.getPositionKind() == IRPosition::IRP_FUNCTION) | ||
return *new (A.Allocator) AAAMDMaxNumWorkgroups(IRP, A); | ||
llvm_unreachable("AAAMDMaxNumWorkgroups is only valid for function position"); | ||
} | ||
|
||
/// Propagate amdgpu-waves-per-eu attribute. | ||
struct AAAMDWavesPerEU : public AAAMDSizeRangeAttribute { | ||
AAAMDWavesPerEU(const IRPosition &IRP, Attributor &A) | ||
|
@@ -1043,8 +1194,8 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM, | |
DenseSet<const char *> Allowed( | ||
{&AAAMDAttributes::ID, &AAUniformWorkGroupSize::ID, | ||
&AAPotentialValues::ID, &AAAMDFlatWorkGroupSize::ID, | ||
&AAAMDWavesPerEU::ID, &AAAMDGPUNoAGPR::ID, &AACallEdges::ID, | ||
&AAPointerInfo::ID, &AAPotentialConstantValues::ID, | ||
&AAAMDMaxNumWorkgroups::ID, &AAAMDWavesPerEU::ID, &AAAMDGPUNoAGPR::ID, | ||
&AACallEdges::ID, &AAPointerInfo::ID, &AAPotentialConstantValues::ID, | ||
&AAUnderlyingObjects::ID, &AAAddressSpace::ID, &AAIndirectCallInfo::ID, | ||
&AAInstanceInfo::ID}); | ||
|
||
|
@@ -1068,6 +1219,7 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM, | |
for (auto *F : Functions) { | ||
A.getOrCreateAAFor<AAAMDAttributes>(IRPosition::function(*F)); | ||
A.getOrCreateAAFor<AAUniformWorkGroupSize>(IRPosition::function(*F)); | ||
A.getOrCreateAAFor<AAAMDMaxNumWorkgroups>(IRPosition::function(*F)); | ||
A.getOrCreateAAFor<AAAMDGPUNoAGPR>(IRPosition::function(*F)); | ||
CallingConv::ID CC = F->getCallingConv(); | ||
if (!AMDGPU::isEntryFunctionCC(CC)) { | ||
|
Oops, something went wrong.
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.
This function might be generic enough to be put somewhere else if needed.
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.
This is attributor boilerplate like the other subtarget queries