[flang-commits] [flang] [flang][cuda] Call CUFGetDeviceAddress to get global device address from host address (PR #112989)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Fri Oct 18 20:48:20 PDT 2024
================
@@ -77,6 +77,69 @@ static bool hasDoubleDescriptors(OpTy op) {
return false;
}
+static mlir::Value createConvertOp(mlir::PatternRewriter &rewriter,
+ mlir::Location loc, mlir::Type toTy,
+ mlir::Value val) {
+ if (val.getType() != toTy)
+ return rewriter.create<fir::ConvertOp>(loc, toTy, val);
+ return val;
+}
+
+mlir::Value getDeviceAddress(mlir::PatternRewriter &rewriter,
+ mlir::OpOperand &operand,
+ const mlir::SymbolTable &symtab) {
+ mlir::Value v = operand.get();
+ auto declareOp = v.getDefiningOp<fir::DeclareOp>();
+ if (!declareOp)
+ return v;
+
+ auto addrOfOp = declareOp.getMemref().getDefiningOp<fir::AddrOfOp>();
+ if (!addrOfOp)
+ return v;
+
+ auto globalOp = symtab.lookup<fir::GlobalOp>(
+ addrOfOp.getSymbol().getRootReference().getValue());
+
+ if (!globalOp)
+ return v;
+
+ bool isDevGlobal{false};
+ auto attr = globalOp.getDataAttrAttr();
+ if (attr) {
+ switch (attr.getValue()) {
+ case cuf::DataAttribute::Device:
+ case cuf::DataAttribute::Managed:
+ case cuf::DataAttribute::Pinned:
----------------
clementval wrote:
Pinned is host address so we probably want to remove it from here. What about Constant?
https://github.com/llvm/llvm-project/pull/112989
More information about the flang-commits
mailing list