-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[Flang] Force lowering to Complex for AMDGPU #144927
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?
Conversation
Avoid libm when targeting AMDGPU as those symbols are not available on the device and we rely on MLIR complex operations to later map to OCML calls.
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.
Pull Request Overview
This PR implements a change to avoid using libm when targeting AMDGPU by forcing lowering to complex operations which later map to OCML calls.
- Add a new check to detect AMDGPU targets using fir::getTargetTriple().isAMDGCN().
- Bypass the invocation of the libm call when AMDGPU is detected.
Comments suppressed due to low confidence (1)
flang/lib/Optimizer/Builder/IntrinsicCall.cpp:1234
- [nitpick] Consider adding unit tests to validate the AMDGPU branch, ensuring that libm is correctly bypassed when targeting AMDGPU.
bool isAMDGPU = fir::getTargetTriple(builder.getModule()).isAMDGCN();
@llvm/pr-subscribers-flang-fir-hlfir Author: Akash Banerjee (TIFitis) ChangesAvoid libm when targeting AMDGPU as those symbols are not available on the device and we rely on MLIR complex operations to later map to OCML calls. PRs #144924 & #144926 add additional related support. Full diff: https://github.com/llvm/llvm-project/pull/144927.diff 1 Files Affected:
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 178b6770d6b53..2ca7f2784aab3 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -1228,8 +1228,11 @@ mlir::Value genComplexMathOp(fir::FirOpBuilder &builder, mlir::Location loc,
llvm::StringRef mathLibFuncName = mathOp.runtimeFunc;
if (!mathLibFuncName.empty()) {
// If we enabled MLIR complex or can use approximate operations, we should
- // NOT use libm.
- if (!forceMlirComplex && !canUseApprox) {
+ // NOT use libm. Avoid libm when targeting AMDGPU as those symbols are not
+ // available on the device and we rely on MLIR complex operations to
+ // later map to OCML calls.
+ bool isAMDGPU = fir::getTargetTriple(builder.getModule()).isAMDGCN();
+ if (!forceMlirComplex && !canUseApprox && !isAMDGPU) {
result = genLibCall(builder, loc, mathOp, mathLibFuncType, args);
LLVM_DEBUG(result.dump(); llvm::dbgs() << "\n");
return result;
|
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.
LGTM
Avoid libm when targeting AMDGPU as those symbols are not available on the device and we rely on MLIR complex operations to later map to OCML calls.
PRs #144924 & #144926 add additional related support.