[flang-commits] [flang] [flang][cuda] Call CUFGetDeviceAddress to get global device address from host address (PR #112989)

Renaud Kauffmann via flang-commits flang-commits at lists.llvm.org
Mon Oct 21 14:08: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:
----------------
Renaud-K wrote:

I will remove pinned. 
I was thinking that we would not be needing transfers to constants. But I guess, there could be transfers from them. I will add it. 

https://github.com/llvm/llvm-project/pull/112989


More information about the flang-commits mailing list