[flang-commits] [flang] [flang][cuda] Make copy to managed variable on host (PR #174012)
via flang-commits
flang-commits at lists.llvm.org
Tue Dec 30 11:26:17 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Valentin Clement (バレンタイン クレメン) (clementval)
<details>
<summary>Changes</summary>
When the LHS has multiple symbols with the managed attribute, still perform the copy on the host.
---
Full diff: https://github.com/llvm/llvm-project/pull/174012.diff
2 Files Affected:
- (modified) flang/include/flang/Evaluate/tools.h (+3-3)
- (modified) flang/test/Lower/CUDA/cuda-data-transfer.cuf (+19)
``````````diff
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index 4248e3a5461f5..888e4bb89f1b2 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -1345,12 +1345,12 @@ inline bool IsCUDADataTransfer(const A &lhs, const B &rhs) {
int rhsNbManagedSymbols = {GetNbOfCUDAManagedOrUnifiedSymbols(rhs)};
int rhsNbSymbols{GetNbOfCUDADeviceSymbols(rhs)};
- // Special cases perforemd on the host:
+ // Special cases performed on the host:
// - Only managed or unifed symbols are involved on RHS and LHS.
// - LHS is managed or unified and the RHS is host only.
- if ((lhsNbManagedSymbols == 1 && rhsNbManagedSymbols == 1 &&
+ if ((lhsNbManagedSymbols >= 1 && rhsNbManagedSymbols == 1 &&
rhsNbSymbols == 1) ||
- (lhsNbManagedSymbols == 1 && rhsNbSymbols == 0)) {
+ (lhsNbManagedSymbols >= 1 && rhsNbSymbols == 0)) {
return false;
}
return HasCUDADeviceAttrs(lhs) || rhsNbSymbols > 0;
diff --git a/flang/test/Lower/CUDA/cuda-data-transfer.cuf b/flang/test/Lower/CUDA/cuda-data-transfer.cuf
index e0c23a1d5df8f..058e2506c1d53 100644
--- a/flang/test/Lower/CUDA/cuda-data-transfer.cuf
+++ b/flang/test/Lower/CUDA/cuda-data-transfer.cuf
@@ -11,6 +11,14 @@ module mod1
integer, device, allocatable, dimension(:) :: x
end type
+ type :: s
+ real :: c(3)
+ end type
+
+ type :: t3
+ type(s), managed, allocatable :: spheres(:)
+ end type
+
integer, device, dimension(11:20) :: cdev
real(kind=8), device, allocatable, dimension(:) :: p
@@ -569,3 +577,14 @@ end subroutine
! CHECK: %[[TMP_BUFFER:.*]]:2 = hlfir.declare %[[TMP]](%{{.*}}) {uniq_name = ".tmp"} : (!fir.heap<!fir.array<?xf16>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf16>>, !fir.heap<!fir.array<?xf16>>)
! CHECK: cuf.data_transfer %{{.*}} to %[[TMP_BUFFER]]#0 {transfer_kind = #cuf.cuda_transfer<device_host>} : !fir.box<!fir.heap<!fir.array<?xf16>>>, !fir.box<!fir.array<?xf16>>
! CHECK: hlfir.elemental
+
+subroutine sub30()
+ use mod1
+ type(t3), managed :: t
+ t%spheres(1) = s([0.0, 0.0, -1.0])
+end subroutine
+
+! CHECK-LABEL: func.func @_QPsub30()
+! CHECK: %{{.*}} = cuf.alloc !fir.type<_QMmod1Tt3{spheres:!fir.box<!fir.heap<!fir.array<?x!fir.type<_QMmod1Ts{c:!fir.array<3xf32>}>>>>}> {bindc_name = "t", data_attr = #cuf.cuda<managed>, uniq_name = "_QFsub30Et"} -> !fir.ref<!fir.type<_QMmod1Tt3{spheres:!fir.box<!fir.heap<!fir.array<?x!fir.type<_QMmod1Ts{c:!fir.array<3xf32>}>>>>}>>
+! CHECK: hlfir.assign
+! CHECK-NOT: cuf.data_transfer
``````````
</details>
https://github.com/llvm/llvm-project/pull/174012
More information about the flang-commits
mailing list