Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
24 changes: 24 additions & 0 deletions flang/test/Lower/CUDA/cuda-managed.cuf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
! 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: %{{.*}} = 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>>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check the actual change?