Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4778,7 +4778,14 @@ class FirConverter : public Fortran::lower::AbstractConverter {
nbDeviceResidentObject <= 1 &&
"Only one reference to the device resident object is supported");
auto addr = getSymbolAddress(sym);
hlfir::Entity entity{addr};
mlir::Value baseValue;
if (auto declareOp =
llvm::dyn_cast<hlfir::DeclareOp>(addr.getDefiningOp()))
baseValue = declareOp.getBase();
else
baseValue = addr;

hlfir::Entity entity{baseValue};
auto [temp, cleanup] =
hlfir::createTempFromMold(loc, builder, entity);
auto needCleanup = fir::getIntIfConstant(cleanup);
Expand Down
27 changes: 27 additions & 0 deletions flang/test/Lower/CUDA/cuda-managed.cuf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s

subroutine testr2(N1,N2)
real(4), managed :: ai4(N1,N2)
real(4), allocatable :: bRefi4(:)

integer :: i1, i2

do i2 = 1, N2
do i1 = 1, N1
ai4(i1,i2) = i1 + N1*(i2-1)
enddo
enddo

allocate(bRefi4 (N1))
do i1 = 1, N1
bRefi4(i1) = (ai4(i1,1)+ai4(i1,N2))*N2/2
enddo
deallocate(bRefi4)

end subroutine

!CHECK-LABEL: func.func @_QPtestr2
!CHECK: %[[ALLOC:.*]] = cuf.alloc !fir.array<?x?xf32>, %{{.*}}, %{{.*}} : index, index {bindc_name = "ai4", data_attr = #cuf.cuda<managed>, uniq_name = "_QFtestr2Eai4"} -> !fir.ref<!fir.array<?x?xf32>>
!CHECK: %[[DECLARE:.*]]:2 = hlfir.declare %[[ALLOC]](%{{.*}}) {data_attr = #cuf.cuda<managed>, uniq_name = "_QFtestr2Eai4"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.ref<!fir.array<?x?xf32>>)
!CHECK: %[[DEST:.*]] = hlfir.designate %[[DECLARE]]#0 (%{{.*}}, %{{.*}}) : (!fir.box<!fir.array<?x?xf32>>, i64, i64) -> !fir.ref<f32>
!CHECK: cuf.data_transfer %{{.*}}#0 to %[[DEST]] {transfer_kind = #cuf.cuda_transfer<host_device>} : !fir.ref<f32>, !fir.ref<f32>
Loading