-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[Target][AMDGPU] Fix TSan error on AMDGPU Target. #79529
Merged
MaheshRavishankar
merged 2 commits into
llvm:main
from
MaheshRavishankar:amdgpu_tsan_fix
Jan 26, 2024
Merged
[Target][AMDGPU] Fix TSan error on AMDGPU Target. #79529
MaheshRavishankar
merged 2 commits into
llvm:main
from
MaheshRavishankar:amdgpu_tsan_fix
Jan 26, 2024
Conversation
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
@llvm/pr-subscribers-backend-amdgpu Author: None (MaheshRavishankar) ChangesUpdating the value of the global flag within the code was flagged as a TSAN error. Fixing that. Full diff: https://github.com/llvm/llvm-project/pull/79529.diff 2 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp b/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
index 0c759e7f3b0957e..317a5bb7462a8bb 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
@@ -46,12 +46,12 @@ char &llvm::AMDGPUResourceUsageAnalysisID = AMDGPUResourceUsageAnalysis::ID;
// In code object v4 and older, we need to tell the runtime some amount ahead of
// time if we don't know the true stack size. Assume a smaller number if this is
// only due to dynamic / non-entry block allocas.
-static cl::opt<uint32_t> AssumedStackSizeForExternalCall(
+static cl::opt<uint32_t> clAssumedStackSizeForExternalCall(
"amdgpu-assume-external-call-stack-size",
cl::desc("Assumed stack use of any external call (in bytes)"), cl::Hidden,
cl::init(16384));
-static cl::opt<uint32_t> AssumedStackSizeForDynamicSizeObjects(
+static cl::opt<uint32_t> clAssumedStackSizeForDynamicSizeObjects(
"amdgpu-assume-dynamic-stack-object-size",
cl::desc("Assumed extra stack use if there are any "
"variable sized objects (in bytes)"),
@@ -112,11 +112,15 @@ bool AMDGPUResourceUsageAnalysis::runOnModule(Module &M) {
// By default, for code object v5 and later, track only the minimum scratch
// size
+ uint32_t AssumedStackSizeForDynamicSizeObjects =
+ clAssumedStackSizeForDynamicSizeObjects.getDefault().getValue();
+ uint32_t AssumedStackSizeForExternalCall =
+ clAssumedStackSizeForExternalCall.getDefault().getValue();
if (AMDGPU::getAMDHSACodeObjectVersion(M) >= AMDGPU::AMDHSA_COV5 ||
STI.getTargetTriple().getOS() == Triple::AMDPAL) {
- if (!AssumedStackSizeForDynamicSizeObjects.getNumOccurrences())
+ if (!clAssumedStackSizeForDynamicSizeObjects.getNumOccurrences())
AssumedStackSizeForDynamicSizeObjects = 0;
- if (!AssumedStackSizeForExternalCall.getNumOccurrences())
+ if (!clAssumedStackSizeForExternalCall.getNumOccurrences())
AssumedStackSizeForExternalCall = 0;
}
@@ -132,7 +136,8 @@ bool AMDGPUResourceUsageAnalysis::runOnModule(Module &M) {
CallGraphResourceInfo.insert(std::pair(F, SIFunctionResourceInfo()));
SIFunctionResourceInfo &Info = CI.first->second;
assert(CI.second && "should only be called once per function");
- Info = analyzeResourceUsage(*MF, TM);
+ Info = analyzeResourceUsage(*MF, TM, AssumedStackSizeForDynamicSizeObjects,
+ AssumedStackSizeForExternalCall);
HasIndirectCall |= Info.HasIndirectCall;
}
@@ -152,7 +157,8 @@ bool AMDGPUResourceUsageAnalysis::runOnModule(Module &M) {
SIFunctionResourceInfo &Info = CI.first->second;
MachineFunction *MF = MMI.getMachineFunction(*F);
assert(MF && "function must have been generated already");
- Info = analyzeResourceUsage(*MF, TM);
+ Info = analyzeResourceUsage(*MF, TM, AssumedStackSizeForDynamicSizeObjects,
+ AssumedStackSizeForExternalCall);
HasIndirectCall |= Info.HasIndirectCall;
}
@@ -164,7 +170,9 @@ bool AMDGPUResourceUsageAnalysis::runOnModule(Module &M) {
AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo
AMDGPUResourceUsageAnalysis::analyzeResourceUsage(
- const MachineFunction &MF, const TargetMachine &TM) const {
+ const MachineFunction &MF, const TargetMachine &TM,
+ uint32_t AssumedStackSizeForDynamicSizeObjects,
+ uint32_t AssumedStackSizeForExternalCall) const {
SIFunctionResourceInfo Info;
const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
@@ -541,9 +549,9 @@ AMDGPUResourceUsageAnalysis::analyzeResourceUsage(
// directly call the tail called function. If a kernel directly
// calls a tail recursive function, we'll assume maximum stack size
// based on the regular call instruction.
- CalleeFrameSize =
- std::max(CalleeFrameSize,
- static_cast<uint64_t>(AssumedStackSizeForExternalCall));
+ CalleeFrameSize = std::max(
+ CalleeFrameSize,
+ static_cast<uint64_t>(AssumedStackSizeForExternalCall));
}
}
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.h b/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.h
index df0789e471c16a5..93b5c3ce71e517d 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.h
@@ -73,7 +73,9 @@ struct AMDGPUResourceUsageAnalysis : public ModulePass {
private:
SIFunctionResourceInfo analyzeResourceUsage(const MachineFunction &MF,
- const TargetMachine &TM) const;
+ const TargetMachine &TM,
+ uint32_t AssumedStackSizeForDynamicSizeObjects,
+ uint32_t AssumedStackSizeForExternalCall) const;
void propagateIndirectCallRegisterUsage();
DenseMap<const Function *, SIFunctionResourceInfo> CallGraphResourceInfo;
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
MaheshRavishankar
force-pushed
the
amdgpu_tsan_fix
branch
from
January 26, 2024 00:40
8431f3a
to
e066308
Compare
kuhar
reviewed
Jan 26, 2024
Updating the value of the global flag within the code was flagged as a TSAN error. Fixing that.
MaheshRavishankar
force-pushed
the
amdgpu_tsan_fix
branch
from
January 26, 2024 01:05
e066308
to
2f8c098
Compare
kuhar
approved these changes
Jan 26, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Updating the value of the global flag within the code was flagged as a TSAN error. Fixing that.