Skip to content

Commit e350485

Browse files
authored
[flang][cuda] Set alloca block in cuf kernel (#128776)
Temporary created during lowering in a cuf kernel must be set in the cuf kernel itself otherwise they will be allocated on the host.
1 parent f3000d7 commit e350485

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

flang/lib/Optimizer/Builder/FIRBuilder.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ mlir::Block *fir::FirOpBuilder::getAllocaBlock() {
276276
return recipeIface.getAllocaBlock(getRegion());
277277
}
278278

279+
if (auto cufKernelOp = getRegion().getParentOfType<cuf::KernelOp>())
280+
return &cufKernelOp.getRegion().front();
281+
279282
return getEntryBlock();
280283
}
281284

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
! RUN: bbc -emit-fir -hlfir -fcuda %s -o - | FileCheck %s
2+
3+
module char1
4+
5+
character*1, dimension(:), allocatable, device :: da, db
6+
7+
contains
8+
attributes(device) logical function check_char( c1, c2 )
9+
character*1, value :: c1, c2
10+
check_char = .false.
11+
if(c1 .eq. c2) check_char = .true.
12+
end function
13+
end module
14+
15+
program p
16+
use char1
17+
integer :: n, i
18+
!$cuf kernel do(1)<<<*,*>>>
19+
do i = 1, n
20+
if (check_char(da(i),db(i))) then
21+
print*,'same'
22+
endif
23+
enddo
24+
end program
25+
26+
! CHECK-LABEL: func.func @_QQmain()
27+
! CHECK: cuf.kernel
28+
! CHECK-COUNT-2: %{{.*}} = fir.alloca !fir.char<1> {bindc_name = ".tmp"}
29+

0 commit comments

Comments
 (0)