[flang-commits] [flang] [flang][cuda] Avoid to issue data transfer in device context (PR #90247)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Fri Apr 26 11:49:49 PDT 2024


================
@@ -3807,16 +3807,30 @@ class FirConverter : public Fortran::lower::AbstractConverter {
     return temps;
   }
 
+  static bool isDeviceContext(fir::FirOpBuilder &builder) {
+    if (builder.getRegion().getParentOfType<fir::CUDAKernelOp>())
+      return true;
+    if (auto funcOp =
+            builder.getRegion().getParentOfType<mlir::func::FuncOp>()) {
+      if (auto cudaProcAttr =
+              funcOp.getOperation()->getAttrOfType<fir::CUDAProcAttributeAttr>(
+                  fir::getCUDAAttrName())) {
+        return cudaProcAttr.getValue() != fir::CUDAProcAttribute::Host;
----------------
vzakhari wrote:

Can you please clarify what will happen for a `host,device` function?  It seems that we will treat it as "device context", and will not generate the data transfer operation.

I suppose there will have to be a pass that creates distinct host and device copies of the `host,device` function, and so we should be able to handle `fir.cuda_data_transfer` during the cloning. So should we still generate `fir.cuda_data_transfer` for "maybe host context" cases?

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


More information about the flang-commits mailing list