From 2696e8c1499682f0b1f357d9035ed59f544892f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Clement=20=28=E3=83=90=E3=83=AC=E3=83=B3?= =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=B3=20=E3=82=AF=E3=83=AC=E3=83=A1?= =?UTF-8?q?=E3=83=B3=29?= Date: Wed, 6 Aug 2025 18:49:52 -0700 Subject: [PATCH] [flang][cuda] Remove too restrictive assert for data transfer (#152398) When the rhs is a an array element, the assert was triggered but this is still a valid transfer. Remove the assert. The operation has a verifier to check its validity. --- flang/lib/Lower/Bridge.cpp | 1 - flang/test/Lower/CUDA/cuda-data-transfer.cuf | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp index 6b7efe6b57db..a5f0beff9ec2 100644 --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -4898,7 +4898,6 @@ private: // device = device if (lhsIsDevice && rhsIsDevice) { - assert(rhs.isVariable() && "CUDA Fortran assignment rhs is not legal"); auto transferKindAttr = cuf::DataTransferKindAttr::get( builder.getContext(), cuf::DataTransferKind::DeviceDevice); cuf::DataTransferOp::create(builder, loc, rhsVal, lhsVal, shape, diff --git a/flang/test/Lower/CUDA/cuda-data-transfer.cuf b/flang/test/Lower/CUDA/cuda-data-transfer.cuf index 3a4aff977b7a..9abf19b77869 100644 --- a/flang/test/Lower/CUDA/cuda-data-transfer.cuf +++ b/flang/test/Lower/CUDA/cuda-data-transfer.cuf @@ -444,3 +444,15 @@ subroutine sub23(n) end subroutine ! CHECK-LABEL: func.func @_QPsub23 + +subroutine sub24() + real, managed :: m + real, device :: d(4) + m = d(1) +end + +! CHECK-LABEL: func.func @_QPsub24() +! CHECK: %[[D:.*]]:2 = hlfir.declare %1(%2) {data_attr = #cuf.cuda, uniq_name = "_QFsub24Ed"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) +! CHECK: %[[M:.*]]:2 = hlfir.declare %4 {data_attr = #cuf.cuda, uniq_name = "_QFsub24Em"} : (!fir.ref) -> (!fir.ref, !fir.ref) +! CHECK: %[[D1:.*]] = hlfir.designate %[[D]]#0 (%c1{{.*}}) : (!fir.ref>, index) -> !fir.ref +! CHECK: cuf.data_transfer %[[D1]] to %[[M]]#0 {transfer_kind = #cuf.cuda_transfer} : !fir.ref, !fir.ref