-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[flang][cuda] Adapt ExternalNameConversion to work in gpu module #117039
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
Conversation
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
@llvm/pr-subscribers-flang-fir-hlfir Author: Valentin Clement (バレンタイン クレメン) (clementval) ChangesFull diff: https://github.com/llvm/llvm-project/pull/117039.diff 2 Files Affected:
diff --git a/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp b/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp
index 648628fd1c9af0..e5919120941fbd 100644
--- a/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp
+++ b/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp
@@ -12,6 +12,7 @@
#include "flang/Optimizer/Dialect/FIROpsSupport.h"
#include "flang/Optimizer/Support/InternalNames.h"
#include "flang/Optimizer/Transforms/Passes.h"
+#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/SymbolTable.h"
#include "mlir/Pass/Pass.h"
@@ -58,24 +59,36 @@ void ExternalNameConversionPass::runOnOperation() {
auto *context = &getContext();
llvm::DenseMap<mlir::StringAttr, mlir::FlatSymbolRefAttr> remappings;
+
+ auto renameFuncOrGlobalInModule = [&](mlir::Operation *module) {
+ for (auto &funcOrGlobal : module->getRegion(0).front()) {
+ if (llvm::isa<mlir::func::FuncOp>(funcOrGlobal) ||
+ llvm::isa<fir::GlobalOp>(funcOrGlobal)) {
+ auto symName = funcOrGlobal.getAttrOfType<mlir::StringAttr>(
+ mlir::SymbolTable::getSymbolAttrName());
+ auto deconstructedName = fir::NameUniquer::deconstruct(symName);
+ if (fir::NameUniquer::isExternalFacingUniquedName(deconstructedName)) {
+ auto newName =
+ mangleExternalName(deconstructedName, appendUnderscoreOpt);
+ auto newAttr = mlir::StringAttr::get(context, newName);
+ mlir::SymbolTable::setSymbolName(&funcOrGlobal, newAttr);
+ auto newSymRef = mlir::FlatSymbolRefAttr::get(newAttr);
+ remappings.try_emplace(symName, newSymRef);
+ if (llvm::isa<mlir::func::FuncOp>(funcOrGlobal))
+ funcOrGlobal.setAttr(fir::getInternalFuncNameAttrName(), symName);
+ }
+ }
+ }
+ };
+
// Update names of external Fortran functions and names of Common Block
// globals.
- for (auto &funcOrGlobal : op->getRegion(0).front()) {
- if (llvm::isa<mlir::func::FuncOp>(funcOrGlobal) ||
- llvm::isa<fir::GlobalOp>(funcOrGlobal)) {
- auto symName = funcOrGlobal.getAttrOfType<mlir::StringAttr>(
- mlir::SymbolTable::getSymbolAttrName());
- auto deconstructedName = fir::NameUniquer::deconstruct(symName);
- if (fir::NameUniquer::isExternalFacingUniquedName(deconstructedName)) {
- auto newName =
- mangleExternalName(deconstructedName, appendUnderscoreOpt);
- auto newAttr = mlir::StringAttr::get(context, newName);
- mlir::SymbolTable::setSymbolName(&funcOrGlobal, newAttr);
- auto newSymRef = mlir::FlatSymbolRefAttr::get(newAttr);
- remappings.try_emplace(symName, newSymRef);
- if (llvm::isa<mlir::func::FuncOp>(funcOrGlobal))
- funcOrGlobal.setAttr(fir::getInternalFuncNameAttrName(), symName);
- }
+ renameFuncOrGlobalInModule(op);
+
+ // Do the same in GPU modules.
+ if (auto mod = mlir::dyn_cast_or_null<mlir::ModuleOp>(*op)) {
+ for (auto gpuMod : mod.getOps<mlir::gpu::GPUModuleOp>()) {
+ renameFuncOrGlobalInModule(gpuMod);
}
}
diff --git a/flang/test/Fir/CUDA/cuda-extranal-mangling.mlir b/flang/test/Fir/CUDA/cuda-extranal-mangling.mlir
new file mode 100644
index 00000000000000..551a89a7018c28
--- /dev/null
+++ b/flang/test/Fir/CUDA/cuda-extranal-mangling.mlir
@@ -0,0 +1,13 @@
+// RUN: fir-opt --split-input-file --external-name-interop %s | FileCheck %s
+
+gpu.module @cuda_device_mod {
+ gpu.func @_QPfoo() {
+ fir.call @_QPthreadfence() fastmath<contract> : () -> ()
+ gpu.return
+ }
+ func.func private @_QPthreadfence() attributes {cuf.proc_attr = #cuf.cuda_proc<device>}
+}
+
+// CHECK-LABEL: gpu.func @_QPfoo
+// CHECK: fir.call @threadfence_()
+// CHECK: func.func private @threadfence_()
|
Renaud-K
reviewed
Nov 20, 2024
Renaud-K
approved these changes
Nov 20, 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.
No description provided.