Skip to content

Commit b5ce7a9

Browse files
authored
[flang][cuda] Avoid generating data transfer when calling size intrinsic (#108081)
cuf.data_transfer was wrongly generated when calling the `size` intrinsic on a device allocatable variable. Since the descriptor is available on the host, there is no transfer needed. Add `DescriptorInquiry` in the `CollectCudaSymbolsHelper` to filter out symbols that are not needed for the transfer decision to be made.
1 parent 0f56ba1 commit b5ce7a9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

flang/lib/Evaluate/tools.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,9 @@ struct CollectCudaSymbolsHelper : public SetTraverse<CollectCudaSymbolsHelper,
10111011
}
10121012
// Overload some of the operator() to filter out the symbols that are not
10131013
// of interest for CUDA data transfer logic.
1014+
semantics::UnorderedSymbolSet operator()(const DescriptorInquiry &) const {
1015+
return {};
1016+
}
10141017
semantics::UnorderedSymbolSet operator()(const Subscript &) const {
10151018
return {};
10161019
}

flang/test/Lower/CUDA/cuda-data-transfer.cuf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,13 @@ end subroutine
353353
! CHECK-LABEL: func.func @_QPsub17()
354354
! CHECK: cuf.kernel<<<*, *>>>
355355
! CHECK-NOT: cuf.data_transfer
356+
357+
subroutine sub18()
358+
integer, device, allocatable :: a(:)
359+
integer :: isz
360+
361+
isz = size(a)
362+
end subroutine
363+
364+
! CHECK-LABEL: func.func @_QPsub18()
365+
! CHECK-NOT: cuf.data_transfer

0 commit comments

Comments
 (0)